Update Theme Settings.

This commit is contained in:
Bruce
2025-12-13 15:02:41 +08:00
parent fc66b6de72
commit 7c10123c8f
420 changed files with 84224 additions and 540 deletions

View File

@@ -13,6 +13,7 @@
#include "mpstr.h"
#include "strcode.h"
using namespace System;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
std::wstring HResultToMessage (HRESULT hr)
@@ -233,7 +234,6 @@ public ref class _I_Path
if (path) CoTaskMemFree (path);
return CStringToMPString (result);
}
bool PEquals (String ^l, String ^r) { return PathEquals (MPStringToStdW (l), MPStringToStdW (r)); }
};
[ComVisible (true)]
@@ -300,6 +300,10 @@ public ref class _I_File: public _I_Entry
auto lastEncoding = sr->CurrentEncoding;
return text;
}
catch (...)
{
return nullptr;
}
finally
{
if (sr) delete sr;
@@ -310,6 +314,11 @@ public ref class _I_File: public _I_Entry
{
using namespace System::IO;
if (String::IsNullOrEmpty (path)) return;
String ^dir = System::IO::Path::GetDirectoryName (path);
if (!String::IsNullOrEmpty (dir) && !System::IO::Directory::Exists (dir))
{
System::IO::Directory::CreateDirectory (dir);
}
Encoding ^enc = lastEncoding ? lastEncoding : Encoding::UTF8;
FileStream ^fs = nullptr;
StreamWriter ^sw = nullptr;
@@ -317,9 +326,9 @@ public ref class _I_File: public _I_Entry
{
fs = gcnew FileStream (
path,
FileMode::Create,
FileAccess::ReadWrite,
FileShare::ReadWrite
FileMode::Create, // 创建或覆盖
FileAccess::Write, // 只写即可
FileShare::Read // 允许别人读
);
sw = gcnew StreamWriter (fs, enc);
sw->Write (content);

View File

@@ -850,7 +850,44 @@ public ref class SplashForm: public System::Windows::Forms::Form
}
}
};
uint64_t GetFileSize (String ^filepath)
{
FileInfo ^fi = gcnew FileInfo (filepath);
if (!fi->Exists) return -1;
return fi->Length;
}
bool CopyFileWithDialog (const std::wstring &src, const std::wstring &dst)
{
HRESULT hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
if (FAILED (hr)) return false;
CComPtr <IFileOperation> pfo;
hr = pfo.CoCreateInstance (CLSID_FileOperation);
if (FAILED (hr)) return false;
pfo->SetOperationFlags (
FOF_NOCONFIRMMKDIR |
FOF_ALLOWUNDO
);
CComPtr <IShellItem> psiSrc;
CComPtr <IShellItem> psiDst;
hr = SHCreateItemFromParsingName (
src.c_str (),
NULL,
IID_PPV_ARGS (&psiSrc)
);
if (FAILED (hr)) return false;
std::wstring dstDir = GetFileDirectoryW (dst);
hr = SHCreateItemFromParsingName (
dstDir.c_str (),
NULL,
IID_PPV_ARGS (&psiDst)
);
if (FAILED (hr)) return false;
hr = pfo->CopyItem (psiSrc, psiDst, NULL, NULL);
if (FAILED (hr)) return false;
hr = pfo->PerformOperations ();
bool ok = SUCCEEDED (hr);
return ok;
}
[ComVisible (true)]
public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScriptBridge
{
@@ -1053,6 +1090,16 @@ public ref class MainHtmlWnd: public System::Windows::Forms::Form, public IScrip
doc.Accept (writer);
return CStringToMPString (StringToWString (buffer.GetString (), CP_UTF8));
}
String ^SelectFilesToJSON (String ^filter, DWORD flags, String ^wndtitle, String ^initdir)
{
std::vector <std::wstring> ret;
std::wstring filterbuf = MPStringToStdW (filter) + L'|||';
for (auto &it : filterbuf) if (it == L'|') it = L'\0';
ExploreFile (wndinst->InvokeGetHWND (), ret, (LPWSTR)filterbuf.c_str (), flags, MPStringToStdW (wndtitle), MPStringToStdW (initdir));
return CStringToMPString (StringArrayToJson (ret));
}
uint64_t GetFileSize (String ^filepath) { return ::GetFileSize (filepath); }
bool ShellCopyFile (String ^src, String ^desc) { return CopyFileWithDialog (MPStringToStdW (src), MPStringToStdW (desc)); }
void CloseWindow ()
{
if (wndinst && wndinst->IsHandleCreated) wndinst->Close ();