Skip to content

Commit

Permalink
- follow rime/librime#806, breaking change
Browse files Browse the repository at this point in the history
- build librime in ci
  • Loading branch information
fxliang committed Feb 6, 2024
1 parent f69f2c2 commit 8c8e958
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Copy Rime files
- name: build librime
run: .\github.install.bat

- name: Build Weasel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Copy Rime files
- name: build librime
run: .\github.install.bat

- name: Build Weasel
Expand Down
6 changes: 4 additions & 2 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ void _RefreshTrayIcon(const UINT session_id, const std::function<void()> _Update
void RimeWithWeaselHandler::_Setup()
{
RIME_STRUCT(RimeTraits, weasel_traits);
weasel_traits.shared_data_dir = weasel_shared_data_dir();
weasel_traits.user_data_dir = weasel_user_data_dir();
std::string shared_dir = weasel_shared_data_dir();
std::string user_dir = weasel_user_data_dir();
weasel_traits.shared_data_dir = shared_dir.c_str();
weasel_traits.user_data_dir = user_dir.c_str();
weasel_traits.prebuilt_data_dir = weasel_traits.shared_data_dir;
std::string distribution_name(wstring_to_string(WEASEL_IME_NAME, CP_UTF8));
weasel_traits.distribution_name = distribution_name.c_str();
Expand Down
21 changes: 10 additions & 11 deletions RimeWithWeasel/WeaselUtility.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include <string>
#include <WeaselUtility.h>

std::wstring WeaselUserDataPath() {
WCHAR path[MAX_PATH] = {0};
Expand All @@ -23,20 +24,18 @@ std::wstring WeaselUserDataPath() {
return path;
}

const char* weasel_shared_data_dir() {
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;
std::string weasel_shared_data_dir() {
wchar_t _path[MAX_PATH] = {0};
GetModuleFileNameW(NULL, _path, _countof(_path));
std::wstring _pathw(_path);
return wstring_to_string(_pathw, CP_UTF8);
}

const char* weasel_user_data_dir() {
static char path[MAX_PATH] = {0};
std::string weasel_user_data_dir() {
char path[MAX_PATH] = {0};
// Windows wants multi-byte file paths in native encoding
WideCharToMultiByte(CP_ACP, 0, WeaselUserDataPath().c_str(), -1, path, _countof(path) - 1, NULL, NULL);
return path;
WideCharToMultiByte(CP_UTF8, 0, WeaselUserDataPath().c_str(), -1, path, _countof(path) - 1, NULL, NULL);
return std::string(path);
}

std::string GetCustomResource(const char *name, const char *type)
Expand Down
6 changes: 4 additions & 2 deletions WeaselDeployer/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Configurator::Configurator()
void Configurator::Initialize()
{
RIME_STRUCT(RimeTraits, weasel_traits);
weasel_traits.shared_data_dir = weasel_shared_data_dir();
weasel_traits.user_data_dir = weasel_user_data_dir();
std::string shared_dir = weasel_shared_data_dir();
std::string user_dir = weasel_user_data_dir();
weasel_traits.shared_data_dir = shared_dir.c_str();
weasel_traits.user_data_dir = user_dir.c_str();
weasel_traits.prebuilt_data_dir = weasel_traits.shared_data_dir;
const int len = 20;
char utf8_str[len];
Expand Down
40 changes: 26 additions & 14 deletions github.install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ setlocal
git submodule init
git submodule update plum

set rime_version=1.9.0

set download_archive=rime-a608767-Windows-msvc.7z
set download_archive_deps=rime-deps-a608767-Windows-msvc.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%

7z x %download_archive% * -olibrime\ -y
7z x %download_archive_deps% * -olibrime\ -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\
rem set rime_version=1.9.0
rem
rem set download_archive=rime-a608767-Windows-msvc.7z
rem set download_archive_deps=rime-deps-a608767-Windows-msvc.7z
rem
rem curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive%
rem curl -LO https://github.com/rime/librime/releases/download/%rime_version%/%download_archive_deps%
rem
rem 7z x %download_archive% * -olibrime\ -y
rem 7z x %download_archive_deps% * -olibrime\ -y
rem
rem copy /Y librime\dist\include\rime_*.h include\
rem copy /Y librime\dist\lib\rime.lib lib\
rem copy /Y librime\dist\lib\rime.dll output\

rem load plugins
pushd librime\plugins\
rem wait for hchunhui/librime-lua#310 merged
rem git clone -v --depth=1 https://github.com/hchunhui/librime-lua.git
git clone -v --depth=1 https://github.com/lotem/librime-lua.git
git clone -v --depth=1 -b thirdparty https://github.com/hchunhui/librime-lua.git librime-lua\thirdparty
git clone -v --depth=1 https://github.com/rime/librime-predict.git
git clone -v --depth=1 https://github.com/lotem/librime-octagram.git
popd

build.bat librime

if not exist output\data\opencc mkdir output\data\opencc
copy /Y librime\share\opencc\*.* output\data\opencc\
Expand Down
5 changes: 2 additions & 3 deletions include/WeaselUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ inline std::wstring getUsername() {

// data directories
std::wstring WeaselUserDataPath();

const char* weasel_shared_data_dir();
const char* weasel_user_data_dir();
std::string weasel_shared_data_dir();
std::string weasel_user_data_dir();

inline BOOL IsUserDarkMode()
{
Expand Down
2 changes: 1 addition & 1 deletion librime
Submodule librime updated 136 files

0 comments on commit 8c8e958

Please sign in to comment.