2018-10-04 15:33:17 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-13 14:02:22 +01:00
|
|
|
|
using System.Collections.Generic;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
2019-04-25 14:29:49 +02:00
|
|
|
|
using DiscUtils.Iso9660;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2019-02-13 14:02:22 +01:00
|
|
|
|
using XenAPI;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Wizards
|
|
|
|
|
{
|
|
|
|
|
public static class WizardHelpers
|
|
|
|
|
{
|
|
|
|
|
public static string GetSuppPackFromDisk(Control control)
|
|
|
|
|
{
|
|
|
|
|
string oldDir = string.Empty;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
oldDir = Directory.GetCurrentDirectory();
|
|
|
|
|
using (var dlg = new OpenFileDialog
|
|
|
|
|
{
|
|
|
|
|
Multiselect = false,
|
|
|
|
|
ShowReadOnly = false,
|
|
|
|
|
Filter = string.Format(Messages.PATCHINGWIZARD_SELECTPATCHPAGE_UPDATESEXT, Branding.Update),
|
|
|
|
|
FilterIndex = 0,
|
|
|
|
|
CheckFileExists = true,
|
|
|
|
|
CheckPathExists = true,
|
|
|
|
|
ShowHelp = false,
|
|
|
|
|
Title = Messages.PATCHINGWIZARD_SELECTPATCHPAGE_CHOOSE
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
dlg.FileOk += dlg_FileOk;
|
|
|
|
|
|
|
|
|
|
if (dlg.ShowDialog(control) == DialogResult.OK)
|
|
|
|
|
return dlg.FileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(oldDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void dlg_FileOk(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var dlg = sender as OpenFileDialog;
|
|
|
|
|
if (dlg == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
if (!IsValidFile(dlg.FileName, out var failureReason))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
using (var popup = new ThreeButtonDialog(new ThreeButtonDialog.Details(
|
2018-11-07 16:21:10 +01:00
|
|
|
|
SystemIcons.Error, failureReason, Messages.UPDATES)))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
{
|
|
|
|
|
popup.ShowDialog();
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
}
|
2018-10-04 15:33:17 +02:00
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
public static string ParseSuppPackFile(string path, Control control, ref bool cancel)
|
2018-10-04 15:33:17 +02:00
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
if (!IsValidFile(path, out var pathFailure))
|
|
|
|
|
using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
|
|
|
|
|
SystemIcons.Error, pathFailure, Messages.UPDATES)))
|
|
|
|
|
{
|
|
|
|
|
cancel = true;
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-10-04 15:33:17 +02:00
|
|
|
|
|
|
|
|
|
if (Path.GetExtension(path).ToLowerInvariant().Equals(".zip"))
|
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
var unzippedPath = ExtractUpdate(path, control);
|
2018-10-04 15:33:17 +02:00
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
if (!IsValidFile(unzippedPath, out var zipFailure))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
|
2018-11-07 16:21:10 +01:00
|
|
|
|
SystemIcons.Error, zipFailure, Messages.UPDATES)))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
cancel = true;
|
|
|
|
|
dlg.ShowDialog();
|
|
|
|
|
return null;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
|
|
|
|
|
return unzippedPath;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
|
|
|
|
|
return path;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ExtractUpdate(string zippedUpdatePath, Control control)
|
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
if (string.IsNullOrEmpty(zippedUpdatePath))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var unzipAction = new DownloadAndUnzipXenServerPatchAction(Path.GetFileNameWithoutExtension(zippedUpdatePath),
|
|
|
|
|
null, zippedUpdatePath, true, Branding.Update, Branding.UpdateIso);
|
|
|
|
|
|
2018-10-04 15:33:17 +02:00
|
|
|
|
using (var dlg = new ActionProgressDialog(unzipAction, ProgressBarStyle.Marquee))
|
|
|
|
|
{
|
|
|
|
|
dlg.ShowDialog(control);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
return !string.IsNullOrEmpty(unzipAction.PatchPath) ? unzipAction.PatchPath : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsValidFile(string fileName, out string failureReason)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(fileName))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
failureReason = Messages.UPDATES_WIZARD_INVALID_FILE;
|
|
|
|
|
return false;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
|
|
|
|
|
if (!File.Exists(fileName))
|
2018-10-04 15:33:17 +02:00
|
|
|
|
{
|
2018-11-07 16:21:10 +01:00
|
|
|
|
failureReason = string.Format(Messages.UPDATES_WIZARD_FILE_NOT_FOUND, fileName);
|
|
|
|
|
return false;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 16:21:10 +01:00
|
|
|
|
bool isValidExt = fileName.ToLowerInvariant().EndsWith("." + Branding.Update.ToLowerInvariant())
|
|
|
|
|
|| fileName.ToLowerInvariant().EndsWith(".zip")
|
|
|
|
|
|| fileName.ToLowerInvariant().EndsWith(".iso");
|
|
|
|
|
|
|
|
|
|
if (!isValidExt)
|
|
|
|
|
{
|
|
|
|
|
failureReason = string.Format(Messages.UPDATES_WIZARD_INVALID_EXTENSION, Branding.Update);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 14:29:49 +02:00
|
|
|
|
if (fileName.ToLowerInvariant().EndsWith(".iso"))
|
|
|
|
|
{
|
|
|
|
|
bool isValidIso;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var isoStream = File.OpenRead(fileName))
|
|
|
|
|
using (var cd = new CDReader(isoStream, true))
|
|
|
|
|
isValidIso = cd.Root.Exists;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
isValidIso = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isValidIso)
|
|
|
|
|
{
|
|
|
|
|
failureReason = Messages.UPDATES_WIZARD_INVALID_ISO_FILE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-07 16:21:10 +01:00
|
|
|
|
failureReason = null;
|
|
|
|
|
return true;
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
2019-02-13 14:02:22 +01:00
|
|
|
|
|
|
|
|
|
public static bool IsHostRebootRequiredForUpdate(Host host, Pool_patch patch, Dictionary<string, livepatch_status> livePatchCodesByHost = null)
|
|
|
|
|
{
|
|
|
|
|
return patch.after_apply_guidance.Contains(after_apply_guidance.restartHost)
|
|
|
|
|
&& (livePatchCodesByHost == null || !livePatchCodesByHost.ContainsKey(host.uuid) || livePatchCodesByHost[host.uuid] != livepatch_status.ok_livepatch_complete);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsHostRebootRequiredForUpdate(Host host, Pool_update poolUpdate, Dictionary<string, livepatch_status> livePatchCodesByHost = null)
|
|
|
|
|
{
|
|
|
|
|
return poolUpdate.after_apply_guidance.Contains(update_after_apply_guidance.restartHost)
|
|
|
|
|
&& (livePatchCodesByHost == null || !livePatchCodesByHost.ContainsKey(host.uuid) || livePatchCodesByHost[host.uuid] != livepatch_status.ok_livepatch_complete);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 15:33:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|