[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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user