Updated manager and added appx manifest reader.

This commit is contained in:
Bruce
2026-01-24 22:06:55 +08:00
parent 75cb72964d
commit 503ece1c64
60 changed files with 4980 additions and 3819 deletions
+1
View File
@@ -62,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataInterface.cs" />
<Compile Include="ManifestReader.cs" />
<Compile Include="PackageManager.cs" />
<Compile Include="PackageReader.cs" />
<Compile Include="PkgMgrNative.cs" />
File diff suppressed because it is too large Load Diff
+7 -3
View File
@@ -77,7 +77,8 @@ namespace AppxPackage
private string familyName = "";
private string fullName = "";
private string resourceId = "";
public PMIdentity (string _name, string _publisher, DataUtils.Version _ver, IEnumerable<Architecture> _archs, string _family, string _full, string _resid)
private string publisherId = "";
public PMIdentity (string _name, string _publisher, DataUtils.Version _ver, IEnumerable<Architecture> _archs, string _family, string _full, string _resid, string _publisherId)
{
name = _name;
publisher = _publisher;
@@ -86,6 +87,7 @@ namespace AppxPackage
familyName = _family;
fullName = _full;
resourceId = _resid;
publisherId = _publisherId;
}
public PMIdentity (PackageManageHelper.FIND_PACKAGE_ID pkgId) :
this (
@@ -95,7 +97,8 @@ namespace AppxPackage
new Architecture [] { (Architecture)pkgId.wProcessArchitecture },
Marshal.PtrToStringUni (pkgId.lpFamilyName),
Marshal.PtrToStringUni (pkgId.lpFullName),
Marshal.PtrToStringUni (pkgId.lpResourceId)
Marshal.PtrToStringUni (pkgId.lpResourceId),
Marshal.PtrToStringUni (pkgId.lpPublisherId)
)
{ }
public string FamilyName => familyName;
@@ -103,8 +106,9 @@ namespace AppxPackage
public string Name => name;
public List<Architecture> ProcessArchitecture => archs.ToList ();
public string Publisher => publisher;
public string PublisherId => publisherId;
public string ResourceId => resourceId;
DataUtils.Version IIdentity.Version => version;
public DataUtils.Version Version => version;
}
[ComVisible (true)]
[ClassInterface (ClassInterfaceType.AutoDual)]
+5 -5
View File
@@ -104,10 +104,10 @@ namespace AppxPackage
[ClassInterface (ClassInterfaceType.AutoDual)]
public class BaseInfoSectWithPRI: BaseInfoSection
{
protected Ref<PackageReader> m_reader = null;
protected Ref<PriReaderBundle> m_priBundle = null;
protected Ref<bool> m_usePri = false;
protected Ref<bool> m_enablePri = false;
protected Ref<PackageReader> m_reader = new Ref<PackageReader> (null);
protected Ref<PriReaderBundle> m_priBundle = new Ref<PriReaderBundle> (null);
protected Ref<bool> m_usePri = new Ref<bool> (false);
protected Ref<bool> m_enablePri = new Ref<bool> (false);
public BaseInfoSectWithPRI (ref IntPtr hReader, PackageReader reader, ref PriReaderBundle priBundle, ref bool usePri, ref bool enablePri) : base (ref hReader)
{
m_reader.Set (reader);
@@ -1168,7 +1168,7 @@ namespace AppxPackage
public PackageReader (string filePath) { FilePath = filePath; }
public PackageReader () { }
public string JSONText { get { return BuildJsonText (); } }
private string BuildJsonText ()
public string BuildJsonText ()
{
var obj = BuildJsonObject ();
return Newtonsoft.Json.JsonConvert.SerializeObject (
+100 -1
View File
@@ -210,7 +210,8 @@ namespace NativeWrappers
string s = Marshal.PtrToStringUni (nativePtr);
try
{
crt_free (nativePtr);
PackageReaderFreeString (nativePtr);
nativePtr = IntPtr.Zero;
}
catch
{
@@ -303,5 +304,103 @@ namespace NativeWrappers
{
}
}
// ================= Manifest Reader =================
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
public static extern IntPtr CreateManifestReader ();
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool LoadManifestFromFile (
IntPtr hReader,
string lpFilePath
);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
public static extern void DestroyManifestReader (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern ushort GetManifestType (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool IsManifestValid (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern ushort GetManifestRole (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
public static extern IntPtr GetManifestIdentityStringValue (
IntPtr hReader,
uint dwName
);
[DllImport (DllName, CallingConvention = CallConv)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool GetManifestIdentityVersion (
IntPtr hReader,
out VERSION pVersion
);
[DllImport (DllName, CallingConvention = CallConv)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool GetManifestIdentityArchitecture (
IntPtr hReader,
out DWORD pdwArchi
);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
public static extern IntPtr GetManifestPropertiesStringValue (
IntPtr hReader,
string lpName
);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
public static extern HRESULT GetManifestPropertiesBoolValue (
IntPtr hReader,
string lpName,
out BOOL pRet
);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool AddManifestApplicationItemGetName (string lpName);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool RemoveManifestApplicationItemGetName (string lpName);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestApplications (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern void DestroyManifestApplications (IntPtr hEnumerator);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestResourcesLanguages (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestResourcesLanguagesToLcid (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestResourcesScales (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern DWORD GetManifestResourcesDxFeatureLevels (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestDependencesInfoList (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestCapabilitiesList (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern IntPtr GetManifestDeviceCapabilitiesList (IntPtr hReader);
[DllImport (DllName, CallingConvention = CallConv, CharSet = CharSet.Unicode)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool GetManifestPrerequisite (
IntPtr hReader,
string lpName,
out VERSION pVerRet
);
[DllImport (DllName, CallingConvention = CallConv)]
public static extern void PackageReaderFreeString (IntPtr p);
}
}
+3 -1
View File
@@ -57,11 +57,13 @@ namespace AppxPackage
[DllImport (DLL, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs (UnmanagedType.Bool)]
public static extern bool IsMsResourceUri ([MarshalAs (UnmanagedType.LPWStr)] string pResUri);
[DllImport (DLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void PriFormatFreeString (IntPtr ptr);
public static string PtrToString (IntPtr ptr)
{
if (ptr == IntPtr.Zero) return null;
string s = Marshal.PtrToStringUni (ptr);
Marshal.FreeHGlobal (ptr); // 如果 DLL 返回的内存要求 free
PriFormatFreeString (ptr); // 如果 DLL 返回的内存要求 free
return s;
}
[DllImport (DLL, CallingConvention = CallingConvention.Cdecl)]