Skip to content

Commit

Permalink
Merge pull request #39 from GeneralLibrary/dev
Browse files Browse the repository at this point in the history
feature:Encapsulate file processing classes
  • Loading branch information
JusterZhu authored Jan 16, 2024
2 parents 484ee88 + 9ee8220 commit fea370a
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/c#/GeneralUpdate.Client/GeneralUpdate.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationManifest></ApplicationManifest>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/c#/GeneralUpdate.Client/MySample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,25 @@ private bool IsDriverFile(string filePath) =>

#endregion


#region 测试WillMessage

public void TestWillMessage()
{
var path1 = "D:\\packet\\source";
var path2 = "D:\\packet\\target";
var hash = "";
var hash = "28d10f1fc2a23dd1afe0af40d132b25c72ea56005963f653c27889f03d381c8d";

for (int i = 0; i < 1; i++)
{
var version = "1.0.0" + i;
var version = "1.0.0." + i;
WillMessageManager.Instance.Backup(path1,path2, version, hash, 1);
}
WillMessageManager.Instance.Builder();
WillMessageManager.Instance.GetWillMessage();
var obj = WillMessageManager.Instance.GetWillMessage();
WillMessageManager.Instance.Check();
WillMessageManager.Instance.Restore();
WillMessageManager.Instance.Clear();
//WillMessageManager.Instance.Clear();
}

#endregion
Expand Down
30 changes: 16 additions & 14 deletions src/c#/GeneralUpdate.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ internal class Program
{
static void Main(string[] args)
{
Task.Run(async() =>
{
//415eed05eb310f480d1e4d15516fa00e484ddb9f416908b217f17b782ded2030
//var zip1 = @"D:\github_project\WpfClient\WebApi\UpdateFiles\WpfClient_1_24.1.5.1218.zip";
//94bd3d806d39cd1b8813298ec0637c7f377658e766845a06cc50917306cb4ad9
//var zip2 = @"D:\github_project\WpfClient\WebApi\UpdateFiles\WpfClient_1_24.1.5.1224.zip";
MySample sample = new MySample();
sample.TestWillMessage();
//Task.Run(async() =>
//{
// //415eed05eb310f480d1e4d15516fa00e484ddb9f416908b217f17b782ded2030
// //var zip1 = @"D:\github_project\WpfClient\WebApi\UpdateFiles\WpfClient_1_24.1.5.1218.zip";
// //94bd3d806d39cd1b8813298ec0637c7f377658e766845a06cc50917306cb4ad9
// //var zip2 = @"D:\github_project\WpfClient\WebApi\UpdateFiles\WpfClient_1_24.1.5.1224.zip";

//var hashAlgorithm = new Sha256HashAlgorithm();
//var hashSha256 = hashAlgorithm.ComputeHash(zip1);
//var hashSha2561 = hashAlgorithm.ComputeHash(zip2);
// //var hashAlgorithm = new Sha256HashAlgorithm();
// //var hashSha256 = hashAlgorithm.ComputeHash(zip1);
// //var hashSha2561 = hashAlgorithm.ComputeHash(zip2);

MySample sample = new MySample();
//await sample.TestDifferentialClean();
//await sample.TestDifferentialDirty();
await sample.Upgrade();
});
// MySample sample = new MySample();
// //await sample.TestDifferentialClean();
// //await sample.TestDifferentialDirty();
// await sample.Upgrade();
//});
Console.Read();
}
}
Expand Down
148 changes: 148 additions & 0 deletions src/c#/GeneralUpdate.Core/ContentProvider/FileNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;

namespace GeneralUpdate.Differential.ContentProvider
{
public class FileNode
{
#region Public Properties

public long Id { get; set; }

public string Name { get; set; }

public string FullName { get; set; }

public string Path { get; set; }

public string Hash { get; set; }

public FileNode Left { get; set; }

public FileNode Right { get; set; }

public int LeftType { get; set; }

public int RightType { get; set; }

public string RelativePath { get; set; }

#endregion Public Properties

#region Constructors

public FileNode()
{ }

public FileNode(int id)
{
Id = id;
}

#endregion Constructors

#region Public Methods

public void Add(FileNode node)
{
if (node == null) return;

if (node.Id < Id)
{
if (Left == null)
{
Left = node;
}
else
{
Left.Add(node);
}
}
else
{
if (Right == null)
{
Right = node;
}
else
{
Right.Add(node);
}
}
}

public void InfixOrder()
{
if (Left != null)
{
Left.InfixOrder();
}
if (Right != null)
{
Right.InfixOrder();
}
}

public FileNode Search(long id)
{
if (id == Id)
{
return this;
}
else if (id < Id)
{
if (Left == null) return null;
return Left.Search(id);
}
else
{
if (Right == null) return null;
return Right.Search(id);
}
}

/// <summary>
/// Find the parent node of the node that you want to delete.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FileNode SearchParent(long id)
{
if (Left != null && Left.Id == id || Right != null && Right.Id == id)
{
return this;
}
else
{
if (id < Id && Left != null)
{
return Left.SearchParent(id);
}
else if (id >= Id && Right != null)
{
return Right.SearchParent(id);
}
else
{
return null;
}
}
}

/// <summary>
/// Compare tree nodes equally by Hash and file names.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj == null) return false;
var tempNode = obj as FileNode;
if (tempNode == null) throw new ArgumentException(nameof(tempNode));
return string.Equals(Hash, tempNode.Hash,StringComparison.OrdinalIgnoreCase) && string.Equals(Name, tempNode.Name,StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode() => base.GetHashCode();

#endregion Public Methods
}
}
Loading

0 comments on commit fea370a

Please sign in to comment.