添加项目文件。

This commit is contained in:
Bruce
2025-02-19 21:09:40 +08:00
parent 11c6392497
commit 3a70be9491
135 changed files with 12698 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "stdafx.h"
#include "PackageManager.h"
#include <iostream>
using namespace std;
void callback (unsigned progress)
{
std::cout << '\r' << progress << "%" << std::ends;
}
[MTAThread]
int __cdecl main(Platform::Array<String^>^ args)
{
wcout << L"Copyright (c) Microsoft Corporation. All rights reserved." << endl;
wcout << L"Add Package" << endl << endl;
if (args->Length < 2)
{
wcout << L"Usage: addpkg.exe packageUri" << endl;
return 1;
}
HANDLE completedEvent = nullptr;
int returnValue = 0;
String^ inputPackageUri = args[1];
cout << endl;
AddPackageFromPath (inputPackageUri->Data (), &callback);
return 0;
}

View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCTargetsPath Condition="'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and '$(VisualStudioVersion)' == ''">$(VCTargetsPath11)</VCTargetsPath>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{59131AB7-2A7D-9A09-8223-174C3F5E0F57}</ProjectGuid>
<ProjectName>PriReader</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<ReferencePath>$(VCINSTALLDIR)\vcpackages;$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib;$(WindowsSdkDir)\References\CommonConfiguration\Neutral</ReferencePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<ReferencePath>$(VCINSTALLDIR)\vcpackages;$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib;$(WindowsSdkDir)\References\CommonConfiguration\Neutral</ReferencePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;PRIREADER_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<CompileAsWinRT>true</CompileAsWinRT>
<MinimalRebuild>false</MinimalRebuild>
<AdditionalOptions>/ZW:nostdlib /FUplatform.winmd /FUwindows.winmd %(AdditionalOptions)</AdditionalOptions>
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>NotSet</SubSystem>
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAsWinRT>true</CompileAsWinRT>
<AdditionalOptions>/ZW:nostdlib /FUplatform.winmd /FUWindows.winmd %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>shlwapi.lib;runtimeobject.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="PriReader.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="README.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="PriReader.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

84
PriReader/PriReader.cpp Normal file
View File

@@ -0,0 +1,84 @@
#include "stdafx.h"
#include "PriReader.h"
static HRESULT InitializeResourceManager (ComPtr<IResourceManager>& resourceManager)
{
ComPtr<IResourceManagerStatics> resourceManagerStatics;
HRESULT hr = RoInitialize (RO_INIT_MULTITHREADED);
if (FAILED (hr))
{
return hr;
}
hr = RoGetActivationFactory (HStringReference (RuntimeClass_Windows_ApplicationModel_Resources_Core_ResourceManager).Get (), IID_PPV_ARGS (&resourceManagerStatics));
if (FAILED (hr))
{
return hr;
}
// Windows 8 使用 `GetCurrent` 获取全局 ResourceManager
hr = resourceManagerStatics->GetCurrent (&resourceManager);
return hr;
}
static LPWSTR GetResourceValue (ComPtr<IResourceManager> resourceManager, LPCWSTR srcName)
{
ComPtr<IResourceMap> resourceMap;
HRESULT hr = resourceManager->get_MainResourceMap (&resourceMap);
if (FAILED (hr))
{
return nullptr;
}
HSTRING hResourceName;
hr = WindowsCreateString (srcName, static_cast<UINT32>(wcslen (srcName)), &hResourceName);
if (FAILED (hr))
{
return nullptr;
}
ComPtr<IResourceCandidate> resourceCandidate;
hr = resourceMap->GetValue (hResourceName, &resourceCandidate);
WindowsDeleteString (hResourceName);
if (FAILED (hr))
{
return nullptr;
}
HSTRING hResourceValue;
hr = resourceCandidate->get_ValueAsString (&hResourceValue);
if (FAILED (hr))
{
return nullptr;
}
const wchar_t* resourceValue = WindowsGetStringRawBuffer (hResourceValue, nullptr);
LPWSTR result = (LPWSTR)calloc (wcslen (resourceValue) + 1, sizeof (wchar_t));
if (result)
{
wcscpy_s (result, wcslen (resourceValue) + 1, resourceValue);
}
WindowsDeleteString (hResourceValue);
return result;
}
EXTERN_C LPWSTR GetStringValueFromPriSource (IStream* priFileStream, LPCWSTR srcName)
{
// Windows 8 不支持直接加载 PRI 文件流,因此省略 stream 参数
ComPtr<IResourceManager> resourceManager;
HRESULT hr = InitializeResourceManager (resourceManager);
if (FAILED (hr))
{
return nullptr;
}
return GetResourceValue (resourceManager, srcName);
}
EXTERN_C LPWSTR GetResourceValueFromPriSource (IStream* priFileStream, LPCWSTR srcName)
{
// Windows 8 仅支持默认 ResourceManager
ComPtr<IResourceManager> resourceManager;
HRESULT hr = InitializeResourceManager (resourceManager);
if (FAILED (hr))
{
return nullptr;
}
return GetResourceValue (resourceManager, srcName);
}

