From ed71d8e3a85683099143725e9fcee1b24959474a Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Fri, 27 Oct 2023 15:34:23 +0100 Subject: [PATCH] Some more corrections. Signed-off-by: Konstantina Chremmou --- XenAdmin/Alerts/Types/ClientUpdateAlert.cs | 30 ++--- XenAdmin/MainWindow.cs | 8 +- .../Actions/Updates/DownloadFileAction.cs | 110 ++++++------------ XenModel/BrandManager.cs | 3 - XenModel/Messages.Designer.cs | 67 ++++++----- XenModel/Messages.resx | 29 ++--- scripts/xenadmin-build.ps1 | 10 +- 7 files changed, 112 insertions(+), 145 deletions(-) diff --git a/XenAdmin/Alerts/Types/ClientUpdateAlert.cs b/XenAdmin/Alerts/Types/ClientUpdateAlert.cs index c457b7a5d..b6ee5ab92 100644 --- a/XenAdmin/Alerts/Types/ClientUpdateAlert.cs +++ b/XenAdmin/Alerts/Types/ClientUpdateAlert.cs @@ -38,6 +38,7 @@ using XenAdmin.Actions.Updates; using XenAdmin.Core; using XenAdmin.Dialogs; +using XenAdmin.Dialogs.WarningDialogs; using XenCenterLib; namespace XenAdmin.Alerts @@ -124,10 +125,13 @@ public static void DownloadAndInstallNewClient(ClientUpdateAlert updateAlert, IW if (currentTasks) { - if (new Dialogs.WarningDialogs.CloseXenCenterWarningDialog(true).ShowDialog(parent) != DialogResult.OK) + using (var dlg = new CloseXenCenterWarningDialog(true)) { - downloadAndInstallClientAction.ReleaseDownloadedContent(); - return; + if (dlg.ShowDialog(parent) != DialogResult.OK) + { + downloadAndInstallClientAction.ReleaseDownloadedContent(); + return; + } } } @@ -153,40 +157,30 @@ public static void DownloadSource(IWin32Window parent) // If no update no need to show where to save dialog var clientVersion = Updates.ClientVersions.FirstOrDefault(); - DownloadSourceAction downloadSourceAction; if (clientVersion == null) { - // There is no XCupdates.xml so direct to website. + // There is no XCUpdates.xml so direct to website. Program.OpenURL(InvisibleMessages.WEBSITE_DOWNLOADS); - return; } else { string outputPathAndFileName; using (var saveSourceDialog = new SaveFileDialog()) { - saveSourceDialog.FileName = string.Format(Messages.SOURCE_FILE_NAME, BrandManager.BrandConsole, clientVersion.Version) + ".zip"; + saveSourceDialog.FileName = $"{BrandManager.BrandConsole}-v{clientVersion.Version}-source.zip"; saveSourceDialog.DefaultExt = "zip"; saveSourceDialog.Filter = "(*.zip)|*.zip|All files (*.*)|*.*"; saveSourceDialog.InitialDirectory = Win32.GetKnownFolderPath(Win32.KnownFolders.Downloads); - if (saveSourceDialog.ShowDialog() != DialogResult.OK) + if (saveSourceDialog.ShowDialog(parent) != DialogResult.OK) { return; } outputPathAndFileName = saveSourceDialog.FileName; } - downloadSourceAction = new DownloadSourceAction(clientVersion.Name, clientVersion.Version, new Uri(clientVersion.SourceUrl), outputPathAndFileName); - - using (var dlg = new ActionProgressDialog(downloadSourceAction, ProgressBarStyle.Continuous)) - { - dlg.ShowCancel = true; - dlg.ShowDialog(parent); - } - - if (!downloadSourceAction.Succeeded) - return; + var downloadSourceAction = new DownloadSourceAction(clientVersion.Name, new Uri(clientVersion.SourceUrl), outputPathAndFileName); + downloadSourceAction.RunAsync(); } } } diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index f4c954686..a9da97ca9 100755 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -2719,12 +2719,12 @@ private void SetClientUpdateAlert() if (updateAlert != null) { relNotesToolStripMenuItem.Text = string.Format(Messages.MAINWINDOW_UPDATE_RELEASE, updateAlert.NewVersion.Version); - downloadSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, updateAlert.NewVersion.Version); + downloadSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, updateAlert.NewVersion.Version); } - var clientVersion = Updates.ClientVersions.FirstOrDefault(); + var clientVersion = Updates.ClientVersions.FirstOrDefault(); downloadLatestSourceToolStripMenuItem.Text = clientVersion != null - ? string.Format(Messages.DOWNLOAD_SOURCE, clientVersion.Version) - : Messages.DOWNLOAD_LATEST_SOURCE; + ? string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, clientVersion.Version) + : string.Format(Messages.DOWNLOAD_LATEST_SOURCE, BrandManager.BrandConsole); updateClientToolStripMenuItem.Visible = updateAlert != null; } diff --git a/XenModel/Actions/Updates/DownloadFileAction.cs b/XenModel/Actions/Updates/DownloadFileAction.cs index 441f8660a..e8271fca7 100644 --- a/XenModel/Actions/Updates/DownloadFileAction.cs +++ b/XenModel/Actions/Updates/DownloadFileAction.cs @@ -49,14 +49,10 @@ public class DownloadFileAction : AsyncAction, IByteProgressAction private const int SLEEP_TIME_TO_CHECK_DOWNLOAD_STATUS_MS = 900; private const int SLEEP_TIME_BEFORE_RETRY_MS = 5000; - //If you consider increasing this for any reason (I think 5 is already more than enough), have a look at the usage of SLEEP_TIME_BEFORE_RETRY_MS in DownloadFile() as well. + //If you consider increasing this for any reason (I think 5 is already more than enough), + //have a look at the usage of SLEEP_TIME_BEFORE_RETRY_MS in DownloadFile() as well. private const int MAX_NUMBER_OF_TRIES = 5; - protected Uri Address => _address; - protected string OutputPathAndFileName => _outputPathAndFileName; - protected string FileName => _fileName; - protected bool CanDownloadFile => _canDownloadFile; - private readonly Uri _address; private readonly string _outputPathAndFileName; private readonly string _fileName; @@ -66,12 +62,10 @@ public class DownloadFileAction : AsyncAction, IByteProgressAction private readonly string _authToken; private WebClient _client; - + protected string OutputPathAndFileName => _outputPathAndFileName; public string ByteProgressDescription { get; set; } - - - public DownloadFileAction(string fileName, Uri uri, string outputFileName, string title, bool suppressHistory) + protected DownloadFileAction(string fileName, Uri uri, string outputFileName, string title, bool suppressHistory) : base(null, title, fileName, suppressHistory) { _fileName = fileName; @@ -79,11 +73,9 @@ public DownloadFileAction(string fileName, Uri uri, string outputFileName, strin _canDownloadFile = _address != null; _outputPathAndFileName = outputFileName; _authToken = XenAdminConfigManager.Provider.GetClientUpdatesQueryParam(); - Title = string.Format(Messages.DOWNLOADING_FILE, fileName); - Description = Title; } - protected void DownloadFile() + private void DownloadFile() { int errorCount = 0; bool needToRetry = false; @@ -195,7 +187,7 @@ protected override void Run() if (!_canDownloadFile) return; - log.InfoFormat("Downloading '{0}' (from '{1}') to '{2}'", FileName, _address, _outputPathAndFileName); + log.InfoFormat("Downloading '{0}' (from '{1}') to '{2}'", _fileName, _address, _outputPathAndFileName); LogDescriptionChanges = false; DownloadFile(); LogDescriptionChanges = true; @@ -207,7 +199,9 @@ protected override void Run() throw new CancelledException(); if (!File.Exists(_outputPathAndFileName)) - throw new Exception(Messages.DOWNLOAD_FILE_NOT_FOUND); + throw new Exception(GetDownloadedFileNotFoundMessage()); + + ValidateDownloadedFile(); Description = Messages.COMPLETED; } @@ -217,7 +211,16 @@ protected override void CleanOnError() ReleaseDownloadedContent(true); } - public void ReleaseDownloadedContent(bool deleteDownloadedContent = false) + protected virtual string GetDownloadedFileNotFoundMessage() + { + return Messages.DOWNLOAD_FILE_ACTION_NOT_FOUND; + } + + protected virtual void ValidateDownloadedFile() + { + } + + public virtual void ReleaseDownloadedContent(bool deleteDownloadedContent = false) { if (!deleteDownloadedContent) return; @@ -237,7 +240,7 @@ private void client_DownloadProgressChanged(object sender, DownloadProgressChang { int pc = (int)(95.0 * e.BytesReceived / e.TotalBytesToReceive); - var descr = string.Format(Messages.DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION, FileName, + var descr = string.Format(Messages.DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION, _fileName, Util.DiskSizeString(e.BytesReceived, "F1"), Util.DiskSizeString(e.TotalBytesToReceive)); ByteProgressDescription = descr; @@ -252,20 +255,20 @@ private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs if (e.Cancelled) { _fileState = DownloadState.Cancelled; - log.DebugFormat("'{0}' download cancelled by the user", FileName); + log.DebugFormat("'{0}' download cancelled by the user", _fileName); return; } if (e.Error != null) { _downloadError = e.Error; - log.DebugFormat("'{0}' download failed", FileName); + log.DebugFormat("'{0}' download failed", _fileName); _fileState = DownloadState.Error; return; } _fileState = DownloadState.Completed; - log.DebugFormat("'{0}' download completed successfully", FileName); + log.DebugFormat("'{0}' download completed successfully", _fileName); } public override void RecomputeCanCancel() @@ -274,51 +277,28 @@ public override void RecomputeCanCancel() } } - public class DownloadAndUpdateClientAction : DownloadFileAction, IByteProgressAction + public class DownloadAndUpdateClientAction : DownloadFileAction { - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly string _checksum; private FileStream _msiStream; - public DownloadAndUpdateClientAction(string updateName, Uri uri, string outputFileName, string checksum) - : base(updateName, + public DownloadAndUpdateClientAction(string installerName, Uri uri, string outputFileName, string checksum) + : base(installerName, uri, outputFileName, - $"{updateName}.msi", + string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_TITLE, installerName), true) { _checksum = checksum; + Description = string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_DESCRIPTION, installerName); } - protected override void Run() + protected override string GetDownloadedFileNotFoundMessage() { - if (!CanDownloadFile) - return; - - log.InfoFormat("Downloading '{0}' installer (from '{1}') to '{2}'", FileName, Address, OutputPathAndFileName); - Description = string.Format(Messages.DOWNLOADING_FILE, FileName); - LogDescriptionChanges = false; - DownloadFile(); - LogDescriptionChanges = true; - - if (IsCompleted || Cancelled) - return; - - if (Cancelling) - throw new CancelledException(); - - if (!File.Exists(OutputPathAndFileName)) - throw new Exception(Messages.DOWNLOAD_CLIENT_INSTALLER_MSI_NOT_FOUND); - - ValidateMsi(); - - Description = Messages.COMPLETED; + return Messages.DOWNLOAD_CLIENT_INSTALLER_MSI_NOT_FOUND; } - - - private void ValidateMsi() + protected override void ValidateDownloadedFile() { Description = Messages.UPDATE_CLIENT_VALIDATING_INSTALLER; @@ -353,38 +333,24 @@ private void ValidateMsi() throw new Exception(Messages.UPDATE_CLIENT_INVALID_DIGITAL_CERTIFICATE); } - public new void ReleaseDownloadedContent(bool deleteDownloadedContent = false) + public override void ReleaseDownloadedContent(bool deleteDownloadedContent = false) { _msiStream.Dispose(); - - if (!deleteDownloadedContent) - return; - - try - { - if (File.Exists(OutputPathAndFileName)) - File.Delete(OutputPathAndFileName); - } - catch - { - //ignore - } + base.ReleaseDownloadedContent(deleteDownloadedContent); } } - public class DownloadSourceAction : DownloadFileAction, IByteProgressAction + public class DownloadSourceAction : DownloadFileAction { - public DownloadSourceAction(string sourceName, Version version, Uri uri, string outputFileName) - : base(String.Format(Messages.SOURCE_FILE_NAME, sourceName, version), + public DownloadSourceAction(string sourceName, Uri uri, string outputFileName) + : base(sourceName, uri, outputFileName, - string.Format(Messages.DOWNLOADING_FILE, version.ToString() + " " + outputFileName), + string.Format(Messages.DOWNLOAD_CLIENT_SOURCE_ACTION_TITLE, sourceName), false) { - + Description = string.Format(Messages.DOWNLOAD_CLIENT_SOURCE_ACTION_DESCRIPTION, sourceName); } } - - } diff --git a/XenModel/BrandManager.cs b/XenModel/BrandManager.cs index b08ad3be2..e22b52b86 100644 --- a/XenModel/BrandManager.cs +++ b/XenModel/BrandManager.cs @@ -31,7 +31,6 @@ using System.Diagnostics; using System.Reflection; using System.Resources; -using System.Web.UI; using XenAdmin.Properties; @@ -114,8 +113,6 @@ static BrandManager() public static readonly string CfuUrl; - public static readonly string SourceUrl; - public static readonly string VmTools; public static readonly string XenHost; diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index b369e42ea..4839432ca 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -14050,11 +14050,20 @@ public static string DOWNLOAD_AND_EXTRACT_ACTION_TITLE { } /// - /// Looks up a localized string similar to Downloading {0} installer ({1} of {2}).... + /// Looks up a localized string similar to Downloading {0} installer. /// - public static string DOWNLOAD_CLIENT_INSTALLER_ACTION_PROGRESS_DESCRIPTION { + public static string DOWNLOAD_CLIENT_INSTALLER_ACTION_DESCRIPTION { get { - return ResourceManager.GetString("DOWNLOAD_CLIENT_INSTALLER_ACTION_PROGRESS_DESCRIPTION", resourceCulture); + return ResourceManager.GetString("DOWNLOAD_CLIENT_INSTALLER_ACTION_DESCRIPTION", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Download {0} installer. + /// + public static string DOWNLOAD_CLIENT_INSTALLER_ACTION_TITLE { + get { + return ResourceManager.GetString("DOWNLOAD_CLIENT_INSTALLER_ACTION_TITLE", resourceCulture); } } @@ -14067,6 +14076,24 @@ public static string DOWNLOAD_CLIENT_INSTALLER_MSI_NOT_FOUND { } } + /// + /// Looks up a localized string similar to Downloading {0} source code. + /// + public static string DOWNLOAD_CLIENT_SOURCE_ACTION_DESCRIPTION { + get { + return ResourceManager.GetString("DOWNLOAD_CLIENT_SOURCE_ACTION_DESCRIPTION", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Download {0} source code. + /// + public static string DOWNLOAD_CLIENT_SOURCE_ACTION_TITLE { + get { + return ResourceManager.GetString("DOWNLOAD_CLIENT_SOURCE_ACTION_TITLE", resourceCulture); + } + } + /// /// Looks up a localized string similar to Download.... /// @@ -14077,25 +14104,25 @@ public static string DOWNLOAD_ELLIPSES { } /// - /// Looks up a localized string similar to Downloading {0} ({1} of {2}).... + /// Looks up a localized string similar to The downloaded file can no longer be found.. /// - public static string DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION { + public static string DOWNLOAD_FILE_ACTION_NOT_FOUND { get { - return ResourceManager.GetString("DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION", resourceCulture); + return ResourceManager.GetString("DOWNLOAD_FILE_ACTION_NOT_FOUND", resourceCulture); } } /// - /// Looks up a localized string similar to The downloaded file can no longer be found.. + /// Looks up a localized string similar to Downloading {0} ({1} of {2}).... /// - public static string DOWNLOAD_FILE_NOT_FOUND { + public static string DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION { get { - return ResourceManager.GetString("DOWNLOAD_FILE_NOT_FOUND", resourceCulture); + return ResourceManager.GetString("DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION", resourceCulture); } } /// - /// Looks up a localized string similar to Download latest source. + /// Looks up a localized string similar to Download latest {0} source code. /// public static string DOWNLOAD_LATEST_SOURCE { get { @@ -14113,7 +14140,7 @@ public static string DOWNLOAD_LATEST_XS_BODY { } /// - /// Looks up a localized string similar to Download v{0} source. + /// Looks up a localized string similar to Download {0} v{1} source code. /// public static string DOWNLOAD_SOURCE { get { @@ -14121,15 +14148,6 @@ public static string DOWNLOAD_SOURCE { } } - /// - /// Looks up a localized string similar to Downloading {0}. - /// - public static string DOWNLOADING_FILE { - get { - return ResourceManager.GetString("DOWNLOADING_FILE", resourceCulture); - } - } - /// /// Looks up a localized string similar to Downloading update from '{0}' ({1} of {2}).... /// @@ -35389,15 +35407,6 @@ public static string SOME_ERRORS_ENCOUNTERED { } } - /// - /// Looks up a localized string similar to {0}-v{1}-source. - /// - public static string SOURCE_FILE_NAME { - get { - return ResourceManager.GetString("SOURCE_FILE_NAME", resourceCulture); - } - } - /// /// Looks up a localized string similar to - . /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index b885d684b..656c03156 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -4962,32 +4962,38 @@ Plugging in untrustworthy USB devices to your computer may put your computer at Download and extract update {0} - - Downloading {0} installer ({1} of {2})... + + Downloading {0} installer + + + Download {0} installer The downloaded installer can no longer be found. + + Downloading {0} source code + + + Download {0} source code + Download... + + The downloaded file can no longer be found. + Downloading {0} ({1} of {2})... - - The downloaded file can no longer be found. - - Download latest source + Download latest {0} source code {0} is now available. Download the latest at the {1} downloads website. - Download v{0} source - - - Downloading {0} + Download {0} v{1} source code Downloading update from '{0}' ({1} of {2})... @@ -12241,9 +12247,6 @@ Reverting to this snapshot will revert the VM back to the point in time that the Some errors were encountered. See the application log for more information. - - {0}-v{1}-source - - diff --git a/scripts/xenadmin-build.ps1 b/scripts/xenadmin-build.ps1 index f283be56c..489a06f0b 100644 --- a/scripts/xenadmin-build.ps1 +++ b/scripts/xenadmin-build.ps1 @@ -322,8 +322,8 @@ $date=(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") $productVersion = "$BRANDING_XC_PRODUCT_VERSION.$buildNumber" $productFullName = "$appName $productVersion" -$prodXml = [string]::Format($xmlFormat, $productFullName, $date, $msi_url, $msi_checksum, $productVersion) -$testXml = [string]::Format($xmlFormat, $productFullName, $date, "@DEV_MSI_URL_PLACEHOLDER@", $msi_checksum, $productVersion) +$prodXml = [string]::Format($xmlFormat, $productFullName, $date, $msi_url, $msi_checksum, $productVersion, $source_url) +$testXml = [string]::Format($xmlFormat, $productFullName, $date, "@DEV_MSI_URL_PLACEHOLDER@", $msi_checksum, $productVersion, "@DEV_SRC_URL_PLACEHOLDER@") Write-Host $prodXml Write-Host $testXml @@ -334,10 +334,8 @@ $bomLessEncoding = New-Object System.Text.UTF8Encoding $false Write-Host "INFO: Generating XCUpdates.xml" -[string]::Format($xmlFormat, $productFullName, $date, $msi_url, $msi_checksum, $productVersion, $source_url) |` - Out-File -FilePath $OUTPUT_DIR\XCUpdates.xml -Encoding utf8 +[System.IO.File]::WriteAllLines("$OUTPUT_DIR\XCUpdates.xml", $prodXml, $bomLessEncoding) Write-Host "INFO: Generating stage-test-XCUpdates.xml. URL is a placeholder value" -[string]::Format($xmlFormat, $productFullName, $date, "@DEV_MSI_URL_PLACEHOLDER@", $msi_checksum, $productVersion, "@DEV_SOURCE_URL_PLACEHOLDER@") |` - Out-File -FilePath $OUTPUT_DIR\stage-test-XCUpdates.xml -Encoding utf8 +[System.IO.File]::WriteAllLines("$OUTPUT_DIR\stage-test-XCUpdates.xml", $testXml, $bomLessEncoding)