Skip to content

Commit

Permalink
[opt][editor]:优化补丁资源计算,将基于MD5的变化资源判断修改为基于写入时间
Browse files Browse the repository at this point in the history
  • Loading branch information
CatImmortal committed Jun 19, 2023
1 parent 020bd28 commit 187dce0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace CatAsset.Editor
{
/// <summary>
/// 移除非补丁资源的依赖,以防止资源内存冗余
/// 移除补丁资源依赖列表中的非补丁资源,以防止资源内存冗余
/// </summary>
public class RemoveNonPatchDependency : IBuildTask
{
Expand Down
56 changes: 28 additions & 28 deletions Assets/CatAsset/Editor/Misc/AssetCacheManifest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using CatAsset.Runtime;

namespace CatAsset.Editor
Expand All @@ -17,12 +18,33 @@ public class AssetCacheManifest
public struct AssetCacheInfo : IEquatable<AssetCacheInfo>
{
public string Name;
public string MD5;
public string MetaMD5;
public long LastWriteTime;
public long MetaLastWriteTime;

public static AssetCacheInfo Create(string assetName)
{
AssetCacheInfo assetCacheInfo = new AssetCacheInfo
{
Name = assetName,
LastWriteTime = File.GetLastWriteTime(assetName).Ticks,
MetaLastWriteTime = File.GetLastWriteTime($"{assetName}.meta").Ticks,
};
return assetCacheInfo;
}

public static bool operator ==(AssetCacheInfo a,AssetCacheInfo b)
{
return Equals(a, b);
}

public static bool operator !=(AssetCacheInfo a,AssetCacheInfo b)
{
return !(a == b);
}

public bool Equals(AssetCacheInfo other)
{
return Name == other.Name && MD5 == other.MD5 && MetaMD5 == other.MetaMD5;
return Name == other.Name && LastWriteTime == other.LastWriteTime && MetaLastWriteTime == other.MetaLastWriteTime;
}

public override bool Equals(object obj)
Expand All @@ -35,33 +57,11 @@ public override int GetHashCode()
unchecked
{
var hashCode = (Name != null ? Name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (MD5 != null ? MD5.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (MetaMD5 != null ? MetaMD5.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ LastWriteTime.GetHashCode();
hashCode = (hashCode * 397) ^ MetaLastWriteTime.GetHashCode();
return hashCode;
}
}

public static bool operator ==(AssetCacheInfo a,AssetCacheInfo b)
{
return Equals(a, b);
}

public static bool operator !=(AssetCacheInfo a,AssetCacheInfo b)
{
return !(a == b);
}

public static AssetCacheInfo Create(string assetName)
{
AssetCacheInfo assetCacheInfo = new AssetCacheInfo
{
Name = assetName,
MD5 = RuntimeUtil.GetFileMD5(assetName),
MetaMD5 = RuntimeUtil.GetFileMD5($"{assetName}.meta")
};
return assetCacheInfo;
}

}

/// <summary>
Expand All @@ -79,7 +79,7 @@ public Dictionary<string, AssetCacheInfo> GetCacheDict()
{
result.Add(assetCache.Name,assetCache);
}

return result;
}

Expand Down

0 comments on commit 187dce0

Please sign in to comment.