[nostalgia/player] Cleanup main
This commit is contained in:
		| @@ -28,59 +28,28 @@ ox::Error run(ox::FileSystem *fs) { | |||||||
| 	return OxError(0); | 	return OxError(0); | ||||||
| } | } | ||||||
|  |  | ||||||
| #ifndef OX_USE_STDLIB | int main(int argc, const char **argv) { | ||||||
|  | 	if (argc > 1) { | ||||||
| int main() { | 		ox::FileSystem *fs = nullptr; | ||||||
| 	auto rom = loadRom(); | 		uint8_t *rom = nullptr; | ||||||
|  | 		auto path = argv[1]; | ||||||
|  | 		const auto lastDot = ox_lastIndexOf(path, '.'); | ||||||
|  | 		const auto fsExt = lastDot != -1 ? path + lastDot : ""; | ||||||
|  | 		if (ox_strcmp(fsExt, ".oxfs") == 0) { | ||||||
|  | 			rom = loadRom(path); | ||||||
| 			if (!rom) { | 			if (!rom) { | ||||||
| 				return 1; | 				return 1; | ||||||
| 			} | 			} | ||||||
| 	ox::FileSystem32 fs(ox::FileStore32(rom, 32 * ox::units::MB)); | 			fs = new (ox_alloca(sizeof(ox::FileStore32))) ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB)); | ||||||
| 	run(&fs); | #ifdef OX_HAS_PASSTHROUGHFS | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #else |  | ||||||
|  |  | ||||||
| #include <vector> |  | ||||||
| #include <cstdio> |  | ||||||
|  |  | ||||||
| std::vector<uint8_t> loadFileBuff(const char *path) { |  | ||||||
| 	auto file = fopen(path, "r"); |  | ||||||
| 	if (file) { |  | ||||||
| 		fseek(file, 0, SEEK_END); |  | ||||||
| 		const auto size = ftell(file); |  | ||||||
| 		rewind(file); |  | ||||||
| 		std::vector<uint8_t> buff(size); |  | ||||||
| 		fread(buff.data(), size, 1, file); |  | ||||||
| 		fclose(file); |  | ||||||
| 		return buff; |  | ||||||
| 		} else { | 		} else { | ||||||
| 		return {}; | 			fs = new (ox_alloca(sizeof(ox::PassThroughFS))) ox::PassThroughFS(path); | ||||||
|  | #endif | ||||||
| 		} | 		} | ||||||
| } | 		auto err = run(fs); | ||||||
|  |  | ||||||
| int main(int argc, const char **argv) { |  | ||||||
| 	if (argc > 1) { |  | ||||||
| 		std::unique_ptr<ox::FileSystem> fs; |  | ||||||
| 		std::vector<uint8_t> rom; |  | ||||||
| 		const std::string path = argv[1]; |  | ||||||
| 		const auto lastDot = path.find_last_of('.'); |  | ||||||
| 		const std::string fsExt = lastDot != std::string::npos ? path.substr(lastDot) : ""; |  | ||||||
| 		if (fsExt == ".oxfs") { |  | ||||||
| 			rom = loadFileBuff(path.c_str()); |  | ||||||
| 			if (!rom.size()) { |  | ||||||
| 				return 1; |  | ||||||
| 			} |  | ||||||
| 			fs = std::make_unique<ox::FileSystem32>(ox::FileStore32(rom.data(), 32 * ox::units::MB)); |  | ||||||
| 		} else { |  | ||||||
| 			fs = std::make_unique<ox::PassThroughFS>(path.c_str()); |  | ||||||
| 		} |  | ||||||
| 		auto err = run(fs.get()); |  | ||||||
| 		oxAssert(err, "Something went wrong..."); | 		oxAssert(err, "Something went wrong..."); | ||||||
|  | 		unloadRom(rom); | ||||||
| 		return err; | 		return err; | ||||||
| 	} | 	} | ||||||
| 	return 2; | 	return 2; | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user