<commit_before>/*
 * Copyright 2016 - 2018 <EMAIL>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <array>
#include <iostream>
#include <QColor>
#include <QImage>
#include <QMap>
#include <nostalgia/core/gba/gba.hpp>
#include <nostalgia/common/point.hpp>
#include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp>
#include <ox/std/units.hpp>

#include "pack/pack.hpp"

using namespace std;
using namespace ox;
using namespace nostalgia::core;
using namespace nostalgia::common;

ox::ValErr<std::vector<uint8_t>> loadFileBuff(QString path, ::size_t *sizeOut = nullptr) {
	auto file = fopen(path.toUtf8(), "rb");
	if (file) {
		fseek(file, 0, SEEK_END);
		const auto size = ftell(file);
		rewind(file);
		std::vector<uint8_t> buff(size);
		auto itemsRead = fread(buff.data(), buff.size(), 1, file);
		fclose(file);
		if (sizeOut) {
			*sizeOut = itemsRead ? size : 0;
		}
		return buff;
	} else {
		return {{}, OxError(1)};
	}
}

int run(ClArgs args) {
	QString argSrc = args.getString("src").c_str();
	QString argDst = args.getString("dst").c_str();
	std::array<uint8_t, 32 * ox::units::MB> buff;
	ox::FileSystem32::format(buff.data(), buff.size());
	ox::PassThroughFS src(argSrc.toUtf8());
	ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size()));
	oxReturnError(nostalgia::pack(&src, &dst));
	return 0;
}

int main(int argc, const char **args) {
	return run(ClArgs(argc, args));
}<commit_msg>[nostalgia/tools/pack] Add input checking to nost-pack<commit_after>/*
 * Copyright 2016 - 2018 <EMAIL>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <iostream>
#include <QColor>
#include <QImage>
#include <QMap>
#include <nostalgia/core/gba/gba.hpp>
#include <nostalgia/common/point.hpp>
#include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp>
#include <ox/std/units.hpp>

#include "pack/pack.hpp"

using namespace std;
using namespace ox;
using namespace nostalgia::core;
using namespace nostalgia::common;

ox::ValErr<std::vector<uint8_t>> loadFileBuff(QString path, ::size_t *sizeOut = nullptr) {
	auto file = fopen(path.toUtf8(), "rb");
	if (file) {
		fseek(file, 0, SEEK_END);
		const auto size = ftell(file);
		rewind(file);
		std::vector<uint8_t> buff(size);
		auto itemsRead = fread(buff.data(), buff.size(), 1, file);
		fclose(file);
		if (sizeOut) {
			*sizeOut = itemsRead ? size : 0;
		}
		return buff;
	} else {
		return {{}, OxError(1)};
	}
}

ox::Error run(ClArgs args) {
	std::string argSrc = args.getString("src").c_str();
	std::string argDst = args.getString("dst").c_str();
	if (argSrc == "") {
		std::cerr << "error: must specify a source directory\n";
		return OxError(1);
	}
	if (argDst == "") {
		std::cerr << "error: must specify a destination ROM file\n";
		return OxError(1);
	}
	std::vector<uint8_t> buff(32 * ox::units::MB);
	ox::FileSystem32::format(buff.data(), buff.size());
	ox::PassThroughFS src(argSrc.c_str());
	ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size()));
	oxReturnError(nostalgia::pack(&src, &dst));
	return OxError(0);
}

int main(int argc, const char **args) {
	return static_cast<int>(run(ClArgs(argc, args)));
}
{'fraction_non_alphanumeric': 0.17481698389458272, 'fraction_numerical': 0.01786237188872621, 'mean_word_length': 4.819420783645656, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2334666', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1262, 'n_words': 317}