mirror of
https://github.com/modernw/AppInstallerForWin8.git
synced 2026-04-11 16:57:18 +10:00
添加项目文件。
This commit is contained in:
58
PackageAdd/PackageAdd.csproj
Normal file
58
PackageAdd/PackageAdd.csproj
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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>{D3DC0F1B-6BEC-4417-AB5F-59686F2F5ED3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PackageAdd</RootNamespace>
|
||||
<AssemblyName>PackageAdd</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetPlatformVersion>8.0</TargetPlatformVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Windows" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PackageInstaller.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</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>
|
||||
70
PackageAdd/PackageInstaller.cs
Normal file
70
PackageAdd/PackageInstaller.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Management.Deployment;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace PackageAdd
|
||||
{
|
||||
public enum AsyncStatus
|
||||
{
|
||||
Started,
|
||||
Completed,
|
||||
Canceled,
|
||||
Error
|
||||
}
|
||||
public delegate void PACKAGE_ADD_CALLBACK (int progress);
|
||||
public static class PackageInstaller
|
||||
{
|
||||
public static AsyncStatus AddPackageFromFile([MarshalAs(UnmanagedType.LPWStr)] string swFilePath, IntPtr callbackPtr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(swFilePath))
|
||||
{
|
||||
return AsyncStatus.Error;
|
||||
}
|
||||
try
|
||||
{
|
||||
Uri packageUri = new Uri(swFilePath);
|
||||
PackageManager packageManager = new PackageManager();
|
||||
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = packageManager.AddPackageAsync(packageUri, null, DeploymentOptions.None);
|
||||
// 获取 C++ 传入的回调函数
|
||||
PACKAGE_ADD_CALLBACK callback = (PACKAGE_ADD_CALLBACK)Marshal.GetDelegateForFunctionPointer(callbackPtr, typeof(PACKAGE_ADD_CALLBACK));
|
||||
ManualResetEvent opCompletedEvent = new ManualResetEvent(false);
|
||||
deploymentOperation.Progress = (depProgress, progress) =>
|
||||
{
|
||||
callback?.Invoke((int)progress.percentage);
|
||||
};
|
||||
deploymentOperation.Completed = (depProgress, status) =>
|
||||
{
|
||||
opCompletedEvent.Set();
|
||||
};
|
||||
//Console.WriteLine($"Installing package {swFilePath}");
|
||||
opCompletedEvent.WaitOne();
|
||||
if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Error)
|
||||
{
|
||||
return AsyncStatus.Error;
|
||||
}
|
||||
else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Canceled)
|
||||
{
|
||||
return AsyncStatus.Canceled;
|
||||
}
|
||||
else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Completed)
|
||||
{
|
||||
return AsyncStatus.Completed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AsyncStatus.Error;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return AsyncStatus.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
PackageAdd/Properties/AssemblyInfo.cs
Normal file
36
PackageAdd/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("PackageAdd")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PackageAdd")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
//将 ComVisible 设置为 false 将使此程序集中的类型
|
||||
//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("d3dc0f1b-6bec-4417-ab5f-59686f2f5ed3")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user