mirror of
https://github.com/modernw/App-Installer-For-Windows-8.x-Reset.git
synced 2026-06-13 19:06:39 +10:00
Coding for Package Manager.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C5587B6E-19C4-4484-AA97-5C20FBB07E43}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ModernNotice</RootNamespace>
|
||||
<AssemblyName>ModernNotice</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Notice.cs" />
|
||||
<Compile Include="NoticeNative.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataUtils\DataUtils.csproj">
|
||||
<Project>{ffd3fd52-37a8-4f43-883c-de8d996cb0e0}</Project>
|
||||
<Name>DataUtils</Name>
|
||||
</ProjectReference>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,120 @@
|
||||
using System.Xml;
|
||||
using System.Runtime.InteropServices;
|
||||
using HResult = DataUtils._I_HResult;
|
||||
using System;
|
||||
|
||||
namespace ModernNotice
|
||||
{
|
||||
public static class Notice
|
||||
{
|
||||
private static XmlDocument XmlStringToDom (string xmlContent)
|
||||
{
|
||||
var ret = new XmlDocument ();
|
||||
ret.LoadXml (xmlContent);
|
||||
return ret;
|
||||
}
|
||||
private static string XmlDomToString (XmlDocument xmlDom) { return xmlDom.OuterXml; }
|
||||
private static HResult BuildHResult (int hr, IntPtr err, IntPtr msg) { return new HResult (hr, Marshal.PtrToStringUni (err), Marshal.PtrToStringUni (msg)); }
|
||||
private static HResult BuildHResult (HRESULT hr, IntPtr err, IntPtr msg) { return BuildHResult (hr.Value, err, msg); }
|
||||
private static HResult BuildHResult (int hr, IntPtr msg) { return new HResult (hr, "", Marshal.PtrToStringUni (msg)); }
|
||||
private static HResult BuildHResult (HRESULT hr, IntPtr msg) { return BuildHResult (hr.Value, msg); }
|
||||
private static HResult BuildHResult (int hr) { return new HResult (hr); }
|
||||
private static HResult BuildHResult (HRESULT hr) { return BuildHResult (hr.Value); }
|
||||
public static string GetTemplateString (string templateName)
|
||||
{
|
||||
var ptr = Native.GetToastNoticeXml (templateName);
|
||||
try { var ret = Marshal.PtrToStringUni (ptr) ?? ""; return ret; }
|
||||
finally { Native.NoticeApiFreeString (ptr); }
|
||||
}
|
||||
public static XmlDocument GetTemplate (string templateName) { return XmlStringToDom (GetTemplateString (templateName)); }
|
||||
public static string GetSimpleTemplateString (string content, string imagePath)
|
||||
{
|
||||
var ptr = Native.GenerateSimpleToastNoticeXml (content, imagePath);
|
||||
try { var ret = Marshal.PtrToStringUni (ptr) ?? ""; return ret; }
|
||||
finally { Native.NoticeApiFreeString (ptr); }
|
||||
}
|
||||
public static XmlDocument GetSimpleTemplate (string content, string imagePath = null) { return XmlStringToDom (GetSimpleTemplateString (content, imagePath)); }
|
||||
public static string GetSimpleTemplateString2 (string title, string content = null, string imagePath = null)
|
||||
{
|
||||
var ptr = Native.GenerateSimpleToastNoticeXml2 (title, content, imagePath);
|
||||
try { var ret = Marshal.PtrToStringUni (ptr) ?? ""; return ret; }
|
||||
finally { Native.NoticeApiFreeString (ptr); }
|
||||
}
|
||||
public static XmlDocument GetSimpleTemplate2 (string title, string content = null, string imagePath = null) { return XmlStringToDom (GetSimpleTemplateString2 (title, content, imagePath)); }
|
||||
public static HResult Create (string appUserId, XmlDocument xml)
|
||||
{
|
||||
IntPtr dt = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var hr = Native.CreateToastNoticeFromXmlDocument (appUserId, XmlDomToString (xml), null, IntPtr.Zero, out dt);
|
||||
return BuildHResult (hr, dt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dt != IntPtr.Zero) Native.NoticeApiFreeString (dt);
|
||||
}
|
||||
}
|
||||
public static HResult Create (string appUserId, string content, string imagePath = null)
|
||||
{
|
||||
var xml = GetSimpleTemplate (content, imagePath);
|
||||
return Create (appUserId, xml);
|
||||
}
|
||||
public static HResult Create (string appUserId, string title, string content, string imagePath = null)
|
||||
{
|
||||
var xml = GetSimpleTemplate2 (title, content, imagePath);
|
||||
return Create (appUserId, xml);
|
||||
}
|
||||
public static HResult Create (string appUserId, string content, IntPtr img)
|
||||
{
|
||||
IntPtr dt = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var hr = Native.CreateToastNoticeWithIStream (appUserId, content, img, null, IntPtr.Zero, out dt);
|
||||
return BuildHResult (hr, dt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dt != IntPtr.Zero) Native.NoticeApiFreeString (dt);
|
||||
}
|
||||
}
|
||||
public static HResult Create (string appUserId, string title, string content, IntPtr img)
|
||||
{
|
||||
IntPtr dt = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var hr = Native.CreateToastNoticeWithIStream2 (appUserId, title, content, img, null, IntPtr.Zero, out dt);
|
||||
return BuildHResult (hr, dt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dt != IntPtr.Zero) Native.NoticeApiFreeString (dt);
|
||||
}
|
||||
}
|
||||
public static HResult CreateWithImgBase64 (string appUserId, string content, string imageBase64)
|
||||
{
|
||||
IntPtr dt = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var hr = Native.CreateToastNoticeWithImgBase64 (appUserId, content, imageBase64, null, IntPtr.Zero, out dt);
|
||||
return BuildHResult (hr, dt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dt != IntPtr.Zero) Native.NoticeApiFreeString (dt);
|
||||
}
|
||||
}
|
||||
public static HResult CreateWithImgBase64 (string appUserId, string title, string content, string imageBase64)
|
||||
{
|
||||
IntPtr dt = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
var hr = Native.CreateToastNotice2WithImgBase64 (appUserId, title, content, imageBase64, null, IntPtr.Zero, out dt);
|
||||
return BuildHResult (hr, dt);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dt != IntPtr.Zero) Native.NoticeApiFreeString (dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ModernNotice
|
||||
{
|
||||
// HRESULT = int
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
public struct HRESULT
|
||||
{
|
||||
public int Value;
|
||||
}
|
||||
|
||||
// Callback delegate
|
||||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
public delegate void NOTICE_ACTIVECALLBACK (IntPtr pCustom);
|
||||
|
||||
public static class Native
|
||||
{
|
||||
private const string DLL = "notice.dll"; // 改成你的 dll 名称
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr GetToastNoticeXml (string lpTemplateName);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr GenerateSimpleToastNoticeXml (string lpText, string lpImagePath);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr GenerateSimpleToastNoticeXml2 (string lpTitle, string lpText, string lpImagePath);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNoticeFromXmlDocument (
|
||||
string lpIdName,
|
||||
string lpXmlString,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNotice (
|
||||
string lpIdName,
|
||||
string lpText,
|
||||
string lpImgPath,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNotice2 (
|
||||
string lpIdName,
|
||||
string lpTitle,
|
||||
string lpText,
|
||||
string lpImgPath,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNoticeWithIStream2 (
|
||||
string lpIdName,
|
||||
string lpTitle,
|
||||
string lpText,
|
||||
IntPtr pIImgStream,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNoticeWithIStream (
|
||||
string lpIdName,
|
||||
string lpText,
|
||||
IntPtr pIImgStream,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int NoticeGetLastHResult ();
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr NoticeGetLastDetailMessage ();
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateShortcutWithAppIdW (
|
||||
string pszShortcutPath,
|
||||
string pszTargetPath,
|
||||
string pszAppId,
|
||||
out IntPtr lpException
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void NoticeApiFreeString (IntPtr lpstr);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNoticeWithImgBase64 (
|
||||
string lpIdName,
|
||||
string lpText,
|
||||
string lpImgBase64,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
|
||||
[DllImport (DLL, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int CreateToastNotice2WithImgBase64 (
|
||||
string lpIdName,
|
||||
string lpTitle,
|
||||
string lpText,
|
||||
string lpImgBase64,
|
||||
NOTICE_ACTIVECALLBACK pfCallback,
|
||||
IntPtr pCustom,
|
||||
out IntPtr lpExceptMsg
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("ModernNotice")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ModernNotice")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2026")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//将 ComVisible 设置为 false 将使此程序集中的类型
|
||||
//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible (true)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("c5587b6e-19c4-4484-aa97-5c20fbb07e43")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user