Пример #1
0
 internal static void StartUpdate(Version version)
 {
     try
     {
         var ver = "0.0.0";
         if (version != null)
         {
             ver = version.ToString(3);
             if (Setting.IsLoaded && Setting.AcceptUnstableVersion.Value)
             {
                 ver = App.Version.ToString(4);
             }
         }
         var pubkey = Path.Combine(App.ExeFileDir, App.PublicKeyFile);
         var dest   = App.ExeFileDir;
         var pid    = Process.GetCurrentProcess().Id;
         var args   = new[]
         {
             ver,
             pubkey,
             dest,
             pid.ToString(CultureInfo.InvariantCulture)
         }.Select(s => "\"" + s + "\"").JoinString(" ");
         var startInfo = new ProcessStartInfo(ExecutablePath)
         {
             Arguments        = args,
             UseShellExecute  = true,
             WorkingDirectory = App.LocalUpdateStorePath
         };
         MainWindowModel.SuppressCloseConfirmation = true;
         Process.Start(startInfo);
         Application.Current.Shutdown();
     }
     catch (Exception ex)
     {
         TaskDialog.Show(new TaskDialogOptions
         {
             Title           = SubsystemResources.AutoUpdateFailedTitle,
             MainIcon        = VistaTaskDialogIcon.Error,
             MainInstruction = SubsystemResources.AutoUpdateFailedInst,
             Content         = SubsystemResources.AutoUpdateFailedContent,
             ExpandedInfo    = ex.ToString(),
             CommonButtons   = TaskDialogCommonButtons.Close
         });
         // cleanup update binaries
         try
         {
             if (Directory.Exists(App.LocalUpdateStorePath))
             {
                 Directory.Delete(App.LocalUpdateStorePath, true);
             }
         }
         catch
         {
             // ignored
         }
     }
 }
Пример #2
0
        internal static void PostUpdate()
        {
            var retryCount = 0;

            try
            {
                var directory = new DirectoryInfo(App.LocalUpdateStorePath);
                while (directory.Exists)
                {
                    try
                    {
                        // remove "read-only" attribute
                        directory.GetFiles("*", SearchOption.AllDirectories)
                        .Where(file => file.Attributes.HasFlag(FileAttributes.ReadOnly))
                        .ForEach(f => f.Attributes ^= FileAttributes.ReadOnly);

                        // delete directory
                        directory.Delete(true);
                        break;
                    }
                    catch (Exception)
                    {
                        if (retryCount > 10)
                        {
                            // exit loop
                            throw;
                        }
                        Thread.Sleep(1000);
                        // refresh directory state
                        directory.Refresh();
                        retryCount++;
                    }
                }
            }
            catch (Exception)
            {
                TaskDialog.Show(new TaskDialogOptions
                {
                    Title           = SubsystemResources.UpdateCompleteErrorTitle,
                    MainIcon        = VistaTaskDialogIcon.Error,
                    MainInstruction = SubsystemResources.UpdateCompleteErrorInst,
                    Content         = SubsystemResources.UpdateCompleteErrorContent,
                    ExpandedInfo    = SubsystemResources.UpdateCompleteErrorExInfo,
                    CommonButtons   = TaskDialogCommonButtons.Close
                });
            }
        }