public async Task <bool> FullCompare() { if (LocalVerions != null) { LocalVerions.FileVers = new List <VerInfoModel>();//clear local records. } VersionDistance = new VersionDistance(); VersionDistance.HasUpdate = true; return(await GetDownloadList(ServerVerions)); }
public async Task <bool> Init() { if (File.Exists("launcher.dat")) { config = await Util.LoadLocalFileToObj <Config>("launcher.dat"); } if (config == null || string.IsNullOrEmpty(config.ServerUrl)) { config = new Config(); config.ServerUrl = "http://127.0.0.1:4500"; Util.SaveObjToFile(config, "launcher.dat"); } ServerUrl = config.ServerUrl; client = new HttpClient(); client.BaseAddress = new Uri(ServerUrl); client.Timeout = TimeSpan.FromSeconds(300); //5 minutes //load local data first. await LoadLocalData(); //load server data ServerVerions = await LoadSvrFileToObj <VersionsModel>($"{BambooBalerDirName}/vers.dat"); //check launcher update if (string.IsNullOrEmpty(ServerVerions?.LauncherMd5) == false) { string exeName = Process.GetCurrentProcess().MainModule.FileName; string exeDir = Path.GetDirectoryName(exeName); string launchermd5 = Util.Md5File(exeName); HasLauncherUpdate = !launchermd5.Equals(ServerVerions.LauncherMd5, StringComparison.CurrentCultureIgnoreCase); if (string.IsNullOrEmpty(launchermd5)) { HasLauncherUpdate = false; } if (HasLauncherUpdate) { string oldname = "oldlauncher.exe"; //remove oldone. if (File.Exists(oldname)) { try { File.Delete(oldname); } catch { } } //rename cur exe try { File.Move(exeName, exeDir + "/" + oldname); } catch { } //download new file await DownloadFile("BambooLauncher.exe", exeName); } } //check update VersionDistance = CheckUpdates(ServerVerions, LocalVerions); await UpdateSkin(); await GetDownloadList(ServerVerions); return(ServerVerions != null); }
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); }