mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
CA-249823 - Accept zip files in Updates Wizard (#1667)
* CA-249823 - Accept zip files in Updates Wizard * CA-258326 - Improve implementation of CA-248823(Accept zip files in Updates Wizard) * Small unrelated bugfix: Stop selectFromDiskRadioButton being checked when restoring dismissed updates. Signed-off-by: Letsibogo Ramadi <letsibogo.ramadi@citrix.com>
This commit is contained in:
parent
c9932a49a1
commit
c44f89bf05
@ -339,6 +339,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
else
|
||||
{
|
||||
listOfDownloadedFiles.AddRange(PatchingWizard_UploadPage.AllDownloadedPatches.Values);
|
||||
listOfDownloadedFiles.AddRange(PatchingWizard_SelectPatchPage.UnzippedUpdateFiles);
|
||||
}
|
||||
|
||||
foreach (string downloadedPatch in listOfDownloadedFiles)
|
||||
|
@ -55,7 +55,8 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
public XenServerPatchAlert SelectedUpdateAlert;
|
||||
public XenServerPatchAlert FileFromDiskAlert;
|
||||
private bool firstLoad = true;
|
||||
|
||||
private string unzippedUpdateFilePath;
|
||||
|
||||
public PatchingWizard_SelectPatchPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -177,7 +178,22 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
{
|
||||
if (!IsInAutomatedUpdatesMode)
|
||||
{
|
||||
var fileName = fileNameTextBox.Text.ToLowerInvariant();
|
||||
if (selectFromDiskRadioButton.Checked && Path.GetExtension(fileNameTextBox.Text).ToLowerInvariant().Equals(".zip"))
|
||||
{
|
||||
//check if we are installing update user sees in textbox
|
||||
if (Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(fileNameTextBox.Text))
|
||||
{
|
||||
unzippedUpdateFilePath = ExtractUpdate(fileNameTextBox.Text);
|
||||
if (unzippedUpdateFilePath == null)
|
||||
cancel = true;
|
||||
|
||||
unzippedFiles.Add(unzippedUpdateFilePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
unzippedUpdateFilePath = null;
|
||||
|
||||
var fileName = isValidFile(unzippedUpdateFilePath) ? unzippedUpdateFilePath.ToLowerInvariant() : fileNameTextBox.Text.ToLowerInvariant();
|
||||
|
||||
SelectedUpdateAlert = downloadUpdateRadioButton.Checked
|
||||
? (XenServerPatchAlert)((PatchGridViewRow)dataGridViewPatches.SelectedRows[0]).UpdateAlert
|
||||
@ -325,10 +341,9 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
else if (selectFromDiskRadioButton.Checked)
|
||||
{
|
||||
if (isValidFile(fileNameTextBox.Text))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -344,7 +359,17 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
private bool isValidFile(string fileName)
|
||||
{
|
||||
return !string.IsNullOrEmpty(fileName) && File.Exists(fileName) && (fileName.ToLowerInvariant().EndsWith(UpdateExtension.ToLowerInvariant()) || fileName.ToLowerInvariant().EndsWith(".iso")); //this iso is supplemental pack iso for XS, not branded
|
||||
return !string.IsNullOrEmpty(fileName) && File.Exists(fileName) && (fileName.ToLowerInvariant().EndsWith(UpdateExtension.ToLowerInvariant())
|
||||
|| fileName.ToLowerInvariant().EndsWith(".zip")
|
||||
|| fileName.ToLowerInvariant().EndsWith(".iso")); //this iso is supplemental pack iso for XS, not branded
|
||||
}
|
||||
|
||||
//list to store unzipped files to be removed later by PatchingWizard
|
||||
private List<string> unzippedFiles = new List<string>();
|
||||
|
||||
public List<string> UnzippedUpdateFiles
|
||||
{
|
||||
get { return unzippedFiles; }
|
||||
}
|
||||
|
||||
private void BrowseButton_Click(object sender, EventArgs e)
|
||||
@ -370,9 +395,10 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
})
|
||||
{
|
||||
if (dlg.ShowDialog(this) == DialogResult.OK && dlg.CheckFileExists)
|
||||
AddFile(dlg.FileName);
|
||||
AddFile(dlg.FileName);
|
||||
}
|
||||
OnPageUpdated();
|
||||
OnPageUpdated();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -382,7 +408,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
public void AddFile(string fileName)
|
||||
{
|
||||
if (fileName.ToLowerInvariant().EndsWith(UpdateExtension.ToLowerInvariant()) || fileName.ToLowerInvariant().EndsWith(".iso")) //this iso is supplemental pack iso for XS, not branded
|
||||
if (isValidFile(fileName))
|
||||
{
|
||||
fileNameTextBox.Text = fileName;
|
||||
selectFromDiskRadioButton.Checked = true;
|
||||
@ -414,13 +440,40 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
else if (selectFromDiskRadioButton.Checked)
|
||||
{
|
||||
return SelectedUpdateType == UpdateType.NewRetail || SelectedUpdateType == UpdateType.ISO
|
||||
? fileNameTextBox.Text
|
||||
: null;
|
||||
? isValidFile(unzippedUpdateFilePath) && Path.GetExtension(fileNameTextBox.Text).ToLowerInvariant().Equals(".zip")
|
||||
? unzippedUpdateFilePath : fileNameTextBox.Text : null;
|
||||
}
|
||||
else return null;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractUpdate(string zippedUpdatePath)
|
||||
{
|
||||
var unzipAction = new DownloadAndUnzipXenServerPatchAction(Path.GetFileNameWithoutExtension(zippedUpdatePath), null, zippedUpdatePath, true, Branding.Update, Branding.UpdateIso);
|
||||
using (var dlg = new ActionProgressDialog(unzipAction, ProgressBarStyle.Marquee))
|
||||
{
|
||||
dlg.ShowDialog(Parent);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(unzipAction.PatchPath))
|
||||
{
|
||||
using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
|
||||
SystemIcons.Error,
|
||||
string.Format(Messages.UPDATES_WIZARD_NOTVALID_ZIPFILE, Path.GetFileName(zippedUpdatePath)),
|
||||
Messages.UPDATES)))
|
||||
{
|
||||
dlg.ShowDialog(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return unzipAction.PatchPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region DataGridView
|
||||
|
||||
private void dataGridViewPatches_SelectionChanged(object sender, EventArgs e)
|
||||
@ -612,6 +665,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
private void RestoreDismUpdatesButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
dataGridViewPatches.Focus();
|
||||
Updates.RestoreDismissedUpdates();
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ namespace XenAdmin.Wizards.PatchingWizard
|
||||
|
||||
bool isIso = SelectedUpdateType == UpdateType.ISO;
|
||||
|
||||
downloadAction = new DownloadAndUnzipXenServerPatchAction(SelectedUpdateAlert.Name, address, tempFile, isIso ? Branding.UpdateIso : Branding.Update);
|
||||
downloadAction = new DownloadAndUnzipXenServerPatchAction(SelectedUpdateAlert.Name, address, tempFile, false, isIso ? Branding.UpdateIso : Branding.Update);
|
||||
|
||||
if (downloadAction != null)
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ namespace XenAdmin.Wizards.PatchingWizard.PlanActions
|
||||
Uri address = new Uri(patchUri);
|
||||
tempFileName = Path.GetTempFileName();
|
||||
|
||||
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, Helpers.ElyOrGreater(Connection) ? Branding.UpdateIso : Branding.Update);
|
||||
var downloadAction = new DownloadAndUnzipXenServerPatchAction(patch.Name, address, tempFileName, false, Helpers.ElyOrGreater(Connection) ? Branding.UpdateIso : Branding.Update);
|
||||
|
||||
if (downloadAction != null)
|
||||
{
|
||||
|
@ -49,9 +49,10 @@ namespace XenAdmin.Actions
|
||||
private Random random = new Random();
|
||||
|
||||
private readonly Uri address;
|
||||
private readonly string outFileName;
|
||||
private readonly string zippedFileName;
|
||||
private readonly string updateName;
|
||||
private readonly string updateFileExtension;
|
||||
private readonly string[] updateFileExtensions;
|
||||
private readonly bool downloadUpdate;
|
||||
private DownloadState patchDownloadState;
|
||||
private Exception patchDownloadError;
|
||||
|
||||
@ -60,17 +61,15 @@ namespace XenAdmin.Actions
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public DownloadAndUnzipXenServerPatchAction(string patchName, Uri uri, string outputFileName)
|
||||
: this(patchName, uri, outputFileName, InvisibleMessages.XEN_UPDATE)
|
||||
{ }
|
||||
|
||||
public DownloadAndUnzipXenServerPatchAction(string patchName, Uri uri, string outputFileName, string updateFileExtension)
|
||||
: base(null, string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_TITLE, patchName), string.Empty, false)
|
||||
public DownloadAndUnzipXenServerPatchAction(string patchName, Uri uri, string outputFileName, bool suppressHist, params string[] updateFileExtensions)
|
||||
: base(null, uri == null ? string.Format(Messages.UPDATES_WIZARD_EXTRACT_ACTION_TITLE, patchName)
|
||||
: string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_TITLE, patchName), string.Empty, suppressHist)
|
||||
{
|
||||
updateName = patchName;
|
||||
address = uri;
|
||||
outFileName = outputFileName;
|
||||
this.updateFileExtension = updateFileExtension;
|
||||
downloadUpdate = address != null;
|
||||
zippedFileName = outputFileName;
|
||||
this.updateFileExtensions = updateFileExtensions;
|
||||
}
|
||||
|
||||
private void DownloadFile()
|
||||
@ -93,7 +92,7 @@ namespace XenAdmin.Actions
|
||||
client.DownloadProgressChanged += client_DownloadProgressChanged;
|
||||
client.DownloadFileCompleted += client_DownloadFileCompleted;
|
||||
//start the download
|
||||
client.DownloadFileAsync(address, outFileName);
|
||||
client.DownloadFileAsync(address, zippedFileName);
|
||||
|
||||
patchDownloadState = DownloadState.InProgress;
|
||||
bool patchDownloadCancelling = false;
|
||||
@ -153,7 +152,7 @@ namespace XenAdmin.Actions
|
||||
ArchiveIterator iterator = null;
|
||||
try
|
||||
{
|
||||
using (Stream stream = new FileStream(outFileName, FileMode.Open, FileAccess.Read))
|
||||
using (Stream stream = new FileStream(zippedFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Zip, stream);
|
||||
DotNetZipZipIterator zipIterator = iterator as DotNetZipZipIterator;
|
||||
@ -165,11 +164,12 @@ namespace XenAdmin.Actions
|
||||
|
||||
while (iterator.HasNext())
|
||||
{
|
||||
string currentExtension = Path.GetExtension(iterator.CurrentFileName());
|
||||
string currentExtension = Path.GetExtension(iterator.CurrentFileName()).Replace(".","");
|
||||
|
||||
if (!string.IsNullOrEmpty(updateFileExtension) && currentExtension == "." + updateFileExtension)
|
||||
if (Array.Exists(updateFileExtensions, item => item == currentExtension))
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(outFileName), iterator.CurrentFileName());
|
||||
string path = downloadUpdate ? Path.Combine(Path.GetDirectoryName(zippedFileName), iterator.CurrentFileName())
|
||||
: Path.Combine(Path.GetTempPath(), iterator.CurrentFileName());
|
||||
|
||||
log.DebugFormat("Found '{0}' in the downloaded archive when looking for a '{1}' file. Extracting...", iterator.CurrentFileName(), currentExtension);
|
||||
|
||||
@ -201,30 +201,35 @@ namespace XenAdmin.Actions
|
||||
{
|
||||
if (iterator != null)
|
||||
iterator.Dispose();
|
||||
File.Delete(outFileName);
|
||||
|
||||
if (downloadUpdate)
|
||||
File.Delete(zippedFileName);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(PatchPath))
|
||||
if (string.IsNullOrEmpty(PatchPath) && downloadUpdate)
|
||||
{
|
||||
MarkCompleted(new Exception(Messages.DOWNLOAD_AND_EXTRACT_ACTION_FILE_NOT_FOUND));
|
||||
log.DebugFormat("File '{0}.{1}' could not be located in downloaded archive", updateName, updateFileExtension);
|
||||
log.DebugFormat("File '{0}.{1}' could not be located in downloaded archive", updateName, updateFileExtensions);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Run()
|
||||
{
|
||||
log.DebugFormat("Downloading XenServer patch '{0}' (url: {1})", updateName, address);
|
||||
if (downloadUpdate)
|
||||
{
|
||||
log.DebugFormat("Downloading XenServer patch '{0}' (url: {1})", updateName, address);
|
||||
|
||||
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_DOWNLOADING_DESC, updateName);
|
||||
LogDescriptionChanges = false;
|
||||
DownloadFile();
|
||||
LogDescriptionChanges = true;
|
||||
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_DOWNLOADING_DESC, updateName);
|
||||
LogDescriptionChanges = false;
|
||||
DownloadFile();
|
||||
LogDescriptionChanges = true;
|
||||
|
||||
if (IsCompleted || Cancelled)
|
||||
return;
|
||||
if (IsCompleted || Cancelled)
|
||||
return;
|
||||
|
||||
if (Cancelling)
|
||||
throw new CancelledException();
|
||||
if (Cancelling)
|
||||
throw new CancelledException();
|
||||
}
|
||||
|
||||
log.DebugFormat("Extracting XenServer patch '{0}'", updateName);
|
||||
Description = string.Format(Messages.DOWNLOAD_AND_EXTRACT_ACTION_EXTRACTING_DESC, updateName);
|
||||
@ -237,7 +242,7 @@ namespace XenAdmin.Actions
|
||||
|
||||
void archiveIterator_CurrentFileExtractProgressChanged(object sender, ExtractProgressChangedEventArgs e)
|
||||
{
|
||||
int pc = 95 + (int)(5.0 * e.BytesTransferred / e.TotalBytesToTransfer);
|
||||
int pc = downloadUpdate ? 95 + (int)(5.0 * e.BytesTransferred / e.TotalBytesToTransfer) : (int)(100.0 * e.BytesTransferred / e.TotalBytesToTransfer);
|
||||
if (pc != PercentComplete)
|
||||
PercentComplete = pc;
|
||||
}
|
||||
|
20
XenModel/Messages.Designer.cs
generated
20
XenModel/Messages.Designer.cs
generated
@ -26824,7 +26824,7 @@ namespace XenAdmin {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [XenServer] Updates and Supplemental Packs (*.{0}, *.iso)|*.{0};*.iso.
|
||||
/// Looks up a localized string similar to [XenServer] Updates and Supplemental Packs (*.{0}, *.iso,*.zip)|*.{0};*.iso;*.zip.
|
||||
/// </summary>
|
||||
public static string PATCHINGWIZARD_SELECTPATCHPAGE_UPDATESEXT {
|
||||
get {
|
||||
@ -33600,6 +33600,15 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Extract {0}.
|
||||
/// </summary>
|
||||
public static string UPDATES_WIZARD_EXTRACT_ACTION_TITLE {
|
||||
get {
|
||||
return ResourceManager.GetString("UPDATES_WIZARD_EXTRACT_ACTION_TITLE", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to find the update file '{0}'.
|
||||
///
|
||||
@ -33818,6 +33827,15 @@ namespace XenAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No valid update file found in {0}.
|
||||
/// </summary>
|
||||
public static string UPDATES_WIZARD_NOTVALID_ZIPFILE {
|
||||
get {
|
||||
return ResourceManager.GetString("UPDATES_WIZARD_NOTVALID_ZIPFILE", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The VM {0} cannot be suspended until it has up to date [XenServer product] Tools..
|
||||
/// </summary>
|
||||
|
@ -9264,7 +9264,7 @@ However, there is not enough space to perform the repartitioning, so the current
|
||||
<value>Choose an existing update to install or upload a new one</value>
|
||||
</data>
|
||||
<data name="PATCHINGWIZARD_SELECTPATCHPAGE_UPDATESEXT" xml:space="preserve">
|
||||
<value>[XenServer] Updates and Supplemental Packs (*.{0}, *.iso)|*.{0};*.iso</value>
|
||||
<value>[XenServer] Updates and Supplemental Packs (*.{0}, *.iso,*.zip)|*.{0};*.iso;*.zip</value>
|
||||
</data>
|
||||
<data name="PATCHINGWIZARD_SELECTSERVERPAGE_AUTOMATED_UPDATES_NOT_SUPPORTED_HOST_VERSION" xml:space="preserve">
|
||||
<value>Automated updates are not supported on this [XenServer] version</value>
|
||||
@ -11598,6 +11598,9 @@ Check your settings and try again.</value>
|
||||
<data name="UPDATES_WIZARD_EXIT_MAINTENANCE_MODE" xml:space="preserve">
|
||||
<value>Exit maintenance mode</value>
|
||||
</data>
|
||||
<data name="UPDATES_WIZARD_EXTRACT_ACTION_TITLE" xml:space="preserve">
|
||||
<value>Extract {0}</value>
|
||||
</data>
|
||||
<data name="UPDATES_WIZARD_FILE_NOT_FOUND" xml:space="preserve">
|
||||
<value>Unable to find the update file '{0}'.
|
||||
|
||||
@ -11642,6 +11645,9 @@ Check your settings and try again.</value>
|
||||
<data name="UPDATES_WIZARD_NOTVALID_EXTENSION" xml:space="preserve">
|
||||
<value>The selected file does not have a valid extension. Valid extensions are: *.{0} and *.iso</value>
|
||||
</data>
|
||||
<data name="UPDATES_WIZARD_NOTVALID_ZIPFILE" xml:space="preserve">
|
||||
<value>No valid update file found in {0}</value>
|
||||
</data>
|
||||
<data name="UPDATES_WIZARD_NOT_ENOUGH_SPACE" xml:space="preserve">
|
||||
<value>This storage repository does not have enough space to suspend the required VMs.</value>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user