mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-20 09:32:54 +01:00
Handle incorrect user settings case.
Ask to the user if he want to delete its invalid user settings.
This commit is contained in:
1 parent
db86b6c372
commit
6166bd60d5
4 files changed
+47
-6
No files matched your search
@@ -43,6 +43,11 @@ namespace FileConverter
|
||||
public Application()
|
||||
{
|
||||
this.ConvertionJobs = this.conversionJobs.AsReadOnly();
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
this.Initialize();
|
||||
|
||||
@@ -98,6 +103,12 @@ namespace FileConverter
|
||||
// Load settigns.
|
||||
Debug.Log("Load settings...");
|
||||
this.Settings = Settings.Load();
|
||||
if (this.Settings == null)
|
||||
{
|
||||
Diagnostics.Debug.LogError("The application will now shutdown. If you want to fix the problem yourself please edit or delete the file: C:\\Users\\UserName\\AppData\\Local\\FileConverter\\Settings.user.xml.");
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve arguments.
|
||||
Debug.Log("Retrieve arguments...");
|
||||
@@ -120,8 +131,8 @@ namespace FileConverter
|
||||
args[6] = @"D:\Test\Track03.mp3";
|
||||
args[7] = @"D:\Test\Track04.mp3";
|
||||
|
||||
System.Array.Resize(ref args, 2);
|
||||
args[1] = "--settings";
|
||||
//System.Array.Resize(ref args, 2);
|
||||
//args[1] = "--settings";
|
||||
|
||||
//System.Array.Resize(ref args, 5);
|
||||
//args[1] = "--conversion-preset";
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace FileConverter
|
||||
|
||||
public partial class Settings : IXmlSerializable
|
||||
{
|
||||
public const int Version = 1;
|
||||
|
||||
private double settingsWindowHeight = 640;
|
||||
private double settingsWindowWidth = 800;
|
||||
private bool exitApplicationWhenConversionsFinished = true;
|
||||
@@ -19,7 +21,7 @@ namespace FileConverter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = 0;
|
||||
} = Version;
|
||||
|
||||
[XmlIgnore]
|
||||
public ObservableCollection<ConversionPreset> ConversionPresets
|
||||
|
||||
@@ -101,7 +101,28 @@ namespace FileConverter
|
||||
string userFilePath = Settings.GetUserSettingsFilePath();
|
||||
if (File.Exists(userFilePath))
|
||||
{
|
||||
XmlHelpers.LoadFromFile<Settings>("Settings", userFilePath, ref settings);
|
||||
try
|
||||
{
|
||||
XmlHelpers.LoadFromFile<Settings>("Settings", userFilePath, ref settings);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MessageBoxResult messageBoxResult = MessageBox.Show("Can't load file converter user settings. Do you want to fall back to default settings ?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||
if (messageBoxResult == MessageBoxResult.Yes)
|
||||
{
|
||||
System.IO.File.Delete(userFilePath);
|
||||
return Settings.Load();
|
||||
}
|
||||
else if (messageBoxResult == MessageBoxResult.No)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.SerializationVersion != Version)
|
||||
{
|
||||
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", settings.SerializationVersion, Version);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,7 +130,14 @@ namespace FileConverter
|
||||
string defaultFilePath = Settings.GetDefaultSettingsFilePath();
|
||||
if (File.Exists(defaultFilePath))
|
||||
{
|
||||
XmlHelpers.LoadFromFile<Settings>("Settings", defaultFilePath, ref settings);
|
||||
try
|
||||
{
|
||||
XmlHelpers.LoadFromFile<Settings>("Settings", defaultFilePath, ref settings);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Diagnostics.Debug.LogError("Fail to load file converter default settings. {0}", exception.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace FileConverter
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
Diagnostics.Debug.LogError("Fail to load asset of type '" + typeof(T) + "'. The following exception was raised:\n " + exception.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
IXmlSerializable xmlSerializableObject = deserializedObject as IXmlSerializable;
|
||||
|
||||
Reference in new issue
Block a user