Skip to content

Commit

Permalink
feat: add x64/WeaselDeployer.exe for wow64 situation, for big diction…
Browse files Browse the repository at this point in the history
…ary deployment.
  • Loading branch information
fxliang committed Sep 18, 2023
1 parent 60c7a71 commit 565ed9c
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 30 deletions.
8 changes: 8 additions & 0 deletions RimeWithWeasel/WeaselUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const char* weasel_shared_data_dir() {
strcpy_s(path + k + 1, _countof(path) - (k + 1), "data");
return path;
}
const char* weasel_shared_data_dir_x64() {
static char path[MAX_PATH] = {0};
GetModuleFileNameA(NULL, path, _countof(path));
std::string str_path(path);
size_t k = str_path.find_last_of("/\\");
strcpy_s(path + k + 1, _countof(path) - (k + 1), "..\\data");
return path;
}

const char* weasel_user_data_dir() {
static char path[MAX_PATH] = {0};
Expand Down
7 changes: 5 additions & 2 deletions WeaselDeployer/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ static void CreateFileIfNotExist(std::string filename)
{
std::string user_data_dir = weasel_user_data_dir();
std::wstring filepathw = string_to_wstring(user_data_dir) + L"\\" + string_to_wstring(filename);
DWORD dwAttrib = GetFileAttributes(filepathw.c_str());
if (!(INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)))
if (!IfFileExistW(filepathw))
{
std::wofstream o(filepathw, std::ios::app);
o.close();
Expand All @@ -36,7 +35,11 @@ Configurator::Configurator()
void Configurator::Initialize()
{
RIME_STRUCT(RimeTraits, weasel_traits);
#ifdef _WIN64
weasel_traits.shared_data_dir = weasel_shared_data_dir_x64();
#else
weasel_traits.shared_data_dir = weasel_shared_data_dir();
#endif
weasel_traits.user_data_dir = weasel_user_data_dir();
weasel_traits.prebuilt_data_dir = weasel_traits.shared_data_dir;
const int len = 20;
Expand Down
7 changes: 0 additions & 7 deletions WeaselDeployer/UIStyleSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ bool UIStyleSettings::GetPresetColorSchemes(std::vector<ColorSchemeInfo>* result
return true;
}

// check if a file exists
static inline bool IfFileExist(std::string filename)
{
DWORD dwAttrib = GetFileAttributes(string_to_wstring(filename).c_str());
return (INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

// get preview image from user dir first, then shared_dir
std::string UIStyleSettings::GetColorSchemePreview(const std::string& color_scheme_id) {
std::string shared_dir = rime_get_api()->get_shared_data_dir();
Expand Down
81 changes: 81 additions & 0 deletions WeaselDeployer/WeaselDeployer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>WeaselDeployer</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="..\weasel.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand All @@ -23,31 +32,58 @@
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<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>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<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>true</LinkIncremental>
<OutDir>$(SolutionDir)output\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)output\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)output\$(Platform)</OutDir>
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
Expand All @@ -66,6 +102,24 @@
<OutputFile>$(SolutionDir)output\$(ProjectName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(BOOST_ROOT);$(SolutionDir)\librime\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)\lib;$(BOOST_ROOT)\stage\lib;$(SolutionDir)\librime\build\lib\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>rimex64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)output\$(ProjectName)x64$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand All @@ -91,6 +145,31 @@
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(BOOST_ROOT);$(SolutionDir)\librime\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>rime$(Platform).lib;rime$(Platform).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\lib;$(BOOST_ROOT)\stage\lib;$(SolutionDir)\librime\build\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)output\$(Platform)\$(ProjectName)$(TargetExt)</OutputFile>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Configurator.h" />
<ClInclude Include="DictManagementDialog.h" />
Expand All @@ -108,7 +187,9 @@
<ClCompile Include="DictManagementDialog.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SwitcherSettingsDialog.cpp" />
<ClCompile Include="UIStyleSettings.cpp" />
Expand Down
16 changes: 12 additions & 4 deletions WeaselServer/WeaselServerApp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "WeaselServerApp.h"
#include "WeaselUtility.h"

WeaselServerApp::WeaselServerApp()
: m_handler(std::make_unique<RimeWithWeaselHandler>(&m_ui))
Expand Down Expand Up @@ -46,10 +47,17 @@ void WeaselServerApp::SetupMenuHandlers()
{
std::wstring dir(install_dir());
m_server.AddMenuHandler(ID_WEASELTRAY_QUIT, [this] { return m_server.Stop() == 0; });
m_server.AddMenuHandler(ID_WEASELTRAY_DEPLOY, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/deploy")));
m_server.AddMenuHandler(ID_WEASELTRAY_SETTINGS, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring()));
m_server.AddMenuHandler(ID_WEASELTRAY_DICT_MANAGEMENT, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/dict")));
m_server.AddMenuHandler(ID_WEASELTRAY_SYNC, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/sync")));
if (is_wow64() && IfFileExistW(dir + L"\\x64\\WeaselDeployer.exe") && IfFileExistW(dir + L"\\x64\\rime.dll")) {
m_server.AddMenuHandler(ID_WEASELTRAY_DEPLOY, std::bind(execute, dir + L"\\x64\\WeaselDeployer.exe", std::wstring(L"/deploy")));
m_server.AddMenuHandler(ID_WEASELTRAY_SETTINGS, std::bind(execute, dir + L"\\x64\\WeaselDeployer.exe", std::wstring()));
m_server.AddMenuHandler(ID_WEASELTRAY_DICT_MANAGEMENT, std::bind(execute, dir + L"\\x64\\WeaselDeployer.exe", std::wstring(L"/dict")));
m_server.AddMenuHandler(ID_WEASELTRAY_SYNC, std::bind(execute, dir + L"\\x64\\WeaselDeployer.exe", std::wstring(L"/sync")));
} else {
m_server.AddMenuHandler(ID_WEASELTRAY_DEPLOY, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/deploy")));
m_server.AddMenuHandler(ID_WEASELTRAY_SETTINGS, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring()));
m_server.AddMenuHandler(ID_WEASELTRAY_DICT_MANAGEMENT, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/dict")));
m_server.AddMenuHandler(ID_WEASELTRAY_SYNC, std::bind(execute, dir + L"\\WeaselDeployer.exe", std::wstring(L"/sync")));
}
m_server.AddMenuHandler(ID_WEASELTRAY_WIKI, std::bind(open, L"https://rime.im/docs/"));
m_server.AddMenuHandler(ID_WEASELTRAY_HOMEPAGE, std::bind(open, L"https://rime.im/"));
m_server.AddMenuHandler(ID_WEASELTRAY_FORUM, std::bind(open, L"https://rime.im/discuss/"));
Expand Down
12 changes: 0 additions & 12 deletions WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,6 @@ void CLangBarItemButton::SetLangbarStatus(DWORD dwStatus, BOOL fSet)
return;
}

BOOL is_wow64()
{
DWORD errorCode;
if (GetSystemWow64DirectoryW(NULL, 0) == 0)
if ((errorCode = GetLastError()) == ERROR_CALL_NOT_IMPLEMENTED)
return FALSE;
else
ExitProcess((UINT)errorCode);
else
return TRUE;
}

void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)
{
if(wID != ID_WEASELTRAY_RERUN_SERVICE)
Expand Down
10 changes: 10 additions & 0 deletions github.install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ set rime_version=1.9.0
set download_archive=rime-a608767-Windows-msvc.7z
set download_archive_deps=rime-deps-a608767-Windows-msvc.7z

set download_archive_x64=rime-a608767-Windows-clang.7z
set download_archive_deps_x64=rime-deps-a608767-Windows-clang.7z

curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive%
curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive_deps%
curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive_x64%
curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive_deps_x64%

7z x %download_archive% * -olibrime\ -y
7z x %download_archive_deps% * -olibrime\ -y
7z x %download_archive_x64% * -olibrime_x64\ -y
7z x %download_archive_deps_x64% * -olibrime_x64\ -y

copy /Y librime\dist\include\rime_*.h include\
copy /Y librime\dist\lib\rime.lib lib\
copy /Y librime\dist\lib\rime.dll output\

copy /Y librime_x64\dist\lib\rime.dll output\x64\
copy /Y librime_x64\dist\lib\rime.lib lib\rimex64.lib

if not exist output\data\opencc mkdir output\data\opencc
copy /Y librime\share\opencc\*.* output\data\opencc\

25 changes: 25 additions & 0 deletions include/WeaselUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ inline std::wstring getUsername() {
std::wstring WeaselUserDataPath();

const char* weasel_shared_data_dir();
const char* weasel_shared_data_dir_x64();
const char* weasel_user_data_dir();

inline std::wstring string_to_wstring(const std::string& str, int code_page = CP_ACP)
Expand Down Expand Up @@ -63,5 +64,29 @@ inline std::string wstring_to_string(const std::wstring& wstr, int code_page = C
return res;
}

inline bool IfFileExistW(std::wstring filepathw)
{
DWORD dwAttrib = GetFileAttributes(filepathw.c_str());
return (INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

inline bool IfFileExist(std::string filepath, int code_page = CP_ACP)
{
std::wstring filepathw{string_to_wstring(filepath, code_page)};
DWORD dwAttrib = GetFileAttributes(filepathw.c_str());
return (INVALID_FILE_ATTRIBUTES != dwAttrib && 0 == (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

inline bool is_wow64() {
DWORD errorCode;
if (GetSystemWow64DirectoryW(NULL, 0) == 0)
if ((errorCode = GetLastError()) == ERROR_CALL_NOT_IMPLEMENTED)
return false;
else
ExitProcess((UINT)errorCode);
else
return true;
}

// resource
std::string GetCustomResource(const char *name, const char *type);
4 changes: 4 additions & 0 deletions output/install.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ program_files:
; images
SetOutPath $INSTDIR\data\preview
File "data\preview\*.png"
; WeaselDeployerx64 files
SetOutPath $INSTDIR\x64
File /nonfatal "x64\WeaselDeployer.exe"
File /nonfatal "x64\rime.dll"

SetOutPath $INSTDIR

Expand Down
Empty file added output/x64/.placeholder
Empty file.
11 changes: 6 additions & 5 deletions weasel.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
# Visual Studio Version 16
VisualStudioVersion = 16.0.33529.622
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{53F79A24-5390-4640-84B5-19984EB3353B}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -141,12 +141,13 @@ Global
{1C497821-BD63-4F02-9094-32B185B62F23}.Release|x64.ActiveCfg = Release|x64
{1C497821-BD63-4F02-9094-32B185B62F23}.ReleaseHant|Win32.ActiveCfg = ReleaseHant|Win32
{1C497821-BD63-4F02-9094-32B185B62F23}.ReleaseHant|x64.ActiveCfg = ReleaseHant|x64
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Debug|Win32.ActiveCfg = Debug|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Debug|Win32.Build.0 = Debug|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Debug|Win32.ActiveCfg = Debug|x64
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Debug|Win32.Build.0 = Debug|x64
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Debug|x64.ActiveCfg = Debug|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Release|Win32.ActiveCfg = Release|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Release|Win32.Build.0 = Release|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Release|x64.ActiveCfg = Release|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Release|x64.ActiveCfg = Release|x64
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.Release|x64.Build.0 = Release|x64
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.ReleaseHant|Win32.ActiveCfg = Release|Win32
{F53F3E9C-CC4D-4D1D-9C2E-719FE60A7E6B}.ReleaseHant|x64.ActiveCfg = Release|Win32
{39F6E3F5-8F0B-4023-BC40-A66AE6C37095}.Debug|Win32.ActiveCfg = Debug|Win32
Expand Down

0 comments on commit 565ed9c

Please sign in to comment.