mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Update
Update
This commit is contained in:
97
Assets/TEngine/Editor/About/TEngineEditorUtil.cs
Normal file
97
Assets/TEngine/Editor/About/TEngineEditorUtil.cs
Normal file
@@ -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<string>();
|
||||
var fileNames = new List<string>();
|
||||
var fileSizes = new List<long>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成md5文件列表
|
||||
/// </summary>
|
||||
/// <param name="source">目录</param>
|
||||
/// <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)
|
||||
{
|
||||
try
|
||||
{
|
||||
var md5List = new List<fileMd5>();
|
||||
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<fileMd5>(md5List)));
|
||||
writer.Flush();
|
||||
writer.Dispose();
|
||||
writer.Close();
|
||||
|
||||
fileList.Add(configPath);
|
||||
fileNames.Add(FileSystem.Md5CheckList);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TLogger.LogError(e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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";
|
||||
/// <summary>
|
||||
/// 资源更新读取根目录
|
||||
/// </summary>
|
||||
@@ -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<T>
|
||||
{
|
||||
[SerializeField]
|
||||
List<T> _target;
|
||||
|
||||
public List<T> ToList()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public Serialization(List<T> target)
|
||||
{
|
||||
this._target = target;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user