public List <IDownloadItem> GetReloadHotfixFiles(HotfixIndexFile indexFile) { float time = Time.realtimeSinceStartup; List <IDownloadItem> list = new List <IDownloadItem>(); foreach (var item in indexFile.FileItems) { try { FileInfo fileInfo = new FileInfo(AssetLoader.ExternalHotfixPath + "/" + item.Path); if (fileInfo.Exists == false || item.Size != fileInfo.Length || MD5Util.Get(fileInfo.FullName) != item.Md5) { list.Add(item); } } catch (Exception e) { list.Add(item); } } Debug.LogWarning("GetReloadHotfixFiles time:" + (Time.realtimeSinceStartup - time)); return(list); }
/// <summary> /// 按照HotfixConfig的配置去删除热更文件 /// </summary> public void DeleteHotfixFile() { string str = FileUtil.ReadFileText(HotfixRecordPath); if (string.IsNullOrEmpty(str)) { return; } string[] arr = str.Split('_'); string hotfixConfigPath = AssetLoader.ExternalHotfixPath + "/HotfixConfig_v" + arr[0] + "_h" + arr[1] + ".zip"; FileInfo fileInfo = new FileInfo(hotfixConfigPath); if (fileInfo.Exists == false) { return; } DirectoryInfo directoryInfo = new DirectoryInfo(AssetLoader.ExternalHotfixPath); if (directoryInfo.Exists == false) { return; } byte[] bytes = FileUtil.ReadBytesFile(hotfixConfigPath); if (bytes == null) { return; } HotfixIndexFile indexFile = HotfixIndexFile.Deserialize(bytes); foreach (var item in indexFile.FileItems) { File.Delete(AssetLoader.ExternalHotfixPath + "/" + item.Path); } fileInfo.Delete(); File.Delete(HotfixRecordPath); }
public static HotfixIndexFile Deserialize(byte[] bytes) { MemoryStream stream = new MemoryStream(bytes); BinaryReader binaryReader = new BinaryReader(stream); string header = Encoding.UTF8.GetString(binaryReader.ReadBytes(4)); if (header.Contains(FileHeader) == false) { Debug.LogError("HotfixIndexFile: File Format Error"); return(null); } int fileVersion = binaryReader.ReadInt32(); HotfixFileFormat format = (HotfixFileFormat)binaryReader.ReadInt32(); BinaryFormatter b = new BinaryFormatter(); HotfixIndexFile clz = b.Deserialize(stream) as HotfixIndexFile; stream.Close(); binaryReader.Close(); return(clz); }