a75c4a11 [nfde] Address CMake warning, remove unwanted logging 347a1657 [sample_project] Update type descriptors fd64bfae [keel] Fix a use after free, cleanup aaeec20a [nostalgia/player] Fix build 37030f9c [keel] Cleanup pack tool 462f2bca [nostalgia,olympic] Change macro names to comply with broader conventions dc72500b [glutils] Change macro names to comply with broader conventions 962fe8bc [ox] Change macro names to comply with broader conventions 305eb626 [studio] Fix build 4754359a [ox/std] Cleanup Vec2 dc07f3d5 [studio] Change FilePicker consturctor to take StringParams fcdcfd10 [ox/std] Run liccor b74f6a7a [studio,turbine] Run liccor ac7e5be1 [ox] Remove OxException ed910c0b [nostalgia/core/studio/tilesheeteditor] Fix access overflow on out of bounds Fill command 345fb038 [ox] Remove OxError 9881253f [glutils] Cleanup OxError 96d27eec [nostalgia,olympic] Cleanup 28ebe93b [ox/std] Make source_location::current only init if valid e849e7a3 [ox/std] Add source_location e6777b0a [cityhash] Add install rule c488c336 [turbine/glfw] Fix mandatoryRefreshPeriodEnd tracking 003f9720 [turbine/glfw] Move MandatoryRefreshPeriod to config.hpp d85a10af [nostalgia/core/studio] Cleanup ff05d860 [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd 76794037 [turbine] Add init wrapper that takes FS path c51a45e1 [olympic] Cleanup a6e24ff2 [ox/std] Add CString type alias e0ec9e0c [nostalgia,olympic] Move olympic::run to global namespace 9a42a9b9 [nfde] Fix Windows warnings 03a05c51 Merge commit '4ccdfc3a6e5bd501968903a01f7d8141b6f88375' bd91137d [nostalgia,olympic] Fix pack tool build for Windows 2b7d1294 [nostalgia/core/studio] Fix MSVC build git-subtree-dir: deps/nostalgia git-subtree-split: a75c4a11d3c555f4d3bed1ea1f70bb29fe49e99c
103 lines
3.5 KiB
C++
103 lines
3.5 KiB
C++
/*
|
|
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
|
*/
|
|
|
|
#include <fstream>
|
|
|
|
#include <ox/clargs/clargs.hpp>
|
|
#include <ox/fs/fs.hpp>
|
|
#include <ox/logconn/def.hpp>
|
|
#include <ox/logconn/logconn.hpp>
|
|
#include <ox/oc/write.hpp>
|
|
|
|
#include <keel/keel.hpp>
|
|
|
|
static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept {
|
|
try {
|
|
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
|
|
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
|
|
} catch (std::fstream::failure const&) {
|
|
return ox::Error(2, "failed to write file");
|
|
}
|
|
return {};
|
|
}
|
|
|
|
static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
|
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
|
|
if (!file.good()) {
|
|
oxErrorf("Could not find OxFS file: {}", path);
|
|
return ox::Error(1, "Could not find OxFS file");
|
|
}
|
|
try {
|
|
auto const size = static_cast<std::size_t>(file.tellg());
|
|
ox::Buffer buff(size);
|
|
file.seekg(0, std::ios::beg);
|
|
file.read(buff.data(), static_cast<std::streamsize>(buff.size()));
|
|
return buff;
|
|
} catch (std::ios_base::failure const&e) {
|
|
oxErrorf("Could not read OxFS file: {}", e.what());
|
|
return ox::Error(2, "Could not read OxFS file");
|
|
}
|
|
}
|
|
|
|
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
|
for (auto const mod : keel::modules()) {
|
|
for (auto gen : mod->types()) {
|
|
OX_RETURN_ERROR(gen(ts));
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
static ox::Error pack(
|
|
ox::StringView argSrc,
|
|
ox::StringView argRomBin,
|
|
ox::StringView argManifest,
|
|
ox::StringView projectDataDir) noexcept {
|
|
ox::Buffer dstBuff(32 * ox::units::MB);
|
|
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
|
ox::FileSystem32 dst(dstBuff);
|
|
OX_REQUIRE(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
|
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
|
OX_RETURN_ERROR(generateTypes(ts));
|
|
keel::Manifest manifest;
|
|
OX_RETURN_ERROR(keel::pack(manifest, *ctx, ts, dst));
|
|
OX_REQUIRE_M(pl, keel::GbaPreloader::make());
|
|
OX_RETURN_ERROR(preload(manifest, ts, dst, *pl));
|
|
OX_RETURN_ERROR(dst.resize());
|
|
// resize buffer
|
|
OX_REQUIRE(dstSize, dst.size());
|
|
dstBuff.resize(dstSize);
|
|
// concatenate ROM segments
|
|
OX_REQUIRE_M(romBuff, readFileBuff(argRomBin));
|
|
oxOutf("Input exe size: {} bytes\n", romBuff.size());
|
|
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
|
oxOutf("Preload buff size: {} bytes\n", pl->buff().size());
|
|
OX_RETURN_ERROR(appendBinary(romBuff, dstBuff, *pl));
|
|
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
|
|
OX_RETURN_ERROR(writeFileBuff(argRomBin, romBuff));
|
|
OX_REQUIRE(manifestJson, ox::writeOCString(manifest));
|
|
OX_RETURN_ERROR(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
|
return {};
|
|
}
|
|
|
|
ox::Error run(
|
|
[[maybe_unused]] ox::StringView project,
|
|
[[maybe_unused]] ox::StringView appName,
|
|
ox::StringView projectDataDir,
|
|
ox::SpanView<ox::CString> argv) noexcept {
|
|
ox::ClArgs const args(argv);
|
|
auto const argSrc = args.getString("src", "");
|
|
auto const argRomBin = args.getString("rom-bin", "");
|
|
auto const argManifest = args.getString("manifest", "");
|
|
if (argSrc == "") {
|
|
oxErr("\033[31;1;1merror:\033[0m must specify a source directory\n");
|
|
return ox::Error(1, "must specify a source directory");
|
|
}
|
|
if (argRomBin == "") {
|
|
oxErr("\033[31;1;1merror:\033[0m must specify a path for ROM file\n");
|
|
return ox::Error(1, "must specify a path for preload file");
|
|
}
|
|
return pack(argSrc, argRomBin, argManifest, projectDataDir);
|
|
}
|