private void ClearLocalFile() { Caching.CleanCache(); PlayerPrefs.SetInt(GameSetting.ShowWaitingTipKey, 0); TableManager.ClearTableCache(); PlayerPrefs.Save(); DeleteDir(DownloadRoot); WriteStringToFile(DownLoadGameVersionPath, LocalGameVersion); WriteStringToFile(DownLoadVersionPath, LocalVersion.ToString()); Logger.Debug("ClearLastGameVersionResource"); }
//获取下载列表,去除已下载文件 public IEnumerator UpdateMd5List(DelegateGetMd5List delFun) { UpdateStatus = GetDictionaryText(3300004); var md5ListUrl = CheckUrl(RemoteUrlRoot + GetMd5DiffListFileName()); Logger.Debug("-----UpdateMd5List : " + md5ListUrl); var wwwMd5ListFile = new WWW(GameUtils.GetNoCacheUrl(md5ListUrl)); yield return(wwwMd5ListFile); if (!String.IsNullOrEmpty(wwwMd5ListFile.error)) { delFun(UpdateResult.GetMd5ListFail, GetDictionaryText(3300014)); yield break; } UpdateStatus = GetDictionaryText(3300005); //读取远端列表 mDownloadMd5Dictionary = new Dictionary <string, string>(); var stream = new MemoryStream(wwwMd5ListFile.bytes); var sr = new StreamReader(stream); var line = sr.ReadLine(); var changed = false; string key; while (!String.IsNullOrEmpty(line)) { var str = line.Split(','); if (!String.IsNullOrEmpty(str[1])) { key = str[1]; if (!mDownloadMd5Dictionary.ContainsKey(key)) { var idx = key.IndexOf('/'); var dir = idx == -1 ? string.Empty : key.Substring(0, idx); bool lateUpdate = false; if (!string.IsNullOrEmpty(dir) && whiteListDirectorys.Contains(dir)) { lateUpdate = !whiteListFils.Contains(key); } if (lateUpdate) { lock (BundleLoader.Instance.mWaitingDownloadBundles) { if (BundleLoader.Instance.mWaitingDownloadBundles.ContainsKey(key)) { BundleLoader.Instance.mWaitingDownloadBundles[key] = RemoteUrlRoot; BundleLoader.Instance.DownloadBundleKeyQueue.Enqueue(key); } else { BundleLoader.Instance.mWaitingDownloadBundles.Add(key, RemoteUrlRoot); BundleLoader.Instance.DownloadBundleKeyQueue.Enqueue(key); } } changed = true; mLateDownloadTotalSize += int.Parse(str[3]); } else { mDownloadMd5Dictionary.Add(str[1], String.Format("{0},{1}", str[2], str[3])); mTotalSize += int.Parse(str[3]); } } else { Logger.Error("md5list have repeated file:" + key); } } line = sr.ReadLine(); } if (changed) { BundleLoader.Instance.SaveBundleDictionary(BundleLoader.Instance.mWaitingDownloadBundles); } Logger.Debug("-----RemoteMd5List have {0} files---", mDownloadMd5Dictionary.Count); //读取本地已下载列表 if (File.Exists(LocalMd5ListFilePath)) { var list = new List <string>(); var localMd5sr = new StreamReader(LocalMd5ListFilePath); var localLine = localMd5sr.ReadLine(); while (!String.IsNullOrEmpty(localLine)) { list.Add(localLine); localLine = localMd5sr.ReadLine(); } localMd5sr.Close(); localMd5sr.Dispose(); Logger.Debug("LocalMd5List have {0} files", list.Count); { var __list3 = list; var __listCount3 = __list3.Count; for (var __i3 = 0; __i3 < __listCount3; ++__i3) { var strline = __list3[__i3]; { var str = strline.Split(','); var fileName = str[0]; var fileMd5 = str[1]; if (mDownloadMd5Dictionary.ContainsKey(fileName)) { var listMd5 = mDownloadMd5Dictionary[fileName].Split(',')[0]; if (listMd5.ToLower().Equals(fileMd5.ToLower())) { mTotalSize -= int.Parse(mDownloadMd5Dictionary[fileName].Split(',')[1]); mDownloadMd5Dictionary.Remove(fileName); } } } } } } else { Logger.Debug("-----already downloaded 0 files---"); } stream.Close(); stream.Dispose(); sr.Close(); sr.Dispose(); wwwMd5ListFile.Dispose(); try { var clearTable = false; var clearCommon = false; foreach (var downloadFile in mDownloadMd5Dictionary) { var fileName = Path.GetDirectoryName(downloadFile.Key); if (!clearTable) { if (fileName.StartsWith("Table")) { clearTable = true; } } if (!clearCommon) { if (fileName.StartsWith("Terrain")) { clearCommon = true; } var name = Path.GetFileNameWithoutExtension(downloadFile.Key); if (GameSetting.Instance.mCommonBundleList.Contains(name)) { clearCommon = true; } } } if (clearTable) { TableManager.ClearTableCache(); } if (clearCommon) { Caching.CleanCache(); } } catch (Exception e) { TableManager.ClearTableCache(); Caching.CleanCache(); Logger.Error("Caching.Clear exception" + e); } if (null != delFun) { try { var size = mLateDownloadTotalSize / 1048576.0f; if (size > 50) { delFun(UpdateResult.GetMd5ListSuccessAndLateUpdate, size.ToString("F2")); } else { delFun(UpdateResult.GetMd5ListSuccess, (mTotalSize / 1048576.0f).ToString("F2")); } } catch (Exception ex) { Logger.Error(ex.StackTrace); } } }