[nostalgia] Replace C strings with ox::StringView

This commit is contained in:
Gary Talent 2022-12-31 17:14:43 -06:00
parent 55ea405a54
commit 679226ef73
31 changed files with 81 additions and 75 deletions

View File

@ -14,7 +14,7 @@ namespace nostalgia::core {
ox::String getClipboardText(class Context *ctx) noexcept;
void setClipboardText(class Context *ctx, const ox::String &text) noexcept;
void setClipboardText(class Context *ctx, ox::CRStringView text) noexcept;
template<typename T>
void setClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] ox::UniquePtr<T> obj) noexcept {

View File

@ -63,7 +63,7 @@ class Context {
const ox::FileAddress &palettePath) noexcept;
friend ox::Error run(Context *ctx) noexcept;
friend void shutdown(Context *ctx) noexcept;
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept;
friend ox::String getClipboardText(Context *ctx) noexcept;
friend uint64_t ticksMs(Context *ctx) noexcept;
friend uint8_t bgStatus(Context *ctx) noexcept;
@ -73,17 +73,15 @@ class Context {
friend void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
friend void setBgStatus(Context *ctx, uint32_t status) noexcept;
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
friend void setClipboardText(Context *ctx, const ox::String &text) noexcept;
friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept;
friend constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept;
friend constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept;
friend void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
friend void setWindowTitle(Context *ctx, const char *title) noexcept;
public:
ox::UniquePtr<ox::FileSystem> rom;
ox::Vector<Drawer*, 5> drawers;
const char *appName = "Nostalgia";
ox::StringView appName = "Nostalgia";
#ifndef OX_BARE_METAL
AssetManager assetManager;

View File

@ -17,7 +17,7 @@
namespace nostalgia::core {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName = "Nostalgia") noexcept;
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName = "Nostalgia") noexcept;
ox::Error run(Context *ctx) noexcept;

View File

@ -54,7 +54,7 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
return OxError(1);
}
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
auto ctx = ox::make_unique<Context>();
ctx->rom = std::move(fs);
ctx->appName = appName;

View File

@ -85,7 +85,7 @@ ox::Error shutdownGfx(Context*) noexcept {
return {};
}
void setWindowTitle(Context*, const char*) noexcept {
void setWindowTitle(Context*, ox::CRStringView) noexcept {
}
void focusWindow(Context*) noexcept {
@ -210,10 +210,11 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p
}
// Do NOT use Context in the GBA version of this function.
void puts(Context *ctx, int column, int row, const char *str) noexcept {
for (int i = 0; str[i]; i++) {
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
const auto col = static_cast<unsigned>(column);
for (auto i = 0u; i < str.bytes(); i++) {
const auto c = charMap[static_cast<unsigned>(str[i])];
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(c));
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(c));
}
}

View File

