mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-08 02:34:06 +02:00
Rewrite config reload & fix some options breaking after import or reset
This commit is contained in:
parent
7601645c12
commit
96469cfca5
@ -165,6 +165,29 @@ public bool Save(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@ -172,7 +195,7 @@ public static UserConfig Load(string file){
|
||||
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){
|
||||
|
@ -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(){
|
||||
@ -201,7 +201,7 @@ public static void ResetConfig(){
|
||||
Reporter.HandleException("Configuration Reset Error", "Could not delete configuration files to reset the options.", true, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ReloadConfig();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user