コード例 #1
0
ファイル: AutoUpdater.cs プロジェクト: lapuinka/naps2
        public Task<bool> DownloadUpdate(VersionInfo versionInfo, string savePath)
        {
            return Task.Factory.StartNew(() =>
            {
                // Store to a temp file while downloading
                string tempPath = Path.Combine(Paths.Temp, Path.GetRandomFileName());

                urlFileDownloader.DownloadFile(versionInfo.DownloadUrl, tempPath);

                // Handle the somewhat tricky situation where the file to save to already exists
                if (File.Exists(savePath))
                {
                    // Try overwriting the file, which should work if it isn't locked by another process
                    try
                    {
                        File.Delete(savePath);
                    }
                    catch (IOException)
                    {
                        File.Delete(tempPath);
                        return false;
                    }
                }

                // Now that the download is complete, rename/move the temp file
                File.Move(tempPath, savePath);

                return true;
            });
        }
コード例 #2
0
ファイル: AutoUpdaterUI.cs プロジェクト: lapuinka/naps2
 public void PerformUpdate(IAutoUpdaterClient client, VersionInfo versionInfo)
 {
     switch (formFactory.Create<FUpdate>().ShowDialog())
     {
         case DialogResult.Yes: // Install
             // TODO: The app process might need to be killed/restarted before/after installing
             autoUpdater.DownloadAndInstallUpdate(versionInfo).ContinueWith(result =>
             {
                 if (result.Result)
                 {
                     client.InstallComplete();
                 }
                 else
                 {
                     MessageBox.Show(MiscResources.InstallFailed, MiscResources.InstallFailedTitle,
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             });
             break;
         case DialogResult.OK: // Download
             var saveDialog = new SaveFileDialog
             {
                 FileName = versionInfo.FileName
             };
             if (saveDialog.ShowDialog() == DialogResult.OK)
             {
                 // TODO: Display progress while downloading
                 autoUpdater.DownloadUpdate(versionInfo, saveDialog.FileName);
             }
             break;
     }
 }
コード例 #3
0
ファイル: AutoUpdater.cs プロジェクト: lapuinka/naps2
 public Task<bool> DownloadAndInstallUpdate(VersionInfo versionInfo)
 {
     return Task.Factory.StartNew(() =>
     {
         var saveFolder = Path.Combine(Paths.Temp, Path.GetRandomFileName());
         var savePath = Path.Combine(saveFolder, versionInfo.FileName);
         Directory.CreateDirectory(saveFolder);
         try
         {
             if (!DownloadUpdate(versionInfo, savePath).Result)
             {
                 return false;
             }
             if (!InstallUpdate(savePath, versionInfo.InstallArguments).Result)
             {
                 return false;
             }
             return true;
         }
         finally
         {
             Directory.Delete(saveFolder, true);
         }
     });
 }
コード例 #4
0
ファイル: FDesktop.cs プロジェクト: lapuinka/naps2
 public void UpdateAvailable(VersionInfo versionInfo)
 {
     Invoke(() => autoUpdaterUI.PerformUpdate(this, versionInfo));
 }