Skip to content

Commit 7a52fce

Browse files
committed
refactor(WeaselTSF): add error handling when try open RimeUserDir
1 parent 1ffd441 commit 7a52fce

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

WeaselTSF/LanguageBar.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,18 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID) {
316316
}
317317
break;
318318
case ID_WEASELTRAY_USERCONFIG:
319-
if (RegGetStringValue(HKEY_CURRENT_USER, L"Software\\Rime\\Weasel",
320-
L"RimeUserDir", dir) == ERROR_SUCCESS) {
321-
explore(dir);
322-
} else {
319+
if (FAILED(RegGetStringValue(HKEY_CURRENT_USER, L"Software\\Rime\\Weasel",
320+
L"RimeUserDir", dir)) ||
321+
dir.empty()) {
323322
WCHAR _path[MAX_PATH] = {0};
324323
ExpandEnvironmentStringsW(L"%AppData%\\Rime", _path, _countof(_path));
325-
if (_path[0]) {
326-
dir = std::wstring(_path);
327-
explore(dir);
328-
}
324+
dir = std::wstring(_path);
329325
}
326+
if (!dir.empty() && fs::exists(dir))
327+
explore(dir);
328+
else
329+
MessageBoxW(NULL, (L"Not found: " + dir).c_str(), L"RimeUserDir",
330+
MB_ICONERROR | MB_OK);
330331
break;
331332
case ID_WEASELTRAY_LOGDIR:
332333
explore(WeaselLogPath().wstring());

0 commit comments

Comments
 (0)