private static void GetDependencies(string bundleName, string bundlePath, ref bool result) { Dictionary <string, FileMD5Item> DicFileMD5 = new Dictionary <string, FileMD5Item>(); Dictionary <string, Dictionary <string, FileMD5Item> > DicFileInfo = new Dictionary <string, Dictionary <string, FileMD5Item> >(); //Debug.Log("bundlePath : "+bundlePath); string[] dependencies = AssetDatabase.GetDependencies(new string[] { bundlePath }); foreach (string path in dependencies) { // Debug.Log("path : "+path); // if(path == bundlePath){ // continue; // } string newPath = Application.dataPath.Replace("Assets", "") + path; //Debug.Log("newPath : "+ newPath); string MD5Hash = EditorTools.GetMD5Hash(newPath); //Debug.Log("MD5Hash:" + MD5Hash); FileStream file = new FileStream(newPath, FileMode.Open, FileAccess.Read, FileShare.Read); string strSize = file.Length.ToString(); FileMD5Item item = new FileMD5Item(path, MD5Hash, strSize); DicFileMD5.Add(path, item); } Debug.Log("bundleName : " + bundleName); DicFileInfo.Add(bundleName, DicFileMD5); result = FileChange(bundleName, DicFileInfo); if (result) { SaveToFile(DicFileInfo); } }
private static void SaveToFile(Dictionary <string, Dictionary <string, FileMD5Item> > DicFileInfo) { string savePath = EditorTools.mExportVersionFolderLocationFloder; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string curPath = EditorTools.mExportVersionFolderLocationFloder + "/" + EditorTools.mExportVersionFolderName; PrefabInfo oldInfo = IO.LoadFromFile <PrefabInfo>(curPath); if (oldInfo != null) { foreach (PrefabCol col in oldInfo.Files) { Dictionary <string, FileMD5Item> DicFileMD5 = new Dictionary <string, FileMD5Item>(); foreach (FileMD5Item item in col.FileInfo) { if (!DicFileMD5.ContainsKey(item.FileName)) { FileMD5Item data = new FileMD5Item(item.FileName, item.MD5, item.Size); DicFileMD5.Add(item.FileName, data); } } if (!DicFileInfo.ContainsKey(col.FileName)) { DicFileInfo.Add(col.FileName, DicFileMD5); } else { DicFileInfo[col.FileName] = DicFileMD5; } } } if (File.Exists(curPath)) { File.Delete(curPath); } PrefabInfo prefabinfo = new PrefabInfo(); foreach (KeyValuePair <string, Dictionary <string, FileMD5Item> > info in DicFileInfo) { PrefabCol prefabcol = new PrefabCol(info.Key); foreach (KeyValuePair <string, FileMD5Item> pair in info.Value) { FileMD5Item item = new FileMD5Item(pair.Value.FileName, pair.Value.MD5, pair.Value.Size); prefabcol.addItem(item); } prefabcol.End(); prefabinfo.addItem(prefabcol); } prefabinfo.End(); IO.SaveToFile(prefabinfo, curPath); }
private static void GetDependencies(string bundleName, List <string> list, ref bool result) { Dictionary <string, FileMD5Item> DicFileMD5 = new Dictionary <string, FileMD5Item>(); Dictionary <string, Dictionary <string, FileMD5Item> > DicFileInfo = new Dictionary <string, Dictionary <string, FileMD5Item> >(); foreach (string path in list) { //Debug.Log("path:" + path); string MD5Hash = EditorTools.GetMD5Hash(path); //Debug.Log("MD5Hash:" + MD5Hash); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); string strSize = file.Length.ToString(); FileMD5Item item = new FileMD5Item(path, MD5Hash, strSize); DicFileMD5.Add(path, item); } DicFileInfo.Add(bundleName, DicFileMD5); result = FileChange(bundleName, DicFileInfo); if (result) { SaveToFile(DicFileInfo); } }
public static bool FileChange(string bundleName, Dictionary <string, Dictionary <string, FileMD5Item> > DicFileInfo) { string curPath = EditorTools.mExportVersionFolderLocationFloder + "/" + EditorTools.mExportVersionFolderName; bool result = false; if (File.Exists(curPath)) { PrefabInfo oldInfo = IO.LoadFromFile <PrefabInfo>(curPath); if (oldInfo != null) { Dictionary <string, Dictionary <string, FileMD5Item> > FileInfos = new Dictionary <string, Dictionary <string, FileMD5Item> >(); foreach (PrefabCol col in oldInfo.Files) { Dictionary <string, FileMD5Item> DicFileMD5 = new Dictionary <string, FileMD5Item>(); foreach (FileMD5Item item in col.FileInfo) { DicFileMD5.Add(item.FileName, item); } FileInfos.Add(col.FileName, DicFileMD5); } if (!FileInfos.ContainsKey(bundleName)) { result = true; } else { foreach (PrefabCol col in oldInfo.Files) { //Debug.Log("col.FileName : "+col.FileName); Dictionary <string, FileMD5Item> dic = null; if (DicFileInfo.TryGetValue(col.FileName, out dic)) { if (dic.Count != col.FileInfo.Length) { Debug.Log(dic.Count + "/" + col.FileInfo.Length); Debug.Log("文件依赖的文件个数有变动!!"); result = true; } else { foreach (FileMD5Item item in col.FileInfo) { FileMD5Item data = null; if (dic.TryGetValue(item.FileName, out data)) { if (item.MD5 != data.MD5) { Debug.Log(item.FileName); Debug.Log("文件依赖的文件有变动!!!"); result = true; } } } } } } } } else { Debug.Log("333333!!!"); result = true; } } else { Debug.Log("4444444!!!"); result = true; } return(result); }