Skip to content

Commit

Permalink
MP1-5185: DeployTool: Add extension platform compatibility whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Dec 9, 2023
1 parent 84c4773 commit 2b9b2da
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
73 changes: 72 additions & 1 deletion mediaportal/MPE/MpeCore/Classes/GeneralInfoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MpeCore.Classes
{
public class GeneralInfoItem
{
private static List<GeneralInfoItem> _ExtensionsWhiteList = null;

public GeneralInfoItem()
{
Version = new VersionInfo();
Expand Down Expand Up @@ -62,7 +65,13 @@ public GeneralInfoItem()
public string Tags { get; set; }
public PlatformCompatibilityEnum PlatformCompatibility
{
get { return this._PlatformCompatibility; }
get
{
if (this.TryGetPlatformCompatibilityFromList(out PlatformCompatibilityEnum compatibility))
return compatibility;

return this._PlatformCompatibility;
}
set { this._PlatformCompatibility = value; }
} private PlatformCompatibilityEnum _PlatformCompatibility = PlatformCompatibilityEnum.x86;

Expand All @@ -78,5 +87,67 @@ public TagCollection TagList
{
get { return new TagCollection(Tags); }
}

private bool TryGetPlatformCompatibilityFromList(out PlatformCompatibilityEnum compatibility)
{
compatibility = PlatformCompatibilityEnum.x86;

if (_ExtensionsWhiteList == null)
{
//Build extension list from embeded resource txt file
try
{
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MpeCore.Data.ExtensionPlatformCompatibilityList.txt"))
{
List<GeneralInfoItem> list = new List<GeneralInfoItem>();
StreamReader sr = new StreamReader(stream);
string strLine;
while (!sr.EndOfStream)
{
strLine = sr.ReadLine().Trim();
if (string.IsNullOrWhiteSpace(strLine) || strLine.StartsWith("#"))
continue;

//#GUID;VERSION;COMPATIBILITY;DESCRIPTION
string[] parts = strLine.Split(';');
if (parts.Length < 4)
continue;

VersionInfo version = new VersionInfo(new Version(parts[1]));

if (list.Exists(p => p.Id.Equals(parts[0], StringComparison.CurrentCultureIgnoreCase) && p.Version == version))
continue;

list.Add(new GeneralInfoItem()
{
Id = parts[0],
Version = version,
PlatformCompatibility = (PlatformCompatibilityEnum)Enum.Parse(typeof(PlatformCompatibilityEnum), parts[2]),
ExtensionDescription = parts[3]
});

}

//Set the extension list
_ExtensionsWhiteList = list;
}

}
catch
{
return false;
}
}

//Try find the extension in the whitelist
GeneralInfoItem gi = _ExtensionsWhiteList.Find(p => p.Id.Equals(this.Id, StringComparison.CurrentCultureIgnoreCase) && p.Version == this.Version);
if (gi != null)
{
compatibility = gi._PlatformCompatibility; //use private field to avoid recursion
return true;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#GUID;VERSION;COMPATIBILITY;DESCRIPTION
b7738156-b6ec-4f0f-b1a8-b5010349d8b1;0.78.0.0;AnyCPU;LAV Filters
e14cf436-6e19-4b40-b65f-3bbc934ae521;1.11.0.2;AnyCPU;SchedulesDirect Plugin
3 changes: 3 additions & 0 deletions mediaportal/MPE/MpeCore/MpeCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@
<ItemGroup>
<None Include="Resources\Bottom.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\ExtensionPlatformCompatibilityList.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 2b9b2da

Please sign in to comment.