public static void SaveHistory(this ABVersion rVersion, string rOutPath) { if (rVersion == null) { return; } string rHistoryDateStr = string.Format("History/{0}", DateTime.Now.ToString("yyyyMMdd_HHmmss")); string rVersionBinPath = UtilTool.PathCombine(rOutPath, rHistoryDateStr, ABVersion.ABVersion_File_Bin); string rDirPath = Path.GetDirectoryName(rVersionBinPath); if (!Directory.Exists(rDirPath)) { Directory.CreateDirectory(rDirPath); } using (FileStream fs = new FileStream(rVersionBinPath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { rVersion.Serialize(bw); } } AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
public static ABVersion CreateVersion(string rOutPath, ABVersion rOldVersion, AssetBundleManifest rNewABManifest) { ABVersion rVersion = new ABVersion(); rVersion.Entries = new Dict <string, ABVersionEntry>(); string[] rAllAssetbundles = rNewABManifest.GetAllAssetBundles(); for (int i = 0; i < rAllAssetbundles.Length; i++) { ABVersionEntry rAVEntry = new ABVersionEntry(); rAVEntry.Name = rAllAssetbundles[i]; var rOldEntry = rOldVersion != null?rOldVersion.GetEntry(rAllAssetbundles[i]) : null; string rOldMD5 = rOldEntry != null ? rOldEntry.MD5 : string.Empty; string rNewMD5 = GetMD5InManifest(rNewABManifest, rAllAssetbundles[i]); rAVEntry.MD5 = rNewMD5; if (!string.IsNullOrEmpty(rOldMD5) && !rOldMD5.Equals(rNewMD5)) { rAVEntry.Version = GetVersionInABVersion(rOldVersion, rAVEntry.Name) + 1; } else { rAVEntry.Version = GetVersionInABVersion(rOldVersion, rAVEntry.Name); } rAVEntry.Size = GetABSizeInManifest(rOutPath, rAllAssetbundles[i]); rAVEntry.Dependencies = rNewABManifest.GetDirectDependencies(rAllAssetbundles[i]); rVersion.Entries.Add(rAllAssetbundles[i], rAVEntry); } return(rVersion); }
public static void SaveInEditor(this ABVersion rVersion, string rOutPath) { if (rVersion == null) { return; } string rVersionBinPath = Path.Combine(rOutPath, ABVersion.ABVersion_File_Bin); string rVersionJsonPath = Path.Combine(rOutPath, ABVersion.ABVersion_File_Json); string rVersionMD5Path = Path.Combine(rOutPath, ABVersion.ABVersion_File_MD5); using (FileStream fs = new FileStream(rVersionBinPath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { rVersion.Serialize(bw); } } JsonNode rJsonNode = JsonParser.ToJsonNode(rVersion); File.WriteAllText(rVersionJsonPath, rJsonNode.ToString()); string rVersionMD5 = UtilTool.GetMD5(rVersionBinPath).ToHEXString(); File.WriteAllText(rVersionMD5Path, rVersionMD5); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
//解析ABVersion配置表 private Dictionary <string, ABVersion> ResolveABContent(string contentResolve) { Dictionary <string, ABVersion> resultDict = new Dictionary <string, ABVersion>(); string[] str = contentResolve.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int toLoadNum = str.Length; for (int k = 1; k < str.Length; k++) { string line = str[k]; if (line != "") { string[] content = line.Split(','); ABVersion ab = new ABVersion { AbName = content[0], Version = int.Parse(content[1]), MD5 = content[2].Trim() }; resultDict.Add(content[0], ab); } } return(resultDict); }
public static int GetVersionInABVersion(ABVersion rVersion, string rABName) { if (rVersion == null) { return(1); } ABVersionEntry rAVEntry = rVersion.GetEntry(rABName); if (rAVEntry == null) { return(1); } return(rAVEntry.Version); }
public static void SaveIncrement(this ABVersion rVersion, string rABPath, string rTargetPath) { if (rVersion == null) { return; } // 保存增量版本文件 string rTargetVersionBinPath = UtilTool.PathCombine(rTargetPath, ABVersion.ABVersion_File_Bin); using (FileStream fs = new FileStream(rTargetVersionBinPath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { rVersion.Serialize(bw); } } // 复制增量AB包 foreach (var rVersionPair in rVersion.Entries) { var rAVEntry = rVersionPair.Value; string rSrcABPath = UtilTool.PathCombine(rABPath, rAVEntry.Name); string rDistABPath = UtilTool.PathCombine(rTargetPath, rAVEntry.Name); string rDistDir = Path.GetDirectoryName(rDistABPath); if (!Directory.Exists(rDistDir)) { Directory.CreateDirectory(rDistDir); } File.Copy(rSrcABPath, rDistABPath, true); } // 复制MD5文件 string rSrcMD5Path = UtilTool.PathCombine(rABPath, ABVersion.ABVersion_File_MD5); string rDistMD5Path = UtilTool.PathCombine(rTargetPath, ABVersion.ABVersion_File_MD5); string rDistMD5Dir = Path.GetDirectoryName(rDistMD5Path); if (!Directory.Exists(rDistMD5Dir)) { Directory.CreateDirectory(rDistMD5Dir); } File.Copy(rSrcMD5Path, rDistMD5Path, true); }
/// <summary> /// 加载本地文件,没有就创建完成。有则比对同名文件的MD5,不一样则version+1 /// </summary> /// <param name="csvListToBeRestored"></param> private static void MatchCSVTotalFile(List <ABVersion> csvListToBeRestored) { string listpath = Application.dataPath + "/StreamingAssets/csvList.txt"; FileStream fs; StreamWriter listwriter; if (DocumentAccessor.IsExists(AssetPathManager.Instance.GetStreamAssetDataPath("csvList.txt", false))) { //本地主配置文件获取 string localContent = null; string localFilePath = AssetPathManager.Instance.GetStreamAssetDataPath("csvList.txt"); DocumentAccessor.LoadAsset(localFilePath, (e) => { localContent = e; }); List <ABVersion> localABVersionsDic = ResolveABContent(localContent); fs = new FileStream(listpath, FileMode.Create); listwriter = new StreamWriter(fs, new UTF8Encoding(false)); listwriter.WriteLine(_csvListTitle); for (int i = 0; i < csvListToBeRestored.Count; i++) { ABVersion toSave = csvListToBeRestored[i]; for (int k = 0; k < localABVersionsDic.Count; k++) { ABVersion local = localABVersionsDic[k]; if (local.AbName == toSave.AbName) { toSave.Version = local.MD5 != toSave.MD5 && local.Version != 0 ? local.Version + 1 : local.Version; } } listwriter.WriteLine(string.Format(_csvContentValue, toSave.AbName, toSave.Version, toSave.MD5)); } } else { fs = new FileStream(listpath, FileMode.Create); listwriter = new StreamWriter(fs, new UTF8Encoding(false)); listwriter.WriteLine(_csvListTitle); for (int i = 0; i < csvListToBeRestored.Count; i++) { listwriter.WriteLine(string.Format(_csvContentValue, csvListToBeRestored[i].AbName, csvListToBeRestored[i].Version, csvListToBeRestored[i].MD5)); } } listwriter.Close(); listwriter.Dispose(); fs.Dispose(); }
public void Initialize(string rOutPath) { mEntries = new Dict <string, Entry>(); string rHistoryPath = UtilTool.PathCombine(rOutPath, "History"); DirectoryInfo rHistoryDirInfo = new DirectoryInfo(rHistoryPath); if (!rHistoryDirInfo.Exists) { return; } ABVersion rCurVersion = ABVersionEditor.Load(rOutPath); var rSubDirs = rHistoryDirInfo.GetDirectories(); for (int i = 0; i < rSubDirs.Length; i++) { Entry rEntry = new Entry(); rEntry.Path = UtilTool.PathCombine(rHistoryPath, rSubDirs[i].Name, ABVersion.ABVersion_File_Bin); rEntry.Time = rSubDirs[i].Name; rEntry.IncVer = new ABVersion(); rEntry.IncVer.Entries = new Dict <string, ABVersionEntry>(); ABVersion rHistoryVersion = ABVersionEditor.Load(rSubDirs[i].FullName); // 比较两个版本 foreach (var rPair in rCurVersion.Entries) { var rAVEntry = rPair.Value; var rOldEntry = rHistoryVersion.GetEntry(rAVEntry.Name); if (rOldEntry == null) // 说明是新增的 { rEntry.IncVer.Entries.Add(rAVEntry.Name, rAVEntry); } else { if (rOldEntry.Version != rAVEntry.Version) // 版本不一致 { rEntry.IncVer.Entries.Add(rAVEntry.Name, rAVEntry); } } } mEntries.Add(rEntry.Time, rEntry); } }
public static ABVersion Load(string rOutPath) { string rVersionPath = Path.Combine(rOutPath, ABVersion.ABVersion_File_Bin); if (!File.Exists(rVersionPath)) { return(null); } ABVersion rABVersion = new ABVersion(); using (FileStream fs = new FileStream(rVersionPath, FileMode.Open)) { using (BinaryReader br = new BinaryReader(fs)) { rABVersion.Deserialize(br); } } return(rABVersion); }