| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using Game.Config;
- using System;
- using System.Reflection;
- using System.IO;
- public class CheckHotUpdateRes : EditorWindow
- {
- public class VersionInfoData:GameData<VersionInfoData>
- {
- public string FullName;
- public string MD5;
- public ulong Size;
-
- public VersionInfoData()
- {
- FullName = "";
- MD5 = "";
- Size = 0;
- }
- private static void OnCsvLoad(CsvReader csvReader)
- {
- VersionInfoData.Onload(csvReader);
- }
- }
- [MenuItem("AssetBundle/热更相关")]
- public static void OpenCheckHotUpdateWindow()
- {
- CheckHotUpdateRes window = GetWindow<CheckHotUpdateRes>("热更相关");
- window.maxSize = new Vector2(800, 600);
- window.minSize = new Vector2(600, 400);
-
- window.Show();
- window.Init();
- }
- private string oldPath = "";
- private string newPath = "";
- private CheckResWindowInfo info;
- private List<VersionInfoData> needResList;
- private GameDataFormatInfo downloadFormatInfo;
- public void Init()
- {
- string path = "Assets/Editor/AssetBundle/CheckHotResWindownInfo.asset";
- //Debug.Log();
- info = AssetDatabase.LoadAssetAtPath<CheckResWindowInfo>(path);
- #if UNITY_IOS
- info.VersionFileName = "afivs";
- info.mainfestFileName = "afimft";
- info.NewPath = Application.dataPath + "/StreamingAssets/unityRes";
- //#else
- // versionFileName = "Version";
- // assetsFileName = "mainfest";
- #endif
- needResList = new List<VersionInfoData>();
- }
- private void OnGUI()
- {
- DrowSelectFolder("旧版本文件", "选择文件路径", "选择旧版本资源MD5文件路径", ref info.OldPath);
- DrowSelectFolder("新版本文件", "选择文件路径", "选择新版本资源MD5文件路径", ref info.NewPath);
- DrowSelectFolder("需跟新文件输出路径", "选择文件路径", "选择需跟新文件输出路径", ref info.OutputPath);
- DrawInfo();
- DrawCheckBtn();
-
- }
- private void DrowSelectFolder(string name, string btnName, string savepath, ref string path)
- {
- GUILayout.Box("", GUILayout.Width(790));
- GUILayout.BeginHorizontal();
- GUILayout.Space(10);
- GUILayout.Label(name, GUILayout.Width(120));
- GUILayout.Space(10);
- path = GUILayout.TextField(path, GUILayout.Width(360));
- if (GUILayout.Button(btnName, GUILayout.Width(100)))
- {
- string getstr = EditorUtility.SaveFolderPanel(savepath, path, "");
- if(!string.IsNullOrEmpty(getstr))
- {
- path = getstr;
- }
- }
- GUILayout.Space(10);
- GUILayout.EndHorizontal();
- }
- private void DrawInfo()
- {
- GUILayout.Box("", GUILayout.Width(790));
- GUILayout.BeginHorizontal();
- GUILayout.Space(10);
- GUILayout.Label("版本文件名:", GUILayout.Width(65));
- GUILayout.Space(10);
- info.VersionFileName = GUILayout.TextField(info.VersionFileName, GUILayout.Width(160));
- GUILayout.Space(60);
- GUILayout.Label("版本文件信息文件名:", GUILayout.Width(120));
- GUILayout.Space(10);
- info.mainfestFileName = GUILayout.TextField(info.mainfestFileName, GUILayout.Width(160));
- GUILayout.EndHorizontal();
- GUILayout.Box("", GUILayout.Width(790));
- GUILayout.BeginHorizontal();
- GUILayout.Space(10);
- GUILayout.Label("资源版本:", GUILayout.Width(65));
- GUILayout.Space(10);
- info.ResVersion = GUILayout.TextField(info.ResVersion, GUILayout.Width(160));
- GUILayout.Space(10);
- if (GUILayout.Button("读取版本", GUILayout.Width(100)))
- {
- info.ResVersion = File.ReadAllText($"{info.OldPath}/{info.VersionFileName}");
- }
- GUILayout.Space(10);
- if (GUILayout.Button("版本+1", GUILayout.Width(100)))
- {
- VersionCode lVersionCode = info.ResVersion;
- lVersionCode.patch += 1;
- info.ResVersion = lVersionCode.ToString();
- }
- GUILayout.Space(10);
- GUILayout.EndHorizontal();
- }
- private void DrawCheckBtn()
- {
- GUILayout.Box("", GUILayout.Width(790));
- GUILayout.BeginHorizontal();
- GUILayout.Space(10);
- if (GUILayout.Button("生成MD5资源版本文件"))
- {
- BundleBuilderZ.CreateMD5File(info.ResVersion);
- }
- GUILayout.Space(60);
- if (GUILayout.Button("对比新旧资源"))
- {
- CheckRes();
- }
- GUILayout.EndHorizontal();
- GUILayout.Box("", GUILayout.Width(790));
- if (GUILayout.Button("复制所以资源到输出路径"))
- {
- CopyFiles();
- }
- if (GUILayout.Button("复制图片资源到输出路径"))
- {
- CopyTexture();
- }
- if (GUILayout.Button("复制mainfest资源到输出路径"))
- {
- CopyMainfestFile();
- }
- if (GUILayout.Button("删除mainfest没有的资源"))
- {
- DelateNoFile();
- }
- if (GUILayout.Button("Tolua"))
- {
- AddLuaWrapBenginClassType("");
- }
- GUILayout.Box("", GUILayout.Width(790));
- GUILayout.BeginHorizontal();
- GUILayout.Space(60);
- info.IsIgnore =GUILayout.Toggle(info.IsIgnore, "是否开启忽略某些文件") ;
- GUILayout.EndHorizontal();
- }
- private List<VersionInfoData> SerizlizeResList(byte[] data)
- {
- CsvReader csvReader = new CsvReader(info.mainfestFileName, data);
- if (downloadFormatInfo == null)
- {
- downloadFormatInfo = new GameDataFormatInfo(csvReader.Fields(), csvReader.Types());
- }
- Type type = typeof(VersionInfoData);
- MethodInfo methodInfo = type.GetMethod("OnCsvLoad", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
- methodInfo?.Invoke(null, new object[] { csvReader });
- List<VersionInfoData> resList = VersionInfoData.AllData();
- VersionInfoData.Clear();
- return resList;
- }
- private void CheckRes()
- {
- needResList.Clear();
- oldPath = $"{info.OldPath}/{ info.mainfestFileName}";
- List<VersionInfoData> Oldlist = GetInfoDatas(oldPath);
- newPath = $"{info.NewPath}/{ info.mainfestFileName}";
- List<VersionInfoData> newlist = GetInfoDatas(newPath);
- ChangeResMD5(newlist);
- if (Oldlist != null && newlist != null)
- {
- int size = newlist.Count;
- for (int i = 0; i < size; i++)
- {
- if (newlist[i].FullName == info.mainfestFileName || newlist[i].FullName == info.VersionFileName)
- {
- continue;
- }
- bool isignore = false;
- if (info.IsIgnore)
- {
- string igstr = info.IgnoreFiles.FindFirst(it => it == newlist[i].FullName);
- if (!string.IsNullOrEmpty(igstr))
- {
- isignore = true;
- Debug.Log("======================" + newlist[i].FullName);
- }
- }
- VersionInfoData ores = Oldlist.FindFirst(it=> it.FullName == newlist[i].FullName);
- if (ores != null )
- {
- if (isignore)
- {
- newlist[i].MD5 = ores.MD5;
- newlist[i].Size = ores.Size;
- }
- else if (newlist[i].MD5 != ores.MD5)
- {
- needResList.Add(newlist[i]);
- }
-
-
- }
- else
- {
- needResList.Add(newlist[i]);
- }
- }
- }
- CsvWriter<VersionInfoData> csvWriter = new CsvWriter<VersionInfoData>(newPath, "", newlist, downloadFormatInfo);
- csvWriter.Write();
-
- CopyFile();
- needResList.Clear();
- Debug.Log($"资源检查完成 输出路径 : 【{info.OutputPath}】");
- }
- private void CopyFile()
- {
- if (needResList == null)
- {
- return;
- }
- int size = needResList.Count;
- string datapath = $"{info.NewPath}/";
- for (int i = 0; i < size; i++)
- {
- if (needResList[i].FullName == "Version")
- {
- continue;
- }
- byte[] fdatas = File.ReadAllBytes(datapath + needResList[i].FullName);
- FileHelper.WirteToFile( $"{info.OutputPath}/{needResList[i].FullName}" ,fdatas);
- }
-
- FileHelper.WirteStringToFile($"{info.OutputPath}/{info.VersionFileName}",info.ResVersion);
- byte[] mdatas = File.ReadAllBytes(datapath + info.mainfestFileName);
- FileHelper.WirteToFile($"{info.OutputPath}/{info.mainfestFileName}", mdatas);
- }
- private void CopyMainfestFile()
- {
- newPath = $"{info.NewPath}/{ info.mainfestFileName}";
- List<VersionInfoData> newlist = GetInfoDatas(newPath);
- if (newlist == null)
- {
- return;
- }
- int size = newlist.Count;
- string datapath = $"{info.NewPath}/";
- for (int i = 0; i < size; i++)
- {
- if (newlist[i].FullName == "Version")
- {
- continue;
- }
- byte[] fdatas = File.ReadAllBytes(datapath + newlist[i].FullName);
- FileHelper.WirteToFile($"{info.OutputPath}/{newlist[i].FullName}", fdatas);
- }
- }
- private void DelateNoFile()
- {
- newPath = $"{info.NewPath}/{ info.mainfestFileName}";
- string[] files1 = FileHelper.GetAllFileNmae(info.NewPath, "meta");
- List<VersionInfoData> newlist = GetInfoDatas(newPath);
- int size = files1.Length;
- string datapath = $"{info.NewPath}/";
- for (int i = 0; i < size; i++)
- {
- if (files1[i] == "afivs" || files1[i] == "afimft")
- {
- continue;
- }
- if (newlist.FindFirst(it => it.FullName == files1[i]) == null)
- {
- FileHelper.DeleteFile(datapath + files1[i]);
- }
- }
-
- }
- private List<VersionInfoData> GetInfoDatas(string path)
- {
- List<VersionInfoData> list = null;
- byte[] datas = null;
- if (FileSystem.Exists(path))
- {
- datas = File.ReadAllBytes(path);
- }
- if (datas != null)
- {
- list = SerizlizeResList(datas);
- }
- else
- {
- Debug.LogError($"请选择正确路径;[{path}]文件不存在!!!!");
- }
- return list;
- }
- private void ChangeResMD5(List<VersionInfoData> datas)
- {
- int[] ids = GenerateRandomArray(info.ChangeNum, 1, datas.Count);
- for (int i = 0; i < ids.Length; i++)
- {
- Debug.Log($"{ datas[ids[i]].FullName} 改===={ datas[ids[i]].MD5}=====");
- datas[ids[i]].MD5 = datas[ids[i]].MD5.Substring(0,6);
- //Debug.Log($"{ datas[ids[i]].FullName} 改===={ datas[ids[i]].MD5}=====eeee");
- }
- }
- int[] GenerateRandomArray(int size, int min, int max)
- {
-
- List<int> array = new List<int>(size);
- if (size >= max - min)
- {
- for (int i = min; i < max; i++)
- {
- array.Add(i);
- }
- }
- else
- {
- while (size > 0)
- {
- int a = UnityEngine.Random.Range(min, max);
- if (!array.Contains(a))
- {
- array.Add(a);
- size--;
- }
- }
- }
-
- return array.ToArray();
- }
- private void CopyFiles()
- {
- string[] files1 = FileHelper.GetAllFileNmae(info.NewPath, "meta");
- int size = files1.Length;
- string datapath = $"{info.NewPath}/";
- for (int i = 0; i < size; i++)
- {
- byte[] fdatas = File.ReadAllBytes(datapath + files1[i]);
- FileHelper.WirteToFile($"{info.OutputPath}/{files1[i]}", fdatas);
- }
- }
- private void CopyTexture()
- {
- string datapath = $"{Application.dataPath}/Content/Icons/";
- FileHelper.CopyDir(datapath, info.OutputPath, "meta");
- }
- //L.BeginClass(typeof(SingletonMono<LuaMgr>), typeof(MonoBase), \"SingletonMono_LuaMgr\");
- private void AddLuaWrapBenginClassType(string path)
- {
- if (String.IsNullOrEmpty(path)) return;
- string[] fdatas = File.ReadAllLines(path); //new string[] { "L.BeginClass(typeof(SingletonMono<LuaMgr>), typeof(MonoBase), \"SingletonMono_LuaMgr\");" };//
- int length = fdatas.Length;
- string newstr = "";
- for (int i = 0; i < length; i++)
- {
- if (fdatas[i].Contains("BeginClass"))
- {
- string[] strarr = fdatas[i].Split("typeof(",StringSplitOptions.RemoveEmptyEntries);
- string classname = strarr[1].Substring(0, strarr[1].IndexOf(")"));
- if (classname.Contains("<"))
- {
- string[] names = classname.Split(new char[]{ '<','>'},StringSplitOptions.RemoveEmptyEntries);
- classname = $"{names[0]}_{names[1]}";
- }
- Debug.Log($"Class Name = {classname}");
- string nameStr = $"\"{classname}\"";
- if (!fdatas[i].Contains(nameStr))
- {
- int endid = fdatas[i].LastIndexOf(")");
- newstr = fdatas[i].Substring(0, endid);
- newstr += $", {nameStr});";
- fdatas[i] = newstr;
- Debug.Log($"New String = {newstr}");
- }
-
- break;
- }
- }
- if (newstr != "")
- {
- //Debug.Log("写");
- File.WriteAllLines(path,fdatas);
- }
-
- }
- }
|