Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Use u8path to fix possible string conversion crashes on Windows #1282

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/utils/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ json Utils::Json::ObsDataToJson(obs_data_t *d, bool includeDefault)

bool Utils::Json::GetJsonFileContent(std::string fileName, json &content)
{
std::ifstream f(fileName);
std::ifstream f(std::filesystem::u8path(fileName));
if (!f.is_open())
return false;

Expand All @@ -195,9 +195,11 @@ bool Utils::Json::GetJsonFileContent(std::string fileName, json &content)

bool Utils::Json::SetJsonFileContent(std::string fileName, const json &content, bool makeDirs)
{
auto jsonFilePath = std::filesystem::u8path(fileName);

if (makeDirs) {
auto p = jsonFilePath.parent_path();
std::error_code ec;
auto p = std::filesystem::path(fileName).parent_path();
if (!ec && !std::filesystem::exists(p, ec))
std::filesystem::create_directories(p, ec);
if (ec) {
Expand All @@ -207,7 +209,7 @@ bool Utils::Json::SetJsonFileContent(std::string fileName, const json &content,
}
}

std::ofstream f(fileName);
std::ofstream f(jsonFilePath);
if (!f.is_open()) {
blog(LOG_ERROR, "[Utils::Json::SetJsonFileContent] Failed to open file `%s` for writing", fileName.c_str());
return false;
Expand Down