2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2015-07-14 11:05:13 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
2018-03-14 13:12:18 +01:00
|
|
|
|
using System.Xml;
|
|
|
|
|
using DiscUtils.Iso9660;
|
2020-04-19 03:50:18 +02:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards.PatchingWizard
|
|
|
|
|
{
|
|
|
|
|
public partial class PatchingWizard_SelectPatchPage : XenTabPage
|
|
|
|
|
{
|
2018-10-04 15:33:17 +02:00
|
|
|
|
private static readonly log4net.ILog log =
|
|
|
|
|
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2018-03-14 13:12:18 +01:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public XenServerPatchAlert AlertFromFileOnDisk;
|
2018-07-06 18:31:29 +02:00
|
|
|
|
public bool FileFromDiskHasUpdateXml { get; private set; }
|
2017-07-21 16:56:27 +02:00
|
|
|
|
private string unzippedUpdateFilePath;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public PatchingWizard_SelectPatchPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public override string Text => Messages.PATCHINGWIZARD_SELECTPATCHPAGE_TEXT;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public override string PageTitle => Messages.PATCHINGWIZARD_SELECTPATCHPAGE_TITLE;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public override string HelpID => "SelectUpdate";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-01-10 14:24:42 +01:00
|
|
|
|
public KeyValuePair<XenServerPatch, string> PatchFromDisk { get; private set; }
|
2018-02-05 13:36:49 +01:00
|
|
|
|
|
2018-03-09 00:55:50 +01:00
|
|
|
|
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (direction == PageLoadedDirection.Forward)
|
|
|
|
|
{
|
2021-05-21 16:13:45 +02:00
|
|
|
|
SelectedPatchFilePath = null;
|
2016-10-05 00:26:35 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
if (!WizardHelpers.IsValidFile(FilePath, out var pathFailure))
|
|
|
|
|
using (var dlg = new ErrorDialog(pathFailure) {WindowTitle = Messages.UPDATES})
|
|
|
|
|
{
|
|
|
|
|
cancel = true;
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 00:26:35 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
SelectedPatchFilePath = FilePath;
|
|
|
|
|
|
|
|
|
|
if (Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip"))
|
2018-11-07 16:21:10 +01:00
|
|
|
|
{
|
2021-05-21 16:13:45 +02:00
|
|
|
|
//check if we are installing the update the user sees in the textbox
|
|
|
|
|
if (unzippedUpdateFilePath == null || !File.Exists(unzippedUpdateFilePath) ||
|
|
|
|
|
Path.GetFileNameWithoutExtension(unzippedUpdateFilePath) != Path.GetFileNameWithoutExtension(FilePath))
|
|
|
|
|
{
|
|
|
|
|
unzippedUpdateFilePath = WizardHelpers.ExtractUpdate(FilePath, this);
|
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
if (!WizardHelpers.IsValidFile(unzippedUpdateFilePath, out var zipFailure))
|
|
|
|
|
{
|
|
|
|
|
using (var dlg = new ErrorDialog(zipFailure) {WindowTitle = Messages.UPDATES})
|
2016-03-14 17:10:16 +01:00
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
cancel = true;
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
return;
|
2016-03-14 17:10:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-31 20:00:35 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
if (!UnzippedUpdateFiles.Contains(unzippedUpdateFilePath))
|
|
|
|
|
UnzippedUpdateFiles.Add(unzippedUpdateFilePath);
|
|
|
|
|
|
|
|
|
|
SelectedPatchFilePath = unzippedUpdateFilePath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
unzippedUpdateFilePath = null;
|
2018-11-07 16:21:10 +01:00
|
|
|
|
|
2022-04-14 12:36:55 +02:00
|
|
|
|
if (SelectedPatchFilePath.ToLowerInvariant().EndsWith($".{BrandManager.ExtensionUpdate.ToLowerInvariant()}"))
|
2021-05-21 16:13:45 +02:00
|
|
|
|
SelectedUpdateType = UpdateType.Legacy;
|
2022-04-14 12:36:55 +02:00
|
|
|
|
else if (SelectedPatchFilePath.ToLowerInvariant().EndsWith(".iso"))
|
2021-05-21 16:13:45 +02:00
|
|
|
|
SelectedUpdateType = UpdateType.ISO;
|
2020-04-19 03:50:18 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
AlertFromFileOnDisk = GetAlertFromFile(SelectedPatchFilePath, out var hasUpdateXml, out var isUpgradeIso);
|
2020-04-19 03:50:18 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
if (isUpgradeIso)
|
|
|
|
|
{
|
|
|
|
|
using (var dlg = new ErrorDialog(Messages.PATCHINGWIZARD_SELECTPATCHPAGE_ERROR_MAINISO))
|
|
|
|
|
dlg.ShowDialog(this);
|
2020-04-19 03:50:18 +02:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
cancel = true;
|
|
|
|
|
return;
|
2016-05-31 20:00:35 +02:00
|
|
|
|
}
|
2016-03-16 13:59:20 +01:00
|
|
|
|
|
2021-05-21 16:13:45 +02:00
|
|
|
|
FileFromDiskHasUpdateXml = hasUpdateXml;
|
|
|
|
|
PatchFromDisk = AlertFromFileOnDisk == null
|
|
|
|
|
? new KeyValuePair<XenServerPatch, string>(null, null)
|
|
|
|
|
: new KeyValuePair<XenServerPatch, string>(AlertFromFileOnDisk.Patch, SelectedPatchFilePath);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 03:50:18 +02:00
|
|
|
|
private XenServerPatchAlert GetAlertFromFile(string fileName, out bool hasUpdateXml, out bool isUpgradeIso)
|
2015-07-20 16:27:41 +02:00
|
|
|
|
{
|
2020-04-19 03:50:18 +02:00
|
|
|
|
var alertFromIso = GetAlertFromIsoFile(fileName, out hasUpdateXml, out isUpgradeIso);
|
2018-03-14 13:12:18 +01:00
|
|
|
|
if (alertFromIso != null)
|
|
|
|
|
return alertFromIso;
|
|
|
|
|
|
|
|
|
|
// couldn't find an alert from the information in the iso file, try matching by name
|
|
|
|
|
return Updates.FindPatchAlertByName(Path.GetFileNameWithoutExtension(fileName));
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 03:50:18 +02:00
|
|
|
|
private XenServerPatchAlert GetAlertFromIsoFile(string fileName, out bool hasUpdateXml, out bool isUpgradeIso)
|
2018-03-14 13:12:18 +01:00
|
|
|
|
{
|
2018-07-06 18:31:29 +02:00
|
|
|
|
hasUpdateXml = false;
|
2020-04-19 03:50:18 +02:00
|
|
|
|
isUpgradeIso = false;
|
2018-07-06 18:31:29 +02:00
|
|
|
|
|
2022-04-14 12:36:55 +02:00
|
|
|
|
if (!fileName.ToLowerInvariant().EndsWith(".iso"))
|
2018-03-14 13:12:18 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var xmlDoc = new XmlDocument();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-04-24 17:04:41 +02:00
|
|
|
|
using (var isoStream = File.OpenRead(fileName))
|
2018-03-14 13:12:18 +01:00
|
|
|
|
{
|
|
|
|
|
var cd = new CDReader(isoStream, true);
|
|
|
|
|
if (cd.Exists("Update.xml"))
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = cd.OpenFile("Update.xml", FileMode.Open))
|
|
|
|
|
{
|
|
|
|
|
xmlDoc.Load(fileStream);
|
2018-07-06 18:31:29 +02:00
|
|
|
|
hasUpdateXml = true;
|
2018-03-14 13:12:18 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-19 03:50:18 +02:00
|
|
|
|
|
|
|
|
|
if (cd.Exists(@"repodata\repomd.xml") && cd.FileExists(".treeinfo"))
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = cd.OpenFile(".treeinfo", FileMode.Open))
|
|
|
|
|
{
|
|
|
|
|
var iniDoc = new IniDocument(fileStream);
|
|
|
|
|
var entry = iniDoc.FindEntry("platform", "name");
|
|
|
|
|
if (entry != null && entry.Value == "XCP")
|
|
|
|
|
{
|
|
|
|
|
isUpgradeIso = true;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-14 13:12:18 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
2015-07-20 16:27:41 +02:00
|
|
|
|
{
|
2019-11-08 13:53:24 +01:00
|
|
|
|
log.Error("Exception while reading the update data from the iso file:", exception);
|
2018-03-14 13:12:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elements = xmlDoc.GetElementsByTagName("update");
|
|
|
|
|
var update = elements.Count > 0 ? elements[0] : null;
|
|
|
|
|
|
|
|
|
|
if (update == null || update.Attributes == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2018-03-16 15:00:07 +01:00
|
|
|
|
var uuid = update.Attributes["uuid"];
|
|
|
|
|
return uuid != null ? Updates.FindPatchAlertByUuid(uuid.Value) : null;
|
2015-07-20 16:27:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public override bool EnableNext()
|
|
|
|
|
{
|
2021-05-21 16:13:45 +02:00
|
|
|
|
return WizardHelpers.IsValidFile(FilePath, out _);
|
2016-08-08 12:41:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 11:36:22 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// List to store unzipped files to be removed later by PatchingWizard
|
|
|
|
|
/// </summary>
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public List<string> UnzippedUpdateFiles { get; } = new List<string>();
|
2017-07-21 16:56:27 +02:00
|
|
|
|
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public string FilePath
|
2017-07-21 16:56:27 +02:00
|
|
|
|
{
|
2020-01-03 11:04:00 +01:00
|
|
|
|
get => fileNameTextBox.Text;
|
|
|
|
|
set => fileNameTextBox.Text = value;
|
2015-07-09 17:32:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 11:04:00 +01:00
|
|
|
|
public UpdateType SelectedUpdateType { get; private set; }
|
|
|
|
|
|
|
|
|
|
public string SelectedPatchFilePath { get; private set; }
|
|
|
|
|
|
2018-10-04 15:33:17 +02:00
|
|
|
|
|
|
|
|
|
private void BrowseButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var suppPack = WizardHelpers.GetSuppPackFromDisk(this);
|
|
|
|
|
if (!string.IsNullOrEmpty(suppPack))
|
|
|
|
|
FilePath = suppPack;
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 12:41:42 +02:00
|
|
|
|
private void fileNameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnPageUpdated();
|
|
|
|
|
}
|
2020-01-03 11:04:00 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
public enum UpdateType { Legacy, ISO }
|
2016-08-08 12:41:42 +02:00
|
|
|
|
}
|