Skip to content

Commit

Permalink
MP1-5185: MPE: Add execution condition to individual parts (Dependenc…
Browse files Browse the repository at this point in the history
…y, Section, Action)
  • Loading branch information
epbk committed Jan 21, 2024
1 parent afa0e54 commit 5a20a79
Show file tree
Hide file tree
Showing 26 changed files with 1,541 additions and 1,275 deletions.
14 changes: 14 additions & 0 deletions mediaportal/MPE/MpeCore/ActionConditionEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MpeCore
{
public enum ActionConditionEnum
{
None = 0,
PlatformTarget_x86 = 1,
PlatformTarget_x64 = 2
}
}
4 changes: 4 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/ActionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ActionItem(string actionType)
Params = new SectionParamCollection();
ConditionGroup = string.Empty;
ExecuteLocation = ActionExecuteLocationEnum.AfterPanelShow;
Condition = ActionConditionEnum.None;
}

[XmlAttribute]
Expand All @@ -62,6 +63,9 @@ public ActionItem(string actionType)
[XmlAttribute]
public string ConditionGroup { get; set; }

[XmlAttribute]
public ActionConditionEnum Condition { get; set; }

public ActionExecuteLocationEnum ExecuteLocation { get; set; }

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public ValidationResponse Validate(PackageClass packageClass, ActionItem actionI
if (!string.IsNullOrEmpty(actionItem.Params[Const_Loc].Value) && !File.Exists(actionItem.Params[Const_Loc].Value))
return new ValidationResponse()
{ Valid = false, Message = "File not found " + actionItem.Params[Const_Loc].Value};
if (!string.IsNullOrEmpty(actionItem.Params[Const_Guid].Value) && MpeInstaller.KnownExtensions.Get(actionItem.Params[Const_Guid].Value, ApplicationSettings.Instance.PlatformCompatibilityCheck) == null)
if (!string.IsNullOrEmpty(actionItem.Params[Const_Guid].Value) && MpeInstaller.KnownExtensions.Get(actionItem.Params[Const_Guid].Value, false) == null)
return new ValidationResponse()
{ Valid = false, Message = "Extension with Id " + actionItem.Params[Const_Loc].Value + " unknown" };
{ Valid = false, Message = "Extension with Id " + actionItem.Params[Const_Guid].Value + " unknown" };
if (!string.IsNullOrEmpty(actionItem.ConditionGroup) && packageClass.Groups[actionItem.ConditionGroup] == null)
return new ValidationResponse()
{ Valid = false, Message = actionItem.Name + " condition group not found " + actionItem.ConditionGroup };
Expand Down
2 changes: 1 addition & 1 deletion mediaportal/MPE/MpeCore/Classes/ActionType/InstallFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SectionParamCollection GetDefaultParams()
public SectionResponseEnum Execute(PackageClass packageClass, ActionItem actionItem)
{
packageClass.FileInstalled += packageClass_FileInstalled;
packageClass.Install();
packageClass.Install(actionItem.ConditionGroup);
packageClass.FileInstalled -= packageClass_FileInstalled;
return SectionResponseEnum.Ok;
}
Expand Down
4 changes: 4 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/DependencyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public DependencyItem()
WarnOnly = true;
Message = string.Empty;
Name = string.Empty;
Condition = ActionConditionEnum.None;
}

public DependencyItem(string type)
Expand All @@ -47,6 +48,7 @@ public DependencyItem(string type)
WarnOnly = true;
Message = string.Empty;
Name = string.Empty;
Condition = ActionConditionEnum.None;
}

public string Type { get; set; }
Expand Down Expand Up @@ -138,6 +140,8 @@ public string Name
set { _name = value; }
}

public ActionConditionEnum Condition { get; set; }

public override string ToString()
{
return string.Format("{0}{1} ({2})-({3})",
Expand Down
4 changes: 4 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/SectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public SectionItem()
ConditionGroup = string.Empty;
Actions = new ActionItemCollection();
WizardButtonsEnum = Classes.WizardButtonsEnum.BackNextCancel;
Condition = ActionConditionEnum.None;
}

//public SectionItem(SectionItem obj)
Expand All @@ -60,6 +61,9 @@ public SectionItem()
[XmlAttribute]
public string ConditionGroup { get; set; }

[XmlAttribute]
public ActionConditionEnum Condition { get; set; }

public WizardButtonsEnum WizardButtonsEnum { get; set; }

public override string ToString()
Expand Down
2 changes: 2 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/SectionPanel/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static SectionResponseEnum ActionExecute(PackageClass packageClass, Secti
continue;
if (!string.IsNullOrEmpty(list.ConditionGroup) && !packageClass.Groups[list.ConditionGroup].Checked)
continue;
if (!Util.IsConditionSatisfied(list.Condition))
continue;
responseEnum = MpeInstaller.ActionProviders[list.ActionType].Execute(packageClass, list);
if (responseEnum != SectionResponseEnum.Ok)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ private void InstallSection_Shown(object sender, EventArgs e)
continue;
if (!string.IsNullOrEmpty(actionItem.ConditionGroup) && !Package.Groups[actionItem.ConditionGroup].Checked)
continue;
if (!Util.IsConditionSatisfied(actionItem.Condition))
continue;

// use a new instance of the action,
// because if we chain MPE installations,
Expand Down
15 changes: 15 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,20 @@ public static void KillProcces(string name, bool silent)
}
}
}

