diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs
index 9dcae336..a3cece2c 100644
--- a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs
+++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs
@@ -6,7 +6,9 @@
using GeneralUpdate.Core.Pipelines.Context;
using GeneralUpdate.Core.Pipelines.Middleware;
using GeneralUpdate.Core.Utils;
+using GeneralUpdate.Differential;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -86,11 +88,11 @@ public override bool StartApp(string appName, int appType)
{
case AppType.ClientApp:
Environment.SetEnvironmentVariable("ProcessBase64", Packet.ProcessBase64, EnvironmentVariableTarget.Machine);
- WaitForProcessToStart(path, TimeSpan.FromSeconds(60));
+ WaitForProcessToStart(path, TimeSpan.FromSeconds(60), Restore);
break;
case AppType.UpgradeApp:
- WaitForProcessToStart(path, TimeSpan.FromSeconds(60));
+ WaitForProcessToStart(path, TimeSpan.FromSeconds(60), Restore);
break;
}
return true;
@@ -137,24 +139,26 @@ private bool Clear()
///
/// Process objects to monitor
/// The maximum interval for waiting for the process to start (The default value is 60 seconds).
- /// If the startup fails, the result is notified to the protection service.
- private void WaitForProcessToStart(string applicationPath, TimeSpan timeout, Action callbackAction = null)
+ ///
+ private void WaitForProcessToStart(string applicationPath, TimeSpan timeout, Action callbackAction = null)
{
using (Process process = Process.Start(applicationPath))
{
var startTime = DateTime.UtcNow;
while (DateTime.UtcNow - startTime < timeout)
{
+ Thread.Sleep(2 * 1000);
if (!process.HasExited)
{
- callbackAction?.Invoke(applicationPath, Packet.TempPath);
+ callbackAction?.Invoke(applicationPath);
return;
}
- Thread.Sleep(2 * 1000);
}
}
}
+ private void Restore(string targetDir) => DifferentialCore.Instance.Restore(targetDir);
+
#endregion Private Methods
}
}
\ No newline at end of file
diff --git a/src/c#/GeneralUpdate.Differential/DifferentialCore.cs b/src/c#/GeneralUpdate.Differential/DifferentialCore.cs
index 043db5ca..1e8b8a51 100644
--- a/src/c#/GeneralUpdate.Differential/DifferentialCore.cs
+++ b/src/c#/GeneralUpdate.Differential/DifferentialCore.cs
@@ -236,8 +236,9 @@ public void Backup(string appPath, string patchPath)
_backupFiles?.Push(files);
}
- public Stack> GetBackups() => _backupFiles;
-
+ ///
+ /// Delete the backup file directory and recursively delete all backup content.
+ ///
public void DeleteRootDir()
{
if (string.IsNullOrWhiteSpace(_backupRootDir)) return;
@@ -246,6 +247,33 @@ public void DeleteRootDir()
Directory.Delete(_backupRootDir, true);
}
+ ///
+ /// Restore the backup files of each version to the original directory.
+ ///
+ ///
+ ///
+ public bool Restore(string targetDirectory)
+ {
+ try
+ {
+ while (_backupFiles?.Count > 0)
+ {
+ List currentList = _backupFiles.Pop();
+ foreach (var filePath in currentList)
+ {
+ string fileName = Path.GetFileName(filePath);
+ string destFile = Path.Combine(targetDirectory, fileName);
+ File.Copy(filePath, destFile, true);
+ }
+ }
+ return true;
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ }
+
#endregion Public Methods
#region Private Methods
@@ -302,6 +330,9 @@ private Task DirtyUnknow(string appPath, string patchPath)
private void OnCompressProgress(object sender, BaseCompressProgressEventArgs e) => _compressProgressCallback(sender, e);
+ ///
+ /// Create a root directory for backup files
+ ///
private void CreateRootDirInTemp()
{
if (!string.IsNullOrEmpty(_backupRootDir)) return;
@@ -311,6 +342,10 @@ private void CreateRootDirInTemp()
if (!Directory.Exists(_backupRootDir)) Directory.CreateDirectory(_backupRootDir);
}
+ ///
+ /// Create a subfolder based on the root directory of the backup file for version-by-version backup.
+ ///
+ ///
private string CreateSubfolderInRootDir()
{
string subFolderName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
diff --git a/src/c#/GeneralUpdate.sln b/src/c#/GeneralUpdate.sln
index f54fd648..600dfae3 100644
--- a/src/c#/GeneralUpdate.sln
+++ b/src/c#/GeneralUpdate.sln
@@ -43,10 +43,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.Maui.OSS", "G
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.OSSClient", "GeneralUpdate.OSSClient\GeneralUpdate.OSSClient.csproj", "{2877DCA1-7EA6-42E9-A1C2-399B51E24893}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service", "service", "{0315E141-AF1C-426D-A032-8D3A20502E3F}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.ProtectService", "GeneralUpdate.ProtectService\GeneralUpdate.ProtectService.csproj", "{ABEE5D49-CC5A-4366-BD50-E7625905D481}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -127,10 +123,6 @@ Global
{2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.Build.0 = Release|Any CPU
{2877DCA1-7EA6-42E9-A1C2-399B51E24893}.Release|Any CPU.Deploy.0 = Release|Any CPU
- {ABEE5D49-CC5A-4366-BD50-E7625905D481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {ABEE5D49-CC5A-4366-BD50-E7625905D481}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {ABEE5D49-CC5A-4366-BD50-E7625905D481}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {ABEE5D49-CC5A-4366-BD50-E7625905D481}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -153,7 +145,6 @@ Global
{9A28F525-124A-4019-8F09-BC48030E0E70} = {50B6BB53-63A9-414B-9BB0-79A69EEF6785}
{C4BDA544-2A6E-442C-B7D0-32CD7A996933} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF}
{2877DCA1-7EA6-42E9-A1C2-399B51E24893} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7}
- {ABEE5D49-CC5A-4366-BD50-E7625905D481} = {0315E141-AF1C-426D-A032-8D3A20502E3F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A7B2D0AD-E000-4749-BAC0-FF21B9872805}