[nostalgia/player] Cleanup main
This commit is contained in:
parent
03fc6280c9
commit
bda4e643af
@ -28,59 +28,28 @@ ox::Error run(ox::FileSystem *fs) {
|
|||||||
return OxError(0);
|
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) {
|
int main(int argc, const char **argv) {
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
std::unique_ptr<ox::FileSystem> fs;
|
ox::FileSystem *fs = nullptr;
|
||||||
std::vector<uint8_t> rom;
|
uint8_t *rom = nullptr;
|
||||||
const std::string path = argv[1];
|
auto path = argv[1];
|
||||||
const auto lastDot = path.find_last_of('.');
|
const auto lastDot = ox_lastIndexOf(path, '.');
|
||||||
const std::string fsExt = lastDot != std::string::npos ? path.substr(lastDot) : "";
|
const auto fsExt = lastDot != -1 ? path + lastDot : "";
|
||||||
if (fsExt == ".oxfs") {
|
if (ox_strcmp(fsExt, ".oxfs") == 0) {
|
||||||
rom = loadFileBuff(path.c_str());
|
rom = loadRom(path);
|
||||||
if (!rom.size()) {
|
if (!rom) {
|
||||||
return 1;
|
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 {
|
} 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...");
|
oxAssert(err, "Something went wrong...");
|
||||||
|
unloadRom(rom);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user