Exemplo n.º 1
0
        private void DoUpdate()
        {
            Log("Starting update...");

            Log($"Looking for process {_processId}");

            var process = Process.GetProcessById(_processId);

            Log("Killing process...");

            process.Kill();

            Log("Process killed");

            var originDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var targetDir = Path.GetDirectoryName(_installPath);

            Log($"Installing update from origin: {originDir} to target: {targetDir}");

            FileHelper.CopyDirectory(originDir, targetDir);

            Log("Update installed");

            Log("Spawning cleanup bootstrapper");

            UpdateHelper.StartUpdater(_installPath, new Dictionary <string, string>
            {
                ["mode"]        = "cleanup",
                ["cleanupPath"] = _cleanupPath,
            }, _elevated);

            if (_restartApp)
            {
                Log("App was requested to restart, spawning updated app");
                Process.Start(_installPath);
                Log("App spawned");
            }

            Log("Done updating");
        }
Exemplo n.º 2
0
        public async Task Update(bool restartOnUpdate = true, IProgress <double> progress = default)
        {
            var updateFile = await _updateProvider.DownloadUpdate(progress);

            if (string.IsNullOrWhiteSpace(updateFile))
            {
                // TODO There should probably be an error here?
                return;
            }

            var runElevated = UpdateNeedsElevation();

            // Get a temporary path to extract the update to, we'll
            // be using this to start the updater and copy the files
            // over
            var updatePath = Path.GetTempPath();

            using (var stream = File.OpenRead(updateFile))
            {
                var readerOptions = new ReaderOptions
                {
                    LeaveStreamOpen = false,
                    ArchiveEncoding = { Default = Encoding.GetEncoding(866) },
                };

                using (var reader = ReaderFactory.Open(stream, readerOptions))
                {
                    while (reader.MoveToNextEntry())
                    {
                        if (!reader.Entry.IsDirectory)
                        {
                            reader.WriteEntryToDirectory(updatePath, new ExtractionOptions()
                            {
                                ExtractFullPath = true,
                                Overwrite       = true
                            });
                        }
                    }
                }
            }

            var installLocation = Assembly.GetEntryAssembly().Location;

            var args = new Dictionary <string, string>
            {
                ["mode"]        = "update",
                ["path"]        = installLocation,
                ["cleanupPath"] = updatePath,
            };

            if (restartOnUpdate)
            {
                args.Add("restartApp", string.Empty);
            }

            if (runElevated)
            {
                args.Add("elevated", string.Empty);
            }

            UpdateHelper.StartUpdater(updatePath, args, runElevated);
        }