Skip to content

Commit 3ee1d2c

Browse files
authored
fix: reg path for system installation (#15)
* fix: reg path for system installation * fix: /MACHINE flag for arm64
1 parent 7f4edcf commit 3ee1d2c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

main.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
],
7070
}],
7171
['target_arch=="arm64"', {
72-
'TargetMachine' : 0,
72+
'TargetMachine' : 18, # /MACHINE:ARM64 https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.vcprojectengine.machinetypeoption?view=visualstudiosdk-2022
7373
'defines': [
7474
'DLL_UUID="F5EA5883-1DA8-4A05-864A-D5DE2D2B2854"',
7575
],
@@ -100,7 +100,7 @@
100100
],
101101
}],
102102
['target_arch=="arm64"', {
103-
'TargetMachine' : 0,
103+
'TargetMachine' : 18, # /MACHINE:ARM64
104104
'defines': [
105105
'DLL_UUID="7D34756D-32DD-4EE6-B99F-2691C0DAD875"',
106106
],

src/explorer_command.cc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,29 @@ class __declspec(uuid(DLL_UUID)) ExplorerCommandHandler final : public RuntimeCl
9191
public:
9292
// IExplorerCommand implementation:
9393
IFACEMETHODIMP GetTitle(IShellItemArray* items, PWSTR* name) {
94-
wchar_t value_w[MAX_PATH];
94+
const size_t kMaxStringLength = 1024;
95+
wchar_t value_w[kMaxStringLength];
96+
wchar_t expanded_value_w[kMaxStringLength];
9597
DWORD value_size_w = sizeof(value_w);
9698
#if defined(INSIDER)
97-
const wchar_t kTitleRegkey[] = L"Software\\Microsoft\\VSCodeInsiders\\ContextMenu";
99+
const wchar_t kTitleRegkey[] = L"Software\\Classes\\VSCodeInsidersContextMenu";
98100
#else
99-
const wchar_t kTitleRegkey[] = L"Software\\Microsoft\\VSCode\\ContextMenu";
101+
const wchar_t kTitleRegkey[] = L"Software\\Classes\\VSCodeContextMenu";
100102
#endif
101-
LONG result = RegGetValueW(HKEY_LOCAL_MACHINE, kTitleRegkey, L"Title", RRF_RT_REG_EXPAND_SZ | RRF_NOEXPAND,
102-
NULL, reinterpret_cast<LPBYTE>(&value_w), &value_size_w);
103-
if (result != ERROR_SUCCESS || value_size_w == 0) {
104-
RETURN_IF_FAILED(RegGetValueW(HKEY_CURRENT_USER, kTitleRegkey, L"Title", RRF_RT_REG_EXPAND_SZ | RRF_NOEXPAND,
105-
NULL, reinterpret_cast<LPBYTE>(&value_w), &value_size_w));
103+
HKEY subhkey = nullptr;
104+
LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, kTitleRegkey, 0, KEY_READ, &subhkey);
105+
if (result != ERROR_SUCCESS) {
106+
result = RegOpenKeyEx(HKEY_CURRENT_USER, kTitleRegkey, 0, KEY_READ, &subhkey);
106107
}
107-
return SHStrDup(value_w, name);
108+
109+
DWORD type = REG_EXPAND_SZ;
110+
RegQueryValueEx(subhkey, L"Title", nullptr, &type,
111+
reinterpret_cast<LPBYTE>(&value_w), &value_size_w);
112+
RegCloseKey(subhkey);
113+
value_size_w = ExpandEnvironmentStrings(value_w, expanded_value_w, kMaxStringLength);
114+
return (value_size_w && value_size_w < kMaxStringLength)
115+
? SHStrDup(expanded_value_w, name)
116+
: SHStrDup(L"UnExpected Title", name);
108117
}
109118

110119
IFACEMETHODIMP GetIcon(IShellItemArray* items, PWSTR* icon) {

0 commit comments

Comments
 (0)