mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
获取AB的Md5
获取AB的Md5
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using TEngineCore.Editor;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,7 +11,7 @@ namespace TEngine.Editor
|
||||
public class TEngineEditorUtil
|
||||
{
|
||||
[MenuItem("TEngine/GenMd5List", priority = 1500)]
|
||||
public static void GenMd5List(string source, string target = "")
|
||||
public static void GenMd5List()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -19,10 +20,10 @@ namespace TEngine.Editor
|
||||
//{
|
||||
// Directory.CreateDirectory(targetPath);
|
||||
//}
|
||||
string source = FileSystem.ResourceRootInStreamAsset;
|
||||
var files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
|
||||
var fileList = new List<string>();
|
||||
var fileNames = new List<string>();
|
||||
var fileSizes = new List<long>();
|
||||
var fileInfos = new Dictionary<string,long>();
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.EndsWith(".meta"))
|
||||
@@ -30,11 +31,10 @@ namespace TEngine.Editor
|
||||
continue;
|
||||
}
|
||||
fileNames.Add(file.Substring(source.Length + 1));
|
||||
fileList.Add(file);
|
||||
fileSizes.Add(file.Length);
|
||||
fileInfos.Add(file, GetFileSize(file));
|
||||
}
|
||||
|
||||
GeneralMd5CheckList(source, files, fileList, fileNames,fileSizes);
|
||||
GeneralMd5CheckList(source, files, fileInfos, fileNames);
|
||||
//FastZip.compress_File_List(9, target, fileList.ToArray(), null, false, fileNames.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -44,6 +44,20 @@ namespace TEngine.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件大小
|
||||
/// </summary>
|
||||
/// <param name="sFullName"></param>
|
||||
/// <returns></returns>
|
||||
public static long GetFileSize(string sFullName)
|
||||
{
|
||||
long lSize = 0;
|
||||
if (File.Exists(sFullName))
|
||||
{
|
||||
lSize = new FileInfo(sFullName).Length;
|
||||
}
|
||||
return lSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成md5文件列表
|
||||
@@ -52,30 +66,31 @@ namespace TEngine.Editor
|
||||
/// <param name="files">文件列表</param>
|
||||
/// <param name="fileList">压缩的文件列表</param>
|
||||
/// <param name="fileNames">文件名字列表</param>
|
||||
/// /// <param name="fileSizes">文件大小列表</param>
|
||||
private static void GeneralMd5CheckList(string source, string[] files, List<string> fileList, List<string> fileNames, List<long> fileSizes)
|
||||
private static void GeneralMd5CheckList(string source, string[] files, Dictionary<string, long> fileInfos, List<string> fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
var md5List = new List<fileMd5>();
|
||||
foreach (var file in files)
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
var file = fileInfo.Key;
|
||||
|
||||
if (file.EndsWith(".meta") || file.EndsWith(".DS_Store"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var md5 = LoaderUtilities.GetMd5Hash(file);
|
||||
var md5 = GetMd5Hash(file);
|
||||
var fd5 = new fileMd5
|
||||
{
|
||||
fileName = file.Substring(source.Length + 1).Replace('\\', '/'),
|
||||
md5 = md5,
|
||||
//fileSize = //todo
|
||||
fileSize = fileInfo.Value,
|
||||
|
||||
};
|
||||
md5List.Add(fd5);
|
||||
}
|
||||
|
||||
var configPath = $"{source}/{FileSystem.Md5CheckList}";
|
||||
var configPath = $"{source}/{FileSystem.Md5List}";
|
||||
var stream = new FileStream(configPath, FileMode.OpenOrCreate);
|
||||
|
||||
var writer = new StreamWriter(stream);
|
||||
@@ -84,14 +99,49 @@ namespace TEngine.Editor
|
||||
writer.Dispose();
|
||||
writer.Close();
|
||||
|
||||
fileList.Add(configPath);
|
||||
fileNames.Add(FileSystem.Md5CheckList);
|
||||
//fileList.Add(configPath);
|
||||
fileNames.Add(FileSystem.Md5List);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TLogger.LogError(e.ToString());
|
||||
throw;
|
||||
}
|
||||
TLogger.LogInfoSuccessd("Gen Md5 List Success");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的md5码
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetMd5Hash(string fileName)
|
||||
{
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
TLogger.LogWarning($"not exit file,path:{fileName}");
|
||||
return string.Empty;
|
||||
}
|
||||
try
|
||||
{
|
||||
using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] retVal = md5.ComputeHash(file);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < retVal.Length; i++)
|
||||
{
|
||||
sb.Append(retVal[i].ToString("x2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TLogger.LogError("GetMD5Hash() fail,error:" + ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Assets/TEngine/Editor/About/TEngineEditorUtil.cs.meta
Normal file
11
Assets/TEngine/Editor/About/TEngineEditorUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73167965a9ecb894388e4fcbe7fa797d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -17,7 +17,7 @@ namespace TEngine
|
||||
public const string BuildPath = "Build";
|
||||
public const string AssetBundleBuildPath = BuildPath + "/AssetBundles";
|
||||
private const string AssetBundleTargetPath = "{0}/AssetBundles";
|
||||
public const string Md5CheckList = "Md5CheckList.json";
|
||||
public const string Md5List = "Md5List.json";
|
||||
/// <summary>
|
||||
/// 资源更新读取根目录
|
||||
/// </summary>
|
||||
@@ -203,7 +203,7 @@ namespace TEngine
|
||||
{
|
||||
public string fileName;
|
||||
public string md5;
|
||||
public string fileSize;
|
||||
public long fileSize;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
Reference in New Issue
Block a user