public static bool IsConditionSatisfied(ActionConditionEnum cond)
{
switch (cond)
{
case ActionConditionEnum.PlatformTarget_x86:
return IntPtr.Size == 4;

case ActionConditionEnum.PlatformTarget_x64:
return IntPtr.Size == 8;

default:
return true;
}
}
}
}
15 changes: 9 additions & 6 deletions mediaportal/MPE/MpeCore/Classes/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ public bool IsAnyVersion
public static VersionInfo Parse(string s)
{
VersionInfo ver = new VersionInfo();
string[] vers = s.Split('.');
if (vers.Length > 3)
if (s != null)
{
ver.Major = vers[0];
ver.Minor = vers[1];
ver.Build = vers[2];
ver.Revision = vers[3];
string[] vers = s.Split('.');
if (vers.Length > 3)
{
ver.Major = vers[0];
ver.Minor = vers[1];
ver.Build = vers[2];
ver.Revision = vers[3];
}
}
return ver;
}
Expand Down
7 changes: 7 additions & 0 deletions mediaportal/MPE/MpeCore/Classes/WizardNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public SectionResponseEnum Navigate()
continue;
}
}

if (!Util.IsConditionSatisfied(currentItem.Condition))
{
pos++;
continue;
}

Response = MpeInstaller.SectionPanels[currentItem.PanelName].Execute(Package,
currentItem);
switch (Response)
Expand Down
1 change: 1 addition & 0 deletions mediaportal/MPE/MpeCore/MpeCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="..\..\..\Common-MP-TVE3\SolutionInfo.cs">
<Link>SolutionInfo.cs</Link>
</Compile>
<Compile Include="ActionConditionEnum.cs" />
<Compile Include="Classes\ActionExecuteLocationEnum.cs" />
<Compile Include="Classes\ActionItem.cs" />
<Compile Include="Classes\ActionItemCollection.cs" />
Expand Down
54 changes: 52 additions & 2 deletions mediaportal/MPE/MpeCore/PackageClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#endregion

using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
Expand Down Expand Up @@ -136,7 +137,8 @@ public void CopyGroupCheck(PackageClass packageClass)
/// Start copy the package file based on group settings
///
/// </summary>
public void Install()
/// <param name="strGroupCondition">Optional name of the group to be processed.</param>
public void Install(string strGroupCondition = null)
{
if (UnInstallInfo == null)
{
Expand All @@ -146,7 +148,7 @@ public void Install()
UnInstallInfo.SetInfo(this);
foreach (GroupItem groupItem in Groups.Items)
{
if (groupItem.Checked)
if (groupItem.Checked && (string.IsNullOrWhiteSpace(strGroupCondition) || strGroupCondition.Equals(groupItem.Name)))
{
foreach (FileItem fileItem in groupItem.Files.Items)
{
Expand Down Expand Up @@ -201,6 +203,9 @@ public bool CheckDependency(bool silent)
bool hasSkinDependency = false;
foreach (DependencyItem item in Dependencies.Items)
{
if (!Util.IsConditionSatisfied(item.Condition))
continue;

if (!hasMPDependency && item.Type == MPDependency.DisplayName)
{
hasMPDependency = true;
Expand Down Expand Up @@ -314,6 +319,51 @@ private static string ByteArrayToString(Encoding encoding, byte[] byteArray)
return encoding.GetString(byteArray);
}

/// <summary>
/// Verify MediaPortal dependency based on needs
/// </summary>
public void VerifyMPDependency()
{
DependencyItem dep;
if (this.CheckMPDependency(out dep))
{
//Fix old MP versioning; 1.1.6.27644 is considered as unset
Version vOld = new Version(1, 1, 6, 27644);

if (!dep.MinVersion.IsAnyVersion && dep.MinVersion.CompareTo(vOld) <= 0)
dep.MinVersion = new VersionInfo();

if (!dep.MinVersion.IsAnyVersion && dep.MaxVersion.CompareTo(vOld) <= 0)
dep.MaxVersion = new VersionInfo();
}
else
{
//Create MP dependancy with both max and min as *.*.*.*
Classes.VersionProvider.MediaPortalVersion mpVersion = new Classes.VersionProvider.MediaPortalVersion();
dep = CreateStrictDependency(mpVersion);
dep.MinVersion = new VersionInfo();
dep.MaxVersion = new VersionInfo();
this.Dependencies.Add(dep);
}

//Conditional execution requires MP 1.33 and higher
if (this.Dependencies.Items.Any(d => d.Condition != ActionConditionEnum.None) ||
this.Sections.Items.Any(s => s.Condition != ActionConditionEnum.None
|| s.Actions.Items.Any(a => a.Condition != ActionConditionEnum.None)))
{
VersionInfo vMin = new VersionInfo(new Version(1, 33, 0, 0));
if (dep.MinVersion.IsAnyVersion || dep.MinVersion < vMin)
dep.MinVersion = vMin;
}

//Make sure the max is always >= min
if (dep.MaxVersion < dep.MinVersion)
dep.MaxVersion = new VersionInfo();

//Refresh the dependency message
dep.Message = null;
}

/// <summary>
/// Checks if package has a MediaPortal dependency.
/// </summary>
Expand Down
Loading

0 comments on commit 5a20a79

Please sign in to comment.