[nostalgia/core] Make loadRomFs return UniquePtr

This commit is contained in:
Gary Talent 2021-04-20 22:12:37 -05:00
parent abf45112b0
commit 4cd8f6a0c1
3 changed files with 18 additions and 18 deletions

View File

@ -10,15 +10,15 @@
namespace nostalgia::core { namespace nostalgia::core {
ox::Result<ox::FileSystem*> loadRomFs(const char *path) noexcept { ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept {
const auto lastDot = ox_lastIndexOf(path, '.'); const auto lastDot = ox_lastIndexOf(path, '.');
const auto fsExt = lastDot != -1 ? path + lastDot : ""; const auto fsExt = lastDot != -1 ? path + lastDot : "";
if (ox_strcmp(fsExt, ".oxfs") == 0) { if (ox_strcmp(fsExt, ".oxfs") == 0) {
oxRequire(rom, core::loadRom(path)); oxRequire(rom, core::loadRom(path));
return new ox::FileSystem32(rom, 32 * ox::units::MB, unloadRom); return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
} else { } else {
#ifdef OX_HAS_PASSTHROUGHFS #ifdef OX_HAS_PASSTHROUGHFS
return new ox::PassThroughFS(path); return {ox::make_unique<ox::PassThroughFS>(path)};
#else #else
return OxError(2); return OxError(2);
#endif #endif

View File

@ -12,7 +12,7 @@
namespace nostalgia::core { namespace nostalgia::core {
ox::Result<ox::FileSystem*> loadRomFs(const char *path) noexcept; ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept;
ox::Result<char*> loadRom(const char *path = "") noexcept; ox::Result<char*> loadRom(const char *path = "") noexcept;

View File

@ -11,19 +11,19 @@
#include "app.hpp" #include "app.hpp"
int main(int argc, const char **argv) { ox::Error run(int argc, const char **argv) {
if (argc > 1) { if (argc < 2) {
ox::trace::init(); oxErrf("Please provide path to project directory or OxFS file.");
auto path = argv[1]; return OxError(1);
auto [fs, err] = nostalgia::core::loadRomFs(path);
if (err) {
oxAssert(err, "Something went wrong...");
return static_cast<int>(err);
}
err = run(fs);
oxAssert(err, "Something went wrong...");
delete fs;
return static_cast<int>(err);
} }
return 1; const auto path = argv[1];
oxRequire(fs, nostalgia::core::loadRomFs(path));
return run(fs.get());
}
int main(int argc, const char **argv) {
ox::trace::init();
const auto err = run(argc, argv);
oxAssert(err, "Something went wrong...");
return static_cast<int>(err);
} }