Bump version.
[simple-x264-launcher.git] / etc / 7zSD.diff
blob24b3b8e006232f1a21f36e4e3cf301dd9417d2d6
1 CPP/7zip/Bundles/SFXSetup/Compat.xml | 1 +
2 CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp | 51 +++++++++++++++++----
3 CPP/7zip/Bundles/SFXSetup/resource.rc | 4 +-
4 CPP/7zip/UI/Explorer/MyMessages.cpp | 4 +-
5 CPP/7zip/UI/Explorer/MyMessages.h | 2 +-
6 CPP/7zip/UI/FileManager/FormatUtils.cpp | 2 +-
7 CPP/7zip/UI/FileManager/ProgressDialog.cpp | 4 +-
8 CPP/Common/MyWindows.h | 1 +
9 CPP/Windows/FileDir.cpp | 73 ++++++++++++++++++++++++++----
10 CPP/Windows/FileDir.h | 1 +
11 10 files changed, 117 insertions(+), 26 deletions(-)
13 diff --git a/CPP/7zip/Bundles/SFXSetup/Compat.xml b/CPP/7zip/Bundles/SFXSetup/Compat.xml
14 new file mode 100644
15 index 0000000..76fecef
16 --- /dev/null
17 +++ b/CPP/7zip/Bundles/SFXSetup/Compat.xml
18 @@ -0,0 +1 @@
19 +<?xml version="1.0" encoding="utf-8"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/></application></compatibility></assembly>
20 \ No newline at end of file
21 diff --git a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
22 index aef2e19..53608cf 100644
23 --- a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
24 +++ b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
25 @@ -37,6 +37,26 @@ static CFSTR kTempDirPrefix = FTEXT("7zS");
27 #define _SHELL_EXECUTE
29 +static HWND GetCurrentHwnd(void)
31 + HWND result = ::GetActiveWindow();
32 + if(!(result && IsWindowVisible(result)))
33 + {
34 + for (int i = 0; i < 256; ++i)
35 + {
36 + ::Sleep(1); /*some delay*/
37 + if(const HWND hwnd = ::GetForegroundWindow())
38 + {
39 + if(IsWindowVisible(result = hwnd))
40 + {
41 + break; /*success*/
42 + }
43 + }
44 + }
45 + }
46 + return result;
49 static bool ReadDataString(CFSTR fileName, LPCSTR startID,
50 LPCSTR endID, AString &stringResult)
52 @@ -145,7 +165,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
54 UString archiveName, switches;
55 #ifdef _SHELL_EXECUTE
56 - UString executeFile, executeParameters;
57 + UString executeFile, executeParameters, executeErrorMsg;
58 #endif
59 NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
61 @@ -191,7 +211,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
62 dirPrefix = pairs[index].String;
63 if (!installPrompt.IsEmpty() && !assumeYes)
65 - if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO |
66 + if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO | MB_SYSTEMMODAL |
67 MB_ICONQUESTION) != IDYES)
68 return 0;
70 @@ -200,6 +220,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
71 #ifdef _SHELL_EXECUTE
72 executeFile = GetTextConfigValue(pairs, L"ExecuteFile");
73 executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters");
74 + executeErrorMsg = GetTextConfigValue(pairs, L"ExecuteErrorMsg");
75 #endif
78 @@ -243,7 +264,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
80 if (errorMessage.IsEmpty())
81 errorMessage = NError::MyFormatMessage(result);
82 - ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
83 + ::MessageBoxW(NULL, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR | MB_SYSTEMMODAL);
86 return 1;
87 @@ -287,13 +308,25 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
88 execInfo.lpDirectory = NULL;
89 execInfo.nShow = SW_SHOWNORMAL;
90 execInfo.hProcess = 0;
91 - /* BOOL success = */ ::ShellExecuteEx(&execInfo);
92 - UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
93 - if (result <= 32)
95 + for (;;)
97 - if (!assumeYes)
98 - ShowErrorMessage(L"Can not open file");
99 - return 1;
100 + execInfo.hwnd = GetCurrentHwnd(); /*prevent UAC dialog from appearing in the background!*/
101 + /* BOOL success = */ ::ShellExecuteEx(&execInfo);
102 + UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
103 + if (result <= 32)
105 + if (!assumeYes)
107 + const wchar_t *const lpErrorMessage = executeErrorMsg.IsEmpty() ? L"Failed to launch installer. Please try again!" : executeErrorMsg;
108 + if (MessageBoxW(NULL, lpErrorMessage, L"Setup", MB_SYSTEMMODAL | MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY)
110 + continue; /*retry*/
113 + return 1;
115 + break; /*success*/
117 hProcess = execInfo.hProcess;
119 diff --git a/CPP/7zip/Bundles/SFXSetup/resource.rc b/CPP/7zip/Bundles/SFXSetup/resource.rc
120 index 47e1b76..c796e65 100644
121 --- a/CPP/7zip/Bundles/SFXSetup/resource.rc
122 +++ b/CPP/7zip/Bundles/SFXSetup/resource.rc
123 @@ -1,14 +1,14 @@
124 #include "../../MyVersionInfo.rc"
125 #include "resource.h"
127 -MY_VERSION_INFO_APP("7z Setup SFX", "7zS.sfx")
128 +MY_VERSION_INFO_APP("Setup SFX", "7zS.sfx")
130 IDI_ICON ICON "setup.ico"
132 STRINGTABLE
133 BEGIN
134 IDS_EXTRACTION_ERROR_TITLE "Extraction Failed"
135 - IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt"
136 + IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt. Please download again!"
137 IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'"
138 IDS_PROGRESS_EXTRACTING "Extracting"
140 diff --git a/CPP/7zip/UI/Explorer/MyMessages.cpp b/CPP/7zip/UI/Explorer/MyMessages.cpp
141 index 70c2a46..84ac8f4 100644
142 --- a/CPP/7zip/UI/Explorer/MyMessages.cpp
143 +++ b/CPP/7zip/UI/Explorer/MyMessages.cpp
144 @@ -1,6 +1,6 @@
145 // MyMessages.cpp
147 -#include "StdAfx.h"
148 +//#include "StdAfx.h"
150 #include "MyMessages.h"
152 @@ -13,7 +13,7 @@ using namespace NWindows;
154 void ShowErrorMessage(HWND window, LPCWSTR message)
156 - ::MessageBoxW(window, message, L"7-Zip", MB_OK | MB_ICONSTOP);
157 + ::MessageBoxW(window, message, L"Setup", MB_OK | MB_SYSTEMMODAL | MB_ICONSTOP);
160 void ShowErrorMessageHwndRes(HWND window, UINT resID)
161 diff --git a/CPP/7zip/UI/Explorer/MyMessages.h b/CPP/7zip/UI/Explorer/MyMessages.h
162 index d5822f4..3bd6e2e 100644
163 --- a/CPP/7zip/UI/Explorer/MyMessages.h
164 +++ b/CPP/7zip/UI/Explorer/MyMessages.h
165 @@ -6,7 +6,7 @@
166 #include "../../../Common/MyString.h"
168 void ShowErrorMessage(HWND window, LPCWSTR message);
169 -inline void ShowErrorMessage(LPCWSTR message) { ShowErrorMessage(0, message); }
170 +inline void ShowErrorMessage(LPCWSTR message) { ShowErrorMessage(NULL, message); }
172 void ShowErrorMessageHwndRes(HWND window, UInt32 langID);
173 void ShowErrorMessageRes(UInt32 langID);
174 diff --git a/CPP/7zip/UI/FileManager/FormatUtils.cpp b/CPP/7zip/UI/FileManager/FormatUtils.cpp
175 index 2143c3f..3a18712 100644
176 --- a/CPP/7zip/UI/FileManager/FormatUtils.cpp
177 +++ b/CPP/7zip/UI/FileManager/FormatUtils.cpp
178 @@ -1,6 +1,6 @@
179 // FormatUtils.cpp
181 -#include "StdAfx.h"
182 +//#include "StdAfx.h"
184 #include "../../../Common/IntToString.h"
186 diff --git a/CPP/7zip/UI/FileManager/ProgressDialog.cpp b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
187 index 65201a9..4d23499 100644
188 --- a/CPP/7zip/UI/FileManager/ProgressDialog.cpp
189 +++ b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
190 @@ -1,6 +1,6 @@
191 // ProgressDialog.cpp
193 -#include "StdAfx.h"
194 +//#include "StdAfx.h"
196 #include "../../../Common/IntToString.h"
198 @@ -165,7 +165,7 @@ bool CProgressDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
199 bool paused = Sync.GetPaused();
200 Sync.SetPaused(true);
201 _inCancelMessageBox = true;
202 - int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL);
203 + int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL | MB_SYSTEMMODAL);
204 _inCancelMessageBox = false;
205 Sync.SetPaused(paused);
206 if (res == IDCANCEL || res == IDNO)
207 diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h
208 index 139a4e8..c40767f 100644
209 --- a/CPP/Common/MyWindows.h
210 +++ b/CPP/Common/MyWindows.h
211 @@ -6,6 +6,7 @@
212 #ifdef _WIN32
214 #include <windows.h>
215 +#include <shlobj.h>
217 #ifdef UNDER_CE
218 #undef VARIANT_TRUE
219 diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp
220 index da71b71..36d89fc 100644
221 --- a/CPP/Windows/FileDir.cpp
222 +++ b/CPP/Windows/FileDir.cpp
223 @@ -14,6 +14,8 @@
224 extern bool g_IsNT;
225 #endif
227 +static CFSTR kTempDirName = FTEXT("TEMP");
229 using namespace NWindows;
230 using namespace NFile;
231 using namespace NName;
232 @@ -67,6 +69,36 @@ bool GetSystemDir(FString &path)
234 return (needLength > 0 && needLength <= MAX_PATH);
237 +bool GetAppDataDir(FString &path)
239 + HRESULT hResult;
240 + static const int FolderId[] = { CSIDL_LOCAL_APPDATA, CSIDL_APPDATA, CSIDL_PROFILE, NULL };
241 + for(size_t i = 0; i < 3; ++i)
243 + #ifndef _UNICODE
244 + if (!g_IsNT)
246 + TCHAR s[MAX_PATH + 2];
247 + s[0] = 0;
248 + hResult = ::SHGetFolderPath(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
249 + path = fas2fs(s);
251 + else
252 + #endif
254 + WCHAR s[MAX_PATH + 2];
255 + s[0] = 0;
256 + hResult = ::SHGetFolderPathW(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
257 + path = us2fs(s);
259 + if(hResult == S_OK)
261 + return true; /*success*/
264 + return false;
266 #endif
268 bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
269 @@ -566,7 +598,7 @@ bool MyGetTempPath(FString &path)
271 WCHAR s[MAX_PATH + 2];
272 s[0] = 0;
273 - needLength = ::GetTempPathW(MAX_PATH + 1, s);;
274 + needLength = ::GetTempPathW(MAX_PATH + 1, s);
275 path = us2fs(s);
277 return (needLength > 0 && needLength <= MAX_PATH);
278 @@ -625,6 +657,35 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu
279 return false;
282 +static bool CreateTempFileSafely(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile)
284 + FString tempPath;
285 + if (MyGetTempPath(tempPath))
287 + if (CreateTempFile(tempPath + prefix, addRandom, path, outFile))
289 + return true;
292 + for(Byte retry = 0; retry < 2; ++retry)
294 + if (retry ? GetWindowsDir(tempPath) : GetAppDataDir(tempPath))
296 + tempPath.Add_PathSepar();
297 + tempPath += kTempDirName;
298 + if(CreateComplexDir(tempPath))
300 + tempPath.Add_PathSepar();
301 + if (CreateTempFile(tempPath + prefix, addRandom, path, outFile))
303 + return true;
308 + return false;
311 bool CTempFile::Create(CFSTR prefix, NIO::COutFile *outFile)
313 if (!Remove())
314 @@ -639,10 +700,7 @@ bool CTempFile::CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFil
316 if (!Remove())
317 return false;
318 - FString tempPath;
319 - if (!MyGetTempPath(tempPath))
320 - return false;
321 - if (!CreateTempFile(tempPath + namePrefix, true, _path, outFile))
322 + if (!CreateTempFileSafely(namePrefix, true, _path, outFile))
323 return false;
324 _mustBeDeleted = true;
325 return true;
326 @@ -670,10 +728,7 @@ bool CTempDir::Create(CFSTR prefix)
328 if (!Remove())
329 return false;
330 - FString tempPath;
331 - if (!MyGetTempPath(tempPath))
332 - return false;
333 - if (!CreateTempFile(tempPath + prefix, true, _path, NULL))
334 + if (!CreateTempFileSafely(prefix, true, _path, NULL))
335 return false;
336 _mustBeDeleted = true;
337 return true;
338 diff --git a/CPP/Windows/FileDir.h b/CPP/Windows/FileDir.h
339 index b13d1cc..1d87bbf 100644
340 --- a/CPP/Windows/FileDir.h
341 +++ b/CPP/Windows/FileDir.h
342 @@ -13,6 +13,7 @@ namespace NDir {
344 bool GetWindowsDir(FString &path);
345 bool GetSystemDir(FString &path);
346 +bool GetAppDataDir(FString &path);
348 bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
349 bool SetFileAttrib(CFSTR path, DWORD attrib);