Skip to content

Commit

Permalink
Update DifferentialCore.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Sep 24, 2024
1 parent c025d33 commit 75dd3e8
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/c#/GeneralUpdate.Differential/DifferentialCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public sealed class DifferentialCore
{
#region Private Members

private static readonly object _lockObj = new object();
private static DifferentialCore _instance;
private static readonly object LockObj = new object();
private static DifferentialCore? _instance;

/// <summary>
/// Differential file format .
Expand All @@ -35,19 +35,14 @@ public sealed class DifferentialCore

#region Public Properties

public static DifferentialCore Instance
public static DifferentialCore? Instance
{
get
{
if (_instance == null)
if (_instance != null) return _instance;
lock (LockObj)
{
lock (_lockObj)
{
if (_instance == null)
{
_instance = new DifferentialCore();
}
}
_instance ??= new DifferentialCore();
}
return _instance;
}
Expand All @@ -64,7 +59,7 @@ public static DifferentialCore Instance
/// <param name="targetPath">Recent version folder path.</param>
/// <param name="patchPath">Store discovered incremental update files in a temporary directory .</param>
/// <returns></returns>
public async Task Clean(string sourcePath, string targetPath, string patchPath = null)
public async Task Clean(string sourcePath, string targetPath, string? patchPath = null)
{
try
{
Expand All @@ -83,8 +78,8 @@ public async Task Clean(string sourcePath, string targetPath, string patchPath =
{
var dirSeparatorChar = Path.DirectorySeparatorChar.ToString().ToCharArray();
var tempPath = file.FullName.Replace(targetPath, "").Replace(Path.GetFileName(file.FullName), "").TrimStart(dirSeparatorChar).TrimEnd(dirSeparatorChar);
var tempPath0 = string.Empty;
var tempDir = string.Empty;
string tempPath0;
string? tempDir;
if (string.IsNullOrEmpty(tempPath))
{
tempDir = patchPath;
Expand Down Expand Up @@ -224,7 +219,7 @@ private async Task DirtyPatch(string appPath, string patchPath)
try
{
if (!File.Exists(appPath) || !File.Exists(patchPath)) return;
var newPath = Path.Combine(Path.GetDirectoryName(appPath), $"{Path.GetRandomFileName()}_{Path.GetFileName(appPath)}");
var newPath = Path.Combine(Path.GetDirectoryName(appPath) ?? string.Empty, $"{Path.GetRandomFileName()}_{Path.GetFileName(appPath)}");
await new BinaryHandler().Dirty(appPath, newPath, patchPath);
}
catch (Exception ex)
Expand Down Expand Up @@ -252,7 +247,7 @@ private Task DirtyUnknow(string appPath, string patchPath)
var targetFileName = file.FullName.Replace(patchPath, "").TrimStart("\\".ToCharArray());
var targetPath = Path.Combine(appPath, targetFileName);
var parentFolder = Directory.GetParent(targetPath);
if (!parentFolder.Exists) parentFolder.Create();
if (parentFolder is { Exists: false }) parentFolder.Create();
File.Copy(file.FullName, Path.Combine(appPath, targetPath), true);
}
if (Directory.Exists(patchPath)) Directory.Delete(patchPath, true);
Expand Down

0 comments on commit 75dd3e8

Please sign in to comment.