@ -11,7 +11,7 @@
namespace nostalgia::core {
ox::Result<char*> loadRom(const char*) noexcept {
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
// put the header in the wrong order to prevent mistaking this code for the
// media section
constexpr auto headerP2 = "HEADER__________";

View File

@ -27,7 +27,7 @@ void panic(const char*, int, const char *msg, const ox::Error &err) noexcept {
puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:");
puts(nullptr, 32 + 2, 6, msg);
if (err) {
puts(nullptr, 32 + 2, 8, serr.c_str());
puts(nullptr, 32 + 2, 8, serr);
}
puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
// disable all interrupt handling and IntrWait on no interrupts

View File

@ -93,11 +93,11 @@ struct TileSheet {
other.columns = 0;
other.rows = 0;
}
constexpr SubSheet(const char *pName, int pColumns, int pRows, int bpp) noexcept:
constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, int bpp) noexcept:
name(pName), columns(pColumns), rows(pRows),
pixels(static_cast<std::size_t>(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) {
}
constexpr SubSheet(const char *pName, int pColumns, int pRows, ox::Vector<uint8_t> pPixels) noexcept:
constexpr SubSheet(ox::CRStringView pName, int pColumns, int pRows, ox::Vector<uint8_t> pPixels) noexcept:
name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) {
}
@ -375,7 +375,7 @@ struct TileSheet {
constexpr ox::Error addSubSheet(const SubSheetIdx &idx) noexcept {
auto &parent = getSubSheet(idx);
if (parent.subsheets.size() < 2) {
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()).c_str(), 1, 1, bpp);
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp);
} else {
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, bpp);
parent.subsheets.emplace_back("Subsheet 1", 1, 1, bpp);
@ -482,7 +482,7 @@ void addCustomDrawer(Context *ctx, Drawer *cd) noexcept;
void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept;
void setWindowTitle(Context *ctx, const char *title) noexcept;
void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept;
void focusWindow(Context *ctx) noexcept;
@ -518,7 +518,7 @@ ox::Error loadSpriteTileSheet(Context *ctx,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept;
void puts(Context *ctx, int column, int row, const char *str) noexcept;
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept;
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;

View File

@ -17,9 +17,11 @@ ox::String getClipboardText(Context *ctx) noexcept {
return glfwGetClipboardString(id->window);
}
void setClipboardText(Context *ctx, const ox::String &text) noexcept {
void setClipboardText(Context *ctx, ox::CRStringView text) noexcept {
const auto id = ctx->windowerData<GlfwImplData>();
glfwSetClipboardString(id->window, text.c_str());
auto cstr = ox_malloca(text.bytes() + 1, char);
ox_strncpy(cstr.get(), text.data(), text.bytes());
glfwSetClipboardString(id->window, cstr);
}
}

View File

@ -13,7 +13,7 @@
namespace nostalgia::core {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
auto ctx = ox::make_unique<Context>();
ctx->rom = std::move(fs);
ctx->appName = appName;

View File

@ -192,7 +192,9 @@ ox::Error initGfx(Context *ctx) noexcept {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
}
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
id->window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx->appName, nullptr, nullptr);
auto cstr = ox_malloca(ctx->appName.bytes() + 1, char);
ox_strncpy(cstr.get(), ctx->appName.data(), ctx->appName.bytes());
id->window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr);
if (id->window == nullptr) {
return OxError(1, "Could not open GLFW window");
}
@ -220,9 +222,11 @@ ox::Error initGfx(Context *ctx) noexcept {
return OxError(0);
}
void setWindowTitle(Context *ctx, const char *title) noexcept {
void setWindowTitle(Context *ctx, ox::CRStringView title) noexcept {
const auto id = ctx->windowerData<GlfwImplData>();
glfwSetWindowTitle(id->window, title);
auto cstr = ox_malloca(title.bytes() + 1, char);
ox_strncpy(cstr.get(), title.data(), title.bytes());
glfwSetWindowTitle(id->window, cstr);
}
void focusWindow(Context *ctx) noexcept {

View File

@ -7,7 +7,7 @@
namespace nostalgia::core {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, const char*) noexcept {
ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, ox::CRStringView) noexcept {
return OxError(1);
}

View File

@ -15,7 +15,7 @@ ox::Error shutdownGfx(Context*) noexcept {
return OxError(0);
}
void setWindowTitle(Context*, const char*) noexcept {
void setWindowTitle(Context*, ox::CRStringView) noexcept {
}
void focusWindow(Context*) noexcept {
@ -75,7 +75,7 @@ ox::Error loadSpritePalette(Context*, int, const ox::FileAddress&) noexcept {
}
// Do NOT use Context in the GBA version of this function.
void puts(Context*, int, int, const char*) noexcept {
void puts(Context*, int, int, ox::CRStringView) noexcept {
}
void setTile(Context*, int, int, int, uint8_t) noexcept {

View File

@ -8,7 +8,7 @@
namespace nostalgia::core {
ox::Result<char*> loadRom(const char*) noexcept {
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
return OxError(1);
}

View File

@ -6,9 +6,9 @@
namespace nostalgia::core {
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept {
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
const auto lastDot = ox_lastIndexOf(path, '.');
const auto fsExt = lastDot != -1 ? path + lastDot : "";
const auto fsExt = lastDot != -1 ? path.substr(static_cast<std::size_t>(lastDot)) : "";
if (ox_strcmp(fsExt, ".oxfs") == 0) {
oxRequire(rom, core::loadRom(path));
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};

View File

@ -89,9 +89,9 @@ ox::Error writeObj(Context *ctx, const ox::FileAddress &file, const T &obj,
return ctx->rom->write(file, objBuff.data(), objBuff.size());
}
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(const char *path) noexcept;
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept;
ox::Result<char*> loadRom(const char *path = "") noexcept;
ox::Result<char*> loadRom(ox::CRStringView path = "") noexcept;
void unloadRom(char*) noexcept;

View File

@ -416,7 +416,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw() noexcept {
if (ImGui::Button("OK")) {
ImGui::CloseCurrentPopup();
m_show = false;
inputSubmitted.emit(m_name.c_str(), m_cols, m_rows);
inputSubmitted.emit(m_name, m_cols, m_rows);
}
ImGui::SameLine();
if (ImGui::Button("Cancel")) {

View File

@ -32,7 +32,7 @@ class TileSheetEditorImGui: public studio::BaseEditor {
int m_rows = 0;
bool m_show = false;
public:
ox::Signal<ox::Error(const ox::String &name, int cols, int rows)> inputSubmitted;
ox::Signal<ox::Error(const ox::StringView &name, int cols, int rows)> inputSubmitted;
constexpr void show(const ox::String &name, int cols, int rows) noexcept {
m_show = true;
m_name = name.c_str();

View File

@ -256,7 +256,7 @@ class AddSubSheetCommand: public TileSheetCommand {
auto &parent = m_img->getSubSheet(m_parentIdx);
if (m_addedSheets.size() < 2) {
auto i = parent.subsheets.size();
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i).c_str(), 1, 1, m_img->bpp);
parent.subsheets.emplace_back(ox::sfmt("Subsheet {}", i), 1, 1, m_img->bpp);
} else {
parent.subsheets.emplace_back("Subsheet 0", parent.columns, parent.rows, std::move(parent.pixels));
parent.rows = 0;

View File

@ -49,8 +49,8 @@ static const auto converters = [] {
}();
[[nodiscard]]
static auto findConverter(const char *srcTypeName, int srcTypeVersion,
const char *dstTypeName, int dstTypeVersion) noexcept -> ox::Result<BaseConverter*> {
static auto findConverter(ox::CRStringView srcTypeName, int srcTypeVersion,
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept -> ox::Result<BaseConverter*> {
for (auto &c : converters) {
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
return c.get();
@ -60,8 +60,8 @@ static auto findConverter(const char *srcTypeName, int srcTypeVersion,
};
static ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
const char *srcTypeName, int srcTypeVersion,
const char *dstTypeName, int dstTypeVersion) noexcept {
ox::CRStringView srcTypeName, int srcTypeVersion,
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept {
// look for direct converter
auto [c, err] = findConverter(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
if (!err) {
@ -82,9 +82,9 @@ static ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
return OxError(1, "Could not convert between types");
}
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer, const char *dstTypeName, int dstTypeVersion) noexcept {
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer, ox::CRStringView dstTypeName, int dstTypeVersion) noexcept {
oxRequire(hdr, ox::readClawHeader(srcBuffer));
return convert(srcBuffer, hdr.typeName.c_str(), hdr.typeVersion, dstTypeName, dstTypeVersion);
return convert(srcBuffer, hdr.typeName, hdr.typeVersion, dstTypeName, dstTypeVersion);
}
#endif

View File

@ -51,24 +51,24 @@ struct BaseConverter {
virtual ~BaseConverter() noexcept = default;
[[nodiscard]]
virtual const char *srcTypeName() noexcept = 0;
virtual ox::StringView srcTypeName() noexcept = 0;
[[nodiscard]]
virtual int srcTypeVersion() noexcept = 0;
[[nodiscard]]
virtual bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept = 0;
virtual bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept = 0;
[[nodiscard]]
virtual bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept = 0;
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(Wrap *src) noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(const ox::Buffer &srcBuff) noexcept = 0;
[[nodiscard]]
inline bool matches(const char *srcTypeName, int srcTypeVersion,
const char *dstTypeName, int dstTypeVersion) const noexcept {
inline bool matches(ox::CRStringView srcTypeName, int srcTypeVersion,
ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept {
return srcMatches(srcTypeName, srcTypeVersion)
&& dstMatches(dstTypeName, dstTypeVersion);
}
@ -81,7 +81,7 @@ struct Converter: public BaseConverter {
virtual ox::Error convert(SrcType*, DstType*) noexcept = 0;
[[nodiscard]]
const char *srcTypeName() noexcept final {
ox::StringView srcTypeName() noexcept final {
return ox::requireModelTypeName<SrcType>();
}
@ -91,7 +91,7 @@ struct Converter: public BaseConverter {
}
[[nodiscard]]
bool srcMatches(const char *srcTypeName, int srcTypeVersion) const noexcept final {
bool srcMatches(ox::CRStringView srcTypeName, int srcTypeVersion) const noexcept final {
static constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
static constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
return ox_strcmp(srcTypeName, SrcTypeName) == 0
@ -99,7 +99,7 @@ struct Converter: public BaseConverter {
}
[[nodiscard]]
bool dstMatches(const char *dstTypeName, int dstTypeVersion) const noexcept final {
bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final {
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
return ox_strcmp(dstTypeName, DstTypeName) == 0
@ -122,7 +122,7 @@ struct Converter: public BaseConverter {
};
ox::Result<ox::UniquePtr<Wrap>> convert(const ox::Buffer &srcBuffer,
const char *dstTypeName, int dstTypeVersion) noexcept;
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept;
template<typename DstType>
ox::Result<DstType> convert(const ox::Buffer &srcBuffer) noexcept {

View File

@ -52,9 +52,10 @@ ox::Error loadSpriteTileSheet(Context*,
return OxError(0);
}
void puts(Context *ctx, int column, int row, const char *str) noexcept {
for (int i = 0; str[i]; ++i) {
setTile(ctx, 0, column + i, row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
const auto col = static_cast<unsigned>(column);
for (auto i = 0u; i < str.bytes(); ++i) {
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
}
}

View File

@ -10,8 +10,8 @@
namespace nostalgia::core {
ox::Result<char*> loadRom(const char *path) noexcept {
std::ifstream file(path, std::ios::binary | std::ios::ate);
ox::Result<char*> loadRom(ox::CRStringView path) noexcept {
std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate);
if (!file.good()) {
oxErrorf("Could not find ROM file: {}", path);
return OxError(1, "Could not find ROM file");

View File

@ -47,7 +47,7 @@ template struct GLObject<deleteProgram>;
template struct GLObject<deleteShader>;
[[nodiscard]]
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, const char *shaderName) noexcept {
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, ox::CRStringView shaderName) noexcept {
GLShader shader(glCreateShader(shaderType));
glShaderSource(shader, 1, &src, nullptr);
glCompileShader(shader);

View File

@ -38,7 +38,7 @@ constexpr auto ConfigDir = [] {
}();
template<typename T>
ox::Result<T> readConfig(core::Context *ctx, const char *name) noexcept {
ox::Result<T> readConfig(core::Context *ctx, ox::CRStringView name) noexcept {
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
@ -70,16 +70,16 @@ template<typename T>
ox::Error writeConfig(core::Context *ctx, const auto &name, T *data) noexcept {
oxAssert(ox_strcmp(name, ""), "Config type has no TypeName");
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName).toStdString();
const auto path = ox::sfmt("{}.json", name).toStdString();
ox::PassThroughFS fs(configPath.c_str());
const auto configPath = ox::sfmt(ConfigDir, homeDir, ctx->appName);
const auto path = ox::sfmt("{}.json", name);
ox::PassThroughFS fs(configPath);
if (auto err = fs.mkdir("/", true)) {
oxErrf("Could not create config directory: {}\n", toStr(err));
return err;
}
oxRequireM(buff, ox::writeOC(data));
buff.back().value = '\n';
if (auto err = fs.write(path.c_str(), buff.data(), buff.size())) {
if (auto err = fs.write(path, buff.data(), buff.size())) {
oxErrf("Could not read config file: {}\n", toStr(err));
return OxError(2, "Could not read config file");
}

View File

@ -21,7 +21,7 @@ class ItemMaker {
fileExt(std::move(pFileExt)) {
}
virtual ~ItemMaker() noexcept = default;
virtual ox::Error write(core::Context *ctx, const char *pName) const noexcept = 0;
virtual ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept = 0;
};
template<typename T>
@ -44,7 +44,7 @@ class ItemMakerT: public ItemMaker {
item(std::forward(pItem)),
fmt(pFmt) {
}
ox::Error write(core::Context *ctx, const char *pName) const noexcept override {
ox::Error write(core::Context *ctx, ox::CRStringView pName) const noexcept override {
const auto path = ox::sfmt("{}/{}.{}", parentDir, pName, fileExt);
auto sctx = core::applicationData<studio::StudioContext>(ctx);
return sctx->project->writeObj(path, &item, fmt);

View File

@ -108,7 +108,7 @@ void NewMenu::drawLastPageButtons(core::Context *ctx) noexcept {
}
void NewMenu::finish(core::Context *ctx) noexcept {
const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName.c_str());
const auto err = m_types[static_cast<std::size_t>(m_selectedType)]->write(ctx, m_itemName);
if (err) {
oxLogError(err);
return;

View File

@ -283,10 +283,10 @@ void StudioUI::save() noexcept {
}
}
ox::Error StudioUI::openProject(const ox::String &path) noexcept {
oxRequireM(fs, core::loadRomFs(path.c_str()));
ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
oxRequireM(fs, core::loadRomFs(path));
m_ctx->rom = std::move(fs);
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path).c_str());
core::setWindowTitle(m_ctx, ox::sfmt("Nostalgia Studio - {}", path));
m_project = ox::make_unique<studio::Project>(m_ctx->rom.get(), path);
auto sctx = applicationData<studio::StudioContext>(m_ctx);
sctx->project = m_project.get();

View File

@ -77,7 +77,7 @@ class StudioUI: public ox::SignalHandler {
void save() noexcept;
ox::Error openProject(const ox::String &path) noexcept;
ox::Error openProject(ox::CRStringView path) noexcept;
ox::Error openFile(ox::CRStringView path) noexcept;

View File

@ -13,9 +13,9 @@
using namespace nostalgia;
static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexcept {
static ox::Error writeFileBuff(ox::CRStringView path, const ox::Buffer &buff) noexcept {
try {
std::ofstream f(path.c_str(), std::ios::binary);
std::ofstream f(toStdStringView(path), std::ios::binary);
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
} catch (const std::fstream::failure&) {
return OxError(2, "failed to write file");
@ -23,8 +23,8 @@ static ox::Error writeFileBuff(ox::CRString path, const ox::Buffer &buff) noexce
return {};
}
static ox::Result<ox::Buffer> readFileBuff(const char *path) noexcept {
std::ifstream file(path, std::ios::binary | std::ios::ate);
static ox::Result<ox::Buffer> readFileBuff(ox::CRStringView path) noexcept {
std::ifstream file(toStdStringView(path), std::ios::binary | std::ios::ate);
if (!file.good()) {
oxErrorf("Could not find OxFS file: {}", path);
return OxError(1, "Could not find OxFS file");
@ -55,7 +55,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
}
ox::Buffer dstBuff(32 * ox::units::MB);
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
ox::PassThroughFS src(argSrc.c_str());
ox::PassThroughFS src(argSrc);
ox::FileSystem32 dst(ox::FileStore32(dstBuff.data(), dstBuff.size()));
core::TypeStore ts(&src);
oxReturnError(pack(&ts, &src, &dst));
@ -66,7 +66,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
oxRequire(dstSize, dst.size());
dstBuff.resize(dstSize);
oxRequireM(romBuff, readFileBuff(argRomBin.c_str()));
oxRequireM(romBuff, readFileBuff(argRomBin));
oxReturnError(appendBinary(&romBuff, &dstBuff, pl.get()));
oxOutf("Dest FS size: {} bytes\n", dstSize);

View File

@ -123,7 +123,7 @@ static ox::Error copy(ox::FileSystem *src, ox::FileSystem *dest, ox::CRStringVie
oxOutf("reading {}\n", currentFile);
oxRequire(stat, src->stat(ox::StringView(currentFile)));
if (stat.fileType == ox::FileType::Directory) {
oxReturnError(dest->mkdir(currentFile.c_str(), true));
oxReturnError(dest->mkdir(currentFile, true));
oxReturnError(copy(src, dest, currentFile + '/'));
} else {
// load file