Skip to content

Commit

Permalink
feat(WeaselDeployer): add Get Schemata button to run plum script (#174)
Browse files Browse the repository at this point in the history
* Add Get Schemata button in WeaselDeployer
* Launch plum Windows bootstrap script in interactive mode
* Reload schema list after running plum script
  • Loading branch information
Prcuvu authored Apr 6, 2018
1 parent c7558bb commit c786bb5
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
38 changes: 38 additions & 0 deletions WeaselDeployer/SwitcherSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <set>
#include <rime_levers_api.h>
#include <WeaselUtility.h>


SwitcherSettingsDialog::SwitcherSettingsDialog(RimeSwitcherSettings* settings)
Expand Down Expand Up @@ -83,6 +84,9 @@ LRESULT SwitcherSettingsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {

hotkeys_.Attach(GetDlgItem(IDC_HOTKEYS));
hotkeys_.EnableWindow(FALSE);

get_schemata_.Attach(GetDlgItem(IDC_GET_SCHEMATA));
get_schemata_.EnableWindow(TRUE);

Populate();

Expand All @@ -96,6 +100,40 @@ LRESULT SwitcherSettingsDialog::OnClose(UINT, WPARAM, LPARAM, BOOL&) {
return 0;
}

LRESULT SwitcherSettingsDialog::OnGetSchemata(WORD, WORD, HWND hWndCtl, BOOL&) {
HKEY hKey;
LSTATUS ret = RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Rime\\Weasel"), &hKey);
if (ret == ERROR_SUCCESS) {
WCHAR value[MAX_PATH];
DWORD len = sizeof(value);
DWORD type = 0;
DWORD data = 0;
ret = RegQueryValueExW(hKey, L"WeaselRoot", NULL, &type, (LPBYTE)value, &len);
if (ret == ERROR_SUCCESS && type == REG_SZ) {
WCHAR parameters[MAX_PATH + 37];
wcscpy_s<_countof(parameters)>(parameters, (std::wstring(L"/k \"") + value + L"\\rime-install.bat\" --select :all").c_str());
SHELLEXECUTEINFOW cmd = {
sizeof(SHELLEXECUTEINFO),
SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC,
hWndCtl,
L"open",
L"cmd",
parameters,
NULL,
SW_SHOW,
NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
ShellExecuteExW(&cmd);
WaitForSingleObject(cmd.hProcess, INFINITE);
CloseHandle(cmd.hProcess);
api_->load_settings(reinterpret_cast<RimeCustomSettings *>(settings_));
Populate();
}
}
RegCloseKey(hKey);
return 0;
}

LRESULT SwitcherSettingsDialog::OnOK(WORD, WORD code, HWND, BOOL&) {
if (modified_ && settings_ && schema_list_.GetItemCount() != 0) {
const char** selection = new const char*[schema_list_.GetItemCount()];
Expand Down
7 changes: 5 additions & 2 deletions WeaselDeployer/SwitcherSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class SwitcherSettingsDialog : public CDialogImpl<SwitcherSettingsDialog> {
BEGIN_MSG_MAP(SwitcherSettingsDialog)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
COMMAND_HANDLER(IDC_GET_SCHEMATA, BN_CLICKED, OnGetSchemata)
COMMAND_ID_HANDLER(IDOK, OnOK)
NOTIFY_HANDLER(IDC_SCHEMA_LIST, LVN_ITEMCHANGED, OnSchemaListItemChanged)
END_MSG_MAP()

LRESULT OnInitDialog(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnClose(UINT, WPARAM, LPARAM, BOOL&);
LRESULT OnOK(WORD, WORD code, HWND, BOOL&);
LRESULT OnGetSchemata(WORD, WORD, HWND, BOOL&);
LRESULT OnOK(WORD, WORD, HWND, BOOL&);
LRESULT OnSchemaListItemChanged(int, LPNMHDR, BOOL&);

void Populate();
Expand All @@ -33,6 +35,7 @@ class SwitcherSettingsDialog : public CDialogImpl<SwitcherSettingsDialog> {

CCheckListViewCtrl schema_list_;
CStatic description_;
CEdit hotkeys_;
CEdit hotkeys_;
CButton get_schemata_;
};

Binary file modified WeaselDeployer/WeaselDeployer.rc
Binary file not shown.
Binary file modified WeaselDeployer/resource.h
Binary file not shown.
1 change: 1 addition & 0 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ exit /b
rem call :build_essay
copy %WEASEL_ROOT%\LICENSE.txt output\
copy %WEASEL_ROOT%\README.md output\README.txt
copy %WEASEL_ROOT%\plum\rime-install.bat output\
set plum_dir=plum
set rime_dir=output/data
bash plum/rime-install
Expand Down
2 changes: 2 additions & 0 deletions output/install.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Section "Weasel"
program_files:
File "LICENSE.txt"
File "README.txt"
File "rime-install.bat"
File "rime-install-config.bat"
File "weasel.dll"
${If} ${RunningX64}
File "weaselx64.dll"
Expand Down
5 changes: 5 additions & 0 deletions output/rime-install-config.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rem for downloading Git for Windows installer
set git_mirror=taobao

rem Rime configuration manager and downloaded packages
set plum_dir=%APPDATA%\plum

0 comments on commit c786bb5

Please sign in to comment.