private static void UnzipBackendStep(Dictionary <string, ResPack> dict, string fileKey, Action <Dictionary <string, ResPack> > onUnzipComplete) { ResPack resPack = dict[fileKey]; string filePath = AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath; Loom.RunAsync(() => { try { ZipUtil.UnzipThread(filePath, AssetLoader.ExternalHotfixPath + "/" + resPack.releasePath); } catch (IOException e) { Debug.LogException(e); } Loom.QueueOnMainThread(() => { File.Delete(filePath); FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend + "_" + fileKey); fm.UpdateRecord(AppConfig.Instance.version + ""); onUnzipComplete?.Invoke(dict); }); }); }
/// <summary> /// 删除热更文件 /// </summary> /// <param name="onDelete"></param> public void DeleteHotfixDir(Action <bool> onDelete) { FileMark fileMark = new FileMark(Application.persistentDataPath, FileChecker.DeleteHotfixMark); fileMark.Delete(); DirectoryInfo dir = new DirectoryInfo(AssetLoader.ExternalHotfixPath); if (dir.Exists) { try { dir.Delete(true); onDelete?.Invoke(true); } catch (Exception e) { onDelete?.Invoke(false); fileMark.UpdateRecord("true"); BuglyAgent.ReportException("DeleteHotfixDir", e.Message, e.StackTrace); PopupManager.ShowAlertWindow(I18NManager.Get("Update_RepairFail"), null, I18NManager.Get("Update_RepairCloseGame")).WindowActionCallback = evt => { Application.Quit(); }; } } else { onDelete?.Invoke(true); } }
private static void OnCompleteFullLoading(DownloadItem downloadItem) { Loom.RunAsync(() => { if (downloadItem.FileType == FileType.Zip) { try { ZipUtil.UnzipThread(downloadItem.LocalPath, AssetLoader.ExternalHotfixPath + "/" + _releasePath); } catch (IOException e) { Debug.LogException(e); } } Loom.QueueOnMainThread(() => { File.Delete(downloadItem.LocalPath); if (_tag == ResPath.AllResources) { //下载完所有资源标记下载 PlayerPrefs.SetInt(UpdateController.LastVersionKey, AppConfig.Instance.version); MarkDownloadAll(); } else if (_tag == ResPath.AppStart) { FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.AppStart); fm.UpdateRecord(AppConfig.Instance.version + ""); } else if (_tag == ResPath.Extend) { FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend); fm.UpdateRecord(AppConfig.Instance.version + ""); } if (timerHandler != null) { ClientTimer.Instance.RemoveCountDown(timerHandler); } _onComplete?.Invoke(_tag); }); }); if (downloadItem.FileType == FileType.Zip) { timerHandler = ClientTimer.Instance.AddCountDown("Upzip", Int64.MaxValue, 0.1f, val => { int progress = (int)((float)ZipUtil.CurrentSize / ZipUtil.TotalSize * 100); LoadingProgress.Instance.SetPercent(progress, true); }, null); } }
public static CacheVo CheckAppStartCache() { Stopwatch sw = Stopwatch.StartNew(); CacheVo vo = new CacheVo(); FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.AppStart); if (fm.IsMatch) { return(vo); } ResIndex resIndex = GetIndexFile(ResPath.AppStart); if (resIndex == null) { return(vo); } ResPack resPack = resIndex.packageDict[ResPath.AppStart]; _releasePath = resPack.releasePath; foreach (var resItem in resPack.items) { FileInfo fileInfo = new FileInfo(AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + resItem.Path); if (fileInfo.Exists == false || fileInfo.Length != resItem.Size) { vo.needDownload = true; break; } } vo.sizeList = new List <long>() { resPack.packageSize }; Debug.LogError("CheckAppStartCache 时间:" + sw.ElapsedMilliseconds); return(vo); }
public static CacheVo CheckExtendCache() { Stopwatch sw = Stopwatch.StartNew(); CacheVo vo = new CacheVo(); ResIndex resIndex = GetIndexFile(ResPath.Extend); if (resIndex == null) { return(vo); } if (IsDownloadMarked()) { return(vo); } if (resIndex.packageDict.ContainsKey(ResPath.Extend) == false) { FlowText.ShowMessage(I18NManager.Get("Download_IndexNoExist")); return(vo); } ResPack resPack = resIndex.packageDict[ResPath.Extend]; _releasePath = resPack.releasePath; FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend); if (fm.IsMatch == false) { vo.needDownload = true; } vo.sizeList = new List <long>() { resPack.packageSize }; Debug.LogError("CheckExtend 时间:" + sw.ElapsedMilliseconds); return(vo); }
/// <summary> /// 获取到需要后台下载的包cachevo /// </summary> /// <returns></returns> public static long CheckCurBackEndCacheSize() { Stopwatch sw = Stopwatch.StartNew(); ResIndex resIndex = GetIndexFile(ResPath.Backend); if (resIndex == null) { return(0); } if (resIndex.packageDict.Count == 0) { Debug.LogError("Download_IndexNoExist"); return(0); } long allsize = 0; foreach (var v in resIndex.packageDict) { //要遍历几遍! CacheVo vo = new CacheVo(); ResPack resPack = v.Value; _releasePath = resPack.releasePath; vo.sizeList = new List <long>() { resPack.packageSize }; FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend + "_" + v.Key); if (fm.IsMatch == false) { allsize += resPack.packageSize; } } Debug.Log("CheckBackEnd===Size 时间:" + sw.ElapsedMilliseconds); return(allsize); }
/// <summary> /// 获取到需要后台下载的包cachevo /// </summary> /// <returns></returns> public static Dictionary <string, CacheVo> CheckBackEndCacheDic(bool handlePackCount) { Stopwatch sw = Stopwatch.StartNew(); Dictionary <string, CacheVo> cacheVodic = new Dictionary <string, CacheVo>(); ResIndex resIndex = GetIndexFile(ResPath.Backend); if (resIndex == null) { return(cacheVodic); } if (resIndex.packageDict.Count == 0) { Debug.LogError("Download_IndexNoExist"); return(cacheVodic); } if (IsDownloadMarked()) { return(cacheVodic); } foreach (var v in resIndex.packageDict) { FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend + "_" + v.Key); if (fm.IsMatch == false) { CacheVo vo = new CacheVo(); vo.needDownload = true; cacheVodic.Add(v.Key, vo); } } if (handlePackCount) { LoadingProgress.Instance.AddPackCount(cacheVodic.Count); } return(cacheVodic); }
private static bool IsDownloadMarked() { FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.AllResources); return(fm.IsMatch); }
private static void MarkDownloadAll() { FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.AllResources); fm.UpdateRecord(AppConfig.Instance.version + ""); }