关闭

热更新_生成版本比较文本

标签: 热更新
21人阅读 评论(0) 收藏 举报
分类:
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);
		}
	}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22次
    • 积分:10
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档