11
PriReader/PriReader.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#ifdef PRIREADER_EXPORTS
#define PRIREADER_API __declspec(dllexport)
#else
#define PRIREADER_API __declspec(dllimport)
#endif
#include <windef.h>
EXTERN_C LPWSTR GetStringValueFromPriSource (IStream *priFileStream, LPCWSTR srcName);
EXTERN_C LPWSTR GetResourceValueFromPriSource (IStream *priFileStream, LPCWSTR srcName);

20
PriReader/PriReader.sln Normal file
View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 12
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AddPackageSample", "AddPackageSample.vcxproj", "{59131AB7-2A7D-9A09-8223-174C3F5E0F57}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{59131AB7-2A7D-9A09-8223-174C3F5E0F57}.Debug|Win32.ActiveCfg = Debug|Win32
{59131AB7-2A7D-9A09-8223-174C3F5E0F57}.Debug|Win32.Build.0 = Debug|Win32
{59131AB7-2A7D-9A09-8223-174C3F5E0F57}.Release|Win32.ActiveCfg = Release|Win32
{59131AB7-2A7D-9A09-8223-174C3F5E0F57}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

39
PriReader/README.txt Normal file
View File

@@ -0,0 +1,39 @@
Add Package Sample
====================
This sample demonstrates how to use IPackageManager to install a package.
Prerequisites
=============
This sample requires Windows 8.1+.
This sample requires Visual Studio 12 Ultimate Developer Preview.
This sample requires the Windows Runtime Software Development Kit.
Sample Language Implementations
===============================
C++
Files:
======
AddPackageSample.cpp
To build the sample using the command prompt:
=============================================
1. Open the Command Prompt window and navigate to the directory.
2. Type msbuild AddPackageSample.sln.
To build the sample using Visual Studio 12 Ultimate Developer Preview (preferred method):
================================================
1. Open File Explorer and navigate to the directory.
2. Double-click the icon for the .sln (solution) file to open the file in
Visual Studio.
3. In the Build menu, select Build Solution. The application will be
built in the default \Debug or \Release directory.
To Run the sample:
==================
1. Open a command prompt.
2. Navigate to the directory containing AddPackageSample.exe
2. Type AddPackageSample.exe "<uri-of-package>" at the command line.
For example, AddPackageSample.exe "file://C|/users/testuser/desktop/testpackage.appx"

18
PriReader/stdafx.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <windows.h>
#include <wrl.h>
#include <roapi.h>
#include <string>
#include <windows.ui.xaml.h>
#include <shlwapi.h>
#include <strsafe.h>
#include <wincodec.h>
#include <vector>
#include <wrl/wrappers/corewrappers.h>
#include <windows.applicationmodel.resources.core.h>
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace Windows::ApplicationModel::Resources::Core;