Skip to content

Commit

Permalink
MP1-5185: MPE: Fix/Improve MediaPortal dependency versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Dec 17, 2023
1 parent b6727b1 commit a45865e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int GetHashCode(UsesSubsystemAttribute obj)

private static readonly HashSet<Assembly> AppAssemblies = new HashSet<Assembly>();
private static readonly Dictionary<string, Version> SubSystemVersions = new Dictionary<string, Version>();
private static readonly Version AppVersion;
public static readonly Version AppVersion;
public static readonly Version SkinVersion = new Version(1, 4, 0, 0);
private static readonly string MinRequiredVersionDefault = "1.1.8.0"; // 1.2.0 RC1

Expand Down
92 changes: 77 additions & 15 deletions mediaportal/MPE/MpeCore/Classes/DependencyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ namespace MpeCore.Classes
{
public class DependencyItem
{
private string _name;
private string _message;
private VersionInfo _MinVersion = new VersionInfo();
private VersionInfo _MaxVersion = new VersionInfo();

public DependencyItem()
{
Type = string.Empty;
Id = string.Empty;
MinVersion = new VersionInfo();
MaxVersion = new VersionInfo();
WarnOnly = true;
Message = string.Empty;
Name = string.Empty;
Expand All @@ -41,34 +44,90 @@ public DependencyItem(string type)
{
Type = type;
Id = string.Empty;
MinVersion = new VersionInfo();
MaxVersion = new VersionInfo();
WarnOnly = true;
Message = string.Empty;
Name = string.Empty;
}

public string Type { get; set; }

public string Id { get; set; }
public VersionInfo MinVersion { get; set; }
public VersionInfo MaxVersion { get; set; }
public bool WarnOnly { get; set; }

private string _message;
public VersionInfo MinVersion
{
get
{
return this._MinVersion;
}
set
{
//Check old MP versioning
if (this.Type != "MediaPortal" || value.Major != "1" || value.Minor != "1" || value.Build != "6" || value.Revision != "27644")
{
this._MinVersion = value;
this._message = null; //force to reload the message
}
}
}

public VersionInfo MaxVersion
{
get
{
return this._MaxVersion;
}
set
{
//Check old MP versioning
if (this.Type != "MediaPortal" || value.Major != "1" || value.Minor != "1" || value.Build != "6" || value.Revision != "27644")
{
this._MaxVersion = value;
this._message = null; //force to reload the message
}
}
}

public bool WarnOnly { get; set; }

public string Message
{
get
{
if (!string.IsNullOrEmpty(_message)
) return _message;
return string.Format("requires {0} version {1} to {2}.", Name, MinVersion, MaxVersion);
if (this._message == null)
{
if (!this.MinVersion.IsAnyVersion && this.MaxVersion.IsAnyVersion)
{
this._message = string.Format("Requires {0} {1} or higher!",
this.Name,
this.MinVersion);
}
else if (this.MinVersion.IsAnyVersion && !this.MaxVersion.IsAnyVersion)
{
this._message = string.Format("Requires {0} {1} or lower!",
this.Name,
this.MaxVersion);
}
else if (!this.MinVersion.IsAnyVersion && !this.MaxVersion.IsAnyVersion)
{
if (this.MinVersion.ToString().Equals(this.MaxVersion.ToString()))
this._message = string.Format("Requires {0} {1}!",
this.Name,
this.MinVersion);
else
this._message = string.Format("Requires {0} from {1} to {2}!",
this.Name,
this.MinVersion,
this.MaxVersion);
}
else
this._message = string.Empty;
}

return this._message;
}
set { _message = value; }
}

private string _name;

public string Name
{
get
Expand All @@ -81,8 +140,11 @@ public string Name

public override string ToString()
{
return string.Format("{0}{1}({2})-({3})", Type,
"", MinVersion, MaxVersion);
return string.Format("{0}{1} ({2})-({3})",
Type,
string.Empty,
MinVersion,
MaxVersion);
}
}
}
44 changes: 32 additions & 12 deletions mediaportal/MPE/MpeCore/Classes/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public override int GetHashCode()
/// </summary>
public VersionInfo()
{
Major = "0";
Minor = "0";
Build = "0";
Revision = "0";
Major = "*";
Minor = "*";
Build = "*";
Revision = "*";
}

public VersionInfo(Version version)
Expand All @@ -75,32 +75,41 @@ public VersionInfo(Version version)

public string Major
{
get { return string.IsNullOrEmpty(_major) ? "0" : _major; }
set { _major = value; }
get { return string.IsNullOrEmpty(_major) ? "*" : _major; }
set { _major = SanityValue(value); }
}

private string _minor;

public string Minor
{
get { return string.IsNullOrEmpty(_minor) ? "0" : _minor; }
set { _minor = value; }
get { return string.IsNullOrEmpty(_minor) ? "*" : _minor; }
set { _minor = SanityValue(value); }
}

private string _build;

public string Build
{
get { return string.IsNullOrEmpty(_build) ? "0" : _build; }
set { _build = value; }
get { return string.IsNullOrEmpty(_build) ? "*" : _build; }
set { _build = SanityValue(value); }
}

private string _revision;

public string Revision
{
get { return string.IsNullOrEmpty(_revision) ? "0" : _revision; }
set { _revision = value; }
get { return string.IsNullOrEmpty(_revision) ? "*" : _revision; }
set { _revision = SanityValue(value); }
}

public bool IsAnyVersion
{
get
{
return this._major == "*" && this._minor == "*"
&& this._build == "*" && this._revision == "*";
}
}

public static VersionInfo Parse(string s)
Expand Down Expand Up @@ -206,5 +215,16 @@ private static int CompareNumber(string s1, string s2)
{
return v1.CompareTo(v2) > 0;
}


private static string SanityValue(string strValue)
{
int i;
if (string.IsNullOrWhiteSpace(strValue) || !int.TryParse(strValue, out i))
return "*";

return i.ToString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,32 @@ namespace MpeCore.Classes.VersionProvider
{
public class MediaPortalVersion : VersionProvider
{
public static readonly VersionInfo MinimumMPVersionRequired = new VersionInfo(MediaPortal.Common.Utils.CompatibilityManager.GetCurrentVersion());

public override string DisplayName
{
get { return "MediaPortal"; }
}

public override bool Validate(DependencyItem dependency)
{
if (dependency.MinVersion < MinimumMPVersionRequired)
return false;

return base.Validate(dependency);
}

public override VersionInfo Version(string id)
{
return new VersionInfo(MediaPortal.Common.Utils.CompatibilityManager.GetCurrentVersion());
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MediaPortal");
if (key != null)
{
VersionInfo version = new VersionInfo
{
Build = ((int)key.GetValue("VersionBuild", 0)).ToString(),
Major = ((int)key.GetValue("VersionMajor", 0)).ToString(),
Minor = ((int)key.GetValue("VersionMinor", 0)).ToString(),
Revision = ((int)key.GetValue("VersionRevision", 0)).ToString(),
};
key.Close();
return version;
}
return new VersionInfo(MediaPortal.Common.Utils.CompatibilityManager.AppVersion);
}
}
}
2 changes: 1 addition & 1 deletion mediaportal/MPE/MpeInstaller/Dialogs/DependencyForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DependencyForm(MpeCore.PackageClass pak)
package = pak;
this.Text = pak.GeneralInfo.Name + " - Dependencies";
versionLabel.Text = string.Format("MediaPortal {0} (API: {1}) - Skin {2}",
MediaPortal.Common.Utils.CompatibilityManager.MediaPortalReleaseForApiVersion(MediaPortal.Common.Utils.CompatibilityManager.GetCurrentMaxVersion()),
MediaPortal.Common.Utils.CompatibilityManager.AppVersion,
MediaPortal.Common.Utils.CompatibilityManager.GetCurrentVersion(),
MediaPortal.Common.Utils.CompatibilityManager.SkinVersion);
generalDepBindSource.DataSource = package.Dependencies.Items;
Expand Down
20 changes: 11 additions & 9 deletions mediaportal/MPE/MpeMaker/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,23 @@ private void SaveProject(string filename)
Package.GenerateRelativePath(Path.GetDirectoryName(filename));
Package.GenerateUniqueFileList();
Package.SetPluginsDependencies();
DependencyItem MPDep;
if (Package.CheckMPDependency(out MPDep))
if (Package.CheckMPDependency(out DependencyItem depMP))
{
if (MPDep.MinVersion.CompareTo(MpeCore.Classes.VersionProvider.MediaPortalVersion.MinimumMPVersionRequired) < 0)
{
MPDep.MinVersion = MpeCore.Classes.VersionProvider.MediaPortalVersion.MinimumMPVersionRequired;
}
//Fix old MP versioning
Version vOld = new Version(1, 1, 6, 27644);

if (depMP.MinVersion.CompareTo(vOld) <= 0)
depMP.MinVersion = new VersionInfo();

if (depMP.MaxVersion.CompareTo(vOld) <= 0)
depMP.MaxVersion = new VersionInfo();
}
else
{
Package.CreateMPDependency();
}
FileItem skinFile;
DependencyItem dep;
if (Package.ProvidesSkin(out skinFile) && !Package.CheckSkinDependency(out dep))

if (Package.ProvidesSkin(out FileItem skinFile) && !Package.CheckSkinDependency(out DependencyItem dep))
{
Package.CreateSkinDependency(skinFile);
}
Expand Down
Loading

0 comments on commit a45865e

Please sign in to comment.