mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-01 17:34:10 +02:00
Implement system config export/import/reset (without UI)
This commit is contained in:
parent
be08fd4445
commit
6df68629f7
Core/Other/Settings
@ -16,7 +16,7 @@ public ExportFileFlags Flags{
|
|||||||
|
|
||||||
set{
|
set{
|
||||||
// this will call events and SetFlag, which also updates the UI
|
// this will call events and SetFlag, which also updates the UI
|
||||||
cbConfig.Checked = value.HasFlag(ExportFileFlags.Config);
|
cbConfig.Checked = value.HasFlag(ExportFileFlags.UserConfig);
|
||||||
cbSession.Checked = value.HasFlag(ExportFileFlags.Session);
|
cbSession.Checked = value.HasFlag(ExportFileFlags.Session);
|
||||||
cbPluginData.Checked = value.HasFlag(ExportFileFlags.PluginData);
|
cbPluginData.Checked = value.HasFlag(ExportFileFlags.PluginData);
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ private void radioDecision_CheckedChanged(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cbConfig_CheckedChanged(object sender, EventArgs e){
|
private void cbConfig_CheckedChanged(object sender, EventArgs e){
|
||||||
SetFlag(ExportFileFlags.Config, cbConfig.Checked);
|
SetFlag(ExportFileFlags.UserConfig, cbConfig.Checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cbSession_CheckedChanged(object sender, EventArgs e){
|
private void cbSession_CheckedChanged(object sender, EventArgs e){
|
||||||
@ -63,7 +63,7 @@ private void btnContinue_Click(object sender, EventArgs e){
|
|||||||
currentState = State.Reset;
|
currentState = State.Reset;
|
||||||
|
|
||||||
Text = "Restore Defaults";
|
Text = "Restore Defaults";
|
||||||
Flags = ExportFileFlags.Config;
|
Flags = ExportFileFlags.UserConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import
|
// Import
|
||||||
@ -108,10 +108,18 @@ private void btnContinue_Click(object sender, EventArgs e){
|
|||||||
|
|
||||||
case State.Reset:
|
case State.Reset:
|
||||||
if (FormMessage.Warning("Reset TweetDuck Options", "This will reset the selected items. Are you sure you want to proceed?", FormMessage.Yes, FormMessage.No)){
|
if (FormMessage.Warning("Reset TweetDuck Options", "This will reset the selected items. Are you sure you want to proceed?", FormMessage.Yes, FormMessage.No)){
|
||||||
if (Flags.HasFlag(ExportFileFlags.Config)){
|
if (Flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||||
Program.ResetConfig();
|
Program.ResetConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||||
|
try{
|
||||||
|
File.Delete(Program.SystemConfigFilePath);
|
||||||
|
}catch(Exception ex){
|
||||||
|
Program.Reporter.HandleException("System Config Reset Error", "Could not delete system config.", true, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Flags.HasFlag(ExportFileFlags.PluginData)){
|
if (Flags.HasFlag(ExportFileFlags.PluginData)){
|
||||||
try{
|
try{
|
||||||
File.Delete(Program.PluginConfigFilePath);
|
File.Delete(Program.PluginConfigFilePath);
|
||||||
@ -124,6 +132,9 @@ private void btnContinue_Click(object sender, EventArgs e){
|
|||||||
if (Flags.HasFlag(ExportFileFlags.Session)){
|
if (Flags.HasFlag(ExportFileFlags.Session)){
|
||||||
Program.Restart(Arguments.ArgDeleteCookies);
|
Program.Restart(Arguments.ArgDeleteCookies);
|
||||||
}
|
}
|
||||||
|
else if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||||
|
Program.Restart();
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
ShouldReloadBrowser = true;
|
ShouldReloadBrowser = true;
|
||||||
}
|
}
|
||||||
@ -139,7 +150,12 @@ private void btnContinue_Click(object sender, EventArgs e){
|
|||||||
Program.UserConfig.Reload();
|
Program.UserConfig.Reload();
|
||||||
|
|
||||||
if (importManager.IsRestarting){
|
if (importManager.IsRestarting){
|
||||||
Program.Restart(Arguments.ArgImportCookies);
|
if (Flags.HasFlag(ExportFileFlags.Session)){
|
||||||
|
Program.Restart(Arguments.ArgImportCookies);
|
||||||
|
}
|
||||||
|
else if (Flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||||
|
Program.Restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ShouldReloadBrowser = true;
|
ShouldReloadBrowser = true;
|
||||||
@ -171,6 +187,8 @@ private void btnContinue_Click(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
Program.UserConfig.Save();
|
Program.UserConfig.Save();
|
||||||
|
Program.SystemConfig.Save();
|
||||||
|
|
||||||
ExportManager manager = new ExportManager(file, plugins);
|
ExportManager manager = new ExportManager(file, plugins);
|
||||||
|
|
||||||
if (!manager.Export(Flags)){
|
if (!manager.Export(Flags)){
|
||||||
|
@ -4,9 +4,10 @@ namespace TweetDuck.Core.Other.Settings.Export{
|
|||||||
[Flags]
|
[Flags]
|
||||||
enum ExportFileFlags{
|
enum ExportFileFlags{
|
||||||
None = 0,
|
None = 0,
|
||||||
Config = 1,
|
UserConfig = 1,
|
||||||
Session = 2,
|
SystemConfig = 2,
|
||||||
PluginData = 4,
|
Session = 4,
|
||||||
All = Config|Session|PluginData
|
PluginData = 8,
|
||||||
|
All = UserConfig|SystemConfig|Session|PluginData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,14 @@ public ExportManager(string file, PluginManager plugins){
|
|||||||
public bool Export(ExportFileFlags flags){
|
public bool Export(ExportFileFlags flags){
|
||||||
try{
|
try{
|
||||||
using(CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))){
|
using(CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))){
|
||||||
if (flags.HasFlag(ExportFileFlags.Config)){
|
if (flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||||
stream.WriteFile("config", Program.UserConfigFilePath);
|
stream.WriteFile("config", Program.UserConfigFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||||
|
stream.WriteFile("system", Program.SystemConfigFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
||||||
stream.WriteFile("plugin.config", Program.PluginConfigFilePath);
|
stream.WriteFile("plugin.config", Program.PluginConfigFilePath);
|
||||||
|
|
||||||
@ -67,7 +71,11 @@ public ExportFileFlags GetImportFlags(){
|
|||||||
while((key = stream.SkipFile()) != null){
|
while((key = stream.SkipFile()) != null){
|
||||||
switch(key){
|
switch(key){
|
||||||
case "config":
|
case "config":
|
||||||
flags |= ExportFileFlags.Config;
|
flags |= ExportFileFlags.UserConfig;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "system":
|
||||||
|
flags |= ExportFileFlags.SystemConfig;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "plugin.config":
|
case "plugin.config":
|
||||||
@ -99,12 +107,20 @@ public bool Import(ExportFileFlags flags){
|
|||||||
while((entry = stream.ReadFile()) != null){
|
while((entry = stream.ReadFile()) != null){
|
||||||
switch(entry.KeyName){
|
switch(entry.KeyName){
|
||||||
case "config":
|
case "config":
|
||||||
if (flags.HasFlag(ExportFileFlags.Config)){
|
if (flags.HasFlag(ExportFileFlags.UserConfig)){
|
||||||
entry.WriteToFile(Program.UserConfigFilePath);
|
entry.WriteToFile(Program.UserConfigFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "system":
|
||||||
|
if (flags.HasFlag(ExportFileFlags.SystemConfig)){
|
||||||
|
entry.WriteToFile(Program.SystemConfigFilePath);
|
||||||
|
IsRestarting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case "plugin.config":
|
case "plugin.config":
|
||||||
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
if (flags.HasFlag(ExportFileFlags.PluginData)){
|
||||||
entry.WriteToFile(Program.PluginConfigFilePath);
|
entry.WriteToFile(Program.PluginConfigFilePath);
|
||||||
|
Loading…
Reference in New Issue
Block a user