Browse Source

魔盒启动失败时会删除自定义配置文件

felix 1 year ago
parent
commit
d319fd3f80

+ 21 - 7
Vinno.FIS.Sonopost/App.xaml.cs

@@ -55,16 +55,25 @@ namespace Vinno.FIS.Sonopost
                 ProcessHelper.FinishProcessByName(SonopostConstants.UpgradeAppName);
                 AppManager.Instance.Initialize();
                 Init();
-                _webHost = new WebHost();
-                _webHost.Start();
+                CreateWebHost();
             }
             catch (Exception ex)
             {
                 Logger.WriteLineError($"Sonopost Start Up Error:{ex}");
+                SonopostUserDefinedSettings.Instance.Reset();
                 Process.GetCurrentProcess().Kill();
             }
         }
 
+        private void CreateWebHost()
+        {
+            if (_webHost == null)
+            {
+                _webHost = new WebHost();
+                _webHost.Start();
+            }
+        }
+
         private void Init()
         {
             AppManager.Instance.GetManager<ILoginManager>().Init();
@@ -239,11 +248,7 @@ namespace Vinno.FIS.Sonopost
                         _networkManager.CurrentWifiLevelChanged -= OnCurrentWifiLevelChanged;
                         AppDomain.CurrentDomain.UnhandledException -= CurrentDomainUnhandledException;
                         SystemEvents.SessionEnded -= OnSessionEnded;
-                        if (_webHost != null)
-                        {
-                            _webHost.Dispose();
-                            _webHost = null;
-                        }
+                        DisposeWebHost();
                         AppManager.Instance.DisposeAllManagers();
                     }
                     catch (Exception ex)
@@ -258,5 +263,14 @@ namespace Vinno.FIS.Sonopost
                 Logger.WriteLineError($"Sonopost Dispose Error:{ex}");
             }
         }
+
+        private void DisposeWebHost()
+        {
+            if (_webHost != null)
+            {
+                _webHost.Dispose();
+                _webHost = null;
+            }
+        }
     }
 }

+ 1 - 7
Vinno.FIS.Sonopost/Features/Config/SonopostUserDefinedSettingInfo.cs

@@ -40,7 +40,6 @@ namespace Vinno.FIS.Sonopost.Features.Config
             if (!LoadConfig())
             {
                 InitInstance();
-                Instance.Save();
             }
         }
 
@@ -111,7 +110,6 @@ namespace Vinno.FIS.Sonopost.Features.Config
         internal void Reset()
         {
             InitInstance();
-            Instance.Delete();
         }
 
         private static void InitInstance()
@@ -162,11 +160,7 @@ namespace Vinno.FIS.Sonopost.Features.Config
                 IsFirstLogin = true,
                 Version = SonopostConstants.CurrentSonopostUserDefinedSettingVersion,
             };
-        }
-
-        private void Delete()
-        {
-            FileHelper.DeleteFile(_userDefinedFilePath);
+            Instance.Save();
         }
 
         /// <summary>