Skip to content

Commit

Permalink
win: fix dump textures and box art saves when path contains non-ascii
Browse files Browse the repository at this point in the history
Texture dumping and local boxart scraper were failing on windows if
image path contains non-ascii chars. nonwide::fopen must be used.
  • Loading branch information
flyinghead committed Apr 3, 2024
1 parent ed78eb4 commit d6efbc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion core/rend/CustomTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,19 @@ void CustomTexture::DumpTexture(u32 hash, int w, int h, TextureType textype, voi
}

stbi_flip_vertically_on_write(1);
stbi_write_png(path.str().c_str(), w, h, STBI_rgb_alpha, dst_buffer, 0);
const auto& savefunc = [](void *context, void *data, int size) {
FILE *f = nowide::fopen((const char *)context, "wb");
if (f == nullptr)
{
WARN_LOG(RENDERER, "Dump texture: can't save to file %s: error %d", context, errno);
}
else
{
fwrite(data, 1, size, f);
fclose(f);
}
};
stbi_write_png_to_func(savefunc, (void *)path.str().c_str(), w, h, STBI_rgb_alpha, dst_buffer, 0);

free(dst_buffer);
}
Expand Down
14 changes: 13 additions & 1 deletion core/rend/boxart/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,19 @@ void OfflineScraper::scrape(GameBoxart& item)
{
stbi_flip_vertically_on_write(0);
item.setBoxartPath(makeUniqueFilename("gdtex.png"));
stbi_write_png(item.boxartPath.c_str(), w, h, 4, out.data(), 0);
const auto& savefunc = [](void *context, void *data, int size) {
FILE *f = nowide::fopen((const char *)context, "wb");
if (f == nullptr)
{
WARN_LOG(COMMON, "can't create local file %s: error %d", context, errno);
}
else
{
fwrite(data, 1, size, f);
fclose(f);
}
};
stbi_write_png_to_func(savefunc, (void *)item.boxartPath.c_str(), w, h, 4, out.data(), 0);
}
}
}
Expand Down

0 comments on commit d6efbc5

Please sign in to comment.