[nostalgia] Replace C strings with ox::StringView
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user