-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlzma2408.dff
More file actions
578 lines (549 loc) · 18.1 KB
/
lzma2408.dff
File metadata and controls
578 lines (549 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
CPP/7zip/Bundles/SFXSetup/BannerDlg.cpp | 111 +++++++++++++++++++++++++++
CPP/7zip/Bundles/SFXSetup/BannerDlg.h | 22 ++++++
CPP/7zip/Bundles/SFXSetup/Compat.xml | 1 +
CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp | 67 ++++++++++++++---
CPP/7zip/Bundles/SFXSetup/resource.rc | 4 +-
CPP/7zip/UI/Explorer/MyMessages.cpp | 2 +-
CPP/7zip/UI/FileManager/ProgressDialog.cpp | 2 +-
CPP/Windows/FileDir.cpp | 116 +++++++++++++++++++++++++----
CPP/Windows/FileIO.cpp | 12 +++
CPP/Windows/FileIO.h | 1 +
10 files changed, 307 insertions(+), 31 deletions(-)
diff --git a/CPP/7zip/Bundles/SFXSetup/BannerDlg.cpp b/CPP/7zip/Bundles/SFXSetup/BannerDlg.cpp
new file mode 100644
index 0000000..ef22dc7
--- /dev/null
+++ b/CPP/7zip/Bundles/SFXSetup/BannerDlg.cpp
@@ -0,0 +1,111 @@
+// BannerDlg.cpp
+
+#include "BannerDlg.h"
+#include "resource.h"
+
+#define RECT_W(X) (((X).right > (X).left) ? ((X).right - (X).left) : 0)
+#define RECT_H(X) (((X).bottom > (X).top) ? ((X).bottom - (X).top) : 0)
+
+static const wchar_t *const DEF_TITLE = L"Setup";
+static const wchar_t *const DEF_MESSAGE = L"Setup is launching, please stay tuned...";
+
+CBannerDlg::CBannerDlg(const HINSTANCE hInstance, const UString &title, const UString &message)
+:
+ _message(message)
+{
+ _hwnd = CreateWindowExW(0, L"#32770", title.IsEmpty() ? DEF_TITLE : title.Ptr(), WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 384, 96, NULL, NULL, hInstance, NULL);
+ if (_hwnd != NULL)
+ {
+ RECT workRect, wndRect;
+ HICON hIcon;
+ SetWindowLongPtrW(_hwnd, GWLP_WNDPROC, (LONG_PTR)&MyWndProc);
+ SetWindowLongPtrW(_hwnd, GWLP_USERDATA, (LONG_PTR)this);
+ SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+ if (SystemParametersInfoW(SPI_GETWORKAREA, 0, &workRect, 0) && GetWindowRect(_hwnd, &wndRect))
+ {
+ MoveWindow(_hwnd, (RECT_W(workRect)-RECT_W(wndRect))/2, (RECT_H(workRect)-RECT_H(wndRect))/2, RECT_W(wndRect), RECT_H(wndRect), true);
+ }
+ if((hIcon = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_ICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR | LR_SHARED)) != NULL)
+ {
+ SendMessage(_hwnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
+ }
+ if((hIcon = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_ICON), IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR | LR_SHARED)) != NULL)
+ {
+ SendMessage(_hwnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
+ }
+ }
+}
+
+CBannerDlg::~CBannerDlg(void)
+{
+ if (_hwnd != NULL)
+ {
+ DestroyWindow(_hwnd);
+ _hwnd = NULL;
+ }
+}
+
+bool CBannerDlg::Show(void)
+{
+ if (_hwnd != NULL)
+ {
+ ShowWindow(_hwnd, SW_SHOWNORMAL);
+ ProcessPendingMessages();
+ Sleep(125);
+ SetForegroundWindow(_hwnd);
+ SetCapture(_hwnd);
+ return true;
+ }
+ return false;
+}
+
+LRESULT CALLBACK CBannerDlg::MyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch(uMsg)
+ {
+ case WM_PAINT:
+ PAINTSTRUCT ps;
+ if(const HDC hdc = BeginPaint(hwnd, &ps))
+ {
+ const CBannerDlg *const self = (const CBannerDlg*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
+ FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
+ DrawTextExW(hdc, (LPWSTR)(self->_message.IsEmpty() ? DEF_MESSAGE : self->_message.Ptr()), -1, &ps.rcPaint, DT_CENTER|DT_SINGLELINE|DT_VCENTER, NULL);
+ EndPaint(hwnd, &ps);
+ }
+ case WM_CLOSE:
+ return 0; /*ignore WM_CLOSE msg*/
+ default:
+ return DefWindowProc(hwnd, uMsg, wParam, lParam);
+ }
+}
+
+void CBannerDlg::ProcessPendingMessages()
+{
+ if (_hwnd != NULL)
+ {
+ MSG msg = {};
+ for (Byte i = 0U; i < 8U; ++i)
+ {
+ BOOL flag = FALSE;
+ if(i > 0U)
+ {
+ Sleep(1); /*delay*/
+ }
+ for (UInt16 k = 0U; k < 8192U; ++k)
+ {
+ if (PeekMessageW(&msg, _hwnd, 0U, 0U, PM_REMOVE))
+ {
+ flag = TRUE;
+ TranslateMessage(&msg);
+ DispatchMessageW(&msg);
+ continue;
+ }
+ break;
+ }
+ if(!flag)
+ {
+ break; /*did not process any messages*/
+ }
+ }
+ }
+}
diff --git a/CPP/7zip/Bundles/SFXSetup/BannerDlg.h b/CPP/7zip/Bundles/SFXSetup/BannerDlg.h
new file mode 100644
index 0000000..738e3b3
--- /dev/null
+++ b/CPP/7zip/Bundles/SFXSetup/BannerDlg.h
@@ -0,0 +1,22 @@
+// BannerDlg.h
+
+#include "../../../Common/MyString.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+class CBannerDlg
+{
+public:
+ CBannerDlg(const HINSTANCE hInstance, const UString &title, const UString &message);
+ ~CBannerDlg(void);
+ bool Show(void);
+ void ProcessPendingMessages();
+ HWND Hwnd() const { return _hwnd; }
+private:
+ CBannerDlg(CBannerDlg const&) {}
+ CBannerDlg& operator=(const CBannerDlg&) {}
+ static LRESULT CALLBACK MyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ HWND _hwnd;
+ const UString _message;
+};
diff --git a/CPP/7zip/Bundles/SFXSetup/Compat.xml b/CPP/7zip/Bundles/SFXSetup/Compat.xml
new file mode 100644
index 0000000..76fecef
--- /dev/null
+++ b/CPP/7zip/Bundles/SFXSetup/Compat.xml
@@ -0,0 +1 @@
+<?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>
\ No newline at end of file
diff --git a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
index eb28f5d..241f5c7 100644
--- a/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
+++ b/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
@@ -1,6 +1,7 @@
// Main.cpp
#include "StdAfx.h"
+#include <memory>
#include "../../../../C/DllSecur.h"
@@ -24,6 +25,8 @@
#include "ExtractEngine.h"
+#include "BannerDlg.h"
+
#include "resource.h"
using namespace NWindows;
@@ -41,12 +44,32 @@ static CFSTR const kTempDirPrefix = FTEXT("7zS");
#define MY_SHELL_EXECUTE
+static HWND GetCurrentHwnd(void)
+{
+ HWND result = ::GetActiveWindow();
+ if(!(result && IsWindowVisible(result)))
+ {
+ for (UInt32 i = 0; i < 256; ++i)
+ {
+ ::Sleep(1); /*some delay*/
+ if(const HWND hwnd = ::GetForegroundWindow())
+ {
+ if(IsWindowVisible(result = hwnd))
+ {
+ break; /*success*/
+ }
+ }
+ }
+ }
+ return result;
+}
+
static bool ReadDataString(CFSTR fileName, LPCSTR startID,
LPCSTR endID, AString &stringResult)
{
stringResult.Empty();
NIO::CInFile inFile;
- if (!inFile.Open(fileName))
+ if (!inFile.OpenSafely(fileName))
return false;
const size_t kBufferSize = (1 << 12);
@@ -151,7 +174,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
UString archiveName, switches;
#ifdef MY_SHELL_EXECUTE
- UString executeFile, executeParameters;
+ UString executeFile, executeParameters, launchingMsg, executeErrorMsg;
#endif
NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
@@ -177,7 +200,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
UString dirPrefix ("." STRING_PATH_SEPARATOR);
UString appLaunched;
- bool showProgress = true;
+ bool showProgress = !switches.IsPrefixedBy_Ascii_NoCase("-ms") && !switches.IsPrefixedBy_Ascii_NoCase("/ini") && !switches.IsPrefixedBy_Ascii_NoCase("/s");
if (!config.IsEmpty())
{
CObjectVector<CTextConfigPair> pairs;
@@ -197,7 +220,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
dirPrefix = pairs[index].String;
if (!installPrompt.IsEmpty() && !assumeYes)
{
- if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO |
+ if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO | MB_SYSTEMMODAL |
MB_ICONQUESTION) != IDYES)
return 0;
}
@@ -206,6 +229,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
#ifdef MY_SHELL_EXECUTE
executeFile = GetTextConfigValue(pairs, "ExecuteFile");
executeParameters = GetTextConfigValue(pairs, "ExecuteParameters");
+ launchingMsg = GetTextConfigValue(pairs, "LaunchingMsg");
+ executeErrorMsg = GetTextConfigValue(pairs, "ExecuteErrorMsg");
#endif
}
@@ -249,7 +274,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
{
if (errorMessage.IsEmpty())
errorMessage = NError::MyFormatMessage(result);
- ::MessageBoxW(NULL, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
+ ::MessageBoxW(NULL, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR | MB_SYSTEMMODAL);
}
}
return 1;
@@ -293,13 +318,33 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
execInfo.lpDirectory = NULL;
execInfo.nShow = SW_SHOWNORMAL;
execInfo.hProcess = NULL;
- /* BOOL success = */ ::ShellExecuteEx(&execInfo);
- UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
- if (result <= 32)
+
+ std::unique_ptr<CBannerDlg> banner;
+ if(showProgress)
+ banner.reset(new CBannerDlg(hInstance, executeFile, launchingMsg));
+ for (;;)
{
- if (!assumeYes)
- ShowErrorMessage(L"Cannot open file");
- return 1;
+ if(banner)
+ banner->Show();
+ execInfo.hwnd = (banner && (banner->Hwnd() != NULL)) ? banner->Hwnd() : GetCurrentHwnd(); /*prevent UAC dialog from appearing in the background!*/
+ const BOOL success = ::ShellExecuteEx(&execInfo);
+ const UINT32 result = success ? ((UINT32)(UINT_PTR)execInfo.hInstApp) : 0U;
+ if (result <= 32)
+ {
+ if(banner)
+ banner->ProcessPendingMessages();
+ if (!assumeYes)
+ {
+ const wchar_t *const lpErrorMessage = executeErrorMsg.IsEmpty() ? L"Failed to launch setup program. Please try again!" : executeErrorMsg;
+ const HWND hwnd = banner ? banner->Hwnd() : NULL;
+ if (MessageBoxW(hwnd, lpErrorMessage, executeFile.Ptr(), (hwnd ? MB_TOPMOST : MB_SYSTEMMODAL) | MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY)
+ {
+ continue; /*retry*/
+ }
+ }
+ return 1;
+ }
+ break; /*success*/
}
hProcess = execInfo.hProcess;
}
diff --git a/CPP/7zip/Bundles/SFXSetup/resource.rc b/CPP/7zip/Bundles/SFXSetup/resource.rc
index 47e1b76..c796e65 100644
--- a/CPP/7zip/Bundles/SFXSetup/resource.rc
+++ b/CPP/7zip/Bundles/SFXSetup/resource.rc
@@ -1,14 +1,14 @@
#include "../../MyVersionInfo.rc"
#include "resource.h"
-MY_VERSION_INFO_APP("7z Setup SFX", "7zS.sfx")
+MY_VERSION_INFO_APP("Setup SFX", "7zS.sfx")
IDI_ICON ICON "setup.ico"
STRINGTABLE
BEGIN
IDS_EXTRACTION_ERROR_TITLE "Extraction Failed"
- IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt"
+ IDS_EXTRACTION_ERROR_MESSAGE "File is corrupt. Please download again!"
IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'"
IDS_PROGRESS_EXTRACTING "Extracting"
END
diff --git a/CPP/7zip/UI/Explorer/MyMessages.cpp b/CPP/7zip/UI/Explorer/MyMessages.cpp
index c079e31..e81f932 100644
--- a/CPP/7zip/UI/Explorer/MyMessages.cpp
+++ b/CPP/7zip/UI/Explorer/MyMessages.cpp
@@ -16,7 +16,7 @@ extern bool g_DisableUserQuestions;
void ShowErrorMessage(HWND window, LPCWSTR message)
{
if (!g_DisableUserQuestions)
- ::MessageBoxW(window, message, L"7-Zip", MB_OK | MB_ICONSTOP);
+ ::MessageBoxW(window, message, L"Setup", MB_OK | MB_SYSTEMMODAL | MB_ICONSTOP);
}
void ShowErrorMessageHwndRes(HWND window, UInt32 resID)
diff --git a/CPP/7zip/UI/FileManager/ProgressDialog.cpp b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
index fc6f559..848482e 100644
--- a/CPP/7zip/UI/FileManager/ProgressDialog.cpp
+++ b/CPP/7zip/UI/FileManager/ProgressDialog.cpp
@@ -170,7 +170,7 @@ bool CProgressDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
bool paused = Sync.GetPaused();
Sync.SetPaused(true);
_inCancelMessageBox = true;
- int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL);
+ int res = ::MessageBoxW(*this, L"Are you sure you want to cancel?", _title, MB_YESNOCANCEL | MB_SYSTEMMODAL);
_inCancelMessageBox = false;
Sync.SetPaused(paused);
if (res == IDCANCEL || res == IDNO)
diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp
index dfeed82..b64dc72 100644
--- a/CPP/Windows/FileDir.cpp
+++ b/CPP/Windows/FileDir.cpp
@@ -1,7 +1,7 @@
// Windows/FileDir.cpp
#include "StdAfx.h"
-
+#include <ShlObj.h>
#ifndef _WIN32
#include <stdio.h>
@@ -27,6 +27,8 @@
extern bool g_IsNT;
#endif
+static CFSTR kTempDirName = FTEXT("TEMP");
+
using namespace NWindows;
using namespace NFile;
using namespace NName;
@@ -120,6 +122,36 @@ bool GetSystemDir(FString &path)
}
return (len != 0 && len < kBufSize);
}
+
+bool GetAppDataDir(FString &path)
+{
+ HRESULT hResult;
+ static const int FolderId[] = { CSIDL_LOCAL_APPDATA, CSIDL_APPDATA, CSIDL_PROFILE, NULL };
+ for(size_t i = 0; i < 3; ++i)
+ {
+ #ifndef _UNICODE
+ if (!g_IsNT)
+ {
+ TCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ hResult = ::SHGetFolderPath(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
+ path = fas2fs(s);
+ }
+ else
+ #endif
+ {
+ WCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ hResult = ::SHGetFolderPathW(NULL, FolderId[i] | CSIDL_FLAG_CREATE, NULL, 0, s);
+ path = us2fs(s);
+ }
+ if(hResult == S_OK)
+ {
+ return true; /*success*/
+ }
+ }
+ return false;
+}
#endif // UNDER_CE
@@ -838,13 +870,42 @@ bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFi
return false;
}
+static bool CreateTempFileSafely(CFSTR prefix, bool addRandom, FString &tempPath, AString &postfix, NIO::COutFile *outFile)
+{
+ if (MyGetTempPath(tempPath))
+ {
+ if (CreateTempFile2(tempPath + prefix, addRandom, postfix, outFile))
+ {
+ return true;
+ }
+ }
+ for(Byte retry = 0; retry < 2; ++retry)
+ {
+ if (retry ? GetWindowsDir(tempPath) : GetAppDataDir(tempPath))
+ {
+ tempPath.Add_PathSepar();
+ tempPath += kTempDirName;
+ if(CreateComplexDir(tempPath))
+ {
+ tempPath.Add_PathSepar();
+ if (CreateTempFile2(tempPath + prefix, addRandom, postfix, outFile))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
bool CTempFile::Create(CFSTR prefix, NIO::COutFile *outFile)
{
if (!Remove())
return false;
_path.Empty();
+ FString tempPath;
AString postfix;
- if (!CreateTempFile2(prefix, false, postfix, outFile))
+ if (!CreateTempFileSafely(prefix, false, tempPath, postfix, outFile))
return false;
_path = prefix;
_path += postfix;
@@ -858,11 +919,8 @@ bool CTempFile::CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFil
return false;
_path.Empty();
FString tempPath;
- if (!MyGetTempPath(tempPath))
- return false;
AString postfix;
- tempPath += namePrefix;
- if (!CreateTempFile2(tempPath, true, postfix, outFile))
+ if (!CreateTempFileSafely(namePrefix, true, tempPath, postfix, outFile))
return false;
_path = tempPath;
_path += postfix;
@@ -874,8 +932,17 @@ bool CTempFile::Remove()
{
if (!_mustBeDeleted)
return true;
- _mustBeDeleted = !DeleteFileAlways(_path);
- return !_mustBeDeleted;
+ for(UInt32 i = 0; i < 256; ++i)
+ {
+ if(i)
+ ::Sleep(i);
+ if(DeleteFileAlways(_path))
+ {
+ _mustBeDeleted = false;
+ return true;
+ }
+ }
+ return false;
}
bool CTempFile::MoveTo(CFSTR name, bool deleteDestBefore)
@@ -886,8 +953,19 @@ bool CTempFile::MoveTo(CFSTR name, bool deleteDestBefore)
if (NFind::DoesFileExist_Raw(name))
{
// attrib = NFind::GetFileAttrib(name);
- if (!DeleteFileAlways(name))
- return false;
+ bool deleted = false;
+ for(UInt32 i = 0; i < 256; ++i)
+ {
+ if(i)
+ ::Sleep(i);
+ if(DeleteFileAlways(name))
+ {
+ deleted = true;
+ break;
+ }
+ }
+ if (!deleted)
+ return false;
}
}
DisableDeleting();
@@ -910,11 +988,8 @@ bool CTempDir::Create(CFSTR prefix)
return false;
_path.Empty();
FString tempPath;
- if (!MyGetTempPath(tempPath))
- return false;
- tempPath += prefix;
AString postfix;
- if (!CreateTempFile2(tempPath, true, postfix, NULL))
+ if (!CreateTempFileSafely(prefix, true, tempPath, postfix, NULL))
return false;
_path = tempPath;
_path += postfix;
@@ -926,8 +1001,17 @@ bool CTempDir::Remove()
{
if (!_mustBeDeleted)
return true;
- _mustBeDeleted = !RemoveDirWithSubItems(_path);
- return !_mustBeDeleted;
+ for(UInt32 i = 0; i < 256; ++i)
+ {
+ if(i)
+ ::Sleep(i);
+ if(RemoveDirWithSubItems(_path))
+ {
+ _mustBeDeleted = false;
+ return true;
+ }
+ }
+ return false;
}
#endif
diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp
index dc4de14..dd80ba2 100644
--- a/CPP/Windows/FileIO.cpp
+++ b/CPP/Windows/FileIO.cpp
@@ -454,6 +454,18 @@ bool CInFile::Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, D
bool CInFile::OpenShared(CFSTR fileName, bool shareForWrite)
{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
+bool CInFile::OpenSafely(CFSTR fileName)
+{
+ for (UInt32 i = 0; i < 256; ++i)
+ {
+ if(i)
+ ::Sleep(i);
+ if (Open(fileName))
+ return true;
+ }
+ return false;
+}
+
bool CInFile::Open(CFSTR fileName)
{ return OpenShared(fileName, false); }
diff --git a/CPP/Windows/FileIO.h b/CPP/Windows/FileIO.h
index 6ba40eb..0628b3c 100644
--- a/CPP/Windows/FileIO.h
+++ b/CPP/Windows/FileIO.h
@@ -233,6 +233,7 @@ public:
bool Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool OpenShared(CFSTR fileName, bool shareForWrite);
bool Open(CFSTR fileName);
+ bool OpenSafely(CFSTR fileName);
#if 0
bool AttachStdIn()