Exemplo n.º 1
0
        private string GetUpdateExecutable()
        {
            var entryAssemblyDirectory = AssemblyHelper.GetEntryAssembly().GetDirectory();
            var updateExe = Path.GetFullPath(UpdateExe, entryAssemblyDirectory);

            return(updateExe);
        }
Exemplo n.º 2
0
        public void GetFullPath_RelativeDotsAndNameDirectory()
        {
            // Declare variables
            string file = @"..\Windows\notepad.exe";
            string path = @"C:\Program Files\";

            // Call method
            string full = Path.GetFullPath(file, path);

            // Validate
            Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower());
        }
Exemplo n.º 3
0
        public void GetFullPath_FileNameOnlyAndDirectoryWithoutTrailingSlash()
        {
            // Declare variables
            string file = @"notepad.exe";
            string path = @"C:\Windows";

            // Call method
            string full = Path.GetFullPath(file, path);

            // Validate
            Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower());
        }
Exemplo n.º 4
0
        public void GetFullPath_FromRootDirectory()
        {
            // Declare variables
            string file = @"Windows\notepad.exe";
            string path = @"C:\";

            // Call method
            string full = Path.GetFullPath(file, path);

            // Validate
            Assert.AreEqual(@"C:\Windows\notepad.exe".ToLower(), full.ToLower());
        }
Exemplo n.º 5
0
        private string GetUpdateExecutable()
        {
            if (string.IsNullOrWhiteSpace(_updateExeLocation))
            {
                var entryAssemblyDirectory = AssemblyHelper.GetEntryAssembly().GetDirectory();
                _updateExeLocation = Path.GetFullPath(UpdateExe, entryAssemblyDirectory);

                Log.Debug($"Determined update executable path '{_updateExeLocation}', exists: {_fileService.Exists(_updateExeLocation)}");
            }

            return(_updateExeLocation);
        }
Exemplo n.º 6
0
        public void GetFullPath_NoBasePath()
        {
            // Declare variables
            string file = @"..\Windows\notepad.exe";
            string path = @"";

            // Set current environment path
            string oldEnvironmentDirectory = Environment.CurrentDirectory;

            Environment.CurrentDirectory = @"C:\Program Files\";

            ExceptionTester.CallMethodAndExpectException <ArgumentException>(() => Path.GetFullPath(file, path));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the updates by installing them if there is an update available.
        /// </summary>
        /// <param name="maximumReleaseDate">The maximum release date.</param>
        /// <returns>Task.</returns>
        public async Task HandleUpdatesAsync(DateTime?maximumReleaseDate = null)
        {
            if (!_initialized)
            {
                throw Log.ErrorAndCreateException <InvalidOperationException>("Service is not initialized, call Initialize first");
            }

            var checkForUpdates = _configurationService.GetValue <bool>(Settings.Application.AutomaticUpdates.CheckForUpdates);

            if (!checkForUpdates)
            {
                Log.Info("Automatic updates are disabled");
                return;
            }

            var channelName            = _configurationService.GetValue <string>(Settings.Application.AutomaticUpdates.UpdateChannel, string.Empty);
            var channelUrlSettingsName = Settings.Application.AutomaticUpdates.GetChannelSettingName(channelName);
            var channelUrl             = _configurationService.GetValue <string>(channelUrlSettingsName, string.Empty);

            if (string.IsNullOrEmpty(channelUrl))
            {
                Log.Warning("Cannot find url for channel '{0}'", channelName);
                return;
            }

            var entryAssemblyDirectory = AssemblyHelper.GetEntryAssembly().GetDirectory();
            var updateExe = GetUpdateExecutable();

            if (!File.Exists(updateExe))
            {
                Log.Warning("Cannot check for updates, update.exe is not available");
                return;
            }

            Log.Info("Calling update.exe for url '{0}'", channelUrl);

            await TaskHelper.Run(() =>
            {
                try
                {
                    if (!maximumReleaseDate.HasValue)
                    {
                        maximumReleaseDate = DateTime.MaxValue;
                    }

                    var startInfo              = new ProcessStartInfo(updateExe);
                    startInfo.Arguments        = string.Format("--update={0} --md={1} --silent", channelUrl, maximumReleaseDate.Value.ToString("yyyyMMddHHmmss"));
                    startInfo.WorkingDirectory = Path.GetFullPath("..", entryAssemblyDirectory);
                    startInfo.UseShellExecute  = true;
                    startInfo.CreateNoWindow   = true;

                    var process = Process.Start(startInfo);
                    process.WaitForExit();

                    Log.Debug("Update.exe exited with exit code '{0}'", process.ExitCode);

                    // Possible exit codes:
                    // -1 => An error occurred. Check the log file for more information about this error
                    //  0 => No errors, no additional information available
                    //  1 => New version available or new version is installed successfully (depending on switch /checkonly)
                    //  2 => New version which is mandatory (forced) is available (for the future?)
                    //  3 => No new version available

                    switch (process.ExitCode)
                    {
                    case 1:
                        IsUpdatedInstalled = true;
                        UpdateInstalled.SafeInvoke(this);

                        Log.Info("Installed new update");
                        break;

                    case 4:
                        IsUpdateOutsideMaintenanceAvailable = true;
                        UpdateOutsideMaintenanceAvailable.SafeInvoke(this);

                        Log.Info("New update is available but is outside maintenance, maintenance ended on '{0}'", maximumReleaseDate);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Failed to check for updates");
                }
            }, true);
        }