private void Window_ContentRendered(object sender, EventArgs e) { progressBar.IsIndeterminate = true; BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.ProgressChanged += Worker_ProgressChanged; worker.RunWorkerCompleted += Worker_WorkCompleted; IDictionary <CommandLineParameter, string> parameters = CommandLineParameter.Parse(Environment.GetCommandLineArgs()); /*if (parameters != null) * foreach (KeyValuePair<CommandLineParameter, string> kp in parameters) * MessageBox.Show(kp.Key + "=" + kp.Value);*/ UpdateService updateService = new UpdateService(worker, parameters); IUpdateManifest manifest = updateService.GetProcess().GetManifest(); IUpdateStatus status = updateService.GetProcess().GetUpdater().Status(); lblTitle.Content = manifest.Application.Name + " " + status.LatestVersion.Tag; updateService.Start(); }
public static void WriteUpdateManifest(IUpdateManifest manifset, string filePath) { Assert(manifset != null); using (FileStream fs = File.Create(filePath)) { var bw = new BinaryWriter(fs); bw.Write(Encoding.UTF8.GetBytes(GLOBAL_MANIFEST_SIGNATURE)); bw.Write(manifset.UpdateKey); bw.Write(manifset.DataGeneration); bw.Write(manifset.Versions.Keys.Count()); foreach (AppArchitecture_t arch in manifset.Versions.Keys) { Version ver = manifset.Versions[arch]; bw.Write((byte)arch); bw.Write(ver.Major); bw.Write(ver.Minor); bw.Write(ver.Build); bw.Write(ver.Revision); } } }
public Updater(IUpdateManifest manifest, IUpdateStatusProvider statusProvider, IUpdateDownloader downloader, IUpdateInstaller installer) { this.manifest = manifest; this.statusProvider = statusProvider; this.downloader = downloader; this.installer = installer; }
public UpdateProcess(IDictionary <CommandLineParameter, string> parameters, int killInitiatingProcessTimeout) { this.initiatingProcess = GetInitiatingProcess(parameters); KeyValuePair <IUpdateManifest, string> manifestAndPath = RetrieveUpdateManifest(parameters); this.manifest = manifestAndPath.Key; this.manifestPath = manifestAndPath.Value; this.updater = UpdaterFactory.Create(manifest); this.followUpProcessPath = GetParameterValue <string>(CommandLineParameter.FollowUpProcess, parameters); this.killInitiatingProcessTimeout = killInitiatingProcessTimeout; }
public IUpdateStatus GetStatus(IUpdateManifest manifest) { GitHubUpdateManifest gitHubUpdateManifest = (GitHubUpdateManifest)manifest; string releasesUrl = string.Format("http://github.com/{0}/{1}/releases", manifest.Repository.Owner, manifest.Repository.Name); GitHubRelease latestRelease = new GitHubLatestReleaseHtmlBuilder().build(releasesUrl, gitHubUpdateManifest); IVersion currentVersion = manifest.Application.Version; return(new UpdateStatusAdapter(currentVersion, latestRelease)); }
public void Run() { List <TableUpdate> tablesUpdate = BuildTablesUpdate(); Opts.AppSettings opt = AppContext.Settings.AppSettings; var inc = new UpdateIncrement(AppContext.TableManager.DataUpdates.CreateUniqID(), opt.DataGeneration); string incFileName = inc.ID.ToString("X"); string incFilePath = System.IO.Path.Combine(AppPaths.DataUpdateFolder, incFileName); UpdateEngin.SaveTablesUpdate(tablesUpdate, incFilePath); AppContext.AccessPath.GetDataProvider(InternalTablesID.INCREMENT).Insert(inc); foreach (TableUpdate tu in tablesUpdate) { AppContext.TableManager.SetTableGeneration(tu.TableID, tu.PostGeneration); } AppContext.TableManager.Transactions.Reset(); string dataMainfest = AppPaths.DataManifestPath; UpdateEngin.UpdateDataManifest(dataMainfest, new UpdateURI(incFileName, opt.DataGeneration)); if (opt.DataGeneration++ == 0) { opt.UpdateKey = (uint)DateTime.Now.Ticks; } AppContext.Settings.Save(); string manifestFile = AppPaths.ManifestPath; try { IUpdateManifest oldManifest = UpdateEngin.ReadUpdateManifest(manifestFile); var newManifest = new UpdateManifest(opt.UpdateKey, opt.DataGeneration, oldManifest.Versions); UpdateEngin.WriteUpdateManifest(newManifest, manifestFile); } catch { UpdateEngin.WriteUpdateManifest(new UpdateManifest(opt.UpdateKey, opt.DataGeneration), manifestFile); } }
public static KeyValuePair <IUpdateManifest, string> Retrieve(UpdateManifestType manifestType, string manifestPath) { IUpdateManifest manifest = null; if (manifestPath == null || manifestPath == string.Empty) { manifestPath = GitHubUpdateManifestFileName; } if (manifestType == UpdateManifestType.GitHub) { manifest = SerializerFactory.GetInstance().Load <GitHubUpdateManifest>(manifestPath); } else { throw new ArgumentException("Manifest type '" + manifestType + "' is not yet handled."); } return(new KeyValuePair <IUpdateManifest, string>(manifest, manifestPath)); }
public static bool UpdateData() { /* * telecharger le fichier manifest * si DataGeneration > manifest.DataGeneration * signaler l'erreur a HubGovernor * sortir * si DataGeneration < manifest.DataGeneration * telecharger manifest.data * pour chaque entrées E dans manifest.data et tant que DataGeneration < manifest.DataGeneration * si DataGeneration == E.PreDataGeneration * Appliquer les maj des tables * mettre a jours DataGeneration */ string manifest = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(manifest))) try { var netEngin = new NetEngin(Program.NetworkSettings); netEngin.Download(manifest, Urls.ManifestURL); IUpdateManifest updateManifest = UpdateEngin.ReadUpdateManifest(manifest); string log = "Recherche de mise à jour des données. Version actulle des données: " + $"{Program.Settings.DataGeneration}. "; if (updateManifest.DataGeneration == Program.Settings.DataGeneration) { Program.DialogManager.PostLog(log + " Les données sont à jour", false); return(true); } if (Program.Settings.UpdateKey != updateManifest.UpdateKey) { if (Program.Settings.UpdateKey == 0) { Program.Settings.UpdateKey = updateManifest.UpdateKey; } else { Log.LogEngin.PushFlash(AppText.ERR_UPDATEKEY); Dbg.Log("Update key mismatch!"); Program.DialogManager.PostLog(log + AppText.ERR_UPDATEKEY, true); return(false); } } //TODO: signaler l'erreur si DataGeneration < manifest.DataGeneration string dataManifest = Path.GetTempFileName(); using (Log.LogEngin.PushMessage("Installation des mises à jour...")) using (new AutoReleaser(() => File.Delete(dataManifest))) { netEngin.Download(dataManifest, Urls.DataManifestURL); var uris = new List <UpdateURI>(UpdateEngin.ReadDataManifest(dataManifest, Program.Settings.DataGeneration)); foreach (UpdateURI uu in uris.OrderBy(u => u.DataPreGeneration)) { if (uu.DataPreGeneration == Program.Settings.DataGeneration) { string updateFile = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(updateFile))) { netEngin.Download(updateFile, Urls.DataUpdateDirURL + uu.FileURI); ApplyUpdate(updateFile); Program.Settings.DataGeneration = uu.DataPostGeneration; } } } DataUpdated?.Invoke(); } Program.DialogManager.PostLog(log + "Mises à jour installées. " + $"Nouvelle version des données: {Program.Settings.DataGeneration}", false); Assert(Program.Settings.DataGeneration == updateManifest.DataGeneration); } catch (Exception ex) { Dbg.Log("Data update: " + ex.Message); } return(true); }
public static void UpdateApp() { //dl global manifest Log.LogEngin.PushFlash("Rechercher d'une mise à jour de l'application..."); const string logTxt = "Rechercher d'une mise à jour de l'application. "; string tmpFile = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(tmpFile))) try { var netEngin = new NetEngin(Program.NetworkSettings); netEngin.Download(tmpFile, Urls.ManifestURL); IUpdateManifest updateManifest = UpdateEngin.ReadUpdateManifest(tmpFile); Version curVer = Assembly.GetExecutingAssembly().GetName().Version; Version ver = updateManifest.GetAppVersion(Program.AppArchitecture); if (ver == null || curVer.CompareTo(ver) >= 0) { Log.LogEngin.PushFlash("Vous disposez déjà de la dernière version de l’application."); Program.DialogManager.PostLog(logTxt + "Pas de nouvelle mise à jour", false); return; } Log.LogEngin.PushFlash($"Une nouvelle version de l'application est disponible ({ver})."); Program.DialogManager.PostLog(logTxt + $"Une nouvelle version de l'application est disponible, version: ({ver})", false); const string setupTxtLog = "L'utilsateur a refuser d'installer la nouvelle version du HUB"; if (CanDownlaodAppUpdate?.Invoke() != true) { Program.DialogManager.PostLog(setupTxtLog, false); return; } Log.LogEngin.PushFlash($"Téléchargement de la mise à jour..."); //dl app manifest netEngin.Download(tmpFile, Urls.AppManifestURL); Dictionary <AppArchitecture_t, string> upFiles = UpdateEngin.ReadAppManifest(tmpFile); string fileName = upFiles[Program.AppArchitecture]; //dl update file var url = Urls.AppUpdateDirURL + fileName; netEngin.Download(tmpFile, url); if (CanRunAppUpdate?.Invoke() != true) { Program.DialogManager.PostLog(setupTxtLog, false); return; } string tmpDir = Path.GetTempPath(); new FilesBag().Decompress(tmpFile, tmpDir); System.Diagnostics.Process.Start(Path.Combine(tmpDir, "setup.exe")); Program.DialogManager.PostLog("Lancement du programme d'installation de la mise à jour du HUB", false); System.Windows.Forms.Application.Exit(); } catch (Exception ex) { Dbg.Log("App update: " + ex.Message); } }
public static IUpdater Create(IUpdateManifest manifest) { //TODO: algorithm to instanciate the right types (using the manifest and maybe application args) return(new Updater(manifest, new GitHubStatusProvider(), new GitHubUpdateDownloader(), new SingleZipInstaller())); }
public async Task <DownloadResult> Download(IUpdateManifest manifest, IVersion targetVersion, string targetDirectoryName, Action <DownloadProgress> progressCallback) { string applicationRoot = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string targetDirectory = Path.Combine(applicationRoot, targetDirectoryName); if (Directory.Exists(targetDirectory)) { Directory.Delete(targetDirectory, true); } Directory.CreateDirectory(targetDirectory); DownloadProgress progress = null; IEnumerable <IVersionFile> releaseFiles = targetVersion.VersionFiles; foreach (IVersionFile file in releaseFiles) { using (var wc = new WebClient()) { var lockThis = new object(); wc.DownloadProgressChanged += (sender, e) => { lock (lockThis) { progress = new DownloadProgress(file.Name, e.BytesReceived, e.TotalBytesToReceive); progressCallback(progress); } }; wc.DownloadFileCompleted += (sender, e) => { if (e.Error != null) { if (progress == null) { progressCallback(new DownloadProgress(file.Name, 0, file.Length, e.Error)); } else { progressCallback(new DownloadProgress(file.Name, progress.BytesProcessed, progress.TotalBytesToProcess, e.Error)); } } else { progress = new DownloadProgress("Done", progress.TotalBytesToProcess, progress.TotalBytesToProcess); progressCallback(progress); } }; string downloadedFilePath = Path.Combine(targetDirectory, Path.GetFileName(file.Uri.ToString())); await wc.DownloadFileTaskAsync(file.Uri, downloadedFilePath); } } if (progress.Error == null) { return(new DownloadResult(progress.BytesProcessed)); } else { return(new DownloadResult(progress.BytesProcessed, progress.Error)); } }
public InstallResult Install(IUpdateManifest manifest, IEnumerable <IVersionFile> files, string updateSourceDirectory, string updateTargetDirectory, Action <IProgress> progressCallback) { if (files == null || files.Count() != 1) { throw new InvalidOperationException("The update can't contain more than one file."); } IVersionFile releaseZipFile = files.ElementAt(0); string zipPath = Path.Combine(updateSourceDirectory, releaseZipFile.Name); string zipDirectory = Path.GetDirectoryName(zipPath); long zipSize = 0; bool extractingFinished = false; bool copyStarted = false; bool copyFinished = false; FileProcessingProgress progress = null; try { using (var extracting = ZipFile.Read(zipPath)) { foreach (ZipEntry e in extracting) { zipSize += e.UncompressedSize; } extracting.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently; extracting.ExtractProgress += (obj, e) => { if (extractingFinished) { return; } if (e.BytesTransferred >= e.TotalBytesToTransfer) { string item = e.CurrentEntry == null ? null : e.CurrentEntry.FileName; if (progress == null) { progress = new FileProcessingProgress("2/3 - Extracting... " + item, e.BytesTransferred, zipSize); } else { if (progress.Done) { item = "Done"; extractingFinished = true; } else if (item != null && item.Contains('/')) { string[] parts = item.Split('/'); if (parts != null && parts.Count() > 1 && parts[1] != string.Empty) { item = parts.Last(); } } progress = new FileProcessingProgress("2/3 - Extracting... " + item, progress.BytesProcessed + e.BytesTransferred, zipSize); progressCallback(progress); if (extractingFinished && !copyStarted && !copyFinished) { string zipEmbeddedRootDirectoryName = extracting.Entries.First().FileName; string extractedDirectoryPath = Path.Combine(zipDirectory, zipEmbeddedRootDirectoryName); long directorySize = GetDirectorySize(new DirectoryInfo(extractedDirectoryPath)); long bytesCopied = 0; Copy(extractedDirectoryPath, AppDomain.CurrentDomain.BaseDirectory, (fileName, copied) => { if (copyFinished) { return; } copyStarted = true; bytesCopied += copied; progress = new FileProcessingProgress("3/3 - Copying... " + fileName, bytesCopied, directorySize); if (progress.Done) { copyFinished = true; progress = new FileProcessingProgress("3/3 - Copying... Done", bytesCopied, directorySize); } progressCallback(progress); }); } } } }; extracting.ExtractAll(zipDirectory); return(new InstallResult(zipSize)); } } catch (Exception ex) { if (progress != null) { progressCallback(new FileProcessingProgress("2/3 - Extracting... " + releaseZipFile.Name, progress.BytesProcessed, progress.TotalBytesToProcess, ex)); return(new InstallResult(progress.BytesProcessed, ex)); } else { progressCallback(new FileProcessingProgress("2/3 - Extracting... " + releaseZipFile.Name, 0, 0, ex)); return(new InstallResult(0, ex)); } } }