MCPcopy Create free account
hub / github.com/Squirrel/Squirrel.Windows / ExtractUpdaterAndRun

Method ExtractUpdaterAndRun

src/Setup/UpdateRunner.cpp:150–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir)
151{
152 PROCESS_INFORMATION pi = { 0 };
153 STARTUPINFO si = { 0 };
154 CResource zipResource;
155 wchar_t targetDir[MAX_PATH] = { 0 };
156 wchar_t logFile[MAX_PATH];
157
158 std::vector<CString> to_delete;
159
160 wchar_t* envSquirrelTemp = _wgetenv(L"SQUIRREL_TEMP");
161 if (envSquirrelTemp &&
162 DirectoryExists(envSquirrelTemp) &&
163 DirectoryIsWritable(envSquirrelTemp) &&
164 !PathIsUNCW(envSquirrelTemp)) {
165 _swprintf_c(targetDir, _countof(targetDir), L"%s", envSquirrelTemp);
166 goto gotADir;
167 }
168
169 if (!useFallbackDir) {
170 SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, targetDir);
171 goto gotADir;
172 }
173
174 wchar_t username[512];
175 wchar_t appDataDir[MAX_PATH];
176 ULONG unameSize = _countof(username);
177
178 SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataDir);
179 GetUserName(username, &unameSize);
180
181 _swprintf_c(targetDir, _countof(targetDir), L"%s\\%s", appDataDir, username);
182
183 if (!CreateDirectory(targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
184 wchar_t err[4096];
185 _swprintf_c(err, _countof(err), L"Unable to write to %s - IT policies may be restricting access to this folder", targetDir);
186 DisplayErrorMessage(CString(err), NULL);
187
188 return -1;
189 }
190
191gotADir:
192
193 wcscat_s(targetDir, _countof(targetDir), L"\\SquirrelTemp");
194
195 if (!CreateDirectory(targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
196 wchar_t err[4096];
197 _swprintf_c(err, _countof(err), L"Unable to write to %s - IT policies may be restricting access to this folder", targetDir);
198
199 if (useFallbackDir) {
200 DisplayErrorMessage(CString(err), NULL);
201 }
202
203 goto failedExtract;
204 }
205
206 swprintf_s(logFile, L"%s\\SquirrelSetup.log", targetDir);
207

Callers

nothing calls this directly

Calls 9

OpenZipFunction · 0.85
SetUnzipBaseDirFunction · 0.85
GetZipItemFunction · 0.85
UnzipItemFunction · 0.85
CStringClass · 0.50
LoadMethod · 0.45
GetSizeMethod · 0.45
LockMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected