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

TextureReplacer: Load ini if available, even if just saving. #19726

Merged
merged 1 commit into from
Dec 13, 2024
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
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
Loading