1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-30 05:34:06 +02:00

Rewrite config reload & fix some options breaking after import or reset

This commit is contained in:
chylex 2017-08-30 12:53:10 +02:00
parent 7601645c12
commit 96469cfca5
2 changed files with 27 additions and 4 deletions

View File

@ -166,13 +166,36 @@ public bool Save(){
}
}
public bool Reload(){
try{
LoadInternal(false);
return true;
}catch(FileNotFoundException){
try{
Serializer.Write(file, new UserConfig(file));
LoadInternal(false);
return true;
}catch(Exception e){
Program.Reporter.HandleException("Configuration Error", "Could not regenerate configuration file.", true, e);
return false;
}
}catch(Exception e){
Program.Reporter.HandleException("Configuration Error", "Could not reload configuration file.", true, e);
return false;
}
}
private void LoadInternal(bool backup){
Serializer.Read(backup ? GetBackupFile(file) : file, this);
}
public static UserConfig Load(string file){
Exception firstException = null;
for(int attempt = 0; attempt < 2; attempt++){
try{
UserConfig config = new UserConfig(file);
Serializer.Read(attempt == 0 ? file : GetBackupFile(file), config);
config.LoadInternal(attempt > 0);
return config;
}catch(FileNotFoundException){
}catch(DirectoryNotFoundException){

View File

@ -114,7 +114,7 @@ private static void Main(){
}
}
ReloadConfig();
UserConfig = UserConfig.Load(UserConfigFilePath);
SystemConfig = SystemConfig.Load(SystemConfigFilePath);
if (Arguments.HasFlag(Arguments.ArgImportCookies)){
@ -190,7 +190,7 @@ private static string GetDataStoragePath(){
}
public static void ReloadConfig(){
UserConfig = UserConfig.Load(UserConfigFilePath);
UserConfig.Reload();
}
public static void ResetConfig(){