From 1af89a3993c9337757c4943674944f0d9b7f39e7 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 May 2022 21:03:33 +0800 Subject: [PATCH] Update Update --- .../TEngine/Editor/About/TEngineEditorUtil.cs | 97 +++++++++++++++++++ .../TEngine/Runtime/FileSystem/FileSystem.cs | 29 +++++- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 Assets/TEngine/Editor/About/TEngineEditorUtil.cs diff --git a/Assets/TEngine/Editor/About/TEngineEditorUtil.cs b/Assets/TEngine/Editor/About/TEngineEditorUtil.cs new file mode 100644 index 00000000..85f38182 --- /dev/null +++ b/Assets/TEngine/Editor/About/TEngineEditorUtil.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.IO; +using TEngineCore.Editor; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor +{ + public class TEngineEditorUtil + { + [MenuItem("TEngine/GenMd5List", priority = 1500)] + public static void GenMd5List(string source, string target = "") + { + try + { + //string targetPath = Path.GetDirectoryName(target); + //if (!Directory.Exists(targetPath)) + //{ + // Directory.CreateDirectory(targetPath); + //} + var files = Directory.GetFiles(source, "*", SearchOption.AllDirectories); + var fileList = new List(); + var fileNames = new List(); + var fileSizes = new List(); + foreach (var file in files) + { + if (file.EndsWith(".meta")) + { + continue; + } + fileNames.Add(file.Substring(source.Length + 1)); + fileList.Add(file); + fileSizes.Add(file.Length); + } + + GeneralMd5CheckList(source, files, fileList, fileNames,fileSizes); + //FastZip.compress_File_List(9, target, fileList.ToArray(), null, false, fileNames.ToArray()); + } + catch (Exception e) + { + TLogger.LogError(e.ToString()); + throw; + } + } + + + /// + /// 生成md5文件列表 + /// + /// 目录 + /// 文件列表 + /// 压缩的文件列表 + /// 文件名字列表 + /// /// 文件大小列表 + private static void GeneralMd5CheckList(string source, string[] files, List fileList, List fileNames, List fileSizes) + { + try + { + var md5List = new List(); + foreach (var file in files) + { + if (file.EndsWith(".meta") || file.EndsWith(".DS_Store")) + { + continue; + } + var md5 = LoaderUtilities.GetMd5Hash(file); + var fd5 = new fileMd5 + { + fileName = file.Substring(source.Length + 1).Replace('\\', '/'), + md5 = md5, + //fileSize = //todo + + }; + md5List.Add(fd5); + } + + var configPath = $"{source}/{FileSystem.Md5CheckList}"; + var stream = new FileStream(configPath, FileMode.OpenOrCreate); + + var writer = new StreamWriter(stream); + writer.Write(JsonUtility.ToJson(new Serialization(md5List))); + writer.Flush(); + writer.Dispose(); + writer.Close(); + + fileList.Add(configPath); + fileNames.Add(FileSystem.Md5CheckList); + } + catch (Exception e) + { + TLogger.LogError(e.ToString()); + throw; + } + } + } +} diff --git a/Assets/TEngine/Runtime/FileSystem/FileSystem.cs b/Assets/TEngine/Runtime/FileSystem/FileSystem.cs index 5869fbb0..5804d4db 100644 --- a/Assets/TEngine/Runtime/FileSystem/FileSystem.cs +++ b/Assets/TEngine/Runtime/FileSystem/FileSystem.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.Networking; @@ -16,6 +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"; /// /// 资源更新读取根目录 /// @@ -195,4 +197,29 @@ namespace TEngine return www.downloadHandler.text; } } + + [Serializable] + public struct fileMd5 + { + public string fileName; + public string md5; + public string fileSize; + } + + [Serializable] + public class Serialization + { + [SerializeField] + List _target; + + public List ToList() + { + return _target; + } + + public Serialization(List target) + { + this._target = target; + } + } } \ No newline at end of file