Replaced NSIS-based installer wrapper by 7z-based one.
[simple-x264-launcher.git] / etc / 7zSD.diff
blobecc58e5aa0dde5c4b8db8fa538d94923ff99d1e5
1 CPP/7zip/Bundles/SFXSetup/Compat.xml | 1 +
2 CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp | 52 +++++++++++++++++++-----
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 | 63 ++++++++++++++++++++++++++----
10 CPP/Windows/FileDir.h | 1 +
11 10 files changed, 110 insertions(+), 24 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..7f856f1 100644
23 --- a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
24 +++ b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
25 @@ -37,6 +37,27 @@ static CFSTR kTempDirPrefix = FTEXT("7zS");
27 #define _SHELL_EXECUTE
29 +static HWND GetCurrentHwnd(void)
31 + HWND result = ::GetActiveWindow();
32 + if(!result)
33 + {
34 + for (int i = 0; i < 256; ++i)
35 + {
36 + if(i > 0)
37 + {
38 + ::Sleep(1); /*some delay*/
39 + }
40 + result = ::GetForegroundWindow();
41 + if(result)
42 + {
43 + break; /*done*/
44 + }
45 + }
46 + }
47 + return result;
50 static bool ReadDataString(CFSTR fileName, LPCSTR startID,
51 LPCSTR endID, AString &stringResult)
53 @@ -145,7 +166,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
55 UString archiveName, switches;
56 #ifdef _SHELL_EXECUTE
57 - UString executeFile, executeParameters;
58 + UString executeFile, executeParameters, executeErrorMsg;
59 #endif
60 NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
62 @@ -191,7 +212,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
63 dirPrefix = pairs[index].String;
64 if (!installPrompt.IsEmpty() && !assumeYes)
66 - if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO |
67 + if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO | MB_SYSTEMMODAL |
68 MB_ICONQUESTION) != IDYES)
69 return 0;
71 @@ -200,6 +221,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
72 #ifdef _SHELL_EXECUTE
73 executeFile = GetTextConfigValue(pairs, L"ExecuteFile");
74 executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters");
75 + executeErrorMsg = GetTextConfigValue(pairs, L"ExecuteErrorMsg");
76 #endif
79 @@ -243,7 +265,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
81 if (errorMessage.IsEmpty())
82 errorMessage = NError::MyFormatMessage(result);
83 - ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
84 + ::MessageBoxW(NULL, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR | MB_SYSTEMMODAL);
87 return 1;
88 @@ -287,13 +309,25 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
89 execInfo.lpDirectory = NULL;
90 execInfo.nShow = SW_SHOWNORMAL;
91 execInfo.hProcess = 0;
92 - /* BOOL success = */ ::ShellExecuteEx(&execInfo);
93 - UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
94 - if (result <= 32)
96 + for (;;)
98 - if (!assumeYes)
99 - ShowErrorMessage(L"Can not open file");
100 - return 1;
101 + execInfo.hwnd = GetCurrentHwnd(); /*prevent UAC dialog from appearing in the background!*/
102 + /* BOOL success = */ ::ShellExecuteEx(&execInfo);
103 + UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
104 + if (result <= 32)
106 + if (!assumeYes)
108 + const wchar_t *const lpErrorMessage = executeErrorMsg.IsEmpty() ? L"Failed to launch installer. Please try again!" : executeErrorMsg;
109 + if (MessageBoxW(NULL, lpErrorMessage, L"Setup", MB_SYSTEMMODAL | MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY)
111 + continue; /*retry*/
114 + return 1;
116 + break; /*success*/
118 hProcess = execInfo.hProcess;
120 diff --git a/CPP/7zip/Bundles/SFXSetup/resource.rc b/CPP/7zip/Bundles/SFXSetup/resource.rc
121 index 47e1b76..c796e65 100644
122 --- a/CPP/7zip/Bundles/SFXSetup/resource.rc
123 +++ b/CPP/7zip/Bundles/SFXSetup/resource.rc
124 @@ -1,14 +1,14 @@
125 #include "../../MyVersionInfo.rc"
126 #include "resource.h"
128 -MY_VERSION_INFO_APP("7z Setup SFX", "7zS.sfx")
129 +MY_VERSION_INFO_APP("Setup SFX", "7zS.sfx")
131 IDI_ICON ICON "setup.ico"
133 STRINGTABLE
134 BEGIN
135 IDS_EXTRACTION_ERROR_TITLE "Extraction Failed"
136 - IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt"
137 + IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt. Please download again!"
138 IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'"
139 IDS_PROGRESS_EXTRACTING "Extracting"
141 diff --git a/CPP/7zip/UI/Explorer/MyMessages.cpp b/CPP/7zip/UI/Explorer/MyMessages.cpp
142 index 70c2a46..84ac8f4 100644
143 --- a/CPP/7zip/UI/Explorer/MyMessages.cpp
144 +++ b/CPP/7zip/UI/Explorer/MyMessages.cpp
145 @@ -1,6 +1,6 @@
146 // MyMessages.cpp
148 -#include "StdAfx.h"
149 +//#include "StdAfx.h"
151 #include "MyMessages.h"
153 @@ -13,7 +13,7 @@ using namespace NWindows;
155 void ShowErrorMessage(HWND window, LPCWSTR message)
157 - ::MessageBoxW(window, message, L"7-Zip", MB_OK | MB_ICONSTOP);
158 + ::MessageBoxW(window, message, L"Setup", MB_OK | MB_SYSTEMMODAL | MB_ICONSTOP);
161 void ShowErrorMessageHwndRes(HWND window, UINT resID)
162 diff --git a/CPP/7zip/UI/Explorer/MyMessages.h b/CPP/7zip/UI/Explorer/MyMessages.h
163 index d5822f4..3bd6e2e 100644
164 --- a/CPP/7zip/UI/Explorer/MyMessages.h
165 +++ b/CPP/7zip/UI/Explorer/MyMessages.h
166 @@ -6,7 +6,7 @@
167 #include "../../../Common/MyString.h"
169 void ShowErrorMessage(HWND window, LPCWSTR message);
170 -inline void ShowErrorMessage(LPCWSTR message) { ShowErrorMessage(0, message); }
171 +inline void ShowErrorMessage(LPCWSTR message) { ShowErrorMessage(NULL, message); }
173 void ShowErrorMessageHwndRes(HWND window, UInt32 langID);
174 void ShowErrorMessageRes(UInt32 langID);
175 diff --git a/CPP/7zip/UI/FileManager/FormatUtils.cpp b/CPP/7zip/UI/FileManager/FormatUtils.cpp
176 index 2143c3f..3a18712 100644
177 --- a/CPP/7zip/UI/FileManager/FormatUtils.cpp
178 +++ b/CPP/7zip/UI/FileManager/FormatUtils.cpp
179 @@ -1,6 +1,6 @@
180 // FormatUtils.cpp
182 -#include "StdAfx.h"
183 +//#include "StdAfx.h"
185 #include "../../../Common/IntToString.h"
187 diff --git a/CPP/7zip/UI/FileManager/ProgressDialog.cpp b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
188 index 65201a9..4d23499 100644
189 --- a/CPP/7zip/UI/FileManager/ProgressDialog.cpp
190 +++ b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
191 @@ -1,6 +1,6 @@
192 // ProgressDialog.cpp
194 -#include "StdAfx.h"
195 +//#include "StdAfx.h"
197 #include "../../../Common/IntToString.h"
199 @@ -165,7 +165,7 @@ bool CProgressDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
200 bool paused = Sync.GetPaused();
201 Sync.SetPaused(true);
202 _inCancelMessageBox = true;
203 - int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL);
204 + int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL | MB_SYSTEMMODAL);
205 _inCancelMessageBox = false;
206 Sync.SetPaused(paused);
207 if (res == IDCANCEL || res == IDNO)
208 diff --git a/CPP/Common/MyWindows.h b/CPP/Common/MyWindows.h
209 index 139a4e8..c40767f 100644
210 --- a/CPP/Common/MyWindows.h
211 +++ b/CPP/Common/MyWindows.h
212 @@ -6,6 +6,7 @@
213 #ifdef _WIN32
215 #include <windows.h>
216 +#include <shlobj.h>
218 #ifdef UNDER_CE
219 #undef VARIANT_TRUE
220 diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp
221 index da71b71..f21400b 100644
222 --- a/CPP/Windows/FileDir.cpp
223 +++ b/CPP/Windows/FileDir.cpp
224 @@ -14,6 +14,8 @@
225 extern bool g_IsNT;
226 #endif
228 +static CFSTR kTempDirName = FTEXT("TEMP");
230 using namespace NWindows;
231 using namespace NFile;
232 using namespace NName;
233 @@ -67,6 +69,36 @@ bool GetSystemDir(FString &path)
235 return (needLength > 0 && needLength <= MAX_PATH);
238 +bool GetAppDataDir(FString &path)
240 + HRESULT hResult;
241 + static const int FolderId[] = { CSIDL_LOCAL_APPDATA, CSIDL_APPDATA, CSIDL_PROFILE, NULL };
242 + for(size_t i = 0; i < 3; ++i)
244 + #ifndef _UNICODE
245 + if (!g_IsNT)
247 + TCHAR s[MAX_PATH + 2];
248 + s[0] = 0;
249 + hResult = ::SHGetFolderPath(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
250 + path = fas2fs(s);
252 + else
253 + #endif
255 + WCHAR s[MAX_PATH + 2];
256 + s[0] = 0;
257 + hResult = ::SHGetFolderPathW(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
258 + path = us2fs(s);
260 + if(hResult == S_OK)
262 + return true; /*success*/
265 + return false;
267 #endif
269 bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
270 @@ -566,7 +598,7 @@ bool MyGetTempPath(FString &path)
272 WCHAR s[MAX_PATH + 2];
273 s[0] = 0;
274 - needLength = ::GetTempPathW(MAX_PATH + 1, s);;
275 + needLength = ::GetTempPathW(MAX_PATH + 1, s);
276 path = us2fs(s);
278 return (needLength > 0 && needLength <= MAX_PATH);
279 @@ -671,12 +703,29 @@ bool CTempDir::Create(CFSTR prefix)
280 if (!Remove())
281 return false;
282 FString tempPath;
283 - if (!MyGetTempPath(tempPath))
284 - return false;
285 - if (!CreateTempFile(tempPath + prefix, true, _path, NULL))
286 - return false;
287 - _mustBeDeleted = true;
288 - return true;
289 + if (MyGetTempPath(tempPath))
291 + if (CreateTempFile(tempPath + prefix, true, _path, NULL))
293 + _mustBeDeleted = true;
294 + return true;
297 + if (GetAppDataDir(tempPath))
299 + tempPath.Add_PathSepar();
300 + tempPath += kTempDirName;
301 + if(CreateComplexDir(tempPath))
303 + tempPath.Add_PathSepar();
304 + if (CreateTempFile(tempPath + prefix, true, _path, NULL))
306 + _mustBeDeleted = true;
307 + return true;
311 + return false;
314 bool CTempDir::Remove()
315 diff --git a/CPP/Windows/FileDir.h b/CPP/Windows/FileDir.h
316 index b13d1cc..1d87bbf 100644
317 --- a/CPP/Windows/FileDir.h
318 +++ b/CPP/Windows/FileDir.h
319 @@ -13,6 +13,7 @@ namespace NDir {
321 bool GetWindowsDir(FString &path);
322 bool GetSystemDir(FString &path);
323 +bool GetAppDataDir(FString &path);
325 bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
326 bool SetFileAttrib(CFSTR path, DWORD attrib);