using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
using UnityEditor;
using SevenZip.Compression.LZMA;
using System;
public class UpdateAB : Editor {
static string resPath = "D://Test";
[MenuItem("Create/CreateConfig")]
static void CreateConfig(){
string[] files = Directory.GetFiles(resPath,"*",SearchOption.AllDirectories);
StringBuilder versions = new StringBuilder();
for(int i = 0, len = files.Length; i<len;i++){
string filePath = files[i];
string extension = filePath.Substring(files[i].LastIndexOf("."));
if (extension == ".txt") {
string relativePath = filePath.Replace(resPath, "").Replace("\\", "/");
string md5 = MD5File(filePath);
versions.Append(relativePath).Append(",").Append(md5).Append("\n");
}
}
FileStream stream = new FileStream(resPath + "version.txt", FileMode.Create);
byte[] data = Encoding.UTF8.GetBytes(versions.ToString());
stream.Write (data, 0, data.Length);
stream.Flush();
stream.Close();
}
public static string MD5File(string file){
try {
FileStream fs = new FileStream(file, FileMode.Open);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(fs);
fs.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++) {
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
} catch (System.Exception ex) {
throw new System.Exception("md5file() fail, error:"+ex.Message);
}
}
}
热更新_生成版本比较文本
最新推荐文章于 2023-03-13 08:53:30 发布