Fix Language Change And Name Collision In Presets

This commit is contained in:
copecone committed 2026-10-14 20:20:06 +09:00
1 parent 27e7327c1e
commit a4dba82729
2 files changed
+31 -7

No files matched your search

+5 -1
View File
@@ -116,7 +116,11 @@ public static class PresetManager
return Path.Combine(root, "UserData", "ADOFAIRenderer", "Presets"); return Path.Combine(root, "UserData", "ADOFAIRenderer", "Presets");
} }
private static string GetSafeFileName(string name) /// <summary>
/// File name (without extension) of the preset file for the given preset name: every character that is invalid
/// in a file name is replaced with '_'. Different preset names can map to the same file name (e.g. "a/b" and "a_b").
/// </summary>
internal static string GetSafeFileName(string name)
{ {
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, '_')); return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, '_'));
} }
+26 -6
View File
@@ -1023,12 +1023,16 @@ internal static class RenderConfigWindow
bool isCurrentPreset = !string.IsNullOrEmpty(_lastLoadedPresetName) && bool isCurrentPreset = !string.IsNullOrEmpty(_lastLoadedPresetName) &&
string.Equals(_lastLoadedPresetName, name, StringComparison.OrdinalIgnoreCase); string.Equals(_lastLoadedPresetName, name, StringComparison.OrdinalIgnoreCase);
var existing = PresetManager.GetPresets().FirstOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)); // A preset with another name can share the file of this name (PresetManager.GetSafeFileName), e.g. "a/b" and "a_b".
var fileName = PresetManager.GetSafeFileName(name);
var existing = PresetManager.GetPresets().FirstOrDefault(p =>
string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase) ||
string.Equals(PresetManager.GetSafeFileName(p.Name), fileName, StringComparison.OrdinalIgnoreCase));
if (existing != null && !isCurrentPreset) if (existing != null && !isCurrentPreset)
{ {
CommonWarningDialogUI.ShowDialog( CommonWarningDialogUI.ShowDialog(
LocalizationManager.Get("ui.render_config.preset_overwrite_title"), LocalizationManager.Get("ui.render_config.preset_overwrite_title"),
LocalizationManager.Get("ui.render_config.preset_overwrite_desc", name), LocalizationManager.Get("ui.render_config.preset_overwrite_desc", existing.Name),
new DialogButton( new DialogButton(
LocalizationManager.Get("ui.render_config.confirm"), LocalizationManager.Get("ui.render_config.confirm"),
() => DoSavePreset(name, config) () => DoSavePreset(name, config)
@@ -1190,12 +1194,28 @@ internal static class RenderConfigWindow
{ {
if (_configWindow == null) return; if (_configWindow == null) return;
if (_presetDropdown != null) if (_presetDropdown == null) return;
// The preset names are not localized, the Custom label is. The list is rebuilt from the preset names
// (which drops the Custom label of the previous language), then the label is decided from the values:
// the Custom label of the new language only when the values differ from the last loaded preset.
var names = PresetManager.GetPresets().Select(p => p.Name).ToList();
if (names.Count == 0)
{ {
var cur = _presetDropdown.Value; _presetDropdown.SetValues(new List<string> { CustomPresetLabel });
var isCustom = cur == "(Modified)" || cur == "(수정됨)" || cur == CustomPresetLabel; _presetDropdown.Set(CustomPresetLabel, false);
ReloadPresetDropdown(isCustom ? CustomPresetLabel : cur); UpdateDeleteButtonState();
return;
} }
_presetDropdown.SetValues(names);
var loadedName = _lastLoadedPresetName;
if (!string.IsNullOrEmpty(loadedName) && names.Contains(loadedName))
{
_presetDropdown.Set(loadedName, false);
}
UpdatePresetLabel(UiConfig);
} }
private static string GetVersionText() private static string GetVersionText()