Skip to content

Commit

Permalink
Backup and restoration function design
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Nov 12, 2023
1 parent 0064bd9 commit 1a88f09
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/dotnet-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
dotnet-quality: 'preview'
- name: Install .NET MAUI
run: dotnet workload install maui
- name: Restore dependencies
Expand Down
10 changes: 8 additions & 2 deletions src/c#/GeneralUpdate.Differential/DifferentialCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public async Task Dirty(string appPath, string patchPath)
public void SetBlocklist(List<string> blackFiles, List<string> blackFileFormats) => Filefilter.SetBlacklist(blackFiles, blackFileFormats);

/// <summary>
///
/// Back up the corresponding local collection of files in the update package.
/// </summary>
/// <param name="appPath"></param>
/// <param name="patchPath"></param>
Expand All @@ -233,11 +233,17 @@ public void Backup(string appPath, string patchPath)
File.Copy(correspondingPathInA, correspondingPathInC, true);
}
}
_backupFiles.Push(files);
_backupFiles?.Push(files);
}

public Stack<List<string>> GetBackups() => _backupFiles;

public void DeleteRootDir()
{
if (Directory.Exists(_backupRootDir))
Directory.Delete(_backupRootDir, true);
}

#endregion Public Methods

#region Private Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
19 changes: 16 additions & 3 deletions src/c#/GeneralUpdate.ProtectService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Newtonsoft.Json;

namespace GeneralUpdate.ProtectService
{
public class Program
Expand All @@ -7,13 +9,24 @@ public static void Main(string[] args)
var builder = WebApplication.CreateSlimBuilder(args);
var app = builder.Build();
var protectApi = app.MapGroup("/protect");
protectApi.MapGet("/{paths}", Restore);
protectApi.MapGet("/{backupJson}/{targetDir}", Restore);
app.Run();
}

internal static string Restore(string paths)
internal static string Restore(string backupJson,string targetDirectory)
{
return paths;
var backupObj = JsonConvert.DeserializeObject<Stack<List<string>>>(backupJson);
while (backupObj?.Count > 0)
{
List<string> currentList = backupObj.Pop();
foreach (var filePath in currentList)
{
string fileName = Path.GetFileName(filePath);
string destFile = Path.Combine(targetDirectory, fileName);
File.Copy(filePath, destFile, true);
}
}
return backupJson;
}
}
}

0 comments on commit 1a88f09

Please sign in to comment.