Update Shell

This commit is contained in:
Bruce
2025-11-21 12:55:08 +08:00
parent 1674f2c35b
commit ae3771bfdb
33 changed files with 972 additions and 78 deletions
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a4e38}"/>
</application>
</compatibility>
</assembly>
Binary file not shown.
+15
View File
@@ -97,6 +97,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>shlwapi.lib;version.lib;dwmapi.lib;$(OutDir)pkgread.lib;$(OutDir)pkgmgr.lib;$(OutDir)certmgr.lib;$(OutDir)priformatcli.lib;$(OutDir)notice.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>app.manifest</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -130,6 +133,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>shlwapi.lib;version.lib;dwmapi.lib;$(OutDir)pkgread.lib;$(OutDir)pkgmgr.lib;$(OutDir)certmgr.lib;$(OutDir)priformatcli.lib;$(OutDir)notice.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<AdditionalManifestFiles>app.manifest</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -150,6 +156,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\certmgr\certmgr.h" />
<ClInclude Include="..\notice\notice.h" />
<ClInclude Include="..\pkgmgr\pkgmgr.h" />
<ClInclude Include="..\pkgread\pkgread.h" />
<ClInclude Include="..\priformatcli\priformatcli.h" />
<ClInclude Include="appxinfo.h" />
<ClInclude Include="cmdargs.h" />
<ClInclude Include="dynarr.h" />
<ClInclude Include="filepath.h" />
@@ -160,6 +172,7 @@
<ClInclude Include="nstring.h" />
<ClInclude Include="raii.h" />
<ClInclude Include="rctools.h" />
<ClInclude Include="resmap.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="strcmp.h" />
<ClInclude Include="strcode.h" />
@@ -194,11 +207,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\pugixml.1.15.0\build\native\pugixml.targets" Condition="Exists('..\packages\pugixml.1.15.0\build\native\pugixml.targets')" />
<Import Project="..\packages\rapidjson.1.0.2\build\native\rapidjson.targets" Condition="Exists('..\packages\rapidjson.1.0.2\build\native\rapidjson.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\pugixml.1.15.0\build\native\pugixml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\pugixml.1.15.0\build\native\pugixml.targets'))" />
<Error Condition="!Exists('..\packages\rapidjson.1.0.2\build\native\rapidjson.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\rapidjson.1.0.2\build\native\rapidjson.targets'))" />
</Target>
</Project>
+21
View File
@@ -66,6 +66,27 @@
<ClInclude Include="ieshell.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resmap.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="appxinfo.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\certmgr\certmgr.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\notice\notice.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\pkgmgr\pkgmgr.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\pkgread\pkgread.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\priformatcli\priformatcli.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
+311
View File
@@ -0,0 +1,311 @@
#pragma once
#include <Windows.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <rapidjson\document.h>
#include <rapidjson\writer.h>
#include <rapidjson\stringbuffer.h>
#include <codecvt>
#include <locale>
#include "nstring.h"
#include "priformatcli.h"
#include "pkgread.h"
static std::string ws2utf8 (const std::wstring &ws)
{
std::wstring_convert <std::codecvt_utf8 <wchar_t>> conv;
return conv.to_bytes (ws);
}
static rapidjson::Value ver_to_json (const VERSION &ver, rapidjson::Document::AllocatorType &alloc)
{
rapidjson::Value obj (rapidjson::kObjectType);
obj.AddMember ("major", ver.major, alloc);
obj.AddMember ("minor", ver.minor, alloc);
obj.AddMember ("build", ver.build, alloc);
obj.AddMember ("revision", ver.revision, alloc);
return obj;
}
struct pkginfo
{
std::wstring filepath;
bool valid = false;
// 包的类型:Appx 包还是 AppxBundle 包。返回 PKGTYPE_* 宏
WORD type = 0;
// 包的类型:是应用包、框架包还是资源包。
// 对于 AppxBundle 包永远返回是资源包(因为框架包无法打包成 AppxBundle,资源包必须与应用包一同打包进 AppxBundle)。
// 返回 PKGROLE_* 宏。
WORD role = 0;
struct
{
std::wstring name,
publisher,
package_family_name,
package_full_name,
resource_id;
VERSION version, realver;
DWORD architecture;
} identity;
struct
{
std::wstring display_name;
std::wstring publisher_display_name;
std::wstring description;
std::wstring logo;
std::wstring logo_base64;
bool framework = false;
bool resource_package = false;
} properties;
struct application: std::map <std::wnstring, std::wstring>
{
using base = std::map <std::wnstring, std::wstring>;
using base::base;
application () = default;
std::wstring user_model_id () { return this->at (L"AppUserModelID"); }
friend bool operator == (application &a1, application &a2) { return a1.user_model_id () == a2.user_model_id (); }
friend bool operator != (application &a1, application &a2) { return a1.user_model_id () != a2.user_model_id (); }
explicit operator bool () { return this->user_model_id ().empty (); }
};
std::vector <application> applications;
struct
{
std::vector <std::wnstring> capabilities_name;
std::vector <std::wnstring> device_capabilities;
} capabilities;
struct dependency
{
std::wstring name, publisher;
VERSION vermin;
dependency (const std::wstring &name = L"", const std::wstring &pub = L"", const VERSION &ver = VERSION ()):
name (name), publisher (pub), vermin (ver) {}
};
std::vector <dependency> dependencies;
struct
{
std::set <std::wnstring> languages;
std::set <UINT32> scales;
// PKG_RESOURCES_DXFEATURE_LEVEL* 前缀常量
std::set <DWORD> dx_feature_levels;
} resources;
struct
{
VERSION os_min_version, os_max_version_tested;
} prerequisites;
static pkginfo parse (const std::wstring &filepath)
{
pkginfo pkg;
pkg.filepath = filepath;
package_reader pread (filepath);
pread.use_pri (true);
pread.enable_pri_convert (true);
pkg.valid = pread.valid ();
if (!pkg.valid) return pkg;
pkg.type = pread.package_type ();
pkg.role = pread.package_role ();
{
auto id = pread.get_identity ();
pkg.identity.architecture = id.architecture ();
pkg.identity.name = id.name ();
pkg.identity.package_family_name = id.package_family_name ();
pkg.identity.package_full_name = id.package_full_name ();
pkg.identity.publisher = id.publisher ();
pkg.identity.resource_id = id.resource_id ();
pkg.identity.version = id.version ();
pkg.identity.realver = id.version (true);
}
{
auto prop = pread.get_properties ();
pkg.properties.description = prop.description ();
pkg.properties.display_name = prop.display_name ();
pkg.properties.framework = prop.framework ();
pkg.properties.logo = prop.logo ();
pkg.properties.logo_base64 = prop.logo_base64 ();
pkg.properties.publisher_display_name = prop.publisher_display_name ();
pkg.properties.resource_package = prop.resource_package ();
}
{
auto prer = pread.get_prerequisites ();
pkg.prerequisites.os_min_version = prer.os_min_version ();
pkg.prerequisites.os_max_version_tested = prer.os_max_version_tested ();
}
{
auto apps = pread.get_applications ();
std::vector <package_reader::application> appmap;
apps.get (appmap);
pkg.applications.reserve (appmap.size ());
for (auto &mp : appmap)
{
application app;
for (auto &it : mp)
{
if (std::find (g_filepathitems.begin (), g_filepathitems.end (), it.first) != g_filepathitems.end ())
app [it.first] = mp.newat_base64 (it.first);
else app [it.first] = mp.newat (it.first);
}
pkg.applications.push_back (app);
}
}
{
auto caps = pread.get_capabilities ();
std::vector <std::wstring> vws;
caps.capabilities_name (vws);
pkg.capabilities.capabilities_name.reserve (vws.size ());
for (auto &it : vws) pkg.capabilities.capabilities_name.push_back (it);
vws.clear ();
caps.device_capabilities (vws);
pkg.capabilities.device_capabilities.reserve (vws.size ());
for (auto &it : vws) pkg.capabilities.device_capabilities.push_back (it);
}
{
std::vector <package_reader::dependency> deps;
auto depr = pread.get_dependencies ();
pkg.dependencies.reserve (depr.get (deps));
for (auto &it : deps)
{
dependency dep;
dep.name = it.name;
dep.publisher = it.publisher;
dep.vermin = it.vermin;
pkg.dependencies.push_back (dep);
}
}
{
auto ress = pread.get_resources ();
{
std::vector <std::wstring> langs;
ress.languages (langs);
for (auto &it : langs) pkg.resources.languages.insert (it);
}
{
std::vector <UINT32> ss;
ress.scales (ss);
for (auto &it : ss) pkg.resources.scales.insert (it);
}
{
DWORD dx = ress.dx_feature_level ();
if (dx & PKG_RESOURCES_DXFEATURE_LEVEL9)
pkg.resources.dx_feature_levels.insert (PKG_RESOURCES_DXFEATURE_LEVEL9);
else if (dx & PKG_RESOURCES_DXFEATURE_LEVEL10)
pkg.resources.dx_feature_levels.insert (PKG_RESOURCES_DXFEATURE_LEVEL10);
else if (dx & PKG_RESOURCES_DXFEATURE_LEVEL11)
pkg.resources.dx_feature_levels.insert (PKG_RESOURCES_DXFEATURE_LEVEL11);
else if (dx & PKG_RESOURCES_DXFEATURE_LEVEL12)
pkg.resources.dx_feature_levels.insert (PKG_RESOURCES_DXFEATURE_LEVEL12);
}
}
return pkg;
}
std::wstring parseJson ()
{
using namespace rapidjson;
Document doc;
doc.SetObject ();
auto &alloc = doc.GetAllocator ();
doc.AddMember ("filepath", Value (ws2utf8 (filepath).c_str (), alloc), alloc);
doc.AddMember ("valid", valid, alloc);
doc.AddMember ("type", type, alloc);
doc.AddMember ("role", role, alloc);
{
Value obj (kObjectType);
obj.AddMember ("name", Value (ws2utf8 (identity.name).c_str (), alloc), alloc);
obj.AddMember ("publisher", Value (ws2utf8 (identity.publisher).c_str (), alloc), alloc);
obj.AddMember ("package_family_name", Value (ws2utf8 (identity.package_family_name).c_str (), alloc), alloc);
obj.AddMember ("package_full_name", Value (ws2utf8 (identity.package_full_name).c_str (), alloc), alloc);
obj.AddMember ("resource_id", Value (ws2utf8 (identity.resource_id).c_str (), alloc), alloc);
obj.AddMember ("architecture", (uint32_t)identity.architecture, alloc);
obj.AddMember ("version", ver_to_json (identity.version, alloc), alloc);
obj.AddMember ("realver", ver_to_json (identity.realver, alloc), alloc);
doc.AddMember ("identity", obj, alloc);
}
{
Value obj (kObjectType);
obj.AddMember ("display_name", Value (ws2utf8 (properties.display_name).c_str (), alloc), alloc);
obj.AddMember ("publisher_display_name", Value (ws2utf8 (properties.publisher_display_name).c_str (), alloc), alloc);
obj.AddMember ("description", Value (ws2utf8 (properties.description).c_str (), alloc), alloc);
obj.AddMember ("logo", Value (ws2utf8 (properties.logo).c_str (), alloc), alloc);
obj.AddMember ("logo_base64", Value (ws2utf8 (properties.logo_base64).c_str (), alloc), alloc);
obj.AddMember ("framework", properties.framework, alloc);
obj.AddMember ("resource_package", properties.resource_package, alloc);
doc.AddMember ("properties", obj, alloc);
}
{
Value arr (kArrayType);
for (auto &app : applications)
{
Value obj (kObjectType);
for (auto &it : app)
{
std::string key = ws2utf8 (it.first);
std::string val = ws2utf8 (it.second);
obj.AddMember (
Value (key.c_str (), alloc),
Value (val.c_str (), alloc),
alloc
);
}
arr.PushBack (obj, alloc);
}
doc.AddMember ("applications", arr, alloc);
}
{
Value obj (kObjectType);
{
Value arr (kArrayType);
for (auto &it : capabilities.capabilities_name)
arr.PushBack (Value (ws2utf8 (it).c_str (), alloc), alloc);
obj.AddMember ("capabilities_name", arr, alloc);
}
{
Value arr (kArrayType);
for (auto &it : capabilities.device_capabilities) arr.PushBack (Value (ws2utf8 (it).c_str (), alloc), alloc);
obj.AddMember ("device_capabilities", arr, alloc);
}
doc.AddMember ("capabilities", obj, alloc);
}
{
Value arr (kArrayType);
for (auto& d : dependencies)
{
Value obj (kObjectType);
obj.AddMember ("name", Value (ws2utf8 (d.name).c_str (), alloc), alloc);
obj.AddMember ("publisher", Value (ws2utf8 (d.publisher).c_str (), alloc), alloc);
obj.AddMember ("vermin", ver_to_json (d.vermin, alloc), alloc);
arr.PushBack (obj, alloc);
}
doc.AddMember ("dependencies", arr, alloc);
}
{
Value obj (kObjectType);
{
Value arr (kArrayType);
for (auto &it : resources.languages) arr.PushBack (Value (ws2utf8 (it).c_str (), alloc), alloc);
obj.AddMember ("languages", arr, alloc);
}
{
Value arr (kArrayType);
for (auto &it : resources.scales) arr.PushBack ((uint32_t)it, alloc);
obj.AddMember ("scales", arr, alloc);
}
{
Value arr (kArrayType);
for (auto &it : resources.dx_feature_levels) arr.PushBack ((uint32_t)it, alloc);
obj.AddMember ("dx_feature_levels", arr, alloc);
}
doc.AddMember ("resources", obj, alloc);
}
{
Value obj (kObjectType);
obj.AddMember ("os_min_version", ver_to_json (prerequisites.os_min_version, alloc), alloc);
obj.AddMember ("os_max_version_tested", ver_to_json (prerequisites.os_max_version_tested, alloc), alloc);
doc.AddMember ("prerequisites", obj, alloc);
}
StringBuffer buffer;
Writer<StringBuffer> writer (buffer);
doc.Accept (writer);
std::string utf8 = buffer.GetString ();
std::wstring_convert <std::codecvt_utf8 <wchar_t>> conv;
return conv.from_bytes (utf8);
}
};
+1
View File
@@ -0,0 +1 @@
E:/Profiles/Bruce/Documents/Visual Studio 2015/Projects/AppInstallerReset/certmgr/certmgr.h
+9 -9
View File
@@ -10,7 +10,7 @@
#include "strcmp.h"
#include "version.h"
#include "module.h"
typedef version VERSION;
typedef version S_VERSION;
template <typename T> constexpr T Max (T l, T r) { return l > r ? l : r; }
template <typename T> constexpr T Max (T l, T m, T r) { return Max (Max (l, r), m); }
template <typename T> constexpr T Max (T l, T ml, T mr, T r) { return Max (Max (l, ml), Max (mr, r)); }
@@ -202,9 +202,9 @@ std::wstring GetCurrentProgramPathW (HMODULE hModule hModule_DefaultParam)
}
std::string GetCurrentProgramNameA (HMODULE hModule hModule_DefaultParam) { return PathFindFileNameA (GetCurrentProgramPathA (hModule).c_str ()); }
std::wstring GetCurrentProgramNameW (HMODULE hModule hModule_DefaultParam) { return PathFindFileNameW (GetCurrentProgramPathW (hModule).c_str ()); }
VERSION GetExeFileVersion (LPCSTR lpszFilePath)
S_VERSION GetExeFileVersion (LPCSTR lpszFilePath)
{
VERSION ver (0);
S_VERSION ver (0);
DWORD dummy;
DWORD size = GetFileVersionInfoSizeA (lpszFilePath, &dummy);
std::vector <BYTE> pVersionInfo (size);
@@ -222,7 +222,7 @@ VERSION GetExeFileVersion (LPCSTR lpszFilePath)
{
return ver;
}
ver = VERSION (
ver = S_VERSION (
HIWORD (pFileInfo->dwFileVersionMS),
LOWORD (pFileInfo->dwFileVersionMS),
HIWORD (pFileInfo->dwFileVersionLS),
@@ -230,9 +230,9 @@ VERSION GetExeFileVersion (LPCSTR lpszFilePath)
);
return ver;
}
VERSION GetExeFileVersion (LPCWSTR lpswFilePath)
S_VERSION GetExeFileVersion (LPCWSTR lpswFilePath)
{
VERSION ver (0);
S_VERSION ver (0);
DWORD dummy;
DWORD size = GetFileVersionInfoSizeW (lpswFilePath, &dummy);
std::vector <BYTE> pVersionInfo (size);
@@ -250,7 +250,7 @@ VERSION GetExeFileVersion (LPCWSTR lpswFilePath)
{
return ver;
}
ver = VERSION (
ver = S_VERSION (
HIWORD (pFileInfo->dwFileVersionMS),
LOWORD (pFileInfo->dwFileVersionMS),
HIWORD (pFileInfo->dwFileVersionLS),
@@ -258,11 +258,11 @@ VERSION GetExeFileVersion (LPCWSTR lpswFilePath)
);
return ver;
}
VERSION GetExeFileVersion (std::wstring objswFilePath)
S_VERSION GetExeFileVersion (std::wstring objswFilePath)
{
return GetExeFileVersion (objswFilePath.c_str ());
}
VERSION GetExeFileVersion (std::string objszFilePath)
S_VERSION GetExeFileVersion (std::string objszFilePath)
{
return GetExeFileVersion (objszFilePath.c_str ());
}
+292 -28
View File
@@ -12,6 +12,9 @@
#include "resource.h"
#include "vemani.h"
#include "ieshell.h"
#include "resmap.h"
#include "appxinfo.h"
using namespace System;
using namespace System::Runtime::InteropServices;
@@ -20,6 +23,7 @@ using namespace System::Runtime::InteropServices;
#else
#define DEBUGMODE false
#endif
#define JS_SAFE [MarshalAs (UnmanagedType::SafeArray, SafeArraySubType = VarEnum::VT_VARIANT)]
LPCWSTR g_lpAppId = L"Microsoft.DesktopAppInstaller";
auto &g_identity = g_lpAppId;
@@ -44,6 +48,9 @@ resxmldoc g_scaleres (
CombinePath (GetProgramRootDirectoryW (), L"VisualElements\\scale.xml") :
CombinePath (GetProgramRootDirectoryW (), L"VisualElementsManifest.xml")
);
WORD g_wcmdflags = 0;
std::set <std::wnstring> g_pkgfiles;
std::vector <pkginfo> g_pkginfo;
HRESULT GetWebBrowser2Interface (System::Windows::Forms::WebBrowser ^fwb, IWebBrowser2 **output)
{
@@ -66,6 +73,9 @@ public ref class SplashForm: public System::Windows::Forms::Form
private:
PictureBox ^picbox;
Timer ^timer;
System::Drawing::Image ^splashimg = nullptr;
System::Drawing::Color background = System::Drawing::Color::Transparent;
// System::Windows::Forms ^parent = nullptr;
double opastep = 0.05;
void InitForm ()
{
@@ -140,14 +150,26 @@ public ref class SplashForm: public System::Windows::Forms::Form
try
{
auto img = System::Drawing::Image::FromFile (gcnew System::String (filefullpath.c_str ()));
if (img != nullptr) picbox->Image = img;
if (img != nullptr)
{
splashimg = img;
picbox->Image = img;
}
}
catch (...) { }
if (splashimg) picbox->Image = splashimg;
if (backcolor != Drawing::Color::Transparent)
{
background = backcolor;
picbox->BackColor = backcolor;
this->BackColor = backcolor;
}
else
{
picbox->BackColor = background;
this->BackColor = background;
}
if (this->Owner != nullptr)
{
this->Owner->Resize += gcnew System::EventHandler (this, &SplashForm::OnResizeOwner);
@@ -160,6 +182,27 @@ public ref class SplashForm: public System::Windows::Forms::Form
timer->Tick += gcnew System::EventHandler (this, &SplashForm::OnFadeTimer);
this->Load += gcnew EventHandler (this, &SplashForm::OnLoad);
}
void ReInit ()
{
InitForm ();
picbox = gcnew System::Windows::Forms::PictureBox ();
picbox->BackColor = background;
if (splashimg) picbox->Image = splashimg;
picbox->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
picbox->Anchor = System::Windows::Forms::AnchorStyles::None;
double dDpi = GetDPI () * 0.01;
picbox->Size = Drawing::Size (620 * dDpi, 300 * dDpi);
this->BackColor = background;
this->Controls->Clear ();
this->Controls->Add (picbox);
timer = gcnew System::Windows::Forms::Timer ();
timer->Interval = 15;
timer->Tick += gcnew EventHandler (this, &SplashForm::OnFadeTimer);
this->Resize += gcnew EventHandler (this, &SplashForm::OnResize);
this->Load += gcnew EventHandler (this, &SplashForm::OnLoad);
ChangePosAndSize ();
this->Opacity = 1.0;
}
void ChangePosAndSize ()
{
if (this->Owner && this->Owner->IsHandleCreated)
@@ -185,14 +228,14 @@ public ref class SplashForm: public System::Windows::Forms::Form
);
}
}
void SetSplashImage (System::Drawing::Image ^img) { if (picbox) picbox->Image = img; }
void SetSplashImage (System::Drawing::Image ^img) { if (picbox && picbox->IsHandleCreated) { splashimg = img; picbox->Image = splashimg; } else splashimg = img; }
void SetSplashImage (System::String ^imgpath) { try { SetSplashImage (System::Drawing::Image::FromFile (imgpath)); } catch (...) {} }
void SetSplashImage (const std::wstring &imgpath) { SetSplashImage (CStringToMPString (imgpath)); }
void SetSplashBackgroundColor (System::Drawing::Color color) { picbox->BackColor = color; this->BackColor = color; }
void SetSplashBackgroundColor (System::Drawing::Color color) { background = color; picbox->BackColor = color; this->BackColor = color; }
// 渐变消失
void FadeOut () { timer->Start (); }
// 立即消失
void FadeAway () { this->Visible = false; this->Close (); }
void FadeAway () { timer->Start (); }
~SplashForm ()
{
if (this->Owner != nullptr)
@@ -202,7 +245,37 @@ public ref class SplashForm: public System::Windows::Forms::Form
}
}
};
bool ReadPackagesTask ()
{
std::set <std::wstring> noread;
std::set <std::wstring> hasread;
for (auto &it : g_pkgfiles)
{
bool isfind = false;
for (auto &rit : g_pkginfo)
{
if (rit.filepath == it)
{
isfind == true;
hasread.insert (it);
break;
}
}
if (!isfind) noread.insert (it);
}
for (auto &it : noread)
{
auto pi = pkginfo::parse (it);
if (pi.valid)
{
hasread.insert (it);
g_pkginfo.push_back (pi);
}
}
g_pkgfiles.clear ();
for (auto &it : hasread) g_pkgfiles.insert (it);
return hasread.size ();
}
[ComVisible (true)]
public ref class MainHtmlWnd: public System::Windows::Forms::Form
{
@@ -229,18 +302,166 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form
private:
MainHtmlWnd ^wndinst = nullptr;
public:
ref struct _I_UI_Size
{
private:
int m_width = 0;
int m_height = 0;
public:
property int width { int get () { return m_width; } }
property int height { int get () { return m_height; }}
property int Width { int get () { return m_width; } }
property int Height { int get () { return m_height; }}
int getWidth () { return m_width; }
int getHeight () { return m_height; }
_I_UI_Size (int w, int h): m_width (w), m_height (h) {}
};
_I_UI (MainHtmlWnd ^wnd): wndinst (wnd) {}
property int DPIPercent { int get () { return GetDPI (); }}
property double DPI { double get () { return DPIPercent * 0.01; }}
void showSplash () { wndinst->SplashScreen->Show (); }
void fadeAwaySplash () { wndinst->SplashScreen->FadeAway (); }
void fadeOutSplash () { wndinst->SplashScreen->FadeOut (); }
property _I_UI_Size ^WndSize { _I_UI_Size ^get () { return gcnew _I_UI_Size (wndinst->Width, wndinst->Height); } }
property _I_UI_Size ^ClientSize { _I_UI_Size ^get () { auto cs = wndinst->ClientSize; return gcnew _I_UI_Size (cs.Width, cs.Height); } }
property String ^SplashImage
{
String ^get ()
{
auto uri = gcnew Uri (CStringToMPString (wndinst->GetSuitSplashImage ()));
return uri->AbsoluteUri;
}
}
property String ^SplashBackgroundColor { String ^get () { return CStringToMPString (g_vemani.splash_screen_backgroundcolor (L"App")); } }
void ShowSplash () { if (wndinst->SplashScreen->IsHandleCreated) wndinst->SplashScreen->Show (); else wndinst->SplashScreen->ReInit (); }
void FadeAwaySplash () { wndinst->SplashScreen->FadeAway (); }
void FadeOutSplash () { wndinst->SplashScreen->FadeOut (); }
};
ref class _I_Resources
{
public:
String ^GetById (unsigned int uiResId) { return GetRCStringCli (uiResId); }
unsigned ToId (String ^lpResName)
{
auto it = g_nameToId.find (MPStringToStdA (lpResName));
return (it != g_nameToId.end ()) ? it->second : 0;
}
String ^ToName (unsigned int ulResId)
{
for (auto &it : g_nameToId) {if (it.second == ulResId) return CStringToMPString (it.first);}
return "";
}
String ^GetByName (String ^lpResId) { return GetById (ToId (lpResId)); }
String ^operator [] (unsigned int uiResId) { return GetRCStringCli (uiResId); }
};
ref class _I_Version
{
private:
UINT16 major = 0, minor = 0, build = 0, revision = 0;
public:
property UINT16 Major { UINT16 get () { return major; } void set (UINT16 value) { major = value; } }
property UINT16 Minor { UINT16 get () { return minor; } void set (UINT16 value) { minor = value; } }
property UINT16 Build { UINT16 get () { return build; } void set (UINT16 value) { build = value; } }
property UINT16 Revision { UINT16 get () { return revision; } void set (UINT16 value) { revision = value; } }
property array <UINT16> ^Data
{
array <UINT16> ^get ()
{
return gcnew array <UINT16> {
major, minor, build, revision
};
}
void set (array <UINT16> ^arr)
{
major = minor = build = revision = 0;
for (size_t i = 0; i < arr->Length; i ++)
{
switch (i)
{
case 0: major = arr [i]; break;
case 1: minor = arr [i]; break;
case 2: build = arr [i]; break;
case 3: revision = arr [i]; break;
default: break;
}
}
}
}
property String ^DataStr
{
String ^get () { return Stringify (); }
void set (String ^str) { Parse (str); }
}
_I_Version (UINT16 p_ma, UINT16 p_mi, UINT16 p_b, UINT16 p_r):
major (p_ma), minor (p_mi), build (p_b), revision (p_r) {}
_I_Version (UINT16 p_ma, UINT16 p_mi, UINT16 p_b):
major (p_ma), minor (p_mi), build (p_b), revision (0) {}
_I_Version (UINT16 p_ma, UINT16 p_mi):
major (p_ma), minor (p_mi), build (0), revision (0) {}
_I_Version (UINT16 p_ma):
major (p_ma), minor (0), build (0), revision (0) {}
_I_Version () {}
_I_Version %Parse (String ^ver)
{
auto strarr = ver->Split ('.');
auto arr = gcnew array <UINT16> (4);
for (size_t i = 0; i < strarr->Length; i ++)
{
try { arr [i] = Convert::ToUInt16 (strarr [i]); }
catch (...) {}
}
Data = arr;
return *this;
}
String ^Stringify () { return major + "." + minor + "." + build + "." + revision; }
String ^ToString () override { return Stringify (); }
bool Valid () { return Major != 0 && Minor != 0 && Build != 0 && Revision != 0; }
};
private:
_I_UI ^ui = gcnew _I_UI (wndinst);
_I_Resources ^ires = gcnew _I_Resources ();
public:
_I_System (MainHtmlWnd ^wnd): wndinst (wnd) {}
property _I_UI ^UI { _I_UI ^get () { return ui; } }
property _I_Resources ^Resources { _I_Resources ^get () { return ires; } }
property _I_Version ^Version
{
_I_Version ^get ()
{
#pragma warning(push)
#pragma warning(disable:4996)
auto ver = gcnew _I_Version ();
OSVERSIONINFOEXW osvi = {0};
osvi.dwOSVersionInfoSize = sizeof (osvi);
if (!GetVersionExW ((LPOSVERSIONINFOW)&osvi)) return ver;
ver->Major = osvi.dwMajorVersion;
ver->Minor = osvi.dwMinorVersion;
ver->Build = osvi.dwBuildNumber;
HKEY hKey;
{
DWORD ubr = 0, size = sizeof (DWORD);
if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
RegQueryValueExW (hKey, L"UBR", 0, NULL, (LPBYTE)&ubr, &size);
RegCloseKey (hKey);
}
ver->Revision = ubr;
}
return ver;
#pragma warning(pop)
}
}
property bool IsWindows10
{
bool get ()
{
OSVERSIONINFOEX osvi = {0};
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
osvi.dwMajorVersion = 10;
DWORDLONG conditionMask = 0;
VER_SET_CONDITION (conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
if (VerifyVersionInfoW (&osvi, VER_MAJORVERSION, conditionMask)) return TRUE;
DWORD error = GetLastError ();
return (error == ERROR_OLD_WIN_VERSION) ? FALSE : FALSE;
}
}
};
ref class _I_IEFrame
{
@@ -289,36 +510,31 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form
String ^ToLower (String ^src) { return CStringToMPString (StringToLower (MPStringToStdW (src))); }
String ^ToUpper (String ^src) { return CStringToMPString (StringToUpper (MPStringToStdW (src))); }
};
ref class _I_Package
{
public:
};
private:
_I_System ^system = gcnew _I_System (wndinst);
_I_IEFrame ^ieframe = gcnew _I_IEFrame (wndinst);
_I_Storage ^storage = gcnew _I_Storage (wndinst);
_I_String ^str = gcnew _I_String ();
_I_Package ^pkg = gcnew _I_Package ();
public:
property _I_System ^System { _I_System ^get () { return system; }}
property _I_IEFrame ^IEFrame { _I_IEFrame ^get () { return ieframe; }}
property _I_Storage ^Storage { _I_Storage ^get () { return storage; }}
property _I_String ^String { _I_String ^get () { return str; }}
property _I_Package ^Package { _I_Package ^get () { return pkg; }}
};
protected:
property WebBrowser ^WebUI { WebBrowser ^get () { return this->webui; } }
property SplashForm ^SplashScreen { SplashForm ^get () { return this->splash; } }
property int DPIPercent { int get () { return GetDPI (); }}
property double DPI { double get () { return DPIPercent * 0.01; }}
void Init ()
void InitSize ()
{
this->Visible = false;
this->webui = gcnew System::Windows::Forms::WebBrowser ();
this->SuspendLayout ();
this->webui->Dock = System::Windows::Forms::DockStyle::Fill;
this->webui->IsWebBrowserContextMenuEnabled = DEBUGMODE;
this->webui->AllowWebBrowserDrop = false;
this->Controls->Add (this->webui);
if (g_hIconMain.hIcon)
{
try { this->Icon = System::Drawing::Icon::FromHandle (IntPtr (g_hIconMain.hIcon)); }
catch (...) {}
}
unsigned ww = 0, wh = 0;
auto &ini = g_initfile;
auto setsect = ini ["Settings"];
@@ -333,11 +549,26 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form
wh = setsect [L"DefaultHeight"].read_uint (rcInt (IDS_DEFAULTHEIGHT));
}
this->MinimumSize = System::Drawing::Size (
setsect [L"MinimumWidth"].read_uint (rcInt (IDS_MINWIDTH)) * DPI,
setsect [L"MinimumWidth"].read_uint (rcInt (IDS_MINWIDTH)) * DPI,
setsect [L"MinimumHeight"].read_uint (rcInt (IDS_MINHIEHGT)) * DPI
);
this->ClientSize = System::Drawing::Size (ww * DPI, wh * DPI);
this->WindowState = (System::Windows::Forms::FormWindowState)setsect [L"LastWndState"].read_int ((int)System::Windows::Forms::FormWindowState::Normal);
}
void Init ()
{
this->Visible = false;
this->webui = gcnew System::Windows::Forms::WebBrowser ();
this->SuspendLayout ();
this->webui->Dock = System::Windows::Forms::DockStyle::Fill;
this->webui->IsWebBrowserContextMenuEnabled = DEBUGMODE;
this->webui->AllowWebBrowserDrop = false;
this->Controls->Add (this->webui);
if (g_hIconMain.hIcon)
{
try { this->Icon = System::Drawing::Icon::FromHandle (IntPtr (g_hIconMain.hIcon)); }
catch (...) {}
}
this->Text = rcString (IDS_WINTITLE);
this->ResumeLayout (false);
webui->ObjectForScripting = gcnew IBridge (this);
@@ -354,7 +585,8 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form
ExecScript ("Windows.UI.DPI.mode = 1");
ExecScript ("Bridge.Frame.scale = Bridge.Frame.scale * Bridge.UI.dpi");
splash->FadeOut ();
// splash->FadeOut ();
splash->FadeAway ();
}
}
void OnCreate (System::Object ^sender, System::EventArgs ^e)
@@ -372,19 +604,45 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form
}
void OnResize (Object ^sender, EventArgs ^e)
{
ResizeEvent ();
}
void OnResizeEnd (Object ^sender, EventArgs ^e)
{
}
std::wstring GetSuitSplashImage ()
{
std::wstring path = g_scaleres [this->Width >= 1024 && this->Height >= 768 ? L"splashlarge" : L"splash"];
if (IsNormalizeStringEmpty (path)) path = g_vemani.splash_screen_image (L"App");
return path;
}
void ResizeEvent ()
{
splash->SetSplashImage (GetSuitSplashImage ());
ExecScript (
"(function () {"
"var splash = Page.splash;"
"if (!splash) return null;"
"splash.imagesrc = Bridge.UI.Splash.imageurl;"
"splash.background = Bridge.UI.Splash.backcolor;"
"var progress = splash.content.querySelector (\"progress\");"
"if (Bridge.Frame.WindowSize.height / Bridge.UI.dpi < 500) {"
"if (progress.classList.contains(\"win-ring\")) progress.classList.remove(\"win-ring\");}"
"else { if (!progress.classList.contains(\"win-ring\")) progress.classList.add(\"win-ring\"); }"
"}) ();"
);
}
void PackageLoadTask ()
{
if (!g_pkginfo.size ())
}
public:
MainHtmlWnd ()
{
InitSize ();
splash = gcnew SplashForm (
gcnew String (g_vemani.splash_screen_image (L"App").c_str ()),
StringToColor (gcnew String (g_vemani.splash_screen_backgroundcolor (L"App").c_str ())),
CStringToMPString (GetSuitSplashImage ()),
StringToColor (CStringToMPString (g_vemani.splash_screen_backgroundcolor (L"App"))),
this
);
System::Windows::Forms::Application::DoEvents ();
@@ -578,7 +836,7 @@ int APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCm
SetProcessDPIAware ();
{
// 设置当前目录为程序所在目录
std::wnstring currdir = GetCurrentProgramPathW ();
std::wnstring currdir = GetCurrentDirectoryW ();
std::wnstring rootdir = GetProgramRootDirectoryW ();
if (!PathEquals (currdir, rootdir)) SetCurrentDirectoryW (rootdir.c_str ());
}
@@ -586,6 +844,12 @@ int APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCm
destruct relco ([] () {
CoUninitialize ();
});
{
std::map <cmdkey, cmdvalue> pair_cmdkv;
ParseCmdLine (lpCmdLine, pair_cmdkv);
std::set <std::wnstring> uris;
g_wcmdflags = CmdMapsToFlags (pair_cmdkv, g_pkgfiles, uris);
}
System::Windows::Forms::Application::EnableVisualStyles ();
System::Windows::Forms::Application::SetCompatibleTextRenderingDefault (false);
auto mwnd = gcnew MainHtmlWnd ();
+1
View File
@@ -0,0 +1 @@
E:/Profiles/Bruce/Documents/Visual Studio 2015/Projects/AppInstallerReset/notice/notice.h
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="pugixml" version="1.15.0" targetFramework="native" />
<package id="rapidjson" version="1.0.2" targetFramework="native" />
</packages>
+1
View File
@@ -0,0 +1 @@
E:/Profiles/Bruce/Documents/Visual Studio 2015/Projects/AppInstallerReset/pkgmgr/pkgmgr.h
+1
View File
@@ -0,0 +1 @@
E:/Profiles/Bruce/Documents/Visual Studio 2015/Projects/AppInstallerReset/pkgread/pkgread.h
+1
View File
@@ -0,0 +1 @@
E:/Profiles/Bruce/Documents/Visual Studio 2015/Projects/AppInstallerReset/priformatcli/priformatcli.h
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <map>
#include <string>
#include "rctools.h"
#include "resource.h"
#define MAKENAMEIDMAP(_Res_Name_) {#_Res_Name_, _Res_Name_}
std::map <std::string, unsigned> g_nameToId = {
MAKENAMEIDMAP (IDS_WINTITLE),
MAKENAMEIDMAP (IDS_PLEASEWAIT),
MAKENAMEIDMAP (IDS_PUBLISHER),
MAKENAMEIDMAP (IDS_VERSION),
MAKENAMEIDMAP (IDS_MSAPP),
MAKENAMEIDMAP (IDS_FUNCTIONNAME),
MAKENAMEIDMAP (IDS_MOREINFO),
MAKENAMEIDMAP (IDS_SELECT_TITLE),
MAKENAMEIDMAP (IDS_SELECT_DLGTITLE),
MAKENAMEIDMAP (IDS_SELECT_DLGAPPX),
MAKENAMEIDMAP (IDS_SELECT_DLGALL),
MAKENAMEIDMAP (IDS_SELECT_OPENFILE),
MAKENAMEIDMAP (IDS_PREINSTALL_TITLE),
MAKENAMEIDMAP (IDS_PREINSTALL_TUPDATE),
MAKENAMEIDMAP (IDS_PREINSTALL_TREINSTALL),
MAKENAMEIDMAP (IDS_PREINSTALL_TINSTALL),
MAKENAMEIDMAP (IDS_PREINSTALL_CUPDATE),
MAKENAMEIDMAP (IDS_PREINSTALL_CREINSTALL),
MAKENAMEIDMAP (IDS_PREINSTALL_CANCEL),
MAKENAMEIDMAP (IDS_PREINSTALL_MTTITLE),
MAKENAMEIDMAP (IDS_PREINSTALL_MSELECT),
MAKENAMEIDMAP (IDS_PREINSTALL_MPKGNAME),
MAKENAMEIDMAP (IDS_INSTALLING_TITLE),
MAKENAMEIDMAP (IDS_INSTALLING_SLOADING),
MAKENAMEIDMAP (IDS_INSTALLING_SLOADCER),
MAKENAMEIDMAP (IDS_INSTALLING_SINSTALLING),
MAKENAMEIDMAP (IDS_INSTALLING_SINSTALLING_PROGRESS),
MAKENAMEIDMAP (IDS_INSTALLING_MTITLE),
MAKENAMEIDMAP (IDS_INSTALLING_MPKGNAME),
MAKENAMEIDMAP (IDS_INSTALLING_MSINSTALLING_PROGRESS),
MAKENAMEIDMAP (IDS_LAUNCHWHENREADY),
MAKENAMEIDMAP (IDS_SUCCESS_TITLE),
MAKENAMEIDMAP (IDS_SUCCESS_MTITLE),
MAKENAMEIDMAP (IDS_FAILED_TITLE),
MAKENAMEIDMAP (IDS_FAILED_REASONNAME),
MAKENAMEIDMAP (IDS_SUCCESS_LAUNCH),
MAKENAMEIDMAP (IDS_COMMAND_CANCEL),
MAKENAMEIDMAP (IDS_CMDPARAM_SILENT),
MAKENAMEIDMAP (IDS_CMDPARAM_VERYSILENT),
MAKENAMEIDMAP (IDS_CMDPARAM_MULTIPLE),
MAKENAMEIDMAP (IDS_DEFAULTWIDTH),
MAKENAMEIDMAP (IDS_DEFAULTHEIGHT),
MAKENAMEIDMAP (IDS_MINWIDTH),
MAKENAMEIDMAP (IDS_MINHIEHGT)
};
+18 -2
View File
@@ -308,13 +308,29 @@ class resxmldoc
catch (...) {}
}
}
std::vector <std::pair <int, std::string>> existfilepath;
{
std::vector <std::pair <int, std::string>> vec (s_v.begin (), s_v.end ());
std::sort (vec.begin (), vec.end (), [] (auto &a, auto &b) { return a.second < b.second; });
for (auto &it_ss : vec)
{
it_ss.second = pugi::as_utf8 (CombinePath (GetFileDirectoryW (filepath), pugi::as_wide (it_ss.second)));
if (IsFileExists (pugi::as_wide (it_ss.second))) existfilepath.push_back (it_ss);
}
}
int dpipercent = GetDPI ();
for (auto &it_path : existfilepath)
{
if (it_path.first >= dpipercent) return it_path.second;
}
if (!existfilepath.empty ()) return existfilepath.at (0).second;
return "";
break;
}
}
return "";
}
std::wstring get (const std::wstring &id) const { return pugi::as_wide (get (WStringToString (id)).c_str ()); }
std::wstring get (const std::wstring &id) const { return pugi::as_wide (get (WStringToString (id))); }
std::wstring operator [] (const std::wstring &id) const { return get (id); }
std::wstring operator [] (const std::wstring &id) { return get (id); }
std::string operator [] (const std::string &id) const { return get (id); }