Parcourir la source

更新魔盒更新逻辑

felix il y a 1 an
Parent
commit
18a27ce944

+ 1 - 1
Vinno.FIS.Sonopost.Upgrade/App.xaml.cs

@@ -40,7 +40,7 @@ namespace Vinno.FIS.Sonopost.Upgrade
                 catch (Exception ex)
                 {
                     File.AppendAllText("UpgradeLog.txt", ex.ToString());
-                    upgrade.RestartSonopostTask();
+                    upgrade.InstallSonopostTask();
                 }
                 finally
                 {

+ 14 - 29
Vinno.FIS.Sonopost.Upgrade/UpgradeOperator.cs

@@ -29,12 +29,12 @@ namespace Vinno.FIS.Sonopost.Upgrade
                 return false;
             }
             StopSonopostService();
-            StopSonopostTask();
+            UninstallSonopostTask();
             StopSonopostKeeper();
             StopSonopost();
             StopTRTCClient();
             RunUpgrade();
-            RestartSonopostTask();
+            InstallSonopostTask();
             return true;
         }
 
@@ -53,41 +53,26 @@ namespace Vinno.FIS.Sonopost.Upgrade
             ServiceHelper.Start();
         }
 
-        public void RestartSonopostTask()
+        public void InstallSonopostTask()
         {
             TaskSchedulerHelper.Install();
         }
 
         private void RunUpgrade()
         {
-            RenameUpgradeProcess();
             MoveFiles(_upgradeFilePath, _targetPath);
             DeleteEmptyFolder(_targetPath);
             DeleteDirectory(_upgradeFilePath);
             DeleteAllFiles();
         }
 
-        private void RenameUpgradeProcess()
-        {
-            var upgradeFile = Path.Combine(_upgradeFilePath, "Vinno.FIS.Sonopost.Upgrade.exe");
-            var newUpgradeFile = Path.Combine(_upgradeFilePath, "Vinno.FIS.Sonopost.NewUpgrade.exe");
-            if (File.Exists(newUpgradeFile))
-            {
-                File.Delete(newUpgradeFile);
-            }
-            if (File.Exists(upgradeFile))
-            {
-                File.Move(upgradeFile, newUpgradeFile);
-            }
-        }
-
         private void StopSonopostService()
         {
             ServiceHelper.Stop();
             ServiceHelper.UnInstall();
         }
 
-        private void StopSonopostTask()
+        private void UninstallSonopostTask()
         {
             TaskSchedulerHelper.UnInstall();
         }
@@ -116,22 +101,22 @@ namespace Vinno.FIS.Sonopost.Upgrade
             var files = Directory.GetFiles(srcFolder);
             foreach (var file in files)
             {
-                if (!file.EndsWith("Vinno.FIS.Sonopost.Upgrade.exe"))
+                try
                 {
-                    try
-                    {
-                        File.Copy(file, file.Replace(srcFolder, targetFolder), true);
-                    }
-                    catch (Exception ex)
-                    {
-                        File.AppendAllText("UpgradeLog.txt", ex.ToString());
-                    }
+                    File.Copy(file, file.Replace(srcFolder, targetFolder), true);
+                }
+                catch (Exception ex)
+                {
+                    File.AppendAllText("UpgradeLog.txt", ex.ToString());
                 }
             }
             var dirs = Directory.GetDirectories(srcFolder);
             foreach (var dir in dirs)
             {
-                MoveFiles(dir, dir.Replace(srcFolder, targetFolder));
+                if (!dir.EndsWith("SonopostUpgrade"))
+                {
+                    MoveFiles(dir, dir.Replace(srcFolder, targetFolder));
+                }
             }
         }
 

+ 2 - 2
Vinno.FIS.Sonopost.Upgrade/Vinno.FIS.Sonopost.Upgrade.csproj

@@ -23,7 +23,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>..\Bin\WindowsSonopost\</OutputPath>
+    <OutputPath>..\Bin\WindowsSonopost\SonopostUpgrade\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -33,7 +33,7 @@
     <PlatformTarget>x64</PlatformTarget>
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>..\Bin\WindowsSonopost\</OutputPath>
+    <OutputPath>..\Bin\WindowsSonopost\SonopostUpgrade\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>

+ 1 - 23
Vinno.FIS.Sonopost/App.xaml.cs

@@ -52,7 +52,7 @@ namespace Vinno.FIS.Sonopost
                 AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
                 this.DispatcherUnhandledException += OnDispatcherUnhandledException;
                 SystemEvents.SessionEnded += OnSessionEnded;
-                ClearUp();
+                ProcessHelper.FinishProcessByName(SonopostConstants.UpgradeAppName);
                 AppManager.Instance.Initialize();
                 Init();
                 _webHost = new WebHost();
@@ -87,28 +87,6 @@ namespace Vinno.FIS.Sonopost
             }
         }
 
-        private void ClearUp()
-        {
-            var path = AppDomain.CurrentDomain.BaseDirectory;
-            string newUpgrade = Path.Combine(path, SonopostConstants.NewUpgradeAppFileName);
-            string oldUpgrade = Path.Combine(path, SonopostConstants.UpgradeAppFileName);
-            if (File.Exists(newUpgrade))
-            {
-                if (File.Exists(oldUpgrade))
-                {
-                    var result = ProcessHelper.FinishProcessByName(SonopostConstants.UpgradeAppName);
-                    if (result == false)
-                    {
-                        Logger.WriteLineError("Finish Upgrade Process Error!");
-                        return;
-                    }
-                    Thread.Sleep(100);
-                    FileHelper.DeleteFile(oldUpgrade);
-                }
-                File.Move(newUpgrade, oldUpgrade);
-            }
-        }
-
         private void OnCurrentNetworkChanged(object sender, NetworkInterfaceInfo e)
         {
             if (e != null)

+ 1 - 1
Vinno.FIS.Sonopost/Common/SonopostConstants.cs

@@ -10,9 +10,9 @@
         public const string UserDefinedSettingsFolder = "UserDefined";
         public const string UserDefinedSettingFileName = "Setting.json";
 
+        public const string UpgradeFolderName = "SonopostUpgrade";
         public const string UpgradeAppName = "Vinno.FIS.Sonopost.Upgrade";
         public const string UpgradeAppFileName = "Vinno.FIS.Sonopost.Upgrade.exe";
-        public const string NewUpgradeAppFileName = "Vinno.FIS.Sonopost.NewUpgrade.exe";
 
         public const string FlyinsonoServerName = "FlyinsonoServer";
 

+ 5 - 11
Vinno.FIS.Sonopost/Helpers/UpgradeHelper.cs

@@ -18,17 +18,11 @@ namespace Vinno.FIS.Sonopost.Helpers
                 Logger.WriteLineError($"Can not find upgrade zip file!");
                 return;
             }
-
-            var upgradeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.UpgradeAppFileName);
-            if (!File.Exists(upgradeFile))
-            {
-                var newUpgradeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.NewUpgradeAppFileName);
-                if (File.Exists(newUpgradeFile))
-                {
-                    File.Move(newUpgradeFile, upgradeFile);
-                }
-            }
+            ProcessHelper.FinishProcessByName(SonopostConstants.UpgradeAppName);
+            var upgradeFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.UpgradeFolderName);
+            var upgradeFile = Path.Combine(upgradeFolderPath, SonopostConstants.UpgradeAppFileName);
             var upgradePath = Path.Combine(SonopostConstants.DataFolder, "UpgradeTemp");
+            var newUpgradeFolderPath = Path.Combine(upgradePath, " SonopostConstants.UpgradeFolderName");
             CompressHelper.DeCompressAll(upgradeZipFilePath, upgradePath);
             if (!Directory.Exists(upgradePath) || Directory.GetFiles(upgradePath).Length == 0)
             {
@@ -42,7 +36,7 @@ namespace Vinno.FIS.Sonopost.Helpers
             {
                 FileHelper.DeleteFile(settingFile);
             }
-
+            DirectoryHelper.CopyDirectory(newUpgradeFolderPath, upgradeFolderPath);
             int processId = ProcessHelper.StartProcess(upgradeFile, $"{upgradePath} {AppDomain.CurrentDomain.BaseDirectory} {deleteAllFiles}");
             if (processId == 0)
             {