public void MergeVers() { if (Version.FileVers == null || Version.FileVers.Count == 0) { return; } int serial = Version.FileVers[0].SerialNo + 1; string urlbase = Version.FileVers[0].UrlBase; if (urlbase == null) { urlbase = ""; } if (urlbase.Length > 0 && urlbase.EndsWith("/") == false) { urlbase = urlbase + "/"; } long downloadsize = 0; FileList fl = new FileList(); fl.Files = new List <FileModel>(); foreach (var item in StagedVersFiles.Values) { if (string.IsNullOrEmpty(item.Url) || item.LocalPath.StartsWith("http", StringComparison.CurrentCultureIgnoreCase) == false) { item.Url = urlbase + item.LocalPath; } downloadsize += item.Size; fl.Files.Add(item); } var listdata = Util.FileListToString(fl); StreamWriter sw = new StreamWriter(GetFullPath($"{BambooBalerDirName}/list{serial}.txt"), false, Encoding.UTF8); sw.WriteLine(listdata); sw.Close(); foreach (var item in Version.FileVers) { File.Delete(GetFullPath($"{BambooBalerDirName}/list{item.SerialNo}.txt")); } Version.FileVers.Clear(); Version.FileVers.Add(ChangesVer); VerInfoModel merged = new VerInfoModel(); merged.SerialNo = serial; merged.Title = "merged version"; merged.UpdateTime = DateTime.Now; merged.ChangeCount = StagedVersFiles.Count; merged.DownloadSize = downloadsize; VersionsModel data = new VersionsModel(); data.SkinVer = Version.SkinVer; data.LaunchTarget = Version.LaunchTarget; data.FileVers = new List <VerInfoModel>(); data.FileVers.Add(merged); Util.SaveObjToFile(data, GetFullPath($"{BambooBalerDirName}/vers.dat")); }
private async Task <bool> GetDownloadList(VersionsModel svrVers) { if (VersionDistance.HasUpdate == false || svrVers == null) { return(false); } int startVer = 0; if (LocalVerions?.FileVers?.Count > 0) { startVer = LocalVerions.FileVers[0].SerialNo; } Dictionary <string, FileModel> files = new Dictionary <string, FileModel>(); //load each version list. merge to files dictionary. new version overwrite old one. for (int i = svrVers.FileVers.Count - 1; i >= 0; i--) { VerInfoModel ver = svrVers.FileVers[i]; string liststr = await LoadSvrFileToStr($"{BambooBalerDirName}/list{ver.SerialNo}.txt"); FileList list = new FileList(); Util.StringToFileList(liststr, list); if (list.Files == null) { continue; } foreach (var item in list.Files) { files[item.LocalPath] = item; } } //convert file list to file operate list. Files.Clear(); foreach (var item in files.Values) { Files.Add(Util.FileModelToFileOperate(item)); } return(false); }
public async Task <bool> ConfirmChanges(string verTitle, string verDetail, bool forceUpdate, string urlbase) { await CheckSkinUpdate(); if (urlbase == null) { urlbase = ""; } if (urlbase.Length > 0 && urlbase.EndsWith("/") == false) { urlbase = urlbase + "/"; } int newserial = 0; if (Version.FileVers?.Count > 0) { newserial = Version.FileVers[0].SerialNo + 1; } //make sure baler dir existed. if (Directory.Exists(GetFullPath(BambooBalerDirName)) == false) { Directory.CreateDirectory(GetFullPath(BambooBalerDirName)); } FileList list = new FileList(); list.Files = Changes; foreach (var item in Changes) { item.Url = urlbase + item.LocalPath; } var liststr = Util.FileListToString(list); StreamWriter sw = new StreamWriter(GetFullPath($"{BambooBalerDirName}/list{newserial}.txt"), false, Encoding.UTF8); sw.WriteLine(liststr); sw.Close(); VersionsModel data = new VersionsModel(); data.SkinVer = Version.SkinVer; data.LaunchTarget = Version.LaunchTarget; data.FileVers = Version.FileVers; data.LauncherMd5 = Util.Md5File(GetFullPath("BambooLauncher.exe")); VerInfoModel newver = new VerInfoModel(); newver.SerialNo = newserial; newver.Title = verTitle; newver.Detail = verDetail; newver.ForceUpdate = forceUpdate; newver.ChangeCount = ChangesVer.ChangeCount; newver.DownloadSize = ChangesVer.DownloadSize; newver.UrlBase = urlbase; newver.UpdateTime = DateTime.Now; data.FileVers.Insert(0, newver); Util.SaveObjToFile(data, GetFullPath($"{BambooBalerDirName}/vers.dat")); Vers.Add(newver); Changes.Clear(); ChangesVer.ChangeCount = 0; ChangesVer.DownloadSize = 0; return(true); }
private VersionDistance CheckUpdates(VersionsModel svrVer, VersionsModel localVer) { progress.Reset(); VersionDistance dst = new VersionDistance(); dst.HasUpdate = false; dst.MustUpdate = false; dst.HasSkinUpdate = false; dst.DownloadSize = 0; dst.DownloadVersions = 0; //server versions is empty. if (svrVer == null || svrVer.FileVers == null || svrVer.FileVers.Count == 0) { progress.Status = "请求服务器数据失败"; return(dst); } //local versions is empty if (localVer == null || localVer.FileVers == null || localVer.FileVers.Count == 0) { dst.HasUpdate = true; dst.MustUpdate = true; dst.HasSkinUpdate = true; dst.DownloadVersions = 0; dst.DownloadSize = 0; foreach (var item in svrVer.FileVers) { dst.DownloadSize += item.DownloadSize; dst.DownloadVersions++; if (item.ForceUpdate) { dst.MustUpdate = true; } } progress.Status = Util.GetDistanceReportString(dst); return(dst); } //check skin update dst.HasSkinUpdate = svrVer.SkinVer > localVer.SkinVer; //local is newer than server, this is not possible, maybe changed by user. VerInfoModel svrLatest = svrVer.FileVers[0]; VerInfoModel localLatest = localVer.FileVers[0]; if (localLatest.SerialNo >= svrLatest.SerialNo) { return(dst); } dst.DownloadVersions = 0; dst.HasUpdate = true; for (int i = svrVer.FileVers.Count - 1; i >= 0; i--) { VerInfoModel ver = svrVer.FileVers[i]; if (ver.SerialNo <= localLatest.SerialNo) { continue; } dst.DownloadSize += ver.DownloadSize; dst.DownloadVersions++; if (ver.ForceUpdate) { dst.MustUpdate = true; } } progress.Status = Util.GetDistanceReportString(dst); return(dst); }