From 7d5595b4054154f0e032ab5cadb66b20c351cfa0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 9 Nov 2019 18:07:28 -0600 Subject: [PATCH] [nostalgia/player] Give player the ability to load from rom file or directory --- src/nostalgia/player/CMakeLists.txt | 1 - src/nostalgia/player/main.cpp | 34 +++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/nostalgia/player/CMakeLists.txt b/src/nostalgia/player/CMakeLists.txt index 9676bb7d..86d49872 100644 --- a/src/nostalgia/player/CMakeLists.txt +++ b/src/nostalgia/player/CMakeLists.txt @@ -23,7 +23,6 @@ endif() target_link_libraries( nostalgia NostalgiaWorld - NostalgiaCore ${NOSTALGIA_PLAYER_DEPS} ) diff --git a/src/nostalgia/player/main.cpp b/src/nostalgia/player/main.cpp index 0fa6a75c..94472f56 100644 --- a/src/nostalgia/player/main.cpp +++ b/src/nostalgia/player/main.cpp @@ -42,10 +42,40 @@ int main() { #else +#include +#include + +std::vector 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 buff(size); + fread(buff.data(), size, 1, file); + fclose(file); + return buff; + } else { + return {}; + } +} + int main(int argc, const char **argv) { if (argc > 1) { - ox::PassThroughFS fs(argv[1]); - auto err = run(&fs); + std::unique_ptr fs; + std::vector rom; + std::string path = argv[1]; + const std::string fsExt = path.substr(path.find_last_of('.')); + if (fsExt == ".oxfs") { + rom = loadFileBuff(path.c_str()); + if (!rom.size()) { + return 1; + } + fs = std::make_unique(ox::FileStore32(rom.data(), 32 * ox::units::MB)); + } else { + fs = std::make_unique(path.c_str()); + } + auto err = run(fs.get()); oxAssert(err, "Something went wrong..."); return err; }