MCPcopy Create free account
hub / github.com/amule-project/amule / BackendReadTargetPath

Function BackendReadTargetPath

src/AutostartManager.cpp:162–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160 static const wchar_t *RUN_VALUE_NAME = L"aMule";
161
162 wxString BackendReadTargetPath()
163 {
164 HKEY hKey;
165 if (RegOpenKeyExW(HKEY_CURRENT_USER, RUN_KEY, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {
166 return wxEmptyString;
167 }
168
169 // First call returns the required buffer size; second call
170 // reads the value. Sized in bytes, includes the trailing NUL.
171 DWORD type = 0;
172 DWORD cb = 0;
173 LSTATUS rc = RegQueryValueExW(hKey, RUN_VALUE_NAME, NULL, &type, NULL, &cb);
174 if (rc != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ) || cb == 0) {
175 RegCloseKey(hKey);
176 return wxEmptyString;
177 }
178
179 // cb is in bytes; convert to wide-character count, rounding up.
180 size_t wlen = (cb + sizeof(wchar_t) - 1) / sizeof(wchar_t);
181 std::vector<wchar_t> buf(wlen + 1, L'\0');
182 rc = RegQueryValueExW(hKey, RUN_VALUE_NAME, NULL, &type,
183 reinterpret_cast<LPBYTE>(buf.data()), &cb);
184 RegCloseKey(hKey);
185 if (rc != ERROR_SUCCESS) {
186 return wxEmptyString;
187 }
188
189 wxString raw(buf.data());
190
191 // Windows stores Run entries either bare ("C:\Foo\bar.exe")
192 // or quoted ('"C:\Foo\bar.exe" --some-flag'). Strip surrounding
193 // quotes and discard any argument tail so the path comparison
194 // in SelfHealOnStartup matches the unadorned canonical path.
195 if (!raw.empty() && raw[0] == wxT('"')) {
196 size_t closing = raw.find(wxT('"'), 1);
197 if (closing != wxString::npos) {
198 return raw.SubString(1, closing - 1);
199 }
200 }
201 // Unquoted: take the leading non-whitespace run as the path.
202 size_t sp = raw.find_first_of(wxT(" \t"));
203 if (sp != wxString::npos) {
204 return raw.SubString(0, sp - 1);
205 }
206 return raw;
207 }
208
209 bool BackendWrite(const wxString &executable)
210 {

Callers 2

IsEnabledMethod · 0.85
SelfHealOnStartupMethod · 0.85

Calls 6

PlistPathFunction · 0.85
DesktopFilePathFunction · 0.85
StartsWithMethod · 0.80
emptyMethod · 0.45
IsOpenedMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected