public void SaveVerInfo(GithubReleaseRes info, string filePath, string infoFile) { if (File.Exists(Path.Combine(filePath, infoFile))) { File.Delete(Path.Combine(filePath, infoFile)); } File.WriteAllText(Path.Combine(filePath, infoFile), JsonSerializer.Serialize(info)); }
public async Task <GithubReleaseRes> GetLatestVerInfo(string url) { try { string res = await HttpUtil.Get(url); GithubReleaseRes githubRelease = JsonSerializer.Deserialize <GithubReleaseRes>(res); return(githubRelease); } catch (Exception ex) { LogUtil.Error(ex); } return(new GithubReleaseRes()); }
public bool IsHasNewVer(GithubReleaseRes info, string localInfoPath) { try { string content = File.ReadAllText(localInfoPath); GithubReleaseRes localInfo = JsonSerializer.Deserialize <GithubReleaseRes>(content); //用時間比對 if (info.Assets[0].AssetCreatedAt.CompareTo(localInfo.Assets[0].AssetCreatedAt) > 0) { return(true); } } catch (Exception ex) { LogUtil.Debug("No Local Version Info"); return(true); } return(false); }
public async Task <bool> DownloadNewVer(GithubReleaseRes info, string dir, string fileName) { try { if (Directory.Exists(dir)) { LogUtil.Debug("New Version Folder is exist"); FileUtil.DeleteWholeFolder(dir); } Directory.CreateDirectory(dir); File.WriteAllBytes(Path.Combine(dir, fileName), await HttpUtil.DownloadFile(info.Assets[0].AssetBrowserDownloadUrl)); return(true); } catch (Exception ex) { LogUtil.Debug("DownloadNewVer Fail"); LogUtil.Error(ex); } return(false); }
static async Task Main(string[] args) { UpdateService updateService = new UpdateService(); InstallService installService = new InstallService(); //ProcessService processService = new ProcessService(Path.Combine(Environment.CurrentDirectory, "")); GithubReleaseRes info = await updateService.GetLatestVerInfo("https://api.github.com/repos/soyCracker/DelegationExporter/releases/latest"); LogUtil.Debug("tag_name:" + info.TagName); LogUtil.Debug("download url:" + info.Assets[0].AssetBrowserDownloadUrl); LogUtil.Debug("file name:" + info.Assets[0].AssetName); //LogUtil.Debug(Environment.CurrentDirectory); //LogUtil.Debug(Path.GetFullPath(BaseConstant.VERSION_FILE_NAME)); if (updateService.IsHasNewVer(info, BaseConstant.VERSION_FILE_NAME)) { LogUtil.Debug("Has new ver, download start"); if (await updateService.DownloadNewVer(info, BaseConstant.DOWNLOAD_TEMP_FOLDER, info.Assets[0].AssetName)) { updateService.SaveVerInfo(info, BaseConstant.DOWNLOAD_TEMP_FOLDER, BaseConstant.VERSION_FILE_NAME); LogUtil.Debug("Download Finish"); /*while(processService.IsProcessRun()) * { * processService.StopProcess(); * Thread.Sleep(1000); * }*/ string zipPath = Path.Combine(BaseConstant.DOWNLOAD_TEMP_FOLDER, info.Assets[0].AssetName); installService.DeleteCurrent(installService.GetZipEntries(zipPath)); installService.Inastall(zipPath, Environment.CurrentDirectory); } } /*if(!processService.IsProcessRun()) * { * processService.StartProcess(); * }*/ }