mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
use PathValidator
for RenameCustomTheme
This commit is contained in:
parent
338ebba191
commit
16d13a2900
@ -194,11 +194,47 @@ namespace Bloxstrap.UI.ViewModels.Settings
|
|||||||
|
|
||||||
private void RenameCustomTheme()
|
private void RenameCustomTheme()
|
||||||
{
|
{
|
||||||
if (SelectedCustomTheme is null)
|
const string LOG_IDENT = "AppearanceViewModel::RenameCustomTheme";
|
||||||
|
|
||||||
|
if (SelectedCustomTheme is null || SelectedCustomTheme == SelectedCustomThemeName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (SelectedCustomTheme == SelectedCustomThemeName)
|
if (string.IsNullOrEmpty(SelectedCustomThemeName))
|
||||||
|
{
|
||||||
|
Frontend.ShowMessageBox(Strings.CustomTheme_Add_Errors_NameEmpty, MessageBoxImage.Error);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var validationResult = PathValidator.IsFileNameValid(SelectedCustomThemeName);
|
||||||
|
|
||||||
|
if (validationResult != PathValidator.ValidationResult.Ok)
|
||||||
|
{
|
||||||
|
switch (validationResult)
|
||||||
|
{
|
||||||
|
case PathValidator.ValidationResult.IllegalCharacter:
|
||||||
|
Frontend.ShowMessageBox(Strings.CustomTheme_Add_Errors_NameIllegalCharacters, MessageBoxImage.Error);
|
||||||
|
break;
|
||||||
|
case PathValidator.ValidationResult.ReservedFileName:
|
||||||
|
Frontend.ShowMessageBox(Strings.CustomTheme_Add_Errors_NameReserved, MessageBoxImage.Error);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
App.Logger.WriteLine(LOG_IDENT, $"Got unhandled PathValidator::ValidationResult {validationResult}");
|
||||||
|
Debug.Assert(false);
|
||||||
|
|
||||||
|
Frontend.ShowMessageBox(Strings.CustomTheme_Add_Errors_Unknown, MessageBoxImage.Error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// better to check for the file instead of the directory so broken themes can be overwritten
|
||||||
|
string path = Path.Combine(Paths.CustomThemes, SelectedCustomThemeName, "Theme.xml");
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
Frontend.ShowMessageBox(Strings.CustomTheme_Add_Errors_NameTaken, MessageBoxImage.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -206,7 +242,7 @@ namespace Bloxstrap.UI.ViewModels.Settings
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
App.Logger.WriteException("AppearanceViewModel::RenameCustomTheme", ex);
|
App.Logger.WriteException(LOG_IDENT, ex);
|
||||||
Frontend.ShowMessageBox(string.Format(Strings.Menu_Appearance_CustomThemes_RenameFailed, SelectedCustomTheme, ex.Message), MessageBoxImage.Error);
|
Frontend.ShowMessageBox(string.Format(Strings.Menu_Appearance_CustomThemes_RenameFailed, SelectedCustomTheme, ex.Message), MessageBoxImage.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user