[nostalgia/player] Cleanup main

This commit is contained in:
Gary Talent 2020-01-12 20:46:12 -06:00
parent 03fc6280c9
commit bda4e643af

View File

@ -28,59 +28,28 @@ ox::Error run(ox::FileSystem *fs) {
return OxError(0);
}
#ifndef OX_USE_STDLIB
int main() {
auto rom = loadRom();
if (!rom) {
return 1;
}
ox::FileSystem32 fs(ox::FileStore32(rom, 32 * ox::units::MB));
run(&fs);
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 {
return {};
}
}
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()) {
ox::FileSystem *fs = nullptr;
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) {
return 1;
}
fs = std::make_unique<ox::FileSystem32>(ox::FileStore32(rom.data(), 32 * ox::units::MB));
fs = new (ox_alloca(sizeof(ox::FileStore32))) ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB));
#ifdef OX_HAS_PASSTHROUGHFS
} else {
fs = std::make_unique<ox::PassThroughFS>(path.c_str());
fs = new (ox_alloca(sizeof(ox::PassThroughFS))) ox::PassThroughFS(path);
#endif
}
auto err = run(fs.get());
auto err = run(fs);
oxAssert(err, "Something went wrong...");
unloadRom(rom);
return err;
}
return 2;
}
#endif