Skip to content

Commit

Permalink
Merge pull request #19726 from hrydgard/replacement-load-ini-on-saving
Browse files Browse the repository at this point in the history
TextureReplacer: Load ini if available, even if just saving.
  • Loading branch information
hrydgard authored Dec 13, 2024
2 parents 1896194 + 6a375b0 commit e959191
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions GPU/Common/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ void TextureReplacer::NotifyConfigChanged() {
}
}

if (saveEnabled_) {
// Somewhat crude message, re-using translation strings.
auto d = GetI18NCategory(I18NCat::DEVELOPER);
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.Show(OSDType::MESSAGE_INFO, std::string(d->T("Save new textures")) + ": " + std::string(di->T("Enabled")), 2.0f);
}

if (!replaceEnabled_ && wasReplaceEnabled) {
delete vfs_;
vfs_ = nullptr;
Expand All @@ -115,6 +108,23 @@ void TextureReplacer::NotifyConfigChanged() {
ERROR_LOG(Log::G3D, "ERROR: %s", error.c_str());
g_OSD.Show(OSDType::MESSAGE_ERROR, error, 5.0f);
}
} else if (saveEnabled_) {
// Even if just saving is enabled, it makes sense to load the ini to get the correct
// settings for saving. See issue #19086
std::string error;
bool result = LoadIni(&error);
if (!result) {
// Ignore errors here, just log if we successfully loaded an ini.
} else {
INFO_LOG(Log::G3D, "Loaded INI file for saving.");
}
}

if (saveEnabled_) {
// Somewhat crude message, re-using translation strings.
auto d = GetI18NCategory(I18NCat::DEVELOPER);
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.Show(OSDType::MESSAGE_INFO, std::string(d->T("Save new textures")) + ": " + std::string(di->T("Enabled")), 2.0f);
}
}

Expand Down Expand Up @@ -144,6 +154,9 @@ bool TextureReplacer::LoadIni(std::string *error) {
vfsIsZip_ = false;
dir = new DirectoryReader(basePath_);
} else {
if (!replaceEnabled_ && saveEnabled_) {
WARN_LOG(Log::TexReplacement, "Found zip file even though only saving is enabled! This is weird.");
}
vfsIsZip_ = true;
}

Expand Down Expand Up @@ -187,7 +200,9 @@ bool TextureReplacer::LoadIni(std::string *error) {
delete dir;
return false;
} else {
WARN_LOG(Log::TexReplacement, "Texture pack lacking ini file: %s Proceeding with only hash-named textures in the root.", basePath_.c_str());
if (replaceEnabled_) {
WARN_LOG(Log::TexReplacement, "Texture pack lacking ini file: %s Proceeding with only hash-named textures in the root.", basePath_.c_str());
}
// Do what we can do anyway: Scan for textures and build the map.
std::map<ReplacementCacheKey, std::map<int, std::string>> filenameMap;
ScanForHashNamedFiles(dir, filenameMap);
Expand All @@ -202,7 +217,9 @@ bool TextureReplacer::LoadIni(std::string *error) {
}

auto gr = GetI18NCategory(I18NCat::GRAPHICS);
g_OSD.Show(OSDType::MESSAGE_SUCCESS, gr->T("Texture replacement pack activated"), 3.0f);
if (replaceEnabled_) {
g_OSD.Show(OSDType::MESSAGE_SUCCESS, gr->T("Texture replacement pack activated"), 3.0f);
}

vfs_ = dir;

Expand All @@ -212,10 +229,12 @@ bool TextureReplacer::LoadIni(std::string *error) {
repl.second->vfs_ = vfs_;
}

if (vfsIsZip_) {
INFO_LOG(Log::TexReplacement, "Texture pack activated from '%s'", (basePath_ / ZIP_FILENAME).c_str());
} else {
INFO_LOG(Log::TexReplacement, "Texture pack activated from '%s'", basePath_.c_str());
if (replaceEnabled_) {
if (vfsIsZip_) {
INFO_LOG(Log::TexReplacement, "Texture pack activated from '%s'", (basePath_ / ZIP_FILENAME).c_str());
} else {
INFO_LOG(Log::TexReplacement, "Texture pack activated from '%s'", basePath_.c_str());
}
}

// The ini doesn't have to exist for the texture directory or zip to be valid.
Expand Down

0 comments on commit e959191

Please sign in to comment.