summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/Windows
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/Windows')
-rw-r--r--3rdparty/lzma/CPP/Windows/COM.h32
-rw-r--r--3rdparty/lzma/CPP/Windows/Clipboard.cpp130
-rw-r--r--3rdparty/lzma/CPP/Windows/Clipboard.h28
-rw-r--r--3rdparty/lzma/CPP/Windows/CommonDialog.cpp310
-rw-r--r--3rdparty/lzma/CPP/Windows/CommonDialog.h44
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ComboBox.cpp8
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ComboBox.h32
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/CommandBar.h12
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Dialog.cpp289
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Dialog.h125
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Edit.h4
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ImageList.h8
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ListView.cpp59
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ListView.h54
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ProgressBar.h26
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/PropertyPage.cpp92
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/PropertyPage.h18
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ReBar.h6
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Static.h4
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/StatusBar.h10
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/StdAfx.h7
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/ToolBar.h6
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Trackbar.h4
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Window2.cpp14
-rw-r--r--3rdparty/lzma/CPP/Windows/Control/Window2.h16
-rw-r--r--3rdparty/lzma/CPP/Windows/DLL.cpp85
-rw-r--r--3rdparty/lzma/CPP/Windows/DLL.h65
-rw-r--r--3rdparty/lzma/CPP/Windows/Defs.h8
-rw-r--r--3rdparty/lzma/CPP/Windows/ErrorMsg.cpp75
-rw-r--r--3rdparty/lzma/CPP/Windows/ErrorMsg.h5
-rw-r--r--3rdparty/lzma/CPP/Windows/FileDir.cpp703
-rw-r--r--3rdparty/lzma/CPP/Windows/FileDir.h43
-rw-r--r--3rdparty/lzma/CPP/Windows/FileFind.cpp696
-rw-r--r--3rdparty/lzma/CPP/Windows/FileFind.h227
-rw-r--r--3rdparty/lzma/CPP/Windows/FileIO.cpp537
-rw-r--r--3rdparty/lzma/CPP/Windows/FileIO.h227
-rw-r--r--3rdparty/lzma/CPP/Windows/FileLink.cpp316
-rw-r--r--3rdparty/lzma/CPP/Windows/FileMapping.h6
-rw-r--r--3rdparty/lzma/CPP/Windows/FileName.cpp251
-rw-r--r--3rdparty/lzma/CPP/Windows/FileName.h48
-rw-r--r--3rdparty/lzma/CPP/Windows/FileSystem.cpp28
-rw-r--r--3rdparty/lzma/CPP/Windows/FileSystem.h8
-rw-r--r--3rdparty/lzma/CPP/Windows/Handle.h10
-rw-r--r--3rdparty/lzma/CPP/Windows/MemoryGlobal.cpp36
-rw-r--r--3rdparty/lzma/CPP/Windows/MemoryGlobal.h55
-rw-r--r--3rdparty/lzma/CPP/Windows/MemoryLock.cpp64
-rw-r--r--3rdparty/lzma/CPP/Windows/MemoryLock.h6
-rw-r--r--3rdparty/lzma/CPP/Windows/NtCheck.h16
-rw-r--r--3rdparty/lzma/CPP/Windows/PropVariant.cpp158
-rw-r--r--3rdparty/lzma/CPP/Windows/PropVariant.h79
-rw-r--r--3rdparty/lzma/CPP/Windows/PropVariantConv.cpp141
-rw-r--r--3rdparty/lzma/CPP/Windows/PropVariantConv.h18
-rw-r--r--3rdparty/lzma/CPP/Windows/Registry.cpp56
-rw-r--r--3rdparty/lzma/CPP/Windows/Registry.h4
-rw-r--r--3rdparty/lzma/CPP/Windows/ResourceString.cpp8
-rw-r--r--3rdparty/lzma/CPP/Windows/ResourceString.h5
-rw-r--r--3rdparty/lzma/CPP/Windows/SecurityUtils.cpp41
-rw-r--r--3rdparty/lzma/CPP/Windows/SecurityUtils.h93
-rw-r--r--3rdparty/lzma/CPP/Windows/Shell.cpp569
-rw-r--r--3rdparty/lzma/CPP/Windows/Shell.h64
-rw-r--r--3rdparty/lzma/CPP/Windows/StdAfx.h8
-rw-r--r--3rdparty/lzma/CPP/Windows/Synchronization.cpp77
-rw-r--r--3rdparty/lzma/CPP/Windows/Synchronization.h253
-rw-r--r--3rdparty/lzma/CPP/Windows/System.cpp194
-rw-r--r--3rdparty/lzma/CPP/Windows/System.h119
-rw-r--r--3rdparty/lzma/CPP/Windows/SystemInfo.cpp1022
-rw-r--r--3rdparty/lzma/CPP/Windows/SystemInfo.h19
-rw-r--r--3rdparty/lzma/CPP/Windows/Thread.h20
-rw-r--r--3rdparty/lzma/CPP/Windows/TimeUtils.cpp251
-rw-r--r--3rdparty/lzma/CPP/Windows/TimeUtils.h138
-rw-r--r--3rdparty/lzma/CPP/Windows/Window.cpp14
-rw-r--r--3rdparty/lzma/CPP/Windows/Window.h117
72 files changed, 7118 insertions, 1203 deletions
diff --git a/3rdparty/lzma/CPP/Windows/COM.h b/3rdparty/lzma/CPP/Windows/COM.h
index cee7f702d6f..a8780cacb30 100644
--- a/3rdparty/lzma/CPP/Windows/COM.h
+++ b/3rdparty/lzma/CPP/Windows/COM.h
@@ -1,9 +1,9 @@
// Windows/COM.h
-#ifndef __WINDOWS_COM_H
-#define __WINDOWS_COM_H
+#ifndef ZIP7_INC_WINDOWS_COM_H
+#define ZIP7_INC_WINDOWS_COM_H
-#include "../Common/MyString.h"
+// #include "../Common/MyString.h"
namespace NWindows {
namespace NCOM {
@@ -21,17 +21,18 @@ public:
// it's single thread. Do we need multithread?
CoInitialize(NULL);
#endif
- };
+ }
~CComInitializer() { CoUninitialize(); }
};
-class CStgMedium
+/*
+class CStgMedium2
{
STGMEDIUM _object;
-public:
bool _mustBeReleased;
- CStgMedium(): _mustBeReleased(false) {}
- ~CStgMedium() { Free(); }
+public:
+ CStgMedium2(): _mustBeReleased(false) {}
+ ~CStgMedium2() { Free(); }
void Free()
{
if (_mustBeReleased)
@@ -42,6 +43,21 @@ public:
STGMEDIUM* operator->() { return &_object;}
STGMEDIUM* operator&() { return &_object; }
};
+*/
+
+struct CStgMedium: public STGMEDIUM
+{
+ CStgMedium()
+ {
+ tymed = TYMED_NULL; // 0
+ hGlobal = NULL;
+ pUnkForRelease = NULL;
+ }
+ ~CStgMedium()
+ {
+ ReleaseStgMedium(this);
+ }
+};
#endif
diff --git a/3rdparty/lzma/CPP/Windows/Clipboard.cpp b/3rdparty/lzma/CPP/Windows/Clipboard.cpp
new file mode 100644
index 00000000000..bc7e201dd8d
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/Clipboard.cpp
@@ -0,0 +1,130 @@
+// Windows/Clipboard.cpp
+
+#include "StdAfx.h"
+
+#ifdef UNDER_CE
+#include <winuserm.h>
+#endif
+
+#include "../Common/StringConvert.h"
+
+#include "Clipboard.h"
+#include "Defs.h"
+#include "MemoryGlobal.h"
+#include "Shell.h"
+
+namespace NWindows {
+
+bool CClipboard::Open(HWND wndNewOwner) throw()
+{
+ m_Open = BOOLToBool(::OpenClipboard(wndNewOwner));
+ return m_Open;
+}
+
+bool CClipboard::Close() throw()
+{
+ if (!m_Open)
+ return true;
+ m_Open = !BOOLToBool(CloseClipboard());
+ return !m_Open;
+}
+
+bool ClipboardIsFormatAvailableHDROP()
+{
+ return BOOLToBool(IsClipboardFormatAvailable(CF_HDROP));
+}
+
+/*
+bool ClipboardGetTextString(AString &s)
+{
+ s.Empty();
+ if (!IsClipboardFormatAvailable(CF_TEXT))
+ return false;
+ CClipboard clipboard;
+
+ if (!clipboard.Open(NULL))
+ return false;
+
+ HGLOBAL h = ::GetClipboardData(CF_TEXT);
+ if (h != NULL)
+ {
+ NMemory::CGlobalLock globalLock(h);
+ const char *p = (const char *)globalLock.GetPointer();
+ if (p != NULL)
+ {
+ s = p;
+ return true;
+ }
+ }
+ return false;
+}
+*/
+
+/*
+bool ClipboardGetFileNames(UStringVector &names)
+{
+ names.Clear();
+ if (!IsClipboardFormatAvailable(CF_HDROP))
+ return false;
+ CClipboard clipboard;
+
+ if (!clipboard.Open(NULL))
+ return false;
+
+ HGLOBAL h = ::GetClipboardData(CF_HDROP);
+ if (h != NULL)
+ {
+ NMemory::CGlobalLock globalLock(h);
+ void *p = (void *)globalLock.GetPointer();
+ if (p != NULL)
+ {
+ NShell::CDrop drop(false);
+ drop.Attach((HDROP)p);
+ drop.QueryFileNames(names);
+ return true;
+ }
+ }
+ return false;
+}
+*/
+
+static bool ClipboardSetData(UINT uFormat, const void *data, size_t size) throw()
+{
+ NMemory::CGlobal global;
+ if (!global.Alloc(GMEM_DDESHARE | GMEM_MOVEABLE, size))
+ return false;
+ {
+ NMemory::CGlobalLock globalLock(global);
+ LPVOID p = globalLock.GetPointer();
+ if (!p)
+ return false;
+ memcpy(p, data, size);
+ }
+ if (::SetClipboardData(uFormat, global) == NULL)
+ return false;
+ global.Detach();
+ return true;
+}
+
+bool ClipboardSetText(HWND owner, const UString &s)
+{
+ CClipboard clipboard;
+ if (!clipboard.Open(owner))
+ return false;
+ if (!::EmptyClipboard())
+ return false;
+
+ bool res;
+ res = ClipboardSetData(CF_UNICODETEXT, (const wchar_t *)s, (s.Len() + 1) * sizeof(wchar_t));
+ #ifndef _UNICODE
+ AString a (UnicodeStringToMultiByte(s, CP_ACP));
+ if (ClipboardSetData(CF_TEXT, (const char *)a, (a.Len() + 1) * sizeof(char)))
+ res = true;
+ a = UnicodeStringToMultiByte(s, CP_OEMCP);
+ if (ClipboardSetData(CF_OEMTEXT, (const char *)a, (a.Len() + 1) * sizeof(char)))
+ res = true;
+ #endif
+ return res;
+}
+
+}
diff --git a/3rdparty/lzma/CPP/Windows/Clipboard.h b/3rdparty/lzma/CPP/Windows/Clipboard.h
new file mode 100644
index 00000000000..3b4f2fe5ee3
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/Clipboard.h
@@ -0,0 +1,28 @@
+// Windows/Clipboard.h
+
+#ifndef ZIP7_INC_CLIPBOARD_H
+#define ZIP7_INC_CLIPBOARD_H
+
+#include "../Common/MyString.h"
+
+namespace NWindows {
+
+class CClipboard
+{
+ bool m_Open;
+public:
+ CClipboard(): m_Open(false) {}
+ ~CClipboard() { Close(); }
+ bool Open(HWND wndNewOwner) throw();
+ bool Close() throw();
+};
+
+bool ClipboardIsFormatAvailableHDROP();
+
+// bool ClipboardGetFileNames(UStringVector &names);
+// bool ClipboardGetTextString(AString &s);
+bool ClipboardSetText(HWND owner, const UString &s);
+
+}
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/CommonDialog.cpp b/3rdparty/lzma/CPP/Windows/CommonDialog.cpp
index 8f4f56d39a4..7a92d5f9b65 100644
--- a/3rdparty/lzma/CPP/Windows/CommonDialog.cpp
+++ b/3rdparty/lzma/CPP/Windows/CommonDialog.cpp
@@ -2,7 +2,7 @@
#include "StdAfx.h"
-#include "../Common/MyWindows.h"
+#include "../Common/MyBuffer.h"
#ifdef UNDER_CE
#include <commdlg.h>
@@ -14,6 +14,7 @@
#include "CommonDialog.h"
#include "Defs.h"
+// #include "FileDir.h"
#ifndef _UNICODE
extern bool g_IsNT;
@@ -21,58 +22,46 @@ extern bool g_IsNT;
namespace NWindows {
-#ifndef _UNICODE
+/*
+ GetSaveFileName()
+ GetOpenFileName()
+ OPENFILENAME
-class CDoubleZeroStringListA
+(lpstrInitialDir) : the initial directory.
+DOCs: the algorithm for selecting the initial directory varies on different platforms:
{
- LPTSTR Buf;
- unsigned Size;
-public:
- CDoubleZeroStringListA(LPSTR buf, unsigned size): Buf(buf), Size(size) {}
- bool Add(LPCSTR s) throw();
- void Finish() { *Buf = 0; }
-};
-
-bool CDoubleZeroStringListA::Add(LPCSTR s) throw()
-{
- unsigned len = MyStringLen(s) + 1;
- if (len >= Size)
- return false;
- MyStringCopy(Buf, s);
- Buf += len;
- Size -= len;
- return true;
+ Win2000/XP/Vista:
+ 1. If lpstrFile contains a path, that path is the initial directory.
+ 2. Otherwise, lpstrInitialDir specifies the initial directory.
+
+ Win7:
+ If lpstrInitialDir has the same value as was passed the first time
+ the application used an Open or Save As dialog box, the path
+ most recently selected by the user is used as the initial directory.
}
-#endif
+Win10:
+ in:
+ function supports (lpstrInitialDir) path with super prefix "\\\\?\\"
+ function supports (lpstrInitialDir) path with long path
+ function doesn't support absolute (lpstrFile) path with super prefix "\\\\?\\"
+ function doesn't support absolute (lpstrFile) path with long path
+ out: the path with super prefix "\\\\?\\" will be returned, if selected path is long
-class CDoubleZeroStringListW
-{
- LPWSTR Buf;
- unsigned Size;
-public:
- CDoubleZeroStringListW(LPWSTR buf, unsigned size): Buf(buf), Size(size) {}
- bool Add(LPCWSTR s) throw();
- void Finish() { *Buf = 0; }
-};
-
-bool CDoubleZeroStringListW::Add(LPCWSTR s) throw()
-{
- unsigned len = MyStringLen(s) + 1;
- if (len >= Size)
- return false;
- MyStringCopy(Buf, s);
- Buf += len;
- Size -= len;
- return true;
-}
+WinXP-64 and Win10: if no filters, the system shows all files.
+ but DOCs say: If all three members are zero or NULL,
+ the system does not use any filters and does not
+ show any files in the file list control of the dialog box.
+
+in Win7+: GetOpenFileName() and GetSaveFileName()
+ do not support pstrCustomFilter feature anymore
+*/
-#define MY__OFN_PROJECT 0x00400000
-#define MY__OFN_SHOW_ALL 0x01000000
+#ifdef UNDER_CE
+#define MY_OFN_PROJECT 0x00400000
+#define MY_OFN_SHOW_ALL 0x01000000
+#endif
-/* if (lpstrFilter == NULL && nFilterIndex == 0)
- MSDN : "the system doesn't show any files",
- but WinXP-64 shows all files. Why ??? */
/*
structures
@@ -86,99 +75,194 @@ contain additional members:
#endif
If we compile the source code with (_WIN32_WINNT >= 0x0500), some functions
-will not work at NT 4.0, if we use sizeof(OPENFILENAME*).
-So we use size of old version of structure. */
+will not work at NT 4.0, if we use sizeof(OPENFILENAME).
+We try to use reduced structure OPENFILENAME_NT4.
+*/
+
+// #if defined(_WIN64) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500)
+#if defined(__GNUC__) && (__GNUC__ <= 9) || defined(Z7_OLD_WIN_SDK)
+ #ifndef _UNICODE
+ #define my_compatib_OPENFILENAMEA OPENFILENAMEA
+ #endif
+ #define my_compatib_OPENFILENAMEW OPENFILENAMEW
-#if defined(UNDER_CE) || defined(_WIN64) || (_WIN32_WINNT < 0x0500)
+ // MinGW doesn't support some required macros. So we define them here:
+ #ifndef CDSIZEOF_STRUCT
+ #define CDSIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
+ #endif
+ #ifndef _UNICODE
+ #ifndef OPENFILENAME_SIZE_VERSION_400A
+ #define OPENFILENAME_SIZE_VERSION_400A CDSIZEOF_STRUCT(OPENFILENAMEA,lpTemplateName)
+ #endif
+ #endif
+ #ifndef OPENFILENAME_SIZE_VERSION_400W
+ #define OPENFILENAME_SIZE_VERSION_400W CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName)
+ #endif
+
+ #ifndef _UNICODE
+ #define my_compatib_OPENFILENAMEA_size OPENFILENAME_SIZE_VERSION_400A
+ #endif
+ #define my_compatib_OPENFILENAMEW_size OPENFILENAME_SIZE_VERSION_400W
+#else
+ #ifndef _UNICODE
+ #define my_compatib_OPENFILENAMEA OPENFILENAME_NT4A
+ #define my_compatib_OPENFILENAMEA_size sizeof(my_compatib_OPENFILENAMEA)
+ #endif
+ #define my_compatib_OPENFILENAMEW OPENFILENAME_NT4W
+ #define my_compatib_OPENFILENAMEW_size sizeof(my_compatib_OPENFILENAMEW)
+#endif
+/*
+#elif defined(UNDER_CE) || defined(_WIN64) || (_WIN32_WINNT < 0x0500)
// || !defined(WINVER)
+ #ifndef _UNICODE
+ #define my_compatib_OPENFILENAMEA OPENFILENAMEA
#define my_compatib_OPENFILENAMEA_size sizeof(OPENFILENAMEA)
+ #endif
+ #define my_compatib_OPENFILENAMEW OPENFILENAMEW
#define my_compatib_OPENFILENAMEW_size sizeof(OPENFILENAMEW)
#else
- #define my_compatib_OPENFILENAMEA_size OPENFILENAME_SIZE_VERSION_400A
- #define my_compatib_OPENFILENAMEW_size OPENFILENAME_SIZE_VERSION_400W
+
#endif
+*/
+#ifndef _UNICODE
#define CONV_U_To_A(dest, src, temp) AString temp; if (src) { temp = GetSystemString(src); dest = temp; }
+#endif
-bool MyGetOpenFileName(HWND hwnd, LPCWSTR title,
- LPCWSTR initialDir,
- LPCWSTR filePath,
- LPCWSTR filterDescription,
- LPCWSTR filter,
- UString &resPath
- #ifdef UNDER_CE
- , bool openFolder
- #endif
- )
+bool CCommonDialogInfo::CommonDlg_BrowseForFile(LPCWSTR lpstrInitialDir, const UStringVector &filters)
{
- const unsigned kBufSize = MAX_PATH * 2;
- const unsigned kFilterBufSize = MAX_PATH;
- if (!filter)
- filter = L"*.*";
- #ifndef _UNICODE
+ /* GetSaveFileName() and GetOpenFileName() could change current dir,
+ if OFN_NOCHANGEDIR is not used.
+ We can restore current dir manually, if it's required.
+ 22.02: we use OFN_NOCHANGEDIR. So we don't need to restore current dir manually. */
+ // NFile::NDir::CCurrentDirRestorer curDirRestorer;
+
+#ifndef _UNICODE
if (!g_IsNT)
{
- CHAR buf[kBufSize];
- MyStringCopy(buf, (const char *)GetSystemString(filePath));
- // OPENFILENAME_NT4A
- OPENFILENAMEA p;
+ AString tempPath;
+ AStringVector f;
+ unsigned i;
+ for (i = 0; i < filters.Size(); i++)
+ f.Add(GetSystemString(filters[i]));
+ unsigned size = f.Size() + 1;
+ for (i = 0; i < f.Size(); i++)
+ size += f[i].Len();
+ CObjArray<char> filterBuf(size);
+ // memset(filterBuf, 0, size * sizeof(char));
+ {
+ char *dest = filterBuf;
+ for (i = 0; i < f.Size(); i++)
+ {
+ const AString &s = f[i];
+ MyStringCopy(dest, s);
+ dest += s.Len() + 1;
+ }
+ *dest = 0;
+ }
+ my_compatib_OPENFILENAMEA p;
memset(&p, 0, sizeof(p));
p.lStructSize = my_compatib_OPENFILENAMEA_size;
- p.hwndOwner = hwnd;
- CHAR filterBuf[kFilterBufSize];
+ p.hwndOwner = hwndOwner;
+ if (size > 1)
{
- CDoubleZeroStringListA dz(filterBuf, kFilterBufSize);
- dz.Add(GetSystemString(filterDescription ? filterDescription : filter));
- dz.Add(GetSystemString(filter));
- dz.Finish();
p.lpstrFilter = filterBuf;
- p.nFilterIndex = 1;
+ p.nFilterIndex = (DWORD)(FilterIndex + 1);
+ }
+
+ CONV_U_To_A(p.lpstrInitialDir, lpstrInitialDir, initialDir_a)
+ CONV_U_To_A(p.lpstrTitle, lpstrTitle, title_a)
+
+ const AString filePath_a = GetSystemString(FilePath);
+ const unsigned bufSize = MAX_PATH * 8
+ + filePath_a.Len()
+ + initialDir_a.Len();
+ p.nMaxFile = bufSize;
+ p.lpstrFile = tempPath.GetBuf(bufSize);
+ MyStringCopy(p.lpstrFile, filePath_a);
+ p.Flags =
+ OFN_EXPLORER
+ | OFN_HIDEREADONLY
+ | OFN_NOCHANGEDIR;
+ const BOOL b = SaveMode ?
+ ::GetSaveFileNameA((LPOPENFILENAMEA)(void *)&p) :
+ ::GetOpenFileNameA((LPOPENFILENAMEA)(void *)&p);
+ if (!b)
+ return false;
+ {
+ tempPath.ReleaseBuf_CalcLen(bufSize);
+ FilePath = GetUnicodeString(tempPath);
+ FilterIndex = (int)p.nFilterIndex - 1;
+ return true;
}
-
- p.lpstrFile = buf;
- p.nMaxFile = kBufSize;
- CONV_U_To_A(p.lpstrInitialDir, initialDir, initialDirA);
- CONV_U_To_A(p.lpstrTitle, title, titleA);
- p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
-
- bool res = BOOLToBool(::GetOpenFileNameA(&p));
- resPath = GetUnicodeString(buf);
- return res;
}
else
- #endif
+#endif
{
- WCHAR buf[kBufSize];
- MyStringCopy(buf, filePath);
- // OPENFILENAME_NT4W
- OPENFILENAMEW p;
+ UString tempPath;
+ unsigned size = filters.Size() + 1;
+ unsigned i;
+ for (i = 0; i < filters.Size(); i++)
+ size += filters[i].Len();
+ CObjArray<wchar_t> filterBuf(size);
+ // memset(filterBuf, 0, size * sizeof(wchar_t));
+ {
+ wchar_t *dest = filterBuf;
+ for (i = 0; i < filters.Size(); i++)
+ {
+ const UString &s = filters[i];
+ MyStringCopy(dest, s);
+ dest += s.Len() + 1;
+ }
+ *dest = 0;
+ // if ((unsigned)(dest + 1 - filterBuf) != size) return false;
+ }
+ my_compatib_OPENFILENAMEW p;
memset(&p, 0, sizeof(p));
p.lStructSize = my_compatib_OPENFILENAMEW_size;
- p.hwndOwner = hwnd;
-
- WCHAR filterBuf[kFilterBufSize];
+ p.hwndOwner = hwndOwner;
+ if (size > 1)
{
- CDoubleZeroStringListW dz(filterBuf, kFilterBufSize);
- dz.Add(filterDescription ? filterDescription : filter);
- dz.Add(filter);
- dz.Finish();
p.lpstrFilter = filterBuf;
- p.nFilterIndex = 1;
+ p.nFilterIndex = (DWORD)(FilterIndex + 1);
+ }
+ unsigned bufSize = MAX_PATH * 8 + FilePath.Len();
+ if (lpstrInitialDir)
+ {
+ p.lpstrInitialDir = lpstrInitialDir;
+ bufSize += MyStringLen(lpstrInitialDir);
}
-
- p.lpstrFile = buf;
- p.nMaxFile = kBufSize;
- p.lpstrInitialDir = initialDir;
- p.lpstrTitle = title;
- p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY
- #ifdef UNDER_CE
- | (openFolder ? (MY__OFN_PROJECT | MY__OFN_SHOW_ALL) : 0)
- #endif
+ p.nMaxFile = bufSize;
+ p.lpstrFile = tempPath.GetBuf(bufSize);
+ MyStringCopy(p.lpstrFile, FilePath);
+ p.lpstrTitle = lpstrTitle;
+ p.Flags =
+ OFN_EXPLORER
+ | OFN_HIDEREADONLY
+ | OFN_NOCHANGEDIR
+ // | OFN_FORCESHOWHIDDEN // Win10 shows hidden items even without this flag
+ // | OFN_PATHMUSTEXIST
+ #ifdef UNDER_CE
+ | (OpenFolderMode ? (MY_OFN_PROJECT | MY_OFN_SHOW_ALL) : 0)
+ #endif
;
-
- bool res = BOOLToBool(::GetOpenFileNameW(&p));
- resPath = buf;
- return res;
+ const BOOL b = SaveMode ?
+ ::GetSaveFileNameW((LPOPENFILENAMEW)(void *)&p) :
+ ::GetOpenFileNameW((LPOPENFILENAMEW)(void *)&p);
+ /* DOCs: lpstrFile :
+ if the buffer is too small, then:
+ - the function returns FALSE
+ - the CommDlgExtendedError() returns FNERR_BUFFERTOOSMALL
+ - the first two bytes of the lpstrFile buffer contain the
+ required size, in bytes or characters. */
+ if (!b)
+ return false;
+ {
+ tempPath.ReleaseBuf_CalcLen(bufSize);
+ FilePath = tempPath;
+ FilterIndex = (int)p.nFilterIndex - 1;
+ return true;
+ }
}
}
diff --git a/3rdparty/lzma/CPP/Windows/CommonDialog.h b/3rdparty/lzma/CPP/Windows/CommonDialog.h
index aaf17ac57ce..85b071f0ce2 100644
--- a/3rdparty/lzma/CPP/Windows/CommonDialog.h
+++ b/3rdparty/lzma/CPP/Windows/CommonDialog.h
@@ -1,22 +1,42 @@
// Windows/CommonDialog.h
-#ifndef __WINDOWS_COMMON_DIALOG_H
-#define __WINDOWS_COMMON_DIALOG_H
+#ifndef ZIP7_INC_WINDOWS_COMMON_DIALOG_H
+#define ZIP7_INC_WINDOWS_COMMON_DIALOG_H
#include "../Common/MyString.h"
namespace NWindows {
-bool MyGetOpenFileName(HWND hwnd, LPCWSTR title,
- LPCWSTR initialDir, // can be NULL, so dir prefix in filePath will be used
- LPCWSTR filePath, // full path
- LPCWSTR filterDescription, // like "All files (*.*)"
- LPCWSTR filter, // like "*.exe"
- UString &resPath
- #ifdef UNDER_CE
- , bool openFolder = false
- #endif
-);
+struct CCommonDialogInfo
+{
+ /* (FilterIndex == -1) means no selected filter.
+ and (-1) also is reserved for unsupported custom filter.
+ if (FilterIndex >= 0), then FilterIndex is index of filter */
+ int FilterIndex; // [in / out]
+ bool SaveMode;
+ #ifdef UNDER_CE
+ bool OpenFolderMode;
+ #endif
+ HWND hwndOwner;
+ // LPCWSTR lpstrInitialDir;
+ LPCWSTR lpstrTitle;
+ UString FilePath; // [in / out]
+
+ CCommonDialogInfo()
+ {
+ FilterIndex = -1;
+ SaveMode = false;
+ #ifdef UNDER_CE
+ OpenFolderMode = false;
+ #endif
+ hwndOwner = NULL;
+ // lpstrInitialDir = NULL;
+ lpstrTitle = NULL;
+ }
+
+ /* (filters) : 2 sequential vector strings (Description, Masks) represent each filter */
+ bool CommonDlg_BrowseForFile(LPCWSTR lpstrInitialDir, const UStringVector &filters);
+};
}
diff --git a/3rdparty/lzma/CPP/Windows/Control/ComboBox.cpp b/3rdparty/lzma/CPP/Windows/Control/ComboBox.cpp
index febc61ef992..8da487d490a 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ComboBox.cpp
+++ b/3rdparty/lzma/CPP/Windows/Control/ComboBox.cpp
@@ -43,10 +43,10 @@ LRESULT CComboBox::GetLBText(int index, UString &s)
s.Empty();
if (g_IsNT)
{
- LRESULT len = SendMsgW(CB_GETLBTEXTLEN, index, 0);
+ LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0);
if (len == CB_ERR)
return len;
- LRESULT len2 = SendMsgW(CB_GETLBTEXT, index, (LPARAM)s.GetBuf((unsigned)len));
+ LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len));
if (len2 == CB_ERR)
return len;
if (len > len2)
@@ -55,11 +55,11 @@ LRESULT CComboBox::GetLBText(int index, UString &s)
return len;
}
AString sa;
- LRESULT len = GetLBText(index, sa);
+ const LRESULT len = GetLBText(index, sa);
if (len == CB_ERR)
return len;
s = GetUnicodeString(sa);
- return s.Len();
+ return (LRESULT)s.Len();
}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/Control/ComboBox.h b/3rdparty/lzma/CPP/Windows/Control/ComboBox.h
index 1d5a482134c..2a60b8aac96 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ComboBox.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ComboBox.h
@@ -1,11 +1,11 @@
// Windows/Control/ComboBox.h
-#ifndef __WINDOWS_CONTROL_COMBOBOX_H
-#define __WINDOWS_CONTROL_COMBOBOX_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H
+#define ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H
#include "../../Common/MyWindows.h"
-#include <commctrl.h>
+#include <CommCtrl.h>
#include "../Window.h"
@@ -20,19 +20,27 @@ public:
#ifndef _UNICODE
LRESULT AddString(LPCWSTR s);
#endif
- LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, index, 0); }
+
+ /* If this parameter is -1, any current selection in the list is removed and the edit control is cleared.*/
+ LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY_int_TO_WPARAM(index), 0); }
+ LRESULT SetCurSel(unsigned index) { return SendMsg(CB_SETCURSEL, index, 0); }
+
+ /* If no item is selected, it returns CB_ERR (-1) */
int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); }
+
+ /* If an error occurs, it is CB_ERR (-1) */
int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); }
- LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, index, 0); }
- LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, index, (LPARAM)s); }
+ LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); }
+ LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s); }
LRESULT GetLBText(int index, CSysString &s);
#ifndef _UNICODE
LRESULT GetLBText(int index, UString &s);
#endif
- LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, index, lParam); }
- LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, index, 0); }
+ LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY_int_TO_WPARAM(index), lParam); }
+ LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY_int_TO_WPARAM(index), 0); }
+ LRESULT GetItemData(unsigned index) { return SendMsg(CB_GETITEMDATA, index, 0); }
LRESULT GetItemData_of_CurSel() { return GetItemData(GetCurSel()); }
@@ -46,14 +54,18 @@ class CComboBoxEx: public CComboBox
public:
bool SetUnicodeFormat(bool fUnicode) { return LRESULTToBool(SendMsg(CBEM_SETUNICODEFORMAT, BOOLToBool(fUnicode), 0)); }
- LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, index, 0); }
+ /* Returns:
+ an INT value that represents the number of items remaining in the control.
+ If (index) is invalid, the message returns CB_ERR. */
+ LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY_int_TO_WPARAM(index), 0); }
+
LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); }
#ifndef _UNICODE
LRESULT InsertItem(COMBOBOXEXITEMW *item) { return SendMsg(CBEM_INSERTITEMW, 0, (LPARAM)item); }
#endif
LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); }
- DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, exStyle); }
+ DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, (LPARAM)exStyle); }
HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); }
HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); }
};
diff --git a/3rdparty/lzma/CPP/Windows/Control/CommandBar.h b/3rdparty/lzma/CPP/Windows/Control/CommandBar.h
index a6197447a40..d1b2f17861d 100644
--- a/3rdparty/lzma/CPP/Windows/Control/CommandBar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/CommandBar.h
@@ -1,7 +1,7 @@
// Windows/Control/CommandBar.h
-#ifndef __WINDOWS_CONTROL_COMMANDBAR_H
-#define __WINDOWS_CONTROL_COMMANDBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_COMMANDBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_COMMANDBAR_H
#ifdef UNDER_CE
@@ -26,12 +26,12 @@ public:
// Macros
// void Destroy() { CommandBar_Destroy(_window); }
// bool AddButtons(UINT numButtons, LPTBBUTTON buttons) { return BOOLToBool(SendMsg(TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)buttons)); }
- bool InsertButton(int iButton, LPTBBUTTON button) { return BOOLToBool(SendMsg(TB_INSERTBUTTON, (WPARAM)iButton, (LPARAM)button)); }
- BOOL AddToolTips(UINT numToolTips, LPTSTR toolTips) { return BOOLToBool(SendMsg(TB_SETTOOLTIPS, (WPARAM)numToolTips, (LPARAM)toolTips)); }
+ // bool InsertButton(unsigned iButton, LPTBBUTTON button) { return BOOLToBool(SendMsg(TB_INSERTBUTTON, (WPARAM)iButton, (LPARAM)button)); }
+ // BOOL AddToolTips(UINT numToolTips, LPTSTR toolTips) { return BOOLToBool(SendMsg(TB_SETTOOLTIPS, (WPARAM)numToolTips, (LPARAM)toolTips)); }
void AutoSize() { SendMsg(TB_AUTOSIZE, 0, 0); }
- bool AddAdornments(DWORD dwFlags) { return BOOLToBool(::CommandBar_AddAdornments(_window, dwFlags, 0)); }
- int AddBitmap(HINSTANCE hInst, int idBitmap, int iNumImages, int iImageWidth, int iImageHeight) { return ::CommandBar_AddBitmap(_window, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight); }
+ // bool AddAdornments(DWORD dwFlags) { return BOOLToBool(::CommandBar_AddAdornments(_window, dwFlags, 0)); }
+ // int AddBitmap(HINSTANCE hInst, int idBitmap, int iNumImages, int iImageWidth, int iImageHeight) { return ::CommandBar_AddBitmap(_window, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight); }
bool DrawMenuBar(WORD iButton) { return BOOLToBool(::CommandBar_DrawMenuBar(_window, iButton)); }
HMENU GetMenu(WORD iButton) { return ::CommandBar_GetMenu(_window, iButton); }
int Height() { return CommandBar_Height(_window); }
diff --git a/3rdparty/lzma/CPP/Windows/Control/Dialog.cpp b/3rdparty/lzma/CPP/Windows/Control/Dialog.cpp
index 9df3ef5ef24..c8f1bd27c79 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Dialog.cpp
+++ b/3rdparty/lzma/CPP/Windows/Control/Dialog.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+// #include "../../Windows/DLL.h"
+
#ifndef _UNICODE
#include "../../Common/StringConvert.h"
#endif
@@ -16,7 +18,14 @@ extern bool g_IsNT;
namespace NWindows {
namespace NControl {
-static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
+static
+#ifdef Z7_OLD_WIN_SDK
+ BOOL
+#else
+ INT_PTR
+#endif
+APIENTRY
+DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
{
CWindow tempDialog(dialogHWND);
if (message == WM_INITDIALOG)
@@ -26,6 +35,14 @@ static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wP
return FALSE;
if (message == WM_INITDIALOG)
dialog->Attach(dialogHWND);
+
+ /* MSDN: The dialog box procedure should return
+ TRUE - if it processed the message
+ FALSE - if it did not process the message
+ If the dialog box procedure returns FALSE,
+ the dialog manager performs the default dialog operation in response to the message.
+ */
+
try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
catch(...) { return TRUE; }
}
@@ -35,10 +52,11 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_INITDIALOG: return OnInit();
- case WM_COMMAND: return OnCommand(wParam, lParam);
+ case WM_COMMAND: return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam);
case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam);
case WM_TIMER: return OnTimer(wParam, lParam);
case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
+ case WM_DESTROY: return OnDestroy();
case WM_HELP: OnHelp(); return true;
/*
OnHelp(
@@ -54,47 +72,104 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
}
}
-bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam)
+/*
+bool CDialog::OnCommand2(WPARAM wParam, LPARAM lParam)
{
return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam);
}
+*/
-bool CDialog::OnCommand(int code, int itemID, LPARAM lParam)
+bool CDialog::OnCommand(unsigned code, unsigned itemID, LPARAM lParam)
{
if (code == BN_CLICKED)
return OnButtonClicked(itemID, (HWND)lParam);
return false;
}
-bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */)
+bool CDialog::OnButtonClicked(unsigned buttonID, HWND /* buttonHWND */)
{
switch (buttonID)
{
case IDOK: OnOK(); break;
case IDCANCEL: OnCancel(); break;
+ case IDCLOSE: OnClose(); break;
case IDHELP: OnHelp(); break;
default: return false;
}
return true;
}
-static bool GetWorkAreaRect(RECT *rect)
+#ifndef UNDER_CE
+/* in win2000/win98 : monitor functions are supported.
+ We need dynamic linking, if we want nt4/win95 support in program.
+ Even if we compile the code with low (WINVER) value, we still
+ want to use monitor functions. So we declare missing functions here */
+// #if (WINVER < 0x0500)
+#ifndef MONITOR_DEFAULTTOPRIMARY
+extern "C" {
+DECLARE_HANDLE(HMONITOR);
+#define MONITOR_DEFAULTTOPRIMARY 0x00000001
+typedef struct tagMONITORINFO
+{
+ DWORD cbSize;
+ RECT rcMonitor;
+ RECT rcWork;
+ DWORD dwFlags;
+} MONITORINFO, *LPMONITORINFO;
+WINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND hwnd, DWORD dwFlags);
+WINUSERAPI BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpmi);
+}
+#endif
+#endif
+
+static bool GetWorkAreaRect(RECT *rect, HWND hwnd)
{
- // use another function for multi-monitor.
+ if (hwnd)
+ {
+ #ifndef UNDER_CE
+ /* MonitorFromWindow() is supported in Win2000+
+ MonitorFromWindow() : retrieves a handle to the display monitor that has the
+ largest area of intersection with the bounding rectangle of a specified window.
+ dwFlags: Determines the function's return value if the window does not intersect any display monitor.
+ MONITOR_DEFAULTTONEAREST : Returns display that is nearest to the window.
+ MONITOR_DEFAULTTONULL : Returns NULL.
+ MONITOR_DEFAULTTOPRIMARY : Returns the primary display monitor.
+ */
+ const HMONITOR hmon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
+ if (hmon)
+ {
+ MONITORINFO mi;
+ memset(&mi, 0, sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ if (GetMonitorInfoA(hmon, &mi))
+ {
+ *rect = mi.rcWork;
+ return true;
+ }
+ }
+ #endif
+ }
+
+ /* Retrieves the size of the work area on the primary display monitor.
+ The work area is the portion of the screen not obscured
+ by the system taskbar or by application desktop toolbars.
+ Any DPI virtualization mode of the caller has no effect on this output. */
+
return BOOLToBool(::SystemParametersInfo(SPI_GETWORKAREA, 0, rect, 0));
}
-bool IsDialogSizeOK(int xSize, int ySize)
+
+bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd)
{
// it returns for system font. Real font uses another values
- LONG v = GetDialogBaseUnits();
- int x = LOWORD(v);
- int y = HIWORD(v);
+ const LONG v = GetDialogBaseUnits();
+ const int x = LOWORD(v);
+ const int y = HIWORD(v);
RECT rect;
- GetWorkAreaRect(&rect);
- int wx = RECT_SIZE_X(rect);
- int wy = RECT_SIZE_Y(rect);
+ GetWorkAreaRect(&rect, hwnd);
+ const int wx = RECT_SIZE_X(rect);
+ const int wy = RECT_SIZE_Y(rect);
return
xSize / 4 * x <= wx &&
ySize / 8 * y <= wy;
@@ -128,7 +203,7 @@ int CDialog::Units_To_Pixels_X(int units)
return rect.right - rect.left;
}
-bool CDialog::GetItemSizes(int id, int &x, int &y)
+bool CDialog::GetItemSizes(unsigned id, int &x, int &y)
{
RECT rect;
if (!::GetWindowRect(GetItem(id), &rect))
@@ -138,62 +213,182 @@ bool CDialog::GetItemSizes(int id, int &x, int &y)
return true;
}
-void CDialog::GetClientRectOfItem(int id, RECT &rect)
+void CDialog::GetClientRectOfItem(unsigned id, RECT &rect)
{
::GetWindowRect(GetItem(id), &rect);
ScreenToClient(&rect);
}
-bool CDialog::MoveItem(int id, int x, int y, int width, int height, bool repaint)
+bool CDialog::MoveItem(unsigned id, int x, int y, int width, int height, bool repaint)
{
return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint)));
}
+
+/*
+typedef BOOL (WINAPI * Func_DwmGetWindowAttribute)(
+ HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute);
+
+static bool GetWindowsRect_DWM(HWND hwnd, RECT *rect)
+{
+ // dll load and free is too slow : 300 calls in second.
+ NDLL::CLibrary dll;
+ if (!dll.Load(FTEXT("dwmapi.dll")))
+ return false;
+ Func_DwmGetWindowAttribute f = (Func_DwmGetWindowAttribute)dll.GetProc("DwmGetWindowAttribute" );
+ if (f)
+ {
+ #define MY__DWMWA_EXTENDED_FRAME_BOUNDS 9
+ // 30000 per second
+ RECT r;
+ if (f(hwnd, MY__DWMWA_EXTENDED_FRAME_BOUNDS, &r, sizeof(RECT)) == S_OK)
+ {
+ *rect = r;
+ return true;
+ }
+ }
+ return false;
+}
+*/
+
+
+static bool IsRect_Small_Inside_Big(const RECT &sm, const RECT &big)
+{
+ return sm.left >= big.left
+ && sm.right <= big.right
+ && sm.top >= big.top
+ && sm.bottom <= big.bottom;
+}
+
+
+static bool AreRectsOverlapped(const RECT &r1, const RECT &r2)
+{
+ return r1.left < r2.right
+ && r1.right > r2.left
+ && r1.top < r2.bottom
+ && r1.bottom > r2.top;
+}
+
+
+static bool AreRectsEqual(const RECT &r1, const RECT &r2)
+{
+ return r1.left == r2.left
+ && r1.right == r2.right
+ && r1.top == r2.top
+ && r1.bottom == r2.bottom;
+}
+
+
void CDialog::NormalizeSize(bool fullNormalize)
{
RECT workRect;
- GetWorkAreaRect(&workRect);
- int xSize = RECT_SIZE_X(workRect);
- int ySize = RECT_SIZE_Y(workRect);
+ if (!GetWorkAreaRect(&workRect, *this))
+ return;
RECT rect;
- GetWindowRect(&rect);
- int xSize2 = RECT_SIZE_X(rect);
- int ySize2 = RECT_SIZE_Y(rect);
- bool needMove = (xSize2 > xSize || ySize2 > ySize);
- if (xSize2 > xSize || (needMove && fullNormalize))
+ if (!GetWindowRect(&rect))
+ return;
+ int xs = RECT_SIZE_X(rect);
+ int ys = RECT_SIZE_Y(rect);
+
+ // we don't want to change size using workRect, if window is outside of WorkArea
+ if (!AreRectsOverlapped(rect, workRect))
+ return;
+
+ /* here rect and workRect are overlapped, but it can be false
+ overlapping of small shadow when window in another display. */
+
+ const int xsW = RECT_SIZE_X(workRect);
+ const int ysW = RECT_SIZE_Y(workRect);
+ if (xs <= xsW && ys <= ysW)
+ return; // size of window is OK
+ if (fullNormalize)
+ {
+ Show(SW_SHOWMAXIMIZED);
+ return;
+ }
+ int x = workRect.left;
+ int y = workRect.top;
+ if (xs < xsW) x += (xsW - xs) / 2; else xs = xsW;
+ if (ys < ysW) y += (ysW - ys) / 2; else ys = ysW;
+ Move(x, y, xs, ys, true);
+}
+
+
+void CDialog::NormalizePosition()
+{
+ RECT workRect;
+ if (!GetWorkAreaRect(&workRect, *this))
+ return;
+
+ RECT rect2 = workRect;
+ bool useWorkArea = true;
+ const HWND parentHWND = GetParent();
+
+ if (parentHWND)
{
- rect.left = workRect.left;
- rect.right = workRect.right;
- xSize2 = xSize;
+ RECT workRectParent;
+ if (!GetWorkAreaRect(&workRectParent, parentHWND))
+ return;
+
+ // if windows are in different monitors, we use only workArea of current window
+
+ if (AreRectsEqual(workRectParent, workRect))
+ {
+ // RECT rect3; if (GetWindowsRect_DWM(parentHWND, &rect3)) {}
+ CWindow wnd(parentHWND);
+ if (wnd.GetWindowRect(&rect2))
+ {
+ // it's same monitor. So we try to use parentHWND rect.
+ /* we don't want to change position, if parent window is not inside work area.
+ In Win10 : parent window rect is 8 pixels larger for each corner than window size for shadow.
+ In maximize mode : window is outside of workRect.
+ if parent window is inside workRect, we will use parent window instead of workRect */
+ if (IsRect_Small_Inside_Big(rect2, workRect))
+ useWorkArea = false;
+ }
+ }
}
- if (ySize2 > ySize || (needMove && fullNormalize))
+
+ RECT rect;
+ if (!GetWindowRect(&rect))
+ return;
+
+ if (useWorkArea)
{
- rect.top = workRect.top;
- rect.bottom = workRect.bottom;
- ySize2 = ySize;
+ // we don't want to move window, if it's already inside.
+ if (IsRect_Small_Inside_Big(rect, workRect))
+ return;
+ // we don't want to move window, if it's outside of workArea
+ if (!AreRectsOverlapped(rect, workRect))
+ return;
+ rect2 = workRect;
}
- if (needMove)
+
{
- if (fullNormalize)
- Show(SW_SHOWMAXIMIZED);
- else
- Move(rect.left, rect.top, xSize2, ySize2, true);
+ const int xs = RECT_SIZE_X(rect);
+ const int ys = RECT_SIZE_Y(rect);
+ const int xs2 = RECT_SIZE_X(rect2);
+ const int ys2 = RECT_SIZE_Y(rect2);
+ // we don't want to change position if parent is smaller.
+ if (xs <= xs2 && ys <= ys2)
+ {
+ const int x = rect2.left + (xs2 - xs) / 2;
+ const int y = rect2.top + (ys2 - ys) / 2;
+
+ if (x != rect.left || y != rect.top)
+ Move(x, y, xs, ys, true);
+ // SetWindowPos(*this, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
+ return;
+ }
}
}
-void CDialog::NormalizePosition()
-{
- RECT workRect, rect;
- GetWorkAreaRect(&workRect);
- GetWindowRect(&rect);
- if (rect.bottom > workRect.bottom && rect.top > workRect.top)
- Move(rect.left, workRect.top, RECT_SIZE_X(rect), RECT_SIZE_Y(rect), true);
-}
+
bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
{
- HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
- if (aHWND == 0)
+ const HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
+ if (!aHWND)
return false;
Attach(aHWND);
return true;
diff --git a/3rdparty/lzma/CPP/Windows/Control/Dialog.h b/3rdparty/lzma/CPP/Windows/Control/Dialog.h
index 59b9f41935c..06be4bf938b 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Dialog.h
+++ b/3rdparty/lzma/CPP/Windows/Control/Dialog.h
@@ -1,7 +1,7 @@
// Windows/Control/Dialog.h
-#ifndef __WINDOWS_CONTROL_DIALOG_H
-#define __WINDOWS_CONTROL_DIALOG_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_DIALOG_H
+#define ZIP7_INC_WINDOWS_CONTROL_DIALOG_H
#include "../Window.h"
@@ -10,53 +10,66 @@ namespace NControl {
class CDialog: public CWindow
{
+ // Z7_CLASS_NO_COPY(CDialog)
public:
- CDialog(HWND wnd = NULL): CWindow(wnd){};
- virtual ~CDialog() {};
+ CDialog(HWND wnd = NULL): CWindow(wnd) {}
+ virtual ~CDialog() {}
- HWND GetItem(int itemID) const
- { return GetDlgItem(_window, itemID); }
+ HWND GetItem(unsigned itemID) const
+ { return GetDlgItem(_window, (int)itemID); }
- bool EnableItem(int itemID, bool enable) const
+ bool EnableItem(unsigned itemID, bool enable) const
{ return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); }
- bool ShowItem(int itemID, int cmdShow) const
+ bool ShowItem(unsigned itemID, int cmdShow) const
{ return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); }
- bool ShowItem_Bool(int itemID, bool show) const
+ bool ShowItem_Bool(unsigned itemID, bool show) const
{ return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); }
- bool HideItem(int itemID) const { return ShowItem(itemID, SW_HIDE); }
+ bool HideItem(unsigned itemID) const { return ShowItem(itemID, SW_HIDE); }
- bool SetItemText(int itemID, LPCTSTR s)
- { return BOOLToBool(SetDlgItemText(_window, itemID, s)); }
+ bool SetItemText(unsigned itemID, LPCTSTR s)
+ { return BOOLToBool(SetDlgItemText(_window, (int)itemID, s)); }
+
+ bool SetItemTextA(unsigned itemID, LPCSTR s)
+ { return BOOLToBool(SetDlgItemTextA(_window, (int)itemID, s)); }
+
+ bool SetItemText_Empty(unsigned itemID)
+ { return SetItemText(itemID, TEXT("")); }
#ifndef _UNICODE
- bool SetItemText(int itemID, LPCWSTR s)
+ bool SetItemText(unsigned itemID, LPCWSTR s)
{
CWindow window(GetItem(itemID));
return window.SetText(s);
}
#endif
- UINT GetItemText(int itemID, LPTSTR string, int maxCount)
- { return GetDlgItemText(_window, itemID, string, maxCount); }
+ UINT GetItemText(unsigned itemID, LPTSTR string, unsigned maxCount)
+ { return GetDlgItemText(_window, (int)itemID, string, (int)maxCount); }
#ifndef _UNICODE
/*
- bool GetItemText(int itemID, LPWSTR string, int maxCount)
+ bool GetItemText(unsigned itemID, LPWSTR string, int maxCount)
{
- CWindow window(GetItem(itemID));
+ CWindow window(GetItem(unsigned));
return window.GetText(string, maxCount);
}
*/
#endif
- bool SetItemInt(int itemID, UINT value, bool isSigned)
- { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); }
- bool GetItemInt(int itemID, bool isSigned, UINT &value)
+ bool GetItemText(unsigned itemID, UString &s)
+ {
+ CWindow window(GetItem(itemID));
+ return window.GetText(s);
+ }
+
+ bool SetItemInt(unsigned itemID, UINT value, bool isSigned)
+ { return BOOLToBool(SetDlgItemInt(_window, (int)itemID, value, BoolToBOOL(isSigned))); }
+ bool GetItemInt(unsigned itemID, bool isSigned, UINT &value)
{
BOOL result;
- value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned));
+ value = GetDlgItemInt(_window, (int)itemID, &result, BoolToBOOL(isSigned));
return BOOLToBool(result);
}
@@ -65,33 +78,42 @@ public:
HWND GetNextTabItem(HWND control, bool previous)
{ return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); }
+ LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam)
+ { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); }
+ LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); }
+ LRESULT SendMsg_NextDlgCtl_CtlId(unsigned id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); }
+ LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); }
+ LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); }
+
bool MapRect(LPRECT rect)
{ return BOOLToBool(MapDialogRect(_window, rect)); }
bool IsMessage(LPMSG message)
{ return BOOLToBool(IsDialogMessage(_window, message)); }
- LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam)
- { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); }
+ LRESULT SendItemMessage(unsigned itemID, UINT message, WPARAM wParam, LPARAM lParam)
+ { return SendDlgItemMessage(_window, (int)itemID, message, wParam, lParam); }
- bool CheckButton(int buttonID, UINT checkState)
- { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); }
- bool CheckButton(int buttonID, bool checkState)
+ bool CheckButton(unsigned buttonID, UINT checkState)
+ { return BOOLToBool(CheckDlgButton(_window, (int)buttonID, checkState)); }
+ bool CheckButton(unsigned buttonID, bool checkState)
{ return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); }
- UINT IsButtonChecked(int buttonID) const
- { return IsDlgButtonChecked(_window, buttonID); }
- bool IsButtonCheckedBool(int buttonID) const
- { return (IsButtonChecked(buttonID) == BST_CHECKED); }
+ UINT IsButtonChecked_BST(unsigned buttonID) const
+ { return IsDlgButtonChecked(_window, (int)buttonID); }
+ bool IsButtonCheckedBool(unsigned buttonID) const
+ { return (IsButtonChecked_BST(buttonID) == BST_CHECKED); }
- bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID)
- { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); }
+ bool CheckRadioButton(unsigned firstButtonID, unsigned lastButtonID, unsigned checkButtonID)
+ { return BOOLToBool(::CheckRadioButton(_window,
+ (int)firstButtonID, (int)lastButtonID, (int)checkButtonID)); }
virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
virtual bool OnInit() { return true; }
- virtual bool OnCommand(WPARAM wParam, LPARAM lParam);
- virtual bool OnCommand(int code, int itemID, LPARAM lParam);
+ // virtual bool OnCommand2(WPARAM wParam, LPARAM lParam);
+ virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam);
virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
+ virtual bool OnDestroy() { return false; }
/*
#ifdef UNDER_CE
@@ -100,11 +122,12 @@ public:
virtual void OnHelp(LPHELPINFO) { OnHelp(); }
#endif
*/
- virtual void OnHelp() {};
+ virtual void OnHelp() {}
- virtual bool OnButtonClicked(int buttonID, HWND buttonHWND);
- virtual void OnOK() {};
- virtual void OnCancel() {};
+ virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND);
+ virtual void OnOK() {}
+ virtual void OnCancel() {}
+ virtual void OnClose() {}
virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; }
virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; }
@@ -115,9 +138,11 @@ public:
bool GetMargins(int margin, int &x, int &y);
int Units_To_Pixels_X(int units);
- bool GetItemSizes(int id, int &x, int &y);
- void GetClientRectOfItem(int id, RECT &rect);
- bool MoveItem(int id, int x, int y, int width, int height, bool repaint = true);
+ bool GetItemSizes(unsigned id, int &x, int &y);
+ void GetClientRectOfItem(unsigned id, RECT &rect);
+ bool MoveItem(unsigned id, int x, int y, int width, int height, bool repaint = true);
+ bool MoveItem_RECT(unsigned id, const RECT &r, bool repaint = true)
+ { return MoveItem(id, r.left, r.top, RECT_SIZE_X(r), RECT_SIZE_Y(r), repaint); }
void NormalizeSize(bool fullNormalize = false);
void NormalizePosition();
@@ -131,8 +156,9 @@ public:
#ifndef _UNICODE
bool Create(LPCWSTR templateName, HWND parentWindow);
#endif
- virtual void OnOK() { Destroy(); }
- virtual void OnCancel() { Destroy(); }
+ virtual void OnOK() Z7_override { Destroy(); }
+ virtual void OnCancel() Z7_override { Destroy(); }
+ virtual void OnClose() Z7_override { Destroy(); }
};
class CModalDialog: public CDialog
@@ -145,22 +171,23 @@ public:
#endif
bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); }
- virtual void OnOK() { End(IDOK); }
- virtual void OnCancel() { End(IDCANCEL); }
+ virtual void OnOK() Z7_override { End(IDOK); }
+ virtual void OnCancel() Z7_override { End(IDCANCEL); }
+ virtual void OnClose() Z7_override { End(IDCLOSE); }
};
class CDialogChildControl: public NWindows::CWindow
{
- int m_ID;
+ // unsigned m_ID;
public:
- void Init(const NWindows::NControl::CDialog &parentDialog, int id)
+ void Init(const NWindows::NControl::CDialog &parentDialog, unsigned id)
{
- m_ID = id;
+ // m_ID = id;
Attach(parentDialog.GetItem(id));
}
};
-bool IsDialogSizeOK(int xSize, int ySize);
+bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd = NULL);
}}
diff --git a/3rdparty/lzma/CPP/Windows/Control/Edit.h b/3rdparty/lzma/CPP/Windows/Control/Edit.h
index 51a22c53740..963470d78bc 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Edit.h
+++ b/3rdparty/lzma/CPP/Windows/Control/Edit.h
@@ -1,7 +1,7 @@
// Windows/Control/Edit.h
-#ifndef __WINDOWS_CONTROL_EDIT_H
-#define __WINDOWS_CONTROL_EDIT_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_EDIT_H
+#define ZIP7_INC_WINDOWS_CONTROL_EDIT_H
#include "../Window.h"
diff --git a/3rdparty/lzma/CPP/Windows/Control/ImageList.h b/3rdparty/lzma/CPP/Windows/Control/ImageList.h
index 0d9c9313103..688f1777c1c 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ImageList.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ImageList.h
@@ -1,9 +1,9 @@
// Windows/Control/ImageList.h
-#ifndef __WINDOWS_CONTROL_IMAGE_LIST_H
-#define __WINDOWS_CONTROL_IMAGE_LIST_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_IMAGE_LIST_H
+#define ZIP7_INC_WINDOWS_CONTROL_IMAGE_LIST_H
-#include <commctrl.h>
+#include <CommCtrl.h>
#include "../Defs.h"
@@ -56,7 +56,7 @@ public:
bool GetImageInfo(int index, IMAGEINFO* imageInfo) const
{ return BOOLToBool(ImageList_GetImageInfo(m_Object, index, imageInfo)); }
- int Add(HBITMAP hbmImage, HBITMAP hbmMask = 0)
+ int Add(HBITMAP hbmImage, HBITMAP hbmMask = NULL)
{ return ImageList_Add(m_Object, hbmImage, hbmMask); }
int AddMasked(HBITMAP hbmImage, COLORREF mask)
{ return ImageList_AddMasked(m_Object, hbmImage, mask); }
diff --git a/3rdparty/lzma/CPP/Windows/Control/ListView.cpp b/3rdparty/lzma/CPP/Windows/Control/ListView.cpp
index 6d916591a51..3e8786a1d95 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ListView.cpp
+++ b/3rdparty/lzma/CPP/Windows/Control/ListView.cpp
@@ -20,78 +20,85 @@ bool CListView::CreateEx(DWORD exStyle, DWORD style,
height, parentWindow, idOrHMenu, instance, createParam);
}
-bool CListView::GetItemParam(int index, LPARAM &param) const
+/* note: LVITEM and LVCOLUMN structures contain optional fields
+ depending from preprocessor macros:
+ #if (_WIN32_IE >= 0x0300)
+ #if (_WIN32_WINNT >= 0x0501)
+ #if (_WIN32_WINNT >= 0x0600)
+*/
+
+bool CListView::GetItemParam(unsigned index, LPARAM &param) const
{
LVITEM item;
- item.iItem = index;
+ item.iItem = (int)index;
item.iSubItem = 0;
item.mask = LVIF_PARAM;
- bool aResult = GetItem(&item);
+ const bool res = GetItem(&item);
param = item.lParam;
- return aResult;
+ return res;
}
-int CListView::InsertColumn(int columnIndex, LPCTSTR text, int width)
+int CListView::InsertColumn(unsigned columnIndex, LPCTSTR text, int width)
{
LVCOLUMN ci;
ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
- ci.pszText = (LPTSTR)text;
- ci.iSubItem = columnIndex;
+ ci.pszText = (LPTSTR)(void *)text;
+ ci.iSubItem = (int)columnIndex;
ci.cx = width;
return InsertColumn(columnIndex, &ci);
}
-int CListView::InsertItem(int index, LPCTSTR text)
+int CListView::InsertItem(unsigned index, LPCTSTR text)
{
LVITEM item;
item.mask = LVIF_TEXT | LVIF_PARAM;
- item.iItem = index;
- item.lParam = index;
- item.pszText = (LPTSTR)text;
+ item.iItem = (int)index;
+ item.lParam = (LPARAM)index;
+ item.pszText = (LPTSTR)(void *)text;
item.iSubItem = 0;
return InsertItem(&item);
}
-int CListView::SetSubItem(int index, int subIndex, LPCTSTR text)
+int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCTSTR text)
{
LVITEM item;
item.mask = LVIF_TEXT;
- item.iItem = index;
- item.pszText = (LPTSTR)text;
- item.iSubItem = subIndex;
+ item.iItem = (int)index;
+ item.pszText = (LPTSTR)(void *)text;
+ item.iSubItem = (int)subIndex;
return SetItem(&item);
}
#ifndef _UNICODE
-int CListView::InsertColumn(int columnIndex, LPCWSTR text, int width)
+int CListView::InsertColumn(unsigned columnIndex, LPCWSTR text, int width)
{
LVCOLUMNW ci;
ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
- ci.pszText = (LPWSTR)text;
- ci.iSubItem = columnIndex;
+ ci.pszText = (LPWSTR)(void *)text;
+ ci.iSubItem = (int)columnIndex;
ci.cx = width;
return InsertColumn(columnIndex, &ci);
}
-int CListView::InsertItem(int index, LPCWSTR text)
+int CListView::InsertItem(unsigned index, LPCWSTR text)
{
LVITEMW item;
item.mask = LVIF_TEXT | LVIF_PARAM;
- item.iItem = index;
- item.lParam = index;
- item.pszText = (LPWSTR)text;
+ item.iItem = (int)index;
+ item.lParam = (LPARAM)index;
+ item.pszText = (LPWSTR)(void *)text;
item.iSubItem = 0;
return InsertItem(&item);
}
-int CListView::SetSubItem(int index, int subIndex, LPCWSTR text)
+int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCWSTR text)
{
LVITEMW item;
item.mask = LVIF_TEXT;
- item.iItem = index;
- item.pszText = (LPWSTR)text;
- item.iSubItem = subIndex;
+ item.iItem = (int)index;
+ item.pszText = (LPWSTR)(void *)text;
+ item.iSubItem = (int)subIndex;
return SetItem(&item);
}
diff --git a/3rdparty/lzma/CPP/Windows/Control/ListView.h b/3rdparty/lzma/CPP/Windows/Control/ListView.h
index 9a3abe70fa1..11a33a07d07 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ListView.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ListView.h
@@ -1,11 +1,11 @@
// Windows/Control/ListView.h
-#ifndef __WINDOWS_CONTROL_LISTVIEW_H
-#define __WINDOWS_CONTROL_LISTVIEW_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_LISTVIEW_H
+#define ZIP7_INC_WINDOWS_CONTROL_LISTVIEW_H
#include "../../Common/MyWindows.h"
-#include <commctrl.h>
+#include <CommCtrl.h>
#include "../Window.h"
@@ -28,11 +28,12 @@ public:
}
bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); }
- bool DeleteColumn(int columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); }
+ bool DeleteColumn(unsigned columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); }
- int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); }
- int InsertColumn(int columnIndex, LPCTSTR text, int width);
- bool SetColumnOrderArray(int count, const int *columns) { return BOOLToBool(ListView_SetColumnOrderArray(_window, count, columns)); }
+ int InsertColumn(unsigned columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); }
+ int InsertColumn(unsigned columnIndex, LPCTSTR text, int width);
+ bool SetColumnOrderArray(unsigned count, const int *columns)
+ { return BOOLToBool(ListView_SetColumnOrderArray(_window, count, (int *)(void *)columns)); }
/*
int GetNumColumns()
@@ -45,43 +46,49 @@ public:
*/
int InsertItem(const LVITEM* item) { return ListView_InsertItem(_window, item); }
- int InsertItem(int index, LPCTSTR text);
+ int InsertItem(unsigned index, LPCTSTR text);
bool SetItem(const LVITEM* item) { return BOOLToBool(ListView_SetItem(_window, item)); }
- int SetSubItem(int index, int subIndex, LPCTSTR text);
+ int SetSubItem(unsigned index, unsigned subIndex, LPCTSTR text);
#ifndef _UNICODE
- int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMsg(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); }
- int InsertColumn(int columnIndex, LPCWSTR text, int width);
+ int InsertColumn(unsigned columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMsg(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); }
+ int InsertColumn(unsigned columnIndex, LPCWSTR text, int width);
int InsertItem(const LV_ITEMW* item) { return (int)SendMsg(LVM_INSERTITEMW, 0, (LPARAM)item); }
- int InsertItem(int index, LPCWSTR text);
+ int InsertItem(unsigned index, LPCWSTR text);
bool SetItem(const LV_ITEMW* item) { return BOOLToBool((BOOL)SendMsg(LVM_SETITEMW, 0, (LPARAM)item)); }
- int SetSubItem(int index, int subIndex, LPCWSTR text);
+ int SetSubItem(unsigned index, unsigned subIndex, LPCWSTR text);
#endif
- bool DeleteItem(int itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); }
+ bool DeleteItem(unsigned itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); }
UINT GetSelectedCount() const { return ListView_GetSelectedCount(_window); }
int GetItemCount() const { return ListView_GetItemCount(_window); }
INT GetSelectionMark() const { return ListView_GetSelectionMark(_window); }
- void SetItemCount(int numItems) { ListView_SetItemCount(_window, numItems); }
- void SetItemCountEx(int numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); }
+ void SetItemCount(unsigned numItems) { ListView_SetItemCount(_window, numItems); }
+ void SetItemCountEx(unsigned numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); }
+ /* startIndex : The index of the item with which to begin the search,
+ or -1 to find the first item that matches the specified flags.
+ The specified item itself is excluded from the search. */
int GetNextItem(int startIndex, UINT flags) const { return ListView_GetNextItem(_window, startIndex, flags); }
int GetNextSelectedItem(int startIndex) const { return GetNextItem(startIndex, LVNI_SELECTED); }
int GetFocusedItem() const { return GetNextItem(-1, LVNI_FOCUSED); }
bool GetItem(LVITEM* item) const { return BOOLToBool(ListView_GetItem(_window, item)); }
- bool GetItemParam(int itemIndex, LPARAM &param) const;
- void GetItemText(int itemIndex, int subItemIndex, LPTSTR text, int textSizeMax) const
- { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax); }
+ bool GetItemParam(unsigned itemIndex, LPARAM &param) const;
+ /*
+ void GetItemText(unsigned itemIndex, unsigned subItemIndex, LPTSTR text, unsigned textSizeMax) const
+ { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax) }
+ */
bool SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam)
{ return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); }
- void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask); }
+ // If (index == -1), then the state change is applied to all items.
+ void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask) }
void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); }
void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); }
void SelectAll() { SetItemState_Selected(-1); }
@@ -89,7 +96,7 @@ public:
UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); }
bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; }
- bool GetColumn(int columnIndex, LVCOLUMN* columnInfo) const
+ bool GetColumn(unsigned columnIndex, LVCOLUMN* columnInfo) const
{ return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); }
HIMAGELIST SetImageList(HIMAGELIST imageList, int imageListType)
@@ -100,7 +107,7 @@ public:
void SetExtendedListViewStyle(DWORD exStyle) { ListView_SetExtendedListViewStyle(_window, exStyle); }
void SetExtendedListViewStyle(DWORD exMask, DWORD exStyle) { ListView_SetExtendedListViewStyleEx(_window, exMask, exStyle); }
- void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)); }
+ void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)) }
bool GetCheckState(UINT index) { return BOOLToBool(ListView_GetCheckState(_window, index)); }
bool EnsureVisible(int index, bool partialOK) { return BOOLToBool(ListView_EnsureVisible(_window, index, BoolToBOOL(partialOK))); }
@@ -128,7 +135,10 @@ public:
class CListView2: public CListView
{
WNDPROC _origWindowProc;
+ // ~CListView2() ZIP7_eq_delete;
public:
+ virtual ~CListView2() {}
+ CListView2() {}
void SetWindowProc();
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
};
diff --git a/3rdparty/lzma/CPP/Windows/Control/ProgressBar.h b/3rdparty/lzma/CPP/Windows/Control/ProgressBar.h
index 38ebcb6131b..2256aa9e912 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ProgressBar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ProgressBar.h
@@ -1,11 +1,11 @@
// Windows/Control/ProgressBar.h
-#ifndef __WINDOWS_CONTROL_PROGRESSBAR_H
-#define __WINDOWS_CONTROL_PROGRESSBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_PROGRESSBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_PROGRESSBAR_H
#include "../../Common/MyWindows.h"
-#include <commctrl.h>
+#include <CommCtrl.h>
#include "../Window.h"
@@ -15,18 +15,18 @@ namespace NControl {
class CProgressBar: public CWindow
{
public:
- LRESULT SetPos(int pos) { return SendMsg(PBM_SETPOS, pos, 0); }
- LRESULT DeltaPos(int increment) { return SendMsg(PBM_DELTAPOS, increment, 0); }
- UINT GetPos() { return (UINT)SendMsg(PBM_GETPOS, 0, 0); }
- LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMsg(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); }
- DWORD SetRange32(int minValue, int maxValue) { return (DWORD)SendMsg(PBM_SETRANGE32, minValue, maxValue); }
- int SetStep(int step) { return (int)SendMsg(PBM_SETSTEP, step, 0); }
- LRESULT StepIt() { return SendMsg(PBM_STEPIT, 0, 0); }
- INT GetRange(bool minValue, PPBRANGE range) { return (INT)SendMsg(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); }
+ LRESULT SetPos(int pos) { return SendMsg(PBM_SETPOS, (unsigned)pos, 0); }
+ // LRESULT DeltaPos(int increment) { return SendMsg(PBM_DELTAPOS, increment, 0); }
+ // UINT GetPos() { return (UINT)SendMsg(PBM_GETPOS, 0, 0); }
+ // LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMsg(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); }
+ DWORD SetRange32(int minValue, int maxValue) { return (DWORD)SendMsg(PBM_SETRANGE32, (unsigned)minValue, (LPARAM)(unsigned)maxValue); }
+ // int SetStep(int step) { return (int)SendMsg(PBM_SETSTEP, step, 0); }
+ // LRESULT StepIt() { return SendMsg(PBM_STEPIT, 0, 0); }
+ // INT GetRange(bool minValue, PPBRANGE range) { return (INT)SendMsg(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); }
#ifndef UNDER_CE
- COLORREF SetBarColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBARCOLOR, 0, color); }
- COLORREF SetBackgroundColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBKCOLOR, 0, color); }
+ COLORREF SetBarColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBARCOLOR, 0, (LPARAM)color); }
+ COLORREF SetBackgroundColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBKCOLOR, 0, (LPARAM)color); }
#endif
};
diff --git a/3rdparty/lzma/CPP/Windows/Control/PropertyPage.cpp b/3rdparty/lzma/CPP/Windows/Control/PropertyPage.cpp
index bbac74ad732..f8effe607bb 100644
--- a/3rdparty/lzma/CPP/Windows/Control/PropertyPage.cpp
+++ b/3rdparty/lzma/CPP/Windows/Control/PropertyPage.cpp
@@ -16,7 +16,13 @@ extern bool g_IsNT;
namespace NWindows {
namespace NControl {
-static INT_PTR APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
+static
+#ifdef Z7_OLD_WIN_SDK
+ BOOL
+#else
+ INT_PTR
+#endif
+APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
{
CWindow tempDialog(dialogHWND);
if (message == WM_INITDIALOG)
@@ -34,75 +40,91 @@ bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam)
{
switch (lParam->code)
{
- case PSN_APPLY: SetMsgResult(OnApply(LPPSHNOTIFY(lParam))); break;
- case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam)))); break;
- case PSN_SETACTIVE: SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam))); break;
- case PSN_RESET: OnReset(LPPSHNOTIFY(lParam)); break;
- case PSN_HELP: OnNotifyHelp(LPPSHNOTIFY(lParam)); break;
+ case PSN_APPLY: SetMsgResult(OnApply2(LPPSHNOTIFY(lParam))); break;
+ case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive2(LPPSHNOTIFY(lParam)))); break;
+ case PSN_SETACTIVE: SetMsgResult(OnSetActive2(LPPSHNOTIFY(lParam))); break;
+ case PSN_RESET: OnReset2(LPPSHNOTIFY(lParam)); break;
+ case PSN_HELP: OnNotifyHelp2(LPPSHNOTIFY(lParam)); break;
default: return false;
}
return true;
}
+/*
+PROPSHEETPAGE fields depend from
+#if (_WIN32_WINNT >= 0x0600)
+#elif (_WIN32_WINNT >= 0x0501)
+#elif (_WIN32_IE >= 0x0400)
+PROPSHEETHEADER fields depend from
+#if (_WIN32_IE >= 0x0400)
+*/
+#if defined(PROPSHEETPAGEA_V1_SIZE) && !defined(Z7_OLD_WIN_SDK)
+#ifndef _UNICODE
+#define my_compatib_PROPSHEETPAGEA PROPSHEETPAGEA_V1
+#endif
+#define my_compatib_PROPSHEETPAGEW PROPSHEETPAGEW_V1
+#else
+// for old mingw:
+#ifndef _UNICODE
+#define my_compatib_PROPSHEETPAGEA PROPSHEETPAGEA
+#endif
+#define my_compatib_PROPSHEETPAGEW PROPSHEETPAGEW
+#endif
+
INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title)
{
- #ifndef _UNICODE
- AStringVector titles;
- #endif
- #ifndef _UNICODE
- CRecordVector<PROPSHEETPAGEA> pagesA;
- #endif
- CRecordVector<PROPSHEETPAGEW> pagesW;
-
unsigned i;
#ifndef _UNICODE
+ AStringVector titles;
for (i = 0; i < pagesInfo.Size(); i++)
titles.Add(GetSystemString(pagesInfo[i].Title));
+ CRecordVector<my_compatib_PROPSHEETPAGEA> pagesA;
#endif
+ CRecordVector<my_compatib_PROPSHEETPAGEW> pagesW;
for (i = 0; i < pagesInfo.Size(); i++)
{
const CPageInfo &pageInfo = pagesInfo[i];
#ifndef _UNICODE
{
- PROPSHEETPAGE page;
+ my_compatib_PROPSHEETPAGEA page;
+ memset(&page, 0, sizeof(page));
page.dwSize = sizeof(page);
page.dwFlags = PSP_HASHELP;
page.hInstance = g_hInstance;
- page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID);
- page.pszIcon = NULL;
+ page.pszTemplate = MAKEINTRESOURCEA(pageInfo.ID);
+ // page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure;
- if (titles[i].IsEmpty())
- page.pszTitle = NULL;
- else
+ if (!titles[i].IsEmpty())
{
- page.dwFlags |= PSP_USETITLE;
page.pszTitle = titles[i];
+ page.dwFlags |= PSP_USETITLE;
}
+ // else page.pszTitle = NULL;
page.lParam = (LPARAM)pageInfo.Page;
- page.pfnCallback = NULL;
+ // page.pfnCallback = NULL;
pagesA.Add(page);
}
#endif
{
- PROPSHEETPAGEW page;
+ my_compatib_PROPSHEETPAGEW page;
+ memset(&page, 0, sizeof(page));
page.dwSize = sizeof(page);
page.dwFlags = PSP_HASHELP;
page.hInstance = g_hInstance;
page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID);
- page.pszIcon = NULL;
+ // page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure;
- if (pageInfo.Title.IsEmpty())
- page.pszTitle = NULL;
- else
+ if (!pageInfo.Title.IsEmpty())
{
- page.dwFlags |= PSP_USETITLE;
page.pszTitle = pageInfo.Title;
+ page.dwFlags |= PSP_USETITLE;
}
+ // else page.pszTitle = NULL;
page.lParam = (LPARAM)pageInfo.Page;
- page.pfnCallback = NULL;
+ // page.pfnCallback = NULL;
pagesW.Add(page);
}
}
@@ -110,16 +132,16 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare
#ifndef _UNICODE
if (!g_IsNT)
{
- PROPSHEETHEADER sheet;
+ PROPSHEETHEADERA sheet;
sheet.dwSize = sizeof(sheet);
sheet.dwFlags = PSH_PROPSHEETPAGE;
sheet.hwndParent = hwndParent;
sheet.hInstance = g_hInstance;
- AString titleA = GetSystemString(title);
+ AString titleA (GetSystemString(title));
sheet.pszCaption = titleA;
- sheet.nPages = pagesInfo.Size();
+ sheet.nPages = pagesA.Size();
sheet.nStartPage = 0;
- sheet.ppsp = &pagesA.Front();
+ sheet.ppsp = (LPCPROPSHEETPAGEA)(const void *)&pagesA.Front();
sheet.pfnCallback = NULL;
return ::PropertySheetA(&sheet);
}
@@ -132,9 +154,9 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare
sheet.hwndParent = hwndParent;
sheet.hInstance = g_hInstance;
sheet.pszCaption = title;
- sheet.nPages = pagesInfo.Size();
+ sheet.nPages = pagesW.Size();
sheet.nStartPage = 0;
- sheet.ppsp = &pagesW.Front();
+ sheet.ppsp = (LPCPROPSHEETPAGEW)(const void *)&pagesW.Front();
sheet.pfnCallback = NULL;
return ::PropertySheetW(&sheet);
}
diff --git a/3rdparty/lzma/CPP/Windows/Control/PropertyPage.h b/3rdparty/lzma/CPP/Windows/Control/PropertyPage.h
index 4c4ddad9113..264a5d29cac 100644
--- a/3rdparty/lzma/CPP/Windows/Control/PropertyPage.h
+++ b/3rdparty/lzma/CPP/Windows/Control/PropertyPage.h
@@ -1,7 +1,7 @@
// Windows/Control/PropertyPage.h
-#ifndef __WINDOWS_CONTROL_PROPERTYPAGE_H
-#define __WINDOWS_CONTROL_PROPERTYPAGE_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_PROPERTYPAGE_H
+#define ZIP7_INC_WINDOWS_CONTROL_PROPERTYPAGE_H
#include "../../Common/MyWindows.h"
@@ -17,23 +17,23 @@ INT_PTR APIENTRY ProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wPar
class CPropertyPage: public CDialog
{
public:
- CPropertyPage(HWND window = NULL): CDialog(window){};
+ CPropertyPage(HWND window = NULL): CDialog(window) {}
void Changed() { PropSheet_Changed(GetParent(), (HWND)*this); }
void UnChanged() { PropSheet_UnChanged(GetParent(), (HWND)*this); }
- virtual bool OnNotify(UINT controlID, LPNMHDR lParam);
+ virtual bool OnNotify(UINT controlID, LPNMHDR lParam) Z7_override;
virtual bool OnKillActive() { return false; } // false = OK
- virtual bool OnKillActive(const PSHNOTIFY *) { return OnKillActive(); }
+ virtual bool OnKillActive2(const PSHNOTIFY *) { return OnKillActive(); }
virtual LONG OnSetActive() { return false; } // false = OK
- virtual LONG OnSetActive(const PSHNOTIFY *) { return OnSetActive(); }
+ virtual LONG OnSetActive2(const PSHNOTIFY *) { return OnSetActive(); }
virtual LONG OnApply() { return PSNRET_NOERROR; }
- virtual LONG OnApply(const PSHNOTIFY *) { return OnApply(); }
+ virtual LONG OnApply2(const PSHNOTIFY *) { return OnApply(); }
virtual void OnNotifyHelp() {}
- virtual void OnNotifyHelp(const PSHNOTIFY *) { OnNotifyHelp(); }
+ virtual void OnNotifyHelp2(const PSHNOTIFY *) { OnNotifyHelp(); }
virtual void OnReset() {}
- virtual void OnReset(const PSHNOTIFY *) { OnReset(); }
+ virtual void OnReset2(const PSHNOTIFY *) { OnReset(); }
};
struct CPageInfo
diff --git a/3rdparty/lzma/CPP/Windows/Control/ReBar.h b/3rdparty/lzma/CPP/Windows/Control/ReBar.h
index c2d58dbe80d..b56f018cb05 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ReBar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ReBar.h
@@ -1,7 +1,7 @@
// Windows/Control/ReBar.h
-#ifndef __WINDOWS_CONTROL_REBAR_H
-#define __WINDOWS_CONTROL_REBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_REBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_REBAR_H
#include "../Window.h"
@@ -14,7 +14,7 @@ public:
bool SetBarInfo(LPREBARINFO barInfo)
{ return LRESULTToBool(SendMsg(RB_SETBARINFO, 0, (LPARAM)barInfo)); }
bool InsertBand(int index, LPREBARBANDINFO bandInfo)
- { return LRESULTToBool(SendMsg(RB_INSERTBAND, index, (LPARAM)bandInfo)); }
+ { return LRESULTToBool(SendMsg(RB_INSERTBAND, MY_int_TO_WPARAM(index), (LPARAM)bandInfo)); }
bool SetBandInfo(unsigned index, LPREBARBANDINFO bandInfo)
{ return LRESULTToBool(SendMsg(RB_SETBANDINFO, index, (LPARAM)bandInfo)); }
void MaximizeBand(unsigned index, bool ideal)
diff --git a/3rdparty/lzma/CPP/Windows/Control/Static.h b/3rdparty/lzma/CPP/Windows/Control/Static.h
index 5523b2e633e..ceeedf96695 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Static.h
+++ b/3rdparty/lzma/CPP/Windows/Control/Static.h
@@ -1,7 +1,7 @@
// Windows/Control/Static.h
-#ifndef __WINDOWS_CONTROL_STATIC_H
-#define __WINDOWS_CONTROL_STATIC_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_STATIC_H
+#define ZIP7_INC_WINDOWS_CONTROL_STATIC_H
#include "../Window.h"
diff --git a/3rdparty/lzma/CPP/Windows/Control/StatusBar.h b/3rdparty/lzma/CPP/Windows/Control/StatusBar.h
index 988b84700b4..38aca478821 100644
--- a/3rdparty/lzma/CPP/Windows/Control/StatusBar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/StatusBar.h
@@ -1,7 +1,7 @@
// Windows/Control/StatusBar.h
-#ifndef __WINDOWS_CONTROL_STATUSBAR_H
-#define __WINDOWS_CONTROL_STATUSBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_STATUSBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_STATUSBAR_H
#include "../Window.h"
@@ -12,7 +12,7 @@ class CStatusBar: public NWindows::CWindow
{
public:
bool Create(LONG style, LPCTSTR text, HWND hwndParent, UINT id)
- { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != 0; }
+ { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != NULL; }
bool SetText(LPCTSTR text)
{ return CWindow::SetText(text); }
bool SetText(unsigned index, LPCTSTR text, UINT type)
@@ -22,7 +22,7 @@ public:
#ifndef _UNICODE
bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id)
- { return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != 0; }
+ { return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != NULL; }
bool SetText(LPCWSTR text)
{ return CWindow::SetText(text); }
bool SetText(unsigned index, LPCWSTR text, UINT type)
@@ -34,7 +34,7 @@ public:
bool SetParts(unsigned numParts, const int *edgePostions)
{ return LRESULTToBool(SendMsg(SB_SETPARTS, numParts, (LPARAM)edgePostions)); }
void Simple(bool simple)
- { SendMsg(SB_SIMPLE, BoolToBOOL(simple), 0); }
+ { SendMsg(SB_SIMPLE, (WPARAM)BoolToBOOL(simple), 0); }
};
}}
diff --git a/3rdparty/lzma/CPP/Windows/Control/StdAfx.h b/3rdparty/lzma/CPP/Windows/Control/StdAfx.h
index 1cbd7feaeec..80866550d1f 100644
--- a/3rdparty/lzma/CPP/Windows/Control/StdAfx.h
+++ b/3rdparty/lzma/CPP/Windows/Control/StdAfx.h
@@ -1,8 +1,11 @@
// StdAfx.h
-#ifndef __STDAFX_H
-#define __STDAFX_H
+#ifndef ZIP7_INC_STDAFX_H
+#define ZIP7_INC_STDAFX_H
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+#pragma warning(disable : 4464) // relative include path contains '..'
+#endif
#include "../../Common/Common.h"
#endif
diff --git a/3rdparty/lzma/CPP/Windows/Control/ToolBar.h b/3rdparty/lzma/CPP/Windows/Control/ToolBar.h
index 7bc93a24170..2bf20a592e3 100644
--- a/3rdparty/lzma/CPP/Windows/Control/ToolBar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/ToolBar.h
@@ -1,7 +1,7 @@
// Windows/Control/ToolBar.h
-#ifndef __WINDOWS_CONTROL_TOOLBAR_H
-#define __WINDOWS_CONTROL_TOOLBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_TOOLBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_TOOLBAR_H
#include "../Window.h"
@@ -18,7 +18,7 @@ public:
#ifdef UNDER_CE
{
// maybe it must be fixed for more than 1 buttons
- DWORD val = GetButtonSize();
+ const DWORD val = GetButtonSize();
size->cx = LOWORD(val);
size->cy = HIWORD(val);
return true;
diff --git a/3rdparty/lzma/CPP/Windows/Control/Trackbar.h b/3rdparty/lzma/CPP/Windows/Control/Trackbar.h
index 313e0c851b6..18d1b29186a 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Trackbar.h
+++ b/3rdparty/lzma/CPP/Windows/Control/Trackbar.h
@@ -1,7 +1,7 @@
// Windows/Control/Trackbar.h
-#ifndef __WINDOWS_CONTROL_TRACKBAR_H
-#define __WINDOWS_CONTROL_TRACKBAR_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_TRACKBAR_H
+#define ZIP7_INC_WINDOWS_CONTROL_TRACKBAR_H
#include "../Window.h"
diff --git a/3rdparty/lzma/CPP/Windows/Control/Window2.cpp b/3rdparty/lzma/CPP/Windows/Control/Window2.cpp
index 994d96e080a..8fe908e0813 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Window2.cpp
+++ b/3rdparty/lzma/CPP/Windows/Control/Window2.cpp
@@ -32,9 +32,9 @@ static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message, WPARAM wParam,
if (message == MY_START_WM_CREATE)
tempWindow.SetUserDataLongPtr((LONG_PTR)(((LPCREATESTRUCT)lParam)->lpCreateParams));
CWindow2 *window = (CWindow2 *)(tempWindow.GetUserDataLongPtr());
- if (window != NULL && message == MY_START_WM_CREATE)
+ if (window && message == MY_START_WM_CREATE)
window->Attach(aHWND);
- if (window == 0)
+ if (!window)
{
#ifndef _UNICODE
if (g_IsNT)
@@ -140,7 +140,7 @@ LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
return -1;
break;
case WM_COMMAND:
- if (OnCommand(wParam, lParam, result))
+ if (OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result))
return result;
break;
case WM_NOTIFY:
@@ -160,12 +160,14 @@ LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
return DefProc(message, wParam, lParam);
}
-bool CWindow2::OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result)
+/*
+bool CWindow2::OnCommand2(WPARAM wParam, LPARAM lParam, LRESULT &result)
{
return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result);
}
+*/
-bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */, LRESULT & /* result */)
+bool CWindow2::OnCommand(unsigned /* code */, unsigned /* itemID */, LPARAM /* lParam */, LRESULT & /* result */)
{
return false;
// return DefProc(message, wParam, lParam);
@@ -176,7 +178,7 @@ bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */,
}
/*
-bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
+bool CDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
{
switch (buttonID)
{
diff --git a/3rdparty/lzma/CPP/Windows/Control/Window2.h b/3rdparty/lzma/CPP/Windows/Control/Window2.h
index 7ac580cb071..ebb59793567 100644
--- a/3rdparty/lzma/CPP/Windows/Control/Window2.h
+++ b/3rdparty/lzma/CPP/Windows/Control/Window2.h
@@ -1,7 +1,7 @@
// Windows/Control/Window2.h
-#ifndef __WINDOWS_CONTROL_WINDOW2_H
-#define __WINDOWS_CONTROL_WINDOW2_H
+#ifndef ZIP7_INC_WINDOWS_CONTROL_WINDOW2_H
+#define ZIP7_INC_WINDOWS_CONTROL_WINDOW2_H
#include "../Window.h"
@@ -10,10 +10,12 @@ namespace NControl {
class CWindow2: public CWindow
{
+ // Z7_CLASS_NO_COPY(CWindow2)
+
LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam);
public:
- CWindow2(HWND newWindow = NULL): CWindow(newWindow){};
- virtual ~CWindow2() {};
+ CWindow2(HWND newWindow = NULL): CWindow(newWindow) {}
+ virtual ~CWindow2() {}
bool CreateEx(DWORD exStyle, LPCTSTR className, LPCTSTR windowName,
DWORD style, int x, int y, int width, int height,
@@ -28,8 +30,8 @@ public:
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
virtual bool OnCreate(CREATESTRUCT * /* createStruct */) { return true; }
// virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
- virtual bool OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result);
- virtual bool OnCommand(int code, int itemID, LPARAM lParam, LRESULT &result);
+ // bool OnCommand2(WPARAM wParam, LPARAM lParam, LRESULT &result);
+ virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam, LRESULT &result);
virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; }
virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */, LRESULT & /* result */) { return false; }
virtual void OnDestroy() { PostQuitMessage(0); }
@@ -37,7 +39,7 @@ public:
/*
virtual LRESULT OnHelp(LPHELPINFO helpInfo) { OnHelp(); }
virtual LRESULT OnHelp() {};
- virtual bool OnButtonClicked(int buttonID, HWND buttonHWND);
+ virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND);
virtual void OnOK() {};
virtual void OnCancel() {};
*/
diff --git a/3rdparty/lzma/CPP/Windows/DLL.cpp b/3rdparty/lzma/CPP/Windows/DLL.cpp
index a71a8017b87..b2499ecdc0e 100644
--- a/3rdparty/lzma/CPP/Windows/DLL.cpp
+++ b/3rdparty/lzma/CPP/Windows/DLL.cpp
@@ -4,6 +4,8 @@
#include "DLL.h"
+#ifdef _WIN32
+
#ifndef _UNICODE
extern bool g_IsNT;
#endif
@@ -15,11 +17,11 @@ namespace NDLL {
bool CLibrary::Free() throw()
{
- if (_module == 0)
+ if (_module == NULL)
return true;
if (!::FreeLibrary(_module))
return false;
- _module = 0;
+ _module = NULL;
return true;
}
@@ -88,7 +90,7 @@ bool MyGetModuleFileName(FString &path)
return false;
}
-#ifndef _SFX
+#ifndef Z7_SFX
FString GetModuleDirPrefix()
{
@@ -97,14 +99,81 @@ FString GetModuleDirPrefix()
{
int pos = s.ReverseFind_PathSepar();
if (pos >= 0)
- {
- s.DeleteFrom(pos + 1);
- return s;
- }
+ s.DeleteFrom((unsigned)(pos + 1));
}
- return FTEXT(".") FSTRING_PATH_SEPARATOR;
+ if (s.IsEmpty())
+ s = "." STRING_PATH_SEPARATOR;
+ return s;
}
#endif
}}
+
+#else // _WIN32
+
+#include <dlfcn.h>
+#include <stdlib.h>
+#include "../Common/Common.h"
+
+// FARPROC
+void *GetProcAddress(HMODULE module, LPCSTR procName)
+{
+ void *ptr = NULL;
+ if (module)
+ ptr = dlsym(module, procName);
+ return ptr;
+}
+
+namespace NWindows {
+namespace NDLL {
+
+bool CLibrary::Free() throw()
+{
+ if (!_module)
+ return true;
+ const int ret = dlclose(_module);
+ if (ret != 0)
+ return false;
+ _module = NULL;
+ return true;
+}
+
+bool CLibrary::Load(CFSTR path) throw()
+{
+ if (!Free())
+ return false;
+
+ int options = 0;
+
+ #ifdef RTLD_LOCAL
+ options |= RTLD_LOCAL;
+ #endif
+
+ #ifdef RTLD_NOW
+ options |= RTLD_NOW;
+ #endif
+
+ #ifdef RTLD_GROUP
+ #if ! (defined(hpux) || defined(__hpux))
+ options |= RTLD_GROUP; // mainly for solaris but not for HPUX
+ #endif
+ #endif
+
+ _module = dlopen(path, options);
+ return (_module != NULL);
+}
+
+/*
+// FARPROC
+void * CLibrary::GetProc(LPCSTR procName) const
+{
+ // return My_GetProcAddress(_module, procName);
+ return local_GetProcAddress(_module, procName);
+ // return NULL;
+}
+*/
+
+}}
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/DLL.h b/3rdparty/lzma/CPP/Windows/DLL.h
index 984a1d33b58..19a82b33b89 100644
--- a/3rdparty/lzma/CPP/Windows/DLL.h
+++ b/3rdparty/lzma/CPP/Windows/DLL.h
@@ -1,18 +1,29 @@
// Windows/DLL.h
-#ifndef __WINDOWS_DLL_H
-#define __WINDOWS_DLL_H
+#ifndef ZIP7_INC_WINDOWS_DLL_H
+#define ZIP7_INC_WINDOWS_DLL_H
#include "../Common/MyString.h"
+#ifndef _WIN32
+typedef void * HMODULE;
+// typedef int (*FARPROC)();
+// typedef void *FARPROC;
+void *GetProcAddress(HMODULE module, LPCSTR procName);
+#endif
+
namespace NWindows {
namespace NDLL {
+#ifdef _WIN32
+
+/*
#ifdef UNDER_CE
-#define My_GetProcAddress(module, procName) ::GetProcAddressA(module, procName)
+#define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName)
#else
-#define My_GetProcAddress(module, procName) ::GetProcAddress(module, procName)
+#define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName)
#endif
+*/
/* Win32: Don't call CLibrary::Free() and FreeLibrary() from another
FreeLibrary() code: detaching code in DLL entry-point or in
@@ -22,13 +33,25 @@ class CLibrary
{
HMODULE _module;
- // CLASS_NO_COPY(CLibrary);
+ // Z7_CLASS_NO_COPY(CLibrary);
+ // copy constructor is required here
public:
- CLibrary(): _module(NULL) {};
+ CLibrary(): _module(NULL) {}
~CLibrary() { Free(); }
- operator HMODULE() const { return _module; }
- HMODULE* operator&() { return &_module; }
+ CLibrary(const CLibrary &c): _module(NULL)
+ {
+ if (c._module)
+ {
+ // we need non const to reference from original item
+ // c._module = NULL;
+ throw 20230102;
+ }
+ }
+
+ HMODULE Get_HMODULE() const { return _module; }
+ // operator HMODULE() const { return _module; }
+ // HMODULE* operator&() { return &_module; }
bool IsLoaded() const { return (_module != NULL); }
void Attach(HMODULE m)
@@ -38,7 +61,7 @@ public:
}
HMODULE Detach()
{
- HMODULE m = _module;
+ const HMODULE m = _module;
_module = NULL;
return m;
}
@@ -46,9 +69,31 @@ public:
bool Free() throw();
bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw();
bool Load(CFSTR path) throw();
- FARPROC GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
+ // FARPROC
+ // void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
+};
+
+#else
+
+class CLibrary
+{
+ HMODULE _module;
+
+ // Z7_CLASS_NO_COPY(CLibrary);
+public:
+ CLibrary(): _module(NULL) {}
+ ~CLibrary() { Free(); }
+
+ HMODULE Get_HMODULE() const { return _module; }
+
+ bool Free() throw();
+ bool Load(CFSTR path) throw();
+ // FARPROC
+ // void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); }
};
+#endif
+
bool MyGetModuleFileName(FString &path);
FString GetModuleDirPrefix();
diff --git a/3rdparty/lzma/CPP/Windows/Defs.h b/3rdparty/lzma/CPP/Windows/Defs.h
index 281c40c33eb..8ab9cf5ea79 100644
--- a/3rdparty/lzma/CPP/Windows/Defs.h
+++ b/3rdparty/lzma/CPP/Windows/Defs.h
@@ -1,16 +1,16 @@
// Windows/Defs.h
-#ifndef __WINDOWS_DEFS_H
-#define __WINDOWS_DEFS_H
+#ifndef ZIP7_INC_WINDOWS_DEFS_H
+#define ZIP7_INC_WINDOWS_DEFS_H
#include "../Common/MyWindows.h"
#ifdef _WIN32
-inline bool LRESULTToBool(LRESULT v) { return (v != FALSE); }
-inline bool BOOLToBool(BOOL v) { return (v != FALSE); }
inline BOOL BoolToBOOL(bool v) { return (v ? TRUE: FALSE); }
#endif
+inline bool BOOLToBool(BOOL v) { return (v != FALSE); }
+
inline VARIANT_BOOL BoolToVARIANT_BOOL(bool v) { return (v ? VARIANT_TRUE: VARIANT_FALSE); }
inline bool VARIANT_BOOLToBool(VARIANT_BOOL v) { return (v != VARIANT_FALSE); }
diff --git a/3rdparty/lzma/CPP/Windows/ErrorMsg.cpp b/3rdparty/lzma/CPP/Windows/ErrorMsg.cpp
index c9de4a6c0a7..5acf3adb613 100644
--- a/3rdparty/lzma/CPP/Windows/ErrorMsg.cpp
+++ b/3rdparty/lzma/CPP/Windows/ErrorMsg.cpp
@@ -2,21 +2,33 @@
#include "StdAfx.h"
-#ifndef _UNICODE
+#if !defined(_UNICODE) || !defined(_WIN32)
#include "../Common/StringConvert.h"
#endif
#include "ErrorMsg.h"
-#ifndef _UNICODE
+#ifdef _WIN32
+#if !defined(_UNICODE)
extern bool g_IsNT;
#endif
+#endif
namespace NWindows {
namespace NError {
static bool MyFormatMessage(DWORD errorCode, UString &message)
{
+ #ifndef Z7_SFX
+ if ((HRESULT)errorCode == MY_HRES_ERROR_INTERNAL_ERROR)
+ {
+ message = "Internal Error: The failure in hardware (RAM or CPU), OS or program";
+ return true;
+ }
+ #endif
+
+ #ifdef _WIN32
+
LPVOID msgBuf;
#ifndef _UNICODE
if (!g_IsNT)
@@ -38,8 +50,63 @@ static bool MyFormatMessage(DWORD errorCode, UString &message)
}
::LocalFree(msgBuf);
return true;
+
+ #else // _WIN32
+
+ AString m;
+
+ const char *s = NULL;
+
+ switch ((Int32)errorCode)
+ {
+ // case ERROR_NO_MORE_FILES : s = "No more files"; break;
+ // case ERROR_DIRECTORY : s = "Error Directory"; break;
+ case E_NOTIMPL : s = "E_NOTIMPL : Not implemented"; break;
+ case E_NOINTERFACE : s = "E_NOINTERFACE : No such interface supported"; break;
+ case E_ABORT : s = "E_ABORT : Operation aborted"; break;
+ case E_FAIL : s = "E_FAIL : Unspecified error"; break;
+
+ case STG_E_INVALIDFUNCTION : s = "STG_E_INVALIDFUNCTION"; break;
+ case CLASS_E_CLASSNOTAVAILABLE : s = "CLASS_E_CLASSNOTAVAILABLE"; break;
+
+ case E_OUTOFMEMORY : s = "E_OUTOFMEMORY : Can't allocate required memory"; break;
+ case E_INVALIDARG : s = "E_INVALIDARG : One or more arguments are invalid"; break;
+
+ // case MY_E_ERROR_NEGATIVE_SEEK : s = "MY_E_ERROR_NEGATIVE_SEEK"; break;
+ default:
+ break;
+ }
+
+ /* strerror() for unknown errors still shows message "Unknown error -12345678")
+ So we must transfer error codes before strerror() */
+ if (!s)
+ {
+ if ((errorCode & 0xFFFF0000) == (UInt32)((MY_FACILITY_WRes << 16) | 0x80000000))
+ errorCode &= 0xFFFF;
+ else if ((errorCode & ((UInt32)1 << 31)))
+ return false; // we will show hex error later for that case
+
+ s = strerror((int)errorCode);
+
+ // if (!s)
+ {
+ m += "errno=";
+ m.Add_UInt32(errorCode);
+ if (s)
+ m += " : ";
+ }
+ }
+
+ if (s)
+ m += s;
+
+ MultiByteToUnicodeString2(message, m);
+ return true;
+
+ #endif
}
+
UString MyFormatMessage(DWORD errorCode)
{
UString m;
@@ -53,8 +120,8 @@ UString MyFormatMessage(DWORD errorCode)
s[7 - i] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
}
s[8] = 0;
- m.AddAscii("Error #");
- m.AddAscii(s);
+ m += "Error #";
+ m += s;
}
else if (m.Len() >= 2
&& m[m.Len() - 1] == 0x0A
diff --git a/3rdparty/lzma/CPP/Windows/ErrorMsg.h b/3rdparty/lzma/CPP/Windows/ErrorMsg.h
index 0957c696ad1..6142b4ebe64 100644
--- a/3rdparty/lzma/CPP/Windows/ErrorMsg.h
+++ b/3rdparty/lzma/CPP/Windows/ErrorMsg.h
@@ -1,7 +1,7 @@
// Windows/ErrorMsg.h
-#ifndef __WINDOWS_ERROR_MSG_H
-#define __WINDOWS_ERROR_MSG_H
+#ifndef ZIP7_INC_WINDOWS_ERROR_MSG_H
+#define ZIP7_INC_WINDOWS_ERROR_MSG_H
#include "../Common/MyString.h"
@@ -9,6 +9,7 @@ namespace NWindows {
namespace NError {
UString MyFormatMessage(DWORD errorCode);
+inline UString MyFormatMessage(HRESULT errorCode) { return MyFormatMessage((DWORD)errorCode); }
}}
diff --git a/3rdparty/lzma/CPP/Windows/FileDir.cpp b/3rdparty/lzma/CPP/Windows/FileDir.cpp
index da71b710bdc..5b1f340b5c7 100644
--- a/3rdparty/lzma/CPP/Windows/FileDir.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileDir.cpp
@@ -2,8 +2,21 @@
#include "StdAfx.h"
-#ifndef _UNICODE
+
+#ifndef _WIN32
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+#include <time.h>
+#include <utime.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include "../Common/StringConvert.h"
+#include "../Common/C_FileIO.h"
#endif
#include "FileDir.h"
@@ -18,58 +31,94 @@ using namespace NWindows;
using namespace NFile;
using namespace NName;
+#ifndef _WIN32
+
+static bool FiTime_To_timespec(const CFiTime *ft, timespec &ts)
+{
+ if (ft)
+ {
+ ts = *ft;
+ return true;
+ }
+ // else
+ {
+ ts.tv_sec = 0;
+ ts.tv_nsec =
+ #ifdef UTIME_OMIT
+ UTIME_OMIT; // -2 keep old timesptamp
+ #else
+ // UTIME_NOW; -1 // set to the current time
+ 0;
+ #endif
+ return false;
+ }
+}
+#endif
+
namespace NWindows {
namespace NFile {
namespace NDir {
+#ifdef _WIN32
+
#ifndef UNDER_CE
bool GetWindowsDir(FString &path)
{
- UINT needLength;
+ const unsigned kBufSize = MAX_PATH + 16;
+ UINT len;
#ifndef _UNICODE
if (!g_IsNT)
{
- TCHAR s[MAX_PATH + 2];
+ TCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetWindowsDirectory(s, MAX_PATH + 1);
+ len = ::GetWindowsDirectory(s, kBufSize);
path = fas2fs(s);
}
else
#endif
{
- WCHAR s[MAX_PATH + 2];
+ WCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetWindowsDirectoryW(s, MAX_PATH + 1);
+ len = ::GetWindowsDirectoryW(s, kBufSize);
path = us2fs(s);
}
- return (needLength > 0 && needLength <= MAX_PATH);
+ return (len != 0 && len < kBufSize);
}
+
+/*
+new DOCs for GetSystemDirectory:
+ returned path does not end with a backslash unless the
+ system directory is the root directory.
+*/
+
bool GetSystemDir(FString &path)
{
- UINT needLength;
+ const unsigned kBufSize = MAX_PATH + 16;
+ UINT len;
#ifndef _UNICODE
if (!g_IsNT)
{
- TCHAR s[MAX_PATH + 2];
+ TCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetSystemDirectory(s, MAX_PATH + 1);
+ len = ::GetSystemDirectory(s, kBufSize);
path = fas2fs(s);
}
else
#endif
{
- WCHAR s[MAX_PATH + 2];
+ WCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetSystemDirectoryW(s, MAX_PATH + 1);
+ len = ::GetSystemDirectoryW(s, kBufSize);
path = us2fs(s);
}
- return (needLength > 0 && needLength <= MAX_PATH);
+ return (len != 0 && len < kBufSize);
}
-#endif
+#endif // UNDER_CE
+
-bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
+bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
{
#ifndef _UNICODE
if (!g_IsNT)
@@ -83,7 +132,7 @@ bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const
IF_USE_MAIN_PATH
hDir = ::CreateFileW(fs2us(path), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (hDir == INVALID_HANDLE_VALUE && USE_SUPER_PATH)
{
UString superPath;
@@ -102,6 +151,8 @@ bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const
return res;
}
+
+
bool SetFileAttrib(CFSTR path, DWORD attrib)
{
#ifndef _UNICODE
@@ -116,7 +167,7 @@ bool SetFileAttrib(CFSTR path, DWORD attrib)
IF_USE_MAIN_PATH
if (::SetFileAttributesW(fs2us(path), attrib))
return true;
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH)
{
UString superPath;
@@ -128,6 +179,17 @@ bool SetFileAttrib(CFSTR path, DWORD attrib)
return false;
}
+
+bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib)
+{
+ #ifdef _WIN32
+ if ((attrib & 0xF0000000) != 0)
+ attrib &= 0x3FFF;
+ #endif
+ return SetFileAttrib(path, attrib);
+}
+
+
bool RemoveDir(CFSTR path)
{
#ifndef _UNICODE
@@ -142,7 +204,7 @@ bool RemoveDir(CFSTR path)
IF_USE_MAIN_PATH
if (::RemoveDirectoryW(fs2us(path)))
return true;
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH)
{
UString superPath;
@@ -154,6 +216,7 @@ bool RemoveDir(CFSTR path)
return false;
}
+
bool MyMoveFile(CFSTR oldFile, CFSTR newFile)
{
#ifndef _UNICODE
@@ -166,9 +229,11 @@ bool MyMoveFile(CFSTR oldFile, CFSTR newFile)
#endif
{
IF_USE_MAIN_PATH_2(oldFile, newFile)
+ {
if (::MoveFileW(fs2us(oldFile), fs2us(newFile)))
return true;
- #ifdef WIN_LONG_PATH
+ }
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH_2)
{
UString d1, d2;
@@ -181,7 +246,6 @@ bool MyMoveFile(CFSTR oldFile, CFSTR newFile)
}
#ifndef UNDER_CE
-
EXTERN_C_BEGIN
typedef BOOL (WINAPI *Func_CreateHardLinkW)(
LPCWSTR lpFileName,
@@ -189,6 +253,7 @@ typedef BOOL (WINAPI *Func_CreateHardLinkW)(
LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
EXTERN_C_END
+#endif // UNDER_CE
bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName)
{
@@ -205,14 +270,19 @@ bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName)
else
#endif
{
- Func_CreateHardLinkW my_CreateHardLinkW = (Func_CreateHardLinkW)
- ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW");
+ const
+ Func_CreateHardLinkW
+ my_CreateHardLinkW = Z7_GET_PROC_ADDRESS(
+ Func_CreateHardLinkW, ::GetModuleHandleW(L"kernel32.dll"),
+ "CreateHardLinkW");
if (!my_CreateHardLinkW)
return false;
IF_USE_MAIN_PATH_2(newFileName, existFileName)
+ {
if (my_CreateHardLinkW(fs2us(newFileName), fs2us(existFileName), NULL))
return true;
- #ifdef WIN_LONG_PATH
+ }
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH_2)
{
UString d1, d2;
@@ -224,7 +294,6 @@ bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName)
return false;
}
-#endif
/*
WinXP-64 CreateDir():
@@ -263,7 +332,7 @@ bool CreateDir(CFSTR path)
IF_USE_MAIN_PATH
if (::CreateDirectoryW(fs2us(path), NULL))
return true;
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH)
{
UString superPath;
@@ -298,7 +367,7 @@ static bool CreateDir2(CFSTR path)
IF_USE_MAIN_PATH
if (::CreateDirectoryW(fs2us(path), NULL))
return true;
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH)
{
UString superPath;
@@ -324,12 +393,16 @@ static bool CreateDir2(CFSTR path)
return fi.IsDir();
}
+#endif // _WIN32
+
+static bool CreateDir2(CFSTR path);
+
bool CreateComplexDir(CFSTR _path)
{
#ifdef _WIN32
{
- DWORD attrib = NFind::GetFileAttrib(_path);
+ const DWORD attrib = NFind::GetFileAttrib(_path);
if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
return true;
}
@@ -339,13 +412,23 @@ bool CreateComplexDir(CFSTR _path)
if (IsDriveRootPath_SuperAllowed(_path))
return false;
- unsigned prefixSize = GetRootPrefixSize(_path);
+ const unsigned prefixSize = GetRootPrefixSize(_path);
- #endif
+ #endif // UNDER_CE
+
+ #else // _WIN32
+
+ // Posix
+ NFind::CFileInfo fi;
+ if (fi.Find(_path))
+ {
+ if (fi.IsDir())
+ return true;
+ }
- #endif
+ #endif // _WIN32
- FString path = _path;
+ FString path (_path);
int pos = path.ReverseFind_PathSepar();
if (pos >= 0 && (unsigned)pos == path.Len() - 1)
@@ -355,8 +438,8 @@ bool CreateComplexDir(CFSTR _path)
path.DeleteBack();
}
- const FString path2 = path;
- pos = path.Len();
+ const FString path2 (path);
+ pos = (int)path.Len();
for (;;)
{
@@ -375,17 +458,17 @@ bool CreateComplexDir(CFSTR _path)
return false;
#endif
- path.DeleteFrom(pos);
+ path.DeleteFrom((unsigned)pos);
}
while (pos < (int)path2.Len())
{
- int pos2 = NName::FindSepar(path2.Ptr(pos + 1));
+ int pos2 = NName::FindSepar(path2.Ptr((unsigned)pos + 1));
if (pos2 < 0)
- pos = path2.Len();
+ pos = (int)path2.Len();
else
pos += 1 + pos2;
- path.SetFrom(path2, pos);
+ path.SetFrom(path2, (unsigned)pos);
if (!CreateDir(path))
return false;
}
@@ -393,6 +476,9 @@ bool CreateComplexDir(CFSTR _path)
return true;
}
+
+#ifdef _WIN32
+
bool DeleteFileAlways(CFSTR path)
{
/* If alt stream, we also need to clear READ-ONLY attribute of main file before delete.
@@ -403,7 +489,7 @@ bool DeleteFileAlways(CFSTR path)
&& (attrib & FILE_ATTRIBUTE_DIRECTORY) == 0
&& (attrib & FILE_ATTRIBUTE_READONLY) != 0)
{
- if (!SetFileAttrib(path, attrib & ~FILE_ATTRIBUTE_READONLY))
+ if (!SetFileAttrib(path, attrib & ~(DWORD)FILE_ATTRIBUTE_READONLY))
return false;
}
}
@@ -422,7 +508,7 @@ bool DeleteFileAlways(CFSTR path)
IF_USE_MAIN_PATH
if (::DeleteFileW(fs2us(path)))
return true;
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH)
{
UString superPath;
@@ -434,6 +520,8 @@ bool DeleteFileAlways(CFSTR path)
return false;
}
+
+
bool RemoveDirWithSubItems(const FString &path)
{
bool needRemoveSubItems = true;
@@ -452,12 +540,14 @@ bool RemoveDirWithSubItems(const FString &path)
if (needRemoveSubItems)
{
- FString s = path;
+ FString s (path);
s.Add_PathSepar();
- unsigned prefixSize = s.Len();
- s += FCHAR_ANY_MASK;
- NFind::CEnumerator enumerator(s);
- NFind::CFileInfo fi;
+ const unsigned prefixSize = s.Len();
+ NFind::CEnumerator enumerator;
+ enumerator.SetDirPrefix(s);
+ NFind::CDirEntry fi;
+ bool isError = false;
+ DWORD lastError = 0;
while (enumerator.Next(fi))
{
s.DeleteFrom(prefixSize);
@@ -465,18 +555,32 @@ bool RemoveDirWithSubItems(const FString &path)
if (fi.IsDir())
{
if (!RemoveDirWithSubItems(s))
- return false;
+ {
+ lastError = GetLastError();
+ isError = true;
+ }
}
else if (!DeleteFileAlways(s))
- return false;
+ {
+ lastError = GetLastError();
+ isError = false;
+ }
+ }
+ if (isError)
+ {
+ SetLastError(lastError);
+ return false;
}
}
+ // we clear read-only attrib to remove read-only dir
if (!SetFileAttrib(path, 0))
return false;
return RemoveDir(path);
}
+#endif // _WIN32
+
#ifdef UNDER_CE
bool MyGetFullPathName(CFSTR path, FString &resFullPath)
@@ -492,9 +596,14 @@ bool MyGetFullPathName(CFSTR path, FString &resFullPath)
return GetFullPath(path, resFullPath);
}
+#ifdef _WIN32
+
+/* Win10: SetCurrentDirectory() doesn't support long paths and
+ doesn't support super prefix "\\?\", if long path behavior is not
+ enabled in registry (LongPathsEnabled) and in manifest (longPathAware). */
+
bool SetCurrentDir(CFSTR path)
{
- // SetCurrentDirectory doesn't support \\?\ prefix
#ifndef _UNICODE
if (!g_IsNT)
{
@@ -507,30 +616,80 @@ bool SetCurrentDir(CFSTR path)
}
}
+
+/*
+we use system function GetCurrentDirectory()
+new GetCurrentDirectory() DOCs:
+ - If the function fails, the return value is zero.
+ - If the function succeeds, the return value specifies
+ the number of characters that are written to the buffer,
+ not including the terminating null character.
+ - If the buffer is not large enough, the return value specifies
+ the required size of the buffer, in characters,
+ including the null-terminating character.
+
+GetCurrentDir() calls GetCurrentDirectory().
+GetCurrentDirectory() in win10 in tests:
+ the returned (path) does not end with a backslash, if
+ current directory is not root directory of drive.
+ But that behavior is not guarantied in specification docs.
+*/
+
bool GetCurrentDir(FString &path)
{
+ const unsigned kBufSize = MAX_PATH + 16;
path.Empty();
- DWORD needLength;
+
#ifndef _UNICODE
if (!g_IsNT)
{
- TCHAR s[MAX_PATH + 2];
+ TCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetCurrentDirectory(MAX_PATH + 1, s);
+ const DWORD len = ::GetCurrentDirectory(kBufSize, s);
+ if (len == 0 || len >= kBufSize)
+ return false;
+ s[kBufSize] = 0; // optional guard
path = fas2fs(s);
+ return true;
}
else
#endif
{
- WCHAR s[MAX_PATH + 2];
- s[0] = 0;
- needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, s);
- path = us2fs(s);
+ DWORD len;
+ {
+ WCHAR s[kBufSize + 1];
+ s[0] = 0;
+ len = ::GetCurrentDirectoryW(kBufSize, s);
+ if (len == 0)
+ return false;
+ if (len < kBufSize)
+ {
+ s[kBufSize] = 0; // optional guard
+ path = us2fs(s);
+ return true;
+ }
+ }
+ UString temp;
+ const DWORD len2 = ::GetCurrentDirectoryW(len, temp.GetBuf(len));
+ if (len2 == 0)
+ return false;
+ temp.ReleaseBuf_CalcLen(len);
+ if (temp.Len() != len2 || len - 1 != len2)
+ {
+ /* it's unexpected case, if current dir of process
+ was changed between two function calls,
+ or some unexpected function implementation */
+ // SetLastError((DWORD)E_FAIL); // we can set some error code
+ return false;
+ }
+ path = us2fs(temp);
+ return true;
}
- return (needLength > 0 && needLength <= MAX_PATH);
}
-#endif
+#endif // _WIN32
+#endif // UNDER_CE
+
bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName)
{
@@ -538,8 +697,9 @@ bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName
if (!res)
resDirPrefix = path;
int pos = resDirPrefix.ReverseFind_PathSepar();
- resFileName = resDirPrefix.Ptr(pos + 1);
- resDirPrefix.DeleteFrom(pos + 1);
+ pos++;
+ resFileName = resDirPrefix.Ptr((unsigned)pos);
+ resDirPrefix.DeleteFrom((unsigned)pos);
return res;
}
@@ -549,50 +709,85 @@ bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix)
return GetFullPathAndSplit(path, resDirPrefix, resFileName);
}
+
+
bool MyGetTempPath(FString &path)
{
- path.Empty();
- DWORD needLength;
+ #ifdef _WIN32
+
+ /*
+ new DOCs for GetTempPathW():
+ - The returned string ends with a backslash.
+ - The maximum possible return value is MAX_PATH+1 (261).
+ */
+
+ const unsigned kBufSize = MAX_PATH + 16;
+ DWORD len;
#ifndef _UNICODE
if (!g_IsNT)
{
- TCHAR s[MAX_PATH + 2];
+ TCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetTempPath(MAX_PATH + 1, s);
+ len = ::GetTempPath(kBufSize, s);
path = fas2fs(s);
}
else
#endif
{
- WCHAR s[MAX_PATH + 2];
+ WCHAR s[kBufSize + 1];
s[0] = 0;
- needLength = ::GetTempPathW(MAX_PATH + 1, s);;
+ len = ::GetTempPathW(kBufSize, s);
path = us2fs(s);
}
- return (needLength > 0 && needLength <= MAX_PATH);
+ /* win10: GetTempPathW() doesn't set backslash at the end of path,
+ if (buffer_size == len_of(path_with_backslash)).
+ So we normalize path here: */
+ NormalizeDirPathPrefix(path);
+ return (len != 0 && len < kBufSize);
+
+ #else // !_WIN32
+
+ // FIXME: improve that code
+ path = STRING_PATH_SEPARATOR "tmp";
+ const char *s;
+ if (NFind::DoesDirExist_FollowLink(path))
+ s = STRING_PATH_SEPARATOR "tmp" STRING_PATH_SEPARATOR;
+ else
+ s = "." STRING_PATH_SEPARATOR;
+ path = s;
+ return true;
+
+ #endif
}
-static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile)
+
+bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile)
{
- UInt32 d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();
+ UInt32 d =
+ #ifdef _WIN32
+ (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();
+ #else
+ (UInt32)(time(NULL) << 12) ^ ((UInt32)getppid() << 14) ^ (UInt32)(getpid());
+ #endif
+
for (unsigned i = 0; i < 100; i++)
{
- path = prefix;
+ postfix.Empty();
if (addRandom)
{
- FChar s[16];
- UInt32 value = d;
+ char s[16];
+ UInt32 val = d;
unsigned k;
for (k = 0; k < 8; k++)
{
- unsigned t = value & 0xF;
- value >>= 4;
- s[k] = (FChar)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
+ const unsigned t = val & 0xF;
+ val >>= 4;
+ s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
}
s[k] = '\0';
if (outFile)
- path += FChar('.');
- path += s;
+ postfix.Add_Dot();
+ postfix += s;
UInt32 step = GetTickCount() + 2;
if (step == 0)
step = 1;
@@ -600,7 +795,9 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu
}
addRandom = true;
if (outFile)
- path += FTEXT(".tmp");
+ postfix += ".tmp";
+ FString path (prefix);
+ path += postfix;
if (NFind::DoesFileOrDirExist(path))
{
SetLastError(ERROR_ALREADY_EXISTS);
@@ -616,12 +813,12 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu
if (CreateDir(path))
return true;
}
- DWORD error = GetLastError();
+ const DWORD error = GetLastError();
if (error != ERROR_FILE_EXISTS &&
error != ERROR_ALREADY_EXISTS)
break;
}
- path.Empty();
+ postfix.Empty();
return false;
}
@@ -629,8 +826,12 @@ bool CTempFile::Create(CFSTR prefix, NIO::COutFile *outFile)
{
if (!Remove())
return false;
- if (!CreateTempFile(prefix, false, _path, outFile))
+ _path.Empty();
+ AString postfix;
+ if (!CreateTempFile2(prefix, false, postfix, outFile))
return false;
+ _path = prefix;
+ _path += postfix;
_mustBeDeleted = true;
return true;
}
@@ -639,11 +840,16 @@ bool CTempFile::CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFil
{
if (!Remove())
return false;
+ _path.Empty();
FString tempPath;
if (!MyGetTempPath(tempPath))
return false;
- if (!CreateTempFile(tempPath + namePrefix, true, _path, outFile))
+ AString postfix;
+ tempPath += namePrefix;
+ if (!CreateTempFile2(tempPath, true, postfix, outFile))
return false;
+ _path = tempPath;
+ _path += postfix;
_mustBeDeleted = true;
return true;
}
@@ -658,23 +864,44 @@ bool CTempFile::Remove()
bool CTempFile::MoveTo(CFSTR name, bool deleteDestBefore)
{
+ // DWORD attrib = 0;
if (deleteDestBefore)
- if (NFind::DoesFileExist(name))
+ {
+ if (NFind::DoesFileExist_Raw(name))
+ {
+ // attrib = NFind::GetFileAttrib(name);
if (!DeleteFileAlways(name))
return false;
+ }
+ }
DisableDeleting();
return MyMoveFile(_path, name);
+
+ /*
+ if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_READONLY))
+ {
+ DWORD attrib2 = NFind::GetFileAttrib(name);
+ if (attrib2 != INVALID_FILE_ATTRIBUTES)
+ SetFileAttrib(name, attrib2 | FILE_ATTRIBUTE_READONLY);
+ }
+ */
}
+#ifdef _WIN32
bool CTempDir::Create(CFSTR prefix)
{
if (!Remove())
return false;
+ _path.Empty();
FString tempPath;
if (!MyGetTempPath(tempPath))
return false;
- if (!CreateTempFile(tempPath + prefix, true, _path, NULL))
+ tempPath += prefix;
+ AString postfix;
+ if (!CreateTempFile2(tempPath, true, postfix, NULL))
return false;
+ _path = tempPath;
+ _path += postfix;
_mustBeDeleted = true;
return true;
}
@@ -686,5 +913,317 @@ bool CTempDir::Remove()
_mustBeDeleted = !RemoveDirWithSubItems(_path);
return !_mustBeDeleted;
}
+#endif
+
+
+
+#ifndef _WIN32
+
+bool RemoveDir(CFSTR path)
+{
+ return (rmdir(path) == 0);
+}
+
+
+static BOOL My_CopyFile(CFSTR oldFile, CFSTR newFile)
+{
+ NWindows::NFile::NIO::COutFile outFile;
+ if (!outFile.Create(newFile, false))
+ return FALSE;
+
+ NWindows::NFile::NIO::CInFile inFile;
+ if (!inFile.Open(oldFile))
+ return FALSE;
+
+ char buf[1 << 14];
+
+ for (;;)
+ {
+ const ssize_t num = inFile.read_part(buf, sizeof(buf));
+ if (num == 0)
+ return TRUE;
+ if (num < 0)
+ return FALSE;
+ size_t processed;
+ const ssize_t num2 = outFile.write_full(buf, (size_t)num, processed);
+ if (num2 != num || processed != (size_t)num)
+ return FALSE;
+ }
+}
+
+
+bool MyMoveFile(CFSTR oldFile, CFSTR newFile)
+{
+ int res = rename(oldFile, newFile);
+ if (res == 0)
+ return true;
+ if (errno != EXDEV) // (oldFile and newFile are not on the same mounted filesystem)
+ return false;
+
+ if (My_CopyFile(oldFile, newFile) == FALSE)
+ return false;
+
+ struct stat info_file;
+ res = stat(oldFile, &info_file);
+ if (res != 0)
+ return false;
+
+ /*
+ ret = chmod(dst,info_file.st_mode & g_umask.mask);
+ */
+ return (unlink(oldFile) == 0);
+}
+
+
+bool CreateDir(CFSTR path)
+{
+ return (mkdir(path, 0777) == 0); // change it
+}
+
+static bool CreateDir2(CFSTR path)
+{
+ return (mkdir(path, 0777) == 0); // change it
+}
+
+
+bool DeleteFileAlways(CFSTR path)
+{
+ return (remove(path) == 0);
+}
+
+bool SetCurrentDir(CFSTR path)
+{
+ return (chdir(path) == 0);
+}
+
+
+bool GetCurrentDir(FString &path)
+{
+ path.Empty();
+
+ #define MY_PATH_MAX PATH_MAX
+ // #define MY_PATH_MAX 1024
+
+ char s[MY_PATH_MAX + 1];
+ char *res = getcwd(s, MY_PATH_MAX);
+ if (res)
+ {
+ path = fas2fs(s);
+ return true;
+ }
+ {
+ // if (errno != ERANGE) return false;
+ #if defined(__GLIBC__) || defined(__APPLE__)
+ /* As an extension to the POSIX.1-2001 standard, glibc's getcwd()
+ allocates the buffer dynamically using malloc(3) if buf is NULL. */
+ res = getcwd(NULL, 0);
+ if (res)
+ {
+ path = fas2fs(res);
+ ::free(res);
+ return true;
+ }
+ #endif
+ return false;
+ }
+}
+
+
+
+// #undef UTIME_OMIT // to debug
+
+#ifndef UTIME_OMIT
+ /* we can define UTIME_OMIT for debian and another systems.
+ Is it OK to define UTIME_OMIT to -2 here, if UTIME_OMIT is not defined? */
+ // #define UTIME_OMIT -2
+#endif
+
+
+
+
+
+bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
+{
+ // need testing
+ /*
+ struct utimbuf buf;
+ struct stat st;
+ UNUSED_VAR(cTime)
+
+ printf("\nstat = %s\n", path);
+ int ret = stat(path, &st);
+
+ if (ret == 0)
+ {
+ buf.actime = st.st_atime;
+ buf.modtime = st.st_mtime;
+ }
+ else
+ {
+ time_t cur_time = time(0);
+ buf.actime = cur_time;
+ buf.modtime = cur_time;
+ }
+
+ if (aTime)
+ {
+ UInt32 ut;
+ if (NTime::FileTimeToUnixTime(*aTime, ut))
+ buf.actime = ut;
+ }
+
+ if (mTime)
+ {
+ UInt32 ut;
+ if (NTime::FileTimeToUnixTime(*mTime, ut))
+ buf.modtime = ut;
+ }
+
+ return utime(path, &buf) == 0;
+ */
+
+ // if (!aTime && !mTime) return true;
+
+ struct timespec times[2];
+ UNUSED_VAR(cTime)
+
+ bool needChange;
+ needChange = FiTime_To_timespec(aTime, times[0]);
+ needChange |= FiTime_To_timespec(mTime, times[1]);
+
+ /*
+ if (mTime)
+ {
+ printf("\n time = %ld.%9ld\n", mTime->tv_sec, mTime->tv_nsec);
+ }
+ */
+
+ if (!needChange)
+ return true;
+ const int flags = 0; // follow link
+ // = AT_SYMLINK_NOFOLLOW; // don't follow link
+ return utimensat(AT_FDCWD, path, times, flags) == 0;
+}
+
+
+
+struct C_umask
+{
+ mode_t mask;
+
+ C_umask()
+ {
+ /* by security reasons we restrict attributes according
+ with process's file mode creation mask (umask) */
+ const mode_t um = umask(0); // octal :0022 is expected
+ mask = 0777 & (~um); // octal: 0755 is expected
+ umask(um); // restore the umask
+ // printf("\n umask = 0%03o mask = 0%03o\n", um, mask);
+
+ // mask = 0777; // debug we can disable the restriction:
+ }
+};
+
+static C_umask g_umask;
+
+// #define PRF(x) x;
+#define PRF(x)
+
+#define TRACE_SetFileAttrib(msg) \
+ PRF(printf("\nSetFileAttrib(%s, %x) : %s\n", (const char *)path, attrib, msg);)
+
+#define TRACE_chmod(s, mode) \
+ PRF(printf("\n chmod(%s, %o)\n", (const char *)path, (unsigned)(mode));)
+
+int my_chown(CFSTR path, uid_t owner, gid_t group)
+{
+ return chown(path, owner, group);
+}
+
+bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib)
+{
+ TRACE_SetFileAttrib("")
+
+ struct stat st;
+
+ bool use_lstat = true;
+ if (use_lstat)
+ {
+ if (lstat(path, &st) != 0)
+ {
+ TRACE_SetFileAttrib("bad lstat()")
+ return false;
+ }
+ // TRACE_chmod("lstat", st.st_mode);
+ }
+ else
+ {
+ if (stat(path, &st) != 0)
+ {
+ TRACE_SetFileAttrib("bad stat()")
+ return false;
+ }
+ }
+
+ if (attrib & FILE_ATTRIBUTE_UNIX_EXTENSION)
+ {
+ TRACE_SetFileAttrib("attrib & FILE_ATTRIBUTE_UNIX_EXTENSION")
+ st.st_mode = attrib >> 16;
+ if (S_ISDIR(st.st_mode))
+ {
+ // user/7z must be able to create files in this directory
+ st.st_mode |= (S_IRUSR | S_IWUSR | S_IXUSR);
+ }
+ else if (!S_ISREG(st.st_mode))
+ return true;
+ }
+ else if (S_ISLNK(st.st_mode))
+ {
+ /* for most systems: permissions for symlinks are fixed to rwxrwxrwx.
+ so we don't need chmod() for symlinks. */
+ return true;
+ // SetLastError(ENOSYS);
+ // return false;
+ }
+ else
+ {
+ TRACE_SetFileAttrib("Only Windows Attributes")
+ // Only Windows Attributes
+ if (S_ISDIR(st.st_mode)
+ || (attrib & FILE_ATTRIBUTE_READONLY) == 0)
+ return true;
+ st.st_mode &= ~(mode_t)(S_IWUSR | S_IWGRP | S_IWOTH); // octal: ~0222; // disable write permissions
+ }
+
+ int res;
+ /*
+ if (S_ISLNK(st.st_mode))
+ {
+ printf("\nfchmodat()\n");
+ TRACE_chmod(path, (st.st_mode) & g_umask.mask)
+ // AT_SYMLINK_NOFOLLOW is not implemted still in Linux.
+ res = fchmodat(AT_FDCWD, path, (st.st_mode) & g_umask.mask,
+ S_ISLNK(st.st_mode) ? AT_SYMLINK_NOFOLLOW : 0);
+ }
+ else
+ */
+ {
+ TRACE_chmod(path, (st.st_mode) & g_umask.mask)
+ res = chmod(path, (st.st_mode) & g_umask.mask);
+ }
+ // TRACE_SetFileAttrib("End")
+ return (res == 0);
+}
+
+
+bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName)
+{
+ PRF(printf("\nhard link() %s -> %s\n", newFileName, existFileName);)
+ return (link(existFileName, newFileName) == 0);
+}
+
+#endif // !_WIN32
+
+// #endif
}}}
diff --git a/3rdparty/lzma/CPP/Windows/FileDir.h b/3rdparty/lzma/CPP/Windows/FileDir.h
index b13d1ccada2..573ffa23329 100644
--- a/3rdparty/lzma/CPP/Windows/FileDir.h
+++ b/3rdparty/lzma/CPP/Windows/FileDir.h
@@ -1,7 +1,7 @@
// Windows/FileDir.h
-#ifndef __WINDOWS_FILE_DIR_H
-#define __WINDOWS_FILE_DIR_H
+#ifndef ZIP7_INC_WINDOWS_FILE_DIR_H
+#define ZIP7_INC_WINDOWS_FILE_DIR_H
#include "../Common/MyString.h"
@@ -14,8 +14,33 @@ namespace NDir {
bool GetWindowsDir(FString &path);
bool GetSystemDir(FString &path);
-bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
+/*
+WIN32 API : SetFileTime() doesn't allow to set zero timestamps in file
+but linux : allows unix time = 0 in filesystem
+*/
+
+bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime);
+
+
+#ifdef _WIN32
+
bool SetFileAttrib(CFSTR path, DWORD attrib);
+
+/*
+ Some programs store posix attributes in high 16 bits of windows attributes field.
+ Also some programs use additional flag markers: 0x8000 or 0x4000.
+ SetFileAttrib_PosixHighDetect() tries to detect posix field, and it extracts only attribute
+ bits that are related to current system only.
+*/
+#else
+
+int my_chown(CFSTR path, uid_t owner, gid_t group);
+
+#endif
+
+bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib);
+
+
bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
#ifndef UNDER_CE
@@ -48,7 +73,9 @@ bool GetCurrentDir(FString &resultPath);
bool MyGetTempPath(FString &resultPath);
-class CTempFile
+bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile);
+
+class CTempFile MY_UNCOPYABLE
{
bool _mustBeDeleted;
FString _path;
@@ -63,7 +90,9 @@ public:
bool MoveTo(CFSTR name, bool deleteDestBefore);
};
-class CTempDir
+
+#ifdef _WIN32
+class CTempDir MY_UNCOPYABLE
{
bool _mustBeDeleted;
FString _path;
@@ -75,9 +104,11 @@ public:
bool Create(CFSTR namePrefix) ;
bool Remove();
};
+#endif
+
#if !defined(UNDER_CE)
-class CCurrentDirRestorer
+class CCurrentDirRestorer MY_UNCOPYABLE
{
FString _path;
public:
diff --git a/3rdparty/lzma/CPP/Windows/FileFind.cpp b/3rdparty/lzma/CPP/Windows/FileFind.cpp
index 05196f927bd..c562a909ce3 100644
--- a/3rdparty/lzma/CPP/Windows/FileFind.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileFind.cpp
@@ -2,8 +2,13 @@
#include "StdAfx.h"
-#ifndef _UNICODE
-#include "../Common/StringConvert.h"
+// #include <stdio.h>
+
+#ifndef _WIN32
+#include <fcntl.h> /* Definition of AT_* constants */
+#include "TimeUtils.h"
+// for major
+// #include <sys/sysmacros.h>
#endif
#include "FileFind.h"
@@ -34,27 +39,62 @@ typedef struct
WCHAR cStreamName[MAX_PATH + 36];
} MY_WIN32_FIND_STREAM_DATA, *MY_PWIN32_FIND_STREAM_DATA;
-typedef WINBASEAPI HANDLE (WINAPI *FindFirstStreamW_Ptr)(LPCWSTR fileName, MY_STREAM_INFO_LEVELS infoLevel,
+typedef HANDLE (WINAPI *Func_FindFirstStreamW)(LPCWSTR fileName, MY_STREAM_INFO_LEVELS infoLevel,
LPVOID findStreamData, DWORD flags);
-typedef WINBASEAPI BOOL (APIENTRY *FindNextStreamW_Ptr)(HANDLE findStream, LPVOID findStreamData);
+typedef BOOL (APIENTRY *Func_FindNextStreamW)(HANDLE findStream, LPVOID findStreamData);
EXTERN_C_END
-#endif
+#endif // defined(_WIN32) && !defined(UNDER_CE)
+
namespace NWindows {
namespace NFile {
-#ifdef SUPPORT_DEVICE_FILE
+
+#ifdef _WIN32
+#ifdef Z7_DEVICE_FILE
namespace NSystem
{
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
}
#endif
+#endif
namespace NFind {
+/*
+#ifdef _WIN32
+#define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0;
+#else
+#define MY_CLEAR_FILETIME(ft) ft.tv_sec = 0; ft.tv_nsec = 0;
+#endif
+*/
+
+void CFileInfoBase::ClearBase() throw()
+{
+ Size = 0;
+ FiTime_Clear(CTime);
+ FiTime_Clear(ATime);
+ FiTime_Clear(MTime);
+
+ #ifdef _WIN32
+ Attrib = 0;
+ // ReparseTag = 0;
+ IsAltStream = false;
+ IsDevice = false;
+ #else
+ dev = 0;
+ ino = 0;
+ mode = 0;
+ nlink = 0;
+ uid = 0;
+ gid = 0;
+ rdev = 0;
+ #endif
+}
+
bool CFileInfo::IsDots() const throw()
{
if (!IsDir() || Name.IsEmpty())
@@ -64,12 +104,17 @@ bool CFileInfo::IsDots() const throw()
return Name.Len() == 1 || (Name.Len() == 2 && Name[1] == '.');
}
+
+#ifdef _WIN32
+
+
#define WIN_FD_TO_MY_FI(fi, fd) \
fi.Attrib = fd.dwFileAttributes; \
fi.CTime = fd.ftCreationTime; \
fi.ATime = fd.ftLastAccessTime; \
fi.MTime = fd.ftLastWriteTime; \
fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; \
+ /* fi.ReparseTag = fd.dwReserved0; */ \
fi.IsAltStream = false; \
fi.IsDevice = false;
@@ -83,7 +128,7 @@ bool CFileInfo::IsDots() const throw()
static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfo &fi)
{
- WIN_FD_TO_MY_FI(fi, fd);
+ WIN_FD_TO_MY_FI(fi, fd)
fi.Name = us2fs(fd.cFileName);
#if defined(_WIN32) && !defined(UNDER_CE)
// fi.ShortName = us2fs(fd.cAlternateFileName);
@@ -91,10 +136,9 @@ static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATAW &fd, CFil
}
#ifndef _UNICODE
-
static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
{
- WIN_FD_TO_MY_FI(fi, fd);
+ WIN_FD_TO_MY_FI(fi, fd)
fi.Name = fas2fs(fd.cFileName);
#if defined(_WIN32) && !defined(UNDER_CE)
// fi.ShortName = fas2fs(fd.cAlternateFileName);
@@ -143,7 +187,8 @@ WinXP-64 FindFirstFile():
\\Server\Share_RootDrive - ERROR_INVALID_NAME
\\Server\Share_RootDrive\ - ERROR_INVALID_NAME
- c:\* - ERROR_FILE_NOT_FOUND, if thare are no item in that folder
+ e:\* - ERROR_FILE_NOT_FOUND, if there are no items in that root folder
+ w:\* - ERROR_PATH_NOT_FOUND, if there is no such drive w:
*/
bool CFindFile::FindFirst(CFSTR path, CFileInfo &fi)
@@ -166,7 +211,7 @@ bool CFindFile::FindFirst(CFSTR path, CFileInfo &fi)
IF_USE_MAIN_PATH
_handle = ::FindFirstFileW(fs2us(path), &fd);
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH)
{
UString superPath;
@@ -207,27 +252,32 @@ bool CFindFile::FindNext(CFileInfo &fi)
////////////////////////////////
// AltStreams
-static FindFirstStreamW_Ptr g_FindFirstStreamW;
-static FindNextStreamW_Ptr g_FindNextStreamW;
+static Func_FindFirstStreamW g_FindFirstStreamW;
+static Func_FindNextStreamW g_FindNextStreamW;
-struct CFindStreamLoader
+static struct CFindStreamLoader
{
CFindStreamLoader()
{
- g_FindFirstStreamW = (FindFirstStreamW_Ptr)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "FindFirstStreamW");
- g_FindNextStreamW = (FindNextStreamW_Ptr)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "FindNextStreamW");
+ const HMODULE hm = ::GetModuleHandleA("kernel32.dll");
+ g_FindFirstStreamW = Z7_GET_PROC_ADDRESS(
+ Func_FindFirstStreamW, hm,
+ "FindFirstStreamW");
+ g_FindNextStreamW = Z7_GET_PROC_ADDRESS(
+ Func_FindNextStreamW, hm,
+ "FindNextStreamW");
}
} g_FindStreamLoader;
bool CStreamInfo::IsMainStream() const throw()
{
return StringsAreEqualNoCase_Ascii(Name, "::$DATA");
-};
+}
UString CStreamInfo::GetReducedName() const
{
// remove ":$DATA" postfix, but keep postfix, if Name is "::$DATA"
- UString s = Name;
+ UString s (Name);
if (s.Len() > 6 + 1 && StringsAreEqualNoCase_Ascii(s.RightPtr(6), ":$DATA"))
s.DeleteFrom(s.Len() - 6);
return s;
@@ -245,7 +295,7 @@ UString CStreamInfo::GetReducedName2() const
static void Convert_WIN32_FIND_STREAM_DATA_to_StreamInfo(const MY_WIN32_FIND_STREAM_DATA &sd, CStreamInfo &si)
{
- si.Size = sd.StreamSize.QuadPart;
+ si.Size = (UInt64)sd.StreamSize.QuadPart;
si.Name = sd.cStreamName;
}
@@ -285,7 +335,7 @@ bool CFindStream::FindFirst(CFSTR path, CStreamInfo &si)
if (::GetLastError() == ERROR_HANDLE_EOF)
return false;
// long name can be tricky for path like ".\dirName".
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH)
{
UString superPath;
@@ -336,19 +386,6 @@ bool CStreamEnumerator::Next(CStreamInfo &si, bool &found)
#endif
-#define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0;
-
-void CFileInfoBase::ClearBase() throw()
-{
- Size = 0;
- MY_CLEAR_FILETIME(CTime);
- MY_CLEAR_FILETIME(ATime);
- MY_CLEAR_FILETIME(MTime);
- Attrib = 0;
- IsAltStream = false;
- IsDevice = false;
-}
-
/*
WinXP-64 GetFileAttributes():
If the function fails, it returns INVALID_FILE_ATTRIBUTES and use GetLastError() to get error code
@@ -381,7 +418,7 @@ DWORD GetFileAttrib(CFSTR path)
if (dw != INVALID_FILE_ATTRIBUTES)
return dw;
}
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (USE_SUPER_PATH)
{
UString superPath;
@@ -416,9 +453,23 @@ also we support paths that are not supported by FindFirstFile:
c::stream - Name = c::stream
*/
-bool CFileInfo::Find(CFSTR path)
+bool CFileInfo::Find(CFSTR path, bool followLink)
{
- #ifdef SUPPORT_DEVICE_FILE
+ #ifdef Z7_DEVICE_FILE
+
+ if (IS_PATH_SEPAR(path[0]) &&
+ IS_PATH_SEPAR(path[1]) &&
+ path[2] == '.' &&
+ path[3] == 0)
+ {
+ // 22.00 : it's virtual directory for devices
+ // IsDevice = true;
+ ClearBase();
+ Name = path + 2;
+ Attrib = FILE_ATTRIBUTE_DIRECTORY;
+ return true;
+ }
+
if (IsDevicePath(path))
{
ClearBase();
@@ -449,12 +500,12 @@ bool CFileInfo::Find(CFSTR path)
#if defined(_WIN32) && !defined(UNDER_CE)
- int colonPos = FindAltStreamColon(path);
+ const int colonPos = FindAltStreamColon(path);
if (colonPos >= 0 && path[(unsigned)colonPos + 1] != 0)
{
UString streamName = fs2us(path + (unsigned)colonPos);
- FString filePath = path;
- filePath.DeleteFrom(colonPos);
+ FString filePath (path);
+ filePath.DeleteFrom((unsigned)colonPos);
/* we allow both cases:
name:stream
name:stream:$DATA
@@ -462,12 +513,12 @@ bool CFileInfo::Find(CFSTR path)
const unsigned kPostfixSize = 6;
if (streamName.Len() <= kPostfixSize
|| !StringsAreEqualNoCase_Ascii(streamName.RightPtr(kPostfixSize), ":$DATA"))
- streamName += L":$DATA";
+ streamName += ":$DATA";
bool isOk = true;
if (IsDrivePath2(filePath) &&
- (colonPos == 2 || colonPos == 3 && filePath[2] == '\\'))
+ (colonPos == 2 || (colonPos == 3 && filePath[2] == '\\')))
{
// FindFirstFile doesn't work for "c:\" and for "c:" (if current dir is ROOT)
ClearBase();
@@ -476,11 +527,11 @@ bool CFileInfo::Find(CFSTR path)
Name = filePath;
}
else
- isOk = Find(filePath);
+ isOk = Find(filePath, followLink); // check it (followLink)
if (isOk)
{
- Attrib &= ~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
+ Attrib &= ~(DWORD)(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT);
Size = 0;
CStreamEnumerator enumerator(filePath);
for (;;)
@@ -536,11 +587,15 @@ bool CFileInfo::Find(CFSTR path)
ClearBase();
Attrib = attrib;
Name = path + rootSize;
- Name.DeleteFrom(2); // we don't need backslash (C:)
+ Name.DeleteFrom(2);
+ if (!Fill_From_ByHandleFileInfo(path))
+ {
+ }
return true;
}
}
else if (IS_PATH_SEPAR(path[0]))
+ {
if (path[1] == 0)
{
DWORD attrib = GetFileAttrib(path);
@@ -559,10 +614,15 @@ bool CFileInfo::Find(CFSTR path)
{
if (NName::FindSepar(path + prefixSize) < 0)
{
- FString s = path;
+ if (Fill_From_ByHandleFileInfo(path))
+ {
+ Name = path + prefixSize;
+ return true;
+ }
+
+ FString s (path);
s.Add_PathSepar();
- s += FCHAR_ANY_MASK;
-
+ s += '*'; // CHAR_ANY_MASK
bool isOK = false;
if (finder.FindFirst(s, *this))
{
@@ -577,7 +637,7 @@ bool CFileInfo::Find(CFSTR path)
}
{
DWORD attrib = GetFileAttrib(path);
- if (isOK || attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ if (isOK || (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0))
{
ClearBase();
if (attrib != INVALID_FILE_ATTRIBUTES)
@@ -592,23 +652,105 @@ bool CFileInfo::Find(CFSTR path)
}
}
}
+ }
}
#endif
- return finder.FindFirst(path, *this);
+ bool res = finder.FindFirst(path, *this);
+ if (!followLink
+ || !res
+ || !HasReparsePoint())
+ return res;
+
+ // return FollowReparse(path, IsDir());
+ return Fill_From_ByHandleFileInfo(path);
}
+bool CFileInfoBase::Fill_From_ByHandleFileInfo(CFSTR path)
+{
+ BY_HANDLE_FILE_INFORMATION info;
+ if (!NIO::CFileBase::GetFileInformation(path, &info))
+ return false;
+ {
+ Size = (((UInt64)info.nFileSizeHigh) << 32) + info.nFileSizeLow;
+ CTime = info.ftCreationTime;
+ ATime = info.ftLastAccessTime;
+ MTime = info.ftLastWriteTime;
+ Attrib = info.dwFileAttributes;
+ return true;
+ }
+}
-bool DoesFileExist(CFSTR name)
+/*
+bool CFileInfo::FollowReparse(CFSTR path, bool isDir)
+{
+ if (isDir)
+ {
+ FString prefix = path;
+ prefix.Add_PathSepar();
+
+ // "folder/." refers to folder itself. So we can't use that path
+ // we must use enumerator and search "." item
+ CEnumerator enumerator;
+ enumerator.SetDirPrefix(prefix);
+ for (;;)
+ {
+ CFileInfo fi;
+ if (!enumerator.NextAny(fi))
+ break;
+ if (fi.Name.IsEqualTo_Ascii_NoCase("."))
+ {
+ // we can copy preperies;
+ CTime = fi.CTime;
+ ATime = fi.ATime;
+ MTime = fi.MTime;
+ Attrib = fi.Attrib;
+ Size = fi.Size;
+ return true;
+ }
+ break;
+ }
+ // LastError(lastError);
+ return false;
+ }
+
+ {
+ NIO::CInFile inFile;
+ if (inFile.Open(path))
+ {
+ BY_HANDLE_FILE_INFORMATION info;
+ if (inFile.GetFileInformation(&info))
+ {
+ ClearBase();
+ Size = (((UInt64)info.nFileSizeHigh) << 32) + info.nFileSizeLow;
+ CTime = info.ftCreationTime;
+ ATime = info.ftLastAccessTime;
+ MTime = info.ftLastWriteTime;
+ Attrib = info.dwFileAttributes;
+ return true;
+ }
+ }
+ return false;
+ }
+}
+*/
+
+bool DoesFileExist_Raw(CFSTR name)
{
CFileInfo fi;
return fi.Find(name) && !fi.IsDir();
}
-bool DoesDirExist(CFSTR name)
+bool DoesFileExist_FollowLink(CFSTR name)
+{
+ CFileInfo fi;
+ return fi.Find_FollowLink(name) && !fi.IsDir();
+}
+
+bool DoesDirExist(CFSTR name, bool followLink)
{
CFileInfo fi;
- return fi.Find(name) && fi.IsDir();
+ return fi.Find(name, followLink) && fi.IsDir();
}
bool DoesFileOrDirExist(CFSTR name)
@@ -618,6 +760,12 @@ bool DoesFileOrDirExist(CFSTR name)
}
+void CEnumerator::SetDirPrefix(const FString &dirPrefix)
+{
+ _wildcard = dirPrefix;
+ _wildcard += '*';
+}
+
bool CEnumerator::NextAny(CFileInfo &fi)
{
if (_findFile.IsHandleAllocated())
@@ -639,15 +787,46 @@ bool CEnumerator::Next(CFileInfo &fi)
bool CEnumerator::Next(CFileInfo &fi, bool &found)
{
+ /*
+ for (;;)
+ {
+ if (!NextAny(fi))
+ break;
+ if (!fi.IsDots())
+ {
+ found = true;
+ return true;
+ }
+ }
+ */
+
if (Next(fi))
{
found = true;
return true;
}
+
found = false;
- return (::GetLastError() == ERROR_NO_MORE_FILES);
+ DWORD lastError = ::GetLastError();
+ if (_findFile.IsHandleAllocated())
+ return (lastError == ERROR_NO_MORE_FILES);
+ // we support the case for empty root folder: FindFirstFile("c:\\*") returns ERROR_FILE_NOT_FOUND
+ if (lastError == ERROR_FILE_NOT_FOUND)
+ return true;
+ if (lastError == ERROR_ACCESS_DENIED)
+ {
+ // here we show inaccessible root system folder as empty folder to eliminate redundant user warnings
+ const char *s = "System Volume Information" STRING_PATH_SEPARATOR "*";
+ const int len = (int)strlen(s);
+ const int delta = (int)_wildcard.Len() - len;
+ if (delta == 0 || (delta > 0 && IS_PATH_SEPAR(_wildcard[(unsigned)delta - 1])))
+ if (StringsAreEqual_Ascii(_wildcard.Ptr((unsigned)delta), s))
+ return true;
+ }
+ return false;
}
+
////////////////////////////////
// CFindChangeNotification
// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.
@@ -672,7 +851,7 @@ HANDLE CFindChangeNotification::FindFirst(CFSTR path, bool watchSubtree, DWORD n
{
IF_USE_MAIN_PATH
_handle = ::FindFirstChangeNotificationW(fs2us(path), BoolToBOOL(watchSubtree), notifyFilter);
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (!IsHandleAllocated())
{
UString superPath;
@@ -738,6 +917,413 @@ bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings)
}
}
-#endif
+#endif // UNDER_CE
+
+
+
+#else // _WIN32
+
+// ---------- POSIX ----------
+
+static int MY__lstat(CFSTR path, struct stat *st, bool followLink)
+{
+ memset(st, 0, sizeof(*st));
+ int res;
+ // #ifdef ENV_HAVE_LSTAT
+ if (/* global_use_lstat && */ !followLink)
+ {
+ // printf("\nlstat\n");
+ res = lstat(path, st);
+ }
+ else
+ // #endif
+ {
+ // printf("\nstat\n");
+ res = stat(path, st);
+ }
+ /*
+ printf("\nres = %d\n", res);
+ printf("\n st_dev = %lld \n", (long long)(st->st_dev));
+ printf("\n st_ino = %lld \n", (long long)(st->st_ino));
+ printf("\n st_mode = %lld \n", (long long)(st->st_mode));
+ printf("\n st_nlink = %lld \n", (long long)(st->st_nlink));
+ printf("\n st_uid = %lld \n", (long long)(st->st_uid));
+ printf("\n st_gid = %lld \n", (long long)(st->st_gid));
+ printf("\n st_size = %lld \n", (long long)(st->st_size));
+ printf("\n st_blksize = %lld \n", (long long)(st->st_blksize));
+ printf("\n st_blocks = %lld \n", (long long)(st->st_blocks));
+ */
+
+ return res;
+}
+
+
+static const char *Get_Name_from_Path(CFSTR path) throw()
+{
+ size_t len = strlen(path);
+ if (len == 0)
+ return path;
+ const char *p = path + len - 1;
+ {
+ if (p == path)
+ return path;
+ p--;
+ }
+ for (;;)
+ {
+ char c = *p;
+ if (IS_PATH_SEPAR(c))
+ return p + 1;
+ if (p == path)
+ return path;
+ p--;
+ }
+}
+
+
+UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode)
+{
+ UInt32 attrib = S_ISDIR(mode) ?
+ FILE_ATTRIBUTE_DIRECTORY :
+ FILE_ATTRIBUTE_ARCHIVE;
+ if ((mode & 0222) == 0) // S_IWUSR in p7zip
+ attrib |= FILE_ATTRIBUTE_READONLY;
+ return attrib | FILE_ATTRIBUTE_UNIX_EXTENSION | ((mode & 0xFFFF) << 16);
+}
+
+/*
+UInt32 Get_WinAttrib_From_stat(const struct stat &st)
+{
+ UInt32 attrib = S_ISDIR(st.st_mode) ?
+ FILE_ATTRIBUTE_DIRECTORY :
+ FILE_ATTRIBUTE_ARCHIVE;
+
+ if ((st.st_mode & 0222) == 0) // check it !!!
+ attrib |= FILE_ATTRIBUTE_READONLY;
+
+ attrib |= FILE_ATTRIBUTE_UNIX_EXTENSION + ((st.st_mode & 0xFFFF) << 16);
+ return attrib;
+}
+*/
+
+void CFileInfo::SetFrom_stat(const struct stat &st)
+{
+ // IsDevice = false;
+
+ if (S_ISDIR(st.st_mode))
+ {
+ Size = 0;
+ }
+ else
+ {
+ Size = (UInt64)st.st_size; // for a symbolic link, size = size of filename
+ }
+
+ // Attrib = Get_WinAttribPosix_From_PosixMode(st.st_mode);
+
+ // NTime::UnixTimeToFileTime(st.st_ctime, CTime);
+ // NTime::UnixTimeToFileTime(st.st_mtime, MTime);
+ // NTime::UnixTimeToFileTime(st.st_atime, ATime);
+ #ifdef __APPLE__
+ // #ifdef _DARWIN_FEATURE_64_BIT_INODE
+ /*
+ here we can use birthtime instead of st_ctimespec.
+ but we use st_ctimespec for compatibility with previous versions and p7zip.
+ st_birthtimespec in OSX
+ st_birthtim : at FreeBSD, NetBSD
+ */
+ // timespec_To_FILETIME(st.st_birthtimespec, CTime);
+ // #else
+ // timespec_To_FILETIME(st.st_ctimespec, CTime);
+ // #endif
+ // timespec_To_FILETIME(st.st_mtimespec, MTime);
+ // timespec_To_FILETIME(st.st_atimespec, ATime);
+ CTime = st.st_ctimespec;
+ MTime = st.st_mtimespec;
+ ATime = st.st_atimespec;
+
+ #else
+ // timespec_To_FILETIME(st.st_ctim, CTime, &CTime_ns100);
+ // timespec_To_FILETIME(st.st_mtim, MTime, &MTime_ns100);
+ // timespec_To_FILETIME(st.st_atim, ATime, &ATime_ns100);
+ CTime = st.st_ctim;
+ MTime = st.st_mtim;
+ ATime = st.st_atim;
+
+ #endif
+
+ dev = st.st_dev;
+ ino = st.st_ino;
+ mode = st.st_mode;
+ nlink = st.st_nlink;
+ uid = st.st_uid;
+ gid = st.st_gid;
+ rdev = st.st_rdev;
+
+ /*
+ printf("\n sizeof timespec = %d", (int)sizeof(timespec));
+ printf("\n sizeof st_rdev = %d", (int)sizeof(rdev));
+ printf("\n sizeof st_ino = %d", (int)sizeof(ino));
+ printf("\n sizeof mode_t = %d", (int)sizeof(mode_t));
+ printf("\n sizeof nlink_t = %d", (int)sizeof(nlink_t));
+ printf("\n sizeof uid_t = %d", (int)sizeof(uid_t));
+ printf("\n");
+ */
+ /*
+ printf("\n st_rdev = %llx", (long long)rdev);
+ printf("\n st_dev = %llx", (long long)dev);
+ printf("\n dev : major = %5x minor = %5x", (unsigned)major(dev), (unsigned)minor(dev));
+ printf("\n st_ino = %lld", (long long)(ino));
+ printf("\n rdev : major = %5x minor = %5x", (unsigned)major(rdev), (unsigned)minor(rdev));
+ printf("\n size = %lld \n", (long long)(Size));
+ printf("\n");
+ */
+}
+
+/*
+int Uid_To_Uname(uid_t uid, AString &name)
+{
+ name.Empty();
+ struct passwd *passwd;
+
+ if (uid != 0 && uid == cached_no_such_uid)
+ {
+ *uname = xstrdup ("");
+ return;
+ }
+
+ if (!cached_uname || uid != cached_uid)
+ {
+ passwd = getpwuid (uid);
+ if (passwd)
+ {
+ cached_uid = uid;
+ assign_string (&cached_uname, passwd->pw_name);
+ }
+ else
+ {
+ cached_no_such_uid = uid;
+ *uname = xstrdup ("");
+ return;
+ }
+ }
+ *uname = xstrdup (cached_uname);
+}
+*/
+
+bool CFileInfo::Find_DontFill_Name(CFSTR path, bool followLink)
+{
+ struct stat st;
+ if (MY__lstat(path, &st, followLink) != 0)
+ return false;
+ // printf("\nFind_DontFill_Name : name=%s\n", path);
+ SetFrom_stat(st);
+ return true;
+}
+
+
+bool CFileInfo::Find(CFSTR path, bool followLink)
+{
+ // printf("\nCEnumerator::Find() name = %s\n", path);
+ if (!Find_DontFill_Name(path, followLink))
+ return false;
+
+ // printf("\nOK\n");
+
+ Name = Get_Name_from_Path(path);
+ if (!Name.IsEmpty())
+ {
+ char c = Name.Back();
+ if (IS_PATH_SEPAR(c))
+ Name.DeleteBack();
+ }
+ return true;
+}
+
+
+bool DoesFileExist_Raw(CFSTR name)
+{
+ // FIXME for symbolic links.
+ struct stat st;
+ if (MY__lstat(name, &st, false) != 0)
+ return false;
+ return !S_ISDIR(st.st_mode);
+}
+
+bool DoesFileExist_FollowLink(CFSTR name)
+{
+ // FIXME for symbolic links.
+ struct stat st;
+ if (MY__lstat(name, &st, true) != 0)
+ return false;
+ return !S_ISDIR(st.st_mode);
+}
+
+bool DoesDirExist(CFSTR name, bool followLink)
+{
+ struct stat st;
+ if (MY__lstat(name, &st, followLink) != 0)
+ return false;
+ return S_ISDIR(st.st_mode);
+}
+
+bool DoesFileOrDirExist(CFSTR name)
+{
+ struct stat st;
+ if (MY__lstat(name, &st, false) != 0)
+ return false;
+ return true;
+}
+
+
+CEnumerator::~CEnumerator()
+{
+ if (_dir)
+ closedir(_dir);
+}
+
+void CEnumerator::SetDirPrefix(const FString &dirPrefix)
+{
+ _wildcard = dirPrefix;
+}
+
+bool CDirEntry::IsDots() const throw()
+{
+ /* some systems (like CentOS 7.x on XFS) have (Type == DT_UNKNOWN)
+ we can call fstatat() for that case, but we use only (Name) check here */
+
+ #if !defined(_AIX)
+ if (Type != DT_DIR && Type != DT_UNKNOWN)
+ return false;
+ #endif
+
+ return Name.Len() != 0
+ && Name.Len() <= 2
+ && Name[0] == '.'
+ && (Name.Len() == 1 || Name[1] == '.');
+}
+
+
+bool CEnumerator::NextAny(CDirEntry &fi, bool &found)
+{
+ found = false;
+
+ if (!_dir)
+ {
+ const char *w = "./";
+ if (!_wildcard.IsEmpty())
+ w = _wildcard.Ptr();
+ _dir = ::opendir((const char *)w);
+ if (_dir == NULL)
+ return false;
+ }
+
+ // To distinguish end of stream from an error, we must set errno to zero before readdir()
+ errno = 0;
+
+ struct dirent *de = readdir(_dir);
+ if (!de)
+ {
+ if (errno == 0)
+ return true; // it's end of stream, and we report it with (found = false)
+ // it's real error
+ return false;
+ }
+
+ fi.iNode = de->d_ino;
+
+ #if !defined(_AIX)
+ fi.Type = de->d_type;
+ /* some systems (like CentOS 7.x on XFS) have (Type == DT_UNKNOWN)
+ we can set (Type) from fstatat() in that case.
+ But (Type) is not too important. So we don't set it here with slow fstatat() */
+ /*
+ // fi.Type = DT_UNKNOWN; // for debug
+ if (fi.Type == DT_UNKNOWN)
+ {
+ struct stat st;
+ if (fstatat(dirfd(_dir), de->d_name, &st, AT_SYMLINK_NOFOLLOW) == 0)
+ if (S_ISDIR(st.st_mode))
+ fi.Type = DT_DIR;
+ }
+ */
+ #endif
+
+ /*
+ if (de->d_type == DT_DIR)
+ fi.Attrib = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_UNIX_EXTENSION | ((UInt32)(S_IFDIR) << 16);
+ else if (de->d_type < 16)
+ fi.Attrib = FILE_ATTRIBUTE_UNIX_EXTENSION | ((UInt32)(de->d_type) << (16 + 12));
+ */
+ fi.Name = de->d_name;
+
+ /*
+ printf("\nCEnumerator::NextAny; len = %d %s \n", (int)fi.Name.Len(), fi.Name.Ptr());
+ for (unsigned i = 0; i < fi.Name.Len(); i++)
+ printf (" %02x", (unsigned)(Byte)de->d_name[i]);
+ printf("\n");
+ */
+
+ found = true;
+ return true;
+}
+
+
+bool CEnumerator::Next(CDirEntry &fi, bool &found)
+{
+ // printf("\nCEnumerator::Next()\n");
+ // PrintName("Next", "");
+ for (;;)
+ {
+ if (!NextAny(fi, found))
+ return false;
+ if (!found)
+ return true;
+ if (!fi.IsDots())
+ {
+ /*
+ if (!NeedFullStat)
+ return true;
+ // we silently skip error file here - it can be wrong link item
+ if (fi.Find_DontFill_Name(path))
+ return true;
+ */
+ return true;
+ }
+ }
+}
+
+/*
+bool CEnumerator::Next(CDirEntry &fileInfo, bool &found)
+{
+ bool found;
+ if (!Next(fi, found))
+ return false;
+ return found;
+}
+*/
+
+bool CEnumerator::Fill_FileInfo(const CDirEntry &de, CFileInfo &fileInfo, bool followLink) const
+{
+ // printf("\nCEnumerator::Fill_FileInfo()\n");
+ struct stat st;
+ // probably it's OK to use fstatat() even if it changes file position dirfd(_dir)
+ int res = fstatat(dirfd(_dir), de.Name, &st, followLink ? 0 : AT_SYMLINK_NOFOLLOW);
+ // if fstatat() is not supported, we can use stat() / lstat()
+
+ /*
+ const FString path = _wildcard + s;
+ int res = MY__lstat(path, &st, followLink);
+ */
+
+ if (res != 0)
+ return false;
+ // printf("\nname=%s\n", de.Name.Ptr());
+ fileInfo.SetFrom_stat(st);
+ fileInfo.Name = de.Name;
+ return true;
+}
+
+#endif // _WIN32
}}}
diff --git a/3rdparty/lzma/CPP/Windows/FileFind.h b/3rdparty/lzma/CPP/Windows/FileFind.h
index 615c2dfe24c..11408d05958 100644
--- a/3rdparty/lzma/CPP/Windows/FileFind.h
+++ b/3rdparty/lzma/CPP/Windows/FileFind.h
@@ -1,15 +1,43 @@
// Windows/FileFind.h
-#ifndef __WINDOWS_FILE_FIND_H
-#define __WINDOWS_FILE_FIND_H
+#ifndef ZIP7_INC_WINDOWS_FILE_FIND_H
+#define ZIP7_INC_WINDOWS_FILE_FIND_H
+#ifndef _WIN32
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#endif
+
+#include "../Common/MyLinux.h"
#include "../Common/MyString.h"
+#include "../Common/MyWindows.h"
+
#include "Defs.h"
+#include "FileIO.h"
+
namespace NWindows {
namespace NFile {
namespace NFind {
+// bool DoesFileExist(CFSTR name, bool followLink);
+bool DoesFileExist_Raw(CFSTR name);
+bool DoesFileExist_FollowLink(CFSTR name);
+bool DoesDirExist(CFSTR name, bool followLink);
+
+inline bool DoesDirExist(CFSTR name)
+ { return DoesDirExist(name, false); }
+inline bool DoesDirExist_FollowLink(CFSTR name)
+ { return DoesDirExist(name, true); }
+
+// it's always _Raw
+bool DoesFileOrDirExist(CFSTR name);
+
+DWORD GetFileAttrib(CFSTR path);
+
+#ifdef _WIN32
+
namespace NAttributes
{
inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }
@@ -19,16 +47,34 @@ namespace NAttributes
inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
+
+ inline UInt32 Get_PosixMode_From_WinAttrib(DWORD attrib)
+ {
+ UInt32 v = IsDir(attrib) ? MY_LIN_S_IFDIR : MY_LIN_S_IFREG;
+ /* 21.06: as WSL we allow write permissions (0222) for directories even for (FILE_ATTRIBUTE_READONLY).
+ So extracting at Linux will be allowed to write files inside (0777) directories. */
+ v |= ((IsReadOnly(attrib) && !IsDir(attrib)) ? 0555 : 0777);
+ return v;
+ }
}
+#else
+
+UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode);
+
+#endif
+
class CFileInfoBase
{
+ #ifdef _WIN32
bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
+ #endif
public:
UInt64 Size;
- FILETIME CTime;
- FILETIME ATime;
- FILETIME MTime;
+ CFiTime CTime;
+ CFiTime ATime;
+ CFiTime MTime;
+ #ifdef _WIN32
DWORD Attrib;
bool IsAltStream;
bool IsDevice;
@@ -40,11 +86,25 @@ public:
UINT32 ReparseTag;
#endif
*/
+ #else
+ dev_t dev; /* ID of device containing file */
+ ino_t ino;
+ mode_t mode;
+ nlink_t nlink;
+ uid_t uid; /* user ID of owner */
+ gid_t gid; /* group ID of owner */
+ dev_t rdev; /* device ID (defined, if S_ISCHR(mode) || S_ISBLK(mode)) */
+ // bool Use_lstat;
+ #endif
CFileInfoBase() { ClearBase(); }
void ClearBase() throw();
- void SetAsDir() { Attrib = FILE_ATTRIBUTE_DIRECTORY; }
+ #ifdef _WIN32
+
+ bool Fill_From_ByHandleFileInfo(CFSTR path);
+ void SetAsDir() { Attrib = FILE_ATTRIBUTE_DIRECTORY; } // |= (FILE_ATTRIBUTE_UNIX_EXTENSION + (S_IFDIR << 16));
+ void SetAsFile() { Attrib = 0; }
bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
@@ -58,6 +118,43 @@ public:
bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
+
+ UInt32 GetWinAttrib() const { return Attrib; }
+ UInt32 GetPosixAttrib() const
+ {
+ return NAttributes::Get_PosixMode_From_WinAttrib(Attrib);
+ }
+ bool Has_Attrib_ReparsePoint() const { return (Attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0; }
+
+ #else
+
+ UInt32 GetPosixAttrib() const { return mode; }
+ UInt32 GetWinAttrib() const { return Get_WinAttribPosix_From_PosixMode(mode); }
+
+ bool IsDir() const { return S_ISDIR(mode); }
+ void SetAsDir() { mode = S_IFDIR; }
+ void SetAsFile() { mode = S_IFREG; }
+
+ bool IsReadOnly() const
+ {
+ // does linux support writing to ReadOnly files?
+ if ((mode & 0222) == 0) // S_IWUSR in p7zip
+ return true;
+ return false;
+ }
+
+ bool IsPosixLink() const { return S_ISLNK(mode); }
+
+ #endif
+
+ bool IsOsSymLink() const
+ {
+ #ifdef _WIN32
+ return HasReparsePoint();
+ #else
+ return IsPosixLink();
+ #endif
+ }
};
struct CFileInfo: public CFileInfoBase
@@ -68,10 +165,22 @@ struct CFileInfo: public CFileInfoBase
#endif
bool IsDots() const throw();
- bool Find(CFSTR path);
+ bool Find(CFSTR path, bool followLink = false);
+ bool Find_FollowLink(CFSTR path) { return Find(path, true); }
+
+ #ifdef _WIN32
+ // bool Fill_From_ByHandleFileInfo(CFSTR path);
+ // bool FollowReparse(CFSTR path, bool isDir);
+ #else
+ bool Find_DontFill_Name(CFSTR path, bool followLink = false);
+ void SetFrom_stat(const struct stat &st);
+ #endif
};
-class CFindFileBase
+
+#ifdef _WIN32
+
+class CFindFileBase MY_UNCOPYABLE
{
protected:
HANDLE _handle;
@@ -108,43 +217,47 @@ public:
bool FindNext(CStreamInfo &streamInfo);
};
-class CStreamEnumerator
+class CStreamEnumerator MY_UNCOPYABLE
{
CFindStream _find;
FString _filePath;
- bool NextAny(CFileInfo &fileInfo);
+ bool NextAny(CFileInfo &fileInfo, bool &found);
public:
CStreamEnumerator(const FString &filePath): _filePath(filePath) {}
bool Next(CStreamInfo &streamInfo, bool &found);
};
-#endif
-
-bool DoesFileExist(CFSTR name);
-bool DoesDirExist(CFSTR name);
-bool DoesFileOrDirExist(CFSTR name);
+#endif // defined(_WIN32) && !defined(UNDER_CE)
-DWORD GetFileAttrib(CFSTR path);
-class CEnumerator
+class CEnumerator MY_UNCOPYABLE
{
CFindFile _findFile;
FString _wildcard;
bool NextAny(CFileInfo &fileInfo);
public:
- CEnumerator(const FString &wildcard): _wildcard(wildcard) {}
+ void SetDirPrefix(const FString &dirPrefix);
bool Next(CFileInfo &fileInfo);
bool Next(CFileInfo &fileInfo, bool &found);
};
-class CFindChangeNotification
+
+class CFindChangeNotification MY_UNCOPYABLE
{
HANDLE _handle;
public:
operator HANDLE () { return _handle; }
- bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
+ bool IsHandleAllocated() const
+ {
+ /* at least on win2000/XP (undocumented):
+ if pathName is "" or NULL,
+ FindFirstChangeNotification() could return NULL.
+ So we check for INVALID_HANDLE_VALUE and NULL.
+ */
+ return _handle != INVALID_HANDLE_VALUE && _handle != NULL;
+ }
CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
~CFindChangeNotification() { Close(); }
bool Close() throw();
@@ -156,6 +269,80 @@ public:
bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings);
#endif
+typedef CFileInfo CDirEntry;
+
+
+#else // WIN32
+
+
+struct CDirEntry
+{
+ ino_t iNode;
+ #if !defined(_AIX)
+ Byte Type;
+ #endif
+ FString Name;
+
+ /*
+ #if !defined(_AIX)
+ bool IsDir() const
+ {
+ // (Type == DT_UNKNOWN) on some systems
+ return Type == DT_DIR;
+ }
+ #endif
+ */
+
+ bool IsDots() const throw();
+};
+
+class CEnumerator MY_UNCOPYABLE
+{
+ DIR *_dir;
+ FString _wildcard;
+
+ bool NextAny(CDirEntry &fileInfo, bool &found);
+public:
+ CEnumerator(): _dir(NULL) {}
+ ~CEnumerator();
+ void SetDirPrefix(const FString &dirPrefix);
+
+ bool Next(CDirEntry &fileInfo, bool &found);
+ bool Fill_FileInfo(const CDirEntry &de, CFileInfo &fileInfo, bool followLink) const;
+ bool DirEntry_IsDir(const CDirEntry &de, bool followLink) const
+ {
+ #if !defined(_AIX)
+ if (de.Type == DT_DIR)
+ return true;
+ if (de.Type != DT_UNKNOWN)
+ return false;
+ #endif
+ CFileInfo fileInfo;
+ if (Fill_FileInfo(de, fileInfo, followLink))
+ {
+ return fileInfo.IsDir();
+ }
+ return false; // change it
+ }
+};
+
+/*
+inline UInt32 Get_WinAttrib_From_PosixMode(UInt32 mode)
+{
+ UInt32 attrib = S_ISDIR(mode) ?
+ FILE_ATTRIBUTE_DIRECTORY :
+ FILE_ATTRIBUTE_ARCHIVE;
+ if ((st.st_mode & 0222) == 0) // check it !!!
+ attrib |= FILE_ATTRIBUTE_READONLY;
+ return attrib;
+}
+*/
+
+// UInt32 Get_WinAttrib_From_stat(const struct stat &st);
+
+
+#endif // WIN32
+
}}}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/FileIO.cpp b/3rdparty/lzma/CPP/Windows/FileIO.cpp
index 56e6ca45796..4ecbb7ed213 100644
--- a/3rdparty/lzma/CPP/Windows/FileIO.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileIO.cpp
@@ -2,13 +2,33 @@
#include "StdAfx.h"
-#ifdef SUPPORT_DEVICE_FILE
+#ifdef Z7_DEVICE_FILE
#include "../../C/Alloc.h"
#endif
+// #include <stdio.h>
+
+/*
+#ifndef _WIN32
+// for ioctl BLKGETSIZE64
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#endif
+*/
+
#include "FileIO.h"
#include "FileName.h"
+HRESULT GetLastError_noZero_HRESULT()
+{
+ const DWORD res = ::GetLastError();
+ if (res == 0)
+ return E_FAIL;
+ return HRESULT_FROM_WIN32(res);
+}
+
+#ifdef _WIN32
+
#ifndef _UNICODE
extern bool g_IsNT;
#endif
@@ -20,7 +40,7 @@ using namespace NName;
namespace NWindows {
namespace NFile {
-#ifdef SUPPORT_DEVICE_FILE
+#ifdef Z7_DEVICE_FILE
namespace NSystem
{
@@ -52,7 +72,7 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess,
if (!Close())
return false;
- #ifdef SUPPORT_DEVICE_FILE
+ #ifdef Z7_DEVICE_FILE
IsDeviceFile = false;
#endif
@@ -68,7 +88,7 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess,
IF_USE_MAIN_PATH
_handle = ::CreateFileW(fs2us(path), desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL);
- #ifdef WIN_LONG_PATH
+ #ifdef Z7_LONG_PATH
if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH)
{
UString superPath;
@@ -78,6 +98,42 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess,
}
#endif
}
+
+ /*
+ #ifndef UNDER_CE
+ #ifndef Z7_SFX
+ if (_handle == INVALID_HANDLE_VALUE)
+ {
+ // it's debug hack to open symbolic links in Windows XP and WSL links in Windows 10
+ DWORD lastError = GetLastError();
+ if (lastError == ERROR_CANT_ACCESS_FILE)
+ {
+ CByteBuffer buf;
+ if (NIO::GetReparseData(path, buf, NULL))
+ {
+ CReparseAttr attr;
+ if (attr.Parse(buf, buf.Size()))
+ {
+ FString dirPrefix, fileName;
+ if (NDir::GetFullPathAndSplit(path, dirPrefix, fileName))
+ {
+ FString fullPath;
+ if (GetFullPath(dirPrefix, us2fs(attr.GetPath()), fullPath))
+ {
+ // FIX IT: recursion levels must be restricted
+ return Create(fullPath, desiredAccess,
+ shareMode, creationDisposition, flagsAndAttributes);
+ }
+ }
+ }
+ }
+ SetLastError(lastError);
+ }
+ }
+ #endif
+ #endif
+ */
+
return (_handle != INVALID_HANDLE_VALUE);
}
@@ -91,14 +147,9 @@ bool CFileBase::Close() throw()
return true;
}
-bool CFileBase::GetPosition(UInt64 &position) const throw()
-{
- return Seek(0, FILE_CURRENT, position);
-}
-
bool CFileBase::GetLength(UInt64 &length) const throw()
{
- #ifdef SUPPORT_DEVICE_FILE
+ #ifdef Z7_DEVICE_FILE
if (IsDeviceFile && SizeDefined)
{
length = Size;
@@ -106,18 +157,69 @@ bool CFileBase::GetLength(UInt64 &length) const throw()
}
#endif
- DWORD sizeHigh;
- DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);
- if (sizeLow == 0xFFFFFFFF)
+ DWORD high = 0;
+ const DWORD low = ::GetFileSize(_handle, &high);
+ if (low == INVALID_FILE_SIZE)
if (::GetLastError() != NO_ERROR)
return false;
- length = (((UInt64)sizeHigh) << 32) + sizeLow;
+ length = (((UInt64)high) << 32) + low;
+ return true;
+
+ /*
+ LARGE_INTEGER fileSize;
+ // GetFileSizeEx() is unsupported in 98/ME/NT, and supported in Win2000+
+ if (!GetFileSizeEx(_handle, &fileSize))
+ return false;
+ length = (UInt64)fileSize.QuadPart;
return true;
+ */
+}
+
+
+/* Specification for SetFilePointer():
+
+ If a new file pointer is a negative value,
+ {
+ the function fails,
+ the file pointer is not moved,
+ the code returned by GetLastError() is ERROR_NEGATIVE_SEEK.
+ }
+
+ If the hFile handle is opened with the FILE_FLAG_NO_BUFFERING flag set
+ {
+ an application can move the file pointer only to sector-aligned positions.
+ A sector-aligned position is a position that is a whole number multiple of
+ the volume sector size.
+ An application can obtain a volume sector size by calling the GetDiskFreeSpace.
+ }
+
+ It is not an error to set a file pointer to a position beyond the end of the file.
+ The size of the file does not increase until you call the SetEndOfFile, WriteFile, or WriteFileEx function.
+
+ If the return value is INVALID_SET_FILE_POINTER and if lpDistanceToMoveHigh is non-NULL,
+ an application must call GetLastError to determine whether or not the function has succeeded or failed.
+*/
+
+bool CFileBase::GetPosition(UInt64 &position) const throw()
+{
+ LONG high = 0;
+ const DWORD low = ::SetFilePointer(_handle, 0, &high, FILE_CURRENT);
+ if (low == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
+ {
+ // for error case we can set (position) to (-1) or (0) or leave (position) unchanged.
+ // position = (UInt64)(Int64)-1; // for debug
+ position = 0;
+ return false;
+ }
+ position = (((UInt64)(UInt32)high) << 32) + low;
+ return true;
+ // we don't want recursed GetPosition()
+ // return Seek(0, FILE_CURRENT, position);
}
bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const throw()
{
- #ifdef SUPPORT_DEVICE_FILE
+ #ifdef Z7_DEVICE_FILE
if (IsDeviceFile && SizeDefined && moveMethod == FILE_END)
{
distanceToMove += Size;
@@ -126,23 +228,31 @@ bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition
#endif
LONG high = (LONG)(distanceToMove >> 32);
- DWORD low = ::SetFilePointer(_handle, (LONG)(distanceToMove & 0xFFFFFFFF), &high, moveMethod);
- if (low == 0xFFFFFFFF)
- if (::GetLastError() != NO_ERROR)
+ const DWORD low = ::SetFilePointer(_handle, (LONG)(distanceToMove & 0xFFFFFFFF), &high, moveMethod);
+ if (low == INVALID_SET_FILE_POINTER)
+ {
+ const DWORD lastError = ::GetLastError();
+ if (lastError != NO_ERROR)
+ {
+ // 21.07: we set (newPosition) to real position even after error.
+ GetPosition(newPosition);
+ SetLastError(lastError); // restore LastError
return false;
+ }
+ }
newPosition = (((UInt64)(UInt32)high) << 32) + low;
return true;
}
bool CFileBase::Seek(UInt64 position, UInt64 &newPosition) const throw()
{
- return Seek(position, FILE_BEGIN, newPosition);
+ return Seek((Int64)position, FILE_BEGIN, newPosition);
}
bool CFileBase::SeekToBegin() const throw()
{
- UInt64 newPosition;
- return Seek(0, newPosition);
+ UInt64 newPosition = 0;
+ return Seek(0, newPosition) && (newPosition == 0);
}
bool CFileBase::SeekToEnd(UInt64 &newPosition) const throw()
@@ -152,12 +262,12 @@ bool CFileBase::SeekToEnd(UInt64 &newPosition) const throw()
// ---------- CInFile ---------
-#ifdef SUPPORT_DEVICE_FILE
+#ifdef Z7_DEVICE_FILE
void CInFile::CorrectDeviceSize()
{
// maybe we must decrease kClusterSize to 1 << 12, if we want correct size at tail
- static const UInt32 kClusterSize = 1 << 14;
+ const UInt32 kClusterSize = 1 << 14;
UInt64 pos = Size & ~(UInt64)(kClusterSize - 1);
UInt64 realNewPosition;
if (!Seek(pos, realNewPosition))
@@ -258,7 +368,7 @@ void CInFile::CalcDeviceSize(CFSTR s)
if (GetPartitionInfo(&partInfo))
{
- Size = partInfo.PartitionLength.QuadPart;
+ Size = (UInt64)partInfo.PartitionLength.QuadPart;
SizeDefined = true;
needCorrectSize = false;
if ((s)[0] == '\\' && (s)[1] == '\\' && (s)[2] == '.' && (s)[3] == '\\' && (s)[5] == ':' && (s)[6] == 0)
@@ -277,7 +387,7 @@ void CInFile::CalcDeviceSize(CFSTR s)
my_DISK_GEOMETRY_EX geomEx;
SizeDefined = GetGeometryEx(&geomEx);
if (SizeDefined)
- Size = geomEx.DiskSize.QuadPart;
+ Size = (UInt64)geomEx.DiskSize.QuadPart;
else
{
DISK_GEOMETRY geom;
@@ -285,7 +395,7 @@ void CInFile::CalcDeviceSize(CFSTR s)
if (!SizeDefined)
SizeDefined = GetCdRomGeometry(&geom);
if (SizeDefined)
- Size = geom.Cylinders.QuadPart * geom.TracksPerCylinder * geom.SectorsPerTrack * geom.BytesPerSector;
+ Size = (UInt64)geom.Cylinders.QuadPart * geom.TracksPerCylinder * geom.SectorsPerTrack * geom.BytesPerSector;
}
}
@@ -310,7 +420,24 @@ void CInFile::CalcDeviceSize(CFSTR s)
bool CInFile::Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{
- bool res = Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes);
+ DWORD desiredAccess = GENERIC_READ;
+
+ #ifdef _WIN32
+ if (PreserveATime)
+ desiredAccess |= FILE_WRITE_ATTRIBUTES;
+ #endif
+
+ bool res = Create(fileName, desiredAccess, shareMode, creationDisposition, flagsAndAttributes);
+
+ #ifdef _WIN32
+ if (res && PreserveATime)
+ {
+ FILETIME ft;
+ ft.dwHighDateTime = ft.dwLowDateTime = 0xFFFFFFFF;
+ ::SetFileTime(_handle, NULL, &ft, NULL);
+ }
+ #endif
+
MY_DEVICE_EXTRA_CODE
return res;
}
@@ -330,12 +457,12 @@ bool CInFile::Open(CFSTR fileName)
// for 32 MB (maybe also for 16 MB).
// And message can be "Network connection was lost"
-static UInt32 kChunkSizeMax = (1 << 22);
+static const UInt32 kChunkSizeMax = (1 << 22);
bool CInFile::Read1(void *data, UInt32 size, UInt32 &processedSize) throw()
{
DWORD processedLoc = 0;
- bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));
+ const bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));
processedSize = (UInt32)processedLoc;
return res;
}
@@ -353,7 +480,27 @@ bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize) throw()
do
{
UInt32 processedLoc = 0;
- bool res = ReadPart(data, size, processedLoc);
+ const bool res = ReadPart(data, size, processedLoc);
+ processedSize += processedLoc;
+ if (!res)
+ return false;
+ if (processedLoc == 0)
+ return true;
+ data = (void *)((unsigned char *)data + processedLoc);
+ size -= processedLoc;
+ }
+ while (size > 0);
+ return true;
+}
+
+bool CInFile::ReadFull(void *data, size_t size, size_t &processedSize) throw()
+{
+ processedSize = 0;
+ do
+ {
+ UInt32 processedLoc = 0;
+ const UInt32 sizeLoc = (size > kChunkSizeMax ? (UInt32)kChunkSizeMax : (UInt32)size);
+ const bool res = Read1(data, sizeLoc, processedLoc);
processedSize += processedLoc;
if (!res)
return false;
@@ -404,7 +551,7 @@ bool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize) throw
do
{
UInt32 processedLoc = 0;
- bool res = WritePart(data, size, processedLoc);
+ const bool res = WritePart(data, size, processedLoc);
processedSize += processedLoc;
if (!res)
return false;
@@ -413,7 +560,24 @@ bool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize) throw
data = (const void *)((const unsigned char *)data + processedLoc);
size -= processedLoc;
}
- while (size > 0);
+ while (size != 0);
+ return true;
+}
+
+bool COutFile::WriteFull(const void *data, size_t size) throw()
+{
+ do
+ {
+ UInt32 processedLoc = 0;
+ const UInt32 sizeCur = (size > kChunkSizeMax ? kChunkSizeMax : (UInt32)size);
+ if (!WritePart(data, sizeCur, processedLoc))
+ return false;
+ if (processedLoc == 0)
+ return (size == 0);
+ data = (const void *)((const unsigned char *)data + processedLoc);
+ size -= processedLoc;
+ }
+ while (size != 0);
return true;
}
@@ -429,4 +593,313 @@ bool COutFile::SetLength(UInt64 length) throw()
return SetEndOfFile();
}
+bool COutFile::SetLength_KeepPosition(UInt64 length) throw()
+{
+ UInt64 currentPos = 0;
+ if (!GetPosition(currentPos))
+ return false;
+ DWORD lastError = 0;
+ const bool result = SetLength(length);
+ if (!result)
+ lastError = GetLastError();
+ UInt64 currentPos2;
+ const bool result2 = Seek(currentPos, currentPos2);
+ if (lastError != 0)
+ SetLastError(lastError);
+ return (result && result2);
+}
+
}}}
+
+#else // _WIN32
+
+
+// POSIX
+
+#include <fcntl.h>
+#include <unistd.h>
+
+namespace NWindows {
+namespace NFile {
+
+namespace NDir {
+bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime);
+}
+
+namespace NIO {
+
+bool CFileBase::OpenBinary(const char *name, int flags, mode_t mode)
+{
+ #ifdef O_BINARY
+ flags |= O_BINARY;
+ #endif
+
+ Close();
+ _handle = ::open(name, flags, mode);
+ return _handle != -1;
+
+ /*
+ if (_handle == -1)
+ return false;
+ if (IsString1PrefixedByString2(name, "/dev/"))
+ {
+ // /dev/sda
+ // IsDeviceFile = true; // for debug
+ // SizeDefined = false;
+ // SizeDefined = (GetDeviceSize_InBytes(Size) == 0);
+ }
+ return true;
+ */
+}
+
+bool CFileBase::Close()
+{
+ if (_handle == -1)
+ return true;
+ if (close(_handle) != 0)
+ return false;
+ _handle = -1;
+ /*
+ IsDeviceFile = false;
+ SizeDefined = false;
+ */
+ return true;
+}
+
+bool CFileBase::GetLength(UInt64 &length) const
+{
+ length = 0;
+ // length = (UInt64)(Int64)-1; // for debug
+ const off_t curPos = seekToCur();
+ if (curPos == -1)
+ return false;
+ const off_t lengthTemp = seek(0, SEEK_END);
+ seek(curPos, SEEK_SET);
+ length = (UInt64)lengthTemp;
+
+ /*
+ // 22.00:
+ if (lengthTemp == 1)
+ if (IsDeviceFile && SizeDefined)
+ {
+ length = Size;
+ return true;
+ }
+ */
+
+ return (lengthTemp != -1);
+}
+
+off_t CFileBase::seek(off_t distanceToMove, int moveMethod) const
+{
+ /*
+ if (IsDeviceFile && SizeDefined && moveMethod == SEEK_END)
+ {
+ printf("\n seek : IsDeviceFile moveMethod = %d distanceToMove = %ld\n", moveMethod, distanceToMove);
+ distanceToMove += Size;
+ moveMethod = SEEK_SET;
+ }
+ */
+
+ // printf("\nCFileBase::seek() moveMethod = %d, distanceToMove = %lld", moveMethod, (long long)distanceToMove);
+ // off_t res = ::lseek(_handle, distanceToMove, moveMethod);
+ // printf("\n lseek : moveMethod = %d distanceToMove = %ld\n", moveMethod, distanceToMove);
+ return ::lseek(_handle, distanceToMove, moveMethod);
+ // return res;
+}
+
+off_t CFileBase::seekToBegin() const throw()
+{
+ return seek(0, SEEK_SET);
+}
+
+off_t CFileBase::seekToCur() const throw()
+{
+ return seek(0, SEEK_CUR);
+}
+
+/*
+bool CFileBase::SeekToBegin() const throw()
+{
+ return (::seek(0, SEEK_SET) != -1);
+}
+*/
+
+
+/////////////////////////
+// CInFile
+
+bool CInFile::Open(const char *name)
+{
+ return CFileBase::OpenBinary(name, O_RDONLY);
+}
+
+bool CInFile::OpenShared(const char *name, bool)
+{
+ return Open(name);
+}
+
+
+/*
+int CFileBase::my_ioctl_BLKGETSIZE64(unsigned long long *numBlocks)
+{
+ // we can read "/sys/block/sda/size" "/sys/block/sda/sda1/size" - partition
+ // #include <linux/fs.h>
+ return ioctl(_handle, BLKGETSIZE64, numBlocks);
+ // in block size
+}
+
+int CFileBase::GetDeviceSize_InBytes(UInt64 &size)
+{
+ size = 0;
+ unsigned long long numBlocks;
+ int res = my_ioctl_BLKGETSIZE64(&numBlocks);
+ if (res == 0)
+ size = numBlocks; // another blockSize s possible?
+ printf("\nGetDeviceSize_InBytes res = %d, size = %lld\n", res, (long long)size);
+ return res;
+}
+*/
+
+/*
+On Linux (32-bit and 64-bit):
+read(), write() (and similar system calls) will transfer at most
+0x7ffff000 = (2GiB - 4 KiB) bytes, returning the number of bytes actually transferred.
+*/
+
+static const size_t kChunkSizeMax = ((size_t)1 << 22);
+
+ssize_t CInFile::read_part(void *data, size_t size) throw()
+{
+ if (size > kChunkSizeMax)
+ size = kChunkSizeMax;
+ return ::read(_handle, data, size);
+}
+
+bool CInFile::ReadFull(void *data, size_t size, size_t &processed) throw()
+{
+ processed = 0;
+ do
+ {
+ const ssize_t res = read_part(data, size);
+ if (res < 0)
+ return false;
+ if (res == 0)
+ break;
+ data = (void *)((unsigned char *)data + (size_t)res);
+ size -= (size_t)res;
+ processed += (size_t)res;
+ }
+ while (size > 0);
+ return true;
+}
+
+
+/////////////////////////
+// COutFile
+
+bool COutFile::Create(const char *name, bool createAlways)
+{
+ Path = name; // change it : set it only if open is success.
+ if (createAlways)
+ {
+ Close();
+ _handle = ::creat(name, mode_for_Create);
+ return _handle != -1;
+ }
+ return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY, mode_for_Create);
+}
+
+bool COutFile::Open(const char *name, DWORD creationDisposition)
+{
+ UNUSED_VAR(creationDisposition) // FIXME
+ return Create(name, false);
+}
+
+ssize_t COutFile::write_part(const void *data, size_t size) throw()
+{
+ if (size > kChunkSizeMax)
+ size = kChunkSizeMax;
+ return ::write(_handle, data, size);
+}
+
+ssize_t COutFile::write_full(const void *data, size_t size, size_t &processed) throw()
+{
+ processed = 0;
+ do
+ {
+ const ssize_t res = write_part(data, size);
+ if (res < 0)
+ return res;
+ if (res == 0)
+ break;
+ data = (const void *)((const unsigned char *)data + (size_t)res);
+ size -= (size_t)res;
+ processed += (size_t)res;
+ }
+ while (size > 0);
+ return (ssize_t)processed;
+}
+
+bool COutFile::SetLength(UInt64 length) throw()
+{
+ const off_t len2 = (off_t)length;
+ if ((Int64)length != len2)
+ {
+ SetLastError(EFBIG);
+ return false;
+ }
+ // The value of the seek pointer shall not be modified by a call to ftruncate().
+ const int iret = ftruncate(_handle, len2);
+ return (iret == 0);
+}
+
+bool COutFile::Close()
+{
+ const bool res = CFileBase::Close();
+ if (!res)
+ return res;
+ if (CTime_defined || ATime_defined || MTime_defined)
+ {
+ /* bool res2 = */ NWindows::NFile::NDir::SetDirTime(Path,
+ CTime_defined ? &CTime : NULL,
+ ATime_defined ? &ATime : NULL,
+ MTime_defined ? &MTime : NULL);
+ }
+ return res;
+}
+
+bool COutFile::SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) throw()
+{
+ // On some OS (cygwin, MacOSX ...), you must close the file before updating times
+ // return true;
+
+ if (cTime) { CTime = *cTime; CTime_defined = true; } else CTime_defined = false;
+ if (aTime) { ATime = *aTime; ATime_defined = true; } else ATime_defined = false;
+ if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false;
+ return true;
+
+ /*
+ struct timespec times[2];
+ UNUSED_VAR(cTime)
+ if (!aTime && !mTime)
+ return true;
+ bool needChange;
+ needChange = FiTime_To_timespec(aTime, times[0]);
+ needChange |= FiTime_To_timespec(mTime, times[1]);
+ if (!needChange)
+ return true;
+ return futimens(_handle, times) == 0;
+ */
+}
+
+bool COutFile::SetMTime(const CFiTime *mTime) throw()
+{
+ if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false;
+ return true;
+}
+
+}}}
+
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/FileIO.h b/3rdparty/lzma/CPP/Windows/FileIO.h
index 32c285fb9cc..03e061a980b 100644
--- a/3rdparty/lzma/CPP/Windows/FileIO.h
+++ b/3rdparty/lzma/CPP/Windows/FileIO.h
@@ -1,32 +1,50 @@
// Windows/FileIO.h
-#ifndef __WINDOWS_FILE_IO_H
-#define __WINDOWS_FILE_IO_H
+#ifndef ZIP7_INC_WINDOWS_FILE_IO_H
+#define ZIP7_INC_WINDOWS_FILE_IO_H
#include "../Common/MyWindows.h"
+#define Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
+#define Z7_WIN_IO_REPARSE_TAG_SYMLINK (0xA000000CL)
+#define Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK (0xA000001DL)
+
+#define Z7_WIN_SYMLINK_FLAG_RELATIVE 1
+
+// what the meaning of that FLAG or field (2)?
+#define Z7_WIN_LX_SYMLINK_FLAG 2
+
+#ifdef _WIN32
+
#if defined(_WIN32) && !defined(UNDER_CE)
#include <winioctl.h>
#endif
+#else
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#endif
+
#include "../Common/MyString.h"
#include "../Common/MyBuffer.h"
-#include "Defs.h"
+#include "../Windows/TimeUtils.h"
-#define _my_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
-#define _my_IO_REPARSE_TAG_SYMLINK (0xA000000CL)
+#include "Defs.h"
-#define _my_SYMLINK_FLAG_RELATIVE 1
+HRESULT GetLastError_noZero_HRESULT();
-#define my_FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
-#define my_FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
+#define my_FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
+#define my_FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
+#define my_FSCTL_DELETE_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 43, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
namespace NWindows {
namespace NFile {
#if defined(_WIN32) && !defined(UNDER_CE)
-bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink);
+bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool isWSL);
#endif
struct CReparseShortInfo
@@ -44,24 +62,56 @@ struct CReparseAttr
UString SubsName;
UString PrintName;
+ AString WslName;
+
+ bool HeaderError;
+ bool TagIsUnknown;
+ bool MinorError;
+ DWORD ErrorCode;
+
CReparseAttr(): Tag(0), Flags(0) {}
+
+ // Parse()
+ // returns (true) and (ErrorCode = 0), if (it'a correct known link)
+ // returns (false) and (ErrorCode = ERROR_REPARSE_TAG_INVALID), if unknown tag
bool Parse(const Byte *p, size_t size);
- bool IsMountPoint() const { return Tag == _my_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction
- bool IsSymLink() const { return Tag == _my_IO_REPARSE_TAG_SYMLINK; }
- bool IsRelative() const { return Flags == _my_SYMLINK_FLAG_RELATIVE; }
+ bool IsMountPoint() const { return Tag == Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction
+ bool IsSymLink_Win() const { return Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK; }
+ bool IsSymLink_WSL() const { return Tag == Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK; }
+
+ bool IsRelative_Win() const { return Flags == Z7_WIN_SYMLINK_FLAG_RELATIVE; }
+
+ bool IsRelative_WSL() const
+ {
+ if (WslName.IsEmpty())
+ return true;
+ char c = WslName[0];
+ return !IS_PATH_SEPAR(c);
+ }
+
// bool IsVolume() const;
bool IsOkNamePair() const;
UString GetPath() const;
};
+#ifdef _WIN32
+#define CFiInfo BY_HANDLE_FILE_INFORMATION
+#define ST_MTIME(st) (st).ftLastWriteTime
+#else
+#define CFiInfo stat
+#endif
+
+#ifdef _WIN32
+
namespace NIO {
bool GetReparseData(CFSTR path, CByteBuffer &reparseData, BY_HANDLE_FILE_INFORMATION *fileInfo = NULL);
bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size);
+bool DeleteReparseData(CFSTR path);
-class CFileBase
+class CFileBase MY_UNCOPYABLE
{
protected:
HANDLE _handle;
@@ -90,15 +140,20 @@ public:
}
public:
- #ifdef SUPPORT_DEVICE_FILE
+ bool PreserveATime;
+ #ifdef Z7_DEVICE_FILE
bool IsDeviceFile;
bool SizeDefined;
UInt64 Size; // it can be larger than real available size
#endif
- CFileBase(): _handle(INVALID_HANDLE_VALUE) {};
+ CFileBase(): _handle(INVALID_HANDLE_VALUE), PreserveATime(false) {}
~CFileBase() { Close(); }
+ HANDLE GetHandle() const { return _handle; }
+
+ // void Detach() { _handle = INVALID_HANDLE_VALUE; }
+
bool Close() throw();
bool GetPosition(UInt64 &position) const throw();
@@ -114,6 +169,7 @@ public:
static bool GetFileInformation(CFSTR path, BY_HANDLE_FILE_INFORMATION *info)
{
+ // probably it can work for complex paths: unsupported by another things
NIO::CFileBase file;
if (!file.Create(path, 0, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS))
return false;
@@ -139,7 +195,7 @@ struct my_DISK_GEOMETRY_EX
class CInFile: public CFileBase
{
- #ifdef SUPPORT_DEVICE_FILE
+ #ifdef Z7_DEVICE_FILE
#ifndef UNDER_CE
@@ -169,9 +225,31 @@ public:
#ifndef UNDER_CE
+ bool Open_for_ReadAttributes(CFSTR fileName)
+ {
+ return Create(fileName, FILE_READ_ATTRIBUTES,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS);
+ // we must use (FILE_FLAG_BACKUP_SEMANTICS) to open handle of directory.
+ }
+
+ bool Open_for_FileRenameInformation(CFSTR fileName)
+ {
+ return Create(fileName, DELETE | SYNCHRONIZE | GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
+ // we must use (FILE_FLAG_BACKUP_SEMANTICS) to open handle of directory.
+ }
+
bool OpenReparse(CFSTR fileName)
{
- return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING,
+ // 17.02 fix: to support Windows XP compatibility junctions:
+ // we use Create() with (desiredAccess = 0) instead of Open() with GENERIC_READ
+ return
+ Create(fileName, 0,
+ // Open(fileName,
+ FILE_SHARE_READ, OPEN_EXISTING,
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS);
}
@@ -180,6 +258,7 @@ public:
bool Read1(void *data, UInt32 size, UInt32 &processedSize) throw();
bool ReadPart(void *data, UInt32 size, UInt32 &processedSize) throw();
bool Read(void *data, UInt32 size, UInt32 &processedSize) throw();
+ bool ReadFull(void *data, size_t size, size_t &processedSize) throw();
};
class COutFile: public CFileBase
@@ -190,14 +269,122 @@ public:
bool Create(CFSTR fileName, bool createAlways);
bool CreateAlways(CFSTR fileName, DWORD flagsAndAttributes);
- bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) throw();
- bool SetMTime(const FILETIME *mTime) throw();
+ bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) throw();
+ bool SetMTime(const CFiTime *mTime) throw();
bool WritePart(const void *data, UInt32 size, UInt32 &processedSize) throw();
bool Write(const void *data, UInt32 size, UInt32 &processedSize) throw();
+ bool WriteFull(const void *data, size_t size) throw();
bool SetEndOfFile() throw();
bool SetLength(UInt64 length) throw();
+ bool SetLength_KeepPosition(UInt64 length) throw();
+};
+
+}
+
+
+#else // _WIN32
+
+namespace NIO {
+
+bool GetReparseData(CFSTR path, CByteBuffer &reparseData);
+// bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size);
+
+// parameters are in reverse order of symlink() function !!!
+bool SetSymLink(CFSTR from, CFSTR to);
+bool SetSymLink_UString(CFSTR from, const UString &to);
+
+
+class CFileBase
+{
+protected:
+ int _handle;
+
+ /*
+ bool IsDeviceFile;
+ bool SizeDefined;
+ UInt64 Size; // it can be larger than real available size
+ */
+
+ bool OpenBinary(const char *name, int flags, mode_t mode = 0666);
+public:
+ bool PreserveATime;
+
+ CFileBase(): _handle(-1), PreserveATime(false) {}
+ ~CFileBase() { Close(); }
+ // void Detach() { _handle = -1; }
+ bool Close();
+ bool GetLength(UInt64 &length) const;
+ off_t seek(off_t distanceToMove, int moveMethod) const;
+ off_t seekToBegin() const throw();
+ off_t seekToCur() const throw();
+ // bool SeekToBegin() throw();
+ int my_fstat(struct stat *st) const { return fstat(_handle, st); }
+ /*
+ int my_ioctl_BLKGETSIZE64(unsigned long long *val);
+ int GetDeviceSize_InBytes(UInt64 &size);
+ void CalcDeviceSize(CFSTR s);
+ */
+};
+
+class CInFile: public CFileBase
+{
+public:
+ bool Open(const char *name);
+ bool OpenShared(const char *name, bool shareForWrite);
+ ssize_t read_part(void *data, size_t size) throw();
+ // ssize_t read_full(void *data, size_t size, size_t &processed);
+ bool ReadFull(void *data, size_t size, size_t &processedSize) throw();
+};
+
+class COutFile: public CFileBase
+{
+ bool CTime_defined;
+ bool ATime_defined;
+ bool MTime_defined;
+ CFiTime CTime;
+ CFiTime ATime;
+ CFiTime MTime;
+
+ AString Path;
+ ssize_t write_part(const void *data, size_t size) throw();
+public:
+ mode_t mode_for_Create;
+
+ COutFile():
+ CTime_defined(false),
+ ATime_defined(false),
+ MTime_defined(false),
+ mode_for_Create(0666)
+ {}
+
+ bool Close();
+ bool Create(const char *name, bool createAlways);
+ bool Open(const char *name, DWORD creationDisposition);
+ ssize_t write_full(const void *data, size_t size, size_t &processed) throw();
+
+ bool WriteFull(const void *data, size_t size) throw()
+ {
+ size_t processed;
+ ssize_t res = write_full(data, size, processed);
+ if (res == -1)
+ return false;
+ return processed == size;
+ }
+
+ bool SetLength(UInt64 length) throw();
+ bool SetLength_KeepPosition(UInt64 length) throw()
+ {
+ return SetLength(length);
+ }
+ bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) throw();
+ bool SetMTime(const CFiTime *mTime) throw();
};
-}}}
+}
+
+#endif // _WIN32
+
+}}
+
#endif
diff --git a/3rdparty/lzma/CPP/Windows/FileLink.cpp b/3rdparty/lzma/CPP/Windows/FileLink.cpp
index 25d49ac3ed6..2b9fa1a0930 100644
--- a/3rdparty/lzma/CPP/Windows/FileLink.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileLink.cpp
@@ -4,15 +4,31 @@
#include "../../C/CpuArch.h"
-#ifdef SUPPORT_DEVICE_FILE
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+#ifdef Z7_DEVICE_FILE
#include "../../C/Alloc.h"
#endif
+#include "../Common/UTFConvert.h"
+#include "../Common/StringConvert.h"
+
#include "FileDir.h"
#include "FileFind.h"
#include "FileIO.h"
#include "FileName.h"
+#ifdef Z7_OLD_WIN_SDK
+#ifndef ERROR_INVALID_REPARSE_DATA
+#define ERROR_INVALID_REPARSE_DATA 4392L
+#endif
+#ifndef ERROR_REPARSE_TAG_INVALID
+#define ERROR_REPARSE_TAG_INVALID 4393L
+#endif
+#endif
+
#ifndef _UNICODE
extern bool g_IsNT;
#endif
@@ -55,61 +71,87 @@ using namespace NName;
*/
/*
+Win10 WSL2:
+admin rights + sudo: it creates normal windows symbolic link.
+in another cases : it creates IO_REPARSE_TAG_LX_SYMLINK repare point.
+*/
+
+/*
static const UInt32 kReparseFlags_Alias = (1 << 29);
static const UInt32 kReparseFlags_HighLatency = (1 << 30);
static const UInt32 kReparseFlags_Microsoft = ((UInt32)1 << 31);
-#define _my_IO_REPARSE_TAG_HSM (0xC0000004L)
-#define _my_IO_REPARSE_TAG_HSM2 (0x80000006L)
-#define _my_IO_REPARSE_TAG_SIS (0x80000007L)
-#define _my_IO_REPARSE_TAG_WIM (0x80000008L)
-#define _my_IO_REPARSE_TAG_CSV (0x80000009L)
-#define _my_IO_REPARSE_TAG_DFS (0x8000000AL)
-#define _my_IO_REPARSE_TAG_DFSR (0x80000012L)
+#define Z7_WIN_IO_REPARSE_TAG_HSM (0xC0000004L)
+#define Z7_WIN_IO_REPARSE_TAG_HSM2 (0x80000006L)
+#define Z7_WIN_IO_REPARSE_TAG_SIS (0x80000007L)
+#define Z7_WIN_IO_REPARSE_TAG_WIM (0x80000008L)
+#define Z7_WIN_IO_REPARSE_TAG_CSV (0x80000009L)
+#define Z7_WIN_IO_REPARSE_TAG_DFS (0x8000000AL)
+#define Z7_WIN_IO_REPARSE_TAG_DFSR (0x80000012L)
*/
#define Get16(p) GetUi16(p)
#define Get32(p) GetUi32(p)
-#define Set16(p, v) SetUi16(p, v)
-#define Set32(p, v) SetUi32(p, v)
-
-static const wchar_t *k_LinkPrefix = L"\\??\\";
+static const wchar_t * const k_LinkPrefix = L"\\??\\";
static const unsigned k_LinkPrefix_Size = 4;
-static const bool IsLinkPrefix(const wchar_t *s)
+static bool IsLinkPrefix(const wchar_t *s)
{
return IsString1PrefixedByString2(s, k_LinkPrefix);
}
/*
-static const wchar_t *k_VolumePrefix = L"Volume{";
+static const wchar_t * const k_VolumePrefix = L"Volume{";
static const bool IsVolumeName(const wchar_t *s)
{
return IsString1PrefixedByString2(s, k_VolumePrefix);
}
*/
-void WriteString(Byte *dest, const wchar_t *path)
+#if defined(_WIN32) && !defined(UNDER_CE)
+
+#define Set16(p, v) SetUi16(p, v)
+#define Set32(p, v) SetUi32(p, v)
+
+static void WriteString(Byte *dest, const wchar_t *path)
{
for (;;)
{
wchar_t c = *path++;
if (c == 0)
return;
- Set16(dest, (UInt16)c);
+ Set16(dest, (UInt16)c)
dest += 2;
}
}
-#if defined(_WIN32) && !defined(UNDER_CE)
-
-bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink)
+bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool isWSL)
{
bool isAbs = IsAbsolutePath(path);
if (!isAbs && !isSymLink)
return false;
+ if (isWSL)
+ {
+ // unsupported characters probably use Replacement Character UTF-16 0xFFFD
+ AString utf;
+ ConvertUnicodeToUTF8(path, utf);
+ const size_t size = 4 + utf.Len();
+ if (size != (UInt16)size)
+ return false;
+ dest.Alloc(8 + size);
+ Byte *p = dest;
+ Set32(p, Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK)
+ Set16(p + 4, (UInt16)(size))
+ Set16(p + 6, 0)
+ Set32(p + 8, Z7_WIN_LX_SYMLINK_FLAG)
+ memcpy(p + 12, utf.Ptr(), utf.Len());
+ return true;
+ }
+
+ // usual symbolic LINK (NOT WSL)
+
bool needPrintName = true;
if (IsSuperPath(path))
@@ -121,12 +163,12 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink)
const unsigned add_Prefix_Len = isAbs ? k_LinkPrefix_Size : 0;
- unsigned len2 = MyStringLen(path) * 2;
- const unsigned len1 = len2 + add_Prefix_Len * 2;
+ size_t len2 = (size_t)MyStringLen(path) * 2;
+ const size_t len1 = len2 + add_Prefix_Len * 2;
if (!needPrintName)
len2 = 0;
- unsigned totalNamesSize = (len1 + len2);
+ size_t totalNamesSize = (len1 + len2);
/* some WIM imagex software uses old scheme for symbolic links.
so we can old scheme for byte to byte compatibility */
@@ -138,34 +180,36 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink)
totalNamesSize += 2 * 2;
const size_t size = 8 + 8 + (isSymLink ? 4 : 0) + totalNamesSize;
+ if (size != (UInt16)size)
+ return false;
dest.Alloc(size);
memset(dest, 0, size);
const UInt32 tag = isSymLink ?
- _my_IO_REPARSE_TAG_SYMLINK :
- _my_IO_REPARSE_TAG_MOUNT_POINT;
+ Z7_WIN_IO_REPARSE_TAG_SYMLINK :
+ Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT;
Byte *p = dest;
- Set32(p, tag);
- Set16(p + 4, (UInt16)(size - 8));
- Set16(p + 6, 0);
+ Set32(p, tag)
+ Set16(p + 4, (UInt16)(size - 8))
+ Set16(p + 6, 0)
p += 8;
unsigned subOffs = 0;
unsigned printOffs = 0;
if (newOrderScheme)
- subOffs = len2;
+ subOffs = (unsigned)len2;
else
- printOffs = len1 + 2;
+ printOffs = (unsigned)len1 + 2;
- Set16(p + 0, (UInt16)subOffs);
- Set16(p + 2, (UInt16)len1);
- Set16(p + 4, (UInt16)printOffs);
- Set16(p + 6, (UInt16)len2);
+ Set16(p + 0, (UInt16)subOffs)
+ Set16(p + 2, (UInt16)len1)
+ Set16(p + 4, (UInt16)printOffs)
+ Set16(p + 6, (UInt16)len2)
p += 8;
if (isSymLink)
{
- UInt32 flags = isAbs ? 0 : _my_SYMLINK_FLAG_RELATIVE;
- Set32(p, flags);
+ UInt32 flags = isAbs ? 0 : Z7_WIN_SYMLINK_FLAG_RELATIVE;
+ Set32(p, flags)
p += 4;
}
@@ -177,7 +221,8 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink)
return true;
}
-#endif
+#endif // defined(_WIN32) && !defined(UNDER_CE)
+
static void GetString(const Byte *p, unsigned len, UString &res)
{
@@ -196,30 +241,67 @@ static void GetString(const Byte *p, unsigned len, UString &res)
bool CReparseAttr::Parse(const Byte *p, size_t size)
{
+ ErrorCode = (DWORD)ERROR_INVALID_REPARSE_DATA;
+ HeaderError = true;
+ TagIsUnknown = true;
+ MinorError = false;
+
if (size < 8)
return false;
Tag = Get32(p);
UInt32 len = Get16(p + 4);
- if (len + 8 > size)
+ if (len + 8 != size)
+ // if (len + 8 > size)
return false;
/*
if ((type & kReparseFlags_Alias) == 0 ||
(type & kReparseFlags_Microsoft) == 0 ||
(type & 0xFFFF) != 3)
*/
- if (Tag != _my_IO_REPARSE_TAG_MOUNT_POINT &&
- Tag != _my_IO_REPARSE_TAG_SYMLINK)
- // return true;
- return false;
if (Get16(p + 6) != 0) // padding
return false;
-
+
+ HeaderError = false;
+
+ if ( Tag != Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT
+ && Tag != Z7_WIN_IO_REPARSE_TAG_SYMLINK
+ && Tag != Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK)
+ {
+ // for unsupported reparse points
+ ErrorCode = (DWORD)ERROR_REPARSE_TAG_INVALID; // ERROR_REPARSE_TAG_MISMATCH
+ // errorCode = ERROR_REPARSE_TAG_MISMATCH; // ERROR_REPARSE_TAG_INVALID
+ return false;
+ }
+
+ TagIsUnknown = false;
+
p += 8;
size -= 8;
- if (len != size) // do we need that check?
- return false;
+ if (Tag == Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK)
+ {
+ if (len < 4)
+ return false;
+ Flags = Get32(p); // maybe it's not Flags
+ if (Flags != Z7_WIN_LX_SYMLINK_FLAG)
+ return false;
+ len -= 4;
+ p += 4;
+ char *s = WslName.GetBuf(len);
+ unsigned i;
+ for (i = 0; i < len; i++)
+ {
+ char c = (char)p[i];
+ s[i] = c;
+ if (c == 0)
+ break;
+ }
+ WslName.ReleaseBuf_SetEnd(i);
+ MinorError = (i != len);
+ ErrorCode = 0;
+ return true;
+ }
if (len < 8)
return false;
@@ -231,7 +313,7 @@ bool CReparseAttr::Parse(const Byte *p, size_t size)
p += 8;
Flags = 0;
- if (Tag == _my_IO_REPARSE_TAG_SYMLINK)
+ if (Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK)
{
if (len < 4)
return false;
@@ -247,9 +329,11 @@ bool CReparseAttr::Parse(const Byte *p, size_t size)
GetString(p + subOffs, subLen >> 1, SubsName);
GetString(p + printOffs, printLen >> 1, PrintName);
+ ErrorCode = 0;
return true;
}
+
bool CReparseShortInfo::Parse(const Byte *p, size_t size)
{
const Byte *start = p;
@@ -266,8 +350,8 @@ bool CReparseShortInfo::Parse(const Byte *p, size_t size)
(type & kReparseFlags_Microsoft) == 0 ||
(type & 0xFFFF) != 3)
*/
- if (Tag != _my_IO_REPARSE_TAG_MOUNT_POINT &&
- Tag != _my_IO_REPARSE_TAG_SYMLINK)
+ if (Tag != Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT &&
+ Tag != Z7_WIN_IO_REPARSE_TAG_SYMLINK)
// return true;
return false;
@@ -290,7 +374,7 @@ bool CReparseShortInfo::Parse(const Byte *p, size_t size)
p += 8;
// UInt32 Flags = 0;
- if (Tag == _my_IO_REPARSE_TAG_SYMLINK)
+ if (Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK)
{
if (len < 4)
return false;
@@ -332,26 +416,34 @@ bool CReparseAttr::IsVolume() const
UString CReparseAttr::GetPath() const
{
- UString s = SubsName;
+ if (IsSymLink_WSL())
+ {
+ UString u;
+ // if (CheckUTF8(attr.WslName)
+ if (!ConvertUTF8ToUnicode(WslName, u))
+ MultiByteToUnicodeString2(u, WslName);
+ return u;
+ }
+
+ UString s (SubsName);
if (IsLinkPrefix(s))
{
- s.ReplaceOneCharAtPos(1, '\\');
+ s.ReplaceOneCharAtPos(1, '\\'); // we normalize prefix from "\??\" to "\\?\"
if (IsDrivePath(s.Ptr(k_LinkPrefix_Size)))
s.DeleteFrontal(k_LinkPrefix_Size);
}
return s;
}
-
-#ifdef SUPPORT_DEVICE_FILE
+#ifdef Z7_DEVICE_FILE
namespace NSystem
{
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
}
-#endif
+#endif // Z7_DEVICE_FILE
-#ifndef UNDER_CE
+#if defined(_WIN32) && !defined(UNDER_CE)
namespace NIO {
@@ -376,7 +468,7 @@ bool GetReparseData(CFSTR path, CByteBuffer &reparseData, BY_HANDLE_FILE_INFORMA
static bool CreatePrefixDirOfFile(CFSTR path)
{
- FString path2 = path;
+ FString path2 (path);
int pos = path2.ReverseFind_PathSepar();
if (pos < 0)
return true;
@@ -384,11 +476,26 @@ static bool CreatePrefixDirOfFile(CFSTR path)
if (pos == 2 && path2[1] == L':')
return true; // we don't create Disk folder;
#endif
- path2.DeleteFrom(pos);
+ path2.DeleteFrom((unsigned)pos);
return NDir::CreateComplexDir(path2);
}
-// If there is Reprase data already, it still writes new Reparse data
+
+static bool OutIoReparseData(DWORD controlCode, CFSTR path, void *data, DWORD size)
+{
+ COutFile file;
+ if (!file.Open(path,
+ FILE_SHARE_WRITE,
+ OPEN_EXISTING,
+ FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS))
+ return false;
+
+ DWORD returnedSize;
+ return file.DeviceIoControl(controlCode, data, size, NULL, 0, &returnedSize);
+}
+
+
+// If there is Reparse data already, it still writes new Reparse data
bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size)
{
NFile::NFind::CFileInfo fi;
@@ -416,21 +523,100 @@ bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size)
}
}
- COutFile file;
- if (!file.Open(path,
- FILE_SHARE_WRITE,
- OPEN_EXISTING,
- FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS))
+ return OutIoReparseData(my_FSCTL_SET_REPARSE_POINT, path, (void *)(const Byte *)(data), size);
+}
+
+
+bool DeleteReparseData(CFSTR path)
+{
+ CByteBuffer reparseData;
+ if (!GetReparseData(path, reparseData, NULL))
+ return false;
+ /* MSDN: The tag specified in the ReparseTag member of this structure
+ must match the tag of the reparse point to be deleted,
+ and the ReparseDataLength member must be zero */
+ #define my_REPARSE_DATA_BUFFER_HEADER_SIZE 8
+ if (reparseData.Size() < my_REPARSE_DATA_BUFFER_HEADER_SIZE)
+ {
+ SetLastError(ERROR_INVALID_REPARSE_DATA);
return false;
+ }
+ BYTE buf[my_REPARSE_DATA_BUFFER_HEADER_SIZE];
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, reparseData, 4); // tag
+ return OutIoReparseData(my_FSCTL_DELETE_REPARSE_POINT, path, buf, sizeof(buf));
+}
- DWORD returnedSize;
- if (!file.DeviceIoControl(my_FSCTL_SET_REPARSE_POINT, (void *)data, size, NULL, 0, &returnedSize))
+}
+
+#endif // defined(_WIN32) && !defined(UNDER_CE)
+
+
+#ifndef _WIN32
+
+namespace NIO {
+
+bool GetReparseData(CFSTR path, CByteBuffer &reparseData)
+{
+ reparseData.Free();
+
+ #define MAX_PATHNAME_LEN 1024
+ char buf[MAX_PATHNAME_LEN + 2];
+ const size_t request = sizeof(buf) - 1;
+
+ // printf("\nreadlink() path = %s \n", path);
+ const ssize_t size = readlink(path, buf, request);
+ // there is no tail zero
+
+ if (size < 0)
return false;
+ if ((size_t)size >= request)
+ {
+ SetLastError(EINVAL); // check it: ENAMETOOLONG
+ return false;
+ }
+
+ // printf("\nreadlink() res = %s size = %d \n", buf, (int)size);
+ reparseData.CopyFrom((const Byte *)buf, (size_t)size);
return true;
}
+
+/*
+// If there is Reparse data already, it still writes new Reparse data
+bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size)
+{
+ // AString s;
+ // s.SetFrom_CalcLen(data, size);
+ // return (symlink(s, path) == 0);
+ UNUSED_VAR(path)
+ UNUSED_VAR(isDir)
+ UNUSED_VAR(data)
+ UNUSED_VAR(size)
+ SetLastError(ENOSYS);
+ return false;
}
+*/
-#endif
+bool SetSymLink(CFSTR from, CFSTR to)
+{
+ // printf("\nsymlink() %s -> %s\n", from, to);
+ int ir;
+ // ir = unlink(path);
+ // if (ir == 0)
+ ir = symlink(to, from);
+ return (ir == 0);
+}
+
+bool SetSymLink_UString(CFSTR from, const UString &to)
+{
+ AString utf;
+ ConvertUnicodeToUTF8(to, utf);
+ return SetSymLink(from, utf);
+}
+
+}
+
+#endif // !_WIN32
}}
diff --git a/3rdparty/lzma/CPP/Windows/FileMapping.h b/3rdparty/lzma/CPP/Windows/FileMapping.h
index f90c429f1d7..caa7ea3ed77 100644
--- a/3rdparty/lzma/CPP/Windows/FileMapping.h
+++ b/3rdparty/lzma/CPP/Windows/FileMapping.h
@@ -1,7 +1,7 @@
// Windows/FileMapping.h
-#ifndef __WINDOWS_FILEMAPPING_H
-#define __WINDOWS_FILEMAPPING_H
+#ifndef ZIP7_INC_WINDOWS_FILE_MAPPING_H
+#define ZIP7_INC_WINDOWS_FILE_MAPPING_H
#include "../Common/MyTypes.h"
@@ -34,7 +34,7 @@ public:
return res;
#else
_handle = ::OpenFileMapping(desiredAccess, FALSE, name);
- if (_handle != 0)
+ if (_handle != NULL)
return 0;
return ::GetLastError();
#endif
diff --git a/3rdparty/lzma/CPP/Windows/FileName.cpp b/3rdparty/lzma/CPP/Windows/FileName.cpp
index 908ed53f4d0..c9c4f8b6ce9 100644
--- a/3rdparty/lzma/CPP/Windows/FileName.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileName.cpp
@@ -2,6 +2,13 @@
#include "StdAfx.h"
+#ifndef _WIN32
+#include <limits.h>
+#include <unistd.h>
+#include "../Common/StringConvert.h"
+#endif
+
+#include "FileDir.h"
#include "FileName.h"
#ifndef _UNICODE
@@ -58,7 +65,32 @@ void NormalizeDirPathPrefix(UString &dirPath)
dirPath.Add_PathSepar();
}
-#define IS_LETTER_CHAR(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
+#ifdef _WIN32
+
+#ifndef USE_UNICODE_FSTRING
+#ifdef Z7_LONG_PATH
+static void NormalizeDirSeparators(UString &s)
+{
+ const unsigned len = s.Len();
+ for (unsigned i = 0; i < len; i++)
+ if (s[i] == '/')
+ s.ReplaceOneCharAtPos(i, WCHAR_PATH_SEPARATOR);
+}
+#endif
+#endif
+
+void NormalizeDirSeparators(FString &s)
+{
+ const unsigned len = s.Len();
+ for (unsigned i = 0; i < len; i++)
+ if (s[i] == '/')
+ s.ReplaceOneCharAtPos(i, FCHAR_PATH_SEPARATOR);
+}
+
+#endif
+
+
+#define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a')))
bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); }
@@ -87,8 +119,10 @@ bool IsAltPathPrefix(CFSTR s) throw()
#if defined(_WIN32) && !defined(UNDER_CE)
-const wchar_t *kSuperPathPrefix = L"\\\\?\\";
-static const wchar_t *kSuperUncPrefix = L"\\\\?\\UNC\\";
+const char * const kSuperPathPrefix = "\\\\?\\";
+#ifdef Z7_LONG_PATH
+static const char * const kSuperUncPrefix = "\\\\?\\UNC\\";
+#endif
#define IS_DEVICE_PATH(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '.' && IS_SEPAR((s)[3]))
#define IS_SUPER_PREFIX(s) (IS_SEPAR((s)[0]) && IS_SEPAR((s)[1]) && (s)[2] == '?' && IS_SEPAR((s)[3]))
@@ -109,7 +143,7 @@ bool IsDevicePath(CFSTR s) throw()
/*
// actually we don't know the way to open device file in WinCE.
unsigned len = MyStringLen(s);
- if (len < 5 || len > 5 || memcmp(s, FTEXT("DSK"), 3 * sizeof(FChar)) != 0)
+ if (len < 5 || len > 5 || !IsString1PrefixedByString2(s, "DSK"))
return false;
if (s[4] != ':')
return false;
@@ -123,7 +157,7 @@ bool IsDevicePath(CFSTR s) throw()
unsigned len = MyStringLen(s);
if (len == 6 && s[5] == ':')
return true;
- if (len < 18 || len > 22 || memcmp(s + kDevicePathPrefixSize, FTEXT("PhysicalDrive"), 13 * sizeof(FChar)) != 0)
+ if (len < 18 || len > 22 || !IsString1PrefixedByString2(s + kDevicePathPrefixSize, "PhysicalDrive"))
return false;
for (unsigned i = 17; i < len; i++)
if (s[i] < '0' || s[i] > '9')
@@ -157,19 +191,19 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw()
if (c == '.' || c == '?')
return 0;
}
- int pos = FindSepar(s + prefixSize);
+ const int pos = FindSepar(s + prefixSize);
if (pos < 0)
return 0;
- return prefixSize + pos + 1;
+ return prefixSize + (unsigned)(pos + 1);
}
bool IsNetworkShareRootPath(CFSTR s) throw()
{
- unsigned prefixSize = GetNetworkServerPrefixSize(s);
+ const unsigned prefixSize = GetNetworkServerPrefixSize(s);
if (prefixSize == 0)
return false;
s += prefixSize;
- int pos = FindSepar(s);
+ const int pos = FindSepar(s);
if (pos < 0)
return true;
return s[(unsigned)pos + 1] == 0;
@@ -183,6 +217,37 @@ bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); }
bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); }
// bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); }
+bool IsAltStreamPrefixWithColon(const UString &s) throw()
+{
+ if (s.IsEmpty())
+ return false;
+ if (s.Back() != ':')
+ return false;
+ unsigned pos = 0;
+ if (IsSuperPath(s))
+ pos = kSuperPathPrefixSize;
+ if (s.Len() - pos == 2 && IsDrivePath2(s.Ptr(pos)))
+ return false;
+ return true;
+}
+
+bool If_IsSuperPath_RemoveSuperPrefix(UString &s)
+{
+ if (!IsSuperPath(s))
+ return false;
+ unsigned start = 0;
+ unsigned count = kSuperPathPrefixSize;
+ const wchar_t *s2 = s.Ptr(kSuperPathPrefixSize);
+ if (IS_UNC_WITH_SLASH(s2))
+ {
+ start = 2;
+ count = kSuperUncPathPrefixSize - 2;
+ }
+ s.Delete(start, count);
+ return true;
+}
+
+
#ifndef USE_UNICODE_FSTRING
bool IsDrivePath2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; }
// bool IsDriveName2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; }
@@ -191,14 +256,12 @@ bool IsSuperPath(CFSTR s) throw() { return IS_SUPER_PREFIX(s); }
bool IsSuperOrDevicePath(CFSTR s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); }
#endif // USE_UNICODE_FSTRING
-/*
-bool IsDrivePath_SuperAllowed(CFSTR s)
+bool IsDrivePath_SuperAllowed(CFSTR s) throw()
{
if (IsSuperPath(s))
s += kSuperPathPrefixSize;
return IsDrivePath(s);
}
-*/
bool IsDriveRootPath_SuperAllowed(CFSTR s) throw()
{
@@ -212,7 +275,7 @@ bool IsAbsolutePath(const wchar_t *s) throw()
return IS_SEPAR(s[0]) || IsDrivePath2(s);
}
-int FindAltStreamColon(CFSTR path)
+int FindAltStreamColon(CFSTR path) throw()
{
unsigned i = 0;
if (IsDrivePath2(path))
@@ -226,7 +289,7 @@ int FindAltStreamColon(CFSTR path)
if (c == ':')
{
if (colonPos < 0)
- colonPos = i;
+ colonPos = (int)i;
continue;
}
if (IS_SEPAR(c))
@@ -256,7 +319,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(CFSTR s)
return 0;
if (s[1] == 0 || !IS_SEPAR(s[1]))
return 1;
- unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2);
+ const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2);
return (size == 0) ? 0 : 2 + size;
}
@@ -264,17 +327,17 @@ static unsigned GetRootPrefixSize_Of_SuperPath(CFSTR s)
{
if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize))
{
- unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize);
+ const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize);
return (size == 0) ? 0 : kSuperUncPathPrefixSize + size;
}
// we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\"
- int pos = FindSepar(s + kSuperPathPrefixSize);
+ const int pos = FindSepar(s + kSuperPathPrefixSize);
if (pos < 0)
return 0;
return kSuperPathPrefixSize + pos + 1;
}
-unsigned GetRootPrefixSize(CFSTR s)
+unsigned GetRootPrefixSize(CFSTR s) throw()
{
if (IS_DEVICE_PATH(s))
return kDevicePathPrefixSize;
@@ -285,7 +348,7 @@ unsigned GetRootPrefixSize(CFSTR s)
#endif // USE_UNICODE_FSTRING
-static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s)
+static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s) throw()
{
// Network path: we look "server\path\" as root prefix
int pos = FindSepar(s);
@@ -294,10 +357,10 @@ static unsigned GetRootPrefixSize_Of_NetworkPath(const wchar_t *s)
int pos2 = FindSepar(s + (unsigned)pos + 1);
if (pos2 < 0)
return 0;
- return pos + pos2 + 2;
+ return (unsigned)(pos + pos2 + 2);
}
-static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s)
+static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s) throw()
{
if (IsDrivePath(s))
return kDrivePrefixSize;
@@ -309,7 +372,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(const wchar_t *s)
return (size == 0) ? 0 : 2 + size;
}
-static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s)
+static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s) throw()
{
if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize))
{
@@ -320,7 +383,7 @@ static unsigned GetRootPrefixSize_Of_SuperPath(const wchar_t *s)
int pos = FindSepar(s + kSuperPathPrefixSize);
if (pos < 0)
return 0;
- return kSuperPathPrefixSize + pos + 1;
+ return kSuperPathPrefixSize + (unsigned)(pos + 1);
}
unsigned GetRootPrefixSize(const wchar_t *s) throw()
@@ -334,41 +397,39 @@ unsigned GetRootPrefixSize(const wchar_t *s) throw()
#else // _WIN32
-bool IsAbsolutePath(const wchar_t *s) { return IS_SEPAR(s[0]); }
+bool IsAbsolutePath(const wchar_t *s) throw() { return IS_SEPAR(s[0]); }
#ifndef USE_UNICODE_FSTRING
-unsigned GetRootPrefixSize(CFSTR s) { return IS_SEPAR(s[0]) ? 1 : 0; }
+unsigned GetRootPrefixSize(CFSTR s) throw();
+unsigned GetRootPrefixSize(CFSTR s) throw() { return IS_SEPAR(s[0]) ? 1 : 0; }
#endif
-unsigned GetRootPrefixSize(const wchar_t *s) { return IS_SEPAR(s[0]) ? 1 : 0; }
+unsigned GetRootPrefixSize(const wchar_t *s) throw() { return IS_SEPAR(s[0]) ? 1 : 0; }
#endif // _WIN32
#ifndef UNDER_CE
+
+#ifdef USE_UNICODE_FSTRING
+
+#define GetCurDir NDir::GetCurrentDir
+
+#else
+
static bool GetCurDir(UString &path)
{
path.Empty();
- DWORD needLength;
- #ifndef _UNICODE
- if (!g_IsNT)
- {
- TCHAR s[MAX_PATH + 2];
- s[0] = 0;
- needLength = ::GetCurrentDirectory(MAX_PATH + 1, s);
- path = fs2us(fas2fs(s));
- }
- else
- #endif
- {
- WCHAR s[MAX_PATH + 2];
- s[0] = 0;
- needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, s);
- path = s;
- }
- return (needLength > 0 && needLength <= MAX_PATH);
+ FString s;
+ if (!NDir::GetCurrentDir(s))
+ return false;
+ path = fs2us(s);
+ return true;
}
+#endif
+
+
static bool ResolveDotsFolders(UString &s)
{
#ifdef _WIN32
@@ -390,7 +451,7 @@ static bool ResolveDotsFolders(UString &s)
{
if (i == 0)
return false;
- int k = i - 2;
+ int k = (int)i - 2;
i += 2;
for (;; k--)
@@ -409,8 +470,8 @@ static bool ResolveDotsFolders(UString &s)
if (k >= 0)
{
- num = i - k;
- i = k;
+ num = i - (unsigned)k;
+ i = (unsigned)k;
}
else
{
@@ -470,7 +531,7 @@ static bool AreThereDotsFolders(CFSTR s)
#endif
#endif // LONG_PATH_DOTS_FOLDERS_PARSING
-#ifdef WIN_LONG_PATH
+#ifdef Z7_LONG_PATH
/*
Most of Windows versions have problems, if some file or dir name
@@ -530,6 +591,7 @@ int GetUseSuperPathType(CFSTR s) throw()
}
+
/*
returns false in two cases:
- if GetCurDir was used, and GetCurDir returned error.
@@ -540,7 +602,6 @@ int GetUseSuperPathType(CFSTR s) throw()
for absolute paths, returns true, res is Super path.
*/
-
static bool GetSuperPathBase(CFSTR s, UString &res)
{
res.Empty();
@@ -564,11 +625,11 @@ static bool GetSuperPathBase(CFSTR s, UString &res)
return true;
UString temp = fs2us(s);
- unsigned fixedSize = GetRootPrefixSize_Of_SuperPath(temp);
+ const unsigned fixedSize = GetRootPrefixSize_Of_SuperPath(temp);
if (fixedSize == 0)
return true;
- UString rem = &temp[fixedSize];
+ UString rem = temp.Ptr(fixedSize);
if (!ResolveDotsFolders(rem))
return true;
@@ -586,13 +647,13 @@ static bool GetSuperPathBase(CFSTR s, UString &res)
if (IS_SEPAR(s[1]))
{
UString temp = fs2us(s + 2);
- unsigned fixedSize = GetRootPrefixSize_Of_NetworkPath(temp);
+ const unsigned fixedSize = GetRootPrefixSize_Of_NetworkPath(temp);
// we ignore that error to allow short network paths server\share?
/*
if (fixedSize == 0)
return false;
*/
- UString rem = &temp[fixedSize];
+ UString rem = temp.Ptr(fixedSize);
if (!ResolveDotsFolders(rem))
return false;
res += kSuperUncPrefix;
@@ -628,7 +689,7 @@ static bool GetSuperPathBase(CFSTR s, UString &res)
unsigned fixedSizeStart = 0;
unsigned fixedSize = 0;
- const wchar_t *superMarker = NULL;
+ const char *superMarker = NULL;
if (IsSuperPath(curDir))
{
fixedSize = GetRootPrefixSize_Of_SuperPath(curDir);
@@ -683,7 +744,7 @@ static bool GetSuperPathBase(CFSTR s, UString &res)
true false * use Super path
true true true don't use any path, we already used mainPath
true true false use main path as Super Path, we don't try mainMath
- That case is possible now if GetCurDir returns unknow
+ That case is possible now if GetCurDir returns unknown
type of path (not drive and not network)
We can change that code if we want to try mainPath, if GetSuperPathBase returns error,
@@ -704,6 +765,8 @@ bool GetSuperPath(CFSTR path, UString &superPath, bool onlyIfNew)
return false;
superPath = fs2us(path);
}
+
+ NormalizeDirSeparators(superPath);
return true;
}
return false;
@@ -714,6 +777,10 @@ bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew)
if (!GetSuperPathBase(s1, d1) ||
!GetSuperPathBase(s2, d2))
return false;
+
+ NormalizeDirSeparators(d1);
+ NormalizeDirSeparators(d2);
+
if (d1.IsEmpty() && d2.IsEmpty() && onlyIfNew)
return false;
if (d1.IsEmpty()) d1 = fs2us(s1);
@@ -731,7 +798,7 @@ bool GetSuperPath(CFSTR path, UString &superPath)
return false;
}
*/
-#endif // WIN_LONG_PATH
+#endif // Z7_LONG_PATH
bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
{
@@ -749,8 +816,11 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
#else
- unsigned prefixSize = GetRootPrefixSize(s);
+ const unsigned prefixSize = GetRootPrefixSize(s);
if (prefixSize != 0)
+#ifdef _WIN32
+ if (prefixSize != 1)
+#endif
{
if (!AreThereDotsFolders(s + prefixSize))
return true;
@@ -763,21 +833,9 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
return true;
}
- /*
- FChar c = s[0];
- if (c == 0)
- return true;
- if (c == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0)))
- return true;
- if (IS_SEPAR(c) && IS_SEPAR(s[1]))
- return true;
- if (IsDrivePath(s))
- return true;
- */
-
UString curDir;
- if (dirPrefix)
- curDir = fs2us(dirPrefix);
+ if (dirPrefix && prefixSize == 0)
+ curDir = fs2us(dirPrefix); // we use (dirPrefix), only if (s) path is relative
else
{
if (!GetCurDir(curDir))
@@ -785,46 +843,40 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
}
NormalizeDirPathPrefix(curDir);
- unsigned fixedSize = 0;
-
- #ifdef _WIN32
+ unsigned fixedSize = GetRootPrefixSize(curDir);
- if (IsSuperPath(curDir))
+ UString temp;
+#ifdef _WIN32
+ if (prefixSize != 0)
{
- fixedSize = GetRootPrefixSize_Of_SuperPath(curDir);
+ /* (s) is absolute path, but only (prefixSize == 1) is possible here.
+ So for full resolving we need root of current folder and
+ relative part of (s). */
+ s += prefixSize;
+ // (s) is relative part now
if (fixedSize == 0)
- return false;
- }
- else
- {
- if (IsDrivePath(curDir))
- fixedSize = kDrivePrefixSize;
- else
{
- if (!IsPathSepar(curDir[0]) || !IsPathSepar(curDir[1]))
- return false;
- fixedSize = GetRootPrefixSize_Of_NetworkPath(curDir.Ptr(2));
- if (fixedSize == 0)
- return false;
- fixedSize += 2;
+ // (curDir) is not absolute.
+ // That case is unexpected, but we support it too.
+ curDir.Empty();
+ curDir.Add_PathSepar();
+ fixedSize = 1;
+ // (curDir) now is just Separ character.
+ // So final (res) path later also will have Separ prefix.
}
}
-
- #endif // _WIN32
-
- UString temp;
- if (IS_SEPAR(s[0]))
- {
- temp = fs2us(s + 1);
- }
else
+#endif // _WIN32
{
- temp += curDir.Ptr(fixedSize);
- temp += fs2us(s);
+ // (s) is relative path
+ temp = curDir.Ptr(fixedSize);
+ // (temp) is relative_part_of(curDir)
}
+ temp += fs2us(s);
if (!ResolveDotsFolders(temp))
return false;
curDir.DeleteFrom(fixedSize);
+ // (curDir) now contains only absolute prefix part
res = us2fs(curDir);
res += us2fs(temp);
@@ -833,6 +885,7 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
return true;
}
+
bool GetFullPath(CFSTR path, FString &fullPath)
{
return GetFullPath(NULL, path, fullPath);
diff --git a/3rdparty/lzma/CPP/Windows/FileName.h b/3rdparty/lzma/CPP/Windows/FileName.h
index 6f9b6e03932..219b656b297 100644
--- a/3rdparty/lzma/CPP/Windows/FileName.h
+++ b/3rdparty/lzma/CPP/Windows/FileName.h
@@ -1,7 +1,7 @@
// Windows/FileName.h
-#ifndef __WINDOWS_FILE_NAME_H
-#define __WINDOWS_FILE_NAME_H
+#ifndef ZIP7_INC_WINDOWS_FILE_NAME_H
+#define ZIP7_INC_WINDOWS_FILE_NAME_H
#include "../Common/MyString.h"
@@ -17,13 +17,17 @@ int FindSepar(const FChar *s) throw();
void NormalizeDirPathPrefix(FString &dirPath); // ensures that it ended with '\\', if dirPath is not epmty
void NormalizeDirPathPrefix(UString &dirPath);
+#ifdef _WIN32
+void NormalizeDirSeparators(FString &s);
+#endif
+
bool IsDrivePath(const wchar_t *s) throw(); // first 3 chars are drive chars like "a:\\"
bool IsAltPathPrefix(CFSTR s) throw(); /* name: */
#if defined(_WIN32) && !defined(UNDER_CE)
-extern const wchar_t *kSuperPathPrefix; /* \\?\ */
+extern const char * const kSuperPathPrefix; /* \\?\ */
const unsigned kDevicePathPrefixSize = 4;
const unsigned kSuperPathPrefixSize = 4;
const unsigned kSuperUncPathPrefixSize = kSuperPathPrefixSize + 4;
@@ -42,7 +46,7 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw();
bool IsNetworkShareRootPath(CFSTR s) throw(); /* \\?\UNC\SERVER\share or \\SERVER\share or with slash */
-// bool IsDrivePath_SuperAllowed(CFSTR s) throw(); // first chars are drive chars like "a:\" or "\\?\a:\"
+bool IsDrivePath_SuperAllowed(CFSTR s) throw(); // first chars are drive chars like "a:\" or "\\?\a:\"
bool IsDriveRootPath_SuperAllowed(CFSTR s) throw(); // exact drive root path "a:\" or "\\?\a:\"
bool IsDrivePath2(const wchar_t *s) throw(); // first 2 chars are drive chars like "a:"
@@ -50,6 +54,10 @@ bool IsDrivePath2(const wchar_t *s) throw(); // first 2 chars are drive chars li
bool IsSuperPath(const wchar_t *s) throw();
bool IsSuperOrDevicePath(const wchar_t *s) throw();
+bool IsAltStreamPrefixWithColon(const UString &s) throw();
+// returns true, if super prefix was removed
+bool If_IsSuperPath_RemoveSuperPrefix(UString &s);
+
#ifndef USE_UNICODE_FSTRING
bool IsDrivePath2(CFSTR s) throw(); // first 2 chars are drive chars like "a:"
// bool IsDriveName2(CFSTR s) throw(); // is drive name like "a:"
@@ -71,14 +79,14 @@ unsigned GetRootPrefixSize(CFSTR s) throw();
#endif
-int FindAltStreamColon(CFSTR path);
+int FindAltStreamColon(CFSTR path) throw();
#endif // _WIN32
bool IsAbsolutePath(const wchar_t *s) throw();
unsigned GetRootPrefixSize(const wchar_t *s) throw();
-#ifdef WIN_LONG_PATH
+#ifdef Z7_LONG_PATH
const int kSuperPathType_UseOnlyMain = 0;
const int kSuperPathType_UseOnlySuper = 1;
@@ -88,16 +96,16 @@ int GetUseSuperPathType(CFSTR s) throw();
bool GetSuperPath(CFSTR path, UString &superPath, bool onlyIfNew);
bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew);
-#define USE_MAIN_PATH (__useSuperPathType != kSuperPathType_UseOnlySuper)
-#define USE_MAIN_PATH_2 (__useSuperPathType1 != kSuperPathType_UseOnlySuper && __useSuperPathType2 != kSuperPathType_UseOnlySuper)
+#define USE_MAIN_PATH (_useSuperPathType != kSuperPathType_UseOnlySuper)
+#define USE_MAIN_PATH_2 (_useSuperPathType1 != kSuperPathType_UseOnlySuper && _useSuperPathType2 != kSuperPathType_UseOnlySuper)
-#define USE_SUPER_PATH (__useSuperPathType != kSuperPathType_UseOnlyMain)
-#define USE_SUPER_PATH_2 (__useSuperPathType1 != kSuperPathType_UseOnlyMain || __useSuperPathType2 != kSuperPathType_UseOnlyMain)
+#define USE_SUPER_PATH (_useSuperPathType != kSuperPathType_UseOnlyMain)
+#define USE_SUPER_PATH_2 (_useSuperPathType1 != kSuperPathType_UseOnlyMain || _useSuperPathType2 != kSuperPathType_UseOnlyMain)
-#define IF_USE_MAIN_PATH int __useSuperPathType = GetUseSuperPathType(path); if (USE_MAIN_PATH)
+#define IF_USE_MAIN_PATH int _useSuperPathType = GetUseSuperPathType(path); if (USE_MAIN_PATH)
#define IF_USE_MAIN_PATH_2(x1, x2) \
- int __useSuperPathType1 = GetUseSuperPathType(x1); \
- int __useSuperPathType2 = GetUseSuperPathType(x2); \
+ int _useSuperPathType1 = GetUseSuperPathType(x1); \
+ int _useSuperPathType2 = GetUseSuperPathType(x2); \
if (USE_MAIN_PATH_2)
#else
@@ -105,8 +113,18 @@ bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew)
#define IF_USE_MAIN_PATH
#define IF_USE_MAIN_PATH_2(x1, x2)
-#endif // WIN_LONG_PATH
-
+#endif // Z7_LONG_PATH
+
+/*
+ if (dirPrefix != NULL && (path) is relative)
+ {
+ (dirPrefix) will be used
+ result (fullPath) will contain prefix part of (dirPrefix).
+ }
+ Current_Dir path can be used in 2 cases:
+ 1) if (path) is relative && dirPrefix == NULL
+ 2) for _WIN32: if (path) is absolute starting wuth "\"
+*/
bool GetFullPath(CFSTR dirPrefix, CFSTR path, FString &fullPath);
bool GetFullPath(CFSTR path, FString &fullPath);
diff --git a/3rdparty/lzma/CPP/Windows/FileSystem.cpp b/3rdparty/lzma/CPP/Windows/FileSystem.cpp
index 6c1f48a206c..6a262d92d7f 100644
--- a/3rdparty/lzma/CPP/Windows/FileSystem.cpp
+++ b/3rdparty/lzma/CPP/Windows/FileSystem.cpp
@@ -19,6 +19,8 @@ namespace NWindows {
namespace NFile {
namespace NSystem {
+#ifdef _WIN32
+
bool MyGetVolumeInformation(
CFSTR rootPath,
UString &volumeName,
@@ -69,14 +71,14 @@ UINT MyGetDriveType(CFSTR pathName)
}
}
-typedef BOOL (WINAPI * GetDiskFreeSpaceExA_Pointer)(
+typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExA)(
LPCSTR lpDirectoryName, // directory name
PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller
PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk
PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk
);
-typedef BOOL (WINAPI * GetDiskFreeSpaceExW_Pointer)(
+typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExW)(
LPCWSTR lpDirectoryName, // directory name
PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller
PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk
@@ -90,12 +92,14 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize,
#ifndef _UNICODE
if (!g_IsNT)
{
- GetDiskFreeSpaceExA_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExA_Pointer)GetProcAddress(
- GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExA");
- if (pGetDiskFreeSpaceEx)
+ const
+ Func_GetDiskFreeSpaceExA f = Z7_GET_PROC_ADDRESS(
+ Func_GetDiskFreeSpaceExA, GetModuleHandle(TEXT("kernel32.dll")),
+ "GetDiskFreeSpaceExA");
+ if (f)
{
ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2;
- sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2));
+ sizeIsDetected = BOOLToBool(f(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2));
totalSize = totalSize2.QuadPart;
freeSize = freeSize2.QuadPart;
}
@@ -105,12 +109,14 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize,
else
#endif
{
- GetDiskFreeSpaceExW_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExW_Pointer)GetProcAddress(
- GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExW");
- if (pGetDiskFreeSpaceEx)
+ const
+ Func_GetDiskFreeSpaceExW f = Z7_GET_PROC_ADDRESS(
+ Func_GetDiskFreeSpaceExW, GetModuleHandle(TEXT("kernel32.dll")),
+ "GetDiskFreeSpaceExW");
+ if (f)
{
ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2;
- sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2));
+ sizeIsDetected = BOOLToBool(f(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2));
totalSize = totalSize2.QuadPart;
freeSize = freeSize2.QuadPart;
}
@@ -126,6 +132,8 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize,
return true;
}
+#endif
+
}}}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/FileSystem.h b/3rdparty/lzma/CPP/Windows/FileSystem.h
index 9076ea13f4f..9f9e399ce75 100644
--- a/3rdparty/lzma/CPP/Windows/FileSystem.h
+++ b/3rdparty/lzma/CPP/Windows/FileSystem.h
@@ -1,7 +1,7 @@
// Windows/FileSystem.h
-#ifndef __WINDOWS_FILE_SYSTEM_H
-#define __WINDOWS_FILE_SYSTEM_H
+#ifndef ZIP7_INC_WINDOWS_FILE_SYSTEM_H
+#define ZIP7_INC_WINDOWS_FILE_SYSTEM_H
#include "../Common/MyString.h"
#include "../Common/MyTypes.h"
@@ -10,6 +10,8 @@ namespace NWindows {
namespace NFile {
namespace NSystem {
+#ifdef _WIN32
+
bool MyGetVolumeInformation(
CFSTR rootPath ,
UString &volumeName,
@@ -22,6 +24,8 @@ UINT MyGetDriveType(CFSTR pathName);
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
+#endif
+
}}}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/Handle.h b/3rdparty/lzma/CPP/Windows/Handle.h
index bb7cb705da0..6ae09ecf53c 100644
--- a/3rdparty/lzma/CPP/Windows/Handle.h
+++ b/3rdparty/lzma/CPP/Windows/Handle.h
@@ -1,11 +1,13 @@
// Windows/Handle.h
-#ifndef __WINDOWS_HANDLE_H
-#define __WINDOWS_HANDLE_H
+#ifndef ZIP7_INC_WINDOWS_HANDLE_H
+#define ZIP7_INC_WINDOWS_HANDLE_H
+
+#include "../Common/MyWindows.h"
namespace NWindows {
-class CHandle
+class CHandle MY_UNCOPYABLE
{
protected:
HANDLE _handle;
@@ -26,7 +28,7 @@ public:
void Attach(HANDLE handle) { _handle = handle; }
HANDLE Detach()
{
- HANDLE handle = _handle;
+ const HANDLE handle = _handle;
_handle = NULL;
return handle;
}
diff --git a/3rdparty/lzma/CPP/Windows/MemoryGlobal.cpp b/3rdparty/lzma/CPP/Windows/MemoryGlobal.cpp
new file mode 100644
index 00000000000..2a22394b39d
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/MemoryGlobal.cpp
@@ -0,0 +1,36 @@
+// Windows/MemoryGlobal.cpp
+
+#include "StdAfx.h"
+
+#include "MemoryGlobal.h"
+
+namespace NWindows {
+namespace NMemory {
+
+bool CGlobal::Alloc(UINT flags, SIZE_T size) throw()
+{
+ HGLOBAL newBlock = ::GlobalAlloc(flags, size);
+ if (newBlock == NULL)
+ return false;
+ _global = newBlock;
+ return true;
+}
+
+bool CGlobal::Free() throw()
+{
+ if (_global == NULL)
+ return true;
+ _global = ::GlobalFree(_global);
+ return (_global == NULL);
+}
+
+bool CGlobal::ReAlloc(SIZE_T size) throw()
+{
+ HGLOBAL newBlock = ::GlobalReAlloc(_global, size, GMEM_MOVEABLE);
+ if (newBlock == NULL)
+ return false;
+ _global = newBlock;
+ return true;
+}
+
+}}
diff --git a/3rdparty/lzma/CPP/Windows/MemoryGlobal.h b/3rdparty/lzma/CPP/Windows/MemoryGlobal.h
new file mode 100644
index 00000000000..68525915800
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/MemoryGlobal.h
@@ -0,0 +1,55 @@
+// Windows/MemoryGlobal.h
+
+#ifndef ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H
+#define ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H
+
+#include "../Common/MyWindows.h"
+
+namespace NWindows {
+namespace NMemory {
+
+class CGlobal
+{
+ HGLOBAL _global;
+public:
+ CGlobal(): _global(NULL) {}
+ ~CGlobal() { Free(); }
+ operator HGLOBAL() const { return _global; }
+ void Attach(HGLOBAL hGlobal)
+ {
+ Free();
+ _global = hGlobal;
+ }
+ HGLOBAL Detach()
+ {
+ const HGLOBAL h = _global;
+ _global = NULL;
+ return h;
+ }
+ bool Alloc(UINT flags, SIZE_T size) throw();
+ bool Free() throw();
+ LPVOID Lock() const { return GlobalLock(_global); }
+ void Unlock() const { GlobalUnlock(_global); }
+ bool ReAlloc(SIZE_T size) throw();
+};
+
+class CGlobalLock
+{
+ HGLOBAL _global;
+ LPVOID _ptr;
+public:
+ LPVOID GetPointer() const { return _ptr; }
+ CGlobalLock(HGLOBAL hGlobal): _global(hGlobal)
+ {
+ _ptr = GlobalLock(hGlobal);
+ }
+ ~CGlobalLock()
+ {
+ if (_ptr)
+ GlobalUnlock(_global);
+ }
+};
+
+}}
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/MemoryLock.cpp b/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
index b628a03e8f9..0bd7504f1cc 100644
--- a/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
+++ b/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include "../../C/CpuArch.h"
+
#include "MemoryLock.h"
namespace NWindows {
@@ -19,7 +21,10 @@ typedef BOOL (WINAPI * Func_LookupPrivilegeValue)(LPCTSTR lpSystemName, LPCTSTR
typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges,
PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength);
}
-#define GET_PROC_ADDR(fff, name) Func_ ## fff my_ ## fff = (Func_ ## fff)GetProcAddress(hModule, name)
+
+#define GET_PROC_ADDR(fff, name) \
+ const Func_ ## fff my_ ## fff = Z7_GET_PROC_ADDRESS( \
+ Func_ ## fff, hModule, name);
#endif
bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
@@ -28,13 +33,19 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
#ifndef _UNICODE
- HMODULE hModule = ::LoadLibrary(TEXT("Advapi32.dll"));
- if (hModule == NULL)
+ const HMODULE hModule = ::LoadLibrary(TEXT("advapi32.dll"));
+ if (!hModule)
return false;
- GET_PROC_ADDR(OpenProcessToken, "OpenProcessToken");
- GET_PROC_ADDR(LookupPrivilegeValue, "LookupPrivilegeValueA");
- GET_PROC_ADDR(AdjustTokenPrivileges, "AdjustTokenPrivileges");
+ GET_PROC_ADDR(
+ OpenProcessToken,
+ "OpenProcessToken")
+ GET_PROC_ADDR(
+ LookupPrivilegeValue,
+ "LookupPrivilegeValueA")
+ GET_PROC_ADDR(
+ AdjustTokenPrivileges,
+ "AdjustTokenPrivileges")
if (my_OpenProcessToken &&
my_AdjustTokenPrivileges &&
@@ -67,6 +78,47 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
return res;
}
+
+
+typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
+
+/*
+ We suppose that Window 10 works incorrectly with "Large Pages" at:
+ - Windows 10 1703 (15063) : incorrect allocating after VirtualFree()
+ - Windows 10 1709 (16299) : incorrect allocating after VirtualFree()
+ - Windows 10 1809 (17763) : the failures for blocks of 1 GiB and larger,
+ if CPU doesn't support 1 GB pages.
+ Windows 10 1903 (18362) probably works correctly.
+*/
+
+unsigned Get_LargePages_RiskLevel()
+{
+ OSVERSIONINFOEXW vi;
+ const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
+ if (!ntdll)
+ return 0;
+ const
+ Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
+ Func_RtlGetVersion, ntdll,
+ "RtlGetVersion");
+ if (!func)
+ return 0;
+ func(&vi);
+ if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ return 0;
+ if (vi.dwMajorVersion + vi.dwMinorVersion != 10)
+ return 0;
+ if (vi.dwBuildNumber <= 16299)
+ return 1;
+
+ #ifdef MY_CPU_X86_OR_AMD64
+ if (vi.dwBuildNumber < 18362 && !CPU_IsSupported_PageGB())
+ return 1;
+ #endif
+
+ return 0;
+}
+
#endif
}}
diff --git a/3rdparty/lzma/CPP/Windows/MemoryLock.h b/3rdparty/lzma/CPP/Windows/MemoryLock.h
index 4a5dafcf01d..2b850029f7a 100644
--- a/3rdparty/lzma/CPP/Windows/MemoryLock.h
+++ b/3rdparty/lzma/CPP/Windows/MemoryLock.h
@@ -1,7 +1,7 @@
// Windows/MemoryLock.h
-#ifndef __WINDOWS_MEMORY_LOCK_H
-#define __WINDOWS_MEMORY_LOCK_H
+#ifndef ZIP7_INC_WINDOWS_MEMORY_LOCK_H
+#define ZIP7_INC_WINDOWS_MEMORY_LOCK_H
#include "../Common/MyWindows.h"
@@ -31,6 +31,8 @@ inline void EnablePrivilege_SymLink()
// Do we need to set SE_BACKUP_NAME ?
}
+unsigned Get_LargePages_RiskLevel();
+
#endif
}}
diff --git a/3rdparty/lzma/CPP/Windows/NtCheck.h b/3rdparty/lzma/CPP/Windows/NtCheck.h
index a1b89ef2d1f..362a05ad973 100644
--- a/3rdparty/lzma/CPP/Windows/NtCheck.h
+++ b/3rdparty/lzma/CPP/Windows/NtCheck.h
@@ -1,22 +1,34 @@
// Windows/NtCheck.h
-#ifndef __WINDOWS_NT_CHECK_H
-#define __WINDOWS_NT_CHECK_H
+#ifndef ZIP7_INC_WINDOWS_NT_CHECK_H
+#define ZIP7_INC_WINDOWS_NT_CHECK_H
#ifdef _WIN32
#include "../Common/MyWindows.h"
#if !defined(_WIN64) && !defined(UNDER_CE)
+
+#if defined(_MSC_VER) && _MSC_VER >= 1900
+#pragma warning(push)
+// GetVersionExW was declared deprecated
+#pragma warning(disable : 4996)
+#endif
static inline bool IsItWindowsNT()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
return (::GetVersionEx(&vi) && vi.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
+#if defined(_MSC_VER) && _MSC_VER >= 1900
+#pragma warning(pop)
+#endif
+
#endif
#ifndef _UNICODE
+ extern
+ bool g_IsNT;
#if defined(_WIN64) || defined(UNDER_CE)
bool g_IsNT = true;
#define SET_IS_NT
diff --git a/3rdparty/lzma/CPP/Windows/PropVariant.cpp b/3rdparty/lzma/CPP/Windows/PropVariant.cpp
index e95cbd2b8d5..457b1dcbbee 100644
--- a/3rdparty/lzma/CPP/Windows/PropVariant.cpp
+++ b/3rdparty/lzma/CPP/Windows/PropVariant.cpp
@@ -91,7 +91,7 @@ CPropVariant& CPropVariant::operator=(BSTR bstrSrc)
return *this;
}
-static const char *kMemException = "out of memory";
+static const char * const kMemException = "out of memory";
CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
{
@@ -192,80 +192,108 @@ BSTR CPropVariant::AllocBstr(unsigned numChars)
return bstrVal;
}
+#define SET_PROP_id_dest(id, dest) \
+ if (vt != id) { InternalClear(); vt = id; } dest = value; wReserved1 = 0;
+
+void CPropVariant::Set_Int32(Int32 value) throw()
+{
+ SET_PROP_id_dest(VT_I4, lVal)
+}
+
+void CPropVariant::Set_Int64(Int64 value) throw()
+{
+ SET_PROP_id_dest(VT_I8, hVal.QuadPart)
+}
+
#define SET_PROP_FUNC(type, id, dest) \
CPropVariant& CPropVariant::operator=(type value) throw() \
- { if (vt != id) { InternalClear(); vt = id; } \
- dest = value; return *this; }
+ { SET_PROP_id_dest(id, dest) return *this; }
SET_PROP_FUNC(Byte, VT_UI1, bVal)
// SET_PROP_FUNC(Int16, VT_I2, iVal)
-SET_PROP_FUNC(Int32, VT_I4, lVal)
+// SET_PROP_FUNC(Int32, VT_I4, lVal)
SET_PROP_FUNC(UInt32, VT_UI4, ulVal)
SET_PROP_FUNC(UInt64, VT_UI8, uhVal.QuadPart)
-SET_PROP_FUNC(Int64, VT_I8, hVal.QuadPart)
+// SET_PROP_FUNC(Int64, VT_I8, hVal.QuadPart)
SET_PROP_FUNC(const FILETIME &, VT_FILETIME, filetime)
+#define CASE_SIMPLE_VT_VALUES \
+ case VT_EMPTY: \
+ case VT_BOOL: \
+ case VT_FILETIME: \
+ case VT_UI8: \
+ case VT_UI4: \
+ case VT_UI2: \
+ case VT_UI1: \
+ case VT_I8: \
+ case VT_I4: \
+ case VT_I2: \
+ case VT_I1: \
+ case VT_UINT: \
+ case VT_INT: \
+ case VT_NULL: \
+ case VT_ERROR: \
+ case VT_R4: \
+ case VT_R8: \
+ case VT_CY: \
+ case VT_DATE: \
+
+
+/*
+ ::VariantClear() and ::VariantCopy() don't work, if (vt == VT_FILETIME)
+ So we handle VT_FILETIME and another simple types directly
+ we call system functions for VT_BSTR and for unknown typed
+*/
+
+CPropVariant::~CPropVariant() throw()
+{
+ switch ((unsigned)vt)
+ {
+ CASE_SIMPLE_VT_VALUES
+ // vt = VT_EMPTY; // it's optional
+ return;
+ }
+ ::VariantClear((tagVARIANT *)this);
+}
+
HRESULT PropVariant_Clear(PROPVARIANT *prop) throw()
{
- switch (prop->vt)
+ switch ((unsigned)prop->vt)
{
- case VT_EMPTY:
- case VT_UI1:
- case VT_I1:
- case VT_I2:
- case VT_UI2:
- case VT_BOOL:
- case VT_I4:
- case VT_UI4:
- case VT_R4:
- case VT_INT:
- case VT_UINT:
- case VT_ERROR:
- case VT_FILETIME:
- case VT_UI8:
- case VT_R8:
- case VT_CY:
- case VT_DATE:
+ CASE_SIMPLE_VT_VALUES
prop->vt = VT_EMPTY;
- prop->wReserved1 = 0;
- prop->wReserved2 = 0;
- prop->wReserved3 = 0;
- prop->uhVal.QuadPart = 0;
- return S_OK;
+ break;
+ default:
+ {
+ const HRESULT res = ::VariantClear((VARIANTARG *)prop);
+ if (res != S_OK || prop->vt != VT_EMPTY)
+ return res;
+ break;
+ }
}
- return ::VariantClear((VARIANTARG *)prop);
- // return ::PropVariantClear(prop);
- // PropVariantClear can clear VT_BLOB.
+ prop->wReserved1 = 0;
+ prop->wReserved2 = 0;
+ prop->wReserved3 = 0;
+ prop->uhVal.QuadPart = 0;
+ return S_OK;
}
HRESULT CPropVariant::Clear() throw()
{
if (vt == VT_EMPTY)
+ {
+ wReserved1 = 0;
return S_OK;
+ }
return PropVariant_Clear(this);
}
HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) throw()
{
- ::VariantClear((tagVARIANT *)this);
- switch (pSrc->vt)
+ Clear();
+ switch ((unsigned)pSrc->vt)
{
- case VT_UI1:
- case VT_I1:
- case VT_I2:
- case VT_UI2:
- case VT_BOOL:
- case VT_I4:
- case VT_UI4:
- case VT_R4:
- case VT_INT:
- case VT_UINT:
- case VT_ERROR:
- case VT_FILETIME:
- case VT_UI8:
- case VT_R8:
- case VT_CY:
- case VT_DATE:
+ CASE_SIMPLE_VT_VALUES
memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));
return S_OK;
}
@@ -275,11 +303,13 @@ HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) throw()
HRESULT CPropVariant::Attach(PROPVARIANT *pSrc) throw()
{
- HRESULT hr = Clear();
+ const HRESULT hr = Clear();
if (FAILED(hr))
return hr;
- memcpy(this, pSrc, sizeof(PROPVARIANT));
+ // memcpy((PROPVARIANT *)this, pSrc, sizeof(PROPVARIANT));
+ *(PROPVARIANT *)this = *pSrc;
pSrc->vt = VT_EMPTY;
+ pSrc->wReserved1 = 0;
return S_OK;
}
@@ -287,20 +317,25 @@ HRESULT CPropVariant::Detach(PROPVARIANT *pDest) throw()
{
if (pDest->vt != VT_EMPTY)
{
- HRESULT hr = PropVariant_Clear(pDest);
+ const HRESULT hr = PropVariant_Clear(pDest);
if (FAILED(hr))
return hr;
}
- memcpy(pDest, this, sizeof(PROPVARIANT));
+ // memcpy(pDest, this, sizeof(PROPVARIANT));
+ *pDest = *(PROPVARIANT *)this;
vt = VT_EMPTY;
+ wReserved1 = 0;
return S_OK;
}
HRESULT CPropVariant::InternalClear() throw()
{
if (vt == VT_EMPTY)
+ {
+ wReserved1 = 0;
return S_OK;
- HRESULT hr = Clear();
+ }
+ const HRESULT hr = Clear();
if (FAILED(hr))
{
vt = VT_ERROR;
@@ -311,7 +346,7 @@ HRESULT CPropVariant::InternalClear() throw()
void CPropVariant::InternalCopy(const PROPVARIANT *pSrc)
{
- HRESULT hr = Copy(pSrc);
+ const HRESULT hr = Copy(pSrc);
if (FAILED(hr))
{
if (hr == E_OUTOFMEMORY)
@@ -321,11 +356,12 @@ void CPropVariant::InternalCopy(const PROPVARIANT *pSrc)
}
}
+
int CPropVariant::Compare(const CPropVariant &a) throw()
{
if (vt != a.vt)
return MyCompare(vt, a.vt);
- switch (vt)
+ switch ((unsigned)vt)
{
case VT_EMPTY: return 0;
// case VT_I1: return MyCompare(cVal, a.cVal);
@@ -338,7 +374,15 @@ int CPropVariant::Compare(const CPropVariant &a) throw()
case VT_I8: return MyCompare(hVal.QuadPart, a.hVal.QuadPart);
case VT_UI8: return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);
case VT_BOOL: return -MyCompare(boolVal, a.boolVal);
- case VT_FILETIME: return ::CompareFileTime(&filetime, &a.filetime);
+ case VT_FILETIME:
+ {
+ const int res = CompareFileTime(&filetime, &a.filetime);
+ if (res != 0)
+ return res;
+ const unsigned v1 = Get_Ns100();
+ const unsigned v2 = a.Get_Ns100();
+ return MyCompare(v1, v2);
+ }
case VT_BSTR: return 0; // Not implemented
default: return 0;
}
diff --git a/3rdparty/lzma/CPP/Windows/PropVariant.h b/3rdparty/lzma/CPP/Windows/PropVariant.h
index 3610d6a8085..f358fdea12f 100644
--- a/3rdparty/lzma/CPP/Windows/PropVariant.h
+++ b/3rdparty/lzma/CPP/Windows/PropVariant.h
@@ -1,7 +1,7 @@
// Windows/PropVariant.h
-#ifndef __WINDOWS_PROP_VARIANT_H
-#define __WINDOWS_PROP_VARIANT_H
+#ifndef ZIP7_INC_WINDOWS_PROP_VARIANT_H
+#define ZIP7_INC_WINDOWS_PROP_VARIANT_H
#include "../Common/MyTypes.h"
#include "../Common/MyWindows.h"
@@ -29,11 +29,14 @@ inline void PropVarEm_Set_UInt64(PROPVARIANT *p, UInt64 v) throw()
p->uhVal.QuadPart = v;
}
-inline void PropVarEm_Set_FileTime64(PROPVARIANT *p, UInt64 v) throw()
+inline void PropVarEm_Set_FileTime64_Prec(PROPVARIANT *p, UInt64 v, unsigned prec) throw()
{
p->vt = VT_FILETIME;
p->filetime.dwLowDateTime = (DWORD)v;
p->filetime.dwHighDateTime = (DWORD)(v >> 32);
+ p->wReserved1 = (WORD)prec;
+ p->wReserved2 = 0;
+ p->wReserved3 = 0;
}
inline void PropVarEm_Set_Bool(PROPVARIANT *p, bool b) throw()
@@ -45,6 +48,14 @@ inline void PropVarEm_Set_Bool(PROPVARIANT *p, bool b) throw()
class CPropVariant : public tagPROPVARIANT
{
+ // ---------- forbidden functions ----------
+ CPropVariant(const char *s);
+ // CPropVariant(const UString &s);
+ #ifdef DEBUG_FSTRING_INHERITS_ASTRING
+ CPropVariant(const FString &s);
+ CPropVariant& operator=(const FString &s);
+ #endif
+
public:
CPropVariant()
{
@@ -53,9 +64,53 @@ public:
// wReserved2 = 0;
// wReserved3 = 0;
// uhVal.QuadPart = 0;
- bstrVal = 0;
+ bstrVal = NULL;
+ }
+
+
+ void Set_FtPrec(unsigned prec)
+ {
+ wReserved1 = (WORD)prec;
+ wReserved2 = 0;
+ wReserved3 = 0;
+ }
+
+ void SetAsTimeFrom_FT_Prec(const FILETIME &ft, unsigned prec)
+ {
+ operator=(ft);
+ Set_FtPrec(prec);
+ }
+
+ void SetAsTimeFrom_Ft64_Prec(UInt64 v, unsigned prec)
+ {
+ FILETIME ft;
+ ft.dwLowDateTime = (DWORD)(UInt32)v;
+ ft.dwHighDateTime = (DWORD)(UInt32)(v >> 32);
+ operator=(ft);
+ Set_FtPrec(prec);
+ }
+
+ void SetAsTimeFrom_FT_Prec_Ns100(const FILETIME &ft, unsigned prec, unsigned ns100)
+ {
+ operator=(ft);
+ wReserved1 = (WORD)prec;
+ wReserved2 = (WORD)ns100;
+ wReserved3 = 0;
+ }
+
+ unsigned Get_Ns100() const
+ {
+ const unsigned prec = wReserved1;
+ const unsigned ns100 = wReserved2;
+ if (prec == 0
+ && prec <= k_PropVar_TimePrec_1ns
+ && ns100 < 100
+ && wReserved3 == 0)
+ return ns100;
+ return 0;
}
- ~CPropVariant() throw() { Clear(); }
+
+ ~CPropVariant() throw();
CPropVariant(const PROPVARIANT &varSrc);
CPropVariant(const CPropVariant &varSrc);
CPropVariant(BSTR bstrSrc);
@@ -64,13 +119,14 @@ public:
CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
private:
+ CPropVariant(UInt16 value); // { vt = VT_UI2; wReserved1 = 0; uiVal = value; }
CPropVariant(Int16 value); // { vt = VT_I2; wReserved1 = 0; iVal = value; }
CPropVariant(Int32 value); // { vt = VT_I4; wReserved1 = 0; lVal = value; }
+ CPropVariant(Int64 value); // { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = value; }
public:
CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; }
- CPropVariant(Int64 value) { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = value; }
CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
CPropVariant& operator=(const CPropVariant &varSrc);
@@ -80,20 +136,26 @@ public:
CPropVariant& operator=(const UString &s);
CPropVariant& operator=(const UString2 &s);
CPropVariant& operator=(const char *s);
+ CPropVariant& operator=(const AString &s)
+ { return (*this)=(const char *)s; }
CPropVariant& operator=(bool bSrc) throw();
CPropVariant& operator=(Byte value) throw();
private:
CPropVariant& operator=(Int16 value) throw();
+ CPropVariant& operator=(UInt16 value) throw();
+ CPropVariant& operator=(Int32 value) throw();
+ CPropVariant& operator=(Int64 value) throw();
public:
- CPropVariant& operator=(Int32 value) throw();
CPropVariant& operator=(UInt32 value) throw();
CPropVariant& operator=(UInt64 value) throw();
- CPropVariant& operator=(Int64 value) throw();
CPropVariant& operator=(const FILETIME &value) throw();
+ void Set_Int32(Int32 value) throw();
+ void Set_Int64(Int64 value) throw();
+
BSTR AllocBstr(unsigned numChars);
HRESULT Clear() throw();
@@ -103,7 +165,6 @@ public:
HRESULT InternalClear() throw();
void InternalCopy(const PROPVARIANT *pSrc);
-
int Compare(const CPropVariant &a) throw();
};
diff --git a/3rdparty/lzma/CPP/Windows/PropVariantConv.cpp b/3rdparty/lzma/CPP/Windows/PropVariantConv.cpp
index fe86f9365f0..5fb96a7c53a 100644
--- a/3rdparty/lzma/CPP/Windows/PropVariantConv.cpp
+++ b/3rdparty/lzma/CPP/Windows/PropVariantConv.cpp
@@ -1,4 +1,4 @@
-// PropVariantConvert.cpp
+// PropVariantConv.cpp
#include "StdAfx.h"
@@ -9,63 +9,120 @@
#define UINT_TO_STR_2(c, val) { s[0] = (c); s[1] = (char)('0' + (val) / 10); s[2] = (char)('0' + (val) % 10); s += 3; }
-bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) throw()
+bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, int level) throw()
{
+ *s = 0;
+ FILETIME ft;
+ if (!FileTimeToLocalFileTime(&utc, &ft))
+ return false;
+
SYSTEMTIME st;
if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
{
- *s = 0;
+ // win10 : that function doesn't work, if bit 63 of 64-bit FILETIME is set.
return false;
}
- unsigned val = st.wYear;
- if (val >= 10000)
- {
- *s++ = (char)('0' + val / 10000);
- val %= 10000;
- }
+
{
+ unsigned val = st.wYear;
+ if (val >= 10000)
+ {
+ *s++ = (char)('0' + val / 10000);
+ val %= 10000;
+ }
s[3] = (char)('0' + val % 10); val /= 10;
s[2] = (char)('0' + val % 10); val /= 10;
s[1] = (char)('0' + val % 10);
s[0] = (char)('0' + val / 10);
s += 4;
}
- UINT_TO_STR_2('-', st.wMonth);
- UINT_TO_STR_2('-', st.wDay);
- if (includeTime)
+ UINT_TO_STR_2('-', st.wMonth)
+ UINT_TO_STR_2('-', st.wDay)
+
+ if (level > kTimestampPrintLevel_DAY)
{
- UINT_TO_STR_2(' ', st.wHour);
- UINT_TO_STR_2(':', st.wMinute);
- if (includeSeconds)
+ UINT_TO_STR_2(' ', st.wHour)
+ UINT_TO_STR_2(':', st.wMinute)
+
+ if (level >= kTimestampPrintLevel_SEC)
{
- UINT_TO_STR_2(':', st.wSecond);
- /*
- *s++ = '.';
- unsigned val = st.wMilliseconds;
- s[2] = (char)('0' + val % 10); val /= 10;
- s[1] = (char)('0' + val % 10);
- s[0] = (char)('0' + val / 10);
- s += 3;
- */
+ UINT_TO_STR_2(':', st.wSecond)
+
+ if (level > kTimestampPrintLevel_SEC)
+ {
+ *s++ = '.';
+ /*
+ {
+ unsigned val = st.wMilliseconds;
+ s[2] = (char)('0' + val % 10); val /= 10;
+ s[1] = (char)('0' + val % 10);
+ s[0] = (char)('0' + val / 10);
+ s += 3;
+ }
+ *s++ = ' ';
+ */
+
+ {
+ unsigned numDigits = 7;
+ UInt32 val = (UInt32)((((UInt64)ft.dwHighDateTime << 32) + ft.dwLowDateTime) % 10000000);
+ for (unsigned i = numDigits; i != 0;)
+ {
+ i--;
+ s[i] = (char)('0' + val % 10); val /= 10;
+ }
+ if (numDigits > (unsigned)level)
+ numDigits = (unsigned)level;
+ s += numDigits;
+ }
+ if (level >= kTimestampPrintLevel_NTFS + 1)
+ {
+ *s++ = (char)('0' + (ns100 / 10));
+ if (level >= kTimestampPrintLevel_NTFS + 2)
+ *s++ = (char)('0' + (ns100 % 10));
+ }
+ }
}
}
+
*s = 0;
return true;
}
-void ConvertFileTimeToString(const FILETIME &ft, wchar_t *dest, bool includeTime, bool includeSeconds) throw()
+
+bool ConvertUtcFileTimeToString(const FILETIME &utc, char *s, int level) throw()
+{
+ return ConvertUtcFileTimeToString2(utc, 0, s, level);
+}
+
+bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, wchar_t *dest, int level) throw()
{
char s[32];
- ConvertFileTimeToString(ft, s, includeTime, includeSeconds);
+ bool res = ConvertUtcFileTimeToString2(ft, ns100, s, level);
for (unsigned i = 0;; i++)
{
- unsigned char c = s[i];
+ Byte c = (Byte)s[i];
dest[i] = c;
if (c == 0)
- return;
+ break;
+ }
+ return res;
+}
+
+bool ConvertUtcFileTimeToString(const FILETIME &ft, wchar_t *dest, int level) throw()
+{
+ char s[32];
+ bool res = ConvertUtcFileTimeToString(ft, s, level);
+ for (unsigned i = 0;; i++)
+ {
+ Byte c = (Byte)s[i];
+ dest[i] = c;
+ if (c == 0)
+ break;
}
+ return res;
}
+
void ConvertPropVariantToShortString(const PROPVARIANT &prop, char *dest) throw()
{
*dest = 0;
@@ -77,7 +134,19 @@ void ConvertPropVariantToShortString(const PROPVARIANT &prop, char *dest) throw(
case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
- case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
+ case VT_FILETIME:
+ {
+ // const unsigned prec = prop.wReserved1;
+ int level = 0;
+ /*
+ if (prec == 0)
+ level = 7;
+ else if (prec > 16 && prec <= 16 + 9)
+ level = prec - 16;
+ */
+ ConvertUtcFileTimeToString(prop.filetime, dest, level);
+ return;
+ }
// case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
@@ -98,7 +167,19 @@ void ConvertPropVariantToShortString(const PROPVARIANT &prop, wchar_t *dest) thr
case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
- case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
+ case VT_FILETIME:
+ {
+ // const unsigned prec = prop.wReserved1;
+ int level = 0;
+ /*
+ if (prec == 0)
+ level = 7;
+ else if (prec > 16 && prec <= 16 + 9)
+ level = prec - 16;
+ */
+ ConvertUtcFileTimeToString(prop.filetime, dest, level);
+ return;
+ }
// case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
diff --git a/3rdparty/lzma/CPP/Windows/PropVariantConv.h b/3rdparty/lzma/CPP/Windows/PropVariantConv.h
index 5d26357f08d..ec5223bd9c5 100644
--- a/3rdparty/lzma/CPP/Windows/PropVariantConv.h
+++ b/3rdparty/lzma/CPP/Windows/PropVariantConv.h
@@ -1,13 +1,23 @@
// Windows/PropVariantConv.h
-#ifndef __PROP_VARIANT_CONV_H
-#define __PROP_VARIANT_CONV_H
+#ifndef ZIP7_INC_PROP_VARIANT_CONV_H
+#define ZIP7_INC_PROP_VARIANT_CONV_H
#include "../Common/MyTypes.h"
// provide at least 32 bytes for buffer including zero-end
-bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true) throw();
-void ConvertFileTimeToString(const FILETIME &ft, wchar_t *s, bool includeTime = true, bool includeSeconds = true) throw();
+
+#define kTimestampPrintLevel_DAY -3
+// #define kTimestampPrintLevel_HOUR -2
+#define kTimestampPrintLevel_MIN -1
+#define kTimestampPrintLevel_SEC 0
+#define kTimestampPrintLevel_NTFS 7
+#define kTimestampPrintLevel_NS 9
+
+bool ConvertUtcFileTimeToString(const FILETIME &ft, char *s, int level = kTimestampPrintLevel_SEC) throw();
+bool ConvertUtcFileTimeToString(const FILETIME &ft, wchar_t *s, int level = kTimestampPrintLevel_SEC) throw();
+bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, char *s, int level = kTimestampPrintLevel_SEC) throw();
+bool ConvertUtcFileTimeToString2(const FILETIME &ft, unsigned ns100, wchar_t *s, int level = kTimestampPrintLevel_SEC) throw();
// provide at least 32 bytes for buffer including zero-end
// don't send VT_BSTR to these functions
diff --git a/3rdparty/lzma/CPP/Windows/Registry.cpp b/3rdparty/lzma/CPP/Windows/Registry.cpp
index c000e62897d..b20157d5a2b 100644
--- a/3rdparty/lzma/CPP/Windows/Registry.cpp
+++ b/3rdparty/lzma/CPP/Windows/Registry.cpp
@@ -3,6 +3,7 @@
#include "StdAfx.h"
#include <wchar.h>
+// #include <stdio.h>
#ifndef _UNICODE
#include "../Common/StringConvert.h"
@@ -17,12 +18,27 @@ namespace NWindows {
namespace NRegistry {
#define MYASSERT(expr) // _ASSERTE(expr)
+#define MY_ASSUME(expr)
+
+/*
+static void Error()
+{
+ #ifdef _CONSOLE
+ printf("\nregistry error\n");
+ #else
+ MessageBoxW(0, L"registry error", L"", 0);
+ // exit(1);
+ #endif
+}
+
+#define MY_ASSUME(expr) { if (!(expr)) Error(); }
+*/
LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LPTSTR keyClass, DWORD options, REGSAM accessMask,
LPSECURITY_ATTRIBUTES securityAttributes, LPDWORD disposition) throw()
{
- MYASSERT(parentKey != NULL);
+ MY_ASSUME(parentKey != NULL);
DWORD dispositionReal;
HKEY key = NULL;
LONG res = RegCreateKeyEx(parentKey, keyName, 0, keyClass,
@@ -39,7 +55,7 @@ LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LONG CKey::Open(HKEY parentKey, LPCTSTR keyName, REGSAM accessMask) throw()
{
- MYASSERT(parentKey != NULL);
+ MY_ASSUME(parentKey != NULL);
HKEY key = NULL;
LONG res = RegOpenKeyEx(parentKey, keyName, 0, accessMask, &key);
if (res == ERROR_SUCCESS)
@@ -66,7 +82,7 @@ LONG CKey::Close() throw()
// winNT to be deleted must not have subkeys
LONG CKey::DeleteSubKey(LPCTSTR subKeyName) throw()
{
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return RegDeleteKey(_object, subKeyName);
}
@@ -101,14 +117,14 @@ static inline bool UINT32ToBool(UInt32 value) { return (value != 0); }
LONG CKey::DeleteValue(LPCTSTR name) throw()
{
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return ::RegDeleteValue(_object, name);
}
#ifndef _UNICODE
LONG CKey::DeleteValue(LPCWSTR name)
{
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
if (g_IsNT)
return ::RegDeleteValueW(_object, name);
return DeleteValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name));
@@ -117,9 +133,9 @@ LONG CKey::DeleteValue(LPCWSTR name)
LONG CKey::SetValue(LPCTSTR name, UInt32 value) throw()
{
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_DWORD,
- (BYTE * const)&value, sizeof(UInt32));
+ (const BYTE *)&value, sizeof(UInt32));
}
LONG CKey::SetValue(LPCTSTR name, bool value) throw()
@@ -130,16 +146,16 @@ LONG CKey::SetValue(LPCTSTR name, bool value) throw()
LONG CKey::SetValue(LPCTSTR name, LPCTSTR value) throw()
{
MYASSERT(value != NULL);
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_SZ,
- (const BYTE * )value, (lstrlen(value) + 1) * sizeof(TCHAR));
+ (const BYTE *)value, ((DWORD)lstrlen(value) + 1) * sizeof(TCHAR));
}
/*
LONG CKey::SetValue(LPCTSTR name, const CSysString &value)
{
MYASSERT(value != NULL);
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, NULL, REG_SZ,
(const BYTE *)(const TCHAR *)value, (value.Len() + 1) * sizeof(TCHAR));
}
@@ -150,9 +166,9 @@ LONG CKey::SetValue(LPCTSTR name, const CSysString &value)
LONG CKey::SetValue(LPCWSTR name, LPCWSTR value)
{
MYASSERT(value != NULL);
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
if (g_IsNT)
- return RegSetValueExW(_object, name, NULL, REG_SZ,
+ return RegSetValueExW(_object, name, 0, REG_SZ,
(const BYTE * )value, (DWORD)((wcslen(value) + 1) * sizeof(wchar_t)));
return SetValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name),
value == 0 ? 0 : (LPCSTR)GetSystemString(value));
@@ -164,7 +180,7 @@ LONG CKey::SetValue(LPCWSTR name, LPCWSTR value)
LONG CKey::SetValue(LPCTSTR name, const void *value, UInt32 size) throw()
{
MYASSERT(value != NULL);
- MYASSERT(_object != NULL);
+ MY_ASSUME(_object != NULL);
return RegSetValueEx(_object, name, 0, REG_BINARY,
(const BYTE *)value, size);
}
@@ -193,7 +209,7 @@ LONG CKey::QueryValue(LPCTSTR name, UInt32 &value) throw()
{
DWORD type = 0;
DWORD count = sizeof(DWORD);
- LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type,
+ LONG res = RegQueryValueEx(_object, name, NULL, &type,
(LPBYTE)&value, &count);
MYASSERT((res != ERROR_SUCCESS) || (type == REG_DWORD));
MYASSERT((res != ERROR_SUCCESS) || (count == sizeof(UInt32)));
@@ -219,7 +235,7 @@ LONG CKey::GetValue_IfOk(LPCTSTR name, UInt32 &value) throw()
LONG CKey::GetValue_IfOk(LPCTSTR name, bool &value) throw()
{
- bool newVal;
+ bool newVal = false;
LONG res = QueryValue(name, newVal);
if (res == ERROR_SUCCESS)
value = newVal;
@@ -229,7 +245,7 @@ LONG CKey::GetValue_IfOk(LPCTSTR name, bool &value) throw()
LONG CKey::QueryValue(LPCTSTR name, LPTSTR value, UInt32 &count) throw()
{
DWORD type = 0;
- LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
+ LONG res = RegQueryValueEx(_object, name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
MYASSERT((res != ERROR_SUCCESS) || (type == REG_SZ) || (type == REG_MULTI_SZ) || (type == REG_EXPAND_SZ));
return res;
}
@@ -239,7 +255,7 @@ LONG CKey::QueryValue(LPCTSTR name, CSysString &value)
value.Empty();
DWORD type = 0;
UInt32 curSize = 0;
- LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, NULL, (DWORD *)&curSize);
+ LONG res = RegQueryValueEx(_object, name, NULL, &type, NULL, (DWORD *)&curSize);
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
return res;
UInt32 curSize2 = curSize;
@@ -296,7 +312,7 @@ LONG CKey::QueryValue(LPCWSTR name, UString &value)
LONG CKey::QueryValue(LPCTSTR name, void *value, UInt32 &count) throw()
{
DWORD type = 0;
- LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
+ LONG res = RegQueryValueEx(_object, name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
MYASSERT((res != ERROR_SUCCESS) || (type == REG_BINARY));
return res;
}
@@ -306,7 +322,7 @@ LONG CKey::QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize)
{
DWORD type = 0;
dataSize = 0;
- LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, NULL, (DWORD *)&dataSize);
+ LONG res = RegQueryValueEx(_object, name, NULL, &type, NULL, (DWORD *)&dataSize);
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
return res;
value.Alloc(dataSize);
@@ -369,7 +385,7 @@ LONG CKey::GetValue_Strings(LPCTSTR valueName, UStringVector &strings)
if (dataSize % sizeof(wchar_t) != 0)
return E_FAIL;
- const wchar_t *data = (const wchar_t *)(const Byte *)buffer;
+ const wchar_t *data = (const wchar_t *)(const void *)(const Byte *)buffer;
size_t numChars = dataSize / sizeof(wchar_t);
size_t prev = 0;
UString s;
diff --git a/3rdparty/lzma/CPP/Windows/Registry.h b/3rdparty/lzma/CPP/Windows/Registry.h
index ca79dfe3cda..0d3b4fcc3d5 100644
--- a/3rdparty/lzma/CPP/Windows/Registry.h
+++ b/3rdparty/lzma/CPP/Windows/Registry.h
@@ -1,7 +1,7 @@
// Windows/Registry.h
-#ifndef __WINDOWS_REGISTRY_H
-#define __WINDOWS_REGISTRY_H
+#ifndef ZIP7_INC_WINDOWS_REGISTRY_H
+#define ZIP7_INC_WINDOWS_REGISTRY_H
#include "../Common/MyBuffer.h"
#include "../Common/MyString.h"
diff --git a/3rdparty/lzma/CPP/Windows/ResourceString.cpp b/3rdparty/lzma/CPP/Windows/ResourceString.cpp
index cc8b964a213..ae8182ed4e4 100644
--- a/3rdparty/lzma/CPP/Windows/ResourceString.cpp
+++ b/3rdparty/lzma/CPP/Windows/ResourceString.cpp
@@ -25,10 +25,10 @@ static CSysString MyLoadStringA(HINSTANCE hInstance, UINT resourceID)
do
{
size <<= 1;
- len = ::LoadString(hInstance, resourceID, s.GetBuf(size - 1), size);
+ len = ::LoadString(hInstance, resourceID, s.GetBuf((unsigned)size - 1), size);
}
while (size - len <= 1);
- s.ReleaseBuf_CalcLen(len);
+ s.ReleaseBuf_CalcLen((unsigned)len);
return s;
}
@@ -43,10 +43,10 @@ static void MyLoadString2(HINSTANCE hInstance, UINT resourceID, UString &s)
do
{
size <<= 1;
- len = ::LoadStringW(hInstance, resourceID, s.GetBuf(size - 1), size);
+ len = ::LoadStringW(hInstance, resourceID, s.GetBuf((unsigned)size - 1), size);
}
while (size - len <= 1);
- s.ReleaseBuf_CalcLen(len);
+ s.ReleaseBuf_CalcLen((unsigned)len);
}
// NT4 doesn't support LoadStringW(,,, 0) to get pointer to resource string. So we don't use it.
diff --git a/3rdparty/lzma/CPP/Windows/ResourceString.h b/3rdparty/lzma/CPP/Windows/ResourceString.h
index f0bdabf47fe..773307b931c 100644
--- a/3rdparty/lzma/CPP/Windows/ResourceString.h
+++ b/3rdparty/lzma/CPP/Windows/ResourceString.h
@@ -1,9 +1,10 @@
// Windows/ResourceString.h
-#ifndef __WINDOWS_RESOURCE_STRING_H
-#define __WINDOWS_RESOURCE_STRING_H
+#ifndef ZIP7_INC_WINDOWS_RESOURCE_STRING_H
+#define ZIP7_INC_WINDOWS_RESOURCE_STRING_H
#include "../Common/MyString.h"
+#include "../Common/MyWindows.h"
namespace NWindows {
diff --git a/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp b/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
index 67a9d7fdcb3..d4282d070c2 100644
--- a/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
+++ b/3rdparty/lzma/CPP/Windows/SecurityUtils.cpp
@@ -2,8 +2,6 @@
#include "StdAfx.h"
-#include "../Common/MyString.h"
-
#include "SecurityUtils.h"
namespace NWindows {
@@ -34,7 +32,7 @@ bool MyLookupAccountSid(LPCTSTR systemName, PSID sid,
static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest)
{
- int len = (int)wcslen(src);
+ const size_t len = (size_t)wcslen(src);
dest->Length = (USHORT)(len * sizeof(WCHAR));
dest->MaximumLength = (USHORT)((len + 1) * sizeof(WCHAR));
dest->Buffer = src;
@@ -52,8 +50,10 @@ static void MyLookupSids(CPolicy &policy, PSID ps)
}
*/
+extern "C" {
+
#ifndef _UNICODE
-typedef BOOL (WINAPI * LookupAccountNameWP)(
+typedef BOOL (WINAPI * Func_LookupAccountNameW)(
LPCWSTR lpSystemName,
LPCWSTR lpAccountName,
PSID Sid,
@@ -64,14 +64,19 @@ typedef BOOL (WINAPI * LookupAccountNameWP)(
);
#endif
+}
+
static PSID GetSid(LPWSTR accountName)
{
#ifndef _UNICODE
- HMODULE hModule = GetModuleHandle(TEXT("Advapi32.dll"));
- if (hModule == NULL)
+ const HMODULE hModule = GetModuleHandle(TEXT("advapi32.dll"));
+ if (!hModule)
return NULL;
- LookupAccountNameWP lookupAccountNameW = (LookupAccountNameWP)GetProcAddress(hModule, "LookupAccountNameW");
- if (lookupAccountNameW == NULL)
+ const
+ Func_LookupAccountNameW lookupAccountNameW = Z7_GET_PROC_ADDRESS(
+ Func_LookupAccountNameW, hModule,
+ "LookupAccountNameW");
+ if (!lookupAccountNameW)
return NULL;
#endif
@@ -81,21 +86,21 @@ static PSID GetSid(LPWSTR accountName)
#ifdef _UNICODE
::LookupAccountNameW
#else
- lookupAccountNameW
+ lookupAccountNameW
#endif
- (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse))
+ (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse))
{
if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
- PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen);
+ const PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen);
LPWSTR domainName = (LPWSTR)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (domainLen + 1) * sizeof(WCHAR));
- BOOL res =
+ const BOOL res =
#ifdef _UNICODE
::LookupAccountNameW
#else
- lookupAccountNameW
+ lookupAccountNameW
#endif
- (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse);
+ (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse);
::HeapFree(GetProcessHeap(), 0, domainName);
if (res)
return pSid;
@@ -104,7 +109,7 @@ static PSID GetSid(LPWSTR accountName)
return NULL;
}
-#define MY__SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege"
+#define Z7_WIN_SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege"
bool AddLockMemoryPrivilege()
{
@@ -124,13 +129,13 @@ bool AddLockMemoryPrivilege()
!= 0)
return false;
LSA_UNICODE_STRING userRights;
- wchar_t s[128] = MY__SE_LOCK_MEMORY_NAME;
+ wchar_t s[128] = Z7_WIN_SE_LOCK_MEMORY_NAME;
SetLsaString(s, &userRights);
WCHAR userName[256 + 2];
DWORD size = 256;
if (!GetUserNameW(userName, &size))
return false;
- PSID psid = GetSid(userName);
+ const PSID psid = GetSid(userName);
if (psid == NULL)
return false;
bool res = false;
@@ -169,7 +174,7 @@ bool AddLockMemoryPrivilege()
res = true;
}
*/
- NTSTATUS status = policy.AddAccountRights(psid, &userRights);
+ const NTSTATUS status = policy.AddAccountRights(psid, &userRights);
if (status == 0)
res = true;
// ULONG res = LsaNtStatusToWinError(status);
diff --git a/3rdparty/lzma/CPP/Windows/SecurityUtils.h b/3rdparty/lzma/CPP/Windows/SecurityUtils.h
index 8966dfd3b7d..4ef3939f8e4 100644
--- a/3rdparty/lzma/CPP/Windows/SecurityUtils.h
+++ b/3rdparty/lzma/CPP/Windows/SecurityUtils.h
@@ -1,12 +1,37 @@
// Windows/SecurityUtils.h
-#ifndef __WINDOWS_SECURITY_UTILS_H
-#define __WINDOWS_SECURITY_UTILS_H
+#ifndef ZIP7_INC_WINDOWS_SECURITY_UTILS_H
+#define ZIP7_INC_WINDOWS_SECURITY_UTILS_H
#include <NTSecAPI.h>
#include "Defs.h"
+#ifndef _UNICODE
+
+extern "C" {
+typedef NTSTATUS (NTAPI *Func_LsaOpenPolicy)(PLSA_UNICODE_STRING SystemName,
+ PLSA_OBJECT_ATTRIBUTES ObjectAttributes, ACCESS_MASK DesiredAccess, PLSA_HANDLE PolicyHandle);
+typedef NTSTATUS (NTAPI *Func_LsaClose)(LSA_HANDLE ObjectHandle);
+typedef NTSTATUS (NTAPI *Func_LsaAddAccountRights)(LSA_HANDLE PolicyHandle,
+ PSID AccountSid, PLSA_UNICODE_STRING UserRights, ULONG CountOfRights );
+#define MY_STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
+}
+
+#define POLICY_FUNC_CALL(fff, str) \
+ if (hModule == NULL) return MY_STATUS_NOT_IMPLEMENTED; \
+ const Func_ ## fff v = Z7_GET_PROC_ADDRESS(Func_ ## fff, hModule, str); \
+ if (!v) return MY_STATUS_NOT_IMPLEMENTED; \
+ const NTSTATUS res = v
+
+#else
+
+#define POLICY_FUNC_CALL(fff, str) \
+ const NTSTATUS res = ::fff
+
+#endif
+
+
namespace NWindows {
namespace NSecurity {
@@ -14,7 +39,7 @@ class CAccessToken
{
HANDLE _handle;
public:
- CAccessToken(): _handle(NULL) {};
+ CAccessToken(): _handle(NULL) {}
~CAccessToken() { Close(); }
bool Close()
{
@@ -53,15 +78,9 @@ public:
};
-#ifndef _UNICODE
-typedef NTSTATUS (NTAPI *LsaOpenPolicyP)(PLSA_UNICODE_STRING SystemName,
- PLSA_OBJECT_ATTRIBUTES ObjectAttributes, ACCESS_MASK DesiredAccess, PLSA_HANDLE PolicyHandle);
-typedef NTSTATUS (NTAPI *LsaCloseP)(LSA_HANDLE ObjectHandle);
-typedef NTSTATUS (NTAPI *LsaAddAccountRightsP)(LSA_HANDLE PolicyHandle,
- PSID AccountSid, PLSA_UNICODE_STRING UserRights, ULONG CountOfRights );
-#define MY_STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
-#endif
+
+
struct CPolicy
{
protected:
@@ -74,51 +93,25 @@ public:
CPolicy(): _handle(NULL)
{
#ifndef _UNICODE
- hModule = GetModuleHandle(TEXT("Advapi32.dll"));
+ hModule = GetModuleHandle(TEXT("advapi32.dll"));
#endif
- };
+ }
~CPolicy() { Close(); }
NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes,
ACCESS_MASK desiredAccess)
{
- #ifndef _UNICODE
- if (hModule == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- LsaOpenPolicyP lsaOpenPolicy = (LsaOpenPolicyP)GetProcAddress(hModule, "LsaOpenPolicy");
- if (lsaOpenPolicy == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- #endif
-
Close();
- return
- #ifdef _UNICODE
- ::LsaOpenPolicy
- #else
- lsaOpenPolicy
- #endif
+ POLICY_FUNC_CALL (LsaOpenPolicy, "LsaOpenPolicy")
(systemName, objectAttributes, desiredAccess, &_handle);
+ return res;
}
NTSTATUS Close()
{
if (_handle == NULL)
return 0;
-
- #ifndef _UNICODE
- if (hModule == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- LsaCloseP lsaClose = (LsaCloseP)GetProcAddress(hModule, "LsaClose");
- if (lsaClose == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- #endif
-
- NTSTATUS res =
- #ifdef _UNICODE
- ::LsaClose
- #else
- lsaClose
- #endif
+ POLICY_FUNC_CALL (LsaClose, "LsaClose")
(_handle);
_handle = NULL;
return res;
@@ -137,21 +130,9 @@ public:
NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights, ULONG countOfRights)
{
- #ifndef _UNICODE
- if (hModule == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- LsaAddAccountRightsP lsaAddAccountRights = (LsaAddAccountRightsP)GetProcAddress(hModule, "LsaAddAccountRights");
- if (lsaAddAccountRights == NULL)
- return MY_STATUS_NOT_IMPLEMENTED;
- #endif
-
- return
- #ifdef _UNICODE
- ::LsaAddAccountRights
- #else
- lsaAddAccountRights
- #endif
+ POLICY_FUNC_CALL (LsaAddAccountRights, "LsaAddAccountRights")
(_handle, accountSid, userRights, countOfRights);
+ return res;
}
NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights)
{ return AddAccountRights(accountSid, userRights, 1); }
diff --git a/3rdparty/lzma/CPP/Windows/Shell.cpp b/3rdparty/lzma/CPP/Windows/Shell.cpp
index 8e82c14a726..b2a3489870d 100644
--- a/3rdparty/lzma/CPP/Windows/Shell.cpp
+++ b/3rdparty/lzma/CPP/Windows/Shell.cpp
@@ -3,17 +3,49 @@
#include "StdAfx.h"
#include "../Common/MyCom.h"
-#ifndef _UNICODE
#include "../Common/StringConvert.h"
-#endif
#include "COM.h"
+#include "FileName.h"
+#include "MemoryGlobal.h"
#include "Shell.h"
#ifndef _UNICODE
extern bool g_IsNT;
#endif
+// MSVC6 and old SDK don't support this function:
+// #define LWSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
+// LWSTDAPI StrRetToStrW(STRRET *pstr, LPCITEMIDLIST pidl, LPWSTR *ppsz);
+
+// #define SHOW_DEBUG_SHELL
+
+#ifdef SHOW_DEBUG_SHELL
+
+#include "../Common/IntToString.h"
+
+static void Print_Number(UInt32 number, const char *s)
+{
+ AString s2;
+ s2.Add_UInt32(number);
+ s2.Add_Space();
+ s2 += s;
+ OutputDebugStringA(s2);
+}
+
+#define ODS(sz) { OutputDebugStringA(sz); }
+#define ODS_U(s) { OutputDebugStringW(s); }
+#define ODS_(op) { op; }
+
+#else
+
+#define ODS(sz)
+#define ODS_U(s)
+#define ODS_(op)
+
+#endif
+
+
namespace NWindows {
namespace NShell {
@@ -23,12 +55,24 @@ namespace NShell {
void CItemIDList::Free()
{
- if (m_Object == NULL)
+ if (!m_Object)
return;
+ /* DOCs:
+ SHGetMalloc was introduced in Windows 95 and Microsoft Windows NT 4.0,
+ but as of Windows 2000 it is no longer necessary.
+ In its place, programs can call the equivalent (and easier to use) CoTaskMemAlloc and CoTaskMemFree.
+ Description from oldnewthings:
+ shell functions could work without COM (if OLE32.DLL is not loaded),
+ but now if OLE32.DLL is loaded, then shell functions and com functions do same things.
+ 22.02: so we use OLE32.DLL function to free memory:
+ */
+ /*
CMyComPtr<IMalloc> shellMalloc;
if (::SHGetMalloc(&shellMalloc) != NOERROR)
throw 41099;
shellMalloc->Free(m_Object);
+ */
+ CoTaskMemFree(m_Object);
m_Object = NULL;
}
@@ -65,9 +109,354 @@ CItemIDList& CItemIDList::operator=(const CItemIDList &object)
}
*/
+
+static HRESULT ReadUnicodeStrings(const wchar_t *p, size_t size, UStringVector &names)
+{
+ names.Clear();
+ const wchar_t *lim = p + size;
+ UString s;
+ /*
+ if (size == 0 || p[size - 1] != 0)
+ return E_INVALIDARG;
+ if (size == 1)
+ return S_OK;
+ if (p[size - 2] != 0)
+ return E_INVALIDARG;
+ */
+ for (;;)
+ {
+ const wchar_t *start = p;
+ for (;;)
+ {
+ if (p == lim) return E_INVALIDARG; // S_FALSE
+ if (*p++ == 0)
+ break;
+ }
+ const size_t num = (size_t)(p - start);
+ if (num == 1)
+ {
+ if (p != lim) return E_INVALIDARG; // S_FALSE
+ return S_OK;
+ }
+ s.SetFrom(start, (unsigned)(num - 1));
+ ODS_U(s)
+ names.Add(s);
+ // names.ReserveOnePosition();
+ // names.AddInReserved_Ptr_of_new(new UString((unsigned)num - 1, start));
+ }
+}
+
+
+static HRESULT ReadAnsiStrings(const char *p, size_t size, UStringVector &names)
+{
+ names.Clear();
+ AString name;
+ for (; size != 0; size--)
+ {
+ const char c = *p++;
+ if (c == 0)
+ {
+ if (name.IsEmpty())
+ return S_OK;
+ names.Add(GetUnicodeString(name));
+ name.Empty();
+ }
+ else
+ name += c;
+ }
+ return E_INVALIDARG;
+}
+
+
+#define INIT_FORMATETC_HGLOBAL(type) { (type), NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }
+
+static HRESULT DataObject_GetData_HGLOBAL(IDataObject *dataObject, CLIPFORMAT cf, NCOM::CStgMedium &medium)
+{
+ FORMATETC etc = INIT_FORMATETC_HGLOBAL(cf);
+ RINOK(dataObject->GetData(&etc, &medium))
+ if (medium.tymed != TYMED_HGLOBAL)
+ return E_INVALIDARG;
+ return S_OK;
+}
+
+static HRESULT DataObject_GetData_HDROP_Names(IDataObject *dataObject, UStringVector &names)
+{
+ names.Clear();
+ NCOM::CStgMedium medium;
+
+ /* Win10 : if (dataObject) is from IContextMenu::Initialize() and
+ if (len_of_path >= MAX_PATH (260) for some file in data object)
+ {
+ GetData() returns HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)
+ "The data area passed to a system call is too small",
+ Is there a way to fix this code for long paths?
+ } */
+
+ RINOK(DataObject_GetData_HGLOBAL(dataObject, CF_HDROP, medium))
+ const size_t blockSize = GlobalSize(medium.hGlobal);
+ if (blockSize < sizeof(DROPFILES))
+ return E_INVALIDARG;
+ NMemory::CGlobalLock dropLock(medium.hGlobal);
+ const DROPFILES *dropFiles = (const DROPFILES *)dropLock.GetPointer();
+ if (!dropFiles)
+ return E_INVALIDARG;
+ if (blockSize < dropFiles->pFiles
+ || dropFiles->pFiles < sizeof(DROPFILES)
+ // || dropFiles->pFiles != sizeof(DROPFILES)
+ )
+ return E_INVALIDARG;
+ const size_t size = blockSize - dropFiles->pFiles;
+ const void *namesData = (const Byte *)(const void *)dropFiles + dropFiles->pFiles;
+ HRESULT hres;
+ if (dropFiles->fWide)
+ {
+ if (size % sizeof(wchar_t) != 0)
+ return E_INVALIDARG;
+ hres = ReadUnicodeStrings((const wchar_t *)namesData, size / sizeof(wchar_t), names);
+ }
+ else
+ hres = ReadAnsiStrings((const char *)namesData, size, names);
+
+ ODS_(Print_Number(names.Size(), "DataObject_GetData_HDROP_Names"))
+ return hres;
+}
+
+
+
+// CF_IDLIST:
+#define MYWIN_CFSTR_SHELLIDLIST TEXT("Shell IDList Array")
+
+typedef struct
+{
+ UINT cidl;
+ UINT aoffset[1];
+} MYWIN_CIDA;
+/*
+ cidl : number of PIDLs that are being transferred, not including the parent folder.
+ aoffset : An array of offsets, relative to the beginning of this structure.
+ aoffset[0] - fully qualified PIDL of a parent folder.
+ If this PIDL is empty, the parent folder is the desktop.
+ aoffset[1] ... aoffset[cidl] : offset to one of the PIDLs to be transferred.
+ All of these PIDLs are relative to the PIDL of the parent folder.
+*/
+
+static HRESULT DataObject_GetData_IDLIST(IDataObject *dataObject, UStringVector &names)
+{
+ names.Clear();
+ NCOM::CStgMedium medium;
+ RINOK(DataObject_GetData_HGLOBAL(dataObject, (CLIPFORMAT)
+ RegisterClipboardFormat(MYWIN_CFSTR_SHELLIDLIST), medium))
+ const size_t blockSize = GlobalSize(medium.hGlobal);
+ if (blockSize < sizeof(MYWIN_CIDA) || blockSize >= (UInt32)((UInt32)0 - 1))
+ return E_INVALIDARG;
+ NMemory::CGlobalLock dropLock(medium.hGlobal);
+ const MYWIN_CIDA *cida = (const MYWIN_CIDA *)dropLock.GetPointer();
+ if (!cida)
+ return E_INVALIDARG;
+ if (cida->cidl == 0)
+ {
+ // is it posssible to have no selected items?
+ // it's unexpected case.
+ return E_INVALIDARG;
+ }
+ if (cida->cidl >= (blockSize - (UInt32)sizeof(MYWIN_CIDA)) / sizeof(UINT))
+ return E_INVALIDARG;
+ const UInt32 start = cida->cidl * (UInt32)sizeof(UINT) + (UInt32)sizeof(MYWIN_CIDA);
+
+ STRRET strret;
+ CMyComPtr<IShellFolder> parentFolder;
+ {
+ const UINT offset = cida->aoffset[0];
+ if (offset < start || offset >= blockSize
+ // || offset != start
+ )
+ return E_INVALIDARG;
+
+ CMyComPtr<IShellFolder> desktopFolder;
+ RINOK(::SHGetDesktopFolder(&desktopFolder))
+ if (!desktopFolder)
+ return E_FAIL;
+
+ LPCITEMIDLIST const lpcItem = (LPCITEMIDLIST)(const void *)((const Byte *)cida + offset);
+
+ #ifdef SHOW_DEBUG_SHELL
+ {
+ const HRESULT res = desktopFolder->GetDisplayNameOf(
+ lpcItem, SHGDN_FORPARSING, &strret);
+ if (res == S_OK && strret.uType == STRRET_WSTR)
+ {
+ ODS_U(strret.pOleStr)
+ /* if lpcItem is empty, the path will be
+ "C:\Users\user_name\Desktop"
+ if lpcItem is "My Computer" folder, the path will be
+ "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" */
+ CoTaskMemFree(strret.pOleStr);
+ }
+ }
+ #endif
+
+ RINOK(desktopFolder->BindToObject(lpcItem,
+ NULL, IID_IShellFolder, (void **)&parentFolder))
+ if (!parentFolder)
+ return E_FAIL;
+ }
+
+ names.ClearAndReserve(cida->cidl);
+ UString path;
+
+ // for (int y = 0; y < 1; y++) // for debug
+ for (unsigned i = 1; i <= cida->cidl; i++)
+ {
+ const UINT offset = cida->aoffset[i];
+ if (offset < start || offset >= blockSize)
+ return E_INVALIDARG;
+ const void *p = (const Byte *)(const void *)cida + offset;
+ /* ITEMIDLIST of file can contain more than one SHITEMID item.
+ In win10 only SHGDN_FORPARSING returns path that contains
+ all path parts related to parts of ITEMIDLIST.
+ So we can use only SHGDN_FORPARSING here.
+ Don't use (SHGDN_INFOLDER)
+ Don't use (SHGDN_INFOLDER | SHGDN_FORPARSING)
+ */
+ RINOK(parentFolder->GetDisplayNameOf((LPCITEMIDLIST)p, SHGDN_FORPARSING, &strret))
+
+ /*
+ // MSVC6 and old SDK do not support StrRetToStrW().
+ LPWSTR lpstr;
+ RINOK (StrRetToStrW(&strret, NULL, &lpstr))
+ ODS_U(lpstr)
+ path = lpstr;
+ CoTaskMemFree(lpstr);
+ */
+ if (strret.uType != STRRET_WSTR)
+ return E_INVALIDARG;
+ ODS_U(strret.pOleStr)
+ path = strret.pOleStr;
+ // the path could have super path prefix "\\\\?\\"
+ // we can remove super path prefix here, if we don't need that prefix
+ #ifdef Z7_LONG_PATH
+ // we remove super prefix, if we can work without that prefix
+ NFile::NName::If_IsSuperPath_RemoveSuperPrefix(path);
+ #endif
+ names.AddInReserved(path);
+ CoTaskMemFree(strret.pOleStr);
+ }
+
+ ODS_(Print_Number(cida->cidl, "CFSTR_SHELLIDLIST END"))
+ return S_OK;
+}
+
+
+HRESULT DataObject_GetData_HDROP_or_IDLIST_Names(IDataObject *dataObject, UStringVector &paths)
+{
+ ODS("-- DataObject_GetData_HDROP_or_IDLIST_Names START")
+ HRESULT hres = NShell::DataObject_GetData_HDROP_Names(dataObject, paths);
+ // if (hres == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
+ if (hres != S_OK)
+ {
+ ODS("-- DataObject_GetData_IDLIST START")
+ // for (int y = 0; y < 10000; y++) // for debug
+ hres = NShell::DataObject_GetData_IDLIST(dataObject, paths);
+ }
+ ODS("-- DataObject_GetData_HDROP_or_IDLIST_Names END")
+ return hres;
+}
+
+
+
+// #if (NTDDI_VERSION >= NTDDI_VISTA)
+typedef struct
+{
+ UINT cItems; // number of items in rgdwFileAttributes array
+ DWORD dwSumFileAttributes; // all of the attributes ORed together
+ DWORD dwProductFileAttributes; // all of the attributes ANDed together
+ DWORD rgdwFileAttributes[1]; // array
+} MYWIN_FILE_ATTRIBUTES_ARRAY;
+
+#define MYWIN_CFSTR_FILE_ATTRIBUTES_ARRAY TEXT("File Attributes Array")
+
+HRESULT DataObject_GetData_FILE_ATTRS(IDataObject *dataObject, CFileAttribs &attribs)
+{
+ attribs.Clear();
+ NCOM::CStgMedium medium;
+ RINOK(DataObject_GetData_HGLOBAL(dataObject, (CLIPFORMAT)
+ RegisterClipboardFormat(MYWIN_CFSTR_FILE_ATTRIBUTES_ARRAY), medium))
+ const size_t blockSize = GlobalSize(medium.hGlobal);
+ if (blockSize < sizeof(MYWIN_FILE_ATTRIBUTES_ARRAY))
+ return E_INVALIDARG;
+ NMemory::CGlobalLock dropLock(medium.hGlobal);
+ const MYWIN_FILE_ATTRIBUTES_ARRAY *faa = (const MYWIN_FILE_ATTRIBUTES_ARRAY *)dropLock.GetPointer();
+ if (!faa)
+ return E_INVALIDARG;
+ const unsigned numFiles = faa->cItems;
+ if (numFiles == 0)
+ {
+ // is it posssible to have empty array here?
+ return E_INVALIDARG;
+ }
+ if ((blockSize - (sizeof(MYWIN_FILE_ATTRIBUTES_ARRAY) - sizeof(DWORD)))
+ / sizeof(DWORD) != numFiles)
+ return E_INVALIDARG;
+ // attribs.Sum = faa->dwSumFileAttributes;
+ // attribs.Product = faa->dwProductFileAttributes;
+ // attribs.Vals.SetFromArray(faa->rgdwFileAttributes, numFiles);
+ // attribs.IsDirVector.ClearAndSetSize(numFiles);
+
+ if ((faa->dwSumFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ {
+ /* in win10: if selected items are volumes (c:\, d:\ ..) in My Compter,
+ all items have FILE_ATTRIBUTE_DIRECTORY attribute
+ ntfs volume also have FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM
+ udf volume: FILE_ATTRIBUTE_READONLY
+ dvd-rom device: (-1) : all bits are set
+ */
+ const DWORD *attr = faa->rgdwFileAttributes;
+ // DWORD product = (UInt32)0 - 1, sum = 0;
+ for (unsigned i = 0; i < numFiles; i++)
+ {
+ if (attr[i] & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ // attribs.ThereAreDirs = true;
+ attribs.FirstDirIndex = (int)i;
+ break;
+ }
+ // attribs.IsDirVector[i] = (attr[i] & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ // product &= v;
+ // sum |= v;
+ }
+ // ODS_(Print_Number(product, "Product calc FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names"))
+ // ODS_(Print_Number(sum, "Sum calc FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names"))
+ }
+ // ODS_(Print_Number(attribs.Product, "Product FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names"))
+ // ODS_(Print_Number(attribs.Sum, "Sum FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names"))
+ ODS_(Print_Number(numFiles, "FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names"))
+ return S_OK;
+}
+
+
/////////////////////////////
// CDrop
+/*
+ win10:
+ DragQueryFile() implementation code is not effective because
+ there is no pointer inside DROP internal file list, so
+ DragQueryFile(fileIndex) runs all names in range [0, fileIndex].
+ DragQueryFile(,, buf, bufSize)
+ if (buf == NULL) by spec
+ {
+ returns value is the required size
+ in characters, of the buffer, not including the terminating null character
+ tests show that if (bufSize == 0), then it also returns required size.
+ }
+ if (bufSize != NULL)
+ {
+ returns: the count of the characters copied, not including null character.
+ win10: null character is also copied at position buf[ret_count];
+ }
+*/
+
+/*
void CDrop::Attach(HDROP object)
{
Free();
@@ -87,43 +476,133 @@ UINT CDrop::QueryCountOfFiles()
return QueryFile(0xFFFFFFFF, (LPTSTR)NULL, 0);
}
-UString CDrop::QueryFileName(UINT fileIndex)
+void CDrop::QueryFileName(UINT fileIndex, UString &fileName)
{
- UString fileName;
#ifndef _UNICODE
if (!g_IsNT)
{
AString fileNameA;
- UINT bufferSize = QueryFile(fileIndex, (LPTSTR)NULL, 0);
- const unsigned len = bufferSize + 2;
- QueryFile(fileIndex, fileNameA.GetBuf(len), bufferSize + 1);
+ const UINT len = QueryFile(fileIndex, (LPTSTR)NULL, 0);
+ const UINT numCopied = QueryFile(fileIndex, fileNameA.GetBuf(len + 2), len + 2);
fileNameA.ReleaseBuf_CalcLen(len);
+ if (numCopied != len)
+ throw 20221223;
fileName = GetUnicodeString(fileNameA);
}
else
#endif
{
- UINT bufferSize = QueryFile(fileIndex, (LPWSTR)NULL, 0);
- const unsigned len = bufferSize + 2;
- QueryFile(fileIndex, fileName.GetBuf(len), bufferSize + 1);
+ // kReserve must be >= 3 for additional buffer size
+ // safety and for optimal performance
+ const unsigned kReserve = 3;
+ {
+ unsigned len = 0;
+ wchar_t *buf = fileName.GetBuf_GetMaxAvail(len);
+ if (len >= kReserve)
+ {
+ const UINT numCopied = QueryFile(fileIndex, buf, len);
+ if (numCopied < len - 1)
+ {
+ // (numCopied < len - 1) case means that it have copied full string.
+ fileName.ReleaseBuf_CalcLen(numCopied);
+ return;
+ }
+ }
+ }
+ const UINT len = QueryFile(fileIndex, (LPWSTR)NULL, 0);
+ const UINT numCopied = QueryFile(fileIndex,
+ fileName.GetBuf(len + kReserve), len + kReserve);
fileName.ReleaseBuf_CalcLen(len);
+ if (numCopied != len)
+ throw 20221223;
}
- return fileName;
}
+
void CDrop::QueryFileNames(UStringVector &fileNames)
{
UINT numFiles = QueryCountOfFiles();
+
+ Print_Number(numFiles, "\n====== CDrop::QueryFileNames START ===== \n");
+
fileNames.ClearAndReserve(numFiles);
+ UString s;
for (UINT i = 0; i < numFiles; i++)
- fileNames.AddInReserved(QueryFileName(i));
+ {
+ QueryFileName(i, s);
+ if (!s.IsEmpty())
+ fileNames.AddInReserved(s);
+ }
+ Print_Number(numFiles, "\n====== CDrop::QueryFileNames END ===== \n");
}
+*/
-bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path)
+// #if (NTDDI_VERSION >= NTDDI_VISTA)
+// SHGetPathFromIDListEx returns a win32 file system path for the item in the name space.
+typedef int Z7_WIN_GPFIDL_FLAGS;
+
+extern "C" {
+typedef BOOL (WINAPI * Func_SHGetPathFromIDListW)(LPCITEMIDLIST pidl, LPWSTR pszPath);
+typedef BOOL (WINAPI * Func_SHGetPathFromIDListEx)(LPCITEMIDLIST pidl, PWSTR pszPath, DWORD cchPath, Z7_WIN_GPFIDL_FLAGS uOpts);
+}
+
+#ifndef _UNICODE
+
+bool GetPathFromIDList(LPCITEMIDLIST itemIDList, AString &path)
{
- const unsigned len = MAX_PATH * 2;
+ path.Empty();
+ const unsigned len = MAX_PATH + 16;
+ const bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuf(len)));
+ path.ReleaseBuf_CalcLen(len);
+ return result;
+}
+
+#endif
+
+bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path)
+{
+ path.Empty();
+ unsigned len = MAX_PATH + 16;
+
+#ifdef _UNICODE
bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuf(len)));
+#else
+ const
+ Func_SHGetPathFromIDListW
+ shGetPathFromIDListW = Z7_GET_PROC_ADDRESS(
+ Func_SHGetPathFromIDListW, ::GetModuleHandleW(L"shell32.dll"),
+ "SHGetPathFromIDListW");
+ if (!shGetPathFromIDListW)
+ return false;
+ bool result = BOOLToBool(shGetPathFromIDListW(itemIDList, path.GetBuf(len)));
+#endif
+
+ if (!result)
+ {
+ ODS("==== GetPathFromIDList() SHGetPathFromIDList() returned false")
+ /* for long path we need SHGetPathFromIDListEx().
+ win10: SHGetPathFromIDListEx() for long path returns path with
+ with super path prefix "\\\\?\\". */
+ const
+ Func_SHGetPathFromIDListEx
+ func_SHGetPathFromIDListEx = Z7_GET_PROC_ADDRESS(
+ Func_SHGetPathFromIDListEx, ::GetModuleHandleW(L"shell32.dll"),
+ "SHGetPathFromIDListEx");
+ if (func_SHGetPathFromIDListEx)
+ {
+ ODS("==== GetPathFromIDList() (SHGetPathFromIDListEx)")
+ do
+ {
+ len *= 4;
+ result = BOOLToBool(func_SHGetPathFromIDListEx(itemIDList, path.GetBuf(len), len, 0));
+ if (result)
+ break;
+ }
+ while (len <= (1 << 16));
+ }
+ }
+
path.ReleaseBuf_CalcLen(len);
return result;
}
@@ -153,8 +632,8 @@ bool BrowseForFolder(HWND /* owner */, LPCTSTR /* title */,
MessageBoxW(0, L"yes", L"", 0);
*/
/*
- UString s = L"all files";
- s += L" (*.*)";
+ UString s = "all files";
+ s += " (*.*)";
return MyGetOpenFileName(owner, title, initialFolder, s, resultPath, true);
*/
return false;
@@ -162,11 +641,16 @@ bool BrowseForFolder(HWND /* owner */, LPCTSTR /* title */,
#else
+/* win10: SHBrowseForFolder() doesn't support long paths,
+ even if long path suppport is enabled in registry and in manifest.
+ and SHBrowseForFolder() doesn't support super path prefix "\\\\?\\". */
+
bool BrowseForFolder(LPBROWSEINFO browseInfo, CSysString &resultPath)
{
+ resultPath.Empty();
NWindows::NCOM::CComInitializer comInitializer;
LPITEMIDLIST itemIDList = ::SHBrowseForFolder(browseInfo);
- if (itemIDList == NULL)
+ if (!itemIDList)
return false;
CItemIDList itemIDListHolder;
itemIDListHolder.Attach(itemIDList);
@@ -174,7 +658,7 @@ bool BrowseForFolder(LPBROWSEINFO browseInfo, CSysString &resultPath)
}
-int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM data)
+static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM data)
{
#ifndef UNDER_CE
switch (uMsg)
@@ -203,7 +687,7 @@ int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM da
}
-bool BrowseForFolder(HWND owner, LPCTSTR title, UINT ulFlags,
+static bool BrowseForFolder(HWND owner, LPCTSTR title, UINT ulFlags,
LPCTSTR initialFolder, CSysString &resultPath)
{
CSysString displayName;
@@ -222,11 +706,18 @@ bool BrowseForFolder(HWND owner, LPCTSTR title, UINT ulFlags,
browseInfo.lpszTitle = title;
// #endif
browseInfo.ulFlags = ulFlags;
- browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc : NULL;
+ browseInfo.lpfn = initialFolder ? BrowseCallbackProc : NULL;
browseInfo.lParam = (LPARAM)initialFolder;
return BrowseForFolder(&browseInfo, resultPath);
}
+#ifdef Z7_OLD_WIN_SDK
+// ShlObj.h:
+#ifndef BIF_NEWDIALOGSTYLE
+#define BIF_NEWDIALOGSTYLE 0x0040
+#endif
+#endif
+
bool BrowseForFolder(HWND owner, LPCTSTR title,
LPCTSTR initialFolder, CSysString &resultPath)
{
@@ -240,39 +731,29 @@ bool BrowseForFolder(HWND owner, LPCTSTR title,
#ifndef _UNICODE
-typedef BOOL (WINAPI * SHGetPathFromIDListWP)(LPCITEMIDLIST pidl, LPWSTR pszPath);
-
-bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path)
-{
- path.Empty();
- SHGetPathFromIDListWP shGetPathFromIDListW = (SHGetPathFromIDListWP)
- ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "SHGetPathFromIDListW");
- if (shGetPathFromIDListW == 0)
- return false;
- const unsigned len = MAX_PATH * 2;
- bool result = BOOLToBool(shGetPathFromIDListW(itemIDList, path.GetBuf(len)));
- path.ReleaseBuf_CalcLen(len);
- return result;
+extern "C" {
+typedef LPITEMIDLIST (WINAPI * Func_SHBrowseForFolderW)(LPBROWSEINFOW lpbi);
}
-typedef LPITEMIDLIST (WINAPI * SHBrowseForFolderWP)(LPBROWSEINFOW lpbi);
-
-bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath)
+static bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath)
{
NWindows::NCOM::CComInitializer comInitializer;
- SHBrowseForFolderWP shBrowseForFolderW = (SHBrowseForFolderWP)
- ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "SHBrowseForFolderW");
- if (shBrowseForFolderW == 0)
+ const
+ Func_SHBrowseForFolderW
+ f_SHBrowseForFolderW = Z7_GET_PROC_ADDRESS(
+ Func_SHBrowseForFolderW, ::GetModuleHandleW(L"shell32.dll"),
+ "SHBrowseForFolderW");
+ if (!f_SHBrowseForFolderW)
return false;
- LPITEMIDLIST itemIDList = shBrowseForFolderW(browseInfo);
- if (itemIDList == NULL)
+ LPITEMIDLIST itemIDList = f_SHBrowseForFolderW(browseInfo);
+ if (!itemIDList)
return false;
CItemIDList itemIDListHolder;
itemIDListHolder.Attach(itemIDList);
return GetPathFromIDList(itemIDList, resultPath);
}
-
+static
int CALLBACK BrowseCallbackProc2(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM data)
{
switch (uMsg)
@@ -311,7 +792,7 @@ static bool BrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags,
browseInfo.pszDisplayName = displayName.GetBuf(MAX_PATH);
browseInfo.lpszTitle = title;
browseInfo.ulFlags = ulFlags;
- browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc2 : NULL;
+ browseInfo.lpfn = initialFolder ? BrowseCallbackProc2 : NULL;
browseInfo.lParam = (LPARAM)initialFolder;
return BrowseForFolder(&browseInfo, resultPath);
}
diff --git a/3rdparty/lzma/CPP/Windows/Shell.h b/3rdparty/lzma/CPP/Windows/Shell.h
index 4bff18cf99a..b4cdb3048e1 100644
--- a/3rdparty/lzma/CPP/Windows/Shell.h
+++ b/3rdparty/lzma/CPP/Windows/Shell.h
@@ -1,17 +1,22 @@
// Windows/Shell.h
-#ifndef __WINDOWS_SHELL_H
-#define __WINDOWS_SHELL_H
+#ifndef ZIP7_WINDOWS_SHELL_H
+#define ZIP7_WINDOWS_SHELL_H
-#include <windows.h>
+#include "../Common/Common.h"
+#include "../Common/MyWindows.h"
+#if defined(__MINGW32__) || defined(__MINGW64__)
#include <shlobj.h>
+#else
+#include <ShlObj.h>
+#endif
#include "../Common/MyString.h"
#include "Defs.h"
-namespace NWindows{
-namespace NShell{
+namespace NWindows {
+namespace NShell {
/////////////////////////
// CItemIDList
@@ -20,6 +25,7 @@ namespace NShell{
class CItemIDList
{
LPITEMIDLIST m_Object;
+ Z7_CLASS_NO_COPY(CItemIDList)
public:
CItemIDList(): m_Object(NULL) {}
// CItemIDList(LPCITEMIDLIST itemIDList);
@@ -49,6 +55,7 @@ public:
/////////////////////////////
// CDrop
+/*
class CDrop
{
HDROP m_Object;
@@ -63,22 +70,51 @@ public:
operator HDROP() { return m_Object;}
bool QueryPoint(LPPOINT point)
{ return BOOLToBool(::DragQueryPoint(m_Object, point)); }
- void Finish() { ::DragFinish(m_Object); }
- UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT fileNameSize)
- { return ::DragQueryFile(m_Object, fileIndex, fileName, fileNameSize); }
+ void Finish()
+ {
+ ::DragFinish(m_Object);
+ }
+ UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT bufSize)
+ { return ::DragQueryFile(m_Object, fileIndex, fileName, bufSize); }
#ifndef _UNICODE
- UINT QueryFile(UINT fileIndex, LPWSTR fileName, UINT fileNameSize)
- { return ::DragQueryFileW(m_Object, fileIndex, fileName, fileNameSize); }
+ UINT QueryFile(UINT fileIndex, LPWSTR fileName, UINT bufSize)
+ { return ::DragQueryFileW(m_Object, fileIndex, fileName, bufSize); }
#endif
UINT QueryCountOfFiles();
- UString QueryFileName(UINT fileIndex);
+ void QueryFileName(UINT fileIndex, UString &fileName);
void QueryFileNames(UStringVector &fileNames);
};
-
+*/
#endif
-/////////////////////////////
-// Functions
+struct CFileAttribs
+{
+ int FirstDirIndex;
+ // DWORD Sum;
+ // DWORD Product;
+ // CRecordVector<DWORD> Vals;
+ // CRecordVector<bool> IsDirVector;
+
+ CFileAttribs()
+ {
+ Clear();
+ }
+
+ void Clear()
+ {
+ FirstDirIndex = -1;
+ // Sum = 0;
+ // Product = 0;
+ // IsDirVector.Clear();
+ }
+};
+
+
+/* read pathnames from HDROP or SHELLIDLIST.
+ The parser can return E_INVALIDARG, if there is some unexpected data in dataObject */
+HRESULT DataObject_GetData_HDROP_or_IDLIST_Names(IDataObject *dataObject, UStringVector &names);
+
+HRESULT DataObject_GetData_FILE_ATTRS(IDataObject *dataObject, CFileAttribs &attribs);
bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path);
bool BrowseForFolder(LPBROWSEINFO lpbi, CSysString &resultPath);
diff --git a/3rdparty/lzma/CPP/Windows/StdAfx.h b/3rdparty/lzma/CPP/Windows/StdAfx.h
index 1766dfa860a..bd5084fdbfe 100644
--- a/3rdparty/lzma/CPP/Windows/StdAfx.h
+++ b/3rdparty/lzma/CPP/Windows/StdAfx.h
@@ -1,7 +1,11 @@
// StdAfx.h
-#ifndef __STDAFX_H
-#define __STDAFX_H
+#ifndef ZIP7_INC_STDAFX_H
+#define ZIP7_INC_STDAFX_H
+
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+#pragma warning(disable : 4464) // relative include path contains '..'
+#endif
#include "../Common/Common.h"
diff --git a/3rdparty/lzma/CPP/Windows/Synchronization.cpp b/3rdparty/lzma/CPP/Windows/Synchronization.cpp
index 5f86d1eb170..d5542af4864 100644
--- a/3rdparty/lzma/CPP/Windows/Synchronization.cpp
+++ b/3rdparty/lzma/CPP/Windows/Synchronization.cpp
@@ -2,9 +2,86 @@
#include "StdAfx.h"
+#ifndef _WIN32
+
#include "Synchronization.h"
namespace NWindows {
namespace NSynchronization {
+/*
+#define INFINITE 0xFFFFFFFF
+#define MAXIMUM_WAIT_OBJECTS 64
+#define STATUS_ABANDONED_WAIT_0 ((NTSTATUS)0x00000080L)
+#define WAIT_ABANDONED ((STATUS_ABANDONED_WAIT_0 ) + 0 )
+#define WAIT_ABANDONED_0 ((STATUS_ABANDONED_WAIT_0 ) + 0 )
+// WINAPI
+DWORD WaitForMultipleObjects(DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout);
+*/
+
+/* clang: we need to place some virtual functions in cpp file to rid off the warning:
+ 'CBaseHandle_WFMO' has no out-of-line virtual method definitions;
+ its vtable will be emitted in every translation unit */
+CBaseHandle_WFMO::~CBaseHandle_WFMO()
+{
+}
+
+bool CBaseEvent_WFMO::IsSignaledAndUpdate()
+{
+ if (this->_state == false)
+ return false;
+ if (this->_manual_reset == false)
+ this->_state = false;
+ return true;
+}
+
+bool CSemaphore_WFMO::IsSignaledAndUpdate()
+{
+ if (this->_count == 0)
+ return false;
+ this->_count--;
+ return true;
+}
+
+DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles)
+{
+ if (count < 1)
+ {
+ // abort();
+ SetLastError(EINVAL);
+ return WAIT_FAILED;
+ }
+
+ CSynchro *synchro = handles[0]->_sync;
+ synchro->Enter();
+
+ // #ifdef DEBUG_SYNCHRO
+ for (DWORD i = 1; i < count; i++)
+ {
+ if (synchro != handles[i]->_sync)
+ {
+ // abort();
+ synchro->Leave();
+ SetLastError(EINVAL);
+ return WAIT_FAILED;
+ }
+ }
+ // #endif
+
+ for (;;)
+ {
+ for (DWORD i = 0; i < count; i++)
+ {
+ if (handles[i]->IsSignaledAndUpdate())
+ {
+ synchro->Leave();
+ return WAIT_OBJECT_0 + i;
+ }
+ }
+ synchro->WaitCond();
+ }
+}
+
}}
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/Synchronization.h b/3rdparty/lzma/CPP/Windows/Synchronization.h
index dc695f6f388..afd03d2cb06 100644
--- a/3rdparty/lzma/CPP/Windows/Synchronization.h
+++ b/3rdparty/lzma/CPP/Windows/Synchronization.h
@@ -1,10 +1,12 @@
// Windows/Synchronization.h
-#ifndef __WINDOWS_SYNCHRONIZATION_H
-#define __WINDOWS_SYNCHRONIZATION_H
+#ifndef ZIP7_INC_WINDOWS_SYNCHRONIZATION_H
+#define ZIP7_INC_WINDOWS_SYNCHRONIZATION_H
#include "../../C/Threads.h"
+#include "../Common/MyTypes.h"
+
#include "Defs.h"
#ifdef _WIN32
@@ -14,28 +16,30 @@
namespace NWindows {
namespace NSynchronization {
-class CBaseEvent
+class CBaseEvent MY_UNCOPYABLE
{
protected:
::CEvent _object;
public:
bool IsCreated() { return Event_IsCreated(&_object) != 0; }
- operator HANDLE() { return _object; }
+
CBaseEvent() { Event_Construct(&_object); }
~CBaseEvent() { Close(); }
WRes Close() { return Event_Close(&_object); }
+
#ifdef _WIN32
+ operator HANDLE() { return _object; }
WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES sa = NULL)
{
_object = ::CreateEvent(sa, BoolToBOOL(manualReset), BoolToBOOL(initiallyOwn), name);
- if (name == NULL && _object != 0)
+ if (name == NULL && _object != NULL)
return 0;
return ::GetLastError();
}
WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
{
_object = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);
- if (_object != 0)
+ if (_object != NULL)
return 0;
return ::GetLastError();
}
@@ -54,10 +58,10 @@ public:
{
return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);
}
- WRes CreateIfNotCreated()
+ WRes CreateIfNotCreated_Reset()
{
if (IsCreated())
- return 0;
+ return Reset();
return ManualResetEvent_CreateNotSignaled(&_object);
}
#ifdef _WIN32
@@ -75,21 +79,25 @@ public:
{
return AutoResetEvent_CreateNotSignaled(&_object);
}
- WRes CreateIfNotCreated()
+ WRes CreateIfNotCreated_Reset()
{
if (IsCreated())
- return 0;
+ return Reset();
return AutoResetEvent_CreateNotSignaled(&_object);
}
};
+
+/*
#ifdef _WIN32
+
class CObject: public CHandle
{
public:
WRes Lock(DWORD timeoutInterval = INFINITE)
{ return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }
};
+
class CMutex: public CObject
{
public:
@@ -114,33 +122,47 @@ public:
return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();
}
};
-class CMutexLock
+
+class CMutexLock MY_UNCOPYABLE
{
CMutex *_object;
public:
CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }
~CMutexLock() { _object->Release(); }
};
-#endif
-class CSemaphore
+#endif // _WIN32
+*/
+
+
+class CSemaphore MY_UNCOPYABLE
{
::CSemaphore _object;
public:
CSemaphore() { Semaphore_Construct(&_object); }
~CSemaphore() { Close(); }
- WRes Close() { return Semaphore_Close(&_object); }
+ WRes Close() { return Semaphore_Close(&_object); }
+
+ #ifdef _WIN32
operator HANDLE() { return _object; }
- WRes Create(UInt32 initiallyCount, UInt32 maxCount)
+ #endif
+
+ // bool IsCreated() const { return Semaphore_IsCreated(&_object) != 0; }
+
+ WRes Create(UInt32 initCount, UInt32 maxCount)
{
- return Semaphore_Create(&_object, initiallyCount, maxCount);
+ return Semaphore_Create(&_object, initCount, maxCount);
+ }
+ WRes OptCreateInit(UInt32 initCount, UInt32 maxCount)
+ {
+ return Semaphore_OptCreateInit(&_object, initCount, maxCount);
}
WRes Release() { return Semaphore_Release1(&_object); }
WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }
WRes Lock() { return Semaphore_Wait(&_object); }
};
-class CCriticalSection
+class CCriticalSection MY_UNCOPYABLE
{
::CCriticalSection _object;
public:
@@ -150,7 +172,7 @@ public:
void Leave() { CriticalSection_Leave(&_object); }
};
-class CCriticalSectionLock
+class CCriticalSectionLock MY_UNCOPYABLE
{
CCriticalSection *_object;
void Unlock() { _object->Leave(); }
@@ -159,6 +181,201 @@ public:
~CCriticalSectionLock() { Unlock(); }
};
+
+#ifdef _WIN32
+
+typedef HANDLE CHandle_WFMO;
+typedef CSemaphore CSemaphore_WFMO;
+typedef CAutoResetEvent CAutoResetEvent_WFMO;
+typedef CManualResetEvent CManualResetEvent_WFMO;
+
+inline DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles)
+{
+ return ::WaitForMultipleObjects(count, handles, FALSE, INFINITE);
+}
+
+#define SYNC_OBJ_DECL(obj)
+#define SYNC_WFMO(x)
+#define SYNC_PARAM(x)
+#define SYNC_PARAM_DECL(x)
+
+#else // _WIN32
+
+// POSIX sync objects for WaitForMultipleObjects
+
+#define SYNC_WFMO(x) x
+#define SYNC_PARAM(x) x,
+#define SYNC_PARAM_DECL(x) NWindows::NSynchronization::CSynchro *x
+#define SYNC_OBJ_DECL(x) NWindows::NSynchronization::CSynchro x;
+
+class CSynchro MY_UNCOPYABLE
+{
+ pthread_mutex_t _mutex;
+ pthread_cond_t _cond;
+ bool _isValid;
+
+public:
+ CSynchro() { _isValid = false; }
+ ~CSynchro()
+ {
+ if (_isValid)
+ {
+ ::pthread_mutex_destroy(&_mutex);
+ ::pthread_cond_destroy(&_cond);
+ }
+ _isValid = false;
+ }
+ WRes Create()
+ {
+ RINOK(::pthread_mutex_init(&_mutex, NULL))
+ const WRes ret = ::pthread_cond_init(&_cond, NULL);
+ _isValid = 1;
+ return ret;
+ }
+ WRes Enter()
+ {
+ return ::pthread_mutex_lock(&_mutex);
+ }
+ WRes Leave()
+ {
+ return ::pthread_mutex_unlock(&_mutex);
+ }
+ WRes WaitCond()
+ {
+ return ::pthread_cond_wait(&_cond, &_mutex);
+ }
+ WRes LeaveAndSignal()
+ {
+ const WRes res1 = ::pthread_cond_broadcast(&_cond);
+ const WRes res2 = ::pthread_mutex_unlock(&_mutex);
+ return (res2 ? res2 : res1);
+ }
+};
+
+
+struct CBaseHandle_WFMO;
+typedef NWindows::NSynchronization::CBaseHandle_WFMO *CHandle_WFMO;
+
+// these constants are from Windows
+#define WAIT_OBJECT_0 0
+#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
+
+DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles);
+
+
+struct CBaseHandle_WFMO MY_UNCOPYABLE
+{
+ CSynchro *_sync;
+
+ CBaseHandle_WFMO(): _sync(NULL) {}
+ virtual ~CBaseHandle_WFMO();
+
+ operator CHandle_WFMO() { return this; }
+ virtual bool IsSignaledAndUpdate() = 0;
+};
+
+
+class CBaseEvent_WFMO : public CBaseHandle_WFMO
+{
+ bool _manual_reset;
+ bool _state;
+
+public:
+
+ // bool IsCreated() { return (this->_sync != NULL); }
+ // CBaseEvent_WFMO() { ; }
+ // ~CBaseEvent_WFMO() Z7_override { Close(); }
+
+ WRes Close() { this->_sync = NULL; return 0; }
+
+ WRes Create(
+ CSynchro *sync,
+ bool manualReset, bool initiallyOwn)
+ {
+ this->_sync = sync;
+ this->_manual_reset = manualReset;
+ this->_state = initiallyOwn;
+ return 0;
+ }
+
+ WRes Set()
+ {
+ RINOK(this->_sync->Enter())
+ this->_state = true;
+ return this->_sync->LeaveAndSignal();
+ }
+
+ WRes Reset()
+ {
+ RINOK(this->_sync->Enter())
+ this->_state = false;
+ return this->_sync->Leave();
+ }
+
+ virtual bool IsSignaledAndUpdate() Z7_override;
+};
+
+
+class CManualResetEvent_WFMO Z7_final: public CBaseEvent_WFMO
+{
+public:
+ WRes Create(CSynchro *sync, bool initiallyOwn = false) { return CBaseEvent_WFMO::Create(sync, true, initiallyOwn); }
+};
+
+
+class CAutoResetEvent_WFMO Z7_final: public CBaseEvent_WFMO
+{
+public:
+ WRes Create(CSynchro *sync) { return CBaseEvent_WFMO::Create(sync, false, false); }
+ WRes CreateIfNotCreated_Reset(CSynchro *sync)
+ {
+ return Create(sync);
+ }
+};
+
+
+class CSemaphore_WFMO Z7_final: public CBaseHandle_WFMO
+{
+ UInt32 _count;
+ UInt32 _maxCount;
+
+public:
+ CSemaphore_WFMO() : _count(0), _maxCount(0) {}
+
+ WRes Close() { this->_sync = NULL; return 0; }
+
+ WRes Create(CSynchro *sync, UInt32 initCount, UInt32 maxCount)
+ {
+ if (initCount > maxCount || maxCount < 1)
+ return EINVAL;
+ this->_sync = sync;
+ this->_count = initCount;
+ this->_maxCount = maxCount;
+ return 0;
+ }
+
+ WRes Release(UInt32 releaseCount = 1)
+ {
+ if (releaseCount < 1)
+ return EINVAL;
+
+ RINOK(this->_sync->Enter())
+ UInt32 newCount = this->_count + releaseCount;
+ if (newCount > this->_maxCount)
+ {
+ RINOK(this->_sync->Leave())
+ return ERROR_TOO_MANY_POSTS; // EINVAL
+ }
+ this->_count = newCount;
+
+ return this->_sync->LeaveAndSignal();
+ }
+
+ virtual bool IsSignaledAndUpdate() Z7_override;
+};
+
+#endif // _WIN32
+
}}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/System.cpp b/3rdparty/lzma/CPP/Windows/System.cpp
index 59cb7c0b4e8..dbe287a0c45 100644
--- a/3rdparty/lzma/CPP/Windows/System.cpp
+++ b/3rdparty/lzma/CPP/Windows/System.cpp
@@ -2,9 +2,20 @@
#include "StdAfx.h"
-#include "../Common/MyWindows.h"
+#ifndef _WIN32
+#include <unistd.h>
+#include <limits.h>
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#else
+#include <sys/sysinfo.h>
+#endif
+#endif
#include "../Common/Defs.h"
+// #include "../Common/MyWindows.h"
+
+// #include "../../C/CpuArch.h"
#include "System.h"
@@ -13,18 +24,84 @@ namespace NSystem {
#ifdef _WIN32
+UInt32 CountAffinity(DWORD_PTR mask)
+{
+ UInt32 num = 0;
+ for (unsigned i = 0; i < sizeof(mask) * 8; i++)
+ num += (UInt32)((mask >> i) & 1);
+ return num;
+}
+
+BOOL CProcessAffinity::Get()
+{
+ #ifndef UNDER_CE
+ return GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask);
+ #else
+ return FALSE;
+ #endif
+}
+
+
UInt32 GetNumberOfProcessors()
{
+ // We need to know how many threads we can use.
+ // By default the process is assigned to one group.
+ // So we get the number of logical processors (threads)
+ // assigned to current process in the current group.
+ // Group size can be smaller than total number logical processors, for exammple, 2x36
+
+ CProcessAffinity pa;
+
+ if (pa.Get() && pa.processAffinityMask != 0)
+ return pa.GetNumProcessThreads();
+
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
+ // the number of logical processors in the current group
return (UInt32)systemInfo.dwNumberOfProcessors;
}
#else
+
+BOOL CProcessAffinity::Get()
+{
+ numSysThreads = GetNumberOfProcessors();
+
+ /*
+ numSysThreads = 8;
+ for (unsigned i = 0; i < numSysThreads; i++)
+ CpuSet_Set(&cpu_set, i);
+ return TRUE;
+ */
+
+ #ifdef Z7_AFFINITY_SUPPORTED
+
+ // numSysThreads = sysconf(_SC_NPROCESSORS_ONLN); // The number of processors currently online
+ if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0)
+ return FALSE;
+ return TRUE;
+
+ #else
+
+ // cpu_set = ((CCpuSet)1 << (numSysThreads)) - 1;
+ return TRUE;
+ // errno = ENOSYS;
+ // return FALSE;
+
+ #endif
+}
+
UInt32 GetNumberOfProcessors()
{
+ #ifndef Z7_ST
+ long n = sysconf(_SC_NPROCESSORS_CONF); // The number of processors configured
+ if (n < 1)
+ n = 1;
+ return (UInt32)n;
+ #else
return 1;
+ #endif
}
#endif
@@ -34,7 +111,8 @@ UInt32 GetNumberOfProcessors()
#ifndef UNDER_CE
-#if !defined(_WIN64) && defined(__GNUC__)
+#if !defined(_WIN64) && \
+ (defined(__MINGW32_VERSION) || defined(Z7_OLD_WIN_SDK))
typedef struct _MY_MEMORYSTATUSEX {
DWORD dwLength;
@@ -55,19 +133,15 @@ typedef struct _MY_MEMORYSTATUSEX {
#endif
-typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);
-
-#endif
-
-#endif
+typedef BOOL (WINAPI *Func_GlobalMemoryStatusEx)(MY_LPMEMORYSTATUSEX lpBuffer);
+#endif // !UNDER_CE
+
bool GetRamSize(UInt64 &size)
{
size = (UInt64)(sizeof(size_t)) << 29;
- #ifdef _WIN32
-
#ifndef UNDER_CE
MY_MEMORYSTATUSEX stat;
stat.dwLength = sizeof(stat);
@@ -83,9 +157,11 @@ bool GetRamSize(UInt64 &size)
#else
#ifndef UNDER_CE
- GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)
- ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx");
- if (globalMemoryStatusEx && globalMemoryStatusEx(&stat))
+ const
+ Func_GlobalMemoryStatusEx fn = Z7_GET_PROC_ADDRESS(
+ Func_GlobalMemoryStatusEx, ::GetModuleHandleA("kernel32.dll"),
+ "GlobalMemoryStatusEx");
+ if (fn && fn(&stat))
{
size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys);
return true;
@@ -99,14 +175,104 @@ bool GetRamSize(UInt64 &size)
size = MyMin(stat2.dwTotalVirtual, stat2.dwTotalPhys);
return true;
}
-
#endif
+}
+
+#else
+
+// POSIX
+// #include <stdio.h>
+
+bool GetRamSize(UInt64 &size)
+{
+ size = (UInt64)(sizeof(size_t)) << 29;
+
+ #ifdef __APPLE__
+
+ #ifdef HW_MEMSIZE
+ uint64_t val = 0; // support 2Gb+ RAM
+ int mib[2] = { CTL_HW, HW_MEMSIZE };
+ #elif defined(HW_PHYSMEM64)
+ uint64_t val = 0; // support 2Gb+ RAM
+ int mib[2] = { CTL_HW, HW_PHYSMEM64 };
+ #else
+ unsigned int val = 0; // For old system
+ int mib[2] = { CTL_HW, HW_PHYSMEM };
+ #endif // HW_MEMSIZE
+ size_t size_sys = sizeof(val);
+
+ sysctl(mib, 2, &val, &size_sys, NULL, 0);
+ if (val)
+ size = val;
+ #elif defined(_AIX)
+ // fixme
+ #elif defined(__gnu_hurd__)
+ // fixme
+ #elif defined(__FreeBSD_kernel__) && defined(__GLIBC__)
+ // GNU/kFreeBSD Debian
+ // fixme
#else
- return false;
+ struct sysinfo info;
+ if (::sysinfo(&info) != 0)
+ return false;
+ size = (UInt64)info.mem_unit * info.totalram;
+ const UInt64 kLimit = (UInt64)1 << (sizeof(size_t) * 8 - 1);
+ if (size > kLimit)
+ size = kLimit;
+
+ /*
+ printf("\n mem_unit = %lld", (UInt64)info.mem_unit);
+ printf("\n totalram = %lld", (UInt64)info.totalram);
+ printf("\n freeram = %lld", (UInt64)info.freeram);
+ */
#endif
+
+ return true;
+}
+
+#endif
+
+
+unsigned long Get_File_OPEN_MAX()
+{
+ #ifdef _WIN32
+ return (1 << 24) - (1 << 16); // ~16M handles
+ #else
+ // some linux versions have default open file limit for user process of 1024 files.
+ long n = sysconf(_SC_OPEN_MAX);
+ // n = -1; // for debug
+ // n = 9; // for debug
+ if (n < 1)
+ {
+ // n = OPEN_MAX; // ???
+ // n = FOPEN_MAX; // = 16 : <stdio.h>
+ #ifdef _POSIX_OPEN_MAX
+ n = _POSIX_OPEN_MAX; // = 20 : <limits.h>
+ #else
+ n = 30; // our limit
+ #endif
+ }
+ return (unsigned long)n;
+ #endif
+}
+
+unsigned Get_File_OPEN_MAX_Reduced_for_3_tasks()
+{
+ unsigned long numFiles_OPEN_MAX = NSystem::Get_File_OPEN_MAX();
+ const unsigned delta = 10; // the reserve for another internal needs of process
+ if (numFiles_OPEN_MAX > delta)
+ numFiles_OPEN_MAX -= delta;
+ else
+ numFiles_OPEN_MAX = 1;
+ numFiles_OPEN_MAX /= 3; // we suppose that we have up to 3 tasks in total for multiple file processing
+ numFiles_OPEN_MAX = MyMax(numFiles_OPEN_MAX, (unsigned long)3);
+ unsigned n = (UInt32)(UInt32)-1;
+ if (n > numFiles_OPEN_MAX)
+ n = (unsigned)numFiles_OPEN_MAX;
+ return n;
}
}}
diff --git a/3rdparty/lzma/CPP/Windows/System.h b/3rdparty/lzma/CPP/Windows/System.h
index 910bc7fd5f5..06500074c7a 100644
--- a/3rdparty/lzma/CPP/Windows/System.h
+++ b/3rdparty/lzma/CPP/Windows/System.h
@@ -1,17 +1,132 @@
// Windows/System.h
-#ifndef __WINDOWS_SYSTEM_H
-#define __WINDOWS_SYSTEM_H
+#ifndef ZIP7_INC_WINDOWS_SYSTEM_H
+#define ZIP7_INC_WINDOWS_SYSTEM_H
+
+#ifndef _WIN32
+// #include <sched.h>
+#include "../../C/Threads.h"
+#endif
#include "../Common/MyTypes.h"
+#include "../Common/MyWindows.h"
namespace NWindows {
namespace NSystem {
+#ifdef _WIN32
+
+UInt32 CountAffinity(DWORD_PTR mask);
+
+struct CProcessAffinity
+{
+ // UInt32 numProcessThreads;
+ // UInt32 numSysThreads;
+ DWORD_PTR processAffinityMask;
+ DWORD_PTR systemAffinityMask;
+
+ void InitST()
+ {
+ // numProcessThreads = 1;
+ // numSysThreads = 1;
+ processAffinityMask = 1;
+ systemAffinityMask = 1;
+ }
+
+ void CpuZero()
+ {
+ processAffinityMask = 0;
+ }
+
+ void CpuSet(unsigned cpuIndex)
+ {
+ processAffinityMask |= ((DWORD_PTR)1 << cpuIndex);
+ }
+
+ UInt32 GetNumProcessThreads() const { return CountAffinity(processAffinityMask); }
+ UInt32 GetNumSystemThreads() const { return CountAffinity(systemAffinityMask); }
+
+ BOOL Get();
+
+ BOOL SetProcAffinity() const
+ {
+ return SetProcessAffinityMask(GetCurrentProcess(), processAffinityMask);
+ }
+};
+
+
+#else // WIN32
+
+struct CProcessAffinity
+{
+ UInt32 numSysThreads;
+
+ UInt32 GetNumSystemThreads() const { return (UInt32)numSysThreads; }
+ BOOL Get();
+
+ #ifdef Z7_AFFINITY_SUPPORTED
+
+ CCpuSet cpu_set;
+
+ void InitST()
+ {
+ numSysThreads = 1;
+ CpuSet_Zero(&cpu_set);
+ CpuSet_Set(&cpu_set, 0);
+ }
+
+ UInt32 GetNumProcessThreads() const { return (UInt32)CPU_COUNT(&cpu_set); }
+ void CpuZero() { CpuSet_Zero(&cpu_set); }
+ void CpuSet(unsigned cpuIndex) { CpuSet_Set(&cpu_set, cpuIndex); }
+ int IsCpuSet(unsigned cpuIndex) const { return CpuSet_IsSet(&cpu_set, cpuIndex); }
+ // void CpuClr(int cpuIndex) { CPU_CLR(cpuIndex, &cpu_set); }
+
+ BOOL SetProcAffinity() const
+ {
+ return sched_setaffinity(0, sizeof(cpu_set), &cpu_set) == 0;
+ }
+
+ #else // Z7_AFFINITY_SUPPORTED
+
+ void InitST()
+ {
+ numSysThreads = 1;
+ }
+
+ UInt32 GetNumProcessThreads() const
+ {
+ return numSysThreads;
+ /*
+ UInt32 num = 0;
+ for (unsigned i = 0; i < sizeof(cpu_set) * 8; i++)
+ num += (UInt32)((cpu_set >> i) & 1);
+ return num;
+ */
+ }
+
+ void CpuZero() { }
+ void CpuSet(unsigned cpuIndex) { UNUSED_VAR(cpuIndex); }
+ int IsCpuSet(unsigned cpuIndex) const { return (cpuIndex < numSysThreads) ? 1 : 0; }
+
+ BOOL SetProcAffinity() const
+ {
+ errno = ENOSYS;
+ return FALSE;
+ }
+
+ #endif // Z7_AFFINITY_SUPPORTED
+};
+
+#endif // _WIN32
+
+
UInt32 GetNumberOfProcessors();
bool GetRamSize(UInt64 &size); // returns false, if unknown ram size
+unsigned long Get_File_OPEN_MAX();
+unsigned Get_File_OPEN_MAX_Reduced_for_3_tasks();
+
}}
#endif
diff --git a/3rdparty/lzma/CPP/Windows/SystemInfo.cpp b/3rdparty/lzma/CPP/Windows/SystemInfo.cpp
new file mode 100644
index 00000000000..6bafc8046b3
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/SystemInfo.cpp
@@ -0,0 +1,1022 @@
+// Windows/SystemInfo.cpp
+
+#include "StdAfx.h"
+
+#include "../../C/CpuArch.h"
+
+#include "../Common/IntToString.h"
+
+#ifdef _WIN32
+
+#include "Registry.h"
+
+#else
+
+#include <unistd.h>
+#include <sys/utsname.h>
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#elif !defined(_AIX)
+
+#include <sys/auxv.h>
+
+// #undef AT_HWCAP // to debug
+// #undef AT_HWCAP2 // to debug
+
+/* the following patch for some debian systems.
+ Is it OK to define AT_HWCAP and AT_HWCAP2 here with these constant numbers? */
+/*
+#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
+ #ifndef AT_HWCAP
+ #define AT_HWCAP 16
+ #endif
+ #ifndef AT_HWCAP2
+ #define AT_HWCAP2 26
+ #endif
+#endif
+*/
+
+#ifdef MY_CPU_ARM_OR_ARM64
+#include <asm/hwcap.h>
+#endif
+#endif
+
+#ifdef __linux__
+#include "../Windows/FileIO.h"
+#endif
+
+#endif // WIN32
+
+#include "SystemInfo.h"
+#include "System.h"
+
+using namespace NWindows;
+
+#ifdef __linux__
+
+static bool ReadFile_to_Buffer(CFSTR fileName, CByteBuffer &buf)
+{
+ NWindows::NFile::NIO::CInFile file;
+ if (!file.Open(fileName))
+ return false;
+ /*
+ UInt64 size;
+ if (!file.GetLength(size))
+ {
+ // GetLength() doesn't work "/proc/cpuinfo"
+ return false;
+ }
+ if (size >= ((UInt32)1 << 29))
+ return false;
+ */
+ size_t size = 0;
+ size_t addSize = ((size_t)1 << 12);
+ for (;;)
+ {
+ // printf("\nsize = %d\n", (unsigned)size);
+ buf.ChangeSize_KeepData(size + addSize, size);
+ size_t processed;
+ if (!file.ReadFull(buf + size, addSize, processed))
+ return false;
+ if (processed == 0)
+ {
+ buf.ChangeSize_KeepData(size, size);
+ return true;
+ }
+ size += processed;
+ addSize *= 2;
+ }
+}
+
+#endif
+
+
+#if defined(_WIN32) || defined(AT_HWCAP) || defined(AT_HWCAP2)
+static void PrintHex(AString &s, UInt64 v)
+{
+ char temp[32];
+ ConvertUInt64ToHex(v, temp);
+ s += temp;
+}
+#endif
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+Z7_NO_INLINE
+static void PrintCpuChars(AString &s, UInt32 v)
+{
+ for (unsigned j = 0; j < 4; j++)
+ {
+ Byte b = (Byte)(v & 0xFF);
+ v >>= 8;
+ if (b == 0)
+ break;
+ if (b >= 0x20 && b <= 0x7f)
+ s += (char)b;
+ else
+ {
+ s += '[';
+ char temp[16];
+ ConvertUInt32ToHex(b, temp);
+ s += temp;
+ s += ']';
+ }
+ }
+}
+
+
+static void x86cpuid_to_String(AString &s)
+{
+ s.Empty();
+
+ UInt32 a[4];
+ // cpuid was called already. So we don't check for cpuid availability here
+ z7_x86_cpuid(a, 0x80000000);
+
+ if (a[0] >= 0x80000004) // if (maxFunc2 >= hi+4) the full name is available
+ {
+ for (unsigned i = 0; i < 3; i++)
+ {
+ z7_x86_cpuid(a, 0x80000002 + i);
+ for (unsigned j = 0; j < 4; j++)
+ PrintCpuChars(s, a[j]);
+ }
+ }
+
+ s.Trim();
+
+ if (s.IsEmpty())
+ {
+ z7_x86_cpuid(a, 0);
+ for (unsigned i = 1; i < 4; i++)
+ {
+ const unsigned j = (i ^ (i >> 1));
+ PrintCpuChars(s, a[j]);
+ }
+ s.Trim();
+ }
+}
+
+/*
+static void x86cpuid_all_to_String(AString &s)
+{
+ Cx86cpuid p;
+ if (!x86cpuid_CheckAndRead(&p))
+ return;
+ s += "x86cpuid maxFunc = ";
+ s.Add_UInt32(p.maxFunc);
+ for (unsigned j = 0; j <= p.maxFunc; j++)
+ {
+ s.Add_LF();
+ // s.Add_UInt32(j); // align
+ {
+ char temp[32];
+ ConvertUInt32ToString(j, temp);
+ unsigned len = (unsigned)strlen(temp);
+ while (len < 8)
+ {
+ len++;
+ s.Add_Space();
+ }
+ s += temp;
+ }
+
+ s += ":";
+ UInt32 d[4] = { 0 };
+ MyCPUID(j, &d[0], &d[1], &d[2], &d[3]);
+ for (unsigned i = 0; i < 4; i++)
+ {
+ char temp[32];
+ ConvertUInt32ToHex8Digits(d[i], temp);
+ s.Add_Space();
+ s += temp;
+ }
+ }
+}
+*/
+
+#endif
+
+
+
+#ifdef _WIN32
+
+static const char * const k_PROCESSOR_ARCHITECTURE[] =
+{
+ "x86" // "INTEL"
+ , "MIPS"
+ , "ALPHA"
+ , "PPC"
+ , "SHX"
+ , "ARM"
+ , "IA64"
+ , "ALPHA64"
+ , "MSIL"
+ , "x64" // "AMD64"
+ , "IA32_ON_WIN64"
+ , "NEUTRAL"
+ , "ARM64"
+ , "ARM32_ON_WIN64"
+};
+
+#define Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL 0
+#define Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 9
+
+
+#define Z7_WIN_PROCESSOR_INTEL_PENTIUM 586
+#define Z7_WIN_PROCESSOR_AMD_X8664 8664
+
+/*
+static const CUInt32PCharPair k_PROCESSOR[] =
+{
+ { 2200, "IA64" },
+ { 8664, "x64" }
+};
+
+#define PROCESSOR_INTEL_386 386
+#define PROCESSOR_INTEL_486 486
+#define PROCESSOR_INTEL_PENTIUM 586
+#define PROCESSOR_INTEL_860 860
+#define PROCESSOR_INTEL_IA64 2200
+#define PROCESSOR_AMD_X8664 8664
+#define PROCESSOR_MIPS_R2000 2000
+#define PROCESSOR_MIPS_R3000 3000
+#define PROCESSOR_MIPS_R4000 4000
+#define PROCESSOR_ALPHA_21064 21064
+#define PROCESSOR_PPC_601 601
+#define PROCESSOR_PPC_603 603
+#define PROCESSOR_PPC_604 604
+#define PROCESSOR_PPC_620 620
+#define PROCESSOR_HITACHI_SH3 10003
+#define PROCESSOR_HITACHI_SH3E 10004
+#define PROCESSOR_HITACHI_SH4 10005
+#define PROCESSOR_MOTOROLA_821 821
+#define PROCESSOR_SHx_SH3 103
+#define PROCESSOR_SHx_SH4 104
+#define PROCESSOR_STRONGARM 2577 // 0xA11
+#define PROCESSOR_ARM720 1824 // 0x720
+#define PROCESSOR_ARM820 2080 // 0x820
+#define PROCESSOR_ARM920 2336 // 0x920
+#define PROCESSOR_ARM_7TDMI 70001
+#define PROCESSOR_OPTIL 18767 // 0x494f
+*/
+
+
+/*
+static const char * const k_PF[] =
+{
+ "FP_ERRATA"
+ , "FP_EMU"
+ , "CMPXCHG"
+ , "MMX"
+ , "PPC_MOVEMEM_64BIT"
+ , "ALPHA_BYTE"
+ , "SSE"
+ , "3DNOW"
+ , "RDTSC"
+ , "PAE"
+ , "SSE2"
+ , "SSE_DAZ"
+ , "NX"
+ , "SSE3"
+ , "CMPXCHG16B"
+ , "CMP8XCHG16"
+ , "CHANNELS"
+ , "XSAVE"
+ , "ARM_VFP_32"
+ , "ARM_NEON"
+ , "L2AT"
+ , "VIRT_FIRMWARE"
+ , "RDWRFSGSBASE"
+ , "FASTFAIL"
+ , "ARM_DIVIDE"
+ , "ARM_64BIT_LOADSTORE_ATOMIC"
+ , "ARM_EXTERNAL_CACHE"
+ , "ARM_FMAC"
+ , "RDRAND"
+ , "ARM_V8"
+ , "ARM_V8_CRYPTO"
+ , "ARM_V8_CRC32"
+ , "RDTSCP"
+ , "RDPID"
+ , "ARM_V81_ATOMIC"
+ , "MONITORX"
+};
+*/
+
+#endif
+
+
+static void PrintPage(AString &s, UInt64 v)
+{
+ const char *t = "B";
+ if ((v & 0x3ff) == 0)
+ {
+ v >>= 10;
+ t = "KB";
+ }
+ s.Add_UInt64(v);
+ s += t;
+}
+
+#ifdef _WIN32
+
+static AString TypeToString2(const char * const table[], unsigned num, UInt32 value)
+{
+ char sz[16];
+ const char *p = NULL;
+ if (value < num)
+ p = table[value];
+ if (!p)
+ {
+ ConvertUInt32ToString(value, sz);
+ p = sz;
+ }
+ return (AString)p;
+}
+
+// #if defined(Z7_LARGE_PAGES) || defined(_WIN32)
+// #ifdef _WIN32
+void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v)
+{
+ char c = 0;
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'K';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'M';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'G';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'T';
+ }}}}
+ else
+ {
+ // s += "0x";
+ PrintHex(s, v);
+ return;
+ }
+ s.Add_UInt64(v);
+ if (c)
+ s += c;
+ s += 'B';
+}
+// #endif
+// #endif
+
+static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
+{
+ s += TypeToString2(k_PROCESSOR_ARCHITECTURE, Z7_ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture);
+
+ if (!( (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == Z7_WIN_PROCESSOR_INTEL_PENTIUM)
+ || (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == Z7_WIN_PROCESSOR_AMD_X8664)))
+ {
+ s.Add_Space();
+ // s += TypePairToString(k_PROCESSOR, Z7_ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType);
+ s.Add_UInt32(si.dwProcessorType);
+ }
+ s.Add_Space();
+ PrintHex(s, si.wProcessorLevel);
+ s.Add_Dot();
+ PrintHex(s, si.wProcessorRevision);
+ if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
+ if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8)
+ {
+ s += " act:";
+ PrintHex(s, si.dwActiveProcessorMask);
+ }
+ s += " cpus:";
+ s.Add_UInt32(si.dwNumberOfProcessors);
+ if (si.dwPageSize != 1 << 12)
+ {
+ s += " page:";
+ PrintPage(s, si.dwPageSize);
+ }
+ if (si.dwAllocationGranularity != 1 << 16)
+ {
+ s += " gran:";
+ PrintPage(s, si.dwAllocationGranularity);
+ }
+ s.Add_Space();
+
+ const DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
+ UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1;
+ const UInt32 kReserveSize = ((UInt32)1 << 16);
+ if (minAdd != kReserveSize)
+ {
+ PrintSize_KMGT_Or_Hex(s, minAdd);
+ s += "-";
+ }
+ else
+ {
+ if ((maxSize & (kReserveSize - 1)) == 0)
+ maxSize += kReserveSize;
+ }
+ PrintSize_KMGT_Or_Hex(s, maxSize);
+}
+
+#ifndef _WIN64
+EXTERN_C_BEGIN
+typedef VOID (WINAPI *Func_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
+EXTERN_C_END
+#endif
+
+#endif
+
+#ifdef __APPLE__
+#ifndef MY_CPU_X86_OR_AMD64
+static void Add_sysctlbyname_to_String(const char *name, AString &s)
+{
+ size_t bufSize = 256;
+ char buf[256];
+ if (z7_sysctlbyname_Get(name, &buf, &bufSize) == 0)
+ s += buf;
+}
+#endif
+#endif
+
+void GetSysInfo(AString &s1, AString &s2);
+void GetSysInfo(AString &s1, AString &s2)
+{
+ s1.Empty();
+ s2.Empty();
+
+ #ifdef _WIN32
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ {
+ SysInfo_To_String(s1, si);
+ // s += " : ";
+ }
+
+ #if !defined(_WIN64) && !defined(UNDER_CE)
+ const
+ Func_GetNativeSystemInfo fn = Z7_GET_PROC_ADDRESS(
+ Func_GetNativeSystemInfo, GetModuleHandleA("kernel32.dll"),
+ "GetNativeSystemInfo");
+ if (fn)
+ {
+ SYSTEM_INFO si2;
+ fn(&si2);
+ // if (memcmp(&si, &si2, sizeof(si)) != 0)
+ {
+ // s += " - ";
+ SysInfo_To_String(s2, si2);
+ }
+ }
+ #endif
+ #endif
+}
+
+
+void GetCpuName(AString &s);
+
+static void AddBracedString(AString &dest, AString &src)
+{
+ if (!src.IsEmpty())
+ {
+ AString s;
+ s += '(';
+ s += src;
+ s += ')';
+ dest.Add_OptSpaced(s);
+ }
+}
+
+struct CCpuName
+{
+ AString CpuName;
+ AString Revision;
+ AString Microcode;
+ AString LargePages;
+
+ void Fill();
+
+ void Get_Revision_Microcode_LargePages(AString &s)
+ {
+ s.Empty();
+ AddBracedString(s, Revision);
+ AddBracedString(s, Microcode);
+ s.Add_OptSpaced(LargePages);
+ }
+};
+
+void CCpuName::Fill()
+{
+ CpuName.Empty();
+ Revision.Empty();
+ Microcode.Empty();
+ LargePages.Empty();
+
+ AString &s = CpuName;
+
+ #ifdef MY_CPU_X86_OR_AMD64
+ {
+ #if !defined(MY_CPU_AMD64)
+ if (!z7_x86_cpuid_GetMaxFunc())
+ s += "x86";
+ else
+ #endif
+ {
+ x86cpuid_to_String(s);
+ {
+ UInt32 a[4];
+ z7_x86_cpuid(a, 1);
+ char temp[16];
+ ConvertUInt32ToHex(a[0], temp);
+ Revision += temp;
+ }
+ }
+ }
+ #elif defined(__APPLE__)
+ {
+ Add_sysctlbyname_to_String("machdep.cpu.brand_string", s);
+ }
+ #endif
+
+
+ if (s.IsEmpty())
+ {
+ #ifdef MY_CPU_LE
+ s += "LE";
+ #elif defined(MY_CPU_BE)
+ s += "BE";
+ #endif
+ }
+
+ #ifdef __APPLE__
+ {
+ AString s2;
+ UInt32 v = 0;
+ if (z7_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0)
+ {
+ s2.Add_UInt32(v);
+ s2 += 'C';
+ }
+ if (z7_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0)
+ {
+ s2.Add_UInt32(v);
+ s2 += 'T';
+ }
+ if (!s2.IsEmpty())
+ {
+ s.Add_Space_if_NotEmpty();
+ s += s2;
+ }
+ }
+ #endif
+
+
+ #ifdef _WIN32
+ {
+ NRegistry::CKey key;
+ if (key.Open(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), KEY_READ) == ERROR_SUCCESS)
+ {
+ LONG res[2];
+ CByteBuffer bufs[2];
+ {
+ for (unsigned i = 0; i < 2; i++)
+ {
+ UInt32 size = 0;
+ res[i] = key.QueryValue(i == 0 ?
+ TEXT("Previous Update Revision") :
+ TEXT("Update Revision"), bufs[i], size);
+ if (res[i] == ERROR_SUCCESS)
+ if (size != bufs[i].Size())
+ res[i] = ERROR_SUCCESS + 1;
+ }
+ }
+ if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS)
+ {
+ for (unsigned i = 0; i < 2; i++)
+ {
+ if (i == 1)
+ Microcode += "->";
+ if (res[i] != ERROR_SUCCESS)
+ continue;
+ const CByteBuffer &buf = bufs[i];
+ if (buf.Size() == 8)
+ {
+ UInt32 high = GetUi32(buf);
+ if (high != 0)
+ {
+ PrintHex(Microcode, high);
+ Microcode += ".";
+ }
+ PrintHex(Microcode, GetUi32(buf + 4));
+ }
+ }
+ }
+ }
+ }
+ #endif
+
+
+ #ifdef Z7_LARGE_PAGES
+ Add_LargePages_String(LargePages);
+ #endif
+}
+
+void AddCpuFeatures(AString &s);
+void AddCpuFeatures(AString &s)
+{
+ #ifdef _WIN32
+ // const unsigned kNumFeatures_Extra = 32; // we check also for unknown features
+ // const unsigned kNumFeatures = Z7_ARRAY_SIZE(k_PF) + kNumFeatures_Extra;
+ const unsigned kNumFeatures = 64;
+ UInt64 flags = 0;
+ for (unsigned i = 0; i < kNumFeatures; i++)
+ {
+ if (IsProcessorFeaturePresent(i))
+ {
+ flags += (UInt64)1 << i;
+ // s.Add_Space_if_NotEmpty();
+ // s += TypeToString2(k_PF, Z7_ARRAY_SIZE(k_PF), i);
+ }
+ }
+ s.Add_OptSpaced("f:");
+ PrintHex(s, flags);
+
+ #elif defined(__APPLE__)
+ {
+ UInt32 v = 0;
+ if (z7_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0)
+ {
+ s.Add_OptSpaced("PageSize:");
+ PrintPage(s, v);
+ }
+ }
+
+ #else
+
+ const long v = sysconf(_SC_PAGESIZE);
+ if (v != -1)
+ {
+ s.Add_OptSpaced("PageSize:");
+ PrintPage(s, (unsigned long)v);
+ }
+
+ #if !defined(_AIX)
+
+ #ifdef __linux__
+
+ CByteBuffer buf;
+ if (ReadFile_to_Buffer("/sys/kernel/mm/transparent_hugepage/enabled", buf))
+ // if (ReadFile_to_Buffer("/proc/cpuinfo", buf))
+ {
+ s.Add_OptSpaced("THP:");
+ AString s2;
+ s2.SetFrom_CalcLen((const char *)(const void *)(const Byte *)buf, (unsigned)buf.Size());
+ const int pos = s2.Find('[');
+ if (pos >= 0)
+ {
+ const int pos2 = s2.Find(']', (unsigned)pos + 1);
+ if (pos2 >= 0)
+ {
+ s2.DeleteFrom((unsigned)pos2);
+ s2.DeleteFrontal((unsigned)pos + 1);
+ }
+ }
+ s += s2;
+ }
+ // else throw CSystemException(MY_SRes_HRESULT_FROM_WRes(errno));
+
+ #endif
+
+
+ #ifdef AT_HWCAP
+ s.Add_OptSpaced("hwcap:");
+ {
+ unsigned long h = getauxval(AT_HWCAP);
+ PrintHex(s, h);
+ #ifdef MY_CPU_ARM64
+ if (h & HWCAP_CRC32) s += ":CRC32";
+ if (h & HWCAP_SHA1) s += ":SHA1";
+ if (h & HWCAP_SHA2) s += ":SHA2";
+ if (h & HWCAP_AES) s += ":AES";
+ if (h & HWCAP_ASIMD) s += ":ASIMD";
+ #elif defined(MY_CPU_ARM)
+ if (h & HWCAP_NEON) s += ":NEON";
+ #endif
+ }
+ #endif // AT_HWCAP
+
+ #ifdef AT_HWCAP2
+ {
+ unsigned long h = getauxval(AT_HWCAP2);
+ #ifndef MY_CPU_ARM
+ if (h != 0)
+ #endif
+ {
+ s += " hwcap2:";
+ PrintHex(s, h);
+ #ifdef MY_CPU_ARM
+ if (h & HWCAP2_CRC32) s += ":CRC32";
+ if (h & HWCAP2_SHA1) s += ":SHA1";
+ if (h & HWCAP2_SHA2) s += ":SHA2";
+ if (h & HWCAP2_AES) s += ":AES";
+ #endif
+ }
+ }
+ #endif // AT_HWCAP2
+ #endif // _AIX
+ #endif // _WIN32
+}
+
+
+#ifdef _WIN32
+#ifndef UNDER_CE
+
+EXTERN_C_BEGIN
+typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
+EXTERN_C_END
+
+static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi)
+{
+ const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
+ if (!ntdll)
+ return FALSE;
+ const
+ Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
+ Func_RtlGetVersion, ntdll,
+ "RtlGetVersion");
+ if (!func)
+ return FALSE;
+ func(vi);
+ return TRUE;
+}
+
+#endif
+#endif
+
+
+void GetOsInfoText(AString &sRes)
+{
+ sRes.Empty();
+ AString s;
+
+ #ifdef _WIN32
+ #ifndef UNDER_CE
+ // OSVERSIONINFO vi;
+ OSVERSIONINFOEXW vi;
+ vi.dwOSVersionInfoSize = sizeof(vi);
+ // if (::GetVersionEx(&vi))
+ if (My_RtlGetVersion(&vi))
+ {
+ s += "Windows";
+ if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ s.Add_UInt32(vi.dwPlatformId);
+ s.Add_Space(); s.Add_UInt32(vi.dwMajorVersion);
+ s.Add_Dot(); s.Add_UInt32(vi.dwMinorVersion);
+ s.Add_Space(); s.Add_UInt32(vi.dwBuildNumber);
+
+ if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0)
+ {
+ s += " SP:"; s.Add_UInt32(vi.wServicePackMajor);
+ s.Add_Dot(); s.Add_UInt32(vi.wServicePackMinor);
+ }
+ // s += " Suite:"; PrintHex(s, vi.wSuiteMask);
+ // s += " Type:"; s.Add_UInt32(vi.wProductType);
+ // s.Add_Space(); s += GetOemString(vi.szCSDVersion);
+ }
+ /*
+ {
+ s += " OEMCP:"; s.Add_UInt32(GetOEMCP());
+ s += " ACP:"; s.Add_UInt32(GetACP());
+ }
+ */
+ #endif
+ #else // _WIN32
+
+ if (!s.IsEmpty())
+ s.Add_LF();
+ struct utsname un;
+ if (uname(&un) == 0)
+ {
+ s += un.sysname;
+ // s += " : "; s += un.nodename; // we don't want to show name of computer
+ s += " : "; s += un.release;
+ s += " : "; s += un.version;
+ s += " : "; s += un.machine;
+
+ #ifdef __APPLE__
+ // Add_sysctlbyname_to_String("kern.version", s);
+ // it's same as "utsname.version"
+ #endif
+ }
+ #endif // _WIN32
+
+ sRes += s;
+ #ifdef MY_CPU_X86_OR_AMD64
+ {
+ AString s2;
+ GetVirtCpuid(s2);
+ if (!s2.IsEmpty())
+ {
+ sRes += " : ";
+ sRes += s2;
+ }
+ }
+ #endif
+}
+
+
+
+void GetSystemInfoText(AString &sRes)
+{
+ GetOsInfoText(sRes);
+ sRes.Add_LF();
+
+ {
+ AString s, s1, s2;
+ GetSysInfo(s1, s2);
+ if (!s1.IsEmpty() || !s2.IsEmpty())
+ {
+ s = s1;
+ if (s1 != s2 && !s2.IsEmpty())
+ {
+ s += " - ";
+ s += s2;
+ }
+ }
+ {
+ AddCpuFeatures(s);
+ if (!s.IsEmpty())
+ {
+ sRes += s;
+ sRes.Add_LF();
+ }
+ }
+ }
+ {
+ AString s;
+ GetCpuName(s);
+ if (!s.IsEmpty())
+ {
+ sRes += s;
+ sRes.Add_LF();
+ }
+ }
+ /*
+ #ifdef MY_CPU_X86_OR_AMD64
+ {
+ AString s;
+ x86cpuid_all_to_String(s);
+ if (!s.IsEmpty())
+ {
+ printCallback->Print(s);
+ printCallback->NewLine();
+ }
+ }
+ #endif
+ */
+}
+
+
+void GetCpuName(AString &s);
+void GetCpuName(AString &s)
+{
+ CCpuName cpuName;
+ cpuName.Fill();
+ s = cpuName.CpuName;
+ AString s2;
+ cpuName.Get_Revision_Microcode_LargePages(s2);
+ s.Add_OptSpaced(s2);
+}
+
+
+void GetCpuName_MultiLine(AString &s);
+void GetCpuName_MultiLine(AString &s)
+{
+ CCpuName cpuName;
+ cpuName.Fill();
+ s = cpuName.CpuName;
+ AString s2;
+ cpuName.Get_Revision_Microcode_LargePages(s2);
+ if (!s2.IsEmpty())
+ {
+ s.Add_LF();
+ s += s2;
+ }
+}
+
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+void GetVirtCpuid(AString &s)
+{
+ const UInt32 kHv = 0x40000000;
+
+ Z7_IF_X86_CPUID_SUPPORTED
+ {
+ UInt32 a[4];
+ z7_x86_cpuid(a, kHv);
+
+ if (a[0] < kHv || a[0] >= kHv + (1 << 16))
+ return;
+ {
+ {
+ for (unsigned j = 1; j < 4; j++)
+ PrintCpuChars(s, a[j]);
+ }
+ }
+ if (a[0] >= kHv + 1)
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, kHv + 1);
+ s += " : ";
+ PrintCpuChars(s, d[0]);
+ if (a[0] >= kHv + 2)
+ {
+ z7_x86_cpuid(d, kHv + 2);
+ s += " : ";
+ s.Add_UInt32(d[1] >> 16);
+ s.Add_Dot(); s.Add_UInt32(d[1] & 0xffff);
+ s.Add_Dot(); s.Add_UInt32(d[0]);
+ s.Add_Dot(); s.Add_UInt32(d[2]);
+ s.Add_Dot(); s.Add_UInt32(d[3] >> 24);
+ s.Add_Dot(); s.Add_UInt32(d[3] & 0xffffff);
+ }
+ /*
+ if (a[0] >= kHv + 5)
+ {
+ z7_x86_cpuid(d, kHv + 5);
+ s += " : ";
+ s.Add_UInt32(d[0]);
+ s += "p";
+ s.Add_UInt32(d[1]);
+ s += "t";
+ }
+ */
+ }
+ }
+}
+
+#endif
+
+
+void GetCompiler(AString &s)
+{
+ #ifdef __VERSION__
+ s += __VERSION__;
+ #endif
+
+ #ifdef __GNUC__
+ s += " GCC ";
+ s.Add_UInt32(__GNUC__);
+ s.Add_Dot();
+ s.Add_UInt32(__GNUC_MINOR__);
+ s.Add_Dot();
+ s.Add_UInt32(__GNUC_PATCHLEVEL__);
+ #endif
+
+ #ifdef __clang__
+ s += " CLANG ";
+ s.Add_UInt32(__clang_major__);
+ s.Add_Dot();
+ s.Add_UInt32(__clang_minor__);
+ #endif
+
+ #ifdef __xlC__
+ s += " XLC ";
+ s.Add_UInt32(__xlC__ >> 8);
+ s.Add_Dot();
+ s.Add_UInt32(__xlC__ & 0xFF);
+ #ifdef __xlC_ver__
+ s.Add_Dot();
+ s.Add_UInt32(__xlC_ver__ >> 8);
+ s.Add_Dot();
+ s.Add_UInt32(__xlC_ver__ & 0xFF);
+ #endif
+ #endif
+
+ #ifdef _MSC_VER
+ s += " MSC ";
+ s.Add_UInt32(_MSC_VER);
+ #endif
+
+ #if defined(__AVX2__)
+ #define MY_CPU_COMPILE_ISA "AVX2"
+ #elif defined(__AVX__)
+ #define MY_CPU_COMPILE_ISA "AVX"
+ #elif defined(__SSE2__)
+ #define MY_CPU_COMPILE_ISA "SSE2"
+ #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 2)
+ #define MY_CPU_COMPILE_ISA "SSE2"
+ #elif defined(__SSE__)
+ #define MY_CPU_COMPILE_ISA "SSE"
+ #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 1)
+ #define MY_CPU_COMPILE_ISA "SSE"
+ #elif defined(__i686__)
+ #define MY_CPU_COMPILE_ISA "i686"
+ #elif defined(__i586__)
+ #define MY_CPU_COMPILE_ISA "i586"
+ #elif defined(__i486__)
+ #define MY_CPU_COMPILE_ISA "i486"
+ #elif defined(__i386__)
+ #define MY_CPU_COMPILE_ISA "i386"
+ #elif defined(_M_IX86_FP)
+ #define MY_CPU_COMPILE_ISA "IA32"
+ #endif
+
+
+ #ifdef MY_CPU_COMPILE_ISA
+ s += ':';
+ s.Add_OptSpaced(MY_CPU_COMPILE_ISA);
+ #endif
+}
diff --git a/3rdparty/lzma/CPP/Windows/SystemInfo.h b/3rdparty/lzma/CPP/Windows/SystemInfo.h
new file mode 100644
index 00000000000..c2e2e3b19fa
--- /dev/null
+++ b/3rdparty/lzma/CPP/Windows/SystemInfo.h
@@ -0,0 +1,19 @@
+// Windows/SystemInfo.h
+
+#ifndef ZIP7_INC_WINDOWS_SYSTEM_INFO_H
+#define ZIP7_INC_WINDOWS_SYSTEM_INFO_H
+
+#include "../Common/MyString.h"
+
+
+void GetCpuName_MultiLine(AString &s);
+
+void GetOsInfoText(AString &sRes);
+void GetSystemInfoText(AString &s);
+void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v);
+void Add_LargePages_String(AString &s);
+
+void GetCompiler(AString &s);
+void GetVirtCpuid(AString &s);
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/Thread.h b/3rdparty/lzma/CPP/Windows/Thread.h
index 16a509d4768..d72f64c47ab 100644
--- a/3rdparty/lzma/CPP/Windows/Thread.h
+++ b/3rdparty/lzma/CPP/Windows/Thread.h
@@ -1,7 +1,7 @@
// Windows/Thread.h
-#ifndef __WINDOWS_THREAD_H
-#define __WINDOWS_THREAD_H
+#ifndef ZIP7_INC_WINDOWS_THREAD_H
+#define ZIP7_INC_WINDOWS_THREAD_H
#include "../../C/Threads.h"
@@ -9,17 +9,23 @@
namespace NWindows {
-class CThread
+class CThread MY_UNCOPYABLE
{
::CThread thread;
public:
- CThread() { Thread_Construct(&thread); }
+ CThread() { Thread_CONSTRUCT(&thread) }
~CThread() { Close(); }
bool IsCreated() { return Thread_WasCreated(&thread) != 0; }
WRes Close() { return Thread_Close(&thread); }
- WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
- { return Thread_Create(&thread, startAddress, parameter); }
- WRes Wait() { return Thread_Wait(&thread); }
+ // WRes Wait() { return Thread_Wait(&thread); }
+ WRes Wait_Close() { return Thread_Wait_Close(&thread); }
+
+ WRes Create(THREAD_FUNC_TYPE startAddress, LPVOID param)
+ { return Thread_Create(&thread, startAddress, param); }
+ WRes Create_With_Affinity(THREAD_FUNC_TYPE startAddress, LPVOID param, CAffinityMask affinity)
+ { return Thread_Create_With_Affinity(&thread, startAddress, param, affinity); }
+ WRes Create_With_CpuSet(THREAD_FUNC_TYPE startAddress, LPVOID param, const CCpuSet *cpuSet)
+ { return Thread_Create_With_CpuSet(&thread, startAddress, param, cpuSet); }
#ifdef _WIN32
operator HANDLE() { return thread; }
diff --git a/3rdparty/lzma/CPP/Windows/TimeUtils.cpp b/3rdparty/lzma/CPP/Windows/TimeUtils.cpp
index 7ef44d9cc50..e80ae13dcac 100644
--- a/3rdparty/lzma/CPP/Windows/TimeUtils.cpp
+++ b/3rdparty/lzma/CPP/Windows/TimeUtils.cpp
@@ -2,6 +2,10 @@
#include "StdAfx.h"
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+
#include "Defs.h"
#include "TimeUtils.h"
@@ -10,13 +14,15 @@ namespace NTime {
static const UInt32 kNumTimeQuantumsInSecond = 10000000;
static const UInt32 kFileTimeStartYear = 1601;
+#if !defined(_WIN32) || defined(UNDER_CE)
static const UInt32 kDosTimeStartYear = 1980;
+#endif
static const UInt32 kUnixTimeStartYear = 1970;
static const UInt64 kUnixTimeOffset =
(UInt64)60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear));
static const UInt64 kNumSecondsInFileTime = (UInt64)(Int64)-1 / kNumTimeQuantumsInSecond;
-bool DosTimeToFileTime(UInt32 dosTime, FILETIME &ft) throw()
+bool DosTime_To_FileTime(UInt32 dosTime, FILETIME &ft) throw()
{
#if defined(_WIN32) && !defined(UNDER_CE)
return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &ft));
@@ -37,11 +43,7 @@ bool DosTimeToFileTime(UInt32 dosTime, FILETIME &ft) throw()
static const UInt32 kHighDosTime = 0xFF9FBF7D;
static const UInt32 kLowDosTime = 0x210000;
-#define PERIOD_4 (4 * 365 + 1)
-#define PERIOD_100 (PERIOD_4 * 25 - 1)
-#define PERIOD_400 (PERIOD_100 * 4 + 1)
-
-bool FileTimeToDosTime(const FILETIME &ft, UInt32 &dosTime) throw()
+bool FileTime_To_DosTime(const FILETIME &ft, UInt32 &dosTime) throw()
{
#if defined(_WIN32) && !defined(UNDER_CE)
@@ -55,6 +57,10 @@ bool FileTimeToDosTime(const FILETIME &ft, UInt32 &dosTime) throw()
#else
+#define PERIOD_4 (4 * 365 + 1)
+#define PERIOD_100 (PERIOD_4 * 25 - 1)
+#define PERIOD_400 (PERIOD_100 * 4 + 1)
+
unsigned year, mon, day, hour, min, sec;
UInt64 v64 = ft.dwLowDateTime | ((UInt64)ft.dwHighDateTime << 32);
Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
@@ -115,39 +121,86 @@ bool FileTimeToDosTime(const FILETIME &ft, UInt32 &dosTime) throw()
return true;
}
-void UnixTimeToFileTime(UInt32 unixTime, FILETIME &ft) throw()
+
+bool UtcFileTime_To_LocalDosTime(const FILETIME &utc, UInt32 &dosTime) throw()
{
- UInt64 v = (kUnixTimeOffset + (UInt64)unixTime) * kNumTimeQuantumsInSecond;
+ FILETIME loc = { 0, 0 };
+ const UInt64 u1 = FILETIME_To_UInt64(utc);
+ const UInt64 kDelta = ((UInt64)1 << 41); // it's larger than quantums in 1 sec.
+ if (u1 >= kDelta)
+ {
+ if (!FileTimeToLocalFileTime(&utc, &loc))
+ loc = utc;
+ else
+ {
+ const UInt64 u2 = FILETIME_To_UInt64(loc);
+ const UInt64 delta = u1 < u2 ? (u2 - u1) : (u1 - u2);
+ if (delta > kDelta) // if FileTimeToLocalFileTime() overflow, we use UTC time
+ loc = utc;
+ }
+ }
+ return FileTime_To_DosTime(loc, dosTime);
+}
+
+UInt64 UnixTime_To_FileTime64(UInt32 unixTime) throw()
+{
+ return (kUnixTimeOffset + (UInt64)unixTime) * kNumTimeQuantumsInSecond;
+}
+
+void UnixTime_To_FileTime(UInt32 unixTime, FILETIME &ft) throw()
+{
+ const UInt64 v = UnixTime_To_FileTime64(unixTime);
ft.dwLowDateTime = (DWORD)v;
ft.dwHighDateTime = (DWORD)(v >> 32);
}
-bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &ft) throw()
+UInt64 UnixTime64_To_FileTime64(Int64 unixTime) throw()
{
- if (unixTime > kNumSecondsInFileTime - kUnixTimeOffset)
+ return (UInt64)((Int64)kUnixTimeOffset + unixTime) * kNumTimeQuantumsInSecond;
+}
+
+
+bool UnixTime64_To_FileTime64(Int64 unixTime, UInt64 &fileTime) throw()
+{
+ if (unixTime > (Int64)(kNumSecondsInFileTime - kUnixTimeOffset))
{
- ft.dwLowDateTime = ft.dwHighDateTime = (UInt32)(Int32)-1;
+ fileTime = (UInt64)(Int64)-1;
return false;
}
- Int64 v = (Int64)kUnixTimeOffset + unixTime;
- if (v < 0)
+ if (unixTime < -(Int64)kUnixTimeOffset)
{
- ft.dwLowDateTime = ft.dwHighDateTime = 0;
+ fileTime = 0;
return false;
}
- UInt64 v2 = (UInt64)v * kNumTimeQuantumsInSecond;
- ft.dwLowDateTime = (DWORD)v2;
- ft.dwHighDateTime = (DWORD)(v2 >> 32);
+ fileTime = UnixTime64_To_FileTime64(unixTime);
return true;
}
-Int64 FileTimeToUnixTime64(const FILETIME &ft) throw()
+
+bool UnixTime64_To_FileTime(Int64 unixTime, FILETIME &ft) throw()
+{
+ UInt64 v;
+ const bool res = UnixTime64_To_FileTime64(unixTime, v);
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+ return res;
+}
+
+
+Int64 FileTime_To_UnixTime64(const FILETIME &ft) throw()
+{
+ const UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+ return (Int64)(winTime / kNumTimeQuantumsInSecond) - (Int64)kUnixTimeOffset;
+}
+
+Int64 FileTime_To_UnixTime64_and_Quantums(const FILETIME &ft, UInt32 &quantums) throw()
{
- UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
- return (Int64)(winTime / kNumTimeQuantumsInSecond) - kUnixTimeOffset;
+ const UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+ quantums = (UInt32)(winTime % kNumTimeQuantumsInSecond);
+ return (Int64)(winTime / kNumTimeQuantumsInSecond) - (Int64)kUnixTimeOffset;
}
-bool FileTimeToUnixTime(const FILETIME &ft, UInt32 &unixTime) throw()
+bool FileTime_To_UnixTime(const FILETIME &ft, UInt32 &unixTime) throw()
{
UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
winTime /= kNumTimeQuantumsInSecond;
@@ -157,9 +210,9 @@ bool FileTimeToUnixTime(const FILETIME &ft, UInt32 &unixTime) throw()
return false;
}
winTime -= kUnixTimeOffset;
- if (winTime > 0xFFFFFFFF)
+ if (winTime > (UInt32)0xFFFFFFFF)
{
- unixTime = 0xFFFFFFFF;
+ unixTime = (UInt32)0xFFFFFFFF;
return false;
}
unixTime = (UInt32)winTime;
@@ -186,11 +239,13 @@ bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
return true;
}
-void GetCurUtcFileTime(FILETIME &ft) throw()
+
+void GetCurUtc_FiTime(CFiTime &ft) throw()
{
+ #ifdef _WIN32
+
// Both variants provide same low resolution on WinXP: about 15 ms.
// But GetSystemTimeAsFileTime is much faster.
-
#ifdef UNDER_CE
SYSTEMTIME st;
GetSystemTime(&st);
@@ -198,6 +253,152 @@ void GetCurUtcFileTime(FILETIME &ft) throw()
#else
GetSystemTimeAsFileTime(&ft);
#endif
+
+ #else
+
+ FiTime_Clear(ft);
+ struct timeval now;
+ if (gettimeofday(&now, NULL) == 0)
+ {
+ ft.tv_sec = now.tv_sec;
+ ft.tv_nsec = now.tv_usec * 1000;
+ }
+
+ #endif
}
+#ifndef _WIN32
+void GetCurUtcFileTime(FILETIME &ft) throw()
+{
+ UInt64 v = 0;
+ struct timeval now;
+ if (gettimeofday(&now, NULL) == 0)
+ {
+ v = ((UInt64)now.tv_sec + kUnixTimeOffset) *
+ kNumTimeQuantumsInSecond + (UInt64)now.tv_usec * 10;
+ }
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+}
+#endif
+
+
}}
+
+
+#ifdef _WIN32
+
+/*
+void FiTime_Normalize_With_Prec(CFiTime &ft, unsigned prec)
+{
+ if (prec == k_PropVar_TimePrec_0
+ || prec == k_PropVar_TimePrec_HighPrec
+ || prec >= k_PropVar_TimePrec_100ns)
+ return;
+ UInt64 v = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+
+ int numDigits = (int)prec - (int)k_PropVar_TimePrec_Base;
+ UInt32 d;
+ if (prec == k_PropVar_TimePrec_DOS)
+ {
+ // we round up as windows DosDateTimeToFileTime()
+ v += NWindows::NTime::kNumTimeQuantumsInSecond * 2 - 1;
+ d = NWindows::NTime::kNumTimeQuantumsInSecond * 2;
+ }
+ else
+ {
+ if (prec == k_PropVar_TimePrec_Unix)
+ numDigits = 0;
+ else if (numDigits < 0)
+ return;
+ d = 1;
+ for (unsigned k = numDigits; k < 7; k++)
+ d *= 10;
+ }
+ v /= d;
+ v *= d;
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+}
+*/
+
+#else
+
+/*
+void FiTime_Normalize_With_Prec(CFiTime &ft, unsigned prec)
+{
+ if (prec >= k_PropVar_TimePrec_1ns
+ || prec == k_PropVar_TimePrec_HighPrec)
+ return;
+
+ int numDigits = (int)prec - (int)k_PropVar_TimePrec_Base;
+ UInt32 d;
+ if (prec == k_PropVar_TimePrec_Unix ||
+ prec == (int)k_PropVar_TimePrec_Base)
+ {
+ ft.tv_nsec = 0;
+ return;
+ }
+ if (prec == k_PropVar_TimePrec_DOS)
+ {
+ // we round up as windows DosDateTimeToFileTime()
+ const unsigned sec1 = (ft.tv_sec & 1);
+ if (ft.tv_nsec == 0 && sec1 == 0)
+ return;
+ ft.tv_nsec = 0;
+ ft.tv_sec += 2 - sec1;
+ return;
+ }
+ {
+ if (prec == k_PropVar_TimePrec_0
+ || numDigits < 0)
+ numDigits = 7;
+ d = 1;
+ for (unsigned k = numDigits; k < 9; k++)
+ d *= 10;
+ ft.tv_nsec /= d;
+ ft.tv_nsec *= d;
+ }
+}
+*/
+
+int Compare_FiTime(const CFiTime *a1, const CFiTime *a2)
+{
+ if (a1->tv_sec < a2->tv_sec) return -1;
+ if (a1->tv_sec > a2->tv_sec) return 1;
+ if (a1->tv_nsec < a2->tv_nsec) return -1;
+ if (a1->tv_nsec > a2->tv_nsec) return 1;
+ return 0;
+}
+
+bool FILETIME_To_timespec(const FILETIME &ft, timespec &ts)
+{
+ UInt32 quantums;
+ const Int64 sec = NWindows::NTime::FileTime_To_UnixTime64_and_Quantums(ft, quantums);
+ // time_t is long
+ const time_t sec2 = (time_t)sec;
+ if (sec2 == sec)
+ {
+ ts.tv_sec = sec2;
+ ts.tv_nsec = (long)(quantums * 100);
+ return true;
+ }
+ return false;
+}
+
+void FiTime_To_FILETIME_ns100(const CFiTime &ts, FILETIME &ft, unsigned &ns100)
+{
+ const UInt64 v = NWindows::NTime::UnixTime64_To_FileTime64(ts.tv_sec) + ((UInt64)ts.tv_nsec / 100);
+ ns100 = (unsigned)((UInt64)ts.tv_nsec % 100);
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+}
+
+void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft)
+{
+ const UInt64 v = NWindows::NTime::UnixTime64_To_FileTime64(ts.tv_sec) + ((UInt64)ts.tv_nsec / 100);
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+}
+
+#endif
diff --git a/3rdparty/lzma/CPP/Windows/TimeUtils.h b/3rdparty/lzma/CPP/Windows/TimeUtils.h
index d3033ede3ef..4a9d0f2fade 100644
--- a/3rdparty/lzma/CPP/Windows/TimeUtils.h
+++ b/3rdparty/lzma/CPP/Windows/TimeUtils.h
@@ -1,24 +1,146 @@
// Windows/TimeUtils.h
-#ifndef __WINDOWS_TIME_UTILS_H
-#define __WINDOWS_TIME_UTILS_H
+#ifndef ZIP7_INC_WINDOWS_TIME_UTILS_H
+#define ZIP7_INC_WINDOWS_TIME_UTILS_H
#include "../Common/MyTypes.h"
#include "../Common/MyWindows.h"
+#include "PropVariant.h"
+
+inline UInt64 FILETIME_To_UInt64(const FILETIME &ft)
+{
+ return (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+}
+
+inline void FILETIME_Clear(FILETIME &ft)
+{
+ ft.dwLowDateTime = 0;
+ ft.dwHighDateTime = 0;
+}
+
+inline bool FILETIME_IsZero(const FILETIME &ft)
+{
+ return (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0);
+}
+
+
+#ifdef _WIN32
+ #define CFiTime FILETIME
+ #define Compare_FiTime ::CompareFileTime
+ inline void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft)
+ {
+ ft = ts;
+ }
+ /*
+ inline void FILETIME_To_FiTime(const FILETIME &ft, CFiTime &ts)
+ {
+ ts = ft;
+ }
+ */
+ inline void FiTime_Clear(CFiTime &ft)
+ {
+ ft.dwLowDateTime = 0;
+ ft.dwHighDateTime = 0;
+ }
+#else
+
+ #include <sys/stat.h>
+
+ #if defined(_AIX)
+ #define CFiTime st_timespec
+ #else
+ #define CFiTime timespec
+ #endif
+ int Compare_FiTime(const CFiTime *a1, const CFiTime *a2);
+ bool FILETIME_To_timespec(const FILETIME &ft, CFiTime &ts);
+ void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft);
+ void FiTime_To_FILETIME_ns100(const CFiTime &ts, FILETIME &ft, unsigned &ns100);
+ inline void FiTime_Clear(CFiTime &ft)
+ {
+ ft.tv_sec = 0;
+ ft.tv_nsec = 0;
+ }
+
+ #ifdef __APPLE__
+ #define ST_MTIME(st) st.st_mtimespec
+ #define ST_ATIME(st) st.st_atimespec
+ #define ST_CTIME(st) st.st_ctimespec
+ #else
+ #define ST_MTIME(st) st.st_mtim
+ #define ST_ATIME(st) st.st_atim
+ #define ST_CTIME(st) st.st_ctim
+ #endif
+
+#endif
+
+// void FiTime_Normalize_With_Prec(CFiTime &ft, unsigned prec);
namespace NWindows {
namespace NTime {
-bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime) throw();
-bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime) throw();
-void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime) throw();
-bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &fileTime) throw();
-bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw();
-Int64 FileTimeToUnixTime64(const FILETIME &ft) throw();
+bool DosTime_To_FileTime(UInt32 dosTime, FILETIME &fileTime) throw();
+bool UtcFileTime_To_LocalDosTime(const FILETIME &utc, UInt32 &dosTime) throw();
+bool FileTime_To_DosTime(const FILETIME &fileTime, UInt32 &dosTime) throw();
+
+// UInt32 Unix Time : for dates 1970-2106
+UInt64 UnixTime_To_FileTime64(UInt32 unixTime) throw();
+void UnixTime_To_FileTime(UInt32 unixTime, FILETIME &fileTime) throw();
+
+// Int64 Unix Time : negative values for dates before 1970
+UInt64 UnixTime64_To_FileTime64(Int64 unixTime) throw(); // no check
+bool UnixTime64_To_FileTime64(Int64 unixTime, UInt64 &fileTime) throw();
+bool UnixTime64_To_FileTime(Int64 unixTime, FILETIME &fileTime) throw();
+
+Int64 FileTime64_To_UnixTime64(UInt64 ft64) throw();
+bool FileTime_To_UnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw();
+Int64 FileTime_To_UnixTime64(const FILETIME &ft) throw();
+Int64 FileTime_To_UnixTime64_and_Quantums(const FILETIME &ft, UInt32 &quantums) throw();
+
bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw();
+
+void GetCurUtc_FiTime(CFiTime &ft) throw();
+#ifdef _WIN32
+#define GetCurUtcFileTime GetCurUtc_FiTime
+#else
void GetCurUtcFileTime(FILETIME &ft) throw();
+#endif
}}
+inline void PropVariant_SetFrom_UnixTime(NWindows::NCOM::CPropVariant &prop, UInt32 unixTime)
+{
+ FILETIME ft;
+ NWindows::NTime::UnixTime_To_FileTime(unixTime, ft);
+ prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_Unix);
+}
+
+inline void PropVariant_SetFrom_NtfsTime(NWindows::NCOM::CPropVariant &prop, const FILETIME &ft)
+{
+ prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_100ns);
+}
+
+inline void PropVariant_SetFrom_FiTime(NWindows::NCOM::CPropVariant &prop, const CFiTime &fts)
+{
+ #ifdef _WIN32
+ PropVariant_SetFrom_NtfsTime(prop, fts);
+ #else
+ unsigned ns100;
+ FILETIME ft;
+ FiTime_To_FILETIME_ns100(fts, ft, ns100);
+ prop.SetAsTimeFrom_FT_Prec_Ns100(ft, k_PropVar_TimePrec_1ns, ns100);
+ #endif
+}
+
+inline bool PropVariant_SetFrom_DosTime(NWindows::NCOM::CPropVariant &prop, UInt32 dosTime)
+{
+ FILETIME localFileTime, utc;
+ if (!NWindows::NTime::DosTime_To_FileTime(dosTime, localFileTime))
+ return false;
+ if (!LocalFileTimeToFileTime(&localFileTime, &utc))
+ return false;
+ prop.SetAsTimeFrom_FT_Prec(utc, k_PropVar_TimePrec_DOS);
+ return true;
+}
+
#endif
diff --git a/3rdparty/lzma/CPP/Windows/Window.cpp b/3rdparty/lzma/CPP/Windows/Window.cpp
index 365850223ce..102c503a567 100644
--- a/3rdparty/lzma/CPP/Windows/Window.cpp
+++ b/3rdparty/lzma/CPP/Windows/Window.cpp
@@ -111,15 +111,15 @@ bool MySetWindowText(HWND wnd, LPCWSTR s)
}
#endif
-bool CWindow::GetText(CSysString &s)
+bool CWindow::GetText(CSysString &s) const
{
s.Empty();
- int len = GetTextLength();
+ unsigned len = (unsigned)GetTextLength();
if (len == 0)
return (::GetLastError() == ERROR_SUCCESS);
TCHAR *p = s.GetBuf(len);
{
- int len2 = GetText(p, len + 1);
+ const unsigned len2 = (unsigned)GetText(p, (int)(len + 1));
if (len > len2)
len = len2;
}
@@ -130,17 +130,17 @@ bool CWindow::GetText(CSysString &s)
}
#ifndef _UNICODE
-bool CWindow::GetText(UString &s)
+bool CWindow::GetText(UString &s) const
{
if (g_IsNT)
{
s.Empty();
- int len = GetWindowTextLengthW(_window);
+ unsigned len = (unsigned)GetWindowTextLengthW(_window);
if (len == 0)
return (::GetLastError() == ERROR_SUCCESS);
wchar_t *p = s.GetBuf(len);
{
- int len2 = GetWindowTextW(_window, p, len + 1);
+ const unsigned len2 = (unsigned)GetWindowTextW(_window, p, (int)(len + 1));
if (len > len2)
len = len2;
}
@@ -150,7 +150,7 @@ bool CWindow::GetText(UString &s)
return true;
}
CSysString sysString;
- bool result = GetText(sysString);
+ const bool result = GetText(sysString);
MultiByteToUnicodeString2(s, sysString);
return result;
}
diff --git a/3rdparty/lzma/CPP/Windows/Window.h b/3rdparty/lzma/CPP/Windows/Window.h
index 3bda6795d0c..a99143bd131 100644
--- a/3rdparty/lzma/CPP/Windows/Window.h
+++ b/3rdparty/lzma/CPP/Windows/Window.h
@@ -1,7 +1,7 @@
// Windows/Window.h
-#ifndef __WINDOWS_WINDOW_H
-#define __WINDOWS_WINDOW_H
+#ifndef ZIP7_INC_WINDOWS_WINDOW_H
+#define ZIP7_INC_WINDOWS_WINDOW_H
#include "../Common/MyWindows.h"
#include "../Common/MyString.h"
@@ -9,23 +9,100 @@
#include "Defs.h"
#ifndef UNDER_CE
+#ifdef WM_CHANGEUISTATE
+#define Z7_WIN_WM_CHANGEUISTATE WM_CHANGEUISTATE
+#define Z7_WIN_WM_UPDATEUISTATE WM_UPDATEUISTATE
+#define Z7_WIN_WM_QUERYUISTATE WM_QUERYUISTATE
+#else
+// these are defined for (_WIN32_WINNT >= 0x0500):
+#define Z7_WIN_WM_CHANGEUISTATE 0x0127
+#define Z7_WIN_WM_UPDATEUISTATE 0x0128
+#define Z7_WIN_WM_QUERYUISTATE 0x0129
+#endif
+
+#ifdef UIS_SET
-#define MY__WM_CHANGEUISTATE 0x0127
-#define MY__WM_UPDATEUISTATE 0x0128
-#define MY__WM_QUERYUISTATE 0x0129
+#define Z7_WIN_UIS_SET UIS_SET
+#define Z7_WIN_UIS_CLEAR UIS_CLEAR
+#define Z7_WIN_UIS_INITIALIZE UIS_INITIALIZE
+#define Z7_WIN_UISF_HIDEFOCUS UISF_HIDEFOCUS
+#define Z7_WIN_UISF_HIDEACCEL UISF_HIDEACCEL
+
+#else
+// these are defined for (_WIN32_WINNT >= 0x0500):
// LOWORD(wParam) values in WM_*UISTATE
-#define MY__UIS_SET 1
-#define MY__UIS_CLEAR 2
-#define MY__UIS_INITIALIZE 3
+#define Z7_WIN_UIS_SET 1
+#define Z7_WIN_UIS_CLEAR 2
+#define Z7_WIN_UIS_INITIALIZE 3
// HIWORD(wParam) values in WM_*UISTATE
-#define MY__UISF_HIDEFOCUS 0x1
-#define MY__UISF_HIDEACCEL 0x2
-#define MY__UISF_ACTIVE 0x4
+#define Z7_WIN_UISF_HIDEFOCUS 0x1
+#define Z7_WIN_UISF_HIDEACCEL 0x2
+// defined for for (_WIN32_WINNT >= 0x0501):
+// #define Z7_WIN_UISF_ACTIVE 0x4
#endif
+#endif // UNDER_CE
+
+
+#ifdef Z7_OLD_WIN_SDK
+
+// #define VK_OEM_1 0xBA // ';:' for US
+#define VK_OEM_PLUS 0xBB // '+' any country
+// #define VK_OEM_COMMA 0xBC // ',' any country
+#define VK_OEM_MINUS 0xBD // '-' any country
+// #define VK_OEM_PERIOD 0xBE // '.' any country
+// #define VK_OEM_2 0xBF // '/?' for US
+// #define VK_OEM_3 0xC0 // '`~' for US
+
+// #ifndef GWLP_USERDATA
+#define GWLP_WNDPROC (-4)
+#define GWLP_USERDATA (-21)
+// #endif
+#define DWLP_MSGRESULT 0
+// #define DWLP_DLGPROC DWLP_MSGRESULT + sizeof(LRESULT)
+// #define DWLP_USER DWLP_DLGPROC + sizeof(DLGPROC)
+
+#define BTNS_BUTTON TBSTYLE_BUTTON // 0x0000
+
+/*
+vc6 defines INT_PTR via long:
+ typedef long INT_PTR, *PINT_PTR;
+ typedef unsigned long UINT_PTR, *PUINT_PTR;
+but newer sdk (sdk2003+) defines INT_PTR via int:
+ typedef _W64 int INT_PTR, *PINT_PTR;
+ typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
+*/
+
+#define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
+
+#define GetWindowLongPtrA GetWindowLongA
+#define GetWindowLongPtrW GetWindowLongW
+#ifdef UNICODE
+#define GetWindowLongPtr GetWindowLongPtrW
+#else
+#define GetWindowLongPtr GetWindowLongPtrA
+#endif // !UNICODE
+
+#define SetWindowLongPtrA SetWindowLongA
+#define SetWindowLongPtrW SetWindowLongW
+#ifdef UNICODE
+#define SetWindowLongPtr SetWindowLongPtrW
+#else
+#define SetWindowLongPtr SetWindowLongPtrA
+#endif // !UNICODE
+
+#define ListView_SetCheckState(hwndLV, i, fCheck) \
+ ListView_SetItemState(hwndLV, i, INDEXTOSTATEIMAGEMASK((fCheck)?2:1), LVIS_STATEIMAGEMASK)
+
+#endif // Z7_OLD_WIN_SDK
+
+inline bool LRESULTToBool(LRESULT v) { return (v != FALSE); }
+
+#define MY_int_TO_WPARAM(i) ((WPARAM)(INT_PTR)(i))
+
namespace NWindows {
inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass)
@@ -52,12 +129,13 @@ bool MySetWindowText(HWND wnd, LPCWSTR s);
class CWindow
{
+ Z7_CLASS_NO_COPY(CWindow)
private:
- // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags);
+ // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags);
protected:
HWND _window;
public:
- CWindow(HWND newWindow = NULL): _window(newWindow){};
+ CWindow(HWND newWindow = NULL): _window(newWindow) {}
CWindow& operator=(HWND newWindow)
{
_window = newWindow;
@@ -171,9 +249,10 @@ public:
bool Update() { return BOOLToBool(::UpdateWindow(_window)); }
bool InvalidateRect(LPCRECT rect, bool backgroundErase = true)
{ return BOOLToBool(::InvalidateRect(_window, rect, BoolToBOOL(backgroundErase))); }
- void SetRedraw(bool redraw = true) { SendMsg(WM_SETREDRAW, BoolToBOOL(redraw), 0); }
+ void SetRedraw(bool redraw = true) { SendMsg(WM_SETREDRAW, (WPARAM)BoolToBOOL(redraw), 0); }
LONG_PTR SetStyle(LONG_PTR style) { return SetLongPtr(GWL_STYLE, style); }
+ // LONG_PTR SetStyle(DWORD style) { return SetLongPtr(GWL_STYLE, (LONG_PTR)style); }
LONG_PTR GetStyle() const { return GetLongPtr(GWL_STYLE); }
// bool MyIsMaximized() const { return ((GetStyle() & WS_MAXIMIZE) != 0); }
@@ -244,21 +323,21 @@ public:
int GetTextLength() const
{ return GetWindowTextLength(_window); }
- UINT GetText(LPTSTR string, int maxCount) const
+ int GetText(LPTSTR string, int maxCount) const
{ return GetWindowText(_window, string, maxCount); }
- bool GetText(CSysString &s);
+ bool GetText(CSysString &s) const;
#ifndef _UNICODE
/*
UINT GetText(LPWSTR string, int maxCount) const
{ return GetWindowTextW(_window, string, maxCount); }
*/
- bool GetText(UString &s);
+ bool GetText(UString &s) const;
#endif
bool Enable(bool enable)
{ return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); }
- bool IsEnabled()
+ bool IsEnabled() const
{ return BOOLToBool(::IsWindowEnabled(_window)); }
#ifndef UNDER_CE
@@ -266,7 +345,7 @@ public:
{ return ::GetSystemMenu(_window, BoolToBOOL(revert)); }
#endif
- UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = 0)
+ UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = NULL)
{ return ::SetTimer(_window, idEvent, elapse, timerFunc); }
bool KillTimer(UINT_PTR idEvent)
{return BOOLToBool(::KillTimer(_window, idEvent)); }