Update Settings Page.

This commit is contained in:
Bruce
2025-11-29 18:19:08 +08:00
parent 87efdc39df
commit cf50b09bf0
111 changed files with 7115 additions and 322 deletions
+57 -18
View File
@@ -1,18 +1,57 @@
<?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>
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,Windows 将
自动选择最兼容的环境。 -->
<!-- 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-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
<!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
+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>
+3
View File
@@ -209,6 +209,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Manifest Include="app.manifest" />
</ItemGroup>
<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')" />
@@ -124,4 +124,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Manifest Include="app.manifest" />
</ItemGroup>
</Project>
+1
View File
@@ -2,6 +2,7 @@
#include <Windows.h>
#include "mpstr.h"
#include "nstring.h"
#include <combaseapi.h>
using namespace System;
using namespace System::Runtime::InteropServices;
+303 -1
View File
@@ -868,4 +868,306 @@ bool PathEquals (const std::wstring &path1, const std::wstring &path2)
PathCanonicalizeW (buf1.data (), path1.c_str ());
PathCanonicalizeW (buf2.data (), path2.c_str ());
return IsNormalizeStringEquals (buf1.data (), buf2.data ());
}
}
#ifdef __cplusplus_cli
#include <rapidjson\document.h>
#include <rapidjson\writer.h>
#include <rapidjson\stringbuffer.h>
#include <codecvt>
#include <locale>
#include "mpstr.h"
#include "strcode.h"
using namespace System;
using namespace System::Runtime::InteropServices;
String ^StringArrayToJson (array <String ^> ^strs)
{
using namespace rapidjson;
Document doc;
doc.SetArray ();
Document::AllocatorType &allocator = doc.GetAllocator ();
for each (String ^s in strs)
{
std::wstring ws = MPStringToStdW (s); // String^ → std::wstring
std::string utf8 = WStringToString (ws, CP_UTF8); // 简易宽转 UTF-8,如需更严谨可用 WideCharToMultiByte
doc.PushBack (Value (utf8.c_str (), allocator), allocator);
}
StringBuffer buffer;
Writer <StringBuffer> writer (buffer);
doc.Accept (writer);
std::string json = buffer.GetString ();
std::wstring wjson = StringToWString (json, CP_UTF8);
return CStringToMPString (wjson);
}
std::wstring StringArrayToJson (const std::vector<std::wstring>& arr)
{
using namespace rapidjson;
Document doc;
doc.SetArray ();
auto &allocator = doc.GetAllocator ();
for (const auto &ws : arr)
{
std::string utf8 = WStringToUtf8 (ws);
doc.PushBack (Value (utf8.c_str (), allocator), allocator);
}
StringBuffer buffer;
Writer <StringBuffer> writer (buffer);
doc.Accept (writer);
return Utf8ToWString (buffer.GetString ());
}
[ComVisible (true)]
public ref class _I_Path
{
public:
property String ^Current
{
String ^get () { return CStringToMPString (GetCurrentDirectoryW ()); }
void set (String ^dir) { SetCurrentDirectoryW (MPStringToStdW (dir).c_str ()); }
}
property String ^Program { String ^get () { return CStringToMPString (GetCurrentProgramPathW ()); } }
String ^Combine (String ^l, String ^r) { return CStringToMPString (CombinePath (MPStringToStdW (l), MPStringToStdW (r))); }
String ^GetName (String ^path)
{
std::wstring cpath = MPStringToStdW (path);
LPWSTR lp = PathFindFileNameW (cpath.c_str ());
return lp ? CStringToMPString (lp) : String::Empty;
}
String ^GetDirectory (String ^path) { return CStringToMPString (GetFileDirectoryW (MPStringToStdW (path))); }
String ^GetDir (String ^path) { return GetDirectory (path); }
bool Exist (String ^path) { return IsPathExists (MPStringToStdW (path)); }
bool FileExist (String ^filepath) { return IsFileExists (MPStringToStdW (filepath)); }
bool DirectoryExist (String ^dirpath) { return IsDirectoryExists (MPStringToStdW (dirpath)); }
bool DirExist (String ^dirpath) { return DirectoryExist (dirpath); }
String ^GetEnvironmentString (String ^str) { return CStringToMPString (ProcessEnvVars (MPStringToStdW (str))); }
bool ValidName (String ^filename) { return IsValidWindowsName (MPStringToStdW (filename)); }
// 过滤器用"\"分隔每个类型
String ^EnumFilesToJson (String ^dir, String ^filter, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
::EnumFiles (MPStringToStdW (dir), MPStringToStdW (filter), res, withpath, sort, includesub);
return CStringToMPString (StringArrayToJson (res));
}
String ^EnumDirsToJson (String ^dir, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
EnumDirectory (MPStringToStdW (dir), res, withpath, sort, includesub);
return CStringToMPString (StringArrayToJson (res));
}
String ^EnumSubDirsToJson (String ^dir, bool withpath)
{
std::vector <std::wstring> res = EnumSubdirectories (MPStringToStdW (dir), withpath);
return CStringToMPString (StringArrayToJson (res));
}
array <String ^> ^EnumFiles (String ^dir, String ^filter, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
::EnumFiles (MPStringToStdW (dir), MPStringToStdW (filter), res, withpath, sort, includesub);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
array <String ^> ^EnumDirs (String ^dir, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
EnumDirectory (MPStringToStdW (dir), res, withpath, sort, includesub);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
array <String ^> ^EnumSubDirs (String ^dir, bool withpath)
{
std::vector <std::wstring> res = EnumSubdirectories (MPStringToStdW (dir), withpath);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
String ^CommonPrefix (String ^path1, String ^path2) { return CStringToMPString (PathCommonPrefix (MPStringToStdW (path1), MPStringToStdW (path2))); }
String ^EnsureDirSlash (String ^dir) { return CStringToMPString (EnsureTrailingSlash (MPStringToStdW (dir))); }
String ^Normalize (String ^path) { return CStringToMPString (NormalizePath (MPStringToStdW (path))); }
String ^FullPathName (String ^path) { return CStringToMPString (GetFullPathName (MPStringToStdW (path))); }
bool PEquals (String ^l, String ^r) { return PathEquals (MPStringToStdW (l), MPStringToStdW (r)); }
};
[ComVisible (true)]
public ref class _I_Entry
{
protected:
String ^path;
public:
_I_Entry (String ^path): path (path) {}
_I_Entry (): path (String::Empty) {}
property String ^Path { String ^get () { return path; } void set (String ^file) { path = file; } }
property String ^Name
{
String ^get ()
{
std::wstring file = MPStringToStdW (path);
LPWSTR lpstr = PathFindFileNameW (file.c_str ());
return lpstr ? CStringToMPString (lpstr) : String::Empty;
}
}
property String ^Directory { String ^get () { return CStringToMPString (GetFileDirectoryW (MPStringToStdW (path))); }}
property String ^Root { String ^get () { return Directory; }}
property bool Exist { virtual bool get () { return IsPathExists (MPStringToStdW (path)); }}
property String ^Uri
{
String ^get ()
{
using namespace System;
try
{
auto uri = gcnew System::Uri (System::IO::Path::GetFullPath (path));
auto uriText = uri->AbsoluteUri;
return uriText;
}
catch (...) { return String::Empty; }
}
}
property String ^FullPath { String ^get () { return System::IO::Path::GetFullPath (path); }}
};
[ComVisible (true)]
public ref class _I_File: public _I_Entry
{
protected:
System::Text::Encoding ^lastEncoding;
public:
_I_File (String ^filepath): _I_Entry (filepath) {}
_I_File (): _I_Entry (String::Empty) {}
String ^Get ()
{
using namespace System::IO;
if (String::IsNullOrEmpty (path)) return String::Empty;
FileStream ^fs = nullptr;
StreamReader ^sr = nullptr;
try
{
fs = gcnew FileStream (
path,
FileMode::OpenOrCreate,
FileAccess::ReadWrite,
FileShare::ReadWrite
);
sr = gcnew StreamReader (fs, Encoding::UTF8, true);
String ^text = sr->ReadToEnd ();
auto lastEncoding = sr->CurrentEncoding;
return text;
}
finally
{
if (sr) delete sr;
if (fs) delete fs;
}
}
void Set (String ^content)
{
using namespace System::IO;
if (String::IsNullOrEmpty (path)) return;
Encoding ^enc = lastEncoding ? lastEncoding : Encoding::UTF8;
FileStream ^fs = nullptr;
StreamWriter ^sw = nullptr;
try
{
fs = gcnew FileStream (
path,
FileMode::Create,
FileAccess::ReadWrite,
FileShare::ReadWrite
);
sw = gcnew StreamWriter (fs, enc);
sw->Write (content);
sw->Flush ();
}
finally
{
if (sw) delete sw;
if (fs) delete fs;
}
}
property String ^Content
{
String ^get () { return Get (); }
void set (String ^value) { Set (value); }
}
property bool Exist { bool get () override { return IsFileExists (MPStringToStdW (path)); }}
property String ^FilePath { String ^get () { return this->Path; } void set (String ^value) { this->Path = value; }}
};
[ComVisible (true)]
public ref class _I_Directory: public _I_Entry
{
public:
_I_Directory (String ^dirpath): _I_Entry (dirpath) {}
_I_Directory (_I_Entry ^file): _I_Entry (file->Directory) {}
_I_Directory (): _I_Entry (String::Empty) {}
property String ^DirectoryPath { String ^get () { return this->Path; } void set (String ^value) { this->Path = value; } }
property String ^DirPath { String ^get () { return this->DirectoryPath; } void set (String ^value) { this->DirectoryPath = value; } }
property bool Exist { bool get () override { return IsDirectoryExists (MPStringToStdW (path)); }}
String ^EnumFilesToJson (String ^filter, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
::EnumFiles (MPStringToStdW (DirPath), MPStringToStdW (filter), res, withpath, sort, includesub);
return CStringToMPString (StringArrayToJson (res));
}
String ^EnumDirsToJson (bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
EnumDirectory (MPStringToStdW (DirPath), res, withpath, sort, includesub);
return CStringToMPString (StringArrayToJson (res));
}
String ^EnumSubDirsToJson (bool withpath)
{
std::vector <std::wstring> res = EnumSubdirectories (MPStringToStdW (DirPath), withpath);
return CStringToMPString (StringArrayToJson (res));
}
array <String ^> ^EnumFiles (String ^filter, bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
::EnumFiles (MPStringToStdW (DirPath), MPStringToStdW (filter), res, withpath, sort, includesub);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
array <String ^> ^EnumDirs (bool withpath, bool sort, bool includesub)
{
std::vector <std::wstring> res;
EnumDirectory (MPStringToStdW (DirPath), res, withpath, sort, includesub);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
array <String ^> ^EnumSubDirs (bool withpath)
{
std::vector <std::wstring> res = EnumSubdirectories (MPStringToStdW (DirPath), withpath);
auto retarr = gcnew array <String ^> (res.size ());
for (size_t i = 0; i < res.size (); i ++)
{
retarr [i] = CStringToMPString (res [i]);
}
return retarr;
}
};
[ComVisible (true)]
public ref class _I_Storage
{
protected:
_I_Path ^path = gcnew _I_Path ();
public:
property _I_Path ^Path { _I_Path ^get () { return path; }}
_I_File ^GetFile (String ^path) { return gcnew _I_File (path); }
_I_Directory ^GetDirectory (String ^path) { return gcnew _I_Directory (path); }
_I_Directory ^GetDir (String ^path) { return GetDirectory (path); }
};
#endif
+1
View File
@@ -2,6 +2,7 @@
#include <WinNls.h>
#include <string>
#include "typestrans.h"
#include "strcode.h"
#undef GetLocaleInfo
std::string GetLocaleInfoA (LCID code, LCTYPE type)
+213 -296
View File
@@ -40,7 +40,7 @@ enum class CMDPARAM: DWORD
MULTIPLE = 0b100
};
LPCWSTR g_lpAppId = L"Microsoft.DesktopAppInstaller";
LPCWSTR g_lpAppId = L"Microsoft.DesktopAppInstaller!App";
auto &g_identity = g_lpAppId;
auto &m_idenName = g_lpAppId;
struct iconhandle
@@ -192,19 +192,158 @@ public ref class _I_Window
Object ^CallEvent (String ^name, ... array <Object ^> ^args) { return wndinst->CallEvent (name, args [0]); }
};
[ComVisible (true)]
public ref class _I_UI
{
private:
System::Windows::Forms::Form ^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 (System::Windows::Forms::Form ^wnd): wndinst (wnd) {}
property int DPIPercent { int get () { return GetDPI (); }}
property double DPI { double get () { return DPIPercent * 0.01; }}
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 ^ThemeColor { String ^get () { return ColorToHtml (GetDwmThemeColor ()); } }
property bool DarkMode { bool get () { return IsAppInDarkMode (); }}
property String ^HighContrast
{
String ^get ()
{
auto highc = GetHighContrastTheme ();
switch (highc)
{
case HighContrastTheme::None: return "none";
break;
case HighContrastTheme::Black: return "black";
break;
case HighContrastTheme::White: return "white";
break;
case HighContrastTheme::Other: return "high";
break;
default: return "none";
break;
}
return "none";
}
}
};
[ComVisible (true)]
public ref class _I_Locale
{
public:
property String ^CurrentLocale { String ^get () { return CStringToMPString (GetComputerLocaleCodeW ()); } }
property LCID CurrentLCID { LCID get () { return LocaleCodeToLcid (GetComputerLocaleCodeW ()); } }
String ^ToLocaleName (LCID lcid) { return CStringToMPString (LcidToLocaleCodeW (lcid)); }
LCID ToLCID (String ^localename) { return LocaleCodeToLcidW (MPStringToStdW (localename)); }
Object ^LocaleInfo (LCID lcid, LCTYPE lctype) { return CStringToMPString (GetLocaleInfoW (lcid, lctype)); }
Object ^LocaleInfoEx (String ^localeName, LCTYPE lctype)
{
std::wstring output = L"";
int ret = GetLocaleInfoEx (MPStringToStdW (localeName), lctype, output);
if (output.empty ()) return ret;
else return CStringToMPString (output);
}
};
[ComVisible (true)]
public ref class _I_System
{
private:
_I_Resources ^ires = gcnew _I_Resources ();
_I_Locale ^ilocale = gcnew _I_Locale ();
public:
property _I_Resources ^Resources { _I_Resources ^get () { return ires; } }
property _I_Locale ^Locale { _I_Locale ^get () { return ilocale; } }
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;
}
}
};
public ref class _I_System2: public _I_System
{
protected:
_I_UI ^ui;
public:
_I_System2 (System::Windows::Forms::Form ^wnd)
{
ui = gcnew _I_UI (wnd);
}
property _I_UI ^UI { _I_UI ^get () { return ui; } }
};
[ComVisible (true)]
public ref class _I_Bridge_Base2: public _I_Bridge_Base
{
protected:
_I_Window ^window;
public:
_I_Bridge_Base2 (IScriptBridge ^wnd)
_I_Bridge_Base2 (IScriptBridge ^iscr)
{
window = gcnew _I_Window (wnd);
window = gcnew _I_Window (iscr);
}
property _I_Window ^Window { _I_Window ^get () { return window; }}
};
[ComVisible (true)]
public ref class _I_Bridge_Base3: public _I_Bridge_Base2
{
protected:
_I_System2 ^system;
public:
_I_Bridge_Base3 (IScriptBridge ^iscr, System::Windows::Forms::Form ^form): _I_Bridge_Base2 (iscr)
{
system = gcnew _I_System2 (form);
}
property _I_System2 ^System { _I_System2 ^get () { return system; }}
};
[ComVisible (true)]
public ref class _I_IEFrame_Base
{
public:
property int Version { int get () { return GetInternetExplorerVersionMajor (); }}
String ^ParseHtmlColor (String ^color)
{
auto dcolor = Drawing::ColorTranslator::FromHtml (color);
{
rapidjson::Document doc;
doc.SetObject ();
auto &alloc = doc.GetAllocator ();
doc.AddMember ("r", (uint16_t)dcolor.R, alloc);
doc.AddMember ("g", (uint16_t)dcolor.G, alloc);
doc.AddMember ("b", (uint16_t)dcolor.B, alloc);
doc.AddMember ("a", (uint16_t)dcolor.A, alloc);
rapidjson::StringBuffer buffer;
rapidjson::Writer <rapidjson::StringBuffer> writer (buffer);
doc.Accept (writer);
std::string utf8 = buffer.GetString ();
std::wstring_convert <std::codecvt_utf8 <wchar_t>> conv;
return CStringToMPString (conv.from_bytes (utf8));
}
return "{}";
}
};
[ComVisible (true)]
public ref class SplashForm: public System::Windows::Forms::Form
{
public:
@@ -559,89 +698,13 @@ public ref class AppListWnd: public System::Windows::Forms::Form, public IScript
using WebBrowser = System::Windows::Forms::WebBrowser;
using Timer = System::Windows::Forms::Timer;
[ComVisible (true)]
ref class IBridge: public _I_Bridge_Base2
ref class IBridge: public _I_Bridge_Base3
{
private:
AppListWnd ^wndinst = nullptr;
public:
using String = System::String;
IBridge (AppListWnd ^wnd): wndinst (wnd), _I_Bridge_Base2 (wnd) {}
ref class _I_System
{
private:
AppListWnd ^wndinst = nullptr;
public:
ref class _I_UI
{
private:
AppListWnd ^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 (AppListWnd ^wnd): wndinst (wnd) {}
property int DPIPercent { int get () { return GetDPI (); }}
property double DPI { double get () { return DPIPercent * 0.01; }}
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 ^ThemeColor { String ^get () { return ColorToHtml (GetDwmThemeColor ()); } }
property bool DarkMode { bool get () { return IsAppInDarkMode (); }}
property String ^HighContrast
{
String ^get ()
{
auto highc = GetHighContrastTheme ();
switch (highc)
{
case HighContrastTheme::None: return "none";
break;
case HighContrastTheme::Black: return "black";
break;
case HighContrastTheme::White: return "white";
break;
case HighContrastTheme::Other: return "high";
break;
default: return "none";
break;
}
return "none";
}
}
};
private:
_I_UI ^ui = gcnew _I_UI (wndinst);
_I_Resources ^ires = gcnew _I_Resources ();
public:
_I_System (AppListWnd ^wnd): wndinst (wnd) {}
property _I_UI ^UI { _I_UI ^get () { return ui; } }
property _I_Resources ^Resources { _I_Resources ^get () { return ires; } }
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
IBridge (AppListWnd ^wnd): wndinst (wnd), _I_Bridge_Base3 (wnd, wnd) {}
ref class _I_IEFrame: public _I_IEFrame_Base
{
private:
AppListWnd ^wndinst = nullptr;
@@ -652,33 +715,10 @@ public ref class AppListWnd: public System::Windows::Forms::Form, public IScript
int get () { return wndinst->PageScale; }
void set (int value) { return wndinst->PageScale = value; }
}
property int Version { int get () { return GetInternetExplorerVersionMajor (); }}
String ^ParseHtmlColor (String ^color)
{
auto dcolor = Drawing::ColorTranslator::FromHtml (color);
{
rapidjson::Document doc;
doc.SetObject ();
auto &alloc = doc.GetAllocator ();
doc.AddMember ("r", (uint16_t)dcolor.R, alloc);
doc.AddMember ("g", (uint16_t)dcolor.G, alloc);
doc.AddMember ("b", (uint16_t)dcolor.B, alloc);
doc.AddMember ("a", (uint16_t)dcolor.A, alloc);
rapidjson::StringBuffer buffer;
rapidjson::Writer <rapidjson::StringBuffer> writer (buffer);
doc.Accept (writer);
std::string utf8 = buffer.GetString ();
std::wstring_convert <std::codecvt_utf8 <wchar_t>> conv;
return CStringToMPString (conv.from_bytes (utf8));
}
return "{}";
}
};
private:
_I_System ^system = gcnew _I_System (wndinst);
_I_IEFrame ^ieframe = gcnew _I_IEFrame (wndinst);
public:
property _I_System ^System { _I_System ^get () { return system; }}
property _I_IEFrame ^IEFrame { _I_IEFrame ^get () { return ieframe; }}
};
private:
@@ -741,7 +781,8 @@ public ref class AppListWnd: public System::Windows::Forms::Form, public IScript
for (auto &app : it.applications)
{
std::wstring launchid = it.identity.package_family_name + L'!' + app [L"Id"];
auto &color = app [L"BackgroundColor"];
std::wnstring color = app [L"BackgroundColor"];
if (color.empty () || color.equals (L"transparent")) color = MPStringToStdW (ColorToHtml (GetDwmThemeColor ()));
std::wnstring displayName = app [L"DisplayName"];
if (displayName.empty ()) displayName = app [L"ShortName"];
auto &logo = app [L"Square44x44Logo"];
@@ -918,163 +959,52 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScrip
ITaskbarList3 *taskbar = nullptr;
public:
[ComVisible (true)]
ref class _I_UI2: public _I_UI
{
private:
MainHtmlWnd ^wndinst = nullptr;
public:
_I_UI2 (MainHtmlWnd ^wnd): wndinst (wnd), _I_UI (wnd) {}
property String ^SplashImage
{
String ^get ()
{
auto uri = gcnew Uri (CStringToMPString (wndinst->GetSuitSplashImage ()));
return uri->AbsoluteUri;
}
}
property String ^SplashBackgroundColor
{
String ^get ()
{
std::wnstring ret = L"";
auto personal = g_initfile [L"Personalization"];
auto thememode = personal [L"AppInstaller:ThemeMode"];
auto custommode = personal [L"AppInstaller:CustomThemeMode"];
bool nowdark =
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"dark") ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"auto") && IsAppInDarkMode () ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"custom") && IsNormalizeStringEquals (custommode.read_wstring ().c_str (), L"dark") ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"custom") && IsNormalizeStringEquals (custommode.read_wstring ().c_str (), L"auto") && IsAppInDarkMode ();
if (nowdark) ret = g_vemani.splash_screen_backgroundcolor_darkmode (L"App");
else ret = g_vemani.splash_screen_backgroundcolor (L"App");
if (ret.empty ()) ret = g_vemani.splash_screen_backgroundcolor (L"App");
if (ret.empty ()) ret = g_vemani.background_color (L"App");
return CStringToMPString (ret);
}
}
void ShowSplash () { if (wndinst->SplashScreen->IsHandleCreated) wndinst->SplashScreen->Show (); else wndinst->SplashScreen->ReInit (); }
void FadeAwaySplash () { wndinst->SplashScreen->FadeAway (); }
void FadeOutSplash () { wndinst->SplashScreen->FadeOut (); }
};
[ComVisible (true)]
ref class IBridge: public _I_Bridge_Base2
{
private:
MainHtmlWnd ^wndinst = nullptr;
public:
using String = System::String;
IBridge (MainHtmlWnd ^wnd): wndinst (wnd), _I_Bridge_Base2 (wnd) {}
ref class _I_System
{
private:
MainHtmlWnd ^wndinst = nullptr;
public:
ref class _I_UI
{
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; }}
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; }}
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 ()
{
std::wnstring ret = L"";
auto personal = g_initfile [L"Personalization"];
auto thememode = personal [L"AppInstaller:ThemeMode"];
auto custommode = personal [L"AppInstaller:CustomThemeMode"];
bool nowdark =
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"dark") ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"auto") && IsAppInDarkMode () ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"custom") && IsNormalizeStringEquals (custommode.read_wstring ().c_str (), L"dark") ||
IsNormalizeStringEquals (thememode.read_wstring ().c_str (), L"custom") && IsNormalizeStringEquals (custommode.read_wstring ().c_str (), L"auto") && IsAppInDarkMode ();
if (nowdark) ret = g_vemani.splash_screen_backgroundcolor_darkmode (L"App");
else ret = g_vemani.splash_screen_backgroundcolor (L"App");
if (ret.empty ()) ret = g_vemani.splash_screen_backgroundcolor (L"App");
if (ret.empty ()) ret = g_vemani.background_color (L"App");
return CStringToMPString (ret);
}
}
void ShowSplash () { if (wndinst->SplashScreen->IsHandleCreated) wndinst->SplashScreen->Show (); else wndinst->SplashScreen->ReInit (); }
void FadeAwaySplash () { wndinst->SplashScreen->FadeAway (); }
void FadeOutSplash () { wndinst->SplashScreen->FadeOut (); }
property String ^ThemeColor { String ^get () { return ColorToHtml (GetDwmThemeColor ()); } }
property bool DarkMode { bool get () { return IsAppInDarkMode (); }}
property String ^HighContrast
{
String ^get ()
{
auto highc = GetHighContrastTheme ();
switch (highc)
{
case HighContrastTheme::None: return "none";
break;
case HighContrastTheme::Black: return "black";
break;
case HighContrastTheme::White: return "white";
break;
case HighContrastTheme::Other: return "high";
break;
default: return "none";
break;
}
return "none";
}
}
};
ref class _I_Locale
{
public:
property String ^CurrentLocale { String ^get () { return CStringToMPString (GetComputerLocaleCodeW ()); } }
property LCID CurrentLCID { LCID get () { return LocaleCodeToLcid (GetComputerLocaleCodeW ()); } }
String ^ToLocaleName (LCID lcid) { return CStringToMPString (LcidToLocaleCodeW (lcid)); }
LCID ToLCID (String ^localename) { return LocaleCodeToLcidW (MPStringToStdW (localename)); }
Object ^LocaleInfo (LCID lcid, LCTYPE lctype) { return CStringToMPString (GetLocaleInfoW (lcid, lctype)); }
Object ^LocaleInfoEx (String ^localeName, LCTYPE lctype)
{
std::wstring output = L"";
int ret = GetLocaleInfoEx (MPStringToStdW (localeName), lctype, output);
if (output.empty ()) return ret;
else return CStringToMPString (output);
}
};
private:
_I_UI ^ui = gcnew _I_UI (wndinst);
_I_Resources ^ires = gcnew _I_Resources ();
_I_Locale ^locale = gcnew _I_Locale ();
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 _I_Locale ^Locale { _I_Locale ^get () { return locale; }}
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
[ComVisible (true)]
ref class _I_IEFrame: public _I_IEFrame_Base
{
private:
MainHtmlWnd ^wndinst = nullptr;
@@ -1085,44 +1015,30 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScrip
int get () { return wndinst->PageScale; }
void set (int value) { return wndinst->PageScale = value; }
}
property int Version { int get () { return GetInternetExplorerVersionMajor (); }}
String ^ParseHtmlColor (String ^color)
{
auto dcolor = Drawing::ColorTranslator::FromHtml (color);
{
rapidjson::Document doc;
doc.SetObject ();
auto &alloc = doc.GetAllocator ();
doc.AddMember ("r", (uint16_t)dcolor.R, alloc);
doc.AddMember ("g", (uint16_t)dcolor.G, alloc);
doc.AddMember ("b", (uint16_t)dcolor.B, alloc);
doc.AddMember ("a", (uint16_t)dcolor.A, alloc);
rapidjson::StringBuffer buffer;
rapidjson::Writer <rapidjson::StringBuffer> writer (buffer);
doc.Accept (writer);
std::string utf8 = buffer.GetString ();
std::wstring_convert <std::codecvt_utf8 <wchar_t>> conv;
return CStringToMPString (conv.from_bytes (utf8));
}
return "{}";
}
};
ref class _I_Window
[ComVisible (true)]
ref class _I_System3: public _I_System
{
private:
MainHtmlWnd ^wndinst = nullptr;
protected:
_I_UI2 ^ui2;
public:
_I_Window (MainHtmlWnd ^wnd): wndinst (wnd) {}
Object ^CallEvent (String ^name, ... array <Object ^> ^args) { return wndinst->CallEvent (name, args [0]); }
_I_System3 (MainHtmlWnd ^wnd)
{
ui2 = gcnew _I_UI2 (wnd);
}
property _I_UI2 ^UI { _I_UI2 ^get () { return ui2; } }
};
private:
_I_System ^system = gcnew _I_System (wndinst);
_I_IEFrame ^ieframe = gcnew _I_IEFrame (wndinst);
_I_Window ^wnd = gcnew _I_Window (wndinst);
_I_IEFrame ^ieframe;
_I_System3 ^sys;
public:
property _I_System ^System { _I_System ^get () { return system; }}
IBridge (MainHtmlWnd ^wnd): wndinst (wnd), _I_Bridge_Base2 (wnd)
{
ieframe = gcnew _I_IEFrame (wnd);
sys = gcnew _I_System3 (wnd);
}
property _I_IEFrame ^IEFrame { _I_IEFrame ^get () { return ieframe; }}
property _I_Window ^Window { _I_Window ^get () { return wnd; }}
property _I_System3 ^System { _I_System3 ^get () { return sys; }}
};
protected:
property WebBrowser ^WebUI { WebBrowser ^get () { return this->webui; } }
@@ -1652,7 +1568,7 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScrip
std::vector <std::wnstring> appids;
for (auto &it : g_pkginfo)
for (auto &it_s : it.applications)
if (!it_s [L"Id"].empty ())
if (!it_s [L"Id"].empty ())
appids.emplace_back (it.identity.package_family_name + L'!' + it_s [L"Id"]);
if (appids.size () == 1) ActivateAppxApplication (appids.at (0));
else if (appids.size () > 1) AppListWnd::DisplayWindow ();
@@ -1756,15 +1672,15 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScrip
Object ^CallScriptFunction (String ^lpFuncName, ... array <Object ^> ^alpParams)
{
try { return this->webui->Document->InvokeScript (lpFuncName, alpParams); }
catch (Exception ^e)
catch (Exception ^e)
{
try
{
this->webui->Document->InvokeScript ("messageBoxAsync", gcnew array <Object ^> {
e->Message,
e->Source,
0,
CStringToMPString (g_vemani.background_color (L"App"))
e->Message,
e->Source,
0,
CStringToMPString (g_vemani.background_color (L"App"))
});
}
catch (Exception ^ex)
@@ -1954,6 +1870,7 @@ int APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCm
if (!PathEquals (currdir, rootdir)) SetCurrentDirectoryW (rootdir.c_str ());
}
CoInitializeEx (NULL, COINIT_MULTITHREADED | COINIT_APARTMENTTHREADED);
SetupInstanceEnvironment ();
destruct relco ([] () {
CoUninitialize ();
});
+7
View File
@@ -115,5 +115,12 @@ public ref class _I_Resources
}
String ^GetByName (String ^lpResId) { return GetById (ToId (lpResId)); }
String ^operator [] (unsigned int uiResId) { return GetRCStringCli (uiResId); }
String ^GetFromOthers (String ^filepath, unsigned int resid)
{
HMODULE module = nullptr;
if (filepath && IsNormalizeStringEmpty (MPStringToStdW (filepath))) module = GetModuleHandleW (MPStringToStdW (filepath).c_str ());
else module = GetModuleHandleW (NULL);
return GetRCStringCli (resid, module);
}
};
#endif
+12
View File
@@ -1,6 +1,8 @@
#pragma once
#include <string>
#include <Windows.h>
#include <locale>
#include <codecvt>
std::wstring StringToWString (const std::string &str, UINT codePage = CP_ACP)
{
if (str.empty ()) return std::wstring ();
@@ -19,3 +21,13 @@ std::string WStringToString (const std::wstring &wstr, UINT codePage = CP_ACP)
WideCharToMultiByte (codePage, 0, wstr.c_str (), -1, &str [0], len, nullptr, nullptr);
return str;
}
std::string WStringToUtf8 (const std::wstring& ws)
{
static std::wstring_convert <std::codecvt_utf8_utf16 <wchar_t>> conv;
return conv.to_bytes (ws);
}
std::wstring Utf8ToWString (const std::string& s)
{
static std::wstring_convert <std::codecvt_utf8_utf16 <wchar_t>> conv;
return conv.from_bytes (s);
}