Skip to content

Commit

Permalink
Retrieve Mozc's installation dir from registry
Browse files Browse the repository at this point in the history
This is a preparation to switch Mozc's installation directory from

  %ProgramFiles(x86)%\Mozc

into

  %ProgramFiles%\Mozc

without user observable downtime (google#1086).

Currently the directory

  %ProgramFiles(x86)%\Mozc

is effectively hard coded in 'mozc_tip{32,64}.dll'. This means if older
versions of 'mozc_tip{32,64}.dll' continue assuming the previous
installation directory until it is unloaded or the process is restarted.

To avoid such mismatch, with this commit

  SystemUtil::GetServerDirectory()

starts dynamically retrieving Mozc's installation directory from
registry by checking COM entries of 'mozc_tip64.dll'. If it fails, we
fall back to the previous behavior.

Note that this is the first step of the migration and we cannot go to
the next step until 'mozc_tip{32,64}.dll' with this commit is deployed
to users.
  • Loading branch information
yukawa committed Oct 17, 2024
1 parent 8c8a446 commit 6de9d73
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Binary file added src/Mozc64.msi
Binary file not shown.
37 changes: 37 additions & 0 deletions src/base/system_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,48 @@ class ProgramFilesX86Cache {
HRESULT result_;
std::string path_;
};

constexpr wchar_t kMozcTipClsid[] =
L"SOFTWARE\\Classes\\CLSID\\"
#ifdef GOOGLE_JAPANESE_INPUT_BUILD
L"{D5A86FD5-5308-47EA-AD16-9C4EB160EC3C}"
#else // GOOGLE_JAPANESE_INPUT_BUILD
L"{10A67BC8-22FA-4A59-90DC-2546652C56BF}"
#endif // GOOGLE_JAPANESE_INPUT_BUILD
L"\\InprocServer32";

std::string GetMozcInstallDirFromRegistry() {
// TSF requires the path of "mozc_tip64.dll" to be registered in the registry,
// which tells us Mozc's installation directory.
HKEY key = nullptr;
LSTATUS result =::RegOpenKeyExW(
HKEY_LOCAL_MACHINE, kMozcTipClsid, 0, KEY_READ | KEY_WOW64_64KEY, &key);
if (result != ERROR_SUCCESS) {
return "";
}

DWORD type = 0;
wchar_t buffer[MAX_PATH] = {};
DWORD buffer_size = sizeof(buffer);
result = ::RegQueryValueExW(
key, nullptr, nullptr, &type, reinterpret_cast<LPBYTE>(buffer),
&buffer_size);
::RegCloseKey(key);
if (result != ERROR_SUCCESS || type != REG_SZ) {
return "";
}
return FileUtil::Dirname(win32::WideToUtf8(buffer));
}

} // namespace
#endif // _WIN32

std::string SystemUtil::GetServerDirectory() {
#ifdef _WIN32
const std::string install_dir_from_registry = GetMozcInstallDirFromRegistry();
if (!install_dir_from_registry.empty()) {
return install_dir_from_registry;
}
DCHECK(SUCCEEDED(Singleton<ProgramFilesX86Cache>::get()->result()));
#if defined(GOOGLE_JAPANESE_INPUT_BUILD)
return FileUtil::JoinPath(
Expand Down

0 comments on commit 6de9d73

Please sign in to comment.