Beispiel #1
0
        /// <summary>
        /// Installs the downloaded update if it exists
        /// </summary>
        public void InstallUpdate()
        {
            int updateFiles = Directory.GetFiles(downloadPath).Length;

            if (updateFiles == 0)
            {
                InstallationFailed?.Invoke(this, new ExceptionEventArgs <Exception>(new FileNotFoundException("There isn't any downloaded update"), "There isn't any downloaded update"));
                return;
            }

            State = UpdaterState.Installing;
            InstallationStarted?.Invoke(this, new VersionEventArgs(currentVersion, latestVersion, false, changelog));

            try
            {
                Process process = new Process
                {
                    StartInfo =
                    {
                        FileName       = batFilePath,
                        Arguments      = $"{Process.GetCurrentProcess().Id} \"{updatePath}\" \"{Path.GetDirectoryName(originalFilePath)}\" \"{originalFilePath}\"",
                        CreateNoWindow = true
                    }
                };

                process.Start();
            }
            catch (Exception e)
            {
                InstallationFailed?.Invoke(this, new ExceptionEventArgs <Exception>(e, e.Message));
                return;
            }

            State = UpdaterState.Idle;
        }
Beispiel #2
0
        /// <summary>
        /// Makes a backup of the current EXE, then overwrites it with the new EXE.
        /// </summary>
        /// <returns>Awaitable Task</returns>
        ///  <exception cref="NullReferenceException">Thrown when the Repository is null</exception>
        public void InstallUpdate()
        {
            InstallationStarted?.Invoke(this, EventArgs.Empty);
            State = UpdaterState.Installing;

            if (repository == null)
            {
                throw new NullReferenceException("Could not retrieve Repository");
            }

            try
            {
                string tempPath = Path.GetTempPath() + backupFileName;
                if (File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }


                // Move current exe to backup.
                File.Move(originalInstallPath, tempPath);

                // Move downloaded exe to the correct folder.
                File.Move(downloadedAssetPath, originalInstallPath);
            }
            catch (Exception ex)
            {
                InstallationFailed?.Invoke(this, new ExceptionEventArgs <Exception>(ex, ex.Message));
                return;
            }

            State = UpdaterState.Idle;
            InstallationCompleted?.Invoke(this, EventArgs.Empty);
        }