diff options
Diffstat (limited to 'CPP/Windows')
79 files changed, 2345 insertions, 1123 deletions
diff --git a/CPP/Windows/COM.h b/CPP/Windows/COM.h index cee7f70..a8780ca 100644 --- a/CPP/Windows/COM.h +++ b/CPP/Windows/COM.h | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | // Windows/COM.h | 1 | // Windows/COM.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_COM_H | 3 | #ifndef ZIP7_INC_WINDOWS_COM_H |
| 4 | #define __WINDOWS_COM_H | 4 | #define ZIP7_INC_WINDOWS_COM_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | // #include "../Common/MyString.h" |
| 7 | 7 | ||
| 8 | namespace NWindows { | 8 | namespace NWindows { |
| 9 | namespace NCOM { | 9 | namespace NCOM { |
| @@ -21,17 +21,18 @@ public: | |||
| 21 | // it's single thread. Do we need multithread? | 21 | // it's single thread. Do we need multithread? |
| 22 | CoInitialize(NULL); | 22 | CoInitialize(NULL); |
| 23 | #endif | 23 | #endif |
| 24 | }; | 24 | } |
| 25 | ~CComInitializer() { CoUninitialize(); } | 25 | ~CComInitializer() { CoUninitialize(); } |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | class CStgMedium | 28 | /* |
| 29 | class CStgMedium2 | ||
| 29 | { | 30 | { |
| 30 | STGMEDIUM _object; | 31 | STGMEDIUM _object; |
| 31 | public: | ||
| 32 | bool _mustBeReleased; | 32 | bool _mustBeReleased; |
| 33 | CStgMedium(): _mustBeReleased(false) {} | 33 | public: |
| 34 | ~CStgMedium() { Free(); } | 34 | CStgMedium2(): _mustBeReleased(false) {} |
| 35 | ~CStgMedium2() { Free(); } | ||
| 35 | void Free() | 36 | void Free() |
| 36 | { | 37 | { |
| 37 | if (_mustBeReleased) | 38 | if (_mustBeReleased) |
| @@ -42,6 +43,21 @@ public: | |||
| 42 | STGMEDIUM* operator->() { return &_object;} | 43 | STGMEDIUM* operator->() { return &_object;} |
| 43 | STGMEDIUM* operator&() { return &_object; } | 44 | STGMEDIUM* operator&() { return &_object; } |
| 44 | }; | 45 | }; |
| 46 | */ | ||
| 47 | |||
| 48 | struct CStgMedium: public STGMEDIUM | ||
| 49 | { | ||
| 50 | CStgMedium() | ||
| 51 | { | ||
| 52 | tymed = TYMED_NULL; // 0 | ||
| 53 | hGlobal = NULL; | ||
| 54 | pUnkForRelease = NULL; | ||
| 55 | } | ||
| 56 | ~CStgMedium() | ||
| 57 | { | ||
| 58 | ReleaseStgMedium(this); | ||
| 59 | } | ||
| 60 | }; | ||
| 45 | 61 | ||
| 46 | #endif | 62 | #endif |
| 47 | 63 | ||
diff --git a/CPP/Windows/Clipboard.h b/CPP/Windows/Clipboard.h index 60fedc1..3b4f2fe 100644 --- a/CPP/Windows/Clipboard.h +++ b/CPP/Windows/Clipboard.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Clipboard.h | 1 | // Windows/Clipboard.h |
| 2 | 2 | ||
| 3 | #ifndef __CLIPBOARD_H | 3 | #ifndef ZIP7_INC_CLIPBOARD_H |
| 4 | #define __CLIPBOARD_H | 4 | #define ZIP7_INC_CLIPBOARD_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| @@ -11,7 +11,7 @@ class CClipboard | |||
| 11 | { | 11 | { |
| 12 | bool m_Open; | 12 | bool m_Open; |
| 13 | public: | 13 | public: |
| 14 | CClipboard(): m_Open(false) {}; | 14 | CClipboard(): m_Open(false) {} |
| 15 | ~CClipboard() { Close(); } | 15 | ~CClipboard() { Close(); } |
| 16 | bool Open(HWND wndNewOwner) throw(); | 16 | bool Open(HWND wndNewOwner) throw(); |
| 17 | bool Close() throw(); | 17 | bool Close() throw(); |
diff --git a/CPP/Windows/CommonDialog.cpp b/CPP/Windows/CommonDialog.cpp index eaaecad..7a92d5f 100644 --- a/CPP/Windows/CommonDialog.cpp +++ b/CPP/Windows/CommonDialog.cpp | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
| 4 | 4 | ||
| 5 | #include "../Common/MyWindows.h" | 5 | #include "../Common/MyBuffer.h" |
| 6 | 6 | ||
| 7 | #ifdef UNDER_CE | 7 | #ifdef UNDER_CE |
| 8 | #include <commdlg.h> | 8 | #include <commdlg.h> |
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include "CommonDialog.h" | 15 | #include "CommonDialog.h" |
| 16 | #include "Defs.h" | 16 | #include "Defs.h" |
| 17 | // #include "FileDir.h" | ||
| 17 | 18 | ||
| 18 | #ifndef _UNICODE | 19 | #ifndef _UNICODE |
| 19 | extern bool g_IsNT; | 20 | extern bool g_IsNT; |
| @@ -21,61 +22,46 @@ extern bool g_IsNT; | |||
| 21 | 22 | ||
| 22 | namespace NWindows { | 23 | namespace NWindows { |
| 23 | 24 | ||
| 24 | #ifndef _UNICODE | 25 | /* |
| 26 | GetSaveFileName() | ||
| 27 | GetOpenFileName() | ||
| 28 | OPENFILENAME | ||
| 25 | 29 | ||
| 26 | class CDoubleZeroStringListA | 30 | (lpstrInitialDir) : the initial directory. |
| 27 | { | 31 | DOCs: the algorithm for selecting the initial directory varies on different platforms: |
| 28 | LPTSTR Buf; | ||
| 29 | unsigned Size; | ||
| 30 | public: | ||
| 31 | CDoubleZeroStringListA(LPSTR buf, unsigned size): Buf(buf), Size(size) {} | ||
| 32 | bool Add(LPCSTR s) throw(); | ||
| 33 | void Finish() { *Buf = 0; } | ||
| 34 | }; | ||
| 35 | |||
| 36 | bool CDoubleZeroStringListA::Add(LPCSTR s) throw() | ||
| 37 | { | 32 | { |
| 38 | unsigned len = MyStringLen(s) + 1; | 33 | Win2000/XP/Vista: |
| 39 | if (len >= Size) | 34 | 1. If lpstrFile contains a path, that path is the initial directory. |
| 40 | return false; | 35 | 2. Otherwise, lpstrInitialDir specifies the initial directory. |
| 41 | MyStringCopy(Buf, s); | 36 | |
| 42 | Buf += len; | 37 | Win7: |
| 43 | Size -= len; | 38 | If lpstrInitialDir has the same value as was passed the first time |
| 44 | return true; | 39 | the application used an Open or Save As dialog box, the path |
| 40 | most recently selected by the user is used as the initial directory. | ||
| 45 | } | 41 | } |
| 46 | 42 | ||
| 47 | #endif | 43 | Win10: |
| 44 | in: | ||
| 45 | function supports (lpstrInitialDir) path with super prefix "\\\\?\\" | ||
| 46 | function supports (lpstrInitialDir) path with long path | ||
| 47 | function doesn't support absolute (lpstrFile) path with super prefix "\\\\?\\" | ||
| 48 | function doesn't support absolute (lpstrFile) path with long path | ||
| 49 | out: the path with super prefix "\\\\?\\" will be returned, if selected path is long | ||
| 48 | 50 | ||
| 49 | class CDoubleZeroStringListW | 51 | WinXP-64 and Win10: if no filters, the system shows all files. |
| 50 | { | 52 | but DOCs say: If all three members are zero or NULL, |
| 51 | LPWSTR Buf; | 53 | the system does not use any filters and does not |
| 52 | unsigned Size; | 54 | show any files in the file list control of the dialog box. |
| 53 | public: | ||
| 54 | CDoubleZeroStringListW(LPWSTR buf, unsigned size): Buf(buf), Size(size) {} | ||
| 55 | bool Add(LPCWSTR s) throw(); | ||
| 56 | void Finish() { *Buf = 0; } | ||
| 57 | }; | ||
| 58 | |||
| 59 | bool CDoubleZeroStringListW::Add(LPCWSTR s) throw() | ||
| 60 | { | ||
| 61 | unsigned len = MyStringLen(s) + 1; | ||
| 62 | if (len >= Size) | ||
| 63 | return false; | ||
| 64 | MyStringCopy(Buf, s); | ||
| 65 | Buf += len; | ||
| 66 | Size -= len; | ||
| 67 | return true; | ||
| 68 | } | ||
| 69 | 55 | ||
| 56 | in Win7+: GetOpenFileName() and GetSaveFileName() | ||
| 57 | do not support pstrCustomFilter feature anymore | ||
| 58 | */ | ||
| 70 | 59 | ||
| 71 | #ifdef UNDER_CE | 60 | #ifdef UNDER_CE |
| 72 | #define MY__OFN_PROJECT 0x00400000 | 61 | #define MY_OFN_PROJECT 0x00400000 |
| 73 | #define MY__OFN_SHOW_ALL 0x01000000 | 62 | #define MY_OFN_SHOW_ALL 0x01000000 |
| 74 | #endif | 63 | #endif |
| 75 | 64 | ||
| 76 | /* if (lpstrFilter == NULL && nFilterIndex == 0) | ||
| 77 | MSDN : "the system doesn't show any files", | ||
| 78 | but WinXP-64 shows all files. Why ??? */ | ||
| 79 | 65 | ||
| 80 | /* | 66 | /* |
| 81 | structures | 67 | structures |
| @@ -89,16 +75,16 @@ contain additional members: | |||
| 89 | #endif | 75 | #endif |
| 90 | 76 | ||
| 91 | If we compile the source code with (_WIN32_WINNT >= 0x0500), some functions | 77 | If we compile the source code with (_WIN32_WINNT >= 0x0500), some functions |
| 92 | will not work at NT 4.0, if we use sizeof(OPENFILENAME*). | 78 | will not work at NT 4.0, if we use sizeof(OPENFILENAME). |
| 93 | So we use size of old version of structure. */ | 79 | We try to use reduced structure OPENFILENAME_NT4. |
| 80 | */ | ||
| 94 | 81 | ||
| 95 | #if defined(UNDER_CE) || defined(_WIN64) || (_WIN32_WINNT < 0x0500) | 82 | // #if defined(_WIN64) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500) |
| 96 | // || !defined(WINVER) | 83 | #if defined(__GNUC__) && (__GNUC__ <= 9) || defined(Z7_OLD_WIN_SDK) |
| 97 | #ifndef _UNICODE | 84 | #ifndef _UNICODE |
| 98 | #define my_compatib_OPENFILENAMEA_size sizeof(OPENFILENAMEA) | 85 | #define my_compatib_OPENFILENAMEA OPENFILENAMEA |
| 99 | #endif | 86 | #endif |
| 100 | #define my_compatib_OPENFILENAMEW_size sizeof(OPENFILENAMEW) | 87 | #define my_compatib_OPENFILENAMEW OPENFILENAMEW |
| 101 | #else | ||
| 102 | 88 | ||
| 103 | // MinGW doesn't support some required macros. So we define them here: | 89 | // MinGW doesn't support some required macros. So we define them here: |
| 104 | #ifndef CDSIZEOF_STRUCT | 90 | #ifndef CDSIZEOF_STRUCT |
| @@ -117,91 +103,166 @@ So we use size of old version of structure. */ | |||
| 117 | #define my_compatib_OPENFILENAMEA_size OPENFILENAME_SIZE_VERSION_400A | 103 | #define my_compatib_OPENFILENAMEA_size OPENFILENAME_SIZE_VERSION_400A |
| 118 | #endif | 104 | #endif |
| 119 | #define my_compatib_OPENFILENAMEW_size OPENFILENAME_SIZE_VERSION_400W | 105 | #define my_compatib_OPENFILENAMEW_size OPENFILENAME_SIZE_VERSION_400W |
| 106 | #else | ||
| 107 | #ifndef _UNICODE | ||
| 108 | #define my_compatib_OPENFILENAMEA OPENFILENAME_NT4A | ||
| 109 | #define my_compatib_OPENFILENAMEA_size sizeof(my_compatib_OPENFILENAMEA) | ||
| 110 | #endif | ||
| 111 | #define my_compatib_OPENFILENAMEW OPENFILENAME_NT4W | ||
| 112 | #define my_compatib_OPENFILENAMEW_size sizeof(my_compatib_OPENFILENAMEW) | ||
| 113 | #endif | ||
| 114 | /* | ||
| 115 | #elif defined(UNDER_CE) || defined(_WIN64) || (_WIN32_WINNT < 0x0500) | ||
| 116 | // || !defined(WINVER) | ||
| 117 | #ifndef _UNICODE | ||
| 118 | #define my_compatib_OPENFILENAMEA OPENFILENAMEA | ||
| 119 | #define my_compatib_OPENFILENAMEA_size sizeof(OPENFILENAMEA) | ||
| 120 | #endif | ||
| 121 | #define my_compatib_OPENFILENAMEW OPENFILENAMEW | ||
| 122 | #define my_compatib_OPENFILENAMEW_size sizeof(OPENFILENAMEW) | ||
| 123 | #else | ||
| 124 | |||
| 120 | #endif | 125 | #endif |
| 126 | */ | ||
| 121 | 127 | ||
| 122 | #ifndef _UNICODE | 128 | #ifndef _UNICODE |
| 123 | #define CONV_U_To_A(dest, src, temp) AString temp; if (src) { temp = GetSystemString(src); dest = temp; } | 129 | #define CONV_U_To_A(dest, src, temp) AString temp; if (src) { temp = GetSystemString(src); dest = temp; } |
| 124 | #endif | 130 | #endif |
| 125 | 131 | ||
| 126 | bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, | 132 | bool CCommonDialogInfo::CommonDlg_BrowseForFile(LPCWSTR lpstrInitialDir, const UStringVector &filters) |
| 127 | LPCWSTR initialDir, | ||
| 128 | LPCWSTR filePath, | ||
| 129 | LPCWSTR filterDescription, | ||
| 130 | LPCWSTR filter, | ||
| 131 | UString &resPath | ||
| 132 | #ifdef UNDER_CE | ||
| 133 | , bool openFolder | ||
| 134 | #endif | ||
| 135 | ) | ||
| 136 | { | 133 | { |
| 137 | const unsigned kBufSize = MAX_PATH * 2; | 134 | /* GetSaveFileName() and GetOpenFileName() could change current dir, |
| 138 | const unsigned kFilterBufSize = MAX_PATH; | 135 | if OFN_NOCHANGEDIR is not used. |
| 139 | if (!filter) | 136 | We can restore current dir manually, if it's required. |
| 140 | filter = L"*.*"; | 137 | 22.02: we use OFN_NOCHANGEDIR. So we don't need to restore current dir manually. */ |
| 141 | #ifndef _UNICODE | 138 | // NFile::NDir::CCurrentDirRestorer curDirRestorer; |
| 139 | |||
| 140 | #ifndef _UNICODE | ||
| 142 | if (!g_IsNT) | 141 | if (!g_IsNT) |
| 143 | { | 142 | { |
| 144 | CHAR buf[kBufSize]; | 143 | AString tempPath; |
| 145 | MyStringCopy(buf, (const char *)GetSystemString(filePath)); | 144 | AStringVector f; |
| 146 | // OPENFILENAME_NT4A | 145 | unsigned i; |
| 147 | OPENFILENAMEA p; | 146 | for (i = 0; i < filters.Size(); i++) |
| 147 | f.Add(GetSystemString(filters[i])); | ||
| 148 | unsigned size = f.Size() + 1; | ||
| 149 | for (i = 0; i < f.Size(); i++) | ||
| 150 | size += f[i].Len(); | ||
| 151 | CObjArray<char> filterBuf(size); | ||
| 152 | // memset(filterBuf, 0, size * sizeof(char)); | ||
| 153 | { | ||
| 154 | char *dest = filterBuf; | ||
| 155 | for (i = 0; i < f.Size(); i++) | ||
| 156 | { | ||
| 157 | const AString &s = f[i]; | ||
| 158 | MyStringCopy(dest, s); | ||
| 159 | dest += s.Len() + 1; | ||
| 160 | } | ||
| 161 | *dest = 0; | ||
| 162 | } | ||
| 163 | my_compatib_OPENFILENAMEA p; | ||
| 148 | memset(&p, 0, sizeof(p)); | 164 | memset(&p, 0, sizeof(p)); |
| 149 | p.lStructSize = my_compatib_OPENFILENAMEA_size; | 165 | p.lStructSize = my_compatib_OPENFILENAMEA_size; |
| 150 | p.hwndOwner = hwnd; | 166 | p.hwndOwner = hwndOwner; |
| 151 | CHAR filterBuf[kFilterBufSize]; | 167 | if (size > 1) |
| 152 | { | 168 | { |
| 153 | CDoubleZeroStringListA dz(filterBuf, kFilterBufSize); | ||
| 154 | dz.Add(GetSystemString(filterDescription ? filterDescription : filter)); | ||
| 155 | dz.Add(GetSystemString(filter)); | ||
| 156 | dz.Finish(); | ||
| 157 | p.lpstrFilter = filterBuf; | 169 | p.lpstrFilter = filterBuf; |
| 158 | p.nFilterIndex = 1; | 170 | p.nFilterIndex = (DWORD)(FilterIndex + 1); |
| 171 | } | ||
| 172 | |||
| 173 | CONV_U_To_A(p.lpstrInitialDir, lpstrInitialDir, initialDir_a) | ||
| 174 | CONV_U_To_A(p.lpstrTitle, lpstrTitle, title_a) | ||
| 175 | |||
| 176 | const AString filePath_a = GetSystemString(FilePath); | ||
| 177 | const unsigned bufSize = MAX_PATH * 8 | ||
| 178 | + filePath_a.Len() | ||
| 179 | + initialDir_a.Len(); | ||
| 180 | p.nMaxFile = bufSize; | ||
| 181 | p.lpstrFile = tempPath.GetBuf(bufSize); | ||
| 182 | MyStringCopy(p.lpstrFile, filePath_a); | ||
| 183 | p.Flags = | ||
| 184 | OFN_EXPLORER | ||
| 185 | | OFN_HIDEREADONLY | ||
| 186 | | OFN_NOCHANGEDIR; | ||
| 187 | const BOOL b = SaveMode ? | ||
| 188 | ::GetSaveFileNameA((LPOPENFILENAMEA)(void *)&p) : | ||
| 189 | ::GetOpenFileNameA((LPOPENFILENAMEA)(void *)&p); | ||
| 190 | if (!b) | ||
| 191 | return false; | ||
| 192 | { | ||
| 193 | tempPath.ReleaseBuf_CalcLen(bufSize); | ||
| 194 | FilePath = GetUnicodeString(tempPath); | ||
| 195 | FilterIndex = (int)p.nFilterIndex - 1; | ||
| 196 | return true; | ||
| 159 | } | 197 | } |
| 160 | |||
| 161 | p.lpstrFile = buf; | ||
| 162 | p.nMaxFile = kBufSize; | ||
| 163 | CONV_U_To_A(p.lpstrInitialDir, initialDir, initialDirA); | ||
| 164 | CONV_U_To_A(p.lpstrTitle, title, titleA); | ||
| 165 | p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; | ||
| 166 | |||
| 167 | bool res = BOOLToBool(::GetOpenFileNameA(&p)); | ||
| 168 | resPath = GetUnicodeString(buf); | ||
| 169 | return res; | ||
| 170 | } | 198 | } |
| 171 | else | 199 | else |
| 172 | #endif | 200 | #endif |
| 173 | { | 201 | { |
| 174 | WCHAR buf[kBufSize]; | 202 | UString tempPath; |
| 175 | MyStringCopy(buf, filePath); | 203 | unsigned size = filters.Size() + 1; |
| 176 | // OPENFILENAME_NT4W | 204 | unsigned i; |
| 177 | OPENFILENAMEW p; | 205 | for (i = 0; i < filters.Size(); i++) |
| 206 | size += filters[i].Len(); | ||
| 207 | CObjArray<wchar_t> filterBuf(size); | ||
| 208 | // memset(filterBuf, 0, size * sizeof(wchar_t)); | ||
| 209 | { | ||
| 210 | wchar_t *dest = filterBuf; | ||
| 211 | for (i = 0; i < filters.Size(); i++) | ||
| 212 | { | ||
| 213 | const UString &s = filters[i]; | ||
| 214 | MyStringCopy(dest, s); | ||
| 215 | dest += s.Len() + 1; | ||
| 216 | } | ||
| 217 | *dest = 0; | ||
| 218 | // if ((unsigned)(dest + 1 - filterBuf) != size) return false; | ||
| 219 | } | ||
| 220 | my_compatib_OPENFILENAMEW p; | ||
| 178 | memset(&p, 0, sizeof(p)); | 221 | memset(&p, 0, sizeof(p)); |
| 179 | p.lStructSize = my_compatib_OPENFILENAMEW_size; | 222 | p.lStructSize = my_compatib_OPENFILENAMEW_size; |
| 180 | p.hwndOwner = hwnd; | 223 | p.hwndOwner = hwndOwner; |
| 181 | 224 | if (size > 1) | |
| 182 | WCHAR filterBuf[kFilterBufSize]; | ||
| 183 | { | 225 | { |
| 184 | CDoubleZeroStringListW dz(filterBuf, kFilterBufSize); | ||
| 185 | dz.Add(filterDescription ? filterDescription : filter); | ||
| 186 | dz.Add(filter); | ||
| 187 | dz.Finish(); | ||
| 188 | p.lpstrFilter = filterBuf; | 226 | p.lpstrFilter = filterBuf; |
| 189 | p.nFilterIndex = 1; | 227 | p.nFilterIndex = (DWORD)(FilterIndex + 1); |
| 190 | } | 228 | } |
| 191 | 229 | unsigned bufSize = MAX_PATH * 8 + FilePath.Len(); | |
| 192 | p.lpstrFile = buf; | 230 | if (lpstrInitialDir) |
| 193 | p.nMaxFile = kBufSize; | 231 | { |
| 194 | p.lpstrInitialDir = initialDir; | 232 | p.lpstrInitialDir = lpstrInitialDir; |
| 195 | p.lpstrTitle = title; | 233 | bufSize += MyStringLen(lpstrInitialDir); |
| 196 | p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | 234 | } |
| 197 | #ifdef UNDER_CE | 235 | p.nMaxFile = bufSize; |
| 198 | | (openFolder ? (MY__OFN_PROJECT | MY__OFN_SHOW_ALL) : 0) | 236 | p.lpstrFile = tempPath.GetBuf(bufSize); |
| 199 | #endif | 237 | MyStringCopy(p.lpstrFile, FilePath); |
| 238 | p.lpstrTitle = lpstrTitle; | ||
| 239 | p.Flags = | ||
| 240 | OFN_EXPLORER | ||
| 241 | | OFN_HIDEREADONLY | ||
| 242 | | OFN_NOCHANGEDIR | ||
| 243 | // | OFN_FORCESHOWHIDDEN // Win10 shows hidden items even without this flag | ||
| 244 | // | OFN_PATHMUSTEXIST | ||
| 245 | #ifdef UNDER_CE | ||
| 246 | | (OpenFolderMode ? (MY_OFN_PROJECT | MY_OFN_SHOW_ALL) : 0) | ||
| 247 | #endif | ||
| 200 | ; | 248 | ; |
| 201 | 249 | const BOOL b = SaveMode ? | |
| 202 | bool res = BOOLToBool(::GetOpenFileNameW(&p)); | 250 | ::GetSaveFileNameW((LPOPENFILENAMEW)(void *)&p) : |
| 203 | resPath = buf; | 251 | ::GetOpenFileNameW((LPOPENFILENAMEW)(void *)&p); |
| 204 | return res; | 252 | /* DOCs: lpstrFile : |
| 253 | if the buffer is too small, then: | ||
| 254 | - the function returns FALSE | ||
| 255 | - the CommDlgExtendedError() returns FNERR_BUFFERTOOSMALL | ||
| 256 | - the first two bytes of the lpstrFile buffer contain the | ||
| 257 | required size, in bytes or characters. */ | ||
| 258 | if (!b) | ||
| 259 | return false; | ||
| 260 | { | ||
| 261 | tempPath.ReleaseBuf_CalcLen(bufSize); | ||
| 262 | FilePath = tempPath; | ||
| 263 | FilterIndex = (int)p.nFilterIndex - 1; | ||
| 264 | return true; | ||
| 265 | } | ||
| 205 | } | 266 | } |
| 206 | } | 267 | } |
| 207 | 268 | ||
diff --git a/CPP/Windows/CommonDialog.h b/CPP/Windows/CommonDialog.h index aaf17ac..85b071f 100644 --- a/CPP/Windows/CommonDialog.h +++ b/CPP/Windows/CommonDialog.h | |||
| @@ -1,22 +1,42 @@ | |||
| 1 | // Windows/CommonDialog.h | 1 | // Windows/CommonDialog.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_COMMON_DIALOG_H | 3 | #ifndef ZIP7_INC_WINDOWS_COMMON_DIALOG_H |
| 4 | #define __WINDOWS_COMMON_DIALOG_H | 4 | #define ZIP7_INC_WINDOWS_COMMON_DIALOG_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| 8 | namespace NWindows { | 8 | namespace NWindows { |
| 9 | 9 | ||
| 10 | bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, | 10 | struct CCommonDialogInfo |
| 11 | LPCWSTR initialDir, // can be NULL, so dir prefix in filePath will be used | 11 | { |
| 12 | LPCWSTR filePath, // full path | 12 | /* (FilterIndex == -1) means no selected filter. |
| 13 | LPCWSTR filterDescription, // like "All files (*.*)" | 13 | and (-1) also is reserved for unsupported custom filter. |
| 14 | LPCWSTR filter, // like "*.exe" | 14 | if (FilterIndex >= 0), then FilterIndex is index of filter */ |
| 15 | UString &resPath | 15 | int FilterIndex; // [in / out] |
| 16 | #ifdef UNDER_CE | 16 | bool SaveMode; |
| 17 | , bool openFolder = false | 17 | #ifdef UNDER_CE |
| 18 | #endif | 18 | bool OpenFolderMode; |
| 19 | ); | 19 | #endif |
| 20 | HWND hwndOwner; | ||
| 21 | // LPCWSTR lpstrInitialDir; | ||
| 22 | LPCWSTR lpstrTitle; | ||
| 23 | UString FilePath; // [in / out] | ||
| 24 | |||
| 25 | CCommonDialogInfo() | ||
| 26 | { | ||
| 27 | FilterIndex = -1; | ||
| 28 | SaveMode = false; | ||
| 29 | #ifdef UNDER_CE | ||
| 30 | OpenFolderMode = false; | ||
| 31 | #endif | ||
| 32 | hwndOwner = NULL; | ||
| 33 | // lpstrInitialDir = NULL; | ||
| 34 | lpstrTitle = NULL; | ||
| 35 | } | ||
| 36 | |||
| 37 | /* (filters) : 2 sequential vector strings (Description, Masks) represent each filter */ | ||
| 38 | bool CommonDlg_BrowseForFile(LPCWSTR lpstrInitialDir, const UStringVector &filters); | ||
| 39 | }; | ||
| 20 | 40 | ||
| 21 | } | 41 | } |
| 22 | 42 | ||
diff --git a/CPP/Windows/Console.h b/CPP/Windows/Console.h index 43e02fa..818b8d4 100644 --- a/CPP/Windows/Console.h +++ b/CPP/Windows/Console.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Console.h | 1 | // Windows/Console.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONSOLE_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONSOLE_H |
| 4 | #define __WINDOWS_CONSOLE_H | 4 | #define ZIP7_INC_WINDOWS_CONSOLE_H |
| 5 | 5 | ||
| 6 | #include "Defs.h" | 6 | #include "Defs.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Control/ComboBox.cpp b/CPP/Windows/Control/ComboBox.cpp index f6ed8d3..8da487d 100644 --- a/CPP/Windows/Control/ComboBox.cpp +++ b/CPP/Windows/Control/ComboBox.cpp | |||
| @@ -43,10 +43,10 @@ LRESULT CComboBox::GetLBText(int index, UString &s) | |||
| 43 | s.Empty(); | 43 | s.Empty(); |
| 44 | if (g_IsNT) | 44 | if (g_IsNT) |
| 45 | { | 45 | { |
| 46 | LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY__int_TO_WPARAM(index), 0); | 46 | LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); |
| 47 | if (len == CB_ERR) | 47 | if (len == CB_ERR) |
| 48 | return len; | 48 | return len; |
| 49 | LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY__int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len)); | 49 | LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len)); |
| 50 | if (len2 == CB_ERR) | 50 | if (len2 == CB_ERR) |
| 51 | return len; | 51 | return len; |
| 52 | if (len > len2) | 52 | if (len > len2) |
| @@ -55,11 +55,11 @@ LRESULT CComboBox::GetLBText(int index, UString &s) | |||
| 55 | return len; | 55 | return len; |
| 56 | } | 56 | } |
| 57 | AString sa; | 57 | AString sa; |
| 58 | LRESULT len = GetLBText(index, sa); | 58 | const LRESULT len = GetLBText(index, sa); |
| 59 | if (len == CB_ERR) | 59 | if (len == CB_ERR) |
| 60 | return len; | 60 | return len; |
| 61 | s = GetUnicodeString(sa); | 61 | s = GetUnicodeString(sa); |
| 62 | return s.Len(); | 62 | return (LRESULT)s.Len(); |
| 63 | } | 63 | } |
| 64 | #endif | 64 | #endif |
| 65 | 65 | ||
diff --git a/CPP/Windows/Control/ComboBox.h b/CPP/Windows/Control/ComboBox.h index f08b1f7..2a60b8a 100644 --- a/CPP/Windows/Control/ComboBox.h +++ b/CPP/Windows/Control/ComboBox.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ComboBox.h | 1 | // Windows/Control/ComboBox.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_COMBOBOX_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H |
| 4 | #define __WINDOWS_CONTROL_COMBOBOX_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H |
| 5 | 5 | ||
| 6 | #include "../../Common/MyWindows.h" | 6 | #include "../../Common/MyWindows.h" |
| 7 | 7 | ||
| @@ -12,8 +12,6 @@ | |||
| 12 | namespace NWindows { | 12 | namespace NWindows { |
| 13 | namespace NControl { | 13 | namespace NControl { |
| 14 | 14 | ||
| 15 | #define MY__int_TO_WPARAM(i) ((WPARAM)(INT_PTR)(i)) | ||
| 16 | |||
| 17 | class CComboBox: public CWindow | 15 | class CComboBox: public CWindow |
| 18 | { | 16 | { |
| 19 | public: | 17 | public: |
| @@ -24,7 +22,8 @@ public: | |||
| 24 | #endif | 22 | #endif |
| 25 | 23 | ||
| 26 | /* If this parameter is -1, any current selection in the list is removed and the edit control is cleared.*/ | 24 | /* If this parameter is -1, any current selection in the list is removed and the edit control is cleared.*/ |
| 27 | LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY__int_TO_WPARAM(index), 0); } | 25 | LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY_int_TO_WPARAM(index), 0); } |
| 26 | LRESULT SetCurSel(unsigned index) { return SendMsg(CB_SETCURSEL, index, 0); } | ||
| 28 | 27 | ||
| 29 | /* If no item is selected, it returns CB_ERR (-1) */ | 28 | /* If no item is selected, it returns CB_ERR (-1) */ |
| 30 | int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); } | 29 | int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); } |
| @@ -32,15 +31,16 @@ public: | |||
| 32 | /* If an error occurs, it is CB_ERR (-1) */ | 31 | /* If an error occurs, it is CB_ERR (-1) */ |
| 33 | int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); } | 32 | int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); } |
| 34 | 33 | ||
| 35 | LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY__int_TO_WPARAM(index), 0); } | 34 | LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); } |
| 36 | LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, MY__int_TO_WPARAM(index), (LPARAM)s); } | 35 | LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s); } |
| 37 | LRESULT GetLBText(int index, CSysString &s); | 36 | LRESULT GetLBText(int index, CSysString &s); |
| 38 | #ifndef _UNICODE | 37 | #ifndef _UNICODE |
| 39 | LRESULT GetLBText(int index, UString &s); | 38 | LRESULT GetLBText(int index, UString &s); |
| 40 | #endif | 39 | #endif |
| 41 | 40 | ||
| 42 | LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY__int_TO_WPARAM(index), lParam); } | 41 | LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY_int_TO_WPARAM(index), lParam); } |
| 43 | LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY__int_TO_WPARAM(index), 0); } | 42 | LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY_int_TO_WPARAM(index), 0); } |
| 43 | LRESULT GetItemData(unsigned index) { return SendMsg(CB_GETITEMDATA, index, 0); } | ||
| 44 | 44 | ||
| 45 | LRESULT GetItemData_of_CurSel() { return GetItemData(GetCurSel()); } | 45 | LRESULT GetItemData_of_CurSel() { return GetItemData(GetCurSel()); } |
| 46 | 46 | ||
| @@ -57,7 +57,7 @@ public: | |||
| 57 | /* Returns: | 57 | /* Returns: |
| 58 | an INT value that represents the number of items remaining in the control. | 58 | an INT value that represents the number of items remaining in the control. |
| 59 | If (index) is invalid, the message returns CB_ERR. */ | 59 | If (index) is invalid, the message returns CB_ERR. */ |
| 60 | LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY__int_TO_WPARAM(index), 0); } | 60 | LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY_int_TO_WPARAM(index), 0); } |
| 61 | 61 | ||
| 62 | LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); } | 62 | LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); } |
| 63 | #ifndef _UNICODE | 63 | #ifndef _UNICODE |
| @@ -65,7 +65,7 @@ public: | |||
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); } | 67 | LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); } |
| 68 | DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, exStyle); } | 68 | DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, (LPARAM)exStyle); } |
| 69 | HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); } | 69 | HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); } |
| 70 | HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); } | 70 | HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); } |
| 71 | }; | 71 | }; |
diff --git a/CPP/Windows/Control/CommandBar.h b/CPP/Windows/Control/CommandBar.h index a619744..d1b2f17 100644 --- a/CPP/Windows/Control/CommandBar.h +++ b/CPP/Windows/Control/CommandBar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/CommandBar.h | 1 | // Windows/Control/CommandBar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_COMMANDBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_COMMANDBAR_H |
| 4 | #define __WINDOWS_CONTROL_COMMANDBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_COMMANDBAR_H |
| 5 | 5 | ||
| 6 | #ifdef UNDER_CE | 6 | #ifdef UNDER_CE |
| 7 | 7 | ||
| @@ -26,12 +26,12 @@ public: | |||
| 26 | // Macros | 26 | // Macros |
| 27 | // void Destroy() { CommandBar_Destroy(_window); } | 27 | // void Destroy() { CommandBar_Destroy(_window); } |
| 28 | // bool AddButtons(UINT numButtons, LPTBBUTTON buttons) { return BOOLToBool(SendMsg(TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)buttons)); } | 28 | // bool AddButtons(UINT numButtons, LPTBBUTTON buttons) { return BOOLToBool(SendMsg(TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)buttons)); } |
| 29 | bool InsertButton(int iButton, LPTBBUTTON button) { return BOOLToBool(SendMsg(TB_INSERTBUTTON, (WPARAM)iButton, (LPARAM)button)); } | 29 | // bool InsertButton(unsigned iButton, LPTBBUTTON button) { return BOOLToBool(SendMsg(TB_INSERTBUTTON, (WPARAM)iButton, (LPARAM)button)); } |
| 30 | BOOL AddToolTips(UINT numToolTips, LPTSTR toolTips) { return BOOLToBool(SendMsg(TB_SETTOOLTIPS, (WPARAM)numToolTips, (LPARAM)toolTips)); } | 30 | // BOOL AddToolTips(UINT numToolTips, LPTSTR toolTips) { return BOOLToBool(SendMsg(TB_SETTOOLTIPS, (WPARAM)numToolTips, (LPARAM)toolTips)); } |
| 31 | void AutoSize() { SendMsg(TB_AUTOSIZE, 0, 0); } | 31 | void AutoSize() { SendMsg(TB_AUTOSIZE, 0, 0); } |
| 32 | 32 | ||
| 33 | bool AddAdornments(DWORD dwFlags) { return BOOLToBool(::CommandBar_AddAdornments(_window, dwFlags, 0)); } | 33 | // bool AddAdornments(DWORD dwFlags) { return BOOLToBool(::CommandBar_AddAdornments(_window, dwFlags, 0)); } |
| 34 | int AddBitmap(HINSTANCE hInst, int idBitmap, int iNumImages, int iImageWidth, int iImageHeight) { return ::CommandBar_AddBitmap(_window, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight); } | 34 | // int AddBitmap(HINSTANCE hInst, int idBitmap, int iNumImages, int iImageWidth, int iImageHeight) { return ::CommandBar_AddBitmap(_window, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight); } |
| 35 | bool DrawMenuBar(WORD iButton) { return BOOLToBool(::CommandBar_DrawMenuBar(_window, iButton)); } | 35 | bool DrawMenuBar(WORD iButton) { return BOOLToBool(::CommandBar_DrawMenuBar(_window, iButton)); } |
| 36 | HMENU GetMenu(WORD iButton) { return ::CommandBar_GetMenu(_window, iButton); } | 36 | HMENU GetMenu(WORD iButton) { return ::CommandBar_GetMenu(_window, iButton); } |
| 37 | int Height() { return CommandBar_Height(_window); } | 37 | int Height() { return CommandBar_Height(_window); } |
diff --git a/CPP/Windows/Control/Dialog.cpp b/CPP/Windows/Control/Dialog.cpp index 9ddd234..c8f1bd2 100644 --- a/CPP/Windows/Control/Dialog.cpp +++ b/CPP/Windows/Control/Dialog.cpp | |||
| @@ -18,7 +18,14 @@ extern bool g_IsNT; | |||
| 18 | namespace NWindows { | 18 | namespace NWindows { |
| 19 | namespace NControl { | 19 | namespace NControl { |
| 20 | 20 | ||
| 21 | static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | 21 | static |
| 22 | #ifdef Z7_OLD_WIN_SDK | ||
| 23 | BOOL | ||
| 24 | #else | ||
| 25 | INT_PTR | ||
| 26 | #endif | ||
| 27 | APIENTRY | ||
| 28 | DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 22 | { | 29 | { |
| 23 | CWindow tempDialog(dialogHWND); | 30 | CWindow tempDialog(dialogHWND); |
| 24 | if (message == WM_INITDIALOG) | 31 | if (message == WM_INITDIALOG) |
| @@ -45,7 +52,7 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 45 | switch (message) | 52 | switch (message) |
| 46 | { | 53 | { |
| 47 | case WM_INITDIALOG: return OnInit(); | 54 | case WM_INITDIALOG: return OnInit(); |
| 48 | case WM_COMMAND: return OnCommand(wParam, lParam); | 55 | case WM_COMMAND: return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); |
| 49 | case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam); | 56 | case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam); |
| 50 | case WM_TIMER: return OnTimer(wParam, lParam); | 57 | case WM_TIMER: return OnTimer(wParam, lParam); |
| 51 | case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); | 58 | case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); |
| @@ -65,19 +72,21 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 65 | } | 72 | } |
| 66 | } | 73 | } |
| 67 | 74 | ||
| 68 | bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) | 75 | /* |
| 76 | bool CDialog::OnCommand2(WPARAM wParam, LPARAM lParam) | ||
| 69 | { | 77 | { |
| 70 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); | 78 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); |
| 71 | } | 79 | } |
| 80 | */ | ||
| 72 | 81 | ||
| 73 | bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) | 82 | bool CDialog::OnCommand(unsigned code, unsigned itemID, LPARAM lParam) |
| 74 | { | 83 | { |
| 75 | if (code == BN_CLICKED) | 84 | if (code == BN_CLICKED) |
| 76 | return OnButtonClicked(itemID, (HWND)lParam); | 85 | return OnButtonClicked(itemID, (HWND)lParam); |
| 77 | return false; | 86 | return false; |
| 78 | } | 87 | } |
| 79 | 88 | ||
| 80 | bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */) | 89 | bool CDialog::OnButtonClicked(unsigned buttonID, HWND /* buttonHWND */) |
| 81 | { | 90 | { |
| 82 | switch (buttonID) | 91 | switch (buttonID) |
| 83 | { | 92 | { |
| @@ -90,6 +99,28 @@ bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */) | |||
| 90 | return true; | 99 | return true; |
| 91 | } | 100 | } |
| 92 | 101 | ||
| 102 | #ifndef UNDER_CE | ||
| 103 | /* in win2000/win98 : monitor functions are supported. | ||
| 104 | We need dynamic linking, if we want nt4/win95 support in program. | ||
| 105 | Even if we compile the code with low (WINVER) value, we still | ||
| 106 | want to use monitor functions. So we declare missing functions here */ | ||
| 107 | // #if (WINVER < 0x0500) | ||
| 108 | #ifndef MONITOR_DEFAULTTOPRIMARY | ||
| 109 | extern "C" { | ||
| 110 | DECLARE_HANDLE(HMONITOR); | ||
| 111 | #define MONITOR_DEFAULTTOPRIMARY 0x00000001 | ||
| 112 | typedef struct tagMONITORINFO | ||
| 113 | { | ||
| 114 | DWORD cbSize; | ||
| 115 | RECT rcMonitor; | ||
| 116 | RECT rcWork; | ||
| 117 | DWORD dwFlags; | ||
| 118 | } MONITORINFO, *LPMONITORINFO; | ||
| 119 | WINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND hwnd, DWORD dwFlags); | ||
| 120 | WINUSERAPI BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpmi); | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | #endif | ||
| 93 | 124 | ||
| 94 | static bool GetWorkAreaRect(RECT *rect, HWND hwnd) | 125 | static bool GetWorkAreaRect(RECT *rect, HWND hwnd) |
| 95 | { | 126 | { |
| @@ -172,7 +203,7 @@ int CDialog::Units_To_Pixels_X(int units) | |||
| 172 | return rect.right - rect.left; | 203 | return rect.right - rect.left; |
| 173 | } | 204 | } |
| 174 | 205 | ||
| 175 | bool CDialog::GetItemSizes(int id, int &x, int &y) | 206 | bool CDialog::GetItemSizes(unsigned id, int &x, int &y) |
| 176 | { | 207 | { |
| 177 | RECT rect; | 208 | RECT rect; |
| 178 | if (!::GetWindowRect(GetItem(id), &rect)) | 209 | if (!::GetWindowRect(GetItem(id), &rect)) |
| @@ -182,13 +213,13 @@ bool CDialog::GetItemSizes(int id, int &x, int &y) | |||
| 182 | return true; | 213 | return true; |
| 183 | } | 214 | } |
| 184 | 215 | ||
| 185 | void CDialog::GetClientRectOfItem(int id, RECT &rect) | 216 | void CDialog::GetClientRectOfItem(unsigned id, RECT &rect) |
| 186 | { | 217 | { |
| 187 | ::GetWindowRect(GetItem(id), &rect); | 218 | ::GetWindowRect(GetItem(id), &rect); |
| 188 | ScreenToClient(&rect); | 219 | ScreenToClient(&rect); |
| 189 | } | 220 | } |
| 190 | 221 | ||
| 191 | bool CDialog::MoveItem(int id, int x, int y, int width, int height, bool repaint) | 222 | bool CDialog::MoveItem(unsigned id, int x, int y, int width, int height, bool repaint) |
| 192 | { | 223 | { |
| 193 | return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint))); | 224 | return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint))); |
| 194 | } | 225 | } |
| @@ -356,8 +387,8 @@ void CDialog::NormalizePosition() | |||
| 356 | 387 | ||
| 357 | bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) | 388 | bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) |
| 358 | { | 389 | { |
| 359 | HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); | 390 | const HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); |
| 360 | if (aHWND == 0) | 391 | if (!aHWND) |
| 361 | return false; | 392 | return false; |
| 362 | Attach(aHWND); | 393 | Attach(aHWND); |
| 363 | return true; | 394 | return true; |
diff --git a/CPP/Windows/Control/Dialog.h b/CPP/Windows/Control/Dialog.h index 8a39e99..06be4bf 100644 --- a/CPP/Windows/Control/Dialog.h +++ b/CPP/Windows/Control/Dialog.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/Dialog.h | 1 | // Windows/Control/Dialog.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_DIALOG_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_DIALOG_H |
| 4 | #define __WINDOWS_CONTROL_DIALOG_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_DIALOG_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
| @@ -10,65 +10,66 @@ namespace NControl { | |||
| 10 | 10 | ||
| 11 | class CDialog: public CWindow | 11 | class CDialog: public CWindow |
| 12 | { | 12 | { |
| 13 | // Z7_CLASS_NO_COPY(CDialog) | ||
| 13 | public: | 14 | public: |
| 14 | CDialog(HWND wnd = NULL): CWindow(wnd){}; | 15 | CDialog(HWND wnd = NULL): CWindow(wnd) {} |
| 15 | virtual ~CDialog() {}; | 16 | virtual ~CDialog() {} |
| 16 | 17 | ||
| 17 | HWND GetItem(int itemID) const | 18 | HWND GetItem(unsigned itemID) const |
| 18 | { return GetDlgItem(_window, itemID); } | 19 | { return GetDlgItem(_window, (int)itemID); } |
| 19 | 20 | ||
| 20 | bool EnableItem(int itemID, bool enable) const | 21 | bool EnableItem(unsigned itemID, bool enable) const |
| 21 | { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); } | 22 | { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); } |
| 22 | 23 | ||
| 23 | bool ShowItem(int itemID, int cmdShow) const | 24 | bool ShowItem(unsigned itemID, int cmdShow) const |
| 24 | { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); } | 25 | { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); } |
| 25 | 26 | ||
| 26 | bool ShowItem_Bool(int itemID, bool show) const | 27 | bool ShowItem_Bool(unsigned itemID, bool show) const |
| 27 | { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); } | 28 | { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); } |
| 28 | 29 | ||
| 29 | bool HideItem(int itemID) const { return ShowItem(itemID, SW_HIDE); } | 30 | bool HideItem(unsigned itemID) const { return ShowItem(itemID, SW_HIDE); } |
| 30 | 31 | ||
| 31 | bool SetItemText(int itemID, LPCTSTR s) | 32 | bool SetItemText(unsigned itemID, LPCTSTR s) |
| 32 | { return BOOLToBool(SetDlgItemText(_window, itemID, s)); } | 33 | { return BOOLToBool(SetDlgItemText(_window, (int)itemID, s)); } |
| 33 | 34 | ||
| 34 | bool SetItemTextA(int itemID, LPCSTR s) | 35 | bool SetItemTextA(unsigned itemID, LPCSTR s) |
| 35 | { return BOOLToBool(SetDlgItemTextA(_window, itemID, s)); } | 36 | { return BOOLToBool(SetDlgItemTextA(_window, (int)itemID, s)); } |
| 36 | 37 | ||
| 37 | bool SetItemText_Empty(int itemID) | 38 | bool SetItemText_Empty(unsigned itemID) |
| 38 | { return SetItemText(itemID, TEXT("")); } | 39 | { return SetItemText(itemID, TEXT("")); } |
| 39 | 40 | ||
| 40 | #ifndef _UNICODE | 41 | #ifndef _UNICODE |
| 41 | bool SetItemText(int itemID, LPCWSTR s) | 42 | bool SetItemText(unsigned itemID, LPCWSTR s) |
| 42 | { | 43 | { |
| 43 | CWindow window(GetItem(itemID)); | 44 | CWindow window(GetItem(itemID)); |
| 44 | return window.SetText(s); | 45 | return window.SetText(s); |
| 45 | } | 46 | } |
| 46 | #endif | 47 | #endif |
| 47 | 48 | ||
| 48 | UINT GetItemText(int itemID, LPTSTR string, int maxCount) | 49 | UINT GetItemText(unsigned itemID, LPTSTR string, unsigned maxCount) |
| 49 | { return GetDlgItemText(_window, itemID, string, maxCount); } | 50 | { return GetDlgItemText(_window, (int)itemID, string, (int)maxCount); } |
| 50 | #ifndef _UNICODE | 51 | #ifndef _UNICODE |
| 51 | /* | 52 | /* |
| 52 | bool GetItemText(int itemID, LPWSTR string, int maxCount) | 53 | bool GetItemText(unsigned itemID, LPWSTR string, int maxCount) |
| 53 | { | 54 | { |
| 54 | CWindow window(GetItem(itemID)); | 55 | CWindow window(GetItem(unsigned)); |
| 55 | return window.GetText(string, maxCount); | 56 | return window.GetText(string, maxCount); |
| 56 | } | 57 | } |
| 57 | */ | 58 | */ |
| 58 | #endif | 59 | #endif |
| 59 | 60 | ||
| 60 | bool GetItemText(int itemID, UString &s) | 61 | bool GetItemText(unsigned itemID, UString &s) |
| 61 | { | 62 | { |
| 62 | CWindow window(GetItem(itemID)); | 63 | CWindow window(GetItem(itemID)); |
| 63 | return window.GetText(s); | 64 | return window.GetText(s); |
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | bool SetItemInt(int itemID, UINT value, bool isSigned) | 67 | bool SetItemInt(unsigned itemID, UINT value, bool isSigned) |
| 67 | { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); } | 68 | { return BOOLToBool(SetDlgItemInt(_window, (int)itemID, value, BoolToBOOL(isSigned))); } |
| 68 | bool GetItemInt(int itemID, bool isSigned, UINT &value) | 69 | bool GetItemInt(unsigned itemID, bool isSigned, UINT &value) |
| 69 | { | 70 | { |
| 70 | BOOL result; | 71 | BOOL result; |
| 71 | value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned)); | 72 | value = GetDlgItemInt(_window, (int)itemID, &result, BoolToBOOL(isSigned)); |
| 72 | return BOOLToBool(result); | 73 | return BOOLToBool(result); |
| 73 | } | 74 | } |
| 74 | 75 | ||
| @@ -80,7 +81,7 @@ public: | |||
| 80 | LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam) | 81 | LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam) |
| 81 | { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); } | 82 | { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); } |
| 82 | LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); } | 83 | LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); } |
| 83 | LRESULT SendMsg_NextDlgCtl_CtlId(int id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); } | 84 | LRESULT SendMsg_NextDlgCtl_CtlId(unsigned id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); } |
| 84 | LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); } | 85 | LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); } |
| 85 | LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); } | 86 | LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); } |
| 86 | 87 | ||
| @@ -90,26 +91,27 @@ public: | |||
| 90 | bool IsMessage(LPMSG message) | 91 | bool IsMessage(LPMSG message) |
| 91 | { return BOOLToBool(IsDialogMessage(_window, message)); } | 92 | { return BOOLToBool(IsDialogMessage(_window, message)); } |
| 92 | 93 | ||
| 93 | LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam) | 94 | LRESULT SendItemMessage(unsigned itemID, UINT message, WPARAM wParam, LPARAM lParam) |
| 94 | { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); } | 95 | { return SendDlgItemMessage(_window, (int)itemID, message, wParam, lParam); } |
| 95 | 96 | ||
| 96 | bool CheckButton(int buttonID, UINT checkState) | 97 | bool CheckButton(unsigned buttonID, UINT checkState) |
| 97 | { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); } | 98 | { return BOOLToBool(CheckDlgButton(_window, (int)buttonID, checkState)); } |
| 98 | bool CheckButton(int buttonID, bool checkState) | 99 | bool CheckButton(unsigned buttonID, bool checkState) |
| 99 | { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); } | 100 | { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); } |
| 100 | 101 | ||
| 101 | UINT IsButtonChecked(int buttonID) const | 102 | UINT IsButtonChecked_BST(unsigned buttonID) const |
| 102 | { return IsDlgButtonChecked(_window, buttonID); } | 103 | { return IsDlgButtonChecked(_window, (int)buttonID); } |
| 103 | bool IsButtonCheckedBool(int buttonID) const | 104 | bool IsButtonCheckedBool(unsigned buttonID) const |
| 104 | { return (IsButtonChecked(buttonID) == BST_CHECKED); } | 105 | { return (IsButtonChecked_BST(buttonID) == BST_CHECKED); } |
| 105 | 106 | ||
| 106 | bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID) | 107 | bool CheckRadioButton(unsigned firstButtonID, unsigned lastButtonID, unsigned checkButtonID) |
| 107 | { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); } | 108 | { return BOOLToBool(::CheckRadioButton(_window, |
| 109 | (int)firstButtonID, (int)lastButtonID, (int)checkButtonID)); } | ||
| 108 | 110 | ||
| 109 | virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | 111 | virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam); |
| 110 | virtual bool OnInit() { return true; } | 112 | virtual bool OnInit() { return true; } |
| 111 | virtual bool OnCommand(WPARAM wParam, LPARAM lParam); | 113 | // virtual bool OnCommand2(WPARAM wParam, LPARAM lParam); |
| 112 | virtual bool OnCommand(int code, int itemID, LPARAM lParam); | 114 | virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam); |
| 113 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } | 115 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } |
| 114 | virtual bool OnDestroy() { return false; } | 116 | virtual bool OnDestroy() { return false; } |
| 115 | 117 | ||
| @@ -120,11 +122,11 @@ public: | |||
| 120 | virtual void OnHelp(LPHELPINFO) { OnHelp(); } | 122 | virtual void OnHelp(LPHELPINFO) { OnHelp(); } |
| 121 | #endif | 123 | #endif |
| 122 | */ | 124 | */ |
| 123 | virtual void OnHelp() {}; | 125 | virtual void OnHelp() {} |
| 124 | 126 | ||
| 125 | virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); | 127 | virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND); |
| 126 | virtual void OnOK() {}; | 128 | virtual void OnOK() {} |
| 127 | virtual void OnCancel() {}; | 129 | virtual void OnCancel() {} |
| 128 | virtual void OnClose() {} | 130 | virtual void OnClose() {} |
| 129 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } | 131 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } |
| 130 | virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } | 132 | virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } |
| @@ -136,9 +138,11 @@ public: | |||
| 136 | 138 | ||
| 137 | bool GetMargins(int margin, int &x, int &y); | 139 | bool GetMargins(int margin, int &x, int &y); |
| 138 | int Units_To_Pixels_X(int units); | 140 | int Units_To_Pixels_X(int units); |
| 139 | bool GetItemSizes(int id, int &x, int &y); | 141 | bool GetItemSizes(unsigned id, int &x, int &y); |
| 140 | void GetClientRectOfItem(int id, RECT &rect); | 142 | void GetClientRectOfItem(unsigned id, RECT &rect); |
| 141 | bool MoveItem(int id, int x, int y, int width, int height, bool repaint = true); | 143 | bool MoveItem(unsigned id, int x, int y, int width, int height, bool repaint = true); |
| 144 | bool MoveItem_RECT(unsigned id, const RECT &r, bool repaint = true) | ||
| 145 | { return MoveItem(id, r.left, r.top, RECT_SIZE_X(r), RECT_SIZE_Y(r), repaint); } | ||
| 142 | 146 | ||
| 143 | void NormalizeSize(bool fullNormalize = false); | 147 | void NormalizeSize(bool fullNormalize = false); |
| 144 | void NormalizePosition(); | 148 | void NormalizePosition(); |
| @@ -152,9 +156,9 @@ public: | |||
| 152 | #ifndef _UNICODE | 156 | #ifndef _UNICODE |
| 153 | bool Create(LPCWSTR templateName, HWND parentWindow); | 157 | bool Create(LPCWSTR templateName, HWND parentWindow); |
| 154 | #endif | 158 | #endif |
| 155 | virtual void OnOK() { Destroy(); } | 159 | virtual void OnOK() Z7_override { Destroy(); } |
| 156 | virtual void OnCancel() { Destroy(); } | 160 | virtual void OnCancel() Z7_override { Destroy(); } |
| 157 | virtual void OnClose() { Destroy(); } | 161 | virtual void OnClose() Z7_override { Destroy(); } |
| 158 | }; | 162 | }; |
| 159 | 163 | ||
| 160 | class CModalDialog: public CDialog | 164 | class CModalDialog: public CDialog |
| @@ -167,18 +171,18 @@ public: | |||
| 167 | #endif | 171 | #endif |
| 168 | 172 | ||
| 169 | bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); } | 173 | bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); } |
| 170 | virtual void OnOK() { End(IDOK); } | 174 | virtual void OnOK() Z7_override { End(IDOK); } |
| 171 | virtual void OnCancel() { End(IDCANCEL); } | 175 | virtual void OnCancel() Z7_override { End(IDCANCEL); } |
| 172 | virtual void OnClose() { End(IDCLOSE); } | 176 | virtual void OnClose() Z7_override { End(IDCLOSE); } |
| 173 | }; | 177 | }; |
| 174 | 178 | ||
| 175 | class CDialogChildControl: public NWindows::CWindow | 179 | class CDialogChildControl: public NWindows::CWindow |
| 176 | { | 180 | { |
| 177 | int m_ID; | 181 | // unsigned m_ID; |
| 178 | public: | 182 | public: |
| 179 | void Init(const NWindows::NControl::CDialog &parentDialog, int id) | 183 | void Init(const NWindows::NControl::CDialog &parentDialog, unsigned id) |
| 180 | { | 184 | { |
| 181 | m_ID = id; | 185 | // m_ID = id; |
| 182 | Attach(parentDialog.GetItem(id)); | 186 | Attach(parentDialog.GetItem(id)); |
| 183 | } | 187 | } |
| 184 | }; | 188 | }; |
diff --git a/CPP/Windows/Control/Edit.h b/CPP/Windows/Control/Edit.h index 51a22c5..963470d 100644 --- a/CPP/Windows/Control/Edit.h +++ b/CPP/Windows/Control/Edit.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/Edit.h | 1 | // Windows/Control/Edit.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_EDIT_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_EDIT_H |
| 4 | #define __WINDOWS_CONTROL_EDIT_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_EDIT_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Control/ImageList.h b/CPP/Windows/Control/ImageList.h index 19feb11..688f177 100644 --- a/CPP/Windows/Control/ImageList.h +++ b/CPP/Windows/Control/ImageList.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ImageList.h | 1 | // Windows/Control/ImageList.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_IMAGE_LIST_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_IMAGE_LIST_H |
| 4 | #define __WINDOWS_CONTROL_IMAGE_LIST_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_IMAGE_LIST_H |
| 5 | 5 | ||
| 6 | #include <CommCtrl.h> | 6 | #include <CommCtrl.h> |
| 7 | 7 | ||
| @@ -56,7 +56,7 @@ public: | |||
| 56 | bool GetImageInfo(int index, IMAGEINFO* imageInfo) const | 56 | bool GetImageInfo(int index, IMAGEINFO* imageInfo) const |
| 57 | { return BOOLToBool(ImageList_GetImageInfo(m_Object, index, imageInfo)); } | 57 | { return BOOLToBool(ImageList_GetImageInfo(m_Object, index, imageInfo)); } |
| 58 | 58 | ||
| 59 | int Add(HBITMAP hbmImage, HBITMAP hbmMask = 0) | 59 | int Add(HBITMAP hbmImage, HBITMAP hbmMask = NULL) |
| 60 | { return ImageList_Add(m_Object, hbmImage, hbmMask); } | 60 | { return ImageList_Add(m_Object, hbmImage, hbmMask); } |
| 61 | int AddMasked(HBITMAP hbmImage, COLORREF mask) | 61 | int AddMasked(HBITMAP hbmImage, COLORREF mask) |
| 62 | { return ImageList_AddMasked(m_Object, hbmImage, mask); } | 62 | { return ImageList_AddMasked(m_Object, hbmImage, mask); } |
diff --git a/CPP/Windows/Control/ListView.cpp b/CPP/Windows/Control/ListView.cpp index 16cfd39..3e8786a 100644 --- a/CPP/Windows/Control/ListView.cpp +++ b/CPP/Windows/Control/ListView.cpp | |||
| @@ -20,78 +20,85 @@ bool CListView::CreateEx(DWORD exStyle, DWORD style, | |||
| 20 | height, parentWindow, idOrHMenu, instance, createParam); | 20 | height, parentWindow, idOrHMenu, instance, createParam); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | bool CListView::GetItemParam(int index, LPARAM ¶m) const | 23 | /* note: LVITEM and LVCOLUMN structures contain optional fields |
| 24 | depending from preprocessor macros: | ||
| 25 | #if (_WIN32_IE >= 0x0300) | ||
| 26 | #if (_WIN32_WINNT >= 0x0501) | ||
| 27 | #if (_WIN32_WINNT >= 0x0600) | ||
| 28 | */ | ||
| 29 | |||
| 30 | bool CListView::GetItemParam(unsigned index, LPARAM ¶m) const | ||
| 24 | { | 31 | { |
| 25 | LVITEM item; | 32 | LVITEM item; |
| 26 | item.iItem = index; | 33 | item.iItem = (int)index; |
| 27 | item.iSubItem = 0; | 34 | item.iSubItem = 0; |
| 28 | item.mask = LVIF_PARAM; | 35 | item.mask = LVIF_PARAM; |
| 29 | bool aResult = GetItem(&item); | 36 | const bool res = GetItem(&item); |
| 30 | param = item.lParam; | 37 | param = item.lParam; |
| 31 | return aResult; | 38 | return res; |
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | int CListView::InsertColumn(int columnIndex, LPCTSTR text, int width) | 41 | int CListView::InsertColumn(unsigned columnIndex, LPCTSTR text, int width) |
| 35 | { | 42 | { |
| 36 | LVCOLUMN ci; | 43 | LVCOLUMN ci; |
| 37 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | 44 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
| 38 | ci.pszText = (LPTSTR)(void *)text; | 45 | ci.pszText = (LPTSTR)(void *)text; |
| 39 | ci.iSubItem = columnIndex; | 46 | ci.iSubItem = (int)columnIndex; |
| 40 | ci.cx = width; | 47 | ci.cx = width; |
| 41 | return InsertColumn(columnIndex, &ci); | 48 | return InsertColumn(columnIndex, &ci); |
| 42 | } | 49 | } |
| 43 | 50 | ||
| 44 | int CListView::InsertItem(int index, LPCTSTR text) | 51 | int CListView::InsertItem(unsigned index, LPCTSTR text) |
| 45 | { | 52 | { |
| 46 | LVITEM item; | 53 | LVITEM item; |
| 47 | item.mask = LVIF_TEXT | LVIF_PARAM; | 54 | item.mask = LVIF_TEXT | LVIF_PARAM; |
| 48 | item.iItem = index; | 55 | item.iItem = (int)index; |
| 49 | item.lParam = index; | 56 | item.lParam = (LPARAM)index; |
| 50 | item.pszText = (LPTSTR)(void *)text; | 57 | item.pszText = (LPTSTR)(void *)text; |
| 51 | item.iSubItem = 0; | 58 | item.iSubItem = 0; |
| 52 | return InsertItem(&item); | 59 | return InsertItem(&item); |
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | int CListView::SetSubItem(int index, int subIndex, LPCTSTR text) | 62 | int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCTSTR text) |
| 56 | { | 63 | { |
| 57 | LVITEM item; | 64 | LVITEM item; |
| 58 | item.mask = LVIF_TEXT; | 65 | item.mask = LVIF_TEXT; |
| 59 | item.iItem = index; | 66 | item.iItem = (int)index; |
| 60 | item.pszText = (LPTSTR)(void *)text; | 67 | item.pszText = (LPTSTR)(void *)text; |
| 61 | item.iSubItem = subIndex; | 68 | item.iSubItem = (int)subIndex; |
| 62 | return SetItem(&item); | 69 | return SetItem(&item); |
| 63 | } | 70 | } |
| 64 | 71 | ||
| 65 | #ifndef _UNICODE | 72 | #ifndef _UNICODE |
| 66 | 73 | ||
| 67 | int CListView::InsertColumn(int columnIndex, LPCWSTR text, int width) | 74 | int CListView::InsertColumn(unsigned columnIndex, LPCWSTR text, int width) |
| 68 | { | 75 | { |
| 69 | LVCOLUMNW ci; | 76 | LVCOLUMNW ci; |
| 70 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | 77 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
| 71 | ci.pszText = (LPWSTR)(void *)text; | 78 | ci.pszText = (LPWSTR)(void *)text; |
| 72 | ci.iSubItem = columnIndex; | 79 | ci.iSubItem = (int)columnIndex; |
| 73 | ci.cx = width; | 80 | ci.cx = width; |
| 74 | return InsertColumn(columnIndex, &ci); | 81 | return InsertColumn(columnIndex, &ci); |
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | int CListView::InsertItem(int index, LPCWSTR text) | 84 | int CListView::InsertItem(unsigned index, LPCWSTR text) |
| 78 | { | 85 | { |
| 79 | LVITEMW item; | 86 | LVITEMW item; |
| 80 | item.mask = LVIF_TEXT | LVIF_PARAM; | 87 | item.mask = LVIF_TEXT | LVIF_PARAM; |
| 81 | item.iItem = index; | 88 | item.iItem = (int)index; |
| 82 | item.lParam = index; | 89 | item.lParam = (LPARAM)index; |
| 83 | item.pszText = (LPWSTR)(void *)text; | 90 | item.pszText = (LPWSTR)(void *)text; |
| 84 | item.iSubItem = 0; | 91 | item.iSubItem = 0; |
| 85 | return InsertItem(&item); | 92 | return InsertItem(&item); |
| 86 | } | 93 | } |
| 87 | 94 | ||
| 88 | int CListView::SetSubItem(int index, int subIndex, LPCWSTR text) | 95 | int CListView::SetSubItem(unsigned index, unsigned subIndex, LPCWSTR text) |
| 89 | { | 96 | { |
| 90 | LVITEMW item; | 97 | LVITEMW item; |
| 91 | item.mask = LVIF_TEXT; | 98 | item.mask = LVIF_TEXT; |
| 92 | item.iItem = index; | 99 | item.iItem = (int)index; |
| 93 | item.pszText = (LPWSTR)(void *)text; | 100 | item.pszText = (LPWSTR)(void *)text; |
| 94 | item.iSubItem = subIndex; | 101 | item.iSubItem = (int)subIndex; |
| 95 | return SetItem(&item); | 102 | return SetItem(&item); |
| 96 | } | 103 | } |
| 97 | 104 | ||
diff --git a/CPP/Windows/Control/ListView.h b/CPP/Windows/Control/ListView.h index a13b104..11a33a0 100644 --- a/CPP/Windows/Control/ListView.h +++ b/CPP/Windows/Control/ListView.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ListView.h | 1 | // Windows/Control/ListView.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_LISTVIEW_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_LISTVIEW_H |
| 4 | #define __WINDOWS_CONTROL_LISTVIEW_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_LISTVIEW_H |
| 5 | 5 | ||
| 6 | #include "../../Common/MyWindows.h" | 6 | #include "../../Common/MyWindows.h" |
| 7 | 7 | ||
| @@ -28,11 +28,11 @@ public: | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); } | 30 | bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); } |
| 31 | bool DeleteColumn(int columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); } | 31 | bool DeleteColumn(unsigned columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); } |
| 32 | 32 | ||
| 33 | int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); } | 33 | int InsertColumn(unsigned columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); } |
| 34 | int InsertColumn(int columnIndex, LPCTSTR text, int width); | 34 | int InsertColumn(unsigned columnIndex, LPCTSTR text, int width); |
| 35 | bool SetColumnOrderArray(int count, const int *columns) | 35 | bool SetColumnOrderArray(unsigned count, const int *columns) |
| 36 | { return BOOLToBool(ListView_SetColumnOrderArray(_window, count, (int *)(void *)columns)); } | 36 | { return BOOLToBool(ListView_SetColumnOrderArray(_window, count, (int *)(void *)columns)); } |
| 37 | 37 | ||
| 38 | /* | 38 | /* |
| @@ -46,43 +46,49 @@ public: | |||
| 46 | */ | 46 | */ |
| 47 | 47 | ||
| 48 | int InsertItem(const LVITEM* item) { return ListView_InsertItem(_window, item); } | 48 | int InsertItem(const LVITEM* item) { return ListView_InsertItem(_window, item); } |
| 49 | int InsertItem(int index, LPCTSTR text); | 49 | int InsertItem(unsigned index, LPCTSTR text); |
| 50 | bool SetItem(const LVITEM* item) { return BOOLToBool(ListView_SetItem(_window, item)); } | 50 | bool SetItem(const LVITEM* item) { return BOOLToBool(ListView_SetItem(_window, item)); } |
| 51 | int SetSubItem(int index, int subIndex, LPCTSTR text); | 51 | int SetSubItem(unsigned index, unsigned subIndex, LPCTSTR text); |
| 52 | 52 | ||
| 53 | #ifndef _UNICODE | 53 | #ifndef _UNICODE |
| 54 | 54 | ||
| 55 | int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMsg(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); } | 55 | int InsertColumn(unsigned columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMsg(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); } |
| 56 | int InsertColumn(int columnIndex, LPCWSTR text, int width); | 56 | int InsertColumn(unsigned columnIndex, LPCWSTR text, int width); |
| 57 | int InsertItem(const LV_ITEMW* item) { return (int)SendMsg(LVM_INSERTITEMW, 0, (LPARAM)item); } | 57 | int InsertItem(const LV_ITEMW* item) { return (int)SendMsg(LVM_INSERTITEMW, 0, (LPARAM)item); } |
| 58 | int InsertItem(int index, LPCWSTR text); | 58 | int InsertItem(unsigned index, LPCWSTR text); |
| 59 | bool SetItem(const LV_ITEMW* item) { return BOOLToBool((BOOL)SendMsg(LVM_SETITEMW, 0, (LPARAM)item)); } | 59 | bool SetItem(const LV_ITEMW* item) { return BOOLToBool((BOOL)SendMsg(LVM_SETITEMW, 0, (LPARAM)item)); } |
| 60 | int SetSubItem(int index, int subIndex, LPCWSTR text); | 60 | int SetSubItem(unsigned index, unsigned subIndex, LPCWSTR text); |
| 61 | 61 | ||
| 62 | #endif | 62 | #endif |
| 63 | 63 | ||
| 64 | bool DeleteItem(int itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); } | 64 | bool DeleteItem(unsigned itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); } |
| 65 | 65 | ||
| 66 | UINT GetSelectedCount() const { return ListView_GetSelectedCount(_window); } | 66 | UINT GetSelectedCount() const { return ListView_GetSelectedCount(_window); } |
| 67 | int GetItemCount() const { return ListView_GetItemCount(_window); } | 67 | int GetItemCount() const { return ListView_GetItemCount(_window); } |
| 68 | 68 | ||
| 69 | INT GetSelectionMark() const { return ListView_GetSelectionMark(_window); } | 69 | INT GetSelectionMark() const { return ListView_GetSelectionMark(_window); } |
| 70 | 70 | ||
| 71 | void SetItemCount(int numItems) { ListView_SetItemCount(_window, numItems); } | 71 | void SetItemCount(unsigned numItems) { ListView_SetItemCount(_window, numItems); } |
| 72 | void SetItemCountEx(int numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); } | 72 | void SetItemCountEx(unsigned numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); } |
| 73 | 73 | ||
| 74 | /* startIndex : The index of the item with which to begin the search, | ||
| 75 | or -1 to find the first item that matches the specified flags. | ||
| 76 | The specified item itself is excluded from the search. */ | ||
| 74 | int GetNextItem(int startIndex, UINT flags) const { return ListView_GetNextItem(_window, startIndex, flags); } | 77 | int GetNextItem(int startIndex, UINT flags) const { return ListView_GetNextItem(_window, startIndex, flags); } |
| 75 | int GetNextSelectedItem(int startIndex) const { return GetNextItem(startIndex, LVNI_SELECTED); } | 78 | int GetNextSelectedItem(int startIndex) const { return GetNextItem(startIndex, LVNI_SELECTED); } |
| 76 | int GetFocusedItem() const { return GetNextItem(-1, LVNI_FOCUSED); } | 79 | int GetFocusedItem() const { return GetNextItem(-1, LVNI_FOCUSED); } |
| 77 | 80 | ||
| 78 | bool GetItem(LVITEM* item) const { return BOOLToBool(ListView_GetItem(_window, item)); } | 81 | bool GetItem(LVITEM* item) const { return BOOLToBool(ListView_GetItem(_window, item)); } |
| 79 | bool GetItemParam(int itemIndex, LPARAM ¶m) const; | 82 | bool GetItemParam(unsigned itemIndex, LPARAM ¶m) const; |
| 80 | void GetItemText(int itemIndex, int subItemIndex, LPTSTR text, int textSizeMax) const | 83 | /* |
| 81 | { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax); } | 84 | void GetItemText(unsigned itemIndex, unsigned subItemIndex, LPTSTR text, unsigned textSizeMax) const |
| 85 | { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax) } | ||
| 86 | */ | ||
| 82 | bool SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) | 87 | bool SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) |
| 83 | { return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); } | 88 | { return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); } |
| 84 | 89 | ||
| 85 | void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask); } | 90 | // If (index == -1), then the state change is applied to all items. |
| 91 | void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask) } | ||
| 86 | void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); } | 92 | void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); } |
| 87 | void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); } | 93 | void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); } |
| 88 | void SelectAll() { SetItemState_Selected(-1); } | 94 | void SelectAll() { SetItemState_Selected(-1); } |
| @@ -90,7 +96,7 @@ public: | |||
| 90 | UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); } | 96 | UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); } |
| 91 | bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; } | 97 | bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; } |
| 92 | 98 | ||
| 93 | bool GetColumn(int columnIndex, LVCOLUMN* columnInfo) const | 99 | bool GetColumn(unsigned columnIndex, LVCOLUMN* columnInfo) const |
| 94 | { return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); } | 100 | { return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); } |
| 95 | 101 | ||
| 96 | HIMAGELIST SetImageList(HIMAGELIST imageList, int imageListType) | 102 | HIMAGELIST SetImageList(HIMAGELIST imageList, int imageListType) |
| @@ -101,7 +107,7 @@ public: | |||
| 101 | void SetExtendedListViewStyle(DWORD exStyle) { ListView_SetExtendedListViewStyle(_window, exStyle); } | 107 | void SetExtendedListViewStyle(DWORD exStyle) { ListView_SetExtendedListViewStyle(_window, exStyle); } |
| 102 | void SetExtendedListViewStyle(DWORD exMask, DWORD exStyle) { ListView_SetExtendedListViewStyleEx(_window, exMask, exStyle); } | 108 | void SetExtendedListViewStyle(DWORD exMask, DWORD exStyle) { ListView_SetExtendedListViewStyleEx(_window, exMask, exStyle); } |
| 103 | 109 | ||
| 104 | void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)); } | 110 | void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)) } |
| 105 | bool GetCheckState(UINT index) { return BOOLToBool(ListView_GetCheckState(_window, index)); } | 111 | bool GetCheckState(UINT index) { return BOOLToBool(ListView_GetCheckState(_window, index)); } |
| 106 | 112 | ||
| 107 | bool EnsureVisible(int index, bool partialOK) { return BOOLToBool(ListView_EnsureVisible(_window, index, BoolToBOOL(partialOK))); } | 113 | bool EnsureVisible(int index, bool partialOK) { return BOOLToBool(ListView_EnsureVisible(_window, index, BoolToBOOL(partialOK))); } |
| @@ -129,7 +135,10 @@ public: | |||
| 129 | class CListView2: public CListView | 135 | class CListView2: public CListView |
| 130 | { | 136 | { |
| 131 | WNDPROC _origWindowProc; | 137 | WNDPROC _origWindowProc; |
| 138 | // ~CListView2() ZIP7_eq_delete; | ||
| 132 | public: | 139 | public: |
| 140 | virtual ~CListView2() {} | ||
| 141 | CListView2() {} | ||
| 133 | void SetWindowProc(); | 142 | void SetWindowProc(); |
| 134 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | 143 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); |
| 135 | }; | 144 | }; |
diff --git a/CPP/Windows/Control/ProgressBar.h b/CPP/Windows/Control/ProgressBar.h index 0374306..2256aa9 100644 --- a/CPP/Windows/Control/ProgressBar.h +++ b/CPP/Windows/Control/ProgressBar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ProgressBar.h | 1 | // Windows/Control/ProgressBar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_PROGRESSBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_PROGRESSBAR_H |
| 4 | #define __WINDOWS_CONTROL_PROGRESSBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_PROGRESSBAR_H |
| 5 | 5 | ||
| 6 | #include "../../Common/MyWindows.h" | 6 | #include "../../Common/MyWindows.h" |
| 7 | 7 | ||
| @@ -15,18 +15,18 @@ namespace NControl { | |||
| 15 | class CProgressBar: public CWindow | 15 | class CProgressBar: public CWindow |
| 16 | { | 16 | { |
| 17 | public: | 17 | public: |
| 18 | LRESULT SetPos(int pos) { return SendMsg(PBM_SETPOS, pos, 0); } | 18 | LRESULT SetPos(int pos) { return SendMsg(PBM_SETPOS, (unsigned)pos, 0); } |
| 19 | LRESULT DeltaPos(int increment) { return SendMsg(PBM_DELTAPOS, increment, 0); } | 19 | // LRESULT DeltaPos(int increment) { return SendMsg(PBM_DELTAPOS, increment, 0); } |
| 20 | UINT GetPos() { return (UINT)SendMsg(PBM_GETPOS, 0, 0); } | 20 | // UINT GetPos() { return (UINT)SendMsg(PBM_GETPOS, 0, 0); } |
| 21 | LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMsg(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); } | 21 | // LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMsg(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); } |
| 22 | DWORD SetRange32(int minValue, int maxValue) { return (DWORD)SendMsg(PBM_SETRANGE32, minValue, maxValue); } | 22 | DWORD SetRange32(int minValue, int maxValue) { return (DWORD)SendMsg(PBM_SETRANGE32, (unsigned)minValue, (LPARAM)(unsigned)maxValue); } |
| 23 | int SetStep(int step) { return (int)SendMsg(PBM_SETSTEP, step, 0); } | 23 | // int SetStep(int step) { return (int)SendMsg(PBM_SETSTEP, step, 0); } |
| 24 | LRESULT StepIt() { return SendMsg(PBM_STEPIT, 0, 0); } | 24 | // LRESULT StepIt() { return SendMsg(PBM_STEPIT, 0, 0); } |
| 25 | INT GetRange(bool minValue, PPBRANGE range) { return (INT)SendMsg(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); } | 25 | // INT GetRange(bool minValue, PPBRANGE range) { return (INT)SendMsg(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); } |
| 26 | 26 | ||
| 27 | #ifndef UNDER_CE | 27 | #ifndef UNDER_CE |
| 28 | COLORREF SetBarColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBARCOLOR, 0, color); } | 28 | COLORREF SetBarColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBARCOLOR, 0, (LPARAM)color); } |
| 29 | COLORREF SetBackgroundColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBKCOLOR, 0, color); } | 29 | COLORREF SetBackgroundColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBKCOLOR, 0, (LPARAM)color); } |
| 30 | #endif | 30 | #endif |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
diff --git a/CPP/Windows/Control/PropertyPage.cpp b/CPP/Windows/Control/PropertyPage.cpp index ce8696d..f8effe6 100644 --- a/CPP/Windows/Control/PropertyPage.cpp +++ b/CPP/Windows/Control/PropertyPage.cpp | |||
| @@ -16,7 +16,13 @@ extern bool g_IsNT; | |||
| 16 | namespace NWindows { | 16 | namespace NWindows { |
| 17 | namespace NControl { | 17 | namespace NControl { |
| 18 | 18 | ||
| 19 | static INT_PTR APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | 19 | static |
| 20 | #ifdef Z7_OLD_WIN_SDK | ||
| 21 | BOOL | ||
| 22 | #else | ||
| 23 | INT_PTR | ||
| 24 | #endif | ||
| 25 | APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 20 | { | 26 | { |
| 21 | CWindow tempDialog(dialogHWND); | 27 | CWindow tempDialog(dialogHWND); |
| 22 | if (message == WM_INITDIALOG) | 28 | if (message == WM_INITDIALOG) |
| @@ -34,75 +40,91 @@ bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam) | |||
| 34 | { | 40 | { |
| 35 | switch (lParam->code) | 41 | switch (lParam->code) |
| 36 | { | 42 | { |
| 37 | case PSN_APPLY: SetMsgResult(OnApply(LPPSHNOTIFY(lParam))); break; | 43 | case PSN_APPLY: SetMsgResult(OnApply2(LPPSHNOTIFY(lParam))); break; |
| 38 | case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam)))); break; | 44 | case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive2(LPPSHNOTIFY(lParam)))); break; |
| 39 | case PSN_SETACTIVE: SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam))); break; | 45 | case PSN_SETACTIVE: SetMsgResult(OnSetActive2(LPPSHNOTIFY(lParam))); break; |
| 40 | case PSN_RESET: OnReset(LPPSHNOTIFY(lParam)); break; | 46 | case PSN_RESET: OnReset2(LPPSHNOTIFY(lParam)); break; |
| 41 | case PSN_HELP: OnNotifyHelp(LPPSHNOTIFY(lParam)); break; | 47 | case PSN_HELP: OnNotifyHelp2(LPPSHNOTIFY(lParam)); break; |
| 42 | default: return false; | 48 | default: return false; |
| 43 | } | 49 | } |
| 44 | return true; | 50 | return true; |
| 45 | } | 51 | } |
| 46 | 52 | ||
| 53 | /* | ||
| 54 | PROPSHEETPAGE fields depend from | ||
| 55 | #if (_WIN32_WINNT >= 0x0600) | ||
| 56 | #elif (_WIN32_WINNT >= 0x0501) | ||
| 57 | #elif (_WIN32_IE >= 0x0400) | ||
| 58 | PROPSHEETHEADER fields depend from | ||
| 59 | #if (_WIN32_IE >= 0x0400) | ||
| 60 | */ | ||
| 61 | #if defined(PROPSHEETPAGEA_V1_SIZE) && !defined(Z7_OLD_WIN_SDK) | ||
| 62 | #ifndef _UNICODE | ||
| 63 | #define my_compatib_PROPSHEETPAGEA PROPSHEETPAGEA_V1 | ||
| 64 | #endif | ||
| 65 | #define my_compatib_PROPSHEETPAGEW PROPSHEETPAGEW_V1 | ||
| 66 | #else | ||
| 67 | // for old mingw: | ||
| 68 | #ifndef _UNICODE | ||
| 69 | #define my_compatib_PROPSHEETPAGEA PROPSHEETPAGEA | ||
| 70 | #endif | ||
| 71 | #define my_compatib_PROPSHEETPAGEW PROPSHEETPAGEW | ||
| 72 | #endif | ||
| 73 | |||
| 47 | INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title) | 74 | INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title) |
| 48 | { | 75 | { |
| 49 | #ifndef _UNICODE | ||
| 50 | AStringVector titles; | ||
| 51 | #endif | ||
| 52 | #ifndef _UNICODE | ||
| 53 | CRecordVector<PROPSHEETPAGEA> pagesA; | ||
| 54 | #endif | ||
| 55 | CRecordVector<PROPSHEETPAGEW> pagesW; | ||
| 56 | |||
| 57 | unsigned i; | 76 | unsigned i; |
| 58 | #ifndef _UNICODE | 77 | #ifndef _UNICODE |
| 78 | AStringVector titles; | ||
| 59 | for (i = 0; i < pagesInfo.Size(); i++) | 79 | for (i = 0; i < pagesInfo.Size(); i++) |
| 60 | titles.Add(GetSystemString(pagesInfo[i].Title)); | 80 | titles.Add(GetSystemString(pagesInfo[i].Title)); |
| 81 | CRecordVector<my_compatib_PROPSHEETPAGEA> pagesA; | ||
| 61 | #endif | 82 | #endif |
| 83 | CRecordVector<my_compatib_PROPSHEETPAGEW> pagesW; | ||
| 62 | 84 | ||
| 63 | for (i = 0; i < pagesInfo.Size(); i++) | 85 | for (i = 0; i < pagesInfo.Size(); i++) |
| 64 | { | 86 | { |
| 65 | const CPageInfo &pageInfo = pagesInfo[i]; | 87 | const CPageInfo &pageInfo = pagesInfo[i]; |
| 66 | #ifndef _UNICODE | 88 | #ifndef _UNICODE |
| 67 | { | 89 | { |
| 68 | PROPSHEETPAGE page; | 90 | my_compatib_PROPSHEETPAGEA page; |
| 91 | memset(&page, 0, sizeof(page)); | ||
| 69 | page.dwSize = sizeof(page); | 92 | page.dwSize = sizeof(page); |
| 70 | page.dwFlags = PSP_HASHELP; | 93 | page.dwFlags = PSP_HASHELP; |
| 71 | page.hInstance = g_hInstance; | 94 | page.hInstance = g_hInstance; |
| 72 | page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID); | 95 | page.pszTemplate = MAKEINTRESOURCEA(pageInfo.ID); |
| 73 | page.pszIcon = NULL; | 96 | // page.pszIcon = NULL; |
| 74 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; | 97 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; |
| 75 | 98 | ||
| 76 | if (titles[i].IsEmpty()) | 99 | if (!titles[i].IsEmpty()) |
| 77 | page.pszTitle = NULL; | ||
| 78 | else | ||
| 79 | { | 100 | { |
| 80 | page.dwFlags |= PSP_USETITLE; | ||
| 81 | page.pszTitle = titles[i]; | 101 | page.pszTitle = titles[i]; |
| 102 | page.dwFlags |= PSP_USETITLE; | ||
| 82 | } | 103 | } |
| 104 | // else page.pszTitle = NULL; | ||
| 83 | page.lParam = (LPARAM)pageInfo.Page; | 105 | page.lParam = (LPARAM)pageInfo.Page; |
| 84 | page.pfnCallback = NULL; | 106 | // page.pfnCallback = NULL; |
| 85 | pagesA.Add(page); | 107 | pagesA.Add(page); |
| 86 | } | 108 | } |
| 87 | #endif | 109 | #endif |
| 88 | { | 110 | { |
| 89 | PROPSHEETPAGEW page; | 111 | my_compatib_PROPSHEETPAGEW page; |
| 112 | memset(&page, 0, sizeof(page)); | ||
| 90 | page.dwSize = sizeof(page); | 113 | page.dwSize = sizeof(page); |
| 91 | page.dwFlags = PSP_HASHELP; | 114 | page.dwFlags = PSP_HASHELP; |
| 92 | page.hInstance = g_hInstance; | 115 | page.hInstance = g_hInstance; |
| 93 | page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID); | 116 | page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID); |
| 94 | page.pszIcon = NULL; | 117 | // page.pszIcon = NULL; |
| 95 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; | 118 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; |
| 96 | 119 | ||
| 97 | if (pageInfo.Title.IsEmpty()) | 120 | if (!pageInfo.Title.IsEmpty()) |
| 98 | page.pszTitle = NULL; | ||
| 99 | else | ||
| 100 | { | 121 | { |
| 101 | page.dwFlags |= PSP_USETITLE; | ||
| 102 | page.pszTitle = pageInfo.Title; | 122 | page.pszTitle = pageInfo.Title; |
| 123 | page.dwFlags |= PSP_USETITLE; | ||
| 103 | } | 124 | } |
| 125 | // else page.pszTitle = NULL; | ||
| 104 | page.lParam = (LPARAM)pageInfo.Page; | 126 | page.lParam = (LPARAM)pageInfo.Page; |
| 105 | page.pfnCallback = NULL; | 127 | // page.pfnCallback = NULL; |
| 106 | pagesW.Add(page); | 128 | pagesW.Add(page); |
| 107 | } | 129 | } |
| 108 | } | 130 | } |
| @@ -110,16 +132,16 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare | |||
| 110 | #ifndef _UNICODE | 132 | #ifndef _UNICODE |
| 111 | if (!g_IsNT) | 133 | if (!g_IsNT) |
| 112 | { | 134 | { |
| 113 | PROPSHEETHEADER sheet; | 135 | PROPSHEETHEADERA sheet; |
| 114 | sheet.dwSize = sizeof(sheet); | 136 | sheet.dwSize = sizeof(sheet); |
| 115 | sheet.dwFlags = PSH_PROPSHEETPAGE; | 137 | sheet.dwFlags = PSH_PROPSHEETPAGE; |
| 116 | sheet.hwndParent = hwndParent; | 138 | sheet.hwndParent = hwndParent; |
| 117 | sheet.hInstance = g_hInstance; | 139 | sheet.hInstance = g_hInstance; |
| 118 | AString titleA (GetSystemString(title)); | 140 | AString titleA (GetSystemString(title)); |
| 119 | sheet.pszCaption = titleA; | 141 | sheet.pszCaption = titleA; |
| 120 | sheet.nPages = pagesInfo.Size(); | 142 | sheet.nPages = pagesA.Size(); |
| 121 | sheet.nStartPage = 0; | 143 | sheet.nStartPage = 0; |
| 122 | sheet.ppsp = &pagesA.Front(); | 144 | sheet.ppsp = (LPCPROPSHEETPAGEA)(const void *)&pagesA.Front(); |
| 123 | sheet.pfnCallback = NULL; | 145 | sheet.pfnCallback = NULL; |
| 124 | return ::PropertySheetA(&sheet); | 146 | return ::PropertySheetA(&sheet); |
| 125 | } | 147 | } |
| @@ -132,9 +154,9 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare | |||
| 132 | sheet.hwndParent = hwndParent; | 154 | sheet.hwndParent = hwndParent; |
| 133 | sheet.hInstance = g_hInstance; | 155 | sheet.hInstance = g_hInstance; |
| 134 | sheet.pszCaption = title; | 156 | sheet.pszCaption = title; |
| 135 | sheet.nPages = pagesInfo.Size(); | 157 | sheet.nPages = pagesW.Size(); |
| 136 | sheet.nStartPage = 0; | 158 | sheet.nStartPage = 0; |
| 137 | sheet.ppsp = &pagesW.Front(); | 159 | sheet.ppsp = (LPCPROPSHEETPAGEW)(const void *)&pagesW.Front(); |
| 138 | sheet.pfnCallback = NULL; | 160 | sheet.pfnCallback = NULL; |
| 139 | return ::PropertySheetW(&sheet); | 161 | return ::PropertySheetW(&sheet); |
| 140 | } | 162 | } |
diff --git a/CPP/Windows/Control/PropertyPage.h b/CPP/Windows/Control/PropertyPage.h index b68fd8f..264a5d2 100644 --- a/CPP/Windows/Control/PropertyPage.h +++ b/CPP/Windows/Control/PropertyPage.h | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | // Windows/Control/PropertyPage.h | 1 | // Windows/Control/PropertyPage.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_PROPERTYPAGE_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_PROPERTYPAGE_H |
| 4 | #define __WINDOWS_CONTROL_PROPERTYPAGE_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_PROPERTYPAGE_H |
| 5 | 5 | ||
| 6 | #include "../../Common/MyWindows.h" | 6 | #include "../../Common/MyWindows.h" |
| 7 | 7 | ||
| 8 | #include <PrSht.h> | 8 | #include <prsht.h> |
| 9 | 9 | ||
| 10 | #include "Dialog.h" | 10 | #include "Dialog.h" |
| 11 | 11 | ||
| @@ -17,23 +17,23 @@ INT_PTR APIENTRY ProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wPar | |||
| 17 | class CPropertyPage: public CDialog | 17 | class CPropertyPage: public CDialog |
| 18 | { | 18 | { |
| 19 | public: | 19 | public: |
| 20 | CPropertyPage(HWND window = NULL): CDialog(window){}; | 20 | CPropertyPage(HWND window = NULL): CDialog(window) {} |
| 21 | 21 | ||
| 22 | void Changed() { PropSheet_Changed(GetParent(), (HWND)*this); } | 22 | void Changed() { PropSheet_Changed(GetParent(), (HWND)*this); } |
| 23 | void UnChanged() { PropSheet_UnChanged(GetParent(), (HWND)*this); } | 23 | void UnChanged() { PropSheet_UnChanged(GetParent(), (HWND)*this); } |
| 24 | 24 | ||
| 25 | virtual bool OnNotify(UINT controlID, LPNMHDR lParam); | 25 | virtual bool OnNotify(UINT controlID, LPNMHDR lParam) Z7_override; |
| 26 | 26 | ||
| 27 | virtual bool OnKillActive() { return false; } // false = OK | 27 | virtual bool OnKillActive() { return false; } // false = OK |
| 28 | virtual bool OnKillActive(const PSHNOTIFY *) { return OnKillActive(); } | 28 | virtual bool OnKillActive2(const PSHNOTIFY *) { return OnKillActive(); } |
| 29 | virtual LONG OnSetActive() { return false; } // false = OK | 29 | virtual LONG OnSetActive() { return false; } // false = OK |
| 30 | virtual LONG OnSetActive(const PSHNOTIFY *) { return OnSetActive(); } | 30 | virtual LONG OnSetActive2(const PSHNOTIFY *) { return OnSetActive(); } |
| 31 | virtual LONG OnApply() { return PSNRET_NOERROR; } | 31 | virtual LONG OnApply() { return PSNRET_NOERROR; } |
| 32 | virtual LONG OnApply(const PSHNOTIFY *) { return OnApply(); } | 32 | virtual LONG OnApply2(const PSHNOTIFY *) { return OnApply(); } |
| 33 | virtual void OnNotifyHelp() {} | 33 | virtual void OnNotifyHelp() {} |
| 34 | virtual void OnNotifyHelp(const PSHNOTIFY *) { OnNotifyHelp(); } | 34 | virtual void OnNotifyHelp2(const PSHNOTIFY *) { OnNotifyHelp(); } |
| 35 | virtual void OnReset() {} | 35 | virtual void OnReset() {} |
| 36 | virtual void OnReset(const PSHNOTIFY *) { OnReset(); } | 36 | virtual void OnReset2(const PSHNOTIFY *) { OnReset(); } |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | struct CPageInfo | 39 | struct CPageInfo |
diff --git a/CPP/Windows/Control/ReBar.h b/CPP/Windows/Control/ReBar.h index c2d58db..b56f018 100644 --- a/CPP/Windows/Control/ReBar.h +++ b/CPP/Windows/Control/ReBar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ReBar.h | 1 | // Windows/Control/ReBar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_REBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_REBAR_H |
| 4 | #define __WINDOWS_CONTROL_REBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_REBAR_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
| @@ -14,7 +14,7 @@ public: | |||
| 14 | bool SetBarInfo(LPREBARINFO barInfo) | 14 | bool SetBarInfo(LPREBARINFO barInfo) |
| 15 | { return LRESULTToBool(SendMsg(RB_SETBARINFO, 0, (LPARAM)barInfo)); } | 15 | { return LRESULTToBool(SendMsg(RB_SETBARINFO, 0, (LPARAM)barInfo)); } |
| 16 | bool InsertBand(int index, LPREBARBANDINFO bandInfo) | 16 | bool InsertBand(int index, LPREBARBANDINFO bandInfo) |
| 17 | { return LRESULTToBool(SendMsg(RB_INSERTBAND, index, (LPARAM)bandInfo)); } | 17 | { return LRESULTToBool(SendMsg(RB_INSERTBAND, MY_int_TO_WPARAM(index), (LPARAM)bandInfo)); } |
| 18 | bool SetBandInfo(unsigned index, LPREBARBANDINFO bandInfo) | 18 | bool SetBandInfo(unsigned index, LPREBARBANDINFO bandInfo) |
| 19 | { return LRESULTToBool(SendMsg(RB_SETBANDINFO, index, (LPARAM)bandInfo)); } | 19 | { return LRESULTToBool(SendMsg(RB_SETBANDINFO, index, (LPARAM)bandInfo)); } |
| 20 | void MaximizeBand(unsigned index, bool ideal) | 20 | void MaximizeBand(unsigned index, bool ideal) |
diff --git a/CPP/Windows/Control/Static.h b/CPP/Windows/Control/Static.h index 5523b2e..ceeedf9 100644 --- a/CPP/Windows/Control/Static.h +++ b/CPP/Windows/Control/Static.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/Static.h | 1 | // Windows/Control/Static.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_STATIC_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_STATIC_H |
| 4 | #define __WINDOWS_CONTROL_STATIC_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_STATIC_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Control/StatusBar.h b/CPP/Windows/Control/StatusBar.h index 988b847..38aca47 100644 --- a/CPP/Windows/Control/StatusBar.h +++ b/CPP/Windows/Control/StatusBar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/StatusBar.h | 1 | // Windows/Control/StatusBar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_STATUSBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_STATUSBAR_H |
| 4 | #define __WINDOWS_CONTROL_STATUSBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_STATUSBAR_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
| @@ -12,7 +12,7 @@ class CStatusBar: public NWindows::CWindow | |||
| 12 | { | 12 | { |
| 13 | public: | 13 | public: |
| 14 | bool Create(LONG style, LPCTSTR text, HWND hwndParent, UINT id) | 14 | bool Create(LONG style, LPCTSTR text, HWND hwndParent, UINT id) |
| 15 | { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != 0; } | 15 | { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != NULL; } |
| 16 | bool SetText(LPCTSTR text) | 16 | bool SetText(LPCTSTR text) |
| 17 | { return CWindow::SetText(text); } | 17 | { return CWindow::SetText(text); } |
| 18 | bool SetText(unsigned index, LPCTSTR text, UINT type) | 18 | bool SetText(unsigned index, LPCTSTR text, UINT type) |
| @@ -22,7 +22,7 @@ public: | |||
| 22 | 22 | ||
| 23 | #ifndef _UNICODE | 23 | #ifndef _UNICODE |
| 24 | bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id) | 24 | bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id) |
| 25 | { return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != 0; } | 25 | { return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != NULL; } |
| 26 | bool SetText(LPCWSTR text) | 26 | bool SetText(LPCWSTR text) |
| 27 | { return CWindow::SetText(text); } | 27 | { return CWindow::SetText(text); } |
| 28 | bool SetText(unsigned index, LPCWSTR text, UINT type) | 28 | bool SetText(unsigned index, LPCWSTR text, UINT type) |
| @@ -34,7 +34,7 @@ public: | |||
| 34 | bool SetParts(unsigned numParts, const int *edgePostions) | 34 | bool SetParts(unsigned numParts, const int *edgePostions) |
| 35 | { return LRESULTToBool(SendMsg(SB_SETPARTS, numParts, (LPARAM)edgePostions)); } | 35 | { return LRESULTToBool(SendMsg(SB_SETPARTS, numParts, (LPARAM)edgePostions)); } |
| 36 | void Simple(bool simple) | 36 | void Simple(bool simple) |
| 37 | { SendMsg(SB_SIMPLE, BoolToBOOL(simple), 0); } | 37 | { SendMsg(SB_SIMPLE, (WPARAM)BoolToBOOL(simple), 0); } |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | }} | 40 | }} |
diff --git a/CPP/Windows/Control/StdAfx.h b/CPP/Windows/Control/StdAfx.h index 1cbd7fe..8086655 100644 --- a/CPP/Windows/Control/StdAfx.h +++ b/CPP/Windows/Control/StdAfx.h | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | // StdAfx.h | 1 | // StdAfx.h |
| 2 | 2 | ||
| 3 | #ifndef __STDAFX_H | 3 | #ifndef ZIP7_INC_STDAFX_H |
| 4 | #define __STDAFX_H | 4 | #define ZIP7_INC_STDAFX_H |
| 5 | 5 | ||
| 6 | #if defined(_MSC_VER) && _MSC_VER >= 1800 | ||
| 7 | #pragma warning(disable : 4464) // relative include path contains '..' | ||
| 8 | #endif | ||
| 6 | #include "../../Common/Common.h" | 9 | #include "../../Common/Common.h" |
| 7 | 10 | ||
| 8 | #endif | 11 | #endif |
diff --git a/CPP/Windows/Control/ToolBar.h b/CPP/Windows/Control/ToolBar.h index 7bc93a2..2bf20a5 100644 --- a/CPP/Windows/Control/ToolBar.h +++ b/CPP/Windows/Control/ToolBar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/ToolBar.h | 1 | // Windows/Control/ToolBar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_TOOLBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_TOOLBAR_H |
| 4 | #define __WINDOWS_CONTROL_TOOLBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_TOOLBAR_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
| @@ -18,7 +18,7 @@ public: | |||
| 18 | #ifdef UNDER_CE | 18 | #ifdef UNDER_CE |
| 19 | { | 19 | { |
| 20 | // maybe it must be fixed for more than 1 buttons | 20 | // maybe it must be fixed for more than 1 buttons |
| 21 | DWORD val = GetButtonSize(); | 21 | const DWORD val = GetButtonSize(); |
| 22 | size->cx = LOWORD(val); | 22 | size->cx = LOWORD(val); |
| 23 | size->cy = HIWORD(val); | 23 | size->cy = HIWORD(val); |
| 24 | return true; | 24 | return true; |
diff --git a/CPP/Windows/Control/Trackbar.h b/CPP/Windows/Control/Trackbar.h index 313e0c8..18d1b29 100644 --- a/CPP/Windows/Control/Trackbar.h +++ b/CPP/Windows/Control/Trackbar.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/Trackbar.h | 1 | // Windows/Control/Trackbar.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_TRACKBAR_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_TRACKBAR_H |
| 4 | #define __WINDOWS_CONTROL_TRACKBAR_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_TRACKBAR_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Control/Window2.cpp b/CPP/Windows/Control/Window2.cpp index 994d96e..8fe908e 100644 --- a/CPP/Windows/Control/Window2.cpp +++ b/CPP/Windows/Control/Window2.cpp | |||
| @@ -32,9 +32,9 @@ static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message, WPARAM wParam, | |||
| 32 | if (message == MY_START_WM_CREATE) | 32 | if (message == MY_START_WM_CREATE) |
| 33 | tempWindow.SetUserDataLongPtr((LONG_PTR)(((LPCREATESTRUCT)lParam)->lpCreateParams)); | 33 | tempWindow.SetUserDataLongPtr((LONG_PTR)(((LPCREATESTRUCT)lParam)->lpCreateParams)); |
| 34 | CWindow2 *window = (CWindow2 *)(tempWindow.GetUserDataLongPtr()); | 34 | CWindow2 *window = (CWindow2 *)(tempWindow.GetUserDataLongPtr()); |
| 35 | if (window != NULL && message == MY_START_WM_CREATE) | 35 | if (window && message == MY_START_WM_CREATE) |
| 36 | window->Attach(aHWND); | 36 | window->Attach(aHWND); |
| 37 | if (window == 0) | 37 | if (!window) |
| 38 | { | 38 | { |
| 39 | #ifndef _UNICODE | 39 | #ifndef _UNICODE |
| 40 | if (g_IsNT) | 40 | if (g_IsNT) |
| @@ -140,7 +140,7 @@ LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 140 | return -1; | 140 | return -1; |
| 141 | break; | 141 | break; |
| 142 | case WM_COMMAND: | 142 | case WM_COMMAND: |
| 143 | if (OnCommand(wParam, lParam, result)) | 143 | if (OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result)) |
| 144 | return result; | 144 | return result; |
| 145 | break; | 145 | break; |
| 146 | case WM_NOTIFY: | 146 | case WM_NOTIFY: |
| @@ -160,12 +160,14 @@ LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 160 | return DefProc(message, wParam, lParam); | 160 | return DefProc(message, wParam, lParam); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | bool CWindow2::OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result) | 163 | /* |
| 164 | bool CWindow2::OnCommand2(WPARAM wParam, LPARAM lParam, LRESULT &result) | ||
| 164 | { | 165 | { |
| 165 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result); | 166 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result); |
| 166 | } | 167 | } |
| 168 | */ | ||
| 167 | 169 | ||
| 168 | bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */, LRESULT & /* result */) | 170 | bool CWindow2::OnCommand(unsigned /* code */, unsigned /* itemID */, LPARAM /* lParam */, LRESULT & /* result */) |
| 169 | { | 171 | { |
| 170 | return false; | 172 | return false; |
| 171 | // return DefProc(message, wParam, lParam); | 173 | // return DefProc(message, wParam, lParam); |
| @@ -176,7 +178,7 @@ bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */, | |||
| 176 | } | 178 | } |
| 177 | 179 | ||
| 178 | /* | 180 | /* |
| 179 | bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) | 181 | bool CDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND) |
| 180 | { | 182 | { |
| 181 | switch (buttonID) | 183 | switch (buttonID) |
| 182 | { | 184 | { |
diff --git a/CPP/Windows/Control/Window2.h b/CPP/Windows/Control/Window2.h index 7ac580c..ebb5979 100644 --- a/CPP/Windows/Control/Window2.h +++ b/CPP/Windows/Control/Window2.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Control/Window2.h | 1 | // Windows/Control/Window2.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_CONTROL_WINDOW2_H | 3 | #ifndef ZIP7_INC_WINDOWS_CONTROL_WINDOW2_H |
| 4 | #define __WINDOWS_CONTROL_WINDOW2_H | 4 | #define ZIP7_INC_WINDOWS_CONTROL_WINDOW2_H |
| 5 | 5 | ||
| 6 | #include "../Window.h" | 6 | #include "../Window.h" |
| 7 | 7 | ||
| @@ -10,10 +10,12 @@ namespace NControl { | |||
| 10 | 10 | ||
| 11 | class CWindow2: public CWindow | 11 | class CWindow2: public CWindow |
| 12 | { | 12 | { |
| 13 | // Z7_CLASS_NO_COPY(CWindow2) | ||
| 14 | |||
| 13 | LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam); | 15 | LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam); |
| 14 | public: | 16 | public: |
| 15 | CWindow2(HWND newWindow = NULL): CWindow(newWindow){}; | 17 | CWindow2(HWND newWindow = NULL): CWindow(newWindow) {} |
| 16 | virtual ~CWindow2() {}; | 18 | virtual ~CWindow2() {} |
| 17 | 19 | ||
| 18 | bool CreateEx(DWORD exStyle, LPCTSTR className, LPCTSTR windowName, | 20 | bool CreateEx(DWORD exStyle, LPCTSTR className, LPCTSTR windowName, |
| 19 | DWORD style, int x, int y, int width, int height, | 21 | DWORD style, int x, int y, int width, int height, |
| @@ -28,8 +30,8 @@ public: | |||
| 28 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | 30 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); |
| 29 | virtual bool OnCreate(CREATESTRUCT * /* createStruct */) { return true; } | 31 | virtual bool OnCreate(CREATESTRUCT * /* createStruct */) { return true; } |
| 30 | // virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam); | 32 | // virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam); |
| 31 | virtual bool OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result); | 33 | // bool OnCommand2(WPARAM wParam, LPARAM lParam, LRESULT &result); |
| 32 | virtual bool OnCommand(int code, int itemID, LPARAM lParam, LRESULT &result); | 34 | virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam, LRESULT &result); |
| 33 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } | 35 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } |
| 34 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */, LRESULT & /* result */) { return false; } | 36 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */, LRESULT & /* result */) { return false; } |
| 35 | virtual void OnDestroy() { PostQuitMessage(0); } | 37 | virtual void OnDestroy() { PostQuitMessage(0); } |
| @@ -37,7 +39,7 @@ public: | |||
| 37 | /* | 39 | /* |
| 38 | virtual LRESULT OnHelp(LPHELPINFO helpInfo) { OnHelp(); } | 40 | virtual LRESULT OnHelp(LPHELPINFO helpInfo) { OnHelp(); } |
| 39 | virtual LRESULT OnHelp() {}; | 41 | virtual LRESULT OnHelp() {}; |
| 40 | virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); | 42 | virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND); |
| 41 | virtual void OnOK() {}; | 43 | virtual void OnOK() {}; |
| 42 | virtual void OnCancel() {}; | 44 | virtual void OnCancel() {}; |
| 43 | */ | 45 | */ |
diff --git a/CPP/Windows/DLL.cpp b/CPP/Windows/DLL.cpp index cf5d01a..b2499ec 100644 --- a/CPP/Windows/DLL.cpp +++ b/CPP/Windows/DLL.cpp | |||
| @@ -17,11 +17,11 @@ namespace NDLL { | |||
| 17 | 17 | ||
| 18 | bool CLibrary::Free() throw() | 18 | bool CLibrary::Free() throw() |
| 19 | { | 19 | { |
| 20 | if (_module == 0) | 20 | if (_module == NULL) |
| 21 | return true; | 21 | return true; |
| 22 | if (!::FreeLibrary(_module)) | 22 | if (!::FreeLibrary(_module)) |
| 23 | return false; | 23 | return false; |
| 24 | _module = 0; | 24 | _module = NULL; |
| 25 | return true; | 25 | return true; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| @@ -90,7 +90,7 @@ bool MyGetModuleFileName(FString &path) | |||
| 90 | return false; | 90 | return false; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | #ifndef _SFX | 93 | #ifndef Z7_SFX |
| 94 | 94 | ||
| 95 | FString GetModuleDirPrefix() | 95 | FString GetModuleDirPrefix() |
| 96 | { | 96 | { |
| @@ -110,38 +110,35 @@ FString GetModuleDirPrefix() | |||
| 110 | 110 | ||
| 111 | }} | 111 | }} |
| 112 | 112 | ||
| 113 | #else | 113 | #else // _WIN32 |
| 114 | 114 | ||
| 115 | #include <dlfcn.h> | 115 | #include <dlfcn.h> |
| 116 | #include <stdlib.h> | 116 | #include <stdlib.h> |
| 117 | #include "../Common/Common.h" | ||
| 118 | |||
| 119 | // FARPROC | ||
| 120 | void *GetProcAddress(HMODULE module, LPCSTR procName) | ||
| 121 | { | ||
| 122 | void *ptr = NULL; | ||
| 123 | if (module) | ||
| 124 | ptr = dlsym(module, procName); | ||
| 125 | return ptr; | ||
| 126 | } | ||
| 117 | 127 | ||
| 118 | namespace NWindows { | 128 | namespace NWindows { |
| 119 | namespace NDLL { | 129 | namespace NDLL { |
| 120 | 130 | ||
| 121 | bool CLibrary::Free() throw() | 131 | bool CLibrary::Free() throw() |
| 122 | { | 132 | { |
| 123 | if (_module == NULL) | 133 | if (!_module) |
| 124 | return true; | 134 | return true; |
| 125 | int ret = dlclose(_module); | 135 | const int ret = dlclose(_module); |
| 126 | if (ret != 0) | 136 | if (ret != 0) |
| 127 | return false; | 137 | return false; |
| 128 | _module = NULL; | 138 | _module = NULL; |
| 129 | return true; | 139 | return true; |
| 130 | } | 140 | } |
| 131 | 141 | ||
| 132 | static | ||
| 133 | // FARPROC | ||
| 134 | void * | ||
| 135 | local_GetProcAddress(HMODULE module, LPCSTR procName) | ||
| 136 | { | ||
| 137 | void *ptr = NULL; | ||
| 138 | if (module) | ||
| 139 | { | ||
| 140 | ptr = dlsym(module, procName); | ||
| 141 | } | ||
| 142 | return ptr; | ||
| 143 | } | ||
| 144 | |||
| 145 | bool CLibrary::Load(CFSTR path) throw() | 142 | bool CLibrary::Load(CFSTR path) throw() |
| 146 | { | 143 | { |
| 147 | if (!Free()) | 144 | if (!Free()) |
| @@ -163,21 +160,11 @@ bool CLibrary::Load(CFSTR path) throw() | |||
| 163 | #endif | 160 | #endif |
| 164 | #endif | 161 | #endif |
| 165 | 162 | ||
| 166 | void *handler = dlopen(path, options); | 163 | _module = dlopen(path, options); |
| 167 | |||
| 168 | if (handler) | ||
| 169 | { | ||
| 170 | // here we can transfer some settings to DLL | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | } | ||
| 175 | |||
| 176 | _module = handler; | ||
| 177 | |||
| 178 | return (_module != NULL); | 164 | return (_module != NULL); |
| 179 | } | 165 | } |
| 180 | 166 | ||
| 167 | /* | ||
| 181 | // FARPROC | 168 | // FARPROC |
| 182 | void * CLibrary::GetProc(LPCSTR procName) const | 169 | void * CLibrary::GetProc(LPCSTR procName) const |
| 183 | { | 170 | { |
| @@ -185,6 +172,7 @@ void * CLibrary::GetProc(LPCSTR procName) const | |||
| 185 | return local_GetProcAddress(_module, procName); | 172 | return local_GetProcAddress(_module, procName); |
| 186 | // return NULL; | 173 | // return NULL; |
| 187 | } | 174 | } |
| 175 | */ | ||
| 188 | 176 | ||
| 189 | }} | 177 | }} |
| 190 | 178 | ||
diff --git a/CPP/Windows/DLL.h b/CPP/Windows/DLL.h index 0c093ee..19a82b3 100644 --- a/CPP/Windows/DLL.h +++ b/CPP/Windows/DLL.h | |||
| @@ -1,20 +1,29 @@ | |||
| 1 | // Windows/DLL.h | 1 | // Windows/DLL.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_DLL_H | 3 | #ifndef ZIP7_INC_WINDOWS_DLL_H |
| 4 | #define __WINDOWS_DLL_H | 4 | #define ZIP7_INC_WINDOWS_DLL_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| 8 | #ifndef _WIN32 | ||
| 9 | typedef void * HMODULE; | ||
| 10 | // typedef int (*FARPROC)(); | ||
| 11 | // typedef void *FARPROC; | ||
| 12 | void *GetProcAddress(HMODULE module, LPCSTR procName); | ||
| 13 | #endif | ||
| 14 | |||
| 8 | namespace NWindows { | 15 | namespace NWindows { |
| 9 | namespace NDLL { | 16 | namespace NDLL { |
| 10 | 17 | ||
| 11 | #ifdef _WIN32 | 18 | #ifdef _WIN32 |
| 12 | 19 | ||
| 20 | /* | ||
| 13 | #ifdef UNDER_CE | 21 | #ifdef UNDER_CE |
| 14 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName) | 22 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddressA(module, procName) |
| 15 | #else | 23 | #else |
| 16 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName) | 24 | #define My_GetProcAddress(module, procName) (void *)::GetProcAddress(module, procName) |
| 17 | #endif | 25 | #endif |
| 26 | */ | ||
| 18 | 27 | ||
| 19 | /* Win32: Don't call CLibrary::Free() and FreeLibrary() from another | 28 | /* Win32: Don't call CLibrary::Free() and FreeLibrary() from another |
| 20 | FreeLibrary() code: detaching code in DLL entry-point or in | 29 | FreeLibrary() code: detaching code in DLL entry-point or in |
| @@ -24,13 +33,25 @@ class CLibrary | |||
| 24 | { | 33 | { |
| 25 | HMODULE _module; | 34 | HMODULE _module; |
| 26 | 35 | ||
| 27 | // CLASS_NO_COPY(CLibrary); | 36 | // Z7_CLASS_NO_COPY(CLibrary); |
| 37 | // copy constructor is required here | ||
| 28 | public: | 38 | public: |
| 29 | CLibrary(): _module(NULL) {}; | 39 | CLibrary(): _module(NULL) {} |
| 30 | ~CLibrary() { Free(); } | 40 | ~CLibrary() { Free(); } |
| 31 | 41 | ||
| 32 | operator HMODULE() const { return _module; } | 42 | CLibrary(const CLibrary &c): _module(NULL) |
| 33 | HMODULE* operator&() { return &_module; } | 43 | { |
| 44 | if (c._module) | ||
| 45 | { | ||
| 46 | // we need non const to reference from original item | ||
| 47 | // c._module = NULL; | ||
| 48 | throw 20230102; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | HMODULE Get_HMODULE() const { return _module; } | ||
| 53 | // operator HMODULE() const { return _module; } | ||
| 54 | // HMODULE* operator&() { return &_module; } | ||
| 34 | bool IsLoaded() const { return (_module != NULL); } | 55 | bool IsLoaded() const { return (_module != NULL); } |
| 35 | 56 | ||
| 36 | void Attach(HMODULE m) | 57 | void Attach(HMODULE m) |
| @@ -40,7 +61,7 @@ public: | |||
| 40 | } | 61 | } |
| 41 | HMODULE Detach() | 62 | HMODULE Detach() |
| 42 | { | 63 | { |
| 43 | HMODULE m = _module; | 64 | const HMODULE m = _module; |
| 44 | _module = NULL; | 65 | _module = NULL; |
| 45 | return m; | 66 | return m; |
| 46 | } | 67 | } |
| @@ -49,28 +70,26 @@ public: | |||
| 49 | bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw(); | 70 | bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw(); |
| 50 | bool Load(CFSTR path) throw(); | 71 | bool Load(CFSTR path) throw(); |
| 51 | // FARPROC | 72 | // FARPROC |
| 52 | void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); } | 73 | // void *GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); } |
| 53 | }; | 74 | }; |
| 54 | 75 | ||
| 55 | #else | 76 | #else |
| 56 | 77 | ||
| 57 | typedef void * HMODULE; | ||
| 58 | // typedef int (*FARPROC)(); | ||
| 59 | // typedef void *FARPROC; | ||
| 60 | |||
| 61 | class CLibrary | 78 | class CLibrary |
| 62 | { | 79 | { |
| 63 | HMODULE _module; | 80 | HMODULE _module; |
| 64 | 81 | ||
| 65 | // CLASS_NO_COPY(CLibrary); | 82 | // Z7_CLASS_NO_COPY(CLibrary); |
| 66 | public: | 83 | public: |
| 67 | CLibrary(): _module(NULL) {}; | 84 | CLibrary(): _module(NULL) {} |
| 68 | ~CLibrary() { Free(); } | 85 | ~CLibrary() { Free(); } |
| 69 | 86 | ||
| 87 | HMODULE Get_HMODULE() const { return _module; } | ||
| 88 | |||
| 70 | bool Free() throw(); | 89 | bool Free() throw(); |
| 71 | bool Load(CFSTR path) throw(); | 90 | bool Load(CFSTR path) throw(); |
| 72 | // FARPROC | 91 | // FARPROC |
| 73 | void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); } | 92 | // void *GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); } |
| 74 | }; | 93 | }; |
| 75 | 94 | ||
| 76 | #endif | 95 | #endif |
diff --git a/CPP/Windows/Defs.h b/CPP/Windows/Defs.h index 1d96078..8ab9cf5 100644 --- a/CPP/Windows/Defs.h +++ b/CPP/Windows/Defs.h | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | // Windows/Defs.h | 1 | // Windows/Defs.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_DEFS_H | 3 | #ifndef ZIP7_INC_WINDOWS_DEFS_H |
| 4 | #define __WINDOWS_DEFS_H | 4 | #define ZIP7_INC_WINDOWS_DEFS_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | 7 | ||
| 8 | #ifdef _WIN32 | 8 | #ifdef _WIN32 |
| 9 | inline bool LRESULTToBool(LRESULT v) { return (v != FALSE); } | ||
| 10 | inline BOOL BoolToBOOL(bool v) { return (v ? TRUE: FALSE); } | 9 | inline BOOL BoolToBOOL(bool v) { return (v ? TRUE: FALSE); } |
| 11 | #endif | 10 | #endif |
| 12 | 11 | ||
diff --git a/CPP/Windows/ErrorMsg.cpp b/CPP/Windows/ErrorMsg.cpp index f6343a5..5acf3ad 100644 --- a/CPP/Windows/ErrorMsg.cpp +++ b/CPP/Windows/ErrorMsg.cpp | |||
| @@ -19,8 +19,8 @@ namespace NError { | |||
| 19 | 19 | ||
| 20 | static bool MyFormatMessage(DWORD errorCode, UString &message) | 20 | static bool MyFormatMessage(DWORD errorCode, UString &message) |
| 21 | { | 21 | { |
| 22 | #ifndef _SFX | 22 | #ifndef Z7_SFX |
| 23 | if ((HRESULT)errorCode == MY_HRES_ERROR__INTERNAL_ERROR) | 23 | if ((HRESULT)errorCode == MY_HRES_ERROR_INTERNAL_ERROR) |
| 24 | { | 24 | { |
| 25 | message = "Internal Error: The failure in hardware (RAM or CPU), OS or program"; | 25 | message = "Internal Error: The failure in hardware (RAM or CPU), OS or program"; |
| 26 | return true; | 26 | return true; |
| @@ -72,7 +72,7 @@ static bool MyFormatMessage(DWORD errorCode, UString &message) | |||
| 72 | case E_OUTOFMEMORY : s = "E_OUTOFMEMORY : Can't allocate required memory"; break; | 72 | case E_OUTOFMEMORY : s = "E_OUTOFMEMORY : Can't allocate required memory"; break; |
| 73 | case E_INVALIDARG : s = "E_INVALIDARG : One or more arguments are invalid"; break; | 73 | case E_INVALIDARG : s = "E_INVALIDARG : One or more arguments are invalid"; break; |
| 74 | 74 | ||
| 75 | // case MY__E_ERROR_NEGATIVE_SEEK : s = "MY__E_ERROR_NEGATIVE_SEEK"; break; | 75 | // case MY_E_ERROR_NEGATIVE_SEEK : s = "MY_E_ERROR_NEGATIVE_SEEK"; break; |
| 76 | default: | 76 | default: |
| 77 | break; | 77 | break; |
| 78 | } | 78 | } |
| @@ -81,7 +81,7 @@ static bool MyFormatMessage(DWORD errorCode, UString &message) | |||
| 81 | So we must transfer error codes before strerror() */ | 81 | So we must transfer error codes before strerror() */ |
| 82 | if (!s) | 82 | if (!s) |
| 83 | { | 83 | { |
| 84 | if ((errorCode & 0xFFFF0000) == (UInt32)((MY__FACILITY__WRes << 16) | 0x80000000)) | 84 | if ((errorCode & 0xFFFF0000) == (UInt32)((MY_FACILITY_WRes << 16) | 0x80000000)) |
| 85 | errorCode &= 0xFFFF; | 85 | errorCode &= 0xFFFF; |
| 86 | else if ((errorCode & ((UInt32)1 << 31))) | 86 | else if ((errorCode & ((UInt32)1 << 31))) |
| 87 | return false; // we will show hex error later for that case | 87 | return false; // we will show hex error later for that case |
diff --git a/CPP/Windows/ErrorMsg.h b/CPP/Windows/ErrorMsg.h index 01204eb..6142b4e 100644 --- a/CPP/Windows/ErrorMsg.h +++ b/CPP/Windows/ErrorMsg.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/ErrorMsg.h | 1 | // Windows/ErrorMsg.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_ERROR_MSG_H | 3 | #ifndef ZIP7_INC_WINDOWS_ERROR_MSG_H |
| 4 | #define __WINDOWS_ERROR_MSG_H | 4 | #define ZIP7_INC_WINDOWS_ERROR_MSG_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp index cce2638..5b1f340 100644 --- a/CPP/Windows/FileDir.cpp +++ b/CPP/Windows/FileDir.cpp | |||
| @@ -65,46 +65,55 @@ namespace NDir { | |||
| 65 | 65 | ||
| 66 | bool GetWindowsDir(FString &path) | 66 | bool GetWindowsDir(FString &path) |
| 67 | { | 67 | { |
| 68 | UINT needLength; | 68 | const unsigned kBufSize = MAX_PATH + 16; |
| 69 | UINT len; | ||
| 69 | #ifndef _UNICODE | 70 | #ifndef _UNICODE |
| 70 | if (!g_IsNT) | 71 | if (!g_IsNT) |
| 71 | { | 72 | { |
| 72 | TCHAR s[MAX_PATH + 2]; | 73 | TCHAR s[kBufSize + 1]; |
| 73 | s[0] = 0; | 74 | s[0] = 0; |
| 74 | needLength = ::GetWindowsDirectory(s, MAX_PATH + 1); | 75 | len = ::GetWindowsDirectory(s, kBufSize); |
| 75 | path = fas2fs(s); | 76 | path = fas2fs(s); |
| 76 | } | 77 | } |
| 77 | else | 78 | else |
| 78 | #endif | 79 | #endif |
| 79 | { | 80 | { |
| 80 | WCHAR s[MAX_PATH + 2]; | 81 | WCHAR s[kBufSize + 1]; |
| 81 | s[0] = 0; | 82 | s[0] = 0; |
| 82 | needLength = ::GetWindowsDirectoryW(s, MAX_PATH + 1); | 83 | len = ::GetWindowsDirectoryW(s, kBufSize); |
| 83 | path = us2fs(s); | 84 | path = us2fs(s); |
| 84 | } | 85 | } |
| 85 | return (needLength > 0 && needLength <= MAX_PATH); | 86 | return (len != 0 && len < kBufSize); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 89 | |||
| 90 | /* | ||
| 91 | new DOCs for GetSystemDirectory: | ||
| 92 | returned path does not end with a backslash unless the | ||
| 93 | system directory is the root directory. | ||
| 94 | */ | ||
| 95 | |||
| 88 | bool GetSystemDir(FString &path) | 96 | bool GetSystemDir(FString &path) |
| 89 | { | 97 | { |
| 90 | UINT needLength; | 98 | const unsigned kBufSize = MAX_PATH + 16; |
| 99 | UINT len; | ||
| 91 | #ifndef _UNICODE | 100 | #ifndef _UNICODE |
| 92 | if (!g_IsNT) | 101 | if (!g_IsNT) |
| 93 | { | 102 | { |
| 94 | TCHAR s[MAX_PATH + 2]; | 103 | TCHAR s[kBufSize + 1]; |
| 95 | s[0] = 0; | 104 | s[0] = 0; |
| 96 | needLength = ::GetSystemDirectory(s, MAX_PATH + 1); | 105 | len = ::GetSystemDirectory(s, kBufSize); |
| 97 | path = fas2fs(s); | 106 | path = fas2fs(s); |
| 98 | } | 107 | } |
| 99 | else | 108 | else |
| 100 | #endif | 109 | #endif |
| 101 | { | 110 | { |
| 102 | WCHAR s[MAX_PATH + 2]; | 111 | WCHAR s[kBufSize + 1]; |
| 103 | s[0] = 0; | 112 | s[0] = 0; |
| 104 | needLength = ::GetSystemDirectoryW(s, MAX_PATH + 1); | 113 | len = ::GetSystemDirectoryW(s, kBufSize); |
| 105 | path = us2fs(s); | 114 | path = us2fs(s); |
| 106 | } | 115 | } |
| 107 | return (needLength > 0 && needLength <= MAX_PATH); | 116 | return (len != 0 && len < kBufSize); |
| 108 | } | 117 | } |
| 109 | #endif // UNDER_CE | 118 | #endif // UNDER_CE |
| 110 | 119 | ||
| @@ -123,7 +132,7 @@ bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CF | |||
| 123 | IF_USE_MAIN_PATH | 132 | IF_USE_MAIN_PATH |
| 124 | hDir = ::CreateFileW(fs2us(path), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, | 133 | hDir = ::CreateFileW(fs2us(path), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 125 | NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 134 | NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
| 126 | #ifdef WIN_LONG_PATH | 135 | #ifdef Z7_LONG_PATH |
| 127 | if (hDir == INVALID_HANDLE_VALUE && USE_SUPER_PATH) | 136 | if (hDir == INVALID_HANDLE_VALUE && USE_SUPER_PATH) |
| 128 | { | 137 | { |
| 129 | UString superPath; | 138 | UString superPath; |
| @@ -158,7 +167,7 @@ bool SetFileAttrib(CFSTR path, DWORD attrib) | |||
| 158 | IF_USE_MAIN_PATH | 167 | IF_USE_MAIN_PATH |
| 159 | if (::SetFileAttributesW(fs2us(path), attrib)) | 168 | if (::SetFileAttributesW(fs2us(path), attrib)) |
| 160 | return true; | 169 | return true; |
| 161 | #ifdef WIN_LONG_PATH | 170 | #ifdef Z7_LONG_PATH |
| 162 | if (USE_SUPER_PATH) | 171 | if (USE_SUPER_PATH) |
| 163 | { | 172 | { |
| 164 | UString superPath; | 173 | UString superPath; |
| @@ -195,7 +204,7 @@ bool RemoveDir(CFSTR path) | |||
| 195 | IF_USE_MAIN_PATH | 204 | IF_USE_MAIN_PATH |
| 196 | if (::RemoveDirectoryW(fs2us(path))) | 205 | if (::RemoveDirectoryW(fs2us(path))) |
| 197 | return true; | 206 | return true; |
| 198 | #ifdef WIN_LONG_PATH | 207 | #ifdef Z7_LONG_PATH |
| 199 | if (USE_SUPER_PATH) | 208 | if (USE_SUPER_PATH) |
| 200 | { | 209 | { |
| 201 | UString superPath; | 210 | UString superPath; |
| @@ -224,7 +233,7 @@ bool MyMoveFile(CFSTR oldFile, CFSTR newFile) | |||
| 224 | if (::MoveFileW(fs2us(oldFile), fs2us(newFile))) | 233 | if (::MoveFileW(fs2us(oldFile), fs2us(newFile))) |
| 225 | return true; | 234 | return true; |
| 226 | } | 235 | } |
| 227 | #ifdef WIN_LONG_PATH | 236 | #ifdef Z7_LONG_PATH |
| 228 | if (USE_SUPER_PATH_2) | 237 | if (USE_SUPER_PATH_2) |
| 229 | { | 238 | { |
| 230 | UString d1, d2; | 239 | UString d1, d2; |
| @@ -261,8 +270,11 @@ bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName) | |||
| 261 | else | 270 | else |
| 262 | #endif | 271 | #endif |
| 263 | { | 272 | { |
| 264 | Func_CreateHardLinkW my_CreateHardLinkW = (Func_CreateHardLinkW) | 273 | const |
| 265 | (void *)::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "CreateHardLinkW"); | 274 | Func_CreateHardLinkW |
| 275 | my_CreateHardLinkW = Z7_GET_PROC_ADDRESS( | ||
| 276 | Func_CreateHardLinkW, ::GetModuleHandleW(L"kernel32.dll"), | ||
| 277 | "CreateHardLinkW"); | ||
| 266 | if (!my_CreateHardLinkW) | 278 | if (!my_CreateHardLinkW) |
| 267 | return false; | 279 | return false; |
| 268 | IF_USE_MAIN_PATH_2(newFileName, existFileName) | 280 | IF_USE_MAIN_PATH_2(newFileName, existFileName) |
| @@ -270,7 +282,7 @@ bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName) | |||
| 270 | if (my_CreateHardLinkW(fs2us(newFileName), fs2us(existFileName), NULL)) | 282 | if (my_CreateHardLinkW(fs2us(newFileName), fs2us(existFileName), NULL)) |
| 271 | return true; | 283 | return true; |
| 272 | } | 284 | } |
| 273 | #ifdef WIN_LONG_PATH | 285 | #ifdef Z7_LONG_PATH |
| 274 | if (USE_SUPER_PATH_2) | 286 | if (USE_SUPER_PATH_2) |
| 275 | { | 287 | { |
| 276 | UString d1, d2; | 288 | UString d1, d2; |
| @@ -320,7 +332,7 @@ bool CreateDir(CFSTR path) | |||
| 320 | IF_USE_MAIN_PATH | 332 | IF_USE_MAIN_PATH |
| 321 | if (::CreateDirectoryW(fs2us(path), NULL)) | 333 | if (::CreateDirectoryW(fs2us(path), NULL)) |
| 322 | return true; | 334 | return true; |
| 323 | #ifdef WIN_LONG_PATH | 335 | #ifdef Z7_LONG_PATH |
| 324 | if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH) | 336 | if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH) |
| 325 | { | 337 | { |
| 326 | UString superPath; | 338 | UString superPath; |
| @@ -355,7 +367,7 @@ static bool CreateDir2(CFSTR path) | |||
| 355 | IF_USE_MAIN_PATH | 367 | IF_USE_MAIN_PATH |
| 356 | if (::CreateDirectoryW(fs2us(path), NULL)) | 368 | if (::CreateDirectoryW(fs2us(path), NULL)) |
| 357 | return true; | 369 | return true; |
| 358 | #ifdef WIN_LONG_PATH | 370 | #ifdef Z7_LONG_PATH |
| 359 | if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH) | 371 | if ((!USE_MAIN_PATH || ::GetLastError() != ERROR_ALREADY_EXISTS) && USE_SUPER_PATH) |
| 360 | { | 372 | { |
| 361 | UString superPath; | 373 | UString superPath; |
| @@ -390,7 +402,7 @@ bool CreateComplexDir(CFSTR _path) | |||
| 390 | #ifdef _WIN32 | 402 | #ifdef _WIN32 |
| 391 | 403 | ||
| 392 | { | 404 | { |
| 393 | DWORD attrib = NFind::GetFileAttrib(_path); | 405 | const DWORD attrib = NFind::GetFileAttrib(_path); |
| 394 | if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0) | 406 | if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0) |
| 395 | return true; | 407 | return true; |
| 396 | } | 408 | } |
| @@ -496,7 +508,7 @@ bool DeleteFileAlways(CFSTR path) | |||
| 496 | IF_USE_MAIN_PATH | 508 | IF_USE_MAIN_PATH |
| 497 | if (::DeleteFileW(fs2us(path))) | 509 | if (::DeleteFileW(fs2us(path))) |
| 498 | return true; | 510 | return true; |
| 499 | #ifdef WIN_LONG_PATH | 511 | #ifdef Z7_LONG_PATH |
| 500 | if (USE_SUPER_PATH) | 512 | if (USE_SUPER_PATH) |
| 501 | { | 513 | { |
| 502 | UString superPath; | 514 | UString superPath; |
| @@ -586,9 +598,12 @@ bool MyGetFullPathName(CFSTR path, FString &resFullPath) | |||
| 586 | 598 | ||
| 587 | #ifdef _WIN32 | 599 | #ifdef _WIN32 |
| 588 | 600 | ||
| 601 | /* Win10: SetCurrentDirectory() doesn't support long paths and | ||
| 602 | doesn't support super prefix "\\?\", if long path behavior is not | ||
| 603 | enabled in registry (LongPathsEnabled) and in manifest (longPathAware). */ | ||
| 604 | |||
| 589 | bool SetCurrentDir(CFSTR path) | 605 | bool SetCurrentDir(CFSTR path) |
| 590 | { | 606 | { |
| 591 | // SetCurrentDirectory doesn't support \\?\ prefix | ||
| 592 | #ifndef _UNICODE | 607 | #ifndef _UNICODE |
| 593 | if (!g_IsNT) | 608 | if (!g_IsNT) |
| 594 | { | 609 | { |
| @@ -602,28 +617,74 @@ bool SetCurrentDir(CFSTR path) | |||
| 602 | } | 617 | } |
| 603 | 618 | ||
| 604 | 619 | ||
| 620 | /* | ||
| 621 | we use system function GetCurrentDirectory() | ||
| 622 | new GetCurrentDirectory() DOCs: | ||
| 623 | - If the function fails, the return value is zero. | ||
| 624 | - If the function succeeds, the return value specifies | ||
| 625 | the number of characters that are written to the buffer, | ||
| 626 | not including the terminating null character. | ||
| 627 | - If the buffer is not large enough, the return value specifies | ||
| 628 | the required size of the buffer, in characters, | ||
| 629 | including the null-terminating character. | ||
| 630 | |||
| 631 | GetCurrentDir() calls GetCurrentDirectory(). | ||
| 632 | GetCurrentDirectory() in win10 in tests: | ||
| 633 | the returned (path) does not end with a backslash, if | ||
| 634 | current directory is not root directory of drive. | ||
| 635 | But that behavior is not guarantied in specification docs. | ||
| 636 | */ | ||
| 637 | |||
| 605 | bool GetCurrentDir(FString &path) | 638 | bool GetCurrentDir(FString &path) |
| 606 | { | 639 | { |
| 640 | const unsigned kBufSize = MAX_PATH + 16; | ||
| 607 | path.Empty(); | 641 | path.Empty(); |
| 608 | 642 | ||
| 609 | DWORD needLength; | ||
| 610 | #ifndef _UNICODE | 643 | #ifndef _UNICODE |
| 611 | if (!g_IsNT) | 644 | if (!g_IsNT) |
| 612 | { | 645 | { |
| 613 | TCHAR s[MAX_PATH + 2]; | 646 | TCHAR s[kBufSize + 1]; |
| 614 | s[0] = 0; | 647 | s[0] = 0; |
| 615 | needLength = ::GetCurrentDirectory(MAX_PATH + 1, s); | 648 | const DWORD len = ::GetCurrentDirectory(kBufSize, s); |
| 649 | if (len == 0 || len >= kBufSize) | ||
| 650 | return false; | ||
| 651 | s[kBufSize] = 0; // optional guard | ||
| 616 | path = fas2fs(s); | 652 | path = fas2fs(s); |
| 653 | return true; | ||
| 617 | } | 654 | } |
| 618 | else | 655 | else |
| 619 | #endif | 656 | #endif |
| 620 | { | 657 | { |
| 621 | WCHAR s[MAX_PATH + 2]; | 658 | DWORD len; |
| 622 | s[0] = 0; | 659 | { |
| 623 | needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, s); | 660 | WCHAR s[kBufSize + 1]; |
| 624 | path = us2fs(s); | 661 | s[0] = 0; |
| 662 | len = ::GetCurrentDirectoryW(kBufSize, s); | ||
| 663 | if (len == 0) | ||
| 664 | return false; | ||
| 665 | if (len < kBufSize) | ||
| 666 | { | ||
| 667 | s[kBufSize] = 0; // optional guard | ||
| 668 | path = us2fs(s); | ||
| 669 | return true; | ||
| 670 | } | ||
| 671 | } | ||
| 672 | UString temp; | ||
| 673 | const DWORD len2 = ::GetCurrentDirectoryW(len, temp.GetBuf(len)); | ||
| 674 | if (len2 == 0) | ||
| 675 | return false; | ||
| 676 | temp.ReleaseBuf_CalcLen(len); | ||
| 677 | if (temp.Len() != len2 || len - 1 != len2) | ||
| 678 | { | ||
| 679 | /* it's unexpected case, if current dir of process | ||
| 680 | was changed between two function calls, | ||
| 681 | or some unexpected function implementation */ | ||
| 682 | // SetLastError((DWORD)E_FAIL); // we can set some error code | ||
| 683 | return false; | ||
| 684 | } | ||
| 685 | path = us2fs(temp); | ||
| 686 | return true; | ||
| 625 | } | 687 | } |
| 626 | return (needLength > 0 && needLength <= MAX_PATH); | ||
| 627 | } | 688 | } |
| 628 | 689 | ||
| 629 | #endif // _WIN32 | 690 | #endif // _WIN32 |
| @@ -648,41 +709,59 @@ bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix) | |||
| 648 | return GetFullPathAndSplit(path, resDirPrefix, resFileName); | 709 | return GetFullPathAndSplit(path, resDirPrefix, resFileName); |
| 649 | } | 710 | } |
| 650 | 711 | ||
| 712 | |||
| 713 | |||
| 651 | bool MyGetTempPath(FString &path) | 714 | bool MyGetTempPath(FString &path) |
| 652 | { | 715 | { |
| 653 | #ifdef _WIN32 | 716 | #ifdef _WIN32 |
| 654 | path.Empty(); | 717 | |
| 655 | DWORD needLength; | 718 | /* |
| 719 | new DOCs for GetTempPathW(): | ||
| 720 | - The returned string ends with a backslash. | ||
| 721 | - The maximum possible return value is MAX_PATH+1 (261). | ||
| 722 | */ | ||
| 723 | |||
| 724 | const unsigned kBufSize = MAX_PATH + 16; | ||
| 725 | DWORD len; | ||
| 656 | #ifndef _UNICODE | 726 | #ifndef _UNICODE |
| 657 | if (!g_IsNT) | 727 | if (!g_IsNT) |
| 658 | { | 728 | { |
| 659 | TCHAR s[MAX_PATH + 2]; | 729 | TCHAR s[kBufSize + 1]; |
| 660 | s[0] = 0; | 730 | s[0] = 0; |
| 661 | needLength = ::GetTempPath(MAX_PATH + 1, s); | 731 | len = ::GetTempPath(kBufSize, s); |
| 662 | path = fas2fs(s); | 732 | path = fas2fs(s); |
| 663 | } | 733 | } |
| 664 | else | 734 | else |
| 665 | #endif | 735 | #endif |
| 666 | { | 736 | { |
| 667 | WCHAR s[MAX_PATH + 2]; | 737 | WCHAR s[kBufSize + 1]; |
| 668 | s[0] = 0; | 738 | s[0] = 0; |
| 669 | needLength = ::GetTempPathW(MAX_PATH + 1, s);; | 739 | len = ::GetTempPathW(kBufSize, s); |
| 670 | path = us2fs(s); | 740 | path = us2fs(s); |
| 671 | } | 741 | } |
| 672 | return (needLength > 0 && needLength <= MAX_PATH); | 742 | /* win10: GetTempPathW() doesn't set backslash at the end of path, |
| 743 | if (buffer_size == len_of(path_with_backslash)). | ||
| 744 | So we normalize path here: */ | ||
| 745 | NormalizeDirPathPrefix(path); | ||
| 746 | return (len != 0 && len < kBufSize); | ||
| 673 | 747 | ||
| 674 | #else | 748 | #else // !_WIN32 |
| 675 | 749 | ||
| 676 | // FIXME: improve that code | 750 | // FIXME: improve that code |
| 677 | path = "/tmp/"; | 751 | path = STRING_PATH_SEPARATOR "tmp"; |
| 678 | if (!NFind::DoesDirExist_FollowLink(path)) | 752 | const char *s; |
| 679 | path = "./"; | 753 | if (NFind::DoesDirExist_FollowLink(path)) |
| 754 | s = STRING_PATH_SEPARATOR "tmp" STRING_PATH_SEPARATOR; | ||
| 755 | else | ||
| 756 | s = "." STRING_PATH_SEPARATOR; | ||
| 757 | path = s; | ||
| 680 | return true; | 758 | return true; |
| 759 | |||
| 681 | #endif | 760 | #endif |
| 682 | } | 761 | } |
| 683 | 762 | ||
| 684 | 763 | ||
| 685 | static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile) | 764 | bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile) |
| 686 | { | 765 | { |
| 687 | UInt32 d = | 766 | UInt32 d = |
| 688 | #ifdef _WIN32 | 767 | #ifdef _WIN32 |
| @@ -693,7 +772,7 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu | |||
| 693 | 772 | ||
| 694 | for (unsigned i = 0; i < 100; i++) | 773 | for (unsigned i = 0; i < 100; i++) |
| 695 | { | 774 | { |
| 696 | path = prefix; | 775 | postfix.Empty(); |
| 697 | if (addRandom) | 776 | if (addRandom) |
| 698 | { | 777 | { |
| 699 | char s[16]; | 778 | char s[16]; |
| @@ -701,14 +780,14 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu | |||
| 701 | unsigned k; | 780 | unsigned k; |
| 702 | for (k = 0; k < 8; k++) | 781 | for (k = 0; k < 8; k++) |
| 703 | { | 782 | { |
| 704 | unsigned t = val & 0xF; | 783 | const unsigned t = val & 0xF; |
| 705 | val >>= 4; | 784 | val >>= 4; |
| 706 | s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); | 785 | s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); |
| 707 | } | 786 | } |
| 708 | s[k] = '\0'; | 787 | s[k] = '\0'; |
| 709 | if (outFile) | 788 | if (outFile) |
| 710 | path += '.'; | 789 | postfix.Add_Dot(); |
| 711 | path += s; | 790 | postfix += s; |
| 712 | UInt32 step = GetTickCount() + 2; | 791 | UInt32 step = GetTickCount() + 2; |
| 713 | if (step == 0) | 792 | if (step == 0) |
| 714 | step = 1; | 793 | step = 1; |
| @@ -716,7 +795,9 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu | |||
| 716 | } | 795 | } |
| 717 | addRandom = true; | 796 | addRandom = true; |
| 718 | if (outFile) | 797 | if (outFile) |
| 719 | path += ".tmp"; | 798 | postfix += ".tmp"; |
| 799 | FString path (prefix); | ||
| 800 | path += postfix; | ||
| 720 | if (NFind::DoesFileOrDirExist(path)) | 801 | if (NFind::DoesFileOrDirExist(path)) |
| 721 | { | 802 | { |
| 722 | SetLastError(ERROR_ALREADY_EXISTS); | 803 | SetLastError(ERROR_ALREADY_EXISTS); |
| @@ -732,12 +813,12 @@ static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COu | |||
| 732 | if (CreateDir(path)) | 813 | if (CreateDir(path)) |
| 733 | return true; | 814 | return true; |
| 734 | } | 815 | } |
| 735 | DWORD error = GetLastError(); | 816 | const DWORD error = GetLastError(); |
| 736 | if (error != ERROR_FILE_EXISTS && | 817 | if (error != ERROR_FILE_EXISTS && |
| 737 | error != ERROR_ALREADY_EXISTS) | 818 | error != ERROR_ALREADY_EXISTS) |
| 738 | break; | 819 | break; |
| 739 | } | 820 | } |
| 740 | path.Empty(); | 821 | postfix.Empty(); |
| 741 | return false; | 822 | return false; |
| 742 | } | 823 | } |
| 743 | 824 | ||
| @@ -745,8 +826,12 @@ bool CTempFile::Create(CFSTR prefix, NIO::COutFile *outFile) | |||
| 745 | { | 826 | { |
| 746 | if (!Remove()) | 827 | if (!Remove()) |
| 747 | return false; | 828 | return false; |
| 748 | if (!CreateTempFile(prefix, false, _path, outFile)) | 829 | _path.Empty(); |
| 830 | AString postfix; | ||
| 831 | if (!CreateTempFile2(prefix, false, postfix, outFile)) | ||
| 749 | return false; | 832 | return false; |
| 833 | _path = prefix; | ||
| 834 | _path += postfix; | ||
| 750 | _mustBeDeleted = true; | 835 | _mustBeDeleted = true; |
| 751 | return true; | 836 | return true; |
| 752 | } | 837 | } |
| @@ -755,11 +840,16 @@ bool CTempFile::CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFil | |||
| 755 | { | 840 | { |
| 756 | if (!Remove()) | 841 | if (!Remove()) |
| 757 | return false; | 842 | return false; |
| 843 | _path.Empty(); | ||
| 758 | FString tempPath; | 844 | FString tempPath; |
| 759 | if (!MyGetTempPath(tempPath)) | 845 | if (!MyGetTempPath(tempPath)) |
| 760 | return false; | 846 | return false; |
| 761 | if (!CreateTempFile(tempPath + namePrefix, true, _path, outFile)) | 847 | AString postfix; |
| 848 | tempPath += namePrefix; | ||
| 849 | if (!CreateTempFile2(tempPath, true, postfix, outFile)) | ||
| 762 | return false; | 850 | return false; |
| 851 | _path = tempPath; | ||
| 852 | _path += postfix; | ||
| 763 | _mustBeDeleted = true; | 853 | _mustBeDeleted = true; |
| 764 | return true; | 854 | return true; |
| 765 | } | 855 | } |
| @@ -802,11 +892,16 @@ bool CTempDir::Create(CFSTR prefix) | |||
| 802 | { | 892 | { |
| 803 | if (!Remove()) | 893 | if (!Remove()) |
| 804 | return false; | 894 | return false; |
| 895 | _path.Empty(); | ||
| 805 | FString tempPath; | 896 | FString tempPath; |
| 806 | if (!MyGetTempPath(tempPath)) | 897 | if (!MyGetTempPath(tempPath)) |
| 807 | return false; | 898 | return false; |
| 808 | if (!CreateTempFile(tempPath + prefix, true, _path, NULL)) | 899 | tempPath += prefix; |
| 900 | AString postfix; | ||
| 901 | if (!CreateTempFile2(tempPath, true, postfix, NULL)) | ||
| 809 | return false; | 902 | return false; |
| 903 | _path = tempPath; | ||
| 904 | _path += postfix; | ||
| 810 | _mustBeDeleted = true; | 905 | _mustBeDeleted = true; |
| 811 | return true; | 906 | return true; |
| 812 | } | 907 | } |
| @@ -830,7 +925,7 @@ bool RemoveDir(CFSTR path) | |||
| 830 | } | 925 | } |
| 831 | 926 | ||
| 832 | 927 | ||
| 833 | static BOOL My__CopyFile(CFSTR oldFile, CFSTR newFile) | 928 | static BOOL My_CopyFile(CFSTR oldFile, CFSTR newFile) |
| 834 | { | 929 | { |
| 835 | NWindows::NFile::NIO::COutFile outFile; | 930 | NWindows::NFile::NIO::COutFile outFile; |
| 836 | if (!outFile.Create(newFile, false)) | 931 | if (!outFile.Create(newFile, false)) |
| @@ -865,7 +960,7 @@ bool MyMoveFile(CFSTR oldFile, CFSTR newFile) | |||
| 865 | if (errno != EXDEV) // (oldFile and newFile are not on the same mounted filesystem) | 960 | if (errno != EXDEV) // (oldFile and newFile are not on the same mounted filesystem) |
| 866 | return false; | 961 | return false; |
| 867 | 962 | ||
| 868 | if (My__CopyFile(oldFile, newFile) == FALSE) | 963 | if (My_CopyFile(oldFile, newFile) == FALSE) |
| 869 | return false; | 964 | return false; |
| 870 | 965 | ||
| 871 | struct stat info_file; | 966 | struct stat info_file; |
| @@ -906,11 +1001,11 @@ bool GetCurrentDir(FString &path) | |||
| 906 | { | 1001 | { |
| 907 | path.Empty(); | 1002 | path.Empty(); |
| 908 | 1003 | ||
| 909 | #define MY__PATH_MAX PATH_MAX | 1004 | #define MY_PATH_MAX PATH_MAX |
| 910 | // #define MY__PATH_MAX 1024 | 1005 | // #define MY_PATH_MAX 1024 |
| 911 | 1006 | ||
| 912 | char s[MY__PATH_MAX + 1]; | 1007 | char s[MY_PATH_MAX + 1]; |
| 913 | char *res = getcwd(s, MY__PATH_MAX); | 1008 | char *res = getcwd(s, MY_PATH_MAX); |
| 914 | if (res) | 1009 | if (res) |
| 915 | { | 1010 | { |
| 916 | path = fas2fs(s); | 1011 | path = fas2fs(s); |
| @@ -1035,10 +1130,10 @@ static C_umask g_umask; | |||
| 1035 | #define PRF(x) | 1130 | #define PRF(x) |
| 1036 | 1131 | ||
| 1037 | #define TRACE_SetFileAttrib(msg) \ | 1132 | #define TRACE_SetFileAttrib(msg) \ |
| 1038 | PRF(printf("\nSetFileAttrib(%s, %x) : %s\n", (const char *)path, attrib, msg)); | 1133 | PRF(printf("\nSetFileAttrib(%s, %x) : %s\n", (const char *)path, attrib, msg);) |
| 1039 | 1134 | ||
| 1040 | #define TRACE_chmod(s, mode) \ | 1135 | #define TRACE_chmod(s, mode) \ |
| 1041 | PRF(printf("\n chmod(%s, %o)\n", (const char *)path, (unsigned)(mode))); | 1136 | PRF(printf("\n chmod(%s, %o)\n", (const char *)path, (unsigned)(mode));) |
| 1042 | 1137 | ||
| 1043 | int my_chown(CFSTR path, uid_t owner, gid_t group) | 1138 | int my_chown(CFSTR path, uid_t owner, gid_t group) |
| 1044 | { | 1139 | { |
| @@ -1047,7 +1142,7 @@ int my_chown(CFSTR path, uid_t owner, gid_t group) | |||
| 1047 | 1142 | ||
| 1048 | bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | 1143 | bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) |
| 1049 | { | 1144 | { |
| 1050 | TRACE_SetFileAttrib(""); | 1145 | TRACE_SetFileAttrib("") |
| 1051 | 1146 | ||
| 1052 | struct stat st; | 1147 | struct stat st; |
| 1053 | 1148 | ||
| @@ -1056,7 +1151,7 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1056 | { | 1151 | { |
| 1057 | if (lstat(path, &st) != 0) | 1152 | if (lstat(path, &st) != 0) |
| 1058 | { | 1153 | { |
| 1059 | TRACE_SetFileAttrib("bad lstat()"); | 1154 | TRACE_SetFileAttrib("bad lstat()") |
| 1060 | return false; | 1155 | return false; |
| 1061 | } | 1156 | } |
| 1062 | // TRACE_chmod("lstat", st.st_mode); | 1157 | // TRACE_chmod("lstat", st.st_mode); |
| @@ -1065,14 +1160,14 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1065 | { | 1160 | { |
| 1066 | if (stat(path, &st) != 0) | 1161 | if (stat(path, &st) != 0) |
| 1067 | { | 1162 | { |
| 1068 | TRACE_SetFileAttrib("bad stat()"); | 1163 | TRACE_SetFileAttrib("bad stat()") |
| 1069 | return false; | 1164 | return false; |
| 1070 | } | 1165 | } |
| 1071 | } | 1166 | } |
| 1072 | 1167 | ||
| 1073 | if (attrib & FILE_ATTRIBUTE_UNIX_EXTENSION) | 1168 | if (attrib & FILE_ATTRIBUTE_UNIX_EXTENSION) |
| 1074 | { | 1169 | { |
| 1075 | TRACE_SetFileAttrib("attrib & FILE_ATTRIBUTE_UNIX_EXTENSION"); | 1170 | TRACE_SetFileAttrib("attrib & FILE_ATTRIBUTE_UNIX_EXTENSION") |
| 1076 | st.st_mode = attrib >> 16; | 1171 | st.st_mode = attrib >> 16; |
| 1077 | if (S_ISDIR(st.st_mode)) | 1172 | if (S_ISDIR(st.st_mode)) |
| 1078 | { | 1173 | { |
| @@ -1092,7 +1187,7 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1092 | } | 1187 | } |
| 1093 | else | 1188 | else |
| 1094 | { | 1189 | { |
| 1095 | TRACE_SetFileAttrib("Only Windows Attributes"); | 1190 | TRACE_SetFileAttrib("Only Windows Attributes") |
| 1096 | // Only Windows Attributes | 1191 | // Only Windows Attributes |
| 1097 | if (S_ISDIR(st.st_mode) | 1192 | if (S_ISDIR(st.st_mode) |
| 1098 | || (attrib & FILE_ATTRIBUTE_READONLY) == 0) | 1193 | || (attrib & FILE_ATTRIBUTE_READONLY) == 0) |
| @@ -1105,7 +1200,7 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1105 | if (S_ISLNK(st.st_mode)) | 1200 | if (S_ISLNK(st.st_mode)) |
| 1106 | { | 1201 | { |
| 1107 | printf("\nfchmodat()\n"); | 1202 | printf("\nfchmodat()\n"); |
| 1108 | TRACE_chmod(path, (st.st_mode) & g_umask.mask); | 1203 | TRACE_chmod(path, (st.st_mode) & g_umask.mask) |
| 1109 | // AT_SYMLINK_NOFOLLOW is not implemted still in Linux. | 1204 | // AT_SYMLINK_NOFOLLOW is not implemted still in Linux. |
| 1110 | res = fchmodat(AT_FDCWD, path, (st.st_mode) & g_umask.mask, | 1205 | res = fchmodat(AT_FDCWD, path, (st.st_mode) & g_umask.mask, |
| 1111 | S_ISLNK(st.st_mode) ? AT_SYMLINK_NOFOLLOW : 0); | 1206 | S_ISLNK(st.st_mode) ? AT_SYMLINK_NOFOLLOW : 0); |
| @@ -1113,7 +1208,7 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1113 | else | 1208 | else |
| 1114 | */ | 1209 | */ |
| 1115 | { | 1210 | { |
| 1116 | TRACE_chmod(path, (st.st_mode) & g_umask.mask); | 1211 | TRACE_chmod(path, (st.st_mode) & g_umask.mask) |
| 1117 | res = chmod(path, (st.st_mode) & g_umask.mask); | 1212 | res = chmod(path, (st.st_mode) & g_umask.mask); |
| 1118 | } | 1213 | } |
| 1119 | // TRACE_SetFileAttrib("End") | 1214 | // TRACE_SetFileAttrib("End") |
| @@ -1123,7 +1218,7 @@ bool SetFileAttrib_PosixHighDetect(CFSTR path, DWORD attrib) | |||
| 1123 | 1218 | ||
| 1124 | bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName) | 1219 | bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName) |
| 1125 | { | 1220 | { |
| 1126 | PRF(printf("\nhard link() %s -> %s\n", newFileName, existFileName)); | 1221 | PRF(printf("\nhard link() %s -> %s\n", newFileName, existFileName);) |
| 1127 | return (link(existFileName, newFileName) == 0); | 1222 | return (link(existFileName, newFileName) == 0); |
| 1128 | } | 1223 | } |
| 1129 | 1224 | ||
diff --git a/CPP/Windows/FileDir.h b/CPP/Windows/FileDir.h index 08281aa..573ffa2 100644 --- a/CPP/Windows/FileDir.h +++ b/CPP/Windows/FileDir.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/FileDir.h | 1 | // Windows/FileDir.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILE_DIR_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_DIR_H |
| 4 | #define __WINDOWS_FILE_DIR_H | 4 | #define ZIP7_INC_WINDOWS_FILE_DIR_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| @@ -73,6 +73,8 @@ bool GetCurrentDir(FString &resultPath); | |||
| 73 | 73 | ||
| 74 | bool MyGetTempPath(FString &resultPath); | 74 | bool MyGetTempPath(FString &resultPath); |
| 75 | 75 | ||
| 76 | bool CreateTempFile2(CFSTR prefix, bool addRandom, AString &postfix, NIO::COutFile *outFile); | ||
| 77 | |||
| 76 | class CTempFile MY_UNCOPYABLE | 78 | class CTempFile MY_UNCOPYABLE |
| 77 | { | 79 | { |
| 78 | bool _mustBeDeleted; | 80 | bool _mustBeDeleted; |
diff --git a/CPP/Windows/FileFind.cpp b/CPP/Windows/FileFind.cpp index c655759..c562a90 100644 --- a/CPP/Windows/FileFind.cpp +++ b/CPP/Windows/FileFind.cpp | |||
| @@ -39,10 +39,10 @@ typedef struct | |||
| 39 | WCHAR cStreamName[MAX_PATH + 36]; | 39 | WCHAR cStreamName[MAX_PATH + 36]; |
| 40 | } MY_WIN32_FIND_STREAM_DATA, *MY_PWIN32_FIND_STREAM_DATA; | 40 | } MY_WIN32_FIND_STREAM_DATA, *MY_PWIN32_FIND_STREAM_DATA; |
| 41 | 41 | ||
| 42 | typedef HANDLE (WINAPI *FindFirstStreamW_Ptr)(LPCWSTR fileName, MY_STREAM_INFO_LEVELS infoLevel, | 42 | typedef HANDLE (WINAPI *Func_FindFirstStreamW)(LPCWSTR fileName, MY_STREAM_INFO_LEVELS infoLevel, |
| 43 | LPVOID findStreamData, DWORD flags); | 43 | LPVOID findStreamData, DWORD flags); |
| 44 | 44 | ||
| 45 | typedef BOOL (APIENTRY *FindNextStreamW_Ptr)(HANDLE findStream, LPVOID findStreamData); | 45 | typedef BOOL (APIENTRY *Func_FindNextStreamW)(HANDLE findStream, LPVOID findStreamData); |
| 46 | 46 | ||
| 47 | EXTERN_C_END | 47 | EXTERN_C_END |
| 48 | 48 | ||
| @@ -54,7 +54,7 @@ namespace NFile { | |||
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | #ifdef _WIN32 | 56 | #ifdef _WIN32 |
| 57 | #ifdef SUPPORT_DEVICE_FILE | 57 | #ifdef Z7_DEVICE_FILE |
| 58 | namespace NSystem | 58 | namespace NSystem |
| 59 | { | 59 | { |
| 60 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize); | 60 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize); |
| @@ -128,7 +128,7 @@ bool CFileInfo::IsDots() const throw() | |||
| 128 | 128 | ||
| 129 | static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfo &fi) | 129 | static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfo &fi) |
| 130 | { | 130 | { |
| 131 | WIN_FD_TO_MY_FI(fi, fd); | 131 | WIN_FD_TO_MY_FI(fi, fd) |
| 132 | fi.Name = us2fs(fd.cFileName); | 132 | fi.Name = us2fs(fd.cFileName); |
| 133 | #if defined(_WIN32) && !defined(UNDER_CE) | 133 | #if defined(_WIN32) && !defined(UNDER_CE) |
| 134 | // fi.ShortName = us2fs(fd.cAlternateFileName); | 134 | // fi.ShortName = us2fs(fd.cAlternateFileName); |
| @@ -138,7 +138,7 @@ static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATAW &fd, CFil | |||
| 138 | #ifndef _UNICODE | 138 | #ifndef _UNICODE |
| 139 | static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi) | 139 | static void Convert_WIN32_FIND_DATA_to_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi) |
| 140 | { | 140 | { |
| 141 | WIN_FD_TO_MY_FI(fi, fd); | 141 | WIN_FD_TO_MY_FI(fi, fd) |
| 142 | fi.Name = fas2fs(fd.cFileName); | 142 | fi.Name = fas2fs(fd.cFileName); |
| 143 | #if defined(_WIN32) && !defined(UNDER_CE) | 143 | #if defined(_WIN32) && !defined(UNDER_CE) |
| 144 | // fi.ShortName = fas2fs(fd.cAlternateFileName); | 144 | // fi.ShortName = fas2fs(fd.cAlternateFileName); |
| @@ -211,7 +211,7 @@ bool CFindFile::FindFirst(CFSTR path, CFileInfo &fi) | |||
| 211 | 211 | ||
| 212 | IF_USE_MAIN_PATH | 212 | IF_USE_MAIN_PATH |
| 213 | _handle = ::FindFirstFileW(fs2us(path), &fd); | 213 | _handle = ::FindFirstFileW(fs2us(path), &fd); |
| 214 | #ifdef WIN_LONG_PATH | 214 | #ifdef Z7_LONG_PATH |
| 215 | if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH) | 215 | if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH) |
| 216 | { | 216 | { |
| 217 | UString superPath; | 217 | UString superPath; |
| @@ -252,23 +252,27 @@ bool CFindFile::FindNext(CFileInfo &fi) | |||
| 252 | //////////////////////////////// | 252 | //////////////////////////////// |
| 253 | // AltStreams | 253 | // AltStreams |
| 254 | 254 | ||
| 255 | static FindFirstStreamW_Ptr g_FindFirstStreamW; | 255 | static Func_FindFirstStreamW g_FindFirstStreamW; |
| 256 | static FindNextStreamW_Ptr g_FindNextStreamW; | 256 | static Func_FindNextStreamW g_FindNextStreamW; |
| 257 | 257 | ||
| 258 | static struct CFindStreamLoader | 258 | static struct CFindStreamLoader |
| 259 | { | 259 | { |
| 260 | CFindStreamLoader() | 260 | CFindStreamLoader() |
| 261 | { | 261 | { |
| 262 | HMODULE hm = ::GetModuleHandleA("kernel32.dll"); | 262 | const HMODULE hm = ::GetModuleHandleA("kernel32.dll"); |
| 263 | g_FindFirstStreamW = (FindFirstStreamW_Ptr)(void *)::GetProcAddress(hm, "FindFirstStreamW"); | 263 | g_FindFirstStreamW = Z7_GET_PROC_ADDRESS( |
| 264 | g_FindNextStreamW = (FindNextStreamW_Ptr)(void *)::GetProcAddress(hm, "FindNextStreamW"); | 264 | Func_FindFirstStreamW, hm, |
| 265 | "FindFirstStreamW"); | ||
| 266 | g_FindNextStreamW = Z7_GET_PROC_ADDRESS( | ||
| 267 | Func_FindNextStreamW, hm, | ||
| 268 | "FindNextStreamW"); | ||
| 265 | } | 269 | } |
| 266 | } g_FindStreamLoader; | 270 | } g_FindStreamLoader; |
| 267 | 271 | ||
| 268 | bool CStreamInfo::IsMainStream() const throw() | 272 | bool CStreamInfo::IsMainStream() const throw() |
| 269 | { | 273 | { |
| 270 | return StringsAreEqualNoCase_Ascii(Name, "::$DATA"); | 274 | return StringsAreEqualNoCase_Ascii(Name, "::$DATA"); |
| 271 | }; | 275 | } |
| 272 | 276 | ||
| 273 | UString CStreamInfo::GetReducedName() const | 277 | UString CStreamInfo::GetReducedName() const |
| 274 | { | 278 | { |
| @@ -331,7 +335,7 @@ bool CFindStream::FindFirst(CFSTR path, CStreamInfo &si) | |||
| 331 | if (::GetLastError() == ERROR_HANDLE_EOF) | 335 | if (::GetLastError() == ERROR_HANDLE_EOF) |
| 332 | return false; | 336 | return false; |
| 333 | // long name can be tricky for path like ".\dirName". | 337 | // long name can be tricky for path like ".\dirName". |
| 334 | #ifdef WIN_LONG_PATH | 338 | #ifdef Z7_LONG_PATH |
| 335 | if (USE_SUPER_PATH) | 339 | if (USE_SUPER_PATH) |
| 336 | { | 340 | { |
| 337 | UString superPath; | 341 | UString superPath; |
| @@ -414,7 +418,7 @@ DWORD GetFileAttrib(CFSTR path) | |||
| 414 | if (dw != INVALID_FILE_ATTRIBUTES) | 418 | if (dw != INVALID_FILE_ATTRIBUTES) |
| 415 | return dw; | 419 | return dw; |
| 416 | } | 420 | } |
| 417 | #ifdef WIN_LONG_PATH | 421 | #ifdef Z7_LONG_PATH |
| 418 | if (USE_SUPER_PATH) | 422 | if (USE_SUPER_PATH) |
| 419 | { | 423 | { |
| 420 | UString superPath; | 424 | UString superPath; |
| @@ -451,7 +455,7 @@ also we support paths that are not supported by FindFirstFile: | |||
| 451 | 455 | ||
| 452 | bool CFileInfo::Find(CFSTR path, bool followLink) | 456 | bool CFileInfo::Find(CFSTR path, bool followLink) |
| 453 | { | 457 | { |
| 454 | #ifdef SUPPORT_DEVICE_FILE | 458 | #ifdef Z7_DEVICE_FILE |
| 455 | 459 | ||
| 456 | if (IS_PATH_SEPAR(path[0]) && | 460 | if (IS_PATH_SEPAR(path[0]) && |
| 457 | IS_PATH_SEPAR(path[1]) && | 461 | IS_PATH_SEPAR(path[1]) && |
| @@ -847,7 +851,7 @@ HANDLE CFindChangeNotification::FindFirst(CFSTR path, bool watchSubtree, DWORD n | |||
| 847 | { | 851 | { |
| 848 | IF_USE_MAIN_PATH | 852 | IF_USE_MAIN_PATH |
| 849 | _handle = ::FindFirstChangeNotificationW(fs2us(path), BoolToBOOL(watchSubtree), notifyFilter); | 853 | _handle = ::FindFirstChangeNotificationW(fs2us(path), BoolToBOOL(watchSubtree), notifyFilter); |
| 850 | #ifdef WIN_LONG_PATH | 854 | #ifdef Z7_LONG_PATH |
| 851 | if (!IsHandleAllocated()) | 855 | if (!IsHandleAllocated()) |
| 852 | { | 856 | { |
| 853 | UString superPath; | 857 | UString superPath; |
diff --git a/CPP/Windows/FileFind.h b/CPP/Windows/FileFind.h index fcfe02c..11408d0 100644 --- a/CPP/Windows/FileFind.h +++ b/CPP/Windows/FileFind.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/FileFind.h | 1 | // Windows/FileFind.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILE_FIND_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_FIND_H |
| 4 | #define __WINDOWS_FILE_FIND_H | 4 | #define ZIP7_INC_WINDOWS_FILE_FIND_H |
| 5 | 5 | ||
| 6 | #ifndef _WIN32 | 6 | #ifndef _WIN32 |
| 7 | #include <sys/stat.h> | 7 | #include <sys/stat.h> |
| @@ -249,7 +249,15 @@ class CFindChangeNotification MY_UNCOPYABLE | |||
| 249 | HANDLE _handle; | 249 | HANDLE _handle; |
| 250 | public: | 250 | public: |
| 251 | operator HANDLE () { return _handle; } | 251 | operator HANDLE () { return _handle; } |
| 252 | bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; } | 252 | bool IsHandleAllocated() const |
| 253 | { | ||
| 254 | /* at least on win2000/XP (undocumented): | ||
| 255 | if pathName is "" or NULL, | ||
| 256 | FindFirstChangeNotification() could return NULL. | ||
| 257 | So we check for INVALID_HANDLE_VALUE and NULL. | ||
| 258 | */ | ||
| 259 | return _handle != INVALID_HANDLE_VALUE && _handle != NULL; | ||
| 260 | } | ||
| 253 | CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {} | 261 | CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {} |
| 254 | ~CFindChangeNotification() { Close(); } | 262 | ~CFindChangeNotification() { Close(); } |
| 255 | bool Close() throw(); | 263 | bool Close() throw(); |
diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp index e51b0eb..4ecbb7e 100644 --- a/CPP/Windows/FileIO.cpp +++ b/CPP/Windows/FileIO.cpp | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
| 4 | 4 | ||
| 5 | #ifdef SUPPORT_DEVICE_FILE | 5 | #ifdef Z7_DEVICE_FILE |
| 6 | #include "../../C/Alloc.h" | 6 | #include "../../C/Alloc.h" |
| 7 | #endif | 7 | #endif |
| 8 | 8 | ||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | HRESULT GetLastError_noZero_HRESULT() | 22 | HRESULT GetLastError_noZero_HRESULT() |
| 23 | { | 23 | { |
| 24 | DWORD res = ::GetLastError(); | 24 | const DWORD res = ::GetLastError(); |
| 25 | if (res == 0) | 25 | if (res == 0) |
| 26 | return E_FAIL; | 26 | return E_FAIL; |
| 27 | return HRESULT_FROM_WIN32(res); | 27 | return HRESULT_FROM_WIN32(res); |
| @@ -40,7 +40,7 @@ using namespace NName; | |||
| 40 | namespace NWindows { | 40 | namespace NWindows { |
| 41 | namespace NFile { | 41 | namespace NFile { |
| 42 | 42 | ||
| 43 | #ifdef SUPPORT_DEVICE_FILE | 43 | #ifdef Z7_DEVICE_FILE |
| 44 | 44 | ||
| 45 | namespace NSystem | 45 | namespace NSystem |
| 46 | { | 46 | { |
| @@ -72,7 +72,7 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess, | |||
| 72 | if (!Close()) | 72 | if (!Close()) |
| 73 | return false; | 73 | return false; |
| 74 | 74 | ||
| 75 | #ifdef SUPPORT_DEVICE_FILE | 75 | #ifdef Z7_DEVICE_FILE |
| 76 | IsDeviceFile = false; | 76 | IsDeviceFile = false; |
| 77 | #endif | 77 | #endif |
| 78 | 78 | ||
| @@ -88,7 +88,7 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess, | |||
| 88 | IF_USE_MAIN_PATH | 88 | IF_USE_MAIN_PATH |
| 89 | _handle = ::CreateFileW(fs2us(path), desiredAccess, shareMode, | 89 | _handle = ::CreateFileW(fs2us(path), desiredAccess, shareMode, |
| 90 | (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL); | 90 | (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL); |
| 91 | #ifdef WIN_LONG_PATH | 91 | #ifdef Z7_LONG_PATH |
| 92 | if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH) | 92 | if (_handle == INVALID_HANDLE_VALUE && USE_SUPER_PATH) |
| 93 | { | 93 | { |
| 94 | UString superPath; | 94 | UString superPath; |
| @@ -101,7 +101,7 @@ bool CFileBase::Create(CFSTR path, DWORD desiredAccess, | |||
| 101 | 101 | ||
| 102 | /* | 102 | /* |
| 103 | #ifndef UNDER_CE | 103 | #ifndef UNDER_CE |
| 104 | #ifndef _SFX | 104 | #ifndef Z7_SFX |
| 105 | if (_handle == INVALID_HANDLE_VALUE) | 105 | if (_handle == INVALID_HANDLE_VALUE) |
| 106 | { | 106 | { |
| 107 | // it's debug hack to open symbolic links in Windows XP and WSL links in Windows 10 | 107 | // it's debug hack to open symbolic links in Windows XP and WSL links in Windows 10 |
| @@ -149,7 +149,7 @@ bool CFileBase::Close() throw() | |||
| 149 | 149 | ||
| 150 | bool CFileBase::GetLength(UInt64 &length) const throw() | 150 | bool CFileBase::GetLength(UInt64 &length) const throw() |
| 151 | { | 151 | { |
| 152 | #ifdef SUPPORT_DEVICE_FILE | 152 | #ifdef Z7_DEVICE_FILE |
| 153 | if (IsDeviceFile && SizeDefined) | 153 | if (IsDeviceFile && SizeDefined) |
| 154 | { | 154 | { |
| 155 | length = Size; | 155 | length = Size; |
| @@ -219,7 +219,7 @@ bool CFileBase::GetPosition(UInt64 &position) const throw() | |||
| 219 | 219 | ||
| 220 | bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const throw() | 220 | bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const throw() |
| 221 | { | 221 | { |
| 222 | #ifdef SUPPORT_DEVICE_FILE | 222 | #ifdef Z7_DEVICE_FILE |
| 223 | if (IsDeviceFile && SizeDefined && moveMethod == FILE_END) | 223 | if (IsDeviceFile && SizeDefined && moveMethod == FILE_END) |
| 224 | { | 224 | { |
| 225 | distanceToMove += Size; | 225 | distanceToMove += Size; |
| @@ -262,12 +262,12 @@ bool CFileBase::SeekToEnd(UInt64 &newPosition) const throw() | |||
| 262 | 262 | ||
| 263 | // ---------- CInFile --------- | 263 | // ---------- CInFile --------- |
| 264 | 264 | ||
| 265 | #ifdef SUPPORT_DEVICE_FILE | 265 | #ifdef Z7_DEVICE_FILE |
| 266 | 266 | ||
| 267 | void CInFile::CorrectDeviceSize() | 267 | void CInFile::CorrectDeviceSize() |
| 268 | { | 268 | { |
| 269 | // maybe we must decrease kClusterSize to 1 << 12, if we want correct size at tail | 269 | // maybe we must decrease kClusterSize to 1 << 12, if we want correct size at tail |
| 270 | static const UInt32 kClusterSize = 1 << 14; | 270 | const UInt32 kClusterSize = 1 << 14; |
| 271 | UInt64 pos = Size & ~(UInt64)(kClusterSize - 1); | 271 | UInt64 pos = Size & ~(UInt64)(kClusterSize - 1); |
| 272 | UInt64 realNewPosition; | 272 | UInt64 realNewPosition; |
| 273 | if (!Seek(pos, realNewPosition)) | 273 | if (!Seek(pos, realNewPosition)) |
| @@ -462,7 +462,7 @@ static const UInt32 kChunkSizeMax = (1 << 22); | |||
| 462 | bool CInFile::Read1(void *data, UInt32 size, UInt32 &processedSize) throw() | 462 | bool CInFile::Read1(void *data, UInt32 size, UInt32 &processedSize) throw() |
| 463 | { | 463 | { |
| 464 | DWORD processedLoc = 0; | 464 | DWORD processedLoc = 0; |
| 465 | bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL)); | 465 | const bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL)); |
| 466 | processedSize = (UInt32)processedLoc; | 466 | processedSize = (UInt32)processedLoc; |
| 467 | return res; | 467 | return res; |
| 468 | } | 468 | } |
| @@ -480,7 +480,7 @@ bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize) throw() | |||
| 480 | do | 480 | do |
| 481 | { | 481 | { |
| 482 | UInt32 processedLoc = 0; | 482 | UInt32 processedLoc = 0; |
| 483 | bool res = ReadPart(data, size, processedLoc); | 483 | const bool res = ReadPart(data, size, processedLoc); |
| 484 | processedSize += processedLoc; | 484 | processedSize += processedLoc; |
| 485 | if (!res) | 485 | if (!res) |
| 486 | return false; | 486 | return false; |
| @@ -551,7 +551,7 @@ bool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize) throw | |||
| 551 | do | 551 | do |
| 552 | { | 552 | { |
| 553 | UInt32 processedLoc = 0; | 553 | UInt32 processedLoc = 0; |
| 554 | bool res = WritePart(data, size, processedLoc); | 554 | const bool res = WritePart(data, size, processedLoc); |
| 555 | processedSize += processedLoc; | 555 | processedSize += processedLoc; |
| 556 | if (!res) | 556 | if (!res) |
| 557 | return false; | 557 | return false; |
| @@ -628,14 +628,14 @@ bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CF | |||
| 628 | 628 | ||
| 629 | namespace NIO { | 629 | namespace NIO { |
| 630 | 630 | ||
| 631 | bool CFileBase::OpenBinary(const char *name, int flags) | 631 | bool CFileBase::OpenBinary(const char *name, int flags, mode_t mode) |
| 632 | { | 632 | { |
| 633 | #ifdef O_BINARY | 633 | #ifdef O_BINARY |
| 634 | flags |= O_BINARY; | 634 | flags |= O_BINARY; |
| 635 | #endif | 635 | #endif |
| 636 | 636 | ||
| 637 | Close(); | 637 | Close(); |
| 638 | _handle = ::open(name, flags, 0666); | 638 | _handle = ::open(name, flags, mode); |
| 639 | return _handle != -1; | 639 | return _handle != -1; |
| 640 | 640 | ||
| 641 | /* | 641 | /* |
| @@ -804,10 +804,10 @@ bool COutFile::Create(const char *name, bool createAlways) | |||
| 804 | if (createAlways) | 804 | if (createAlways) |
| 805 | { | 805 | { |
| 806 | Close(); | 806 | Close(); |
| 807 | _handle = ::creat(name, 0666); | 807 | _handle = ::creat(name, mode_for_Create); |
| 808 | return _handle != -1; | 808 | return _handle != -1; |
| 809 | } | 809 | } |
| 810 | return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY); | 810 | return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY, mode_for_Create); |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | bool COutFile::Open(const char *name, DWORD creationDisposition) | 813 | bool COutFile::Open(const char *name, DWORD creationDisposition) |
| @@ -850,13 +850,13 @@ bool COutFile::SetLength(UInt64 length) throw() | |||
| 850 | return false; | 850 | return false; |
| 851 | } | 851 | } |
| 852 | // The value of the seek pointer shall not be modified by a call to ftruncate(). | 852 | // The value of the seek pointer shall not be modified by a call to ftruncate(). |
| 853 | int iret = ftruncate(_handle, len2); | 853 | const int iret = ftruncate(_handle, len2); |
| 854 | return (iret == 0); | 854 | return (iret == 0); |
| 855 | } | 855 | } |
| 856 | 856 | ||
| 857 | bool COutFile::Close() | 857 | bool COutFile::Close() |
| 858 | { | 858 | { |
| 859 | bool res = CFileBase::Close(); | 859 | const bool res = CFileBase::Close(); |
| 860 | if (!res) | 860 | if (!res) |
| 861 | return res; | 861 | return res; |
| 862 | if (CTime_defined || ATime_defined || MTime_defined) | 862 | if (CTime_defined || ATime_defined || MTime_defined) |
diff --git a/CPP/Windows/FileIO.h b/CPP/Windows/FileIO.h index 8050965..03e061a 100644 --- a/CPP/Windows/FileIO.h +++ b/CPP/Windows/FileIO.h | |||
| @@ -1,23 +1,23 @@ | |||
| 1 | // Windows/FileIO.h | 1 | // Windows/FileIO.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILE_IO_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_IO_H |
| 4 | #define __WINDOWS_FILE_IO_H | 4 | #define ZIP7_INC_WINDOWS_FILE_IO_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | 7 | ||
| 8 | #define _my_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) | 8 | #define Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L) |
| 9 | #define _my_IO_REPARSE_TAG_SYMLINK (0xA000000CL) | 9 | #define Z7_WIN_IO_REPARSE_TAG_SYMLINK (0xA000000CL) |
| 10 | #define _my_IO_REPARSE_TAG_LX_SYMLINK (0xA000001DL) | 10 | #define Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK (0xA000001DL) |
| 11 | 11 | ||
| 12 | #define _my_SYMLINK_FLAG_RELATIVE 1 | 12 | #define Z7_WIN_SYMLINK_FLAG_RELATIVE 1 |
| 13 | 13 | ||
| 14 | // what the meaning of that FLAG or field (2)? | 14 | // what the meaning of that FLAG or field (2)? |
| 15 | #define _my_LX_SYMLINK_FLAG 2 | 15 | #define Z7_WIN_LX_SYMLINK_FLAG 2 |
| 16 | 16 | ||
| 17 | #ifdef _WIN32 | 17 | #ifdef _WIN32 |
| 18 | 18 | ||
| 19 | #if defined(_WIN32) && !defined(UNDER_CE) | 19 | #if defined(_WIN32) && !defined(UNDER_CE) |
| 20 | #include <WinIoCtl.h> | 20 | #include <winioctl.h> |
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | #else | 23 | #else |
| @@ -76,11 +76,11 @@ struct CReparseAttr | |||
| 76 | // returns (false) and (ErrorCode = ERROR_REPARSE_TAG_INVALID), if unknown tag | 76 | // returns (false) and (ErrorCode = ERROR_REPARSE_TAG_INVALID), if unknown tag |
| 77 | bool Parse(const Byte *p, size_t size); | 77 | bool Parse(const Byte *p, size_t size); |
| 78 | 78 | ||
| 79 | bool IsMountPoint() const { return Tag == _my_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction | 79 | bool IsMountPoint() const { return Tag == Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction |
| 80 | bool IsSymLink_Win() const { return Tag == _my_IO_REPARSE_TAG_SYMLINK; } | 80 | bool IsSymLink_Win() const { return Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK; } |
| 81 | bool IsSymLink_WSL() const { return Tag == _my_IO_REPARSE_TAG_LX_SYMLINK; } | 81 | bool IsSymLink_WSL() const { return Tag == Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK; } |
| 82 | 82 | ||
| 83 | bool IsRelative_Win() const { return Flags == _my_SYMLINK_FLAG_RELATIVE; } | 83 | bool IsRelative_Win() const { return Flags == Z7_WIN_SYMLINK_FLAG_RELATIVE; } |
| 84 | 84 | ||
| 85 | bool IsRelative_WSL() const | 85 | bool IsRelative_WSL() const |
| 86 | { | 86 | { |
| @@ -141,17 +141,19 @@ public: | |||
| 141 | 141 | ||
| 142 | public: | 142 | public: |
| 143 | bool PreserveATime; | 143 | bool PreserveATime; |
| 144 | #ifdef SUPPORT_DEVICE_FILE | 144 | #ifdef Z7_DEVICE_FILE |
| 145 | bool IsDeviceFile; | 145 | bool IsDeviceFile; |
| 146 | bool SizeDefined; | 146 | bool SizeDefined; |
| 147 | UInt64 Size; // it can be larger than real available size | 147 | UInt64 Size; // it can be larger than real available size |
| 148 | #endif | 148 | #endif |
| 149 | 149 | ||
| 150 | CFileBase(): _handle(INVALID_HANDLE_VALUE), PreserveATime(false) {}; | 150 | CFileBase(): _handle(INVALID_HANDLE_VALUE), PreserveATime(false) {} |
| 151 | ~CFileBase() { Close(); } | 151 | ~CFileBase() { Close(); } |
| 152 | 152 | ||
| 153 | HANDLE GetHandle() const { return _handle; } | 153 | HANDLE GetHandle() const { return _handle; } |
| 154 | 154 | ||
| 155 | // void Detach() { _handle = INVALID_HANDLE_VALUE; } | ||
| 156 | |||
| 155 | bool Close() throw(); | 157 | bool Close() throw(); |
| 156 | 158 | ||
| 157 | bool GetPosition(UInt64 &position) const throw(); | 159 | bool GetPosition(UInt64 &position) const throw(); |
| @@ -193,7 +195,7 @@ struct my_DISK_GEOMETRY_EX | |||
| 193 | 195 | ||
| 194 | class CInFile: public CFileBase | 196 | class CInFile: public CFileBase |
| 195 | { | 197 | { |
| 196 | #ifdef SUPPORT_DEVICE_FILE | 198 | #ifdef Z7_DEVICE_FILE |
| 197 | 199 | ||
| 198 | #ifndef UNDER_CE | 200 | #ifndef UNDER_CE |
| 199 | 201 | ||
| @@ -232,6 +234,14 @@ public: | |||
| 232 | // we must use (FILE_FLAG_BACKUP_SEMANTICS) to open handle of directory. | 234 | // we must use (FILE_FLAG_BACKUP_SEMANTICS) to open handle of directory. |
| 233 | } | 235 | } |
| 234 | 236 | ||
| 237 | bool Open_for_FileRenameInformation(CFSTR fileName) | ||
| 238 | { | ||
| 239 | return Create(fileName, DELETE | SYNCHRONIZE | GENERIC_READ, | ||
| 240 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | ||
| 241 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); | ||
| 242 | // we must use (FILE_FLAG_BACKUP_SEMANTICS) to open handle of directory. | ||
| 243 | } | ||
| 244 | |||
| 235 | bool OpenReparse(CFSTR fileName) | 245 | bool OpenReparse(CFSTR fileName) |
| 236 | { | 246 | { |
| 237 | // 17.02 fix: to support Windows XP compatibility junctions: | 247 | // 17.02 fix: to support Windows XP compatibility junctions: |
| @@ -295,12 +305,13 @@ protected: | |||
| 295 | UInt64 Size; // it can be larger than real available size | 305 | UInt64 Size; // it can be larger than real available size |
| 296 | */ | 306 | */ |
| 297 | 307 | ||
| 298 | bool OpenBinary(const char *name, int flags); | 308 | bool OpenBinary(const char *name, int flags, mode_t mode = 0666); |
| 299 | public: | 309 | public: |
| 300 | bool PreserveATime; | 310 | bool PreserveATime; |
| 301 | 311 | ||
| 302 | CFileBase(): _handle(-1), PreserveATime(false) {}; | 312 | CFileBase(): _handle(-1), PreserveATime(false) {} |
| 303 | ~CFileBase() { Close(); } | 313 | ~CFileBase() { Close(); } |
| 314 | // void Detach() { _handle = -1; } | ||
| 304 | bool Close(); | 315 | bool Close(); |
| 305 | bool GetLength(UInt64 &length) const; | 316 | bool GetLength(UInt64 &length) const; |
| 306 | off_t seek(off_t distanceToMove, int moveMethod) const; | 317 | off_t seek(off_t distanceToMove, int moveMethod) const; |
| @@ -330,7 +341,6 @@ class COutFile: public CFileBase | |||
| 330 | bool CTime_defined; | 341 | bool CTime_defined; |
| 331 | bool ATime_defined; | 342 | bool ATime_defined; |
| 332 | bool MTime_defined; | 343 | bool MTime_defined; |
| 333 | |||
| 334 | CFiTime CTime; | 344 | CFiTime CTime; |
| 335 | CFiTime ATime; | 345 | CFiTime ATime; |
| 336 | CFiTime MTime; | 346 | CFiTime MTime; |
| @@ -338,10 +348,13 @@ class COutFile: public CFileBase | |||
| 338 | AString Path; | 348 | AString Path; |
| 339 | ssize_t write_part(const void *data, size_t size) throw(); | 349 | ssize_t write_part(const void *data, size_t size) throw(); |
| 340 | public: | 350 | public: |
| 351 | mode_t mode_for_Create; | ||
| 352 | |||
| 341 | COutFile(): | 353 | COutFile(): |
| 342 | CTime_defined(false), | 354 | CTime_defined(false), |
| 343 | ATime_defined(false), | 355 | ATime_defined(false), |
| 344 | MTime_defined(false) | 356 | MTime_defined(false), |
| 357 | mode_for_Create(0666) | ||
| 345 | {} | 358 | {} |
| 346 | 359 | ||
| 347 | bool Close(); | 360 | bool Close(); |
diff --git a/CPP/Windows/FileLink.cpp b/CPP/Windows/FileLink.cpp index 8ce634f..2b9fa1a 100644 --- a/CPP/Windows/FileLink.cpp +++ b/CPP/Windows/FileLink.cpp | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | #include <unistd.h> | 8 | #include <unistd.h> |
| 9 | #endif | 9 | #endif |
| 10 | 10 | ||
| 11 | #ifdef SUPPORT_DEVICE_FILE | 11 | #ifdef Z7_DEVICE_FILE |
| 12 | #include "../../C/Alloc.h" | 12 | #include "../../C/Alloc.h" |
| 13 | #endif | 13 | #endif |
| 14 | 14 | ||
| @@ -20,6 +20,15 @@ | |||
| 20 | #include "FileIO.h" | 20 | #include "FileIO.h" |
| 21 | #include "FileName.h" | 21 | #include "FileName.h" |
| 22 | 22 | ||
| 23 | #ifdef Z7_OLD_WIN_SDK | ||
| 24 | #ifndef ERROR_INVALID_REPARSE_DATA | ||
| 25 | #define ERROR_INVALID_REPARSE_DATA 4392L | ||
| 26 | #endif | ||
| 27 | #ifndef ERROR_REPARSE_TAG_INVALID | ||
| 28 | #define ERROR_REPARSE_TAG_INVALID 4393L | ||
| 29 | #endif | ||
| 30 | #endif | ||
| 31 | |||
| 23 | #ifndef _UNICODE | 32 | #ifndef _UNICODE |
| 24 | extern bool g_IsNT; | 33 | extern bool g_IsNT; |
| 25 | #endif | 34 | #endif |
| @@ -72,13 +81,13 @@ static const UInt32 kReparseFlags_Alias = (1 << 29); | |||
| 72 | static const UInt32 kReparseFlags_HighLatency = (1 << 30); | 81 | static const UInt32 kReparseFlags_HighLatency = (1 << 30); |
| 73 | static const UInt32 kReparseFlags_Microsoft = ((UInt32)1 << 31); | 82 | static const UInt32 kReparseFlags_Microsoft = ((UInt32)1 << 31); |
| 74 | 83 | ||
| 75 | #define _my_IO_REPARSE_TAG_HSM (0xC0000004L) | 84 | #define Z7_WIN_IO_REPARSE_TAG_HSM (0xC0000004L) |
| 76 | #define _my_IO_REPARSE_TAG_HSM2 (0x80000006L) | 85 | #define Z7_WIN_IO_REPARSE_TAG_HSM2 (0x80000006L) |
| 77 | #define _my_IO_REPARSE_TAG_SIS (0x80000007L) | 86 | #define Z7_WIN_IO_REPARSE_TAG_SIS (0x80000007L) |
| 78 | #define _my_IO_REPARSE_TAG_WIM (0x80000008L) | 87 | #define Z7_WIN_IO_REPARSE_TAG_WIM (0x80000008L) |
| 79 | #define _my_IO_REPARSE_TAG_CSV (0x80000009L) | 88 | #define Z7_WIN_IO_REPARSE_TAG_CSV (0x80000009L) |
| 80 | #define _my_IO_REPARSE_TAG_DFS (0x8000000AL) | 89 | #define Z7_WIN_IO_REPARSE_TAG_DFS (0x8000000AL) |
| 81 | #define _my_IO_REPARSE_TAG_DFSR (0x80000012L) | 90 | #define Z7_WIN_IO_REPARSE_TAG_DFSR (0x80000012L) |
| 82 | */ | 91 | */ |
| 83 | 92 | ||
| 84 | #define Get16(p) GetUi16(p) | 93 | #define Get16(p) GetUi16(p) |
| @@ -112,7 +121,7 @@ static void WriteString(Byte *dest, const wchar_t *path) | |||
| 112 | wchar_t c = *path++; | 121 | wchar_t c = *path++; |
| 113 | if (c == 0) | 122 | if (c == 0) |
| 114 | return; | 123 | return; |
| 115 | Set16(dest, (UInt16)c); | 124 | Set16(dest, (UInt16)c) |
| 116 | dest += 2; | 125 | dest += 2; |
| 117 | } | 126 | } |
| 118 | } | 127 | } |
| @@ -133,10 +142,10 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool i | |||
| 133 | return false; | 142 | return false; |
| 134 | dest.Alloc(8 + size); | 143 | dest.Alloc(8 + size); |
| 135 | Byte *p = dest; | 144 | Byte *p = dest; |
| 136 | Set32(p, _my_IO_REPARSE_TAG_LX_SYMLINK); | 145 | Set32(p, Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK) |
| 137 | Set16(p + 4, (UInt16)(size)); | 146 | Set16(p + 4, (UInt16)(size)) |
| 138 | Set16(p + 6, 0); | 147 | Set16(p + 6, 0) |
| 139 | Set32(p + 8, _my_LX_SYMLINK_FLAG); | 148 | Set32(p + 8, Z7_WIN_LX_SYMLINK_FLAG) |
| 140 | memcpy(p + 12, utf.Ptr(), utf.Len()); | 149 | memcpy(p + 12, utf.Ptr(), utf.Len()); |
| 141 | return true; | 150 | return true; |
| 142 | } | 151 | } |
| @@ -176,12 +185,12 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool i | |||
| 176 | dest.Alloc(size); | 185 | dest.Alloc(size); |
| 177 | memset(dest, 0, size); | 186 | memset(dest, 0, size); |
| 178 | const UInt32 tag = isSymLink ? | 187 | const UInt32 tag = isSymLink ? |
| 179 | _my_IO_REPARSE_TAG_SYMLINK : | 188 | Z7_WIN_IO_REPARSE_TAG_SYMLINK : |
| 180 | _my_IO_REPARSE_TAG_MOUNT_POINT; | 189 | Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT; |
| 181 | Byte *p = dest; | 190 | Byte *p = dest; |
| 182 | Set32(p, tag); | 191 | Set32(p, tag) |
| 183 | Set16(p + 4, (UInt16)(size - 8)); | 192 | Set16(p + 4, (UInt16)(size - 8)) |
| 184 | Set16(p + 6, 0); | 193 | Set16(p + 6, 0) |
| 185 | p += 8; | 194 | p += 8; |
| 186 | 195 | ||
| 187 | unsigned subOffs = 0; | 196 | unsigned subOffs = 0; |
| @@ -191,16 +200,16 @@ bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool i | |||
| 191 | else | 200 | else |
| 192 | printOffs = (unsigned)len1 + 2; | 201 | printOffs = (unsigned)len1 + 2; |
| 193 | 202 | ||
| 194 | Set16(p + 0, (UInt16)subOffs); | 203 | Set16(p + 0, (UInt16)subOffs) |
| 195 | Set16(p + 2, (UInt16)len1); | 204 | Set16(p + 2, (UInt16)len1) |
| 196 | Set16(p + 4, (UInt16)printOffs); | 205 | Set16(p + 4, (UInt16)printOffs) |
| 197 | Set16(p + 6, (UInt16)len2); | 206 | Set16(p + 6, (UInt16)len2) |
| 198 | 207 | ||
| 199 | p += 8; | 208 | p += 8; |
| 200 | if (isSymLink) | 209 | if (isSymLink) |
| 201 | { | 210 | { |
| 202 | UInt32 flags = isAbs ? 0 : _my_SYMLINK_FLAG_RELATIVE; | 211 | UInt32 flags = isAbs ? 0 : Z7_WIN_SYMLINK_FLAG_RELATIVE; |
| 203 | Set32(p, flags); | 212 | Set32(p, flags) |
| 204 | p += 4; | 213 | p += 4; |
| 205 | } | 214 | } |
| 206 | 215 | ||
| @@ -255,9 +264,9 @@ bool CReparseAttr::Parse(const Byte *p, size_t size) | |||
| 255 | 264 | ||
| 256 | HeaderError = false; | 265 | HeaderError = false; |
| 257 | 266 | ||
| 258 | if ( Tag != _my_IO_REPARSE_TAG_MOUNT_POINT | 267 | if ( Tag != Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT |
| 259 | && Tag != _my_IO_REPARSE_TAG_SYMLINK | 268 | && Tag != Z7_WIN_IO_REPARSE_TAG_SYMLINK |
| 260 | && Tag != _my_IO_REPARSE_TAG_LX_SYMLINK) | 269 | && Tag != Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK) |
| 261 | { | 270 | { |
| 262 | // for unsupported reparse points | 271 | // for unsupported reparse points |
| 263 | ErrorCode = (DWORD)ERROR_REPARSE_TAG_INVALID; // ERROR_REPARSE_TAG_MISMATCH | 272 | ErrorCode = (DWORD)ERROR_REPARSE_TAG_INVALID; // ERROR_REPARSE_TAG_MISMATCH |
| @@ -270,12 +279,12 @@ bool CReparseAttr::Parse(const Byte *p, size_t size) | |||
| 270 | p += 8; | 279 | p += 8; |
| 271 | size -= 8; | 280 | size -= 8; |
| 272 | 281 | ||
| 273 | if (Tag == _my_IO_REPARSE_TAG_LX_SYMLINK) | 282 | if (Tag == Z7_WIN_IO_REPARSE_TAG_LX_SYMLINK) |
| 274 | { | 283 | { |
| 275 | if (len < 4) | 284 | if (len < 4) |
| 276 | return false; | 285 | return false; |
| 277 | Flags = Get32(p); // maybe it's not Flags | 286 | Flags = Get32(p); // maybe it's not Flags |
| 278 | if (Flags != _my_LX_SYMLINK_FLAG) | 287 | if (Flags != Z7_WIN_LX_SYMLINK_FLAG) |
| 279 | return false; | 288 | return false; |
| 280 | len -= 4; | 289 | len -= 4; |
| 281 | p += 4; | 290 | p += 4; |
| @@ -304,7 +313,7 @@ bool CReparseAttr::Parse(const Byte *p, size_t size) | |||
| 304 | p += 8; | 313 | p += 8; |
| 305 | 314 | ||
| 306 | Flags = 0; | 315 | Flags = 0; |
| 307 | if (Tag == _my_IO_REPARSE_TAG_SYMLINK) | 316 | if (Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK) |
| 308 | { | 317 | { |
| 309 | if (len < 4) | 318 | if (len < 4) |
| 310 | return false; | 319 | return false; |
| @@ -341,8 +350,8 @@ bool CReparseShortInfo::Parse(const Byte *p, size_t size) | |||
| 341 | (type & kReparseFlags_Microsoft) == 0 || | 350 | (type & kReparseFlags_Microsoft) == 0 || |
| 342 | (type & 0xFFFF) != 3) | 351 | (type & 0xFFFF) != 3) |
| 343 | */ | 352 | */ |
| 344 | if (Tag != _my_IO_REPARSE_TAG_MOUNT_POINT && | 353 | if (Tag != Z7_WIN_IO_REPARSE_TAG_MOUNT_POINT && |
| 345 | Tag != _my_IO_REPARSE_TAG_SYMLINK) | 354 | Tag != Z7_WIN_IO_REPARSE_TAG_SYMLINK) |
| 346 | // return true; | 355 | // return true; |
| 347 | return false; | 356 | return false; |
| 348 | 357 | ||
| @@ -365,7 +374,7 @@ bool CReparseShortInfo::Parse(const Byte *p, size_t size) | |||
| 365 | p += 8; | 374 | p += 8; |
| 366 | 375 | ||
| 367 | // UInt32 Flags = 0; | 376 | // UInt32 Flags = 0; |
| 368 | if (Tag == _my_IO_REPARSE_TAG_SYMLINK) | 377 | if (Tag == Z7_WIN_IO_REPARSE_TAG_SYMLINK) |
| 369 | { | 378 | { |
| 370 | if (len < 4) | 379 | if (len < 4) |
| 371 | return false; | 380 | return false; |
| @@ -426,13 +435,13 @@ UString CReparseAttr::GetPath() const | |||
| 426 | return s; | 435 | return s; |
| 427 | } | 436 | } |
| 428 | 437 | ||
| 429 | #ifdef SUPPORT_DEVICE_FILE | 438 | #ifdef Z7_DEVICE_FILE |
| 430 | 439 | ||
| 431 | namespace NSystem | 440 | namespace NSystem |
| 432 | { | 441 | { |
| 433 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize); | 442 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize); |
| 434 | } | 443 | } |
| 435 | #endif // SUPPORT_DEVICE_FILE | 444 | #endif // Z7_DEVICE_FILE |
| 436 | 445 | ||
| 437 | #if defined(_WIN32) && !defined(UNDER_CE) | 446 | #if defined(_WIN32) && !defined(UNDER_CE) |
| 438 | 447 | ||
diff --git a/CPP/Windows/FileMapping.h b/CPP/Windows/FileMapping.h index f90c429..caa7ea3 100644 --- a/CPP/Windows/FileMapping.h +++ b/CPP/Windows/FileMapping.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/FileMapping.h | 1 | // Windows/FileMapping.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILEMAPPING_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_MAPPING_H |
| 4 | #define __WINDOWS_FILEMAPPING_H | 4 | #define ZIP7_INC_WINDOWS_FILE_MAPPING_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyTypes.h" |
| 7 | 7 | ||
| @@ -34,7 +34,7 @@ public: | |||
| 34 | return res; | 34 | return res; |
| 35 | #else | 35 | #else |
| 36 | _handle = ::OpenFileMapping(desiredAccess, FALSE, name); | 36 | _handle = ::OpenFileMapping(desiredAccess, FALSE, name); |
| 37 | if (_handle != 0) | 37 | if (_handle != NULL) |
| 38 | return 0; | 38 | return 0; |
| 39 | return ::GetLastError(); | 39 | return ::GetLastError(); |
| 40 | #endif | 40 | #endif |
diff --git a/CPP/Windows/FileName.cpp b/CPP/Windows/FileName.cpp index d61ff7e..c9c4f8b 100644 --- a/CPP/Windows/FileName.cpp +++ b/CPP/Windows/FileName.cpp | |||
| @@ -6,9 +6,9 @@ | |||
| 6 | #include <limits.h> | 6 | #include <limits.h> |
| 7 | #include <unistd.h> | 7 | #include <unistd.h> |
| 8 | #include "../Common/StringConvert.h" | 8 | #include "../Common/StringConvert.h" |
| 9 | #include "FileDir.h" | ||
| 10 | #endif | 9 | #endif |
| 11 | 10 | ||
| 11 | #include "FileDir.h" | ||
| 12 | #include "FileName.h" | 12 | #include "FileName.h" |
| 13 | 13 | ||
| 14 | #ifndef _UNICODE | 14 | #ifndef _UNICODE |
| @@ -68,7 +68,7 @@ void NormalizeDirPathPrefix(UString &dirPath) | |||
| 68 | #ifdef _WIN32 | 68 | #ifdef _WIN32 |
| 69 | 69 | ||
| 70 | #ifndef USE_UNICODE_FSTRING | 70 | #ifndef USE_UNICODE_FSTRING |
| 71 | #ifdef WIN_LONG_PATH | 71 | #ifdef Z7_LONG_PATH |
| 72 | static void NormalizeDirSeparators(UString &s) | 72 | static void NormalizeDirSeparators(UString &s) |
| 73 | { | 73 | { |
| 74 | const unsigned len = s.Len(); | 74 | const unsigned len = s.Len(); |
| @@ -90,7 +90,7 @@ void NormalizeDirSeparators(FString &s) | |||
| 90 | #endif | 90 | #endif |
| 91 | 91 | ||
| 92 | 92 | ||
| 93 | #define IS_LETTER_CHAR(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) | 93 | #define IS_LETTER_CHAR(c) ((((unsigned)(int)(c) | 0x20) - (unsigned)'a' <= (unsigned)('z' - 'a'))) |
| 94 | 94 | ||
| 95 | bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } | 95 | bool IsDrivePath(const wchar_t *s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && IS_SEPAR(s[2]); } |
| 96 | 96 | ||
| @@ -120,7 +120,7 @@ bool IsAltPathPrefix(CFSTR s) throw() | |||
| 120 | #if defined(_WIN32) && !defined(UNDER_CE) | 120 | #if defined(_WIN32) && !defined(UNDER_CE) |
| 121 | 121 | ||
| 122 | const char * const kSuperPathPrefix = "\\\\?\\"; | 122 | const char * const kSuperPathPrefix = "\\\\?\\"; |
| 123 | #ifdef WIN_LONG_PATH | 123 | #ifdef Z7_LONG_PATH |
| 124 | static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; | 124 | static const char * const kSuperUncPrefix = "\\\\?\\UNC\\"; |
| 125 | #endif | 125 | #endif |
| 126 | 126 | ||
| @@ -191,7 +191,7 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw() | |||
| 191 | if (c == '.' || c == '?') | 191 | if (c == '.' || c == '?') |
| 192 | return 0; | 192 | return 0; |
| 193 | } | 193 | } |
| 194 | int pos = FindSepar(s + prefixSize); | 194 | const int pos = FindSepar(s + prefixSize); |
| 195 | if (pos < 0) | 195 | if (pos < 0) |
| 196 | return 0; | 196 | return 0; |
| 197 | return prefixSize + (unsigned)(pos + 1); | 197 | return prefixSize + (unsigned)(pos + 1); |
| @@ -199,11 +199,11 @@ unsigned GetNetworkServerPrefixSize(CFSTR s) throw() | |||
| 199 | 199 | ||
| 200 | bool IsNetworkShareRootPath(CFSTR s) throw() | 200 | bool IsNetworkShareRootPath(CFSTR s) throw() |
| 201 | { | 201 | { |
| 202 | unsigned prefixSize = GetNetworkServerPrefixSize(s); | 202 | const unsigned prefixSize = GetNetworkServerPrefixSize(s); |
| 203 | if (prefixSize == 0) | 203 | if (prefixSize == 0) |
| 204 | return false; | 204 | return false; |
| 205 | s += prefixSize; | 205 | s += prefixSize; |
| 206 | int pos = FindSepar(s); | 206 | const int pos = FindSepar(s); |
| 207 | if (pos < 0) | 207 | if (pos < 0) |
| 208 | return true; | 208 | return true; |
| 209 | return s[(unsigned)pos + 1] == 0; | 209 | return s[(unsigned)pos + 1] == 0; |
| @@ -217,6 +217,37 @@ bool IsSuperPath(const wchar_t *s) throw() { return IS_SUPER_PREFIX(s); } | |||
| 217 | bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } | 217 | bool IsSuperOrDevicePath(const wchar_t *s) throw() { return IS_SUPER_OR_DEVICE_PATH(s); } |
| 218 | // bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } | 218 | // bool IsSuperUncPath(const wchar_t *s) throw() { return (IS_SUPER_PREFIX(s) && IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)); } |
| 219 | 219 | ||
| 220 | bool IsAltStreamPrefixWithColon(const UString &s) throw() | ||
| 221 | { | ||
| 222 | if (s.IsEmpty()) | ||
| 223 | return false; | ||
| 224 | if (s.Back() != ':') | ||
| 225 | return false; | ||
| 226 | unsigned pos = 0; | ||
| 227 | if (IsSuperPath(s)) | ||
| 228 | pos = kSuperPathPrefixSize; | ||
| 229 | if (s.Len() - pos == 2 && IsDrivePath2(s.Ptr(pos))) | ||
| 230 | return false; | ||
| 231 | return true; | ||
| 232 | } | ||
| 233 | |||
| 234 | bool If_IsSuperPath_RemoveSuperPrefix(UString &s) | ||
| 235 | { | ||
| 236 | if (!IsSuperPath(s)) | ||
| 237 | return false; | ||
| 238 | unsigned start = 0; | ||
| 239 | unsigned count = kSuperPathPrefixSize; | ||
| 240 | const wchar_t *s2 = s.Ptr(kSuperPathPrefixSize); | ||
| 241 | if (IS_UNC_WITH_SLASH(s2)) | ||
| 242 | { | ||
| 243 | start = 2; | ||
| 244 | count = kSuperUncPathPrefixSize - 2; | ||
| 245 | } | ||
| 246 | s.Delete(start, count); | ||
| 247 | return true; | ||
| 248 | } | ||
| 249 | |||
| 250 | |||
| 220 | #ifndef USE_UNICODE_FSTRING | 251 | #ifndef USE_UNICODE_FSTRING |
| 221 | bool IsDrivePath2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } | 252 | bool IsDrivePath2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':'; } |
| 222 | // bool IsDriveName2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } | 253 | // bool IsDriveName2(CFSTR s) throw() { return IS_LETTER_CHAR(s[0]) && s[1] == ':' && s[2] == 0; } |
| @@ -288,7 +319,7 @@ static unsigned GetRootPrefixSize_Of_SimplePath(CFSTR s) | |||
| 288 | return 0; | 319 | return 0; |
| 289 | if (s[1] == 0 || !IS_SEPAR(s[1])) | 320 | if (s[1] == 0 || !IS_SEPAR(s[1])) |
| 290 | return 1; | 321 | return 1; |
| 291 | unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); | 322 | const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + 2); |
| 292 | return (size == 0) ? 0 : 2 + size; | 323 | return (size == 0) ? 0 : 2 + size; |
| 293 | } | 324 | } |
| 294 | 325 | ||
| @@ -296,11 +327,11 @@ static unsigned GetRootPrefixSize_Of_SuperPath(CFSTR s) | |||
| 296 | { | 327 | { |
| 297 | if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) | 328 | if (IS_UNC_WITH_SLASH(s + kSuperPathPrefixSize)) |
| 298 | { | 329 | { |
| 299 | unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); | 330 | const unsigned size = GetRootPrefixSize_Of_NetworkPath(s + kSuperUncPathPrefixSize); |
| 300 | return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; | 331 | return (size == 0) ? 0 : kSuperUncPathPrefixSize + size; |
| 301 | } | 332 | } |
| 302 | // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" | 333 | // we support \\?\c:\ paths and volume GUID paths \\?\Volume{GUID}\" |
| 303 | int pos = FindSepar(s + kSuperPathPrefixSize); | 334 | const int pos = FindSepar(s + kSuperPathPrefixSize); |
| 304 | if (pos < 0) | 335 | if (pos < 0) |
| 305 | return 0; | 336 | return 0; |
| 306 | return kSuperPathPrefixSize + pos + 1; | 337 | return kSuperPathPrefixSize + pos + 1; |
| @@ -379,42 +410,26 @@ unsigned GetRootPrefixSize(const wchar_t *s) throw() { return IS_SEPAR(s[0]) ? 1 | |||
| 379 | 410 | ||
| 380 | #ifndef UNDER_CE | 411 | #ifndef UNDER_CE |
| 381 | 412 | ||
| 382 | static bool GetCurDir(UString &path) | ||
| 383 | { | ||
| 384 | path.Empty(); | ||
| 385 | 413 | ||
| 386 | #ifdef _WIN32 | 414 | #ifdef USE_UNICODE_FSTRING |
| 387 | 415 | ||
| 388 | DWORD needLength; | 416 | #define GetCurDir NDir::GetCurrentDir |
| 389 | #ifndef _UNICODE | ||
| 390 | if (!g_IsNT) | ||
| 391 | { | ||
| 392 | TCHAR s[MAX_PATH + 2]; | ||
| 393 | s[0] = 0; | ||
| 394 | needLength = ::GetCurrentDirectory(MAX_PATH + 1, s); | ||
| 395 | path = fs2us(fas2fs(s)); | ||
| 396 | } | ||
| 397 | else | ||
| 398 | #endif | ||
| 399 | { | ||
| 400 | WCHAR s[MAX_PATH + 2]; | ||
| 401 | s[0] = 0; | ||
| 402 | needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, s); | ||
| 403 | path = s; | ||
| 404 | } | ||
| 405 | return (needLength > 0 && needLength <= MAX_PATH); | ||
| 406 | 417 | ||
| 407 | #else | 418 | #else |
| 408 | 419 | ||
| 420 | static bool GetCurDir(UString &path) | ||
| 421 | { | ||
| 422 | path.Empty(); | ||
| 409 | FString s; | 423 | FString s; |
| 410 | if (!NDir::GetCurrentDir(s)) | 424 | if (!NDir::GetCurrentDir(s)) |
| 411 | return false; | 425 | return false; |
| 412 | path = GetUnicodeString(s); | 426 | path = fs2us(s); |
| 413 | return true; | 427 | return true; |
| 414 | |||
| 415 | #endif | ||
| 416 | } | 428 | } |
| 417 | 429 | ||
| 430 | #endif | ||
| 431 | |||
| 432 | |||
| 418 | static bool ResolveDotsFolders(UString &s) | 433 | static bool ResolveDotsFolders(UString &s) |
| 419 | { | 434 | { |
| 420 | #ifdef _WIN32 | 435 | #ifdef _WIN32 |
| @@ -516,7 +531,7 @@ static bool AreThereDotsFolders(CFSTR s) | |||
| 516 | #endif | 531 | #endif |
| 517 | #endif // LONG_PATH_DOTS_FOLDERS_PARSING | 532 | #endif // LONG_PATH_DOTS_FOLDERS_PARSING |
| 518 | 533 | ||
| 519 | #ifdef WIN_LONG_PATH | 534 | #ifdef Z7_LONG_PATH |
| 520 | 535 | ||
| 521 | /* | 536 | /* |
| 522 | Most of Windows versions have problems, if some file or dir name | 537 | Most of Windows versions have problems, if some file or dir name |
| @@ -610,11 +625,11 @@ static bool GetSuperPathBase(CFSTR s, UString &res) | |||
| 610 | return true; | 625 | return true; |
| 611 | 626 | ||
| 612 | UString temp = fs2us(s); | 627 | UString temp = fs2us(s); |
| 613 | unsigned fixedSize = GetRootPrefixSize_Of_SuperPath(temp); | 628 | const unsigned fixedSize = GetRootPrefixSize_Of_SuperPath(temp); |
| 614 | if (fixedSize == 0) | 629 | if (fixedSize == 0) |
| 615 | return true; | 630 | return true; |
| 616 | 631 | ||
| 617 | UString rem = &temp[fixedSize]; | 632 | UString rem = temp.Ptr(fixedSize); |
| 618 | if (!ResolveDotsFolders(rem)) | 633 | if (!ResolveDotsFolders(rem)) |
| 619 | return true; | 634 | return true; |
| 620 | 635 | ||
| @@ -632,13 +647,13 @@ static bool GetSuperPathBase(CFSTR s, UString &res) | |||
| 632 | if (IS_SEPAR(s[1])) | 647 | if (IS_SEPAR(s[1])) |
| 633 | { | 648 | { |
| 634 | UString temp = fs2us(s + 2); | 649 | UString temp = fs2us(s + 2); |
| 635 | unsigned fixedSize = GetRootPrefixSize_Of_NetworkPath(temp); | 650 | const unsigned fixedSize = GetRootPrefixSize_Of_NetworkPath(temp); |
| 636 | // we ignore that error to allow short network paths server\share? | 651 | // we ignore that error to allow short network paths server\share? |
| 637 | /* | 652 | /* |
| 638 | if (fixedSize == 0) | 653 | if (fixedSize == 0) |
| 639 | return false; | 654 | return false; |
| 640 | */ | 655 | */ |
| 641 | UString rem = &temp[fixedSize]; | 656 | UString rem = temp.Ptr(fixedSize); |
| 642 | if (!ResolveDotsFolders(rem)) | 657 | if (!ResolveDotsFolders(rem)) |
| 643 | return false; | 658 | return false; |
| 644 | res += kSuperUncPrefix; | 659 | res += kSuperUncPrefix; |
| @@ -783,7 +798,7 @@ bool GetSuperPath(CFSTR path, UString &superPath) | |||
| 783 | return false; | 798 | return false; |
| 784 | } | 799 | } |
| 785 | */ | 800 | */ |
| 786 | #endif // WIN_LONG_PATH | 801 | #endif // Z7_LONG_PATH |
| 787 | 802 | ||
| 788 | bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) | 803 | bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) |
| 789 | { | 804 | { |
| @@ -801,8 +816,11 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) | |||
| 801 | 816 | ||
| 802 | #else | 817 | #else |
| 803 | 818 | ||
| 804 | unsigned prefixSize = GetRootPrefixSize(s); | 819 | const unsigned prefixSize = GetRootPrefixSize(s); |
| 805 | if (prefixSize != 0) | 820 | if (prefixSize != 0) |
| 821 | #ifdef _WIN32 | ||
| 822 | if (prefixSize != 1) | ||
| 823 | #endif | ||
| 806 | { | 824 | { |
| 807 | if (!AreThereDotsFolders(s + prefixSize)) | 825 | if (!AreThereDotsFolders(s + prefixSize)) |
| 808 | return true; | 826 | return true; |
| @@ -815,21 +833,9 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) | |||
| 815 | return true; | 833 | return true; |
| 816 | } | 834 | } |
| 817 | 835 | ||
| 818 | /* | ||
| 819 | FChar c = s[0]; | ||
| 820 | if (c == 0) | ||
| 821 | return true; | ||
| 822 | if (c == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0))) | ||
| 823 | return true; | ||
| 824 | if (IS_SEPAR(c) && IS_SEPAR(s[1])) | ||
| 825 | return true; | ||
| 826 | if (IsDrivePath(s)) | ||
| 827 | return true; | ||
| 828 | */ | ||
| 829 | |||
| 830 | UString curDir; | 836 | UString curDir; |
| 831 | if (dirPrefix) | 837 | if (dirPrefix && prefixSize == 0) |
| 832 | curDir = fs2us(dirPrefix); | 838 | curDir = fs2us(dirPrefix); // we use (dirPrefix), only if (s) path is relative |
| 833 | else | 839 | else |
| 834 | { | 840 | { |
| 835 | if (!GetCurDir(curDir)) | 841 | if (!GetCurDir(curDir)) |
| @@ -837,46 +843,40 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) | |||
| 837 | } | 843 | } |
| 838 | NormalizeDirPathPrefix(curDir); | 844 | NormalizeDirPathPrefix(curDir); |
| 839 | 845 | ||
| 840 | unsigned fixedSize = 0; | 846 | unsigned fixedSize = GetRootPrefixSize(curDir); |
| 841 | 847 | ||
| 842 | #ifdef _WIN32 | 848 | UString temp; |
| 843 | 849 | #ifdef _WIN32 | |
| 844 | if (IsSuperPath(curDir)) | 850 | if (prefixSize != 0) |
| 845 | { | 851 | { |
| 846 | fixedSize = GetRootPrefixSize_Of_SuperPath(curDir); | 852 | /* (s) is absolute path, but only (prefixSize == 1) is possible here. |
| 853 | So for full resolving we need root of current folder and | ||
| 854 | relative part of (s). */ | ||
| 855 | s += prefixSize; | ||
| 856 | // (s) is relative part now | ||
| 847 | if (fixedSize == 0) | 857 | if (fixedSize == 0) |
| 848 | return false; | ||
| 849 | } | ||
| 850 | else | ||
| 851 | { | ||
| 852 | if (IsDrivePath(curDir)) | ||
| 853 | fixedSize = kDrivePrefixSize; | ||
| 854 | else | ||
| 855 | { | 858 | { |
| 856 | if (!IsPathSepar(curDir[0]) || !IsPathSepar(curDir[1])) | 859 | // (curDir) is not absolute. |
| 857 | return false; | 860 | // That case is unexpected, but we support it too. |
| 858 | fixedSize = GetRootPrefixSize_Of_NetworkPath(curDir.Ptr(2)); | 861 | curDir.Empty(); |
| 859 | if (fixedSize == 0) | 862 | curDir.Add_PathSepar(); |
| 860 | return false; | 863 | fixedSize = 1; |
| 861 | fixedSize += 2; | 864 | // (curDir) now is just Separ character. |
| 865 | // So final (res) path later also will have Separ prefix. | ||
| 862 | } | 866 | } |
| 863 | } | 867 | } |
| 864 | |||
| 865 | #endif // _WIN32 | ||
| 866 | |||
| 867 | UString temp; | ||
| 868 | if (IS_SEPAR(s[0])) | ||
| 869 | { | ||
| 870 | temp = fs2us(s + 1); | ||
| 871 | } | ||
| 872 | else | 868 | else |
| 869 | #endif // _WIN32 | ||
| 873 | { | 870 | { |
| 874 | temp += curDir.Ptr(fixedSize); | 871 | // (s) is relative path |
| 875 | temp += fs2us(s); | 872 | temp = curDir.Ptr(fixedSize); |
| 873 | // (temp) is relative_part_of(curDir) | ||
| 876 | } | 874 | } |
| 875 | temp += fs2us(s); | ||
| 877 | if (!ResolveDotsFolders(temp)) | 876 | if (!ResolveDotsFolders(temp)) |
| 878 | return false; | 877 | return false; |
| 879 | curDir.DeleteFrom(fixedSize); | 878 | curDir.DeleteFrom(fixedSize); |
| 879 | // (curDir) now contains only absolute prefix part | ||
| 880 | res = us2fs(curDir); | 880 | res = us2fs(curDir); |
| 881 | res += us2fs(temp); | 881 | res += us2fs(temp); |
| 882 | 882 | ||
| @@ -885,6 +885,7 @@ bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res) | |||
| 885 | return true; | 885 | return true; |
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | |||
| 888 | bool GetFullPath(CFSTR path, FString &fullPath) | 889 | bool GetFullPath(CFSTR path, FString &fullPath) |
| 889 | { | 890 | { |
| 890 | return GetFullPath(NULL, path, fullPath); | 891 | return GetFullPath(NULL, path, fullPath); |
diff --git a/CPP/Windows/FileName.h b/CPP/Windows/FileName.h index de8bd13..219b656 100644 --- a/CPP/Windows/FileName.h +++ b/CPP/Windows/FileName.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/FileName.h | 1 | // Windows/FileName.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILE_NAME_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_NAME_H |
| 4 | #define __WINDOWS_FILE_NAME_H | 4 | #define ZIP7_INC_WINDOWS_FILE_NAME_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| @@ -54,6 +54,10 @@ bool IsDrivePath2(const wchar_t *s) throw(); // first 2 chars are drive chars li | |||
| 54 | bool IsSuperPath(const wchar_t *s) throw(); | 54 | bool IsSuperPath(const wchar_t *s) throw(); |
| 55 | bool IsSuperOrDevicePath(const wchar_t *s) throw(); | 55 | bool IsSuperOrDevicePath(const wchar_t *s) throw(); |
| 56 | 56 | ||
| 57 | bool IsAltStreamPrefixWithColon(const UString &s) throw(); | ||
| 58 | // returns true, if super prefix was removed | ||
| 59 | bool If_IsSuperPath_RemoveSuperPrefix(UString &s); | ||
| 60 | |||
| 57 | #ifndef USE_UNICODE_FSTRING | 61 | #ifndef USE_UNICODE_FSTRING |
| 58 | bool IsDrivePath2(CFSTR s) throw(); // first 2 chars are drive chars like "a:" | 62 | bool IsDrivePath2(CFSTR s) throw(); // first 2 chars are drive chars like "a:" |
| 59 | // bool IsDriveName2(CFSTR s) throw(); // is drive name like "a:" | 63 | // bool IsDriveName2(CFSTR s) throw(); // is drive name like "a:" |
| @@ -82,7 +86,7 @@ int FindAltStreamColon(CFSTR path) throw(); | |||
| 82 | bool IsAbsolutePath(const wchar_t *s) throw(); | 86 | bool IsAbsolutePath(const wchar_t *s) throw(); |
| 83 | unsigned GetRootPrefixSize(const wchar_t *s) throw(); | 87 | unsigned GetRootPrefixSize(const wchar_t *s) throw(); |
| 84 | 88 | ||
| 85 | #ifdef WIN_LONG_PATH | 89 | #ifdef Z7_LONG_PATH |
| 86 | 90 | ||
| 87 | const int kSuperPathType_UseOnlyMain = 0; | 91 | const int kSuperPathType_UseOnlyMain = 0; |
| 88 | const int kSuperPathType_UseOnlySuper = 1; | 92 | const int kSuperPathType_UseOnlySuper = 1; |
| @@ -92,16 +96,16 @@ int GetUseSuperPathType(CFSTR s) throw(); | |||
| 92 | bool GetSuperPath(CFSTR path, UString &superPath, bool onlyIfNew); | 96 | bool GetSuperPath(CFSTR path, UString &superPath, bool onlyIfNew); |
| 93 | bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew); | 97 | bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew); |
| 94 | 98 | ||
| 95 | #define USE_MAIN_PATH (__useSuperPathType != kSuperPathType_UseOnlySuper) | 99 | #define USE_MAIN_PATH (_useSuperPathType != kSuperPathType_UseOnlySuper) |
| 96 | #define USE_MAIN_PATH_2 (__useSuperPathType1 != kSuperPathType_UseOnlySuper && __useSuperPathType2 != kSuperPathType_UseOnlySuper) | 100 | #define USE_MAIN_PATH_2 (_useSuperPathType1 != kSuperPathType_UseOnlySuper && _useSuperPathType2 != kSuperPathType_UseOnlySuper) |
| 97 | 101 | ||
| 98 | #define USE_SUPER_PATH (__useSuperPathType != kSuperPathType_UseOnlyMain) | 102 | #define USE_SUPER_PATH (_useSuperPathType != kSuperPathType_UseOnlyMain) |
| 99 | #define USE_SUPER_PATH_2 (__useSuperPathType1 != kSuperPathType_UseOnlyMain || __useSuperPathType2 != kSuperPathType_UseOnlyMain) | 103 | #define USE_SUPER_PATH_2 (_useSuperPathType1 != kSuperPathType_UseOnlyMain || _useSuperPathType2 != kSuperPathType_UseOnlyMain) |
| 100 | 104 | ||
| 101 | #define IF_USE_MAIN_PATH int __useSuperPathType = GetUseSuperPathType(path); if (USE_MAIN_PATH) | 105 | #define IF_USE_MAIN_PATH int _useSuperPathType = GetUseSuperPathType(path); if (USE_MAIN_PATH) |
| 102 | #define IF_USE_MAIN_PATH_2(x1, x2) \ | 106 | #define IF_USE_MAIN_PATH_2(x1, x2) \ |
| 103 | int __useSuperPathType1 = GetUseSuperPathType(x1); \ | 107 | int _useSuperPathType1 = GetUseSuperPathType(x1); \ |
| 104 | int __useSuperPathType2 = GetUseSuperPathType(x2); \ | 108 | int _useSuperPathType2 = GetUseSuperPathType(x2); \ |
| 105 | if (USE_MAIN_PATH_2) | 109 | if (USE_MAIN_PATH_2) |
| 106 | 110 | ||
| 107 | #else | 111 | #else |
| @@ -109,8 +113,18 @@ bool GetSuperPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2, bool onlyIfNew) | |||
| 109 | #define IF_USE_MAIN_PATH | 113 | #define IF_USE_MAIN_PATH |
| 110 | #define IF_USE_MAIN_PATH_2(x1, x2) | 114 | #define IF_USE_MAIN_PATH_2(x1, x2) |
| 111 | 115 | ||
| 112 | #endif // WIN_LONG_PATH | 116 | #endif // Z7_LONG_PATH |
| 113 | 117 | ||
| 118 | /* | ||
| 119 | if (dirPrefix != NULL && (path) is relative) | ||
| 120 | { | ||
| 121 | (dirPrefix) will be used | ||
| 122 | result (fullPath) will contain prefix part of (dirPrefix). | ||
| 123 | } | ||
| 124 | Current_Dir path can be used in 2 cases: | ||
| 125 | 1) if (path) is relative && dirPrefix == NULL | ||
| 126 | 2) for _WIN32: if (path) is absolute starting wuth "\" | ||
| 127 | */ | ||
| 114 | bool GetFullPath(CFSTR dirPrefix, CFSTR path, FString &fullPath); | 128 | bool GetFullPath(CFSTR dirPrefix, CFSTR path, FString &fullPath); |
| 115 | bool GetFullPath(CFSTR path, FString &fullPath); | 129 | bool GetFullPath(CFSTR path, FString &fullPath); |
| 116 | 130 | ||
diff --git a/CPP/Windows/FileSystem.cpp b/CPP/Windows/FileSystem.cpp index 6259453..6a262d9 100644 --- a/CPP/Windows/FileSystem.cpp +++ b/CPP/Windows/FileSystem.cpp | |||
| @@ -71,14 +71,14 @@ UINT MyGetDriveType(CFSTR pathName) | |||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | typedef BOOL (WINAPI * GetDiskFreeSpaceExA_Pointer)( | 74 | typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExA)( |
| 75 | LPCSTR lpDirectoryName, // directory name | 75 | LPCSTR lpDirectoryName, // directory name |
| 76 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller | 76 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller |
| 77 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk | 77 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk |
| 78 | PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk | 78 | PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk |
| 79 | ); | 79 | ); |
| 80 | 80 | ||
| 81 | typedef BOOL (WINAPI * GetDiskFreeSpaceExW_Pointer)( | 81 | typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExW)( |
| 82 | LPCWSTR lpDirectoryName, // directory name | 82 | LPCWSTR lpDirectoryName, // directory name |
| 83 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller | 83 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller |
| 84 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk | 84 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk |
| @@ -92,12 +92,14 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, | |||
| 92 | #ifndef _UNICODE | 92 | #ifndef _UNICODE |
| 93 | if (!g_IsNT) | 93 | if (!g_IsNT) |
| 94 | { | 94 | { |
| 95 | GetDiskFreeSpaceExA_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExA_Pointer)(void *)GetProcAddress( | 95 | const |
| 96 | GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExA"); | 96 | Func_GetDiskFreeSpaceExA f = Z7_GET_PROC_ADDRESS( |
| 97 | if (pGetDiskFreeSpaceEx) | 97 | Func_GetDiskFreeSpaceExA, GetModuleHandle(TEXT("kernel32.dll")), |
| 98 | "GetDiskFreeSpaceExA"); | ||
| 99 | if (f) | ||
| 98 | { | 100 | { |
| 99 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; | 101 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; |
| 100 | sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | 102 | sizeIsDetected = BOOLToBool(f(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); |
| 101 | totalSize = totalSize2.QuadPart; | 103 | totalSize = totalSize2.QuadPart; |
| 102 | freeSize = freeSize2.QuadPart; | 104 | freeSize = freeSize2.QuadPart; |
| 103 | } | 105 | } |
| @@ -107,12 +109,14 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, | |||
| 107 | else | 109 | else |
| 108 | #endif | 110 | #endif |
| 109 | { | 111 | { |
| 110 | GetDiskFreeSpaceExW_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExW_Pointer)(void *)GetProcAddress( | 112 | const |
| 111 | GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExW"); | 113 | Func_GetDiskFreeSpaceExW f = Z7_GET_PROC_ADDRESS( |
| 112 | if (pGetDiskFreeSpaceEx) | 114 | Func_GetDiskFreeSpaceExW, GetModuleHandle(TEXT("kernel32.dll")), |
| 115 | "GetDiskFreeSpaceExW"); | ||
| 116 | if (f) | ||
| 113 | { | 117 | { |
| 114 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; | 118 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; |
| 115 | sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | 119 | sizeIsDetected = BOOLToBool(f(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); |
| 116 | totalSize = totalSize2.QuadPart; | 120 | totalSize = totalSize2.QuadPart; |
| 117 | freeSize = freeSize2.QuadPart; | 121 | freeSize = freeSize2.QuadPart; |
| 118 | } | 122 | } |
diff --git a/CPP/Windows/FileSystem.h b/CPP/Windows/FileSystem.h index 9b49a02..9f9e399 100644 --- a/CPP/Windows/FileSystem.h +++ b/CPP/Windows/FileSystem.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/FileSystem.h | 1 | // Windows/FileSystem.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_FILE_SYSTEM_H | 3 | #ifndef ZIP7_INC_WINDOWS_FILE_SYSTEM_H |
| 4 | #define __WINDOWS_FILE_SYSTEM_H | 4 | #define ZIP7_INC_WINDOWS_FILE_SYSTEM_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | #include "../Common/MyTypes.h" | 7 | #include "../Common/MyTypes.h" |
diff --git a/CPP/Windows/Handle.h b/CPP/Windows/Handle.h index 5878c83..6ae09ec 100644 --- a/CPP/Windows/Handle.h +++ b/CPP/Windows/Handle.h | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | // Windows/Handle.h | 1 | // Windows/Handle.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_HANDLE_H | 3 | #ifndef ZIP7_INC_WINDOWS_HANDLE_H |
| 4 | #define __WINDOWS_HANDLE_H | 4 | #define ZIP7_INC_WINDOWS_HANDLE_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | 7 | ||
| 8 | namespace NWindows { | 8 | namespace NWindows { |
| 9 | 9 | ||
| @@ -28,7 +28,7 @@ public: | |||
| 28 | void Attach(HANDLE handle) { _handle = handle; } | 28 | void Attach(HANDLE handle) { _handle = handle; } |
| 29 | HANDLE Detach() | 29 | HANDLE Detach() |
| 30 | { | 30 | { |
| 31 | HANDLE handle = _handle; | 31 | const HANDLE handle = _handle; |
| 32 | _handle = NULL; | 32 | _handle = NULL; |
| 33 | return handle; | 33 | return handle; |
| 34 | } | 34 | } |
diff --git a/CPP/Windows/MemoryGlobal.h b/CPP/Windows/MemoryGlobal.h index c217510..6852591 100644 --- a/CPP/Windows/MemoryGlobal.h +++ b/CPP/Windows/MemoryGlobal.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/MemoryGlobal.h | 1 | // Windows/MemoryGlobal.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_MEMORY_GLOBAL_H | 3 | #ifndef ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H |
| 4 | #define __WINDOWS_MEMORY_GLOBAL_H | 4 | #define ZIP7_INC_WINDOWS_MEMORY_GLOBAL_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | 7 | ||
| @@ -12,7 +12,7 @@ class CGlobal | |||
| 12 | { | 12 | { |
| 13 | HGLOBAL _global; | 13 | HGLOBAL _global; |
| 14 | public: | 14 | public: |
| 15 | CGlobal(): _global(NULL){}; | 15 | CGlobal(): _global(NULL) {} |
| 16 | ~CGlobal() { Free(); } | 16 | ~CGlobal() { Free(); } |
| 17 | operator HGLOBAL() const { return _global; } | 17 | operator HGLOBAL() const { return _global; } |
| 18 | void Attach(HGLOBAL hGlobal) | 18 | void Attach(HGLOBAL hGlobal) |
| @@ -22,7 +22,7 @@ public: | |||
| 22 | } | 22 | } |
| 23 | HGLOBAL Detach() | 23 | HGLOBAL Detach() |
| 24 | { | 24 | { |
| 25 | HGLOBAL h = _global; | 25 | const HGLOBAL h = _global; |
| 26 | _global = NULL; | 26 | _global = NULL; |
| 27 | return h; | 27 | return h; |
| 28 | } | 28 | } |
| @@ -42,10 +42,10 @@ public: | |||
| 42 | CGlobalLock(HGLOBAL hGlobal): _global(hGlobal) | 42 | CGlobalLock(HGLOBAL hGlobal): _global(hGlobal) |
| 43 | { | 43 | { |
| 44 | _ptr = GlobalLock(hGlobal); | 44 | _ptr = GlobalLock(hGlobal); |
| 45 | }; | 45 | } |
| 46 | ~CGlobalLock() | 46 | ~CGlobalLock() |
| 47 | { | 47 | { |
| 48 | if (_ptr != NULL) | 48 | if (_ptr) |
| 49 | GlobalUnlock(_global); | 49 | GlobalUnlock(_global); |
| 50 | } | 50 | } |
| 51 | }; | 51 | }; |
diff --git a/CPP/Windows/MemoryLock.cpp b/CPP/Windows/MemoryLock.cpp index 24866b1..0bd7504 100644 --- a/CPP/Windows/MemoryLock.cpp +++ b/CPP/Windows/MemoryLock.cpp | |||
| @@ -21,7 +21,10 @@ typedef BOOL (WINAPI * Func_LookupPrivilegeValue)(LPCTSTR lpSystemName, LPCTSTR | |||
| 21 | typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges, | 21 | typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges, |
| 22 | PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength); | 22 | PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength); |
| 23 | } | 23 | } |
| 24 | #define GET_PROC_ADDR(fff, name) Func_ ## fff my_ ## fff = (Func_ ## fff) (void(*)()) GetProcAddress(hModule, name) | 24 | |
| 25 | #define GET_PROC_ADDR(fff, name) \ | ||
| 26 | const Func_ ## fff my_ ## fff = Z7_GET_PROC_ADDRESS( \ | ||
| 27 | Func_ ## fff, hModule, name); | ||
| 25 | #endif | 28 | #endif |
| 26 | 29 | ||
| 27 | bool EnablePrivilege(LPCTSTR privilegeName, bool enable) | 30 | bool EnablePrivilege(LPCTSTR privilegeName, bool enable) |
| @@ -30,13 +33,19 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable) | |||
| 30 | 33 | ||
| 31 | #ifndef _UNICODE | 34 | #ifndef _UNICODE |
| 32 | 35 | ||
| 33 | HMODULE hModule = ::LoadLibrary(TEXT("Advapi32.dll")); | 36 | const HMODULE hModule = ::LoadLibrary(TEXT("advapi32.dll")); |
| 34 | if (hModule == NULL) | 37 | if (!hModule) |
| 35 | return false; | 38 | return false; |
| 36 | 39 | ||
| 37 | GET_PROC_ADDR(OpenProcessToken, "OpenProcessToken"); | 40 | GET_PROC_ADDR( |
| 38 | GET_PROC_ADDR(LookupPrivilegeValue, "LookupPrivilegeValueA"); | 41 | OpenProcessToken, |
| 39 | GET_PROC_ADDR(AdjustTokenPrivileges, "AdjustTokenPrivileges"); | 42 | "OpenProcessToken") |
| 43 | GET_PROC_ADDR( | ||
| 44 | LookupPrivilegeValue, | ||
| 45 | "LookupPrivilegeValueA") | ||
| 46 | GET_PROC_ADDR( | ||
| 47 | AdjustTokenPrivileges, | ||
| 48 | "AdjustTokenPrivileges") | ||
| 40 | 49 | ||
| 41 | if (my_OpenProcessToken && | 50 | if (my_OpenProcessToken && |
| 42 | my_AdjustTokenPrivileges && | 51 | my_AdjustTokenPrivileges && |
| @@ -85,10 +94,13 @@ typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *); | |||
| 85 | unsigned Get_LargePages_RiskLevel() | 94 | unsigned Get_LargePages_RiskLevel() |
| 86 | { | 95 | { |
| 87 | OSVERSIONINFOEXW vi; | 96 | OSVERSIONINFOEXW vi; |
| 88 | HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); | 97 | const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); |
| 89 | if (!ntdll) | 98 | if (!ntdll) |
| 90 | return 0; | 99 | return 0; |
| 91 | Func_RtlGetVersion func = (Func_RtlGetVersion)(void *)GetProcAddress(ntdll, "RtlGetVersion"); | 100 | const |
| 101 | Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS( | ||
| 102 | Func_RtlGetVersion, ntdll, | ||
| 103 | "RtlGetVersion"); | ||
| 92 | if (!func) | 104 | if (!func) |
| 93 | return 0; | 105 | return 0; |
| 94 | func(&vi); | 106 | func(&vi); |
diff --git a/CPP/Windows/MemoryLock.h b/CPP/Windows/MemoryLock.h index dcaf182..2b85002 100644 --- a/CPP/Windows/MemoryLock.h +++ b/CPP/Windows/MemoryLock.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/MemoryLock.h | 1 | // Windows/MemoryLock.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_MEMORY_LOCK_H | 3 | #ifndef ZIP7_INC_WINDOWS_MEMORY_LOCK_H |
| 4 | #define __WINDOWS_MEMORY_LOCK_H | 4 | #define ZIP7_INC_WINDOWS_MEMORY_LOCK_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Menu.cpp b/CPP/Windows/Menu.cpp index 3ad6953..af54c66 100644 --- a/CPP/Windows/Menu.cpp +++ b/CPP/Windows/Menu.cpp | |||
| @@ -22,8 +22,23 @@ contain additional member: | |||
| 22 | HBITMAP hbmpItem; | 22 | HBITMAP hbmpItem; |
| 23 | #endif | 23 | #endif |
| 24 | If we compile the source code with (WINVER >= 0x0500), some functions | 24 | If we compile the source code with (WINVER >= 0x0500), some functions |
| 25 | will not work at NT 4.0, if cbSize is set as sizeof(MENUITEMINFO*). | 25 | will not work at NT4, if cbSize is set as sizeof(MENUITEMINFO). |
| 26 | So we use size of old version of structure. */ | 26 | So we use size of old version of structure in some conditions. |
| 27 | Win98 probably supports full structure including hbmpItem. | ||
| 28 | |||
| 29 | We have 2 ways to get/set string in menu item: | ||
| 30 | win95/NT4: we must use MIIM_TYPE only. | ||
| 31 | MIIM_TYPE : Retrieves or sets the fType and dwTypeData members. | ||
| 32 | win98/win2000: there are new flags that can be used instead of MIIM_TYPE: | ||
| 33 | MIIM_FTYPE : Retrieves or sets the fType member. | ||
| 34 | MIIM_STRING : Retrieves or sets the dwTypeData member. | ||
| 35 | |||
| 36 | Windows versions probably support MIIM_TYPE flag, if we set MENUITEMINFO::cbSize | ||
| 37 | as sizeof of old (small) MENUITEMINFO that doesn't include (hbmpItem) field. | ||
| 38 | But do all Windows versions support old MIIM_TYPE flag, if we use | ||
| 39 | MENUITEMINFO::cbSize as sizeof of new (big) MENUITEMINFO including (hbmpItem) field ? | ||
| 40 | win10 probably supports any combination of small/big (cbSize) and old/new MIIM_TYPE/MIIM_STRING. | ||
| 41 | */ | ||
| 27 | 42 | ||
| 28 | #if defined(UNDER_CE) || defined(_WIN64) || (WINVER < 0x0500) | 43 | #if defined(UNDER_CE) || defined(_WIN64) || (WINVER < 0x0500) |
| 29 | #ifndef _UNICODE | 44 | #ifndef _UNICODE |
| @@ -36,20 +51,31 @@ So we use size of old version of structure. */ | |||
| 36 | #define my_compatib_MENUITEMINFOA_size MY_STRUCT_SIZE_BEFORE(MENUITEMINFOA, hbmpItem) | 51 | #define my_compatib_MENUITEMINFOA_size MY_STRUCT_SIZE_BEFORE(MENUITEMINFOA, hbmpItem) |
| 37 | #endif | 52 | #endif |
| 38 | #define my_compatib_MENUITEMINFOW_size MY_STRUCT_SIZE_BEFORE(MENUITEMINFOW, hbmpItem) | 53 | #define my_compatib_MENUITEMINFOW_size MY_STRUCT_SIZE_BEFORE(MENUITEMINFOW, hbmpItem) |
| 54 | #if defined(__clang__) && __clang_major__ >= 13 | ||
| 55 | // error : performing pointer subtraction with a null pointer may have undefined behavior | ||
| 56 | #pragma GCC diagnostic ignored "-Wnull-pointer-subtraction" | ||
| 39 | #endif | 57 | #endif |
| 58 | #endif | ||
| 59 | |||
| 60 | |||
| 61 | #define COPY_MENUITEM_field(d, s, name) \ | ||
| 62 | d.name = s.name; | ||
| 63 | |||
| 64 | #define COPY_MENUITEM_fields(d, s) \ | ||
| 65 | COPY_MENUITEM_field(d, s, fMask) \ | ||
| 66 | COPY_MENUITEM_field(d, s, fType) \ | ||
| 67 | COPY_MENUITEM_field(d, s, fState) \ | ||
| 68 | COPY_MENUITEM_field(d, s, wID) \ | ||
| 69 | COPY_MENUITEM_field(d, s, hSubMenu) \ | ||
| 70 | COPY_MENUITEM_field(d, s, hbmpChecked) \ | ||
| 71 | COPY_MENUITEM_field(d, s, hbmpUnchecked) \ | ||
| 72 | COPY_MENUITEM_field(d, s, dwItemData) \ | ||
| 40 | 73 | ||
| 41 | static void ConvertItemToSysForm(const CMenuItem &item, MENUITEMINFOW &si) | 74 | static void ConvertItemToSysForm(const CMenuItem &item, MENUITEMINFOW &si) |
| 42 | { | 75 | { |
| 43 | ZeroMemory(&si, sizeof(si)); | 76 | ZeroMemory(&si, sizeof(si)); |
| 44 | si.cbSize = my_compatib_MENUITEMINFOW_size; // sizeof(si); | 77 | si.cbSize = my_compatib_MENUITEMINFOW_size; // sizeof(si); |
| 45 | si.fMask = item.fMask; | 78 | COPY_MENUITEM_fields(si, item) |
| 46 | si.fType = item.fType; | ||
| 47 | si.fState = item.fState; | ||
| 48 | si.wID = item.wID; | ||
| 49 | si.hSubMenu = item.hSubMenu; | ||
| 50 | si.hbmpChecked = item.hbmpChecked; | ||
| 51 | si.hbmpUnchecked = item.hbmpUnchecked; | ||
| 52 | si.dwItemData = item.dwItemData; | ||
| 53 | } | 79 | } |
| 54 | 80 | ||
| 55 | #ifndef _UNICODE | 81 | #ifndef _UNICODE |
| @@ -57,62 +83,63 @@ static void ConvertItemToSysForm(const CMenuItem &item, MENUITEMINFOA &si) | |||
| 57 | { | 83 | { |
| 58 | ZeroMemory(&si, sizeof(si)); | 84 | ZeroMemory(&si, sizeof(si)); |
| 59 | si.cbSize = my_compatib_MENUITEMINFOA_size; // sizeof(si); | 85 | si.cbSize = my_compatib_MENUITEMINFOA_size; // sizeof(si); |
| 60 | si.fMask = item.fMask; | 86 | COPY_MENUITEM_fields(si, item) |
| 61 | si.fType = item.fType; | ||
| 62 | si.fState = item.fState; | ||
| 63 | si.wID = item.wID; | ||
| 64 | si.hSubMenu = item.hSubMenu; | ||
| 65 | si.hbmpChecked = item.hbmpChecked; | ||
| 66 | si.hbmpUnchecked = item.hbmpUnchecked; | ||
| 67 | si.dwItemData = item.dwItemData; | ||
| 68 | } | 87 | } |
| 69 | #endif | 88 | #endif |
| 70 | 89 | ||
| 71 | static void ConvertItemToMyForm(const MENUITEMINFOW &si, CMenuItem &item) | 90 | static void ConvertItemToMyForm(const MENUITEMINFOW &si, CMenuItem &item) |
| 72 | { | 91 | { |
| 73 | item.fMask = si.fMask; | 92 | COPY_MENUITEM_fields(item, si) |
| 74 | item.fType = si.fType; | ||
| 75 | item.fState = si.fState; | ||
| 76 | item.wID = si.wID; | ||
| 77 | item.hSubMenu = si.hSubMenu; | ||
| 78 | item.hbmpChecked = si.hbmpChecked; | ||
| 79 | item.hbmpUnchecked = si.hbmpUnchecked; | ||
| 80 | item.dwItemData = si.dwItemData; | ||
| 81 | } | 93 | } |
| 82 | 94 | ||
| 83 | #ifndef _UNICODE | 95 | #ifndef _UNICODE |
| 84 | static void ConvertItemToMyForm(const MENUITEMINFOA &si, CMenuItem &item) | 96 | static void ConvertItemToMyForm(const MENUITEMINFOA &si, CMenuItem &item) |
| 85 | { | 97 | { |
| 86 | item.fMask = si.fMask; | 98 | COPY_MENUITEM_fields(item, si) |
| 87 | item.fType = si.fType; | ||
| 88 | item.fState = si.fState; | ||
| 89 | item.wID = si.wID; | ||
| 90 | item.hSubMenu = si.hSubMenu; | ||
| 91 | item.hbmpChecked = si.hbmpChecked; | ||
| 92 | item.hbmpUnchecked = si.hbmpUnchecked; | ||
| 93 | item.dwItemData = si.dwItemData; | ||
| 94 | } | 99 | } |
| 95 | #endif | 100 | #endif |
| 96 | 101 | ||
| 97 | bool CMenu::GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) | 102 | |
| 103 | bool CMenu::GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) const | ||
| 98 | { | 104 | { |
| 99 | const UINT kMaxSize = 512; | 105 | item.StringValue.Empty(); |
| 106 | const unsigned kMaxSize = 512; | ||
| 100 | #ifndef _UNICODE | 107 | #ifndef _UNICODE |
| 101 | if (!g_IsNT) | 108 | if (!g_IsNT) |
| 102 | { | 109 | { |
| 103 | CHAR s[kMaxSize + 1]; | ||
| 104 | MENUITEMINFOA si; | 110 | MENUITEMINFOA si; |
| 105 | ConvertItemToSysForm(item, si); | 111 | ConvertItemToSysForm(item, si); |
| 106 | if (item.IsString()) | 112 | const bool isString = item.IsString(); |
| 113 | unsigned bufSize = kMaxSize; | ||
| 114 | AString a; | ||
| 115 | if (isString) | ||
| 107 | { | 116 | { |
| 108 | si.cch = kMaxSize; | 117 | si.cch = bufSize; |
| 109 | si.dwTypeData = s; | 118 | si.dwTypeData = a.GetBuf(bufSize); |
| 110 | } | 119 | } |
| 111 | if (GetItemInfo(itemIndex, byPosition, &si)) | 120 | bool res = GetItemInfo(itemIndex, byPosition, &si); |
| 121 | if (isString) | ||
| 122 | a.ReleaseBuf_CalcLen(bufSize); | ||
| 123 | if (!res) | ||
| 124 | return false; | ||
| 112 | { | 125 | { |
| 126 | if (isString && si.cch >= bufSize - 1) | ||
| 127 | { | ||
| 128 | si.dwTypeData = NULL; | ||
| 129 | res = GetItemInfo(itemIndex, byPosition, &si); | ||
| 130 | if (!res) | ||
| 131 | return false; | ||
| 132 | si.cch++; | ||
| 133 | bufSize = si.cch; | ||
| 134 | si.dwTypeData = a.GetBuf(bufSize); | ||
| 135 | res = GetItemInfo(itemIndex, byPosition, &si); | ||
| 136 | a.ReleaseBuf_CalcLen(bufSize); | ||
| 137 | if (!res) | ||
| 138 | return false; | ||
| 139 | } | ||
| 113 | ConvertItemToMyForm(si, item); | 140 | ConvertItemToMyForm(si, item); |
| 114 | if (item.IsString()) | 141 | if (isString) |
| 115 | item.StringValue = GetUnicodeString(s); | 142 | item.StringValue = GetUnicodeString(a); |
| 116 | return true; | 143 | return true; |
| 117 | } | 144 | } |
| 118 | } | 145 | } |
| @@ -120,24 +147,45 @@ bool CMenu::GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) | |||
| 120 | #endif | 147 | #endif |
| 121 | { | 148 | { |
| 122 | wchar_t s[kMaxSize + 1]; | 149 | wchar_t s[kMaxSize + 1]; |
| 150 | s[0] = 0; | ||
| 123 | MENUITEMINFOW si; | 151 | MENUITEMINFOW si; |
| 124 | ConvertItemToSysForm(item, si); | 152 | ConvertItemToSysForm(item, si); |
| 125 | if (item.IsString()) | 153 | const bool isString = item.IsString(); |
| 154 | unsigned bufSize = kMaxSize; | ||
| 155 | if (isString) | ||
| 126 | { | 156 | { |
| 127 | si.cch = kMaxSize; | 157 | si.cch = bufSize; |
| 128 | si.dwTypeData = s; | 158 | si.dwTypeData = s; |
| 129 | } | 159 | } |
| 130 | if (GetItemInfo(itemIndex, byPosition, &si)) | 160 | bool res = GetItemInfo(itemIndex, byPosition, &si); |
| 161 | if (!res) | ||
| 162 | return false; | ||
| 163 | if (isString) | ||
| 131 | { | 164 | { |
| 132 | ConvertItemToMyForm(si, item); | 165 | s[Z7_ARRAY_SIZE(s) - 1] = 0; |
| 133 | if (item.IsString()) | 166 | item.StringValue = s; |
| 134 | item.StringValue = s; | 167 | if (si.cch >= bufSize - 1) |
| 135 | return true; | 168 | { |
| 169 | si.dwTypeData = NULL; | ||
| 170 | res = GetItemInfo(itemIndex, byPosition, &si); | ||
| 171 | if (!res) | ||
| 172 | return false; | ||
| 173 | si.cch++; | ||
| 174 | bufSize = si.cch; | ||
| 175 | si.dwTypeData = item.StringValue.GetBuf(bufSize); | ||
| 176 | res = GetItemInfo(itemIndex, byPosition, &si); | ||
| 177 | item.StringValue.ReleaseBuf_CalcLen(bufSize); | ||
| 178 | if (!res) | ||
| 179 | return false; | ||
| 180 | } | ||
| 181 | // if (item.StringValue.Len() != si.cch) throw 123; // for debug | ||
| 136 | } | 182 | } |
| 183 | ConvertItemToMyForm(si, item); | ||
| 184 | return true; | ||
| 137 | } | 185 | } |
| 138 | return false; | ||
| 139 | } | 186 | } |
| 140 | 187 | ||
| 188 | |||
| 141 | bool CMenu::SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item) | 189 | bool CMenu::SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item) |
| 142 | { | 190 | { |
| 143 | #ifndef _UNICODE | 191 | #ifndef _UNICODE |
| @@ -164,6 +212,7 @@ bool CMenu::SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item) | |||
| 164 | } | 212 | } |
| 165 | } | 213 | } |
| 166 | 214 | ||
| 215 | |||
| 167 | bool CMenu::InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item) | 216 | bool CMenu::InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item) |
| 168 | { | 217 | { |
| 169 | #ifndef _UNICODE | 218 | #ifndef _UNICODE |
| @@ -188,11 +237,11 @@ bool CMenu::InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item) | |||
| 188 | si.dwTypeData = item.StringValue.Ptr_non_const(); | 237 | si.dwTypeData = item.StringValue.Ptr_non_const(); |
| 189 | #ifdef UNDER_CE | 238 | #ifdef UNDER_CE |
| 190 | UINT flags = (item.fType & MFT_SEPARATOR) ? MF_SEPARATOR : MF_STRING; | 239 | UINT flags = (item.fType & MFT_SEPARATOR) ? MF_SEPARATOR : MF_STRING; |
| 191 | UINT id = item.wID; | 240 | UINT_PTR id = item.wID; |
| 192 | if ((item.fMask & MIIM_SUBMENU) != 0) | 241 | if ((item.fMask & MIIM_SUBMENU) != 0) |
| 193 | { | 242 | { |
| 194 | flags |= MF_POPUP; | 243 | flags |= MF_POPUP; |
| 195 | id = (UINT)item.hSubMenu; | 244 | id = (UINT_PTR)item.hSubMenu; |
| 196 | } | 245 | } |
| 197 | if (!Insert(itemIndex, flags | (byPosition ? MF_BYPOSITION : MF_BYCOMMAND), id, item.StringValue)) | 246 | if (!Insert(itemIndex, flags | (byPosition ? MF_BYPOSITION : MF_BYCOMMAND), id, item.StringValue)) |
| 198 | return false; | 247 | return false; |
diff --git a/CPP/Windows/Menu.h b/CPP/Windows/Menu.h index aacdc7c..e1de4c4 100644 --- a/CPP/Windows/Menu.h +++ b/CPP/Windows/Menu.h | |||
| @@ -1,14 +1,27 @@ | |||
| 1 | // Windows/Menu.h | 1 | // Windows/Menu.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_MENU_H | 3 | #ifndef ZIP7_INC_WINDOWS_MENU_H |
| 4 | #define __WINDOWS_MENU_H | 4 | #define ZIP7_INC_WINDOWS_MENU_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | ||
| 6 | #include "../Common/MyString.h" | 7 | #include "../Common/MyString.h" |
| 7 | 8 | ||
| 8 | #include "Defs.h" | 9 | #include "Defs.h" |
| 9 | 10 | ||
| 10 | namespace NWindows { | 11 | namespace NWindows { |
| 11 | 12 | ||
| 13 | #ifndef MIIM_STRING | ||
| 14 | #define MIIM_STRING 0x00000040 | ||
| 15 | #endif | ||
| 16 | /* | ||
| 17 | #ifndef MIIM_BITMAP | ||
| 18 | #define MIIM_BITMAP 0x00000080 | ||
| 19 | #endif | ||
| 20 | */ | ||
| 21 | #ifndef MIIM_FTYPE | ||
| 22 | #define MIIM_FTYPE 0x00000100 | ||
| 23 | #endif | ||
| 24 | |||
| 12 | struct CMenuItem | 25 | struct CMenuItem |
| 13 | { | 26 | { |
| 14 | UString StringValue; | 27 | UString StringValue; |
| @@ -23,24 +36,23 @@ struct CMenuItem | |||
| 23 | // LPTSTR dwTypeData; | 36 | // LPTSTR dwTypeData; |
| 24 | // UINT cch; | 37 | // UINT cch; |
| 25 | // HBITMAP hbmpItem; | 38 | // HBITMAP hbmpItem; |
| 26 | bool IsString() const // change it MIIM_STRING | 39 | bool IsString() const { return (fMask & (MIIM_TYPE | MIIM_STRING)) != 0; } |
| 27 | { return ((fMask & MIIM_TYPE) != 0 && (fType == MFT_STRING)); } | ||
| 28 | bool IsSeparator() const { return (fType == MFT_SEPARATOR); } | 40 | bool IsSeparator() const { return (fType == MFT_SEPARATOR); } |
| 29 | CMenuItem(): fMask(0), fType(0), fState(0), wID(0), hSubMenu(0), hbmpChecked(0), | 41 | CMenuItem(): fMask(0), fType(0), fState(0), wID(0), |
| 30 | hbmpUnchecked(0), dwItemData(0) {} | 42 | hSubMenu(NULL), hbmpChecked(NULL), hbmpUnchecked(NULL), dwItemData(0) {} |
| 31 | }; | 43 | }; |
| 32 | 44 | ||
| 33 | class CMenu | 45 | class CMenu |
| 34 | { | 46 | { |
| 35 | HMENU _menu; | 47 | HMENU _menu; |
| 36 | public: | 48 | public: |
| 37 | CMenu(): _menu(NULL) {}; | 49 | CMenu(): _menu(NULL) {} |
| 38 | operator HMENU() const { return _menu; } | 50 | operator HMENU() const { return _menu; } |
| 39 | void Attach(HMENU menu) { _menu = menu; } | 51 | void Attach(HMENU menu) { _menu = menu; } |
| 40 | 52 | ||
| 41 | HMENU Detach() | 53 | HMENU Detach() |
| 42 | { | 54 | { |
| 43 | HMENU menu = _menu; | 55 | const HMENU menu = _menu; |
| 44 | _menu = NULL; | 56 | _menu = NULL; |
| 45 | return menu; | 57 | return menu; |
| 46 | } | 58 | } |
| @@ -59,27 +71,27 @@ public: | |||
| 59 | 71 | ||
| 60 | bool Destroy() | 72 | bool Destroy() |
| 61 | { | 73 | { |
| 62 | if (_menu == NULL) | 74 | if (!_menu) |
| 63 | return false; | 75 | return false; |
| 64 | return BOOLToBool(::DestroyMenu(Detach())); | 76 | return BOOLToBool(::DestroyMenu(Detach())); |
| 65 | } | 77 | } |
| 66 | 78 | ||
| 67 | int GetItemCount() | 79 | int GetItemCount() const |
| 68 | { | 80 | { |
| 69 | #ifdef UNDER_CE | 81 | #ifdef UNDER_CE |
| 70 | for (int i = 0;; i++) | 82 | for (unsigned i = 0;; i++) |
| 71 | { | 83 | { |
| 72 | CMenuItem item; | 84 | CMenuItem item; |
| 73 | item.fMask = MIIM_STATE; | 85 | item.fMask = MIIM_STATE; |
| 74 | if (!GetItem(i, true, item)) | 86 | if (!GetItem(i, true, item)) |
| 75 | return i; | 87 | return (int)i; |
| 76 | } | 88 | } |
| 77 | #else | 89 | #else |
| 78 | return GetMenuItemCount(_menu); | 90 | return GetMenuItemCount(_menu); |
| 79 | #endif | 91 | #endif |
| 80 | } | 92 | } |
| 81 | 93 | ||
| 82 | HMENU GetSubMenu(int pos) { return ::GetSubMenu(_menu, pos); } | 94 | HMENU GetSubMenu(int pos) const { return ::GetSubMenu(_menu, pos); } |
| 83 | #ifndef UNDER_CE | 95 | #ifndef UNDER_CE |
| 84 | /* | 96 | /* |
| 85 | bool GetItemString(UINT idItem, UINT flag, CSysString &result) | 97 | bool GetItemString(UINT idItem, UINT flag, CSysString &result) |
| @@ -93,11 +105,11 @@ public: | |||
| 93 | return (len != 0); | 105 | return (len != 0); |
| 94 | } | 106 | } |
| 95 | */ | 107 | */ |
| 96 | UINT GetItemID(int pos) { return ::GetMenuItemID(_menu, pos); } | 108 | UINT GetItemID(int pos) const { return ::GetMenuItemID(_menu, pos); } |
| 97 | UINT GetItemState(UINT id, UINT flags) { return ::GetMenuState(_menu, id, flags); } | 109 | UINT GetItemState(UINT id, UINT flags) const { return ::GetMenuState(_menu, id, flags); } |
| 98 | #endif | 110 | #endif |
| 99 | 111 | ||
| 100 | bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) | 112 | bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) const |
| 101 | { return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } | 113 | { return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } |
| 102 | bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) | 114 | bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo) |
| 103 | { return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } | 115 | { return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } |
| @@ -118,7 +130,7 @@ public: | |||
| 118 | void RemoveAllItems() { RemoveAllItemsFrom(0); } | 130 | void RemoveAllItems() { RemoveAllItemsFrom(0); } |
| 119 | 131 | ||
| 120 | #ifndef _UNICODE | 132 | #ifndef _UNICODE |
| 121 | bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) | 133 | bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) const |
| 122 | { return BOOLToBool(::GetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } | 134 | { return BOOLToBool(::GetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } |
| 123 | bool InsertItem(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) | 135 | bool InsertItem(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo) |
| 124 | { return BOOLToBool(::InsertMenuItemW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } | 136 | { return BOOLToBool(::InsertMenuItemW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); } |
| @@ -127,7 +139,7 @@ public: | |||
| 127 | bool AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem); | 139 | bool AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem); |
| 128 | #endif | 140 | #endif |
| 129 | 141 | ||
| 130 | bool GetItem(UINT itemIndex, bool byPosition, CMenuItem &item); | 142 | bool GetItem(UINT itemIndex, bool byPosition, CMenuItem &item) const; |
| 131 | bool SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item); | 143 | bool SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item); |
| 132 | bool InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item); | 144 | bool InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item); |
| 133 | 145 | ||
| @@ -147,10 +159,10 @@ class CMenuDestroyer | |||
| 147 | CMenu *_menu; | 159 | CMenu *_menu; |
| 148 | public: | 160 | public: |
| 149 | CMenuDestroyer(CMenu &menu): _menu(&menu) {} | 161 | CMenuDestroyer(CMenu &menu): _menu(&menu) {} |
| 150 | CMenuDestroyer(): _menu(0) {} | 162 | CMenuDestroyer(): _menu(NULL) {} |
| 151 | ~CMenuDestroyer() { if (_menu) _menu->Destroy(); } | 163 | ~CMenuDestroyer() { if (_menu) _menu->Destroy(); } |
| 152 | void Attach(CMenu &menu) { _menu = &menu; } | 164 | void Attach(CMenu &menu) { _menu = &menu; } |
| 153 | void Disable() { _menu = 0; } | 165 | void Disable() { _menu = NULL; } |
| 154 | }; | 166 | }; |
| 155 | 167 | ||
| 156 | } | 168 | } |
diff --git a/CPP/Windows/NationalTime.cpp b/CPP/Windows/NationalTime.cpp index 0dcd31e..d3c38de 100644 --- a/CPP/Windows/NationalTime.cpp +++ b/CPP/Windows/NationalTime.cpp | |||
| @@ -16,8 +16,8 @@ bool MyGetTimeFormat(LCID locale, DWORD flags, CONST SYSTEMTIME *time, | |||
| 16 | if (numChars == 0) | 16 | if (numChars == 0) |
| 17 | return false; | 17 | return false; |
| 18 | numChars = ::GetTimeFormat(locale, flags, time, format, | 18 | numChars = ::GetTimeFormat(locale, flags, time, format, |
| 19 | resultString.GetBuf(numChars), numChars + 1); | 19 | resultString.GetBuf((unsigned)numChars), numChars + 1); |
| 20 | resultString.ReleaseBuf_CalcLen(numChars); | 20 | resultString.ReleaseBuf_CalcLen((unsigned)numChars); |
| 21 | return (numChars != 0); | 21 | return (numChars != 0); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| @@ -29,8 +29,8 @@ bool MyGetDateFormat(LCID locale, DWORD flags, CONST SYSTEMTIME *time, | |||
| 29 | if (numChars == 0) | 29 | if (numChars == 0) |
| 30 | return false; | 30 | return false; |
| 31 | numChars = ::GetDateFormat(locale, flags, time, format, | 31 | numChars = ::GetDateFormat(locale, flags, time, format, |
| 32 | resultString.GetBuf(numChars), numChars + 1); | 32 | resultString.GetBuf((unsigned)numChars), numChars + 1); |
| 33 | resultString.ReleaseBuf_CalcLen(numChars); | 33 | resultString.ReleaseBuf_CalcLen((unsigned)numChars); |
| 34 | return (numChars != 0); | 34 | return (numChars != 0); |
| 35 | } | 35 | } |
| 36 | 36 | ||
diff --git a/CPP/Windows/NationalTime.h b/CPP/Windows/NationalTime.h index 49b0e5e..32ba479 100644 --- a/CPP/Windows/NationalTime.h +++ b/CPP/Windows/NationalTime.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/NationalTime.h | 1 | // Windows/NationalTime.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_NATIONAL_TIME_H | 3 | #ifndef ZIP7_INC_WINDOWS_NATIONAL_TIME_H |
| 4 | #define __WINDOWS_NATIONAL_TIME_H | 4 | #define ZIP7_INC_WINDOWS_NATIONAL_TIME_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/Net.cpp b/CPP/Windows/Net.cpp index 2a3952a..0ac82d4 100644 --- a/CPP/Windows/Net.cpp +++ b/CPP/Windows/Net.cpp | |||
| @@ -14,13 +14,41 @@ | |||
| 14 | extern bool g_IsNT; | 14 | extern bool g_IsNT; |
| 15 | #endif | 15 | #endif |
| 16 | 16 | ||
| 17 | extern "C" | ||
| 18 | { | ||
| 19 | #if !defined(WNetGetResourceParent) | ||
| 20 | // #if defined(Z7_OLD_WIN_SDK) | ||
| 21 | // #if (WINVER >= 0x0400) | ||
| 22 | DWORD APIENTRY WNetGetResourceParentA(IN LPNETRESOURCEA lpNetResource, | ||
| 23 | OUT LPVOID lpBuffer, IN OUT LPDWORD lpcbBuffer); | ||
| 24 | DWORD APIENTRY WNetGetResourceParentW(IN LPNETRESOURCEW lpNetResource, | ||
| 25 | OUT LPVOID lpBuffer, IN OUT LPDWORD lpcbBuffer); | ||
| 26 | #ifdef UNICODE | ||
| 27 | #define WNetGetResourceParent WNetGetResourceParentW | ||
| 28 | #else | ||
| 29 | #define WNetGetResourceParent WNetGetResourceParentA | ||
| 30 | #endif | ||
| 31 | |||
| 32 | DWORD APIENTRY WNetGetResourceInformationA(IN LPNETRESOURCEA lpNetResource, | ||
| 33 | OUT LPVOID lpBuffer, IN OUT LPDWORD lpcbBuffer, OUT LPSTR *lplpSystem); | ||
| 34 | DWORD APIENTRY WNetGetResourceInformationW(IN LPNETRESOURCEW lpNetResource, | ||
| 35 | OUT LPVOID lpBuffer, IN OUT LPDWORD lpcbBuffer, OUT LPWSTR *lplpSystem); | ||
| 36 | #ifdef UNICODE | ||
| 37 | #define WNetGetResourceInformation WNetGetResourceInformationW | ||
| 38 | #else | ||
| 39 | #define WNetGetResourceInformation WNetGetResourceInformationA | ||
| 40 | #endif | ||
| 41 | // #endif // (WINVER >= 0x0400) | ||
| 42 | #endif | ||
| 43 | } | ||
| 44 | |||
| 17 | namespace NWindows { | 45 | namespace NWindows { |
| 18 | namespace NNet { | 46 | namespace NNet { |
| 19 | 47 | ||
| 20 | DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResource) | 48 | DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResource) |
| 21 | { | 49 | { |
| 22 | Close(); | 50 | Close(); |
| 23 | DWORD result = ::WNetOpenEnum(scope, type, usage, netResource, &_handle); | 51 | const DWORD result = ::WNetOpenEnum(scope, type, usage, netResource, &_handle); |
| 24 | _handleAllocated = (result == NO_ERROR); | 52 | _handleAllocated = (result == NO_ERROR); |
| 25 | return result; | 53 | return result; |
| 26 | } | 54 | } |
| @@ -29,7 +57,7 @@ DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResourc | |||
| 29 | DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCEW netResource) | 57 | DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCEW netResource) |
| 30 | { | 58 | { |
| 31 | Close(); | 59 | Close(); |
| 32 | DWORD result = ::WNetOpenEnumW(scope, type, usage, netResource, &_handle); | 60 | const DWORD result = ::WNetOpenEnumW(scope, type, usage, netResource, &_handle); |
| 33 | _handleAllocated = (result == NO_ERROR); | 61 | _handleAllocated = (result == NO_ERROR); |
| 34 | return result; | 62 | return result; |
| 35 | } | 63 | } |
| @@ -37,7 +65,7 @@ DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCEW netResour | |||
| 37 | 65 | ||
| 38 | static void SetComplexString(bool &defined, CSysString &destString, LPCTSTR srcString) | 66 | static void SetComplexString(bool &defined, CSysString &destString, LPCTSTR srcString) |
| 39 | { | 67 | { |
| 40 | defined = (srcString != 0); | 68 | defined = (srcString != NULL); |
| 41 | if (defined) | 69 | if (defined) |
| 42 | destString = srcString; | 70 | destString = srcString; |
| 43 | else | 71 | else |
| @@ -179,7 +207,7 @@ DWORD CEnum::Close() | |||
| 179 | { | 207 | { |
| 180 | if (!_handleAllocated) | 208 | if (!_handleAllocated) |
| 181 | return NO_ERROR; | 209 | return NO_ERROR; |
| 182 | DWORD result = ::WNetCloseEnum(_handle); | 210 | const DWORD result = ::WNetCloseEnum(_handle); |
| 183 | _handleAllocated = (result != NO_ERROR); | 211 | _handleAllocated = (result != NO_ERROR); |
| 184 | return result; | 212 | return result; |
| 185 | } | 213 | } |
| @@ -204,7 +232,7 @@ DWORD CEnum::Next(CResource &resource) | |||
| 204 | ZeroMemory(lpnrLocal, kBufferSize); | 232 | ZeroMemory(lpnrLocal, kBufferSize); |
| 205 | DWORD bufferSize = kBufferSize; | 233 | DWORD bufferSize = kBufferSize; |
| 206 | DWORD numEntries = 1; | 234 | DWORD numEntries = 1; |
| 207 | DWORD result = Next(&numEntries, lpnrLocal, &bufferSize); | 235 | const DWORD result = Next(&numEntries, lpnrLocal, &bufferSize); |
| 208 | if (result != NO_ERROR) | 236 | if (result != NO_ERROR) |
| 209 | return result; | 237 | return result; |
| 210 | if (numEntries != 1) | 238 | if (numEntries != 1) |
| @@ -224,7 +252,7 @@ DWORD CEnum::Next(CResourceW &resource) | |||
| 224 | ZeroMemory(lpnrLocal, kBufferSize); | 252 | ZeroMemory(lpnrLocal, kBufferSize); |
| 225 | DWORD bufferSize = kBufferSize; | 253 | DWORD bufferSize = kBufferSize; |
| 226 | DWORD numEntries = 1; | 254 | DWORD numEntries = 1; |
| 227 | DWORD result = NextW(&numEntries, lpnrLocal, &bufferSize); | 255 | const DWORD result = NextW(&numEntries, lpnrLocal, &bufferSize); |
| 228 | if (result != NO_ERROR) | 256 | if (result != NO_ERROR) |
| 229 | return result; | 257 | return result; |
| 230 | if (numEntries != 1) | 258 | if (numEntries != 1) |
| @@ -233,7 +261,7 @@ DWORD CEnum::Next(CResourceW &resource) | |||
| 233 | return result; | 261 | return result; |
| 234 | } | 262 | } |
| 235 | CResource resourceA; | 263 | CResource resourceA; |
| 236 | DWORD result = Next(resourceA); | 264 | const DWORD result = Next(resourceA); |
| 237 | ConvertResourceToResourceW(resourceA, resource); | 265 | ConvertResourceToResourceW(resourceA, resource); |
| 238 | return result; | 266 | return result; |
| 239 | } | 267 | } |
| @@ -249,7 +277,7 @@ DWORD GetResourceParent(const CResource &resource, CResource &parentResource) | |||
| 249 | DWORD bufferSize = kBufferSize; | 277 | DWORD bufferSize = kBufferSize; |
| 250 | NETRESOURCE netResource; | 278 | NETRESOURCE netResource; |
| 251 | ConvertCResourceToNETRESOURCE(resource, netResource); | 279 | ConvertCResourceToNETRESOURCE(resource, netResource); |
| 252 | DWORD result = ::WNetGetResourceParent(&netResource, lpnrLocal, &bufferSize); | 280 | const DWORD result = ::WNetGetResourceParent(&netResource, lpnrLocal, &bufferSize); |
| 253 | if (result != NO_ERROR) | 281 | if (result != NO_ERROR) |
| 254 | return result; | 282 | return result; |
| 255 | ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource); | 283 | ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource); |
| @@ -268,7 +296,7 @@ DWORD GetResourceParent(const CResourceW &resource, CResourceW &parentResource) | |||
| 268 | DWORD bufferSize = kBufferSize; | 296 | DWORD bufferSize = kBufferSize; |
| 269 | NETRESOURCEW netResource; | 297 | NETRESOURCEW netResource; |
| 270 | ConvertCResourceToNETRESOURCE(resource, netResource); | 298 | ConvertCResourceToNETRESOURCE(resource, netResource); |
| 271 | DWORD result = ::WNetGetResourceParentW(&netResource, lpnrLocal, &bufferSize); | 299 | const DWORD result = ::WNetGetResourceParentW(&netResource, lpnrLocal, &bufferSize); |
| 272 | if (result != NO_ERROR) | 300 | if (result != NO_ERROR) |
| 273 | return result; | 301 | return result; |
| 274 | ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource); | 302 | ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource); |
| @@ -276,7 +304,7 @@ DWORD GetResourceParent(const CResourceW &resource, CResourceW &parentResource) | |||
| 276 | } | 304 | } |
| 277 | CResource resourceA, parentResourceA; | 305 | CResource resourceA, parentResourceA; |
| 278 | ConvertResourceWToResource(resource, resourceA); | 306 | ConvertResourceWToResource(resource, resourceA); |
| 279 | DWORD result = GetResourceParent(resourceA, parentResourceA); | 307 | const DWORD result = GetResourceParent(resourceA, parentResourceA); |
| 280 | ConvertResourceToResourceW(parentResourceA, parentResource); | 308 | ConvertResourceToResourceW(parentResourceA, parentResource); |
| 281 | return result; | 309 | return result; |
| 282 | } | 310 | } |
| @@ -293,11 +321,11 @@ DWORD GetResourceInformation(const CResource &resource, | |||
| 293 | NETRESOURCE netResource; | 321 | NETRESOURCE netResource; |
| 294 | ConvertCResourceToNETRESOURCE(resource, netResource); | 322 | ConvertCResourceToNETRESOURCE(resource, netResource); |
| 295 | LPTSTR lplpSystem; | 323 | LPTSTR lplpSystem; |
| 296 | DWORD result = ::WNetGetResourceInformation(&netResource, | 324 | const DWORD result = ::WNetGetResourceInformation(&netResource, |
| 297 | lpnrLocal, &bufferSize, &lplpSystem); | 325 | lpnrLocal, &bufferSize, &lplpSystem); |
| 298 | if (result != NO_ERROR) | 326 | if (result != NO_ERROR) |
| 299 | return result; | 327 | return result; |
| 300 | if (lplpSystem != 0) | 328 | if (lplpSystem != NULL) |
| 301 | systemPathPart = lplpSystem; | 329 | systemPathPart = lplpSystem; |
| 302 | ConvertNETRESOURCEToCResource(lpnrLocal[0], destResource); | 330 | ConvertNETRESOURCEToCResource(lpnrLocal[0], destResource); |
| 303 | return result; | 331 | return result; |
| @@ -317,7 +345,7 @@ DWORD GetResourceInformation(const CResourceW &resource, | |||
| 317 | NETRESOURCEW netResource; | 345 | NETRESOURCEW netResource; |
| 318 | ConvertCResourceToNETRESOURCE(resource, netResource); | 346 | ConvertCResourceToNETRESOURCE(resource, netResource); |
| 319 | LPWSTR lplpSystem; | 347 | LPWSTR lplpSystem; |
| 320 | DWORD result = ::WNetGetResourceInformationW(&netResource, | 348 | const DWORD result = ::WNetGetResourceInformationW(&netResource, |
| 321 | lpnrLocal, &bufferSize, &lplpSystem); | 349 | lpnrLocal, &bufferSize, &lplpSystem); |
| 322 | if (result != NO_ERROR) | 350 | if (result != NO_ERROR) |
| 323 | return result; | 351 | return result; |
| @@ -329,7 +357,7 @@ DWORD GetResourceInformation(const CResourceW &resource, | |||
| 329 | CResource resourceA, destResourceA; | 357 | CResource resourceA, destResourceA; |
| 330 | ConvertResourceWToResource(resource, resourceA); | 358 | ConvertResourceWToResource(resource, resourceA); |
| 331 | AString systemPathPartA; | 359 | AString systemPathPartA; |
| 332 | DWORD result = GetResourceInformation(resourceA, destResourceA, systemPathPartA); | 360 | const DWORD result = GetResourceInformation(resourceA, destResourceA, systemPathPartA); |
| 333 | ConvertResourceToResourceW(destResourceA, destResource); | 361 | ConvertResourceToResourceW(destResourceA, destResource); |
| 334 | systemPathPart = GetUnicodeString(systemPathPartA); | 362 | systemPathPart = GetUnicodeString(systemPathPartA); |
| 335 | return result; | 363 | return result; |
diff --git a/CPP/Windows/Net.h b/CPP/Windows/Net.h index 7b60b1b..a954bdb 100644 --- a/CPP/Windows/Net.h +++ b/CPP/Windows/Net.h | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | // Windows/Net.h | 1 | // Windows/Net.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_NET_H | 3 | #ifndef ZIP7_INC_WINDOWS_NET_H |
| 4 | #define __WINDOWS_NET_H | 4 | #define ZIP7_INC_WINDOWS_NET_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | #include "../Common/MyWindows.h" | ||
| 7 | 8 | ||
| 8 | namespace NWindows { | 9 | namespace NWindows { |
| 9 | namespace NNet { | 10 | namespace NNet { |
diff --git a/CPP/Windows/NtCheck.h b/CPP/Windows/NtCheck.h index 0af3291..362a05a 100644 --- a/CPP/Windows/NtCheck.h +++ b/CPP/Windows/NtCheck.h | |||
| @@ -1,19 +1,29 @@ | |||
| 1 | // Windows/NtCheck.h | 1 | // Windows/NtCheck.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_NT_CHECK_H | 3 | #ifndef ZIP7_INC_WINDOWS_NT_CHECK_H |
| 4 | #define __WINDOWS_NT_CHECK_H | 4 | #define ZIP7_INC_WINDOWS_NT_CHECK_H |
| 5 | 5 | ||
| 6 | #ifdef _WIN32 | 6 | #ifdef _WIN32 |
| 7 | 7 | ||
| 8 | #include "../Common/MyWindows.h" | 8 | #include "../Common/MyWindows.h" |
| 9 | 9 | ||
| 10 | #if !defined(_WIN64) && !defined(UNDER_CE) | 10 | #if !defined(_WIN64) && !defined(UNDER_CE) |
| 11 | |||
| 12 | #if defined(_MSC_VER) && _MSC_VER >= 1900 | ||
| 13 | #pragma warning(push) | ||
| 14 | // GetVersionExW was declared deprecated | ||
| 15 | #pragma warning(disable : 4996) | ||
| 16 | #endif | ||
| 11 | static inline bool IsItWindowsNT() | 17 | static inline bool IsItWindowsNT() |
| 12 | { | 18 | { |
| 13 | OSVERSIONINFO vi; | 19 | OSVERSIONINFO vi; |
| 14 | vi.dwOSVersionInfoSize = sizeof(vi); | 20 | vi.dwOSVersionInfoSize = sizeof(vi); |
| 15 | return (::GetVersionEx(&vi) && vi.dwPlatformId == VER_PLATFORM_WIN32_NT); | 21 | return (::GetVersionEx(&vi) && vi.dwPlatformId == VER_PLATFORM_WIN32_NT); |
| 16 | } | 22 | } |
| 23 | #if defined(_MSC_VER) && _MSC_VER >= 1900 | ||
| 24 | #pragma warning(pop) | ||
| 25 | #endif | ||
| 26 | |||
| 17 | #endif | 27 | #endif |
| 18 | 28 | ||
| 19 | #ifndef _UNICODE | 29 | #ifndef _UNICODE |
diff --git a/CPP/Windows/ProcessMessages.h b/CPP/Windows/ProcessMessages.h index b2558a0..aa98bbb 100644 --- a/CPP/Windows/ProcessMessages.h +++ b/CPP/Windows/ProcessMessages.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/ProcessMessages.h | 1 | // Windows/ProcessMessages.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_PROCESSMESSAGES_H | 3 | #ifndef ZIP7_INC_WINDOWS_PROCESS_MESSAGES_H |
| 4 | #define __WINDOWS_PROCESSMESSAGES_H | 4 | #define ZIP7_INC_WINDOWS_PROCESS_MESSAGES_H |
| 5 | 5 | ||
| 6 | namespace NWindows { | 6 | namespace NWindows { |
| 7 | 7 | ||
diff --git a/CPP/Windows/ProcessUtils.cpp b/CPP/Windows/ProcessUtils.cpp index 9bf0538..607b4bb 100644 --- a/CPP/Windows/ProcessUtils.cpp +++ b/CPP/Windows/ProcessUtils.cpp | |||
| @@ -46,9 +46,9 @@ WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir) | |||
| 46 | #endif | 46 | #endif |
| 47 | params; | 47 | params; |
| 48 | #ifdef UNDER_CE | 48 | #ifdef UNDER_CE |
| 49 | curDir = 0; | 49 | curDir = NULL; |
| 50 | #else | 50 | #else |
| 51 | imageName = 0; | 51 | imageName = NULL; |
| 52 | #endif | 52 | #endif |
| 53 | PROCESS_INFORMATION pi; | 53 | PROCESS_INFORMATION pi; |
| 54 | BOOL result; | 54 | BOOL result; |
| @@ -57,12 +57,12 @@ WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir) | |||
| 57 | { | 57 | { |
| 58 | STARTUPINFOA si; | 58 | STARTUPINFOA si; |
| 59 | si.cb = sizeof(si); | 59 | si.cb = sizeof(si); |
| 60 | si.lpReserved = 0; | 60 | si.lpReserved = NULL; |
| 61 | si.lpDesktop = 0; | 61 | si.lpDesktop = NULL; |
| 62 | si.lpTitle = 0; | 62 | si.lpTitle = NULL; |
| 63 | si.dwFlags = 0; | 63 | si.dwFlags = 0; |
| 64 | si.cbReserved2 = 0; | 64 | si.cbReserved2 = 0; |
| 65 | si.lpReserved2 = 0; | 65 | si.lpReserved2 = NULL; |
| 66 | 66 | ||
| 67 | CSysString curDirA; | 67 | CSysString curDirA; |
| 68 | if (curDir != 0) | 68 | if (curDir != 0) |
| @@ -76,12 +76,12 @@ WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir) | |||
| 76 | { | 76 | { |
| 77 | STARTUPINFOW si; | 77 | STARTUPINFOW si; |
| 78 | si.cb = sizeof(si); | 78 | si.cb = sizeof(si); |
| 79 | si.lpReserved = 0; | 79 | si.lpReserved = NULL; |
| 80 | si.lpDesktop = 0; | 80 | si.lpDesktop = NULL; |
| 81 | si.lpTitle = 0; | 81 | si.lpTitle = NULL; |
| 82 | si.dwFlags = 0; | 82 | si.dwFlags = 0; |
| 83 | si.cbReserved2 = 0; | 83 | si.cbReserved2 = 0; |
| 84 | si.lpReserved2 = 0; | 84 | si.lpReserved2 = NULL; |
| 85 | 85 | ||
| 86 | result = CreateProcessW(imageName, params2.Ptr_non_const(), | 86 | result = CreateProcessW(imageName, params2.Ptr_non_const(), |
| 87 | NULL, NULL, FALSE, 0, NULL, curDir, &si, &pi); | 87 | NULL, NULL, FALSE, 0, NULL, curDir, &si, &pi); |
| @@ -96,7 +96,7 @@ WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir) | |||
| 96 | WRes MyCreateProcess(LPCWSTR imageName, const UString ¶ms) | 96 | WRes MyCreateProcess(LPCWSTR imageName, const UString ¶ms) |
| 97 | { | 97 | { |
| 98 | CProcess process; | 98 | CProcess process; |
| 99 | return process.Create(imageName, params, 0); | 99 | return process.Create(imageName, params, NULL); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | } | 102 | } |
diff --git a/CPP/Windows/ProcessUtils.h b/CPP/Windows/ProcessUtils.h index e46f9ab..b1fce3a 100644 --- a/CPP/Windows/ProcessUtils.h +++ b/CPP/Windows/ProcessUtils.h | |||
| @@ -1,9 +1,41 @@ | |||
| 1 | // Windows/ProcessUtils.h | 1 | // Windows/ProcessUtils.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_PROCESS_UTILS_H | 3 | #ifndef ZIP7_INC_WINDOWS_PROCESS_UTILS_H |
| 4 | #define __WINDOWS_PROCESS_UTILS_H | 4 | #define ZIP7_INC_WINDOWS_PROCESS_UTILS_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | ||
| 7 | |||
| 8 | #ifndef Z7_OLD_WIN_SDK | ||
| 9 | |||
| 10 | #if defined(__MINGW32__) || defined(__MINGW64__) | ||
| 11 | #include <psapi.h> | ||
| 12 | #else | ||
| 6 | #include <Psapi.h> | 13 | #include <Psapi.h> |
| 14 | #endif | ||
| 15 | |||
| 16 | #else // Z7_OLD_WIN_SDK | ||
| 17 | |||
| 18 | typedef struct _MODULEINFO { | ||
| 19 | LPVOID lpBaseOfDll; | ||
| 20 | DWORD SizeOfImage; | ||
| 21 | LPVOID EntryPoint; | ||
| 22 | } MODULEINFO, *LPMODULEINFO; | ||
| 23 | |||
| 24 | typedef struct _PROCESS_MEMORY_COUNTERS { | ||
| 25 | DWORD cb; | ||
| 26 | DWORD PageFaultCount; | ||
| 27 | SIZE_T PeakWorkingSetSize; | ||
| 28 | SIZE_T WorkingSetSize; | ||
| 29 | SIZE_T QuotaPeakPagedPoolUsage; | ||
| 30 | SIZE_T QuotaPagedPoolUsage; | ||
| 31 | SIZE_T QuotaPeakNonPagedPoolUsage; | ||
| 32 | SIZE_T QuotaNonPagedPoolUsage; | ||
| 33 | SIZE_T PagefileUsage; | ||
| 34 | SIZE_T PeakPagefileUsage; | ||
| 35 | } PROCESS_MEMORY_COUNTERS; | ||
| 36 | typedef PROCESS_MEMORY_COUNTERS *PPROCESS_MEMORY_COUNTERS; | ||
| 37 | |||
| 38 | #endif // Z7_OLD_WIN_SDK | ||
| 7 | 39 | ||
| 8 | #include "../Common/MyString.h" | 40 | #include "../Common/MyString.h" |
| 9 | 41 | ||
| @@ -18,7 +50,7 @@ public: | |||
| 18 | bool Open(DWORD desiredAccess, bool inheritHandle, DWORD processId) | 50 | bool Open(DWORD desiredAccess, bool inheritHandle, DWORD processId) |
| 19 | { | 51 | { |
| 20 | _handle = ::OpenProcess(desiredAccess, inheritHandle, processId); | 52 | _handle = ::OpenProcess(desiredAccess, inheritHandle, processId); |
| 21 | return (_handle != 0); | 53 | return (_handle != NULL); |
| 22 | } | 54 | } |
| 23 | 55 | ||
| 24 | #ifndef UNDER_CE | 56 | #ifndef UNDER_CE |
| @@ -43,9 +75,14 @@ public: | |||
| 43 | { return BOOLToBool(::ReadProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesRead)); } | 75 | { return BOOLToBool(::ReadProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesRead)); } |
| 44 | 76 | ||
| 45 | bool WriteMemory(LPVOID baseAddress, LPCVOID buffer, SIZE_T size, SIZE_T* numberOfBytesWritten) | 77 | bool WriteMemory(LPVOID baseAddress, LPCVOID buffer, SIZE_T size, SIZE_T* numberOfBytesWritten) |
| 46 | { return BOOLToBool(::WriteProcessMemory(_handle, baseAddress, buffer, size, numberOfBytesWritten)); } | 78 | { return BOOLToBool(::WriteProcessMemory(_handle, baseAddress, |
| 47 | 79 | #ifdef Z7_OLD_WIN_SDK | |
| 48 | bool FlushInstructionCache(LPCVOID baseAddress = 0, SIZE_T size = 0) | 80 | (LPVOID) |
| 81 | #endif | ||
| 82 | buffer, | ||
| 83 | size, numberOfBytesWritten)); } | ||
| 84 | |||
| 85 | bool FlushInstructionCache(LPCVOID baseAddress = NULL, SIZE_T size = 0) | ||
| 49 | { return BOOLToBool(::FlushInstructionCache(_handle, baseAddress, size)); } | 86 | { return BOOLToBool(::FlushInstructionCache(_handle, baseAddress, size)); } |
| 50 | 87 | ||
| 51 | LPVOID VirtualAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect) | 88 | LPVOID VirtualAlloc(LPVOID address, SIZE_T size, DWORD allocationType, DWORD protect) |
| @@ -56,17 +93,17 @@ public: | |||
| 56 | 93 | ||
| 57 | // Process Status API (PSAPI) | 94 | // Process Status API (PSAPI) |
| 58 | 95 | ||
| 96 | /* | ||
| 59 | bool EmptyWorkingSet() | 97 | bool EmptyWorkingSet() |
| 60 | { return BOOLToBool(::EmptyWorkingSet(_handle)); } | 98 | { return BOOLToBool(::EmptyWorkingSet(_handle)); } |
| 61 | bool EnumModules(HMODULE *hModules, DWORD arraySizeInBytes, LPDWORD receivedBytes) | 99 | bool EnumModules(HMODULE *hModules, DWORD arraySizeInBytes, LPDWORD receivedBytes) |
| 62 | { return BOOLToBool(::EnumProcessModules(_handle, hModules, arraySizeInBytes, receivedBytes)); } | 100 | { return BOOLToBool(::EnumProcessModules(_handle, hModules, arraySizeInBytes, receivedBytes)); } |
| 63 | |||
| 64 | DWORD MyGetModuleBaseName(HMODULE hModule, LPTSTR baseName, DWORD size) | 101 | DWORD MyGetModuleBaseName(HMODULE hModule, LPTSTR baseName, DWORD size) |
| 65 | { return ::GetModuleBaseName(_handle, hModule, baseName, size); } | 102 | { return ::GetModuleBaseName(_handle, hModule, baseName, size); } |
| 66 | bool MyGetModuleBaseName(HMODULE hModule, CSysString &name) | 103 | bool MyGetModuleBaseName(HMODULE hModule, CSysString &name) |
| 67 | { | 104 | { |
| 68 | const unsigned len = MAX_PATH + 100; | 105 | const unsigned len = MAX_PATH + 100; |
| 69 | DWORD resultLen = MyGetModuleBaseName(hModule, name.GetBuf(len), len); | 106 | const DWORD resultLen = MyGetModuleBaseName(hModule, name.GetBuf(len), len); |
| 70 | name.ReleaseBuf_CalcLen(len); | 107 | name.ReleaseBuf_CalcLen(len); |
| 71 | return (resultLen != 0); | 108 | return (resultLen != 0); |
| 72 | } | 109 | } |
| @@ -76,7 +113,7 @@ public: | |||
| 76 | bool MyGetModuleFileNameEx(HMODULE hModule, CSysString &name) | 113 | bool MyGetModuleFileNameEx(HMODULE hModule, CSysString &name) |
| 77 | { | 114 | { |
| 78 | const unsigned len = MAX_PATH + 100; | 115 | const unsigned len = MAX_PATH + 100; |
| 79 | DWORD resultLen = MyGetModuleFileNameEx(hModule, name.GetBuf(len), len); | 116 | const DWORD resultLen = MyGetModuleFileNameEx(hModule, name.GetBuf(len), len); |
| 80 | name.ReleaseBuf_CalcLen(len); | 117 | name.ReleaseBuf_CalcLen(len); |
| 81 | return (resultLen != 0); | 118 | return (resultLen != 0); |
| 82 | } | 119 | } |
| @@ -85,6 +122,7 @@ public: | |||
| 85 | { return BOOLToBool(::GetModuleInformation(_handle, hModule, moduleInfo, sizeof(MODULEINFO))); } | 122 | { return BOOLToBool(::GetModuleInformation(_handle, hModule, moduleInfo, sizeof(MODULEINFO))); } |
| 86 | bool GetMemoryInfo(PPROCESS_MEMORY_COUNTERS memCounters) | 123 | bool GetMemoryInfo(PPROCESS_MEMORY_COUNTERS memCounters) |
| 87 | { return BOOLToBool(::GetProcessMemoryInfo(_handle, memCounters, sizeof(PROCESS_MEMORY_COUNTERS))); } | 124 | { return BOOLToBool(::GetProcessMemoryInfo(_handle, memCounters, sizeof(PROCESS_MEMORY_COUNTERS))); } |
| 125 | */ | ||
| 88 | 126 | ||
| 89 | #endif | 127 | #endif |
| 90 | 128 | ||
diff --git a/CPP/Windows/PropVariant.cpp b/CPP/Windows/PropVariant.cpp index 2b17950..457b1dc 100644 --- a/CPP/Windows/PropVariant.cpp +++ b/CPP/Windows/PropVariant.cpp | |||
| @@ -197,17 +197,17 @@ BSTR CPropVariant::AllocBstr(unsigned numChars) | |||
| 197 | 197 | ||
| 198 | void CPropVariant::Set_Int32(Int32 value) throw() | 198 | void CPropVariant::Set_Int32(Int32 value) throw() |
| 199 | { | 199 | { |
| 200 | SET_PROP_id_dest(VT_I4, lVal); | 200 | SET_PROP_id_dest(VT_I4, lVal) |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | void CPropVariant::Set_Int64(Int64 value) throw() | 203 | void CPropVariant::Set_Int64(Int64 value) throw() |
| 204 | { | 204 | { |
| 205 | SET_PROP_id_dest(VT_I8, hVal.QuadPart); | 205 | SET_PROP_id_dest(VT_I8, hVal.QuadPart) |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | #define SET_PROP_FUNC(type, id, dest) \ | 208 | #define SET_PROP_FUNC(type, id, dest) \ |
| 209 | CPropVariant& CPropVariant::operator=(type value) throw() \ | 209 | CPropVariant& CPropVariant::operator=(type value) throw() \ |
| 210 | { SET_PROP_id_dest(id, dest); return *this; } | 210 | { SET_PROP_id_dest(id, dest) return *this; } |
| 211 | 211 | ||
| 212 | SET_PROP_FUNC(Byte, VT_UI1, bVal) | 212 | SET_PROP_FUNC(Byte, VT_UI1, bVal) |
| 213 | // SET_PROP_FUNC(Int16, VT_I2, iVal) | 213 | // SET_PROP_FUNC(Int16, VT_I2, iVal) |
| @@ -245,7 +245,7 @@ SET_PROP_FUNC(const FILETIME &, VT_FILETIME, filetime) | |||
| 245 | we call system functions for VT_BSTR and for unknown typed | 245 | we call system functions for VT_BSTR and for unknown typed |
| 246 | */ | 246 | */ |
| 247 | 247 | ||
| 248 | CPropVariant::~CPropVariant() | 248 | CPropVariant::~CPropVariant() throw() |
| 249 | { | 249 | { |
| 250 | switch ((unsigned)vt) | 250 | switch ((unsigned)vt) |
| 251 | { | 251 | { |
diff --git a/CPP/Windows/PropVariant.h b/CPP/Windows/PropVariant.h index 171402f..f358fde 100644 --- a/CPP/Windows/PropVariant.h +++ b/CPP/Windows/PropVariant.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/PropVariant.h | 1 | // Windows/PropVariant.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_PROP_VARIANT_H | 3 | #ifndef ZIP7_INC_WINDOWS_PROP_VARIANT_H |
| 4 | #define __WINDOWS_PROP_VARIANT_H | 4 | #define ZIP7_INC_WINDOWS_PROP_VARIANT_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyTypes.h" |
| 7 | #include "../Common/MyWindows.h" | 7 | #include "../Common/MyWindows.h" |
| @@ -64,7 +64,7 @@ public: | |||
| 64 | // wReserved2 = 0; | 64 | // wReserved2 = 0; |
| 65 | // wReserved3 = 0; | 65 | // wReserved3 = 0; |
| 66 | // uhVal.QuadPart = 0; | 66 | // uhVal.QuadPart = 0; |
| 67 | bstrVal = 0; | 67 | bstrVal = NULL; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | 70 | ||
| @@ -104,13 +104,13 @@ public: | |||
| 104 | const unsigned ns100 = wReserved2; | 104 | const unsigned ns100 = wReserved2; |
| 105 | if (prec == 0 | 105 | if (prec == 0 |
| 106 | && prec <= k_PropVar_TimePrec_1ns | 106 | && prec <= k_PropVar_TimePrec_1ns |
| 107 | && ns100 < 100 | 107 | && ns100 < 100 |
| 108 | && wReserved3 == 0) | 108 | && wReserved3 == 0) |
| 109 | return ns100; | 109 | return ns100; |
| 110 | return 0; | 110 | return 0; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | ~CPropVariant(); | 113 | ~CPropVariant() throw(); |
| 114 | CPropVariant(const PROPVARIANT &varSrc); | 114 | CPropVariant(const PROPVARIANT &varSrc); |
| 115 | CPropVariant(const CPropVariant &varSrc); | 115 | CPropVariant(const CPropVariant &varSrc); |
| 116 | CPropVariant(BSTR bstrSrc); | 116 | CPropVariant(BSTR bstrSrc); |
diff --git a/CPP/Windows/PropVariantConv.cpp b/CPP/Windows/PropVariantConv.cpp index 3c9bbd1..5fb96a7 100644 --- a/CPP/Windows/PropVariantConv.cpp +++ b/CPP/Windows/PropVariantConv.cpp | |||
| @@ -36,17 +36,17 @@ bool ConvertUtcFileTimeToString2(const FILETIME &utc, unsigned ns100, char *s, i | |||
| 36 | s[0] = (char)('0' + val / 10); | 36 | s[0] = (char)('0' + val / 10); |
| 37 | s += 4; | 37 | s += 4; |
| 38 | } | 38 | } |
| 39 | UINT_TO_STR_2('-', st.wMonth); | 39 | UINT_TO_STR_2('-', st.wMonth) |
| 40 | UINT_TO_STR_2('-', st.wDay); | 40 | UINT_TO_STR_2('-', st.wDay) |
| 41 | 41 | ||
| 42 | if (level > kTimestampPrintLevel_DAY) | 42 | if (level > kTimestampPrintLevel_DAY) |
| 43 | { | 43 | { |
| 44 | UINT_TO_STR_2(' ', st.wHour); | 44 | UINT_TO_STR_2(' ', st.wHour) |
| 45 | UINT_TO_STR_2(':', st.wMinute); | 45 | UINT_TO_STR_2(':', st.wMinute) |
| 46 | 46 | ||
| 47 | if (level >= kTimestampPrintLevel_SEC) | 47 | if (level >= kTimestampPrintLevel_SEC) |
| 48 | { | 48 | { |
| 49 | UINT_TO_STR_2(':', st.wSecond); | 49 | UINT_TO_STR_2(':', st.wSecond) |
| 50 | 50 | ||
| 51 | if (level > kTimestampPrintLevel_SEC) | 51 | if (level > kTimestampPrintLevel_SEC) |
| 52 | { | 52 | { |
diff --git a/CPP/Windows/PropVariantConv.h b/CPP/Windows/PropVariantConv.h index 6067784..ec5223b 100644 --- a/CPP/Windows/PropVariantConv.h +++ b/CPP/Windows/PropVariantConv.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/PropVariantConv.h | 1 | // Windows/PropVariantConv.h |
| 2 | 2 | ||
| 3 | #ifndef __PROP_VARIANT_CONV_H | 3 | #ifndef ZIP7_INC_PROP_VARIANT_CONV_H |
| 4 | #define __PROP_VARIANT_CONV_H | 4 | #define ZIP7_INC_PROP_VARIANT_CONV_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyTypes.h" |
| 7 | 7 | ||
diff --git a/CPP/Windows/PropVariantUtils.h b/CPP/Windows/PropVariantUtils.h index 3dd8295..78adb50 100644 --- a/CPP/Windows/PropVariantUtils.h +++ b/CPP/Windows/PropVariantUtils.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/PropVariantUtils.h | 1 | // Windows/PropVariantUtils.h |
| 2 | 2 | ||
| 3 | #ifndef __PROP_VARIANT_UTILS_H | 3 | #ifndef ZIP7_INC_PROP_VARIANT_UTILS_H |
| 4 | #define __PROP_VARIANT_UTILS_H | 4 | #define ZIP7_INC_PROP_VARIANT_UTILS_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| @@ -24,11 +24,11 @@ void FlagsToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags, NWin | |||
| 24 | AString TypeToString(const char * const table[], unsigned num, UInt32 value); | 24 | AString TypeToString(const char * const table[], unsigned num, UInt32 value); |
| 25 | void TypeToProp(const char * const table[], unsigned num, UInt32 value, NWindows::NCOM::CPropVariant &prop); | 25 | void TypeToProp(const char * const table[], unsigned num, UInt32 value, NWindows::NCOM::CPropVariant &prop); |
| 26 | 26 | ||
| 27 | #define PAIR_TO_PROP(pairs, value, prop) PairToProp(pairs, ARRAY_SIZE(pairs), value, prop) | 27 | #define PAIR_TO_PROP(pairs, value, prop) PairToProp(pairs, Z7_ARRAY_SIZE(pairs), value, prop) |
| 28 | #define FLAGS_TO_PROP(pairs, value, prop) FlagsToProp(pairs, ARRAY_SIZE(pairs), value, prop) | 28 | #define FLAGS_TO_PROP(pairs, value, prop) FlagsToProp(pairs, Z7_ARRAY_SIZE(pairs), value, prop) |
| 29 | #define TYPE_TO_PROP(table, value, prop) TypeToProp(table, ARRAY_SIZE(table), value, prop) | 29 | #define TYPE_TO_PROP(table, value, prop) TypeToProp(table, Z7_ARRAY_SIZE(table), value, prop) |
| 30 | 30 | ||
| 31 | void Flags64ToProp(const CUInt32PCharPair *pairs, unsigned num, UInt64 flags, NWindows::NCOM::CPropVariant &prop); | 31 | void Flags64ToProp(const CUInt32PCharPair *pairs, unsigned num, UInt64 flags, NWindows::NCOM::CPropVariant &prop); |
| 32 | #define FLAGS64_TO_PROP(pairs, value, prop) Flags64ToProp(pairs, ARRAY_SIZE(pairs), value, prop) | 32 | #define FLAGS64_TO_PROP(pairs, value, prop) Flags64ToProp(pairs, Z7_ARRAY_SIZE(pairs), value, prop) |
| 33 | 33 | ||
| 34 | #endif | 34 | #endif |
diff --git a/CPP/Windows/Registry.h b/CPP/Windows/Registry.h index ca79dfe..0d3b4fc 100644 --- a/CPP/Windows/Registry.h +++ b/CPP/Windows/Registry.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Registry.h | 1 | // Windows/Registry.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_REGISTRY_H | 3 | #ifndef ZIP7_INC_WINDOWS_REGISTRY_H |
| 4 | #define __WINDOWS_REGISTRY_H | 4 | #define ZIP7_INC_WINDOWS_REGISTRY_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyBuffer.h" | 6 | #include "../Common/MyBuffer.h" |
| 7 | #include "../Common/MyString.h" | 7 | #include "../Common/MyString.h" |
diff --git a/CPP/Windows/ResourceString.h b/CPP/Windows/ResourceString.h index f0bdabf..773307b 100644 --- a/CPP/Windows/ResourceString.h +++ b/CPP/Windows/ResourceString.h | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | // Windows/ResourceString.h | 1 | // Windows/ResourceString.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_RESOURCE_STRING_H | 3 | #ifndef ZIP7_INC_WINDOWS_RESOURCE_STRING_H |
| 4 | #define __WINDOWS_RESOURCE_STRING_H | 4 | #define ZIP7_INC_WINDOWS_RESOURCE_STRING_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | #include "../Common/MyWindows.h" | ||
| 7 | 8 | ||
| 8 | namespace NWindows { | 9 | namespace NWindows { |
| 9 | 10 | ||
diff --git a/CPP/Windows/SecurityUtils.cpp b/CPP/Windows/SecurityUtils.cpp index ede83fa..d4282d0 100644 --- a/CPP/Windows/SecurityUtils.cpp +++ b/CPP/Windows/SecurityUtils.cpp | |||
| @@ -4,9 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "SecurityUtils.h" | 5 | #include "SecurityUtils.h" |
| 6 | 6 | ||
| 7 | #define MY_CAST_FUNC (void(*)()) | ||
| 8 | // #define MY_CAST_FUNC | ||
| 9 | |||
| 10 | namespace NWindows { | 7 | namespace NWindows { |
| 11 | namespace NSecurity { | 8 | namespace NSecurity { |
| 12 | 9 | ||
| @@ -35,7 +32,7 @@ bool MyLookupAccountSid(LPCTSTR systemName, PSID sid, | |||
| 35 | 32 | ||
| 36 | static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest) | 33 | static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest) |
| 37 | { | 34 | { |
| 38 | size_t len = (size_t)wcslen(src); | 35 | const size_t len = (size_t)wcslen(src); |
| 39 | dest->Length = (USHORT)(len * sizeof(WCHAR)); | 36 | dest->Length = (USHORT)(len * sizeof(WCHAR)); |
| 40 | dest->MaximumLength = (USHORT)((len + 1) * sizeof(WCHAR)); | 37 | dest->MaximumLength = (USHORT)((len + 1) * sizeof(WCHAR)); |
| 41 | dest->Buffer = src; | 38 | dest->Buffer = src; |
| @@ -72,13 +69,14 @@ typedef BOOL (WINAPI * Func_LookupAccountNameW)( | |||
| 72 | static PSID GetSid(LPWSTR accountName) | 69 | static PSID GetSid(LPWSTR accountName) |
| 73 | { | 70 | { |
| 74 | #ifndef _UNICODE | 71 | #ifndef _UNICODE |
| 75 | HMODULE hModule = GetModuleHandle(TEXT("Advapi32.dll")); | 72 | const HMODULE hModule = GetModuleHandle(TEXT("advapi32.dll")); |
| 76 | if (hModule == NULL) | 73 | if (!hModule) |
| 77 | return NULL; | 74 | return NULL; |
| 78 | Func_LookupAccountNameW lookupAccountNameW = (Func_LookupAccountNameW) | 75 | const |
| 79 | MY_CAST_FUNC | 76 | Func_LookupAccountNameW lookupAccountNameW = Z7_GET_PROC_ADDRESS( |
| 80 | GetProcAddress(hModule, "LookupAccountNameW"); | 77 | Func_LookupAccountNameW, hModule, |
| 81 | if (lookupAccountNameW == NULL) | 78 | "LookupAccountNameW"); |
| 79 | if (!lookupAccountNameW) | ||
| 82 | return NULL; | 80 | return NULL; |
| 83 | #endif | 81 | #endif |
| 84 | 82 | ||
| @@ -88,21 +86,21 @@ static PSID GetSid(LPWSTR accountName) | |||
| 88 | #ifdef _UNICODE | 86 | #ifdef _UNICODE |
| 89 | ::LookupAccountNameW | 87 | ::LookupAccountNameW |
| 90 | #else | 88 | #else |
| 91 | lookupAccountNameW | 89 | lookupAccountNameW |
| 92 | #endif | 90 | #endif |
| 93 | (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse)) | 91 | (NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse)) |
| 94 | { | 92 | { |
| 95 | if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) | 93 | if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) |
| 96 | { | 94 | { |
| 97 | PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen); | 95 | const PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen); |
| 98 | LPWSTR domainName = (LPWSTR)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (domainLen + 1) * sizeof(WCHAR)); | 96 | LPWSTR domainName = (LPWSTR)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (domainLen + 1) * sizeof(WCHAR)); |
| 99 | BOOL res = | 97 | const BOOL res = |
| 100 | #ifdef _UNICODE | 98 | #ifdef _UNICODE |
| 101 | ::LookupAccountNameW | 99 | ::LookupAccountNameW |
| 102 | #else | 100 | #else |
| 103 | lookupAccountNameW | 101 | lookupAccountNameW |
| 104 | #endif | 102 | #endif |
| 105 | (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse); | 103 | (NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse); |
| 106 | ::HeapFree(GetProcessHeap(), 0, domainName); | 104 | ::HeapFree(GetProcessHeap(), 0, domainName); |
| 107 | if (res) | 105 | if (res) |
| 108 | return pSid; | 106 | return pSid; |
| @@ -111,7 +109,7 @@ static PSID GetSid(LPWSTR accountName) | |||
| 111 | return NULL; | 109 | return NULL; |
| 112 | } | 110 | } |
| 113 | 111 | ||
| 114 | #define MY__SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege" | 112 | #define Z7_WIN_SE_LOCK_MEMORY_NAME L"SeLockMemoryPrivilege" |
| 115 | 113 | ||
| 116 | bool AddLockMemoryPrivilege() | 114 | bool AddLockMemoryPrivilege() |
| 117 | { | 115 | { |
| @@ -131,13 +129,13 @@ bool AddLockMemoryPrivilege() | |||
| 131 | != 0) | 129 | != 0) |
| 132 | return false; | 130 | return false; |
| 133 | LSA_UNICODE_STRING userRights; | 131 | LSA_UNICODE_STRING userRights; |
| 134 | wchar_t s[128] = MY__SE_LOCK_MEMORY_NAME; | 132 | wchar_t s[128] = Z7_WIN_SE_LOCK_MEMORY_NAME; |
| 135 | SetLsaString(s, &userRights); | 133 | SetLsaString(s, &userRights); |
| 136 | WCHAR userName[256 + 2]; | 134 | WCHAR userName[256 + 2]; |
| 137 | DWORD size = 256; | 135 | DWORD size = 256; |
| 138 | if (!GetUserNameW(userName, &size)) | 136 | if (!GetUserNameW(userName, &size)) |
| 139 | return false; | 137 | return false; |
| 140 | PSID psid = GetSid(userName); | 138 | const PSID psid = GetSid(userName); |
| 141 | if (psid == NULL) | 139 | if (psid == NULL) |
| 142 | return false; | 140 | return false; |
| 143 | bool res = false; | 141 | bool res = false; |
| @@ -176,7 +174,7 @@ bool AddLockMemoryPrivilege() | |||
| 176 | res = true; | 174 | res = true; |
| 177 | } | 175 | } |
| 178 | */ | 176 | */ |
| 179 | NTSTATUS status = policy.AddAccountRights(psid, &userRights); | 177 | const NTSTATUS status = policy.AddAccountRights(psid, &userRights); |
| 180 | if (status == 0) | 178 | if (status == 0) |
| 181 | res = true; | 179 | res = true; |
| 182 | // ULONG res = LsaNtStatusToWinError(status); | 180 | // ULONG res = LsaNtStatusToWinError(status); |
diff --git a/CPP/Windows/SecurityUtils.h b/CPP/Windows/SecurityUtils.h index c0d7b12..4ef3939 100644 --- a/CPP/Windows/SecurityUtils.h +++ b/CPP/Windows/SecurityUtils.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/SecurityUtils.h | 1 | // Windows/SecurityUtils.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_SECURITY_UTILS_H | 3 | #ifndef ZIP7_INC_WINDOWS_SECURITY_UTILS_H |
| 4 | #define __WINDOWS_SECURITY_UTILS_H | 4 | #define ZIP7_INC_WINDOWS_SECURITY_UTILS_H |
| 5 | 5 | ||
| 6 | #include <NTSecAPI.h> | 6 | #include <NTSecAPI.h> |
| 7 | 7 | ||
| @@ -20,7 +20,7 @@ typedef NTSTATUS (NTAPI *Func_LsaAddAccountRights)(LSA_HANDLE PolicyHandle, | |||
| 20 | 20 | ||
| 21 | #define POLICY_FUNC_CALL(fff, str) \ | 21 | #define POLICY_FUNC_CALL(fff, str) \ |
| 22 | if (hModule == NULL) return MY_STATUS_NOT_IMPLEMENTED; \ | 22 | if (hModule == NULL) return MY_STATUS_NOT_IMPLEMENTED; \ |
| 23 | Func_ ## fff v = (Func_ ## fff) (void(*)()) GetProcAddress(hModule, str); \ | 23 | const Func_ ## fff v = Z7_GET_PROC_ADDRESS(Func_ ## fff, hModule, str); \ |
| 24 | if (!v) return MY_STATUS_NOT_IMPLEMENTED; \ | 24 | if (!v) return MY_STATUS_NOT_IMPLEMENTED; \ |
| 25 | const NTSTATUS res = v | 25 | const NTSTATUS res = v |
| 26 | 26 | ||
| @@ -39,7 +39,7 @@ class CAccessToken | |||
| 39 | { | 39 | { |
| 40 | HANDLE _handle; | 40 | HANDLE _handle; |
| 41 | public: | 41 | public: |
| 42 | CAccessToken(): _handle(NULL) {}; | 42 | CAccessToken(): _handle(NULL) {} |
| 43 | ~CAccessToken() { Close(); } | 43 | ~CAccessToken() { Close(); } |
| 44 | bool Close() | 44 | bool Close() |
| 45 | { | 45 | { |
| @@ -93,9 +93,9 @@ public: | |||
| 93 | CPolicy(): _handle(NULL) | 93 | CPolicy(): _handle(NULL) |
| 94 | { | 94 | { |
| 95 | #ifndef _UNICODE | 95 | #ifndef _UNICODE |
| 96 | hModule = GetModuleHandle(TEXT("Advapi32.dll")); | 96 | hModule = GetModuleHandle(TEXT("advapi32.dll")); |
| 97 | #endif | 97 | #endif |
| 98 | }; | 98 | } |
| 99 | ~CPolicy() { Close(); } | 99 | ~CPolicy() { Close(); } |
| 100 | 100 | ||
| 101 | NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes, | 101 | NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes, |
diff --git a/CPP/Windows/Shell.cpp b/CPP/Windows/Shell.cpp index 071833c..b2a3489 100644 --- a/CPP/Windows/Shell.cpp +++ b/CPP/Windows/Shell.cpp | |||
| @@ -2,23 +2,50 @@ | |||
| 2 | 2 | ||
| 3 | #include "StdAfx.h" | 3 | #include "StdAfx.h" |
| 4 | 4 | ||
| 5 | /* | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "../Common/MyCom.h" | 5 | #include "../Common/MyCom.h" |
| 11 | #ifndef _UNICODE | ||
| 12 | #include "../Common/StringConvert.h" | 6 | #include "../Common/StringConvert.h" |
| 13 | #endif | ||
| 14 | 7 | ||
| 15 | #include "COM.h" | 8 | #include "COM.h" |
| 9 | #include "FileName.h" | ||
| 10 | #include "MemoryGlobal.h" | ||
| 16 | #include "Shell.h" | 11 | #include "Shell.h" |
| 17 | 12 | ||
| 18 | #ifndef _UNICODE | 13 | #ifndef _UNICODE |
| 19 | extern bool g_IsNT; | 14 | extern bool g_IsNT; |
| 20 | #endif | 15 | #endif |
| 21 | 16 | ||
| 17 | // MSVC6 and old SDK don't support this function: | ||
| 18 | // #define LWSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE | ||
| 19 | // LWSTDAPI StrRetToStrW(STRRET *pstr, LPCITEMIDLIST pidl, LPWSTR *ppsz); | ||
| 20 | |||
| 21 | // #define SHOW_DEBUG_SHELL | ||
| 22 | |||
| 23 | #ifdef SHOW_DEBUG_SHELL | ||
| 24 | |||
| 25 | #include "../Common/IntToString.h" | ||
| 26 | |||
| 27 | static void Print_Number(UInt32 number, const char *s) | ||
| 28 | { | ||
| 29 | AString s2; | ||
| 30 | s2.Add_UInt32(number); | ||
| 31 | s2.Add_Space(); | ||
| 32 | s2 += s; | ||
| 33 | OutputDebugStringA(s2); | ||
| 34 | } | ||
| 35 | |||
| 36 | #define ODS(sz) { OutputDebugStringA(sz); } | ||
| 37 | #define ODS_U(s) { OutputDebugStringW(s); } | ||
| 38 | #define ODS_(op) { op; } | ||
| 39 | |||
| 40 | #else | ||
| 41 | |||
| 42 | #define ODS(sz) | ||
| 43 | #define ODS_U(s) | ||
| 44 | #define ODS_(op) | ||
| 45 | |||
| 46 | #endif | ||
| 47 | |||
| 48 | |||
| 22 | namespace NWindows { | 49 | namespace NWindows { |
| 23 | namespace NShell { | 50 | namespace NShell { |
| 24 | 51 | ||
| @@ -28,12 +55,24 @@ namespace NShell { | |||
| 28 | 55 | ||
| 29 | void CItemIDList::Free() | 56 | void CItemIDList::Free() |
| 30 | { | 57 | { |
| 31 | if (m_Object == NULL) | 58 | if (!m_Object) |
| 32 | return; | 59 | return; |
| 60 | /* DOCs: | ||
| 61 | SHGetMalloc was introduced in Windows 95 and Microsoft Windows NT 4.0, | ||
| 62 | but as of Windows 2000 it is no longer necessary. | ||
| 63 | In its place, programs can call the equivalent (and easier to use) CoTaskMemAlloc and CoTaskMemFree. | ||
| 64 | Description from oldnewthings: | ||
| 65 | shell functions could work without COM (if OLE32.DLL is not loaded), | ||
| 66 | but now if OLE32.DLL is loaded, then shell functions and com functions do same things. | ||
| 67 | 22.02: so we use OLE32.DLL function to free memory: | ||
| 68 | */ | ||
| 69 | /* | ||
| 33 | CMyComPtr<IMalloc> shellMalloc; | 70 | CMyComPtr<IMalloc> shellMalloc; |
| 34 | if (::SHGetMalloc(&shellMalloc) != NOERROR) | 71 | if (::SHGetMalloc(&shellMalloc) != NOERROR) |
| 35 | throw 41099; | 72 | throw 41099; |
| 36 | shellMalloc->Free(m_Object); | 73 | shellMalloc->Free(m_Object); |
| 74 | */ | ||
| 75 | CoTaskMemFree(m_Object); | ||
| 37 | m_Object = NULL; | 76 | m_Object = NULL; |
| 38 | } | 77 | } |
| 39 | 78 | ||
| @@ -70,9 +109,354 @@ CItemIDList& CItemIDList::operator=(const CItemIDList &object) | |||
| 70 | } | 109 | } |
| 71 | */ | 110 | */ |
| 72 | 111 | ||
| 112 | |||
| 113 | static HRESULT ReadUnicodeStrings(const wchar_t *p, size_t size, UStringVector &names) | ||
| 114 | { | ||
| 115 | names.Clear(); | ||
| 116 | const wchar_t *lim = p + size; | ||
| 117 | UString s; | ||
| 118 | /* | ||
| 119 | if (size == 0 || p[size - 1] != 0) | ||
| 120 | return E_INVALIDARG; | ||
| 121 | if (size == 1) | ||
| 122 | return S_OK; | ||
| 123 | if (p[size - 2] != 0) | ||
| 124 | return E_INVALIDARG; | ||
| 125 | */ | ||
| 126 | for (;;) | ||
| 127 | { | ||
| 128 | const wchar_t *start = p; | ||
| 129 | for (;;) | ||
| 130 | { | ||
| 131 | if (p == lim) return E_INVALIDARG; // S_FALSE | ||
| 132 | if (*p++ == 0) | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | const size_t num = (size_t)(p - start); | ||
| 136 | if (num == 1) | ||
| 137 | { | ||
| 138 | if (p != lim) return E_INVALIDARG; // S_FALSE | ||
| 139 | return S_OK; | ||
| 140 | } | ||
| 141 | s.SetFrom(start, (unsigned)(num - 1)); | ||
| 142 | ODS_U(s) | ||
| 143 | names.Add(s); | ||
| 144 | // names.ReserveOnePosition(); | ||
| 145 | // names.AddInReserved_Ptr_of_new(new UString((unsigned)num - 1, start)); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | static HRESULT ReadAnsiStrings(const char *p, size_t size, UStringVector &names) | ||
| 151 | { | ||
| 152 | names.Clear(); | ||
| 153 | AString name; | ||
| 154 | for (; size != 0; size--) | ||
| 155 | { | ||
| 156 | const char c = *p++; | ||
| 157 | if (c == 0) | ||
| 158 | { | ||
| 159 | if (name.IsEmpty()) | ||
| 160 | return S_OK; | ||
| 161 | names.Add(GetUnicodeString(name)); | ||
| 162 | name.Empty(); | ||
| 163 | } | ||
| 164 | else | ||
| 165 | name += c; | ||
| 166 | } | ||
| 167 | return E_INVALIDARG; | ||
| 168 | } | ||
| 169 | |||
| 170 | |||
| 171 | #define INIT_FORMATETC_HGLOBAL(type) { (type), NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL } | ||
| 172 | |||
| 173 | static HRESULT DataObject_GetData_HGLOBAL(IDataObject *dataObject, CLIPFORMAT cf, NCOM::CStgMedium &medium) | ||
| 174 | { | ||
| 175 | FORMATETC etc = INIT_FORMATETC_HGLOBAL(cf); | ||
| 176 | RINOK(dataObject->GetData(&etc, &medium)) | ||
| 177 | if (medium.tymed != TYMED_HGLOBAL) | ||
| 178 | return E_INVALIDARG; | ||
| 179 | return S_OK; | ||
| 180 | } | ||
| 181 | |||
| 182 | static HRESULT DataObject_GetData_HDROP_Names(IDataObject *dataObject, UStringVector &names) | ||
| 183 | { | ||
| 184 | names.Clear(); | ||
| 185 | NCOM::CStgMedium medium; | ||
| 186 | |||
| 187 | /* Win10 : if (dataObject) is from IContextMenu::Initialize() and | ||
| 188 | if (len_of_path >= MAX_PATH (260) for some file in data object) | ||
| 189 | { | ||
| 190 | GetData() returns HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) | ||
| 191 | "The data area passed to a system call is too small", | ||
| 192 | Is there a way to fix this code for long paths? | ||
| 193 | } */ | ||
| 194 | |||
| 195 | RINOK(DataObject_GetData_HGLOBAL(dataObject, CF_HDROP, medium)) | ||
| 196 | const size_t blockSize = GlobalSize(medium.hGlobal); | ||
| 197 | if (blockSize < sizeof(DROPFILES)) | ||
| 198 | return E_INVALIDARG; | ||
| 199 | NMemory::CGlobalLock dropLock(medium.hGlobal); | ||
| 200 | const DROPFILES *dropFiles = (const DROPFILES *)dropLock.GetPointer(); | ||
| 201 | if (!dropFiles) | ||
| 202 | return E_INVALIDARG; | ||
| 203 | if (blockSize < dropFiles->pFiles | ||
| 204 | || dropFiles->pFiles < sizeof(DROPFILES) | ||
| 205 | // || dropFiles->pFiles != sizeof(DROPFILES) | ||
| 206 | ) | ||
| 207 | return E_INVALIDARG; | ||
| 208 | const size_t size = blockSize - dropFiles->pFiles; | ||
| 209 | const void *namesData = (const Byte *)(const void *)dropFiles + dropFiles->pFiles; | ||
| 210 | HRESULT hres; | ||
| 211 | if (dropFiles->fWide) | ||
| 212 | { | ||
| 213 | if (size % sizeof(wchar_t) != 0) | ||
| 214 | return E_INVALIDARG; | ||
| 215 | hres = ReadUnicodeStrings((const wchar_t *)namesData, size / sizeof(wchar_t), names); | ||
| 216 | } | ||
| 217 | else | ||
| 218 | hres = ReadAnsiStrings((const char *)namesData, size, names); | ||
| 219 | |||
| 220 | ODS_(Print_Number(names.Size(), "DataObject_GetData_HDROP_Names")) | ||
| 221 | return hres; | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | // CF_IDLIST: | ||
| 227 | #define MYWIN_CFSTR_SHELLIDLIST TEXT("Shell IDList Array") | ||
| 228 | |||
| 229 | typedef struct | ||
| 230 | { | ||
| 231 | UINT cidl; | ||
| 232 | UINT aoffset[1]; | ||
| 233 | } MYWIN_CIDA; | ||
| 234 | /* | ||
| 235 | cidl : number of PIDLs that are being transferred, not including the parent folder. | ||
| 236 | aoffset : An array of offsets, relative to the beginning of this structure. | ||
| 237 | aoffset[0] - fully qualified PIDL of a parent folder. | ||
| 238 | If this PIDL is empty, the parent folder is the desktop. | ||
| 239 | aoffset[1] ... aoffset[cidl] : offset to one of the PIDLs to be transferred. | ||
| 240 | All of these PIDLs are relative to the PIDL of the parent folder. | ||
| 241 | */ | ||
| 242 | |||
| 243 | static HRESULT DataObject_GetData_IDLIST(IDataObject *dataObject, UStringVector &names) | ||
| 244 | { | ||
| 245 | names.Clear(); | ||
| 246 | NCOM::CStgMedium medium; | ||
| 247 | RINOK(DataObject_GetData_HGLOBAL(dataObject, (CLIPFORMAT) | ||
| 248 | RegisterClipboardFormat(MYWIN_CFSTR_SHELLIDLIST), medium)) | ||
| 249 | const size_t blockSize = GlobalSize(medium.hGlobal); | ||
| 250 | if (blockSize < sizeof(MYWIN_CIDA) || blockSize >= (UInt32)((UInt32)0 - 1)) | ||
| 251 | return E_INVALIDARG; | ||
| 252 | NMemory::CGlobalLock dropLock(medium.hGlobal); | ||
| 253 | const MYWIN_CIDA *cida = (const MYWIN_CIDA *)dropLock.GetPointer(); | ||
| 254 | if (!cida) | ||
| 255 | return E_INVALIDARG; | ||
| 256 | if (cida->cidl == 0) | ||
| 257 | { | ||
| 258 | // is it posssible to have no selected items? | ||
| 259 | // it's unexpected case. | ||
| 260 | return E_INVALIDARG; | ||
| 261 | } | ||
| 262 | if (cida->cidl >= (blockSize - (UInt32)sizeof(MYWIN_CIDA)) / sizeof(UINT)) | ||
| 263 | return E_INVALIDARG; | ||
| 264 | const UInt32 start = cida->cidl * (UInt32)sizeof(UINT) + (UInt32)sizeof(MYWIN_CIDA); | ||
| 265 | |||
| 266 | STRRET strret; | ||
| 267 | CMyComPtr<IShellFolder> parentFolder; | ||
| 268 | { | ||
| 269 | const UINT offset = cida->aoffset[0]; | ||
| 270 | if (offset < start || offset >= blockSize | ||
| 271 | // || offset != start | ||
| 272 | ) | ||
| 273 | return E_INVALIDARG; | ||
| 274 | |||
| 275 | CMyComPtr<IShellFolder> desktopFolder; | ||
| 276 | RINOK(::SHGetDesktopFolder(&desktopFolder)) | ||
| 277 | if (!desktopFolder) | ||
| 278 | return E_FAIL; | ||
| 279 | |||
| 280 | LPCITEMIDLIST const lpcItem = (LPCITEMIDLIST)(const void *)((const Byte *)cida + offset); | ||
| 281 | |||
| 282 | #ifdef SHOW_DEBUG_SHELL | ||
| 283 | { | ||
| 284 | const HRESULT res = desktopFolder->GetDisplayNameOf( | ||
| 285 | lpcItem, SHGDN_FORPARSING, &strret); | ||
| 286 | if (res == S_OK && strret.uType == STRRET_WSTR) | ||
| 287 | { | ||
| 288 | ODS_U(strret.pOleStr) | ||
| 289 | /* if lpcItem is empty, the path will be | ||
| 290 | "C:\Users\user_name\Desktop" | ||
| 291 | if lpcItem is "My Computer" folder, the path will be | ||
| 292 | "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" */ | ||
| 293 | CoTaskMemFree(strret.pOleStr); | ||
| 294 | } | ||
| 295 | } | ||
| 296 | #endif | ||
| 297 | |||
| 298 | RINOK(desktopFolder->BindToObject(lpcItem, | ||
| 299 | NULL, IID_IShellFolder, (void **)&parentFolder)) | ||
| 300 | if (!parentFolder) | ||
| 301 | return E_FAIL; | ||
| 302 | } | ||
| 303 | |||
| 304 | names.ClearAndReserve(cida->cidl); | ||
| 305 | UString path; | ||
| 306 | |||
| 307 | // for (int y = 0; y < 1; y++) // for debug | ||
| 308 | for (unsigned i = 1; i <= cida->cidl; i++) | ||
| 309 | { | ||
| 310 | const UINT offset = cida->aoffset[i]; | ||
| 311 | if (offset < start || offset >= blockSize) | ||
| 312 | return E_INVALIDARG; | ||
| 313 | const void *p = (const Byte *)(const void *)cida + offset; | ||
| 314 | /* ITEMIDLIST of file can contain more than one SHITEMID item. | ||
| 315 | In win10 only SHGDN_FORPARSING returns path that contains | ||
| 316 | all path parts related to parts of ITEMIDLIST. | ||
| 317 | So we can use only SHGDN_FORPARSING here. | ||
| 318 | Don't use (SHGDN_INFOLDER) | ||
| 319 | Don't use (SHGDN_INFOLDER | SHGDN_FORPARSING) | ||
| 320 | */ | ||
| 321 | RINOK(parentFolder->GetDisplayNameOf((LPCITEMIDLIST)p, SHGDN_FORPARSING, &strret)) | ||
| 322 | |||
| 323 | /* | ||
| 324 | // MSVC6 and old SDK do not support StrRetToStrW(). | ||
| 325 | LPWSTR lpstr; | ||
| 326 | RINOK (StrRetToStrW(&strret, NULL, &lpstr)) | ||
| 327 | ODS_U(lpstr) | ||
| 328 | path = lpstr; | ||
| 329 | CoTaskMemFree(lpstr); | ||
| 330 | */ | ||
| 331 | if (strret.uType != STRRET_WSTR) | ||
| 332 | return E_INVALIDARG; | ||
| 333 | ODS_U(strret.pOleStr) | ||
| 334 | path = strret.pOleStr; | ||
| 335 | // the path could have super path prefix "\\\\?\\" | ||
| 336 | // we can remove super path prefix here, if we don't need that prefix | ||
| 337 | #ifdef Z7_LONG_PATH | ||
| 338 | // we remove super prefix, if we can work without that prefix | ||
| 339 | NFile::NName::If_IsSuperPath_RemoveSuperPrefix(path); | ||
| 340 | #endif | ||
| 341 | names.AddInReserved(path); | ||
| 342 | CoTaskMemFree(strret.pOleStr); | ||
| 343 | } | ||
| 344 | |||
| 345 | ODS_(Print_Number(cida->cidl, "CFSTR_SHELLIDLIST END")) | ||
| 346 | return S_OK; | ||
| 347 | } | ||
| 348 | |||
| 349 | |||
| 350 | HRESULT DataObject_GetData_HDROP_or_IDLIST_Names(IDataObject *dataObject, UStringVector &paths) | ||
| 351 | { | ||
| 352 | ODS("-- DataObject_GetData_HDROP_or_IDLIST_Names START") | ||
| 353 | HRESULT hres = NShell::DataObject_GetData_HDROP_Names(dataObject, paths); | ||
| 354 | // if (hres == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) | ||
| 355 | if (hres != S_OK) | ||
| 356 | { | ||
| 357 | ODS("-- DataObject_GetData_IDLIST START") | ||
| 358 | // for (int y = 0; y < 10000; y++) // for debug | ||
| 359 | hres = NShell::DataObject_GetData_IDLIST(dataObject, paths); | ||
| 360 | } | ||
| 361 | ODS("-- DataObject_GetData_HDROP_or_IDLIST_Names END") | ||
| 362 | return hres; | ||
| 363 | } | ||
| 364 | |||
| 365 | |||
| 366 | |||
| 367 | // #if (NTDDI_VERSION >= NTDDI_VISTA) | ||
| 368 | typedef struct | ||
| 369 | { | ||
| 370 | UINT cItems; // number of items in rgdwFileAttributes array | ||
| 371 | DWORD dwSumFileAttributes; // all of the attributes ORed together | ||
| 372 | DWORD dwProductFileAttributes; // all of the attributes ANDed together | ||
| 373 | DWORD rgdwFileAttributes[1]; // array | ||
| 374 | } MYWIN_FILE_ATTRIBUTES_ARRAY; | ||
| 375 | |||
| 376 | #define MYWIN_CFSTR_FILE_ATTRIBUTES_ARRAY TEXT("File Attributes Array") | ||
| 377 | |||
| 378 | HRESULT DataObject_GetData_FILE_ATTRS(IDataObject *dataObject, CFileAttribs &attribs) | ||
| 379 | { | ||
| 380 | attribs.Clear(); | ||
| 381 | NCOM::CStgMedium medium; | ||
| 382 | RINOK(DataObject_GetData_HGLOBAL(dataObject, (CLIPFORMAT) | ||
| 383 | RegisterClipboardFormat(MYWIN_CFSTR_FILE_ATTRIBUTES_ARRAY), medium)) | ||
| 384 | const size_t blockSize = GlobalSize(medium.hGlobal); | ||
| 385 | if (blockSize < sizeof(MYWIN_FILE_ATTRIBUTES_ARRAY)) | ||
| 386 | return E_INVALIDARG; | ||
| 387 | NMemory::CGlobalLock dropLock(medium.hGlobal); | ||
| 388 | const MYWIN_FILE_ATTRIBUTES_ARRAY *faa = (const MYWIN_FILE_ATTRIBUTES_ARRAY *)dropLock.GetPointer(); | ||
| 389 | if (!faa) | ||
| 390 | return E_INVALIDARG; | ||
| 391 | const unsigned numFiles = faa->cItems; | ||
| 392 | if (numFiles == 0) | ||
| 393 | { | ||
| 394 | // is it posssible to have empty array here? | ||
| 395 | return E_INVALIDARG; | ||
| 396 | } | ||
| 397 | if ((blockSize - (sizeof(MYWIN_FILE_ATTRIBUTES_ARRAY) - sizeof(DWORD))) | ||
| 398 | / sizeof(DWORD) != numFiles) | ||
| 399 | return E_INVALIDARG; | ||
| 400 | // attribs.Sum = faa->dwSumFileAttributes; | ||
| 401 | // attribs.Product = faa->dwProductFileAttributes; | ||
| 402 | // attribs.Vals.SetFromArray(faa->rgdwFileAttributes, numFiles); | ||
| 403 | // attribs.IsDirVector.ClearAndSetSize(numFiles); | ||
| 404 | |||
| 405 | if ((faa->dwSumFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) | ||
| 406 | { | ||
| 407 | /* in win10: if selected items are volumes (c:\, d:\ ..) in My Compter, | ||
| 408 | all items have FILE_ATTRIBUTE_DIRECTORY attribute | ||
| 409 | ntfs volume also have FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | ||
| 410 | udf volume: FILE_ATTRIBUTE_READONLY | ||
| 411 | dvd-rom device: (-1) : all bits are set | ||
| 412 | */ | ||
| 413 | const DWORD *attr = faa->rgdwFileAttributes; | ||
| 414 | // DWORD product = (UInt32)0 - 1, sum = 0; | ||
| 415 | for (unsigned i = 0; i < numFiles; i++) | ||
| 416 | { | ||
| 417 | if (attr[i] & FILE_ATTRIBUTE_DIRECTORY) | ||
| 418 | { | ||
| 419 | // attribs.ThereAreDirs = true; | ||
| 420 | attribs.FirstDirIndex = (int)i; | ||
| 421 | break; | ||
| 422 | } | ||
| 423 | // attribs.IsDirVector[i] = (attr[i] & FILE_ATTRIBUTE_DIRECTORY) != 0; | ||
| 424 | // product &= v; | ||
| 425 | // sum |= v; | ||
| 426 | } | ||
| 427 | // ODS_(Print_Number(product, "Product calc FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names")) | ||
| 428 | // ODS_(Print_Number(sum, "Sum calc FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names")) | ||
| 429 | } | ||
| 430 | // ODS_(Print_Number(attribs.Product, "Product FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names")) | ||
| 431 | // ODS_(Print_Number(attribs.Sum, "Sum FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names")) | ||
| 432 | ODS_(Print_Number(numFiles, "FILE_ATTRIBUTES_ARRAY ==== DataObject_GetData_HDROP_Names")) | ||
| 433 | return S_OK; | ||
| 434 | } | ||
| 435 | |||
| 436 | |||
| 73 | ///////////////////////////// | 437 | ///////////////////////////// |
| 74 | // CDrop | 438 | // CDrop |
| 75 | 439 | ||
| 440 | /* | ||
| 441 | win10: | ||
| 442 | DragQueryFile() implementation code is not effective because | ||
| 443 | there is no pointer inside DROP internal file list, so | ||
| 444 | DragQueryFile(fileIndex) runs all names in range [0, fileIndex]. | ||
| 445 | DragQueryFile(,, buf, bufSize) | ||
| 446 | if (buf == NULL) by spec | ||
| 447 | { | ||
| 448 | returns value is the required size | ||
| 449 | in characters, of the buffer, not including the terminating null character | ||
| 450 | tests show that if (bufSize == 0), then it also returns required size. | ||
| 451 | } | ||
| 452 | if (bufSize != NULL) | ||
| 453 | { | ||
| 454 | returns: the count of the characters copied, not including null character. | ||
| 455 | win10: null character is also copied at position buf[ret_count]; | ||
| 456 | } | ||
| 457 | */ | ||
| 458 | |||
| 459 | /* | ||
| 76 | void CDrop::Attach(HDROP object) | 460 | void CDrop::Attach(HDROP object) |
| 77 | { | 461 | { |
| 78 | Free(); | 462 | Free(); |
| @@ -92,56 +476,133 @@ UINT CDrop::QueryCountOfFiles() | |||
| 92 | return QueryFile(0xFFFFFFFF, (LPTSTR)NULL, 0); | 476 | return QueryFile(0xFFFFFFFF, (LPTSTR)NULL, 0); |
| 93 | } | 477 | } |
| 94 | 478 | ||
| 95 | UString CDrop::QueryFileName(UINT fileIndex) | 479 | void CDrop::QueryFileName(UINT fileIndex, UString &fileName) |
| 96 | { | 480 | { |
| 97 | UString fileName; | ||
| 98 | #ifndef _UNICODE | 481 | #ifndef _UNICODE |
| 99 | if (!g_IsNT) | 482 | if (!g_IsNT) |
| 100 | { | 483 | { |
| 101 | AString fileNameA; | 484 | AString fileNameA; |
| 102 | UINT bufferSize = QueryFile(fileIndex, (LPTSTR)NULL, 0); | 485 | const UINT len = QueryFile(fileIndex, (LPTSTR)NULL, 0); |
| 103 | const unsigned len = bufferSize + 2; | 486 | const UINT numCopied = QueryFile(fileIndex, fileNameA.GetBuf(len + 2), len + 2); |
| 104 | QueryFile(fileIndex, fileNameA.GetBuf(len), bufferSize + 1); | ||
| 105 | fileNameA.ReleaseBuf_CalcLen(len); | 487 | fileNameA.ReleaseBuf_CalcLen(len); |
| 488 | if (numCopied != len) | ||
| 489 | throw 20221223; | ||
| 106 | fileName = GetUnicodeString(fileNameA); | 490 | fileName = GetUnicodeString(fileNameA); |
| 107 | } | 491 | } |
| 108 | else | 492 | else |
| 109 | #endif | 493 | #endif |
| 110 | { | 494 | { |
| 111 | UINT bufferSize = QueryFile(fileIndex, (LPWSTR)NULL, 0); | 495 | // kReserve must be >= 3 for additional buffer size |
| 112 | const unsigned len = bufferSize + 2; | 496 | // safety and for optimal performance |
| 113 | QueryFile(fileIndex, fileName.GetBuf(len), bufferSize + 1); | 497 | const unsigned kReserve = 3; |
| 498 | { | ||
| 499 | unsigned len = 0; | ||
| 500 | wchar_t *buf = fileName.GetBuf_GetMaxAvail(len); | ||
| 501 | if (len >= kReserve) | ||
| 502 | { | ||
| 503 | const UINT numCopied = QueryFile(fileIndex, buf, len); | ||
| 504 | if (numCopied < len - 1) | ||
| 505 | { | ||
| 506 | // (numCopied < len - 1) case means that it have copied full string. | ||
| 507 | fileName.ReleaseBuf_CalcLen(numCopied); | ||
| 508 | return; | ||
| 509 | } | ||
| 510 | } | ||
| 511 | } | ||
| 512 | const UINT len = QueryFile(fileIndex, (LPWSTR)NULL, 0); | ||
| 513 | const UINT numCopied = QueryFile(fileIndex, | ||
| 514 | fileName.GetBuf(len + kReserve), len + kReserve); | ||
| 114 | fileName.ReleaseBuf_CalcLen(len); | 515 | fileName.ReleaseBuf_CalcLen(len); |
| 516 | if (numCopied != len) | ||
| 517 | throw 20221223; | ||
| 115 | } | 518 | } |
| 116 | return fileName; | ||
| 117 | } | 519 | } |
| 118 | 520 | ||
| 521 | |||
| 119 | void CDrop::QueryFileNames(UStringVector &fileNames) | 522 | void CDrop::QueryFileNames(UStringVector &fileNames) |
| 120 | { | 523 | { |
| 121 | UINT numFiles = QueryCountOfFiles(); | 524 | UINT numFiles = QueryCountOfFiles(); |
| 122 | /* | 525 | |
| 123 | char s[100]; | 526 | Print_Number(numFiles, "\n====== CDrop::QueryFileNames START ===== \n"); |
| 124 | sprintf(s, "QueryFileNames: %d files", numFiles); | 527 | |
| 125 | OutputDebugStringA(s); | ||
| 126 | */ | ||
| 127 | fileNames.ClearAndReserve(numFiles); | 528 | fileNames.ClearAndReserve(numFiles); |
| 529 | UString s; | ||
| 128 | for (UINT i = 0; i < numFiles; i++) | 530 | for (UINT i = 0; i < numFiles; i++) |
| 129 | { | 531 | { |
| 130 | const UString s2 = QueryFileName(i); | 532 | QueryFileName(i, s); |
| 131 | if (!s2.IsEmpty()) | 533 | if (!s.IsEmpty()) |
| 132 | fileNames.AddInReserved(s2); | 534 | fileNames.AddInReserved(s); |
| 133 | /* | ||
| 134 | OutputDebugStringW(L"file ---"); | ||
| 135 | OutputDebugStringW(s2); | ||
| 136 | */ | ||
| 137 | } | 535 | } |
| 536 | Print_Number(numFiles, "\n====== CDrop::QueryFileNames END ===== \n"); | ||
| 537 | } | ||
| 538 | */ | ||
| 539 | |||
| 540 | |||
| 541 | // #if (NTDDI_VERSION >= NTDDI_VISTA) | ||
| 542 | // SHGetPathFromIDListEx returns a win32 file system path for the item in the name space. | ||
| 543 | typedef int Z7_WIN_GPFIDL_FLAGS; | ||
| 544 | |||
| 545 | extern "C" { | ||
| 546 | typedef BOOL (WINAPI * Func_SHGetPathFromIDListW)(LPCITEMIDLIST pidl, LPWSTR pszPath); | ||
| 547 | typedef BOOL (WINAPI * Func_SHGetPathFromIDListEx)(LPCITEMIDLIST pidl, PWSTR pszPath, DWORD cchPath, Z7_WIN_GPFIDL_FLAGS uOpts); | ||
| 138 | } | 548 | } |
| 139 | 549 | ||
| 550 | #ifndef _UNICODE | ||
| 140 | 551 | ||
| 141 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path) | 552 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, AString &path) |
| 553 | { | ||
| 554 | path.Empty(); | ||
| 555 | const unsigned len = MAX_PATH + 16; | ||
| 556 | const bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuf(len))); | ||
| 557 | path.ReleaseBuf_CalcLen(len); | ||
| 558 | return result; | ||
| 559 | } | ||
| 560 | |||
| 561 | #endif | ||
| 562 | |||
| 563 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path) | ||
| 142 | { | 564 | { |
| 143 | const unsigned len = MAX_PATH * 2; | 565 | path.Empty(); |
| 566 | unsigned len = MAX_PATH + 16; | ||
| 567 | |||
| 568 | #ifdef _UNICODE | ||
| 144 | bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuf(len))); | 569 | bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuf(len))); |
| 570 | #else | ||
| 571 | const | ||
| 572 | Func_SHGetPathFromIDListW | ||
| 573 | shGetPathFromIDListW = Z7_GET_PROC_ADDRESS( | ||
| 574 | Func_SHGetPathFromIDListW, ::GetModuleHandleW(L"shell32.dll"), | ||
| 575 | "SHGetPathFromIDListW"); | ||
| 576 | if (!shGetPathFromIDListW) | ||
| 577 | return false; | ||
| 578 | bool result = BOOLToBool(shGetPathFromIDListW(itemIDList, path.GetBuf(len))); | ||
| 579 | #endif | ||
| 580 | |||
| 581 | if (!result) | ||
| 582 | { | ||
| 583 | ODS("==== GetPathFromIDList() SHGetPathFromIDList() returned false") | ||
| 584 | /* for long path we need SHGetPathFromIDListEx(). | ||
| 585 | win10: SHGetPathFromIDListEx() for long path returns path with | ||
| 586 | with super path prefix "\\\\?\\". */ | ||
| 587 | const | ||
| 588 | Func_SHGetPathFromIDListEx | ||
| 589 | func_SHGetPathFromIDListEx = Z7_GET_PROC_ADDRESS( | ||
| 590 | Func_SHGetPathFromIDListEx, ::GetModuleHandleW(L"shell32.dll"), | ||
| 591 | "SHGetPathFromIDListEx"); | ||
| 592 | if (func_SHGetPathFromIDListEx) | ||
| 593 | { | ||
| 594 | ODS("==== GetPathFromIDList() (SHGetPathFromIDListEx)") | ||
| 595 | do | ||
| 596 | { | ||
| 597 | len *= 4; | ||
| 598 | result = BOOLToBool(func_SHGetPathFromIDListEx(itemIDList, path.GetBuf(len), len, 0)); | ||
| 599 | if (result) | ||
| 600 | break; | ||
| 601 | } | ||
| 602 | while (len <= (1 << 16)); | ||
| 603 | } | ||
| 604 | } | ||
| 605 | |||
| 145 | path.ReleaseBuf_CalcLen(len); | 606 | path.ReleaseBuf_CalcLen(len); |
| 146 | return result; | 607 | return result; |
| 147 | } | 608 | } |
| @@ -180,11 +641,16 @@ bool BrowseForFolder(HWND /* owner */, LPCTSTR /* title */, | |||
| 180 | 641 | ||
| 181 | #else | 642 | #else |
| 182 | 643 | ||
| 644 | /* win10: SHBrowseForFolder() doesn't support long paths, | ||
| 645 | even if long path suppport is enabled in registry and in manifest. | ||
| 646 | and SHBrowseForFolder() doesn't support super path prefix "\\\\?\\". */ | ||
| 647 | |||
| 183 | bool BrowseForFolder(LPBROWSEINFO browseInfo, CSysString &resultPath) | 648 | bool BrowseForFolder(LPBROWSEINFO browseInfo, CSysString &resultPath) |
| 184 | { | 649 | { |
| 650 | resultPath.Empty(); | ||
| 185 | NWindows::NCOM::CComInitializer comInitializer; | 651 | NWindows::NCOM::CComInitializer comInitializer; |
| 186 | LPITEMIDLIST itemIDList = ::SHBrowseForFolder(browseInfo); | 652 | LPITEMIDLIST itemIDList = ::SHBrowseForFolder(browseInfo); |
| 187 | if (itemIDList == NULL) | 653 | if (!itemIDList) |
| 188 | return false; | 654 | return false; |
| 189 | CItemIDList itemIDListHolder; | 655 | CItemIDList itemIDListHolder; |
| 190 | itemIDListHolder.Attach(itemIDList); | 656 | itemIDListHolder.Attach(itemIDList); |
| @@ -240,11 +706,18 @@ static bool BrowseForFolder(HWND owner, LPCTSTR title, UINT ulFlags, | |||
| 240 | browseInfo.lpszTitle = title; | 706 | browseInfo.lpszTitle = title; |
| 241 | // #endif | 707 | // #endif |
| 242 | browseInfo.ulFlags = ulFlags; | 708 | browseInfo.ulFlags = ulFlags; |
| 243 | browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc : NULL; | 709 | browseInfo.lpfn = initialFolder ? BrowseCallbackProc : NULL; |
| 244 | browseInfo.lParam = (LPARAM)initialFolder; | 710 | browseInfo.lParam = (LPARAM)initialFolder; |
| 245 | return BrowseForFolder(&browseInfo, resultPath); | 711 | return BrowseForFolder(&browseInfo, resultPath); |
| 246 | } | 712 | } |
| 247 | 713 | ||
| 714 | #ifdef Z7_OLD_WIN_SDK | ||
| 715 | // ShlObj.h: | ||
| 716 | #ifndef BIF_NEWDIALOGSTYLE | ||
| 717 | #define BIF_NEWDIALOGSTYLE 0x0040 | ||
| 718 | #endif | ||
| 719 | #endif | ||
| 720 | |||
| 248 | bool BrowseForFolder(HWND owner, LPCTSTR title, | 721 | bool BrowseForFolder(HWND owner, LPCTSTR title, |
| 249 | LPCTSTR initialFolder, CSysString &resultPath) | 722 | LPCTSTR initialFolder, CSysString &resultPath) |
| 250 | { | 723 | { |
| @@ -259,38 +732,21 @@ bool BrowseForFolder(HWND owner, LPCTSTR title, | |||
| 259 | #ifndef _UNICODE | 732 | #ifndef _UNICODE |
| 260 | 733 | ||
| 261 | extern "C" { | 734 | extern "C" { |
| 262 | typedef BOOL (WINAPI * Func_SHGetPathFromIDListW)(LPCITEMIDLIST pidl, LPWSTR pszPath); | ||
| 263 | typedef LPITEMIDLIST (WINAPI * Func_SHBrowseForFolderW)(LPBROWSEINFOW lpbi); | 735 | typedef LPITEMIDLIST (WINAPI * Func_SHBrowseForFolderW)(LPBROWSEINFOW lpbi); |
| 264 | } | 736 | } |
| 265 | 737 | ||
| 266 | #define MY_CAST_FUNC (void(*)()) | ||
| 267 | // #define MY_CAST_FUNC | ||
| 268 | |||
| 269 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path) | ||
| 270 | { | ||
| 271 | path.Empty(); | ||
| 272 | Func_SHGetPathFromIDListW shGetPathFromIDListW = (Func_SHGetPathFromIDListW) | ||
| 273 | MY_CAST_FUNC | ||
| 274 | ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "SHGetPathFromIDListW"); | ||
| 275 | if (!shGetPathFromIDListW) | ||
| 276 | return false; | ||
| 277 | const unsigned len = MAX_PATH * 2; | ||
| 278 | bool result = BOOLToBool(shGetPathFromIDListW(itemIDList, path.GetBuf(len))); | ||
| 279 | path.ReleaseBuf_CalcLen(len); | ||
| 280 | return result; | ||
| 281 | } | ||
| 282 | |||
| 283 | |||
| 284 | static bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath) | 738 | static bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath) |
| 285 | { | 739 | { |
| 286 | NWindows::NCOM::CComInitializer comInitializer; | 740 | NWindows::NCOM::CComInitializer comInitializer; |
| 287 | Func_SHBrowseForFolderW shBrowseForFolderW = (Func_SHBrowseForFolderW) | 741 | const |
| 288 | MY_CAST_FUNC | 742 | Func_SHBrowseForFolderW |
| 289 | ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "SHBrowseForFolderW"); | 743 | f_SHBrowseForFolderW = Z7_GET_PROC_ADDRESS( |
| 290 | if (!shBrowseForFolderW) | 744 | Func_SHBrowseForFolderW, ::GetModuleHandleW(L"shell32.dll"), |
| 745 | "SHBrowseForFolderW"); | ||
| 746 | if (!f_SHBrowseForFolderW) | ||
| 291 | return false; | 747 | return false; |
| 292 | LPITEMIDLIST itemIDList = shBrowseForFolderW(browseInfo); | 748 | LPITEMIDLIST itemIDList = f_SHBrowseForFolderW(browseInfo); |
| 293 | if (itemIDList == NULL) | 749 | if (!itemIDList) |
| 294 | return false; | 750 | return false; |
| 295 | CItemIDList itemIDListHolder; | 751 | CItemIDList itemIDListHolder; |
| 296 | itemIDListHolder.Attach(itemIDList); | 752 | itemIDListHolder.Attach(itemIDList); |
| @@ -336,7 +792,7 @@ static bool BrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags, | |||
| 336 | browseInfo.pszDisplayName = displayName.GetBuf(MAX_PATH); | 792 | browseInfo.pszDisplayName = displayName.GetBuf(MAX_PATH); |
| 337 | browseInfo.lpszTitle = title; | 793 | browseInfo.lpszTitle = title; |
| 338 | browseInfo.ulFlags = ulFlags; | 794 | browseInfo.ulFlags = ulFlags; |
| 339 | browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc2 : NULL; | 795 | browseInfo.lpfn = initialFolder ? BrowseCallbackProc2 : NULL; |
| 340 | browseInfo.lParam = (LPARAM)initialFolder; | 796 | browseInfo.lParam = (LPARAM)initialFolder; |
| 341 | return BrowseForFolder(&browseInfo, resultPath); | 797 | return BrowseForFolder(&browseInfo, resultPath); |
| 342 | } | 798 | } |
diff --git a/CPP/Windows/Shell.h b/CPP/Windows/Shell.h index de91d3f..b4cdb30 100644 --- a/CPP/Windows/Shell.h +++ b/CPP/Windows/Shell.h | |||
| @@ -1,17 +1,22 @@ | |||
| 1 | // Windows/Shell.h | 1 | // Windows/Shell.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_SHELL_H | 3 | #ifndef ZIP7_WINDOWS_SHELL_H |
| 4 | #define __WINDOWS_SHELL_H | 4 | #define ZIP7_WINDOWS_SHELL_H |
| 5 | 5 | ||
| 6 | #include "../Common/Common.h" | ||
| 6 | #include "../Common/MyWindows.h" | 7 | #include "../Common/MyWindows.h" |
| 8 | #if defined(__MINGW32__) || defined(__MINGW64__) | ||
| 9 | #include <shlobj.h> | ||
| 10 | #else | ||
| 7 | #include <ShlObj.h> | 11 | #include <ShlObj.h> |
| 12 | #endif | ||
| 8 | 13 | ||
| 9 | #include "../Common/MyString.h" | 14 | #include "../Common/MyString.h" |
| 10 | 15 | ||
| 11 | #include "Defs.h" | 16 | #include "Defs.h" |
| 12 | 17 | ||
| 13 | namespace NWindows{ | 18 | namespace NWindows { |
| 14 | namespace NShell{ | 19 | namespace NShell { |
| 15 | 20 | ||
| 16 | ///////////////////////// | 21 | ///////////////////////// |
| 17 | // CItemIDList | 22 | // CItemIDList |
| @@ -20,6 +25,7 @@ namespace NShell{ | |||
| 20 | class CItemIDList | 25 | class CItemIDList |
| 21 | { | 26 | { |
| 22 | LPITEMIDLIST m_Object; | 27 | LPITEMIDLIST m_Object; |
| 28 | Z7_CLASS_NO_COPY(CItemIDList) | ||
| 23 | public: | 29 | public: |
| 24 | CItemIDList(): m_Object(NULL) {} | 30 | CItemIDList(): m_Object(NULL) {} |
| 25 | // CItemIDList(LPCITEMIDLIST itemIDList); | 31 | // CItemIDList(LPCITEMIDLIST itemIDList); |
| @@ -49,6 +55,7 @@ public: | |||
| 49 | ///////////////////////////// | 55 | ///////////////////////////// |
| 50 | // CDrop | 56 | // CDrop |
| 51 | 57 | ||
| 58 | /* | ||
| 52 | class CDrop | 59 | class CDrop |
| 53 | { | 60 | { |
| 54 | HDROP m_Object; | 61 | HDROP m_Object; |
| @@ -63,22 +70,51 @@ public: | |||
| 63 | operator HDROP() { return m_Object;} | 70 | operator HDROP() { return m_Object;} |
| 64 | bool QueryPoint(LPPOINT point) | 71 | bool QueryPoint(LPPOINT point) |
| 65 | { return BOOLToBool(::DragQueryPoint(m_Object, point)); } | 72 | { return BOOLToBool(::DragQueryPoint(m_Object, point)); } |
| 66 | void Finish() { ::DragFinish(m_Object); } | 73 | void Finish() |
| 67 | UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT fileNameSize) | 74 | { |
| 68 | { return ::DragQueryFile(m_Object, fileIndex, fileName, fileNameSize); } | 75 | ::DragFinish(m_Object); |
| 76 | } | ||
| 77 | UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT bufSize) | ||
| 78 | { return ::DragQueryFile(m_Object, fileIndex, fileName, bufSize); } | ||
| 69 | #ifndef _UNICODE | 79 | #ifndef _UNICODE |
| 70 | UINT QueryFile(UINT fileIndex, LPWSTR fileName, UINT fileNameSize) | 80 | UINT QueryFile(UINT fileIndex, LPWSTR fileName, UINT bufSize) |
| 71 | { return ::DragQueryFileW(m_Object, fileIndex, fileName, fileNameSize); } | 81 | { return ::DragQueryFileW(m_Object, fileIndex, fileName, bufSize); } |
| 72 | #endif | 82 | #endif |
| 73 | UINT QueryCountOfFiles(); | 83 | UINT QueryCountOfFiles(); |
| 74 | UString QueryFileName(UINT fileIndex); | 84 | void QueryFileName(UINT fileIndex, UString &fileName); |
| 75 | void QueryFileNames(UStringVector &fileNames); | 85 | void QueryFileNames(UStringVector &fileNames); |
| 76 | }; | 86 | }; |
| 77 | 87 | */ | |
| 78 | #endif | 88 | #endif |
| 79 | 89 | ||
| 80 | ///////////////////////////// | 90 | struct CFileAttribs |
| 81 | // Functions | 91 | { |
| 92 | int FirstDirIndex; | ||
| 93 | // DWORD Sum; | ||
| 94 | // DWORD Product; | ||
| 95 | // CRecordVector<DWORD> Vals; | ||
| 96 | // CRecordVector<bool> IsDirVector; | ||
| 97 | |||
| 98 | CFileAttribs() | ||
| 99 | { | ||
| 100 | Clear(); | ||
| 101 | } | ||
| 102 | |||
| 103 | void Clear() | ||
| 104 | { | ||
| 105 | FirstDirIndex = -1; | ||
| 106 | // Sum = 0; | ||
| 107 | // Product = 0; | ||
| 108 | // IsDirVector.Clear(); | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | |||
| 112 | |||
| 113 | /* read pathnames from HDROP or SHELLIDLIST. | ||
| 114 | The parser can return E_INVALIDARG, if there is some unexpected data in dataObject */ | ||
| 115 | HRESULT DataObject_GetData_HDROP_or_IDLIST_Names(IDataObject *dataObject, UStringVector &names); | ||
| 116 | |||
| 117 | HRESULT DataObject_GetData_FILE_ATTRS(IDataObject *dataObject, CFileAttribs &attribs); | ||
| 82 | 118 | ||
| 83 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path); | 119 | bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path); |
| 84 | bool BrowseForFolder(LPBROWSEINFO lpbi, CSysString &resultPath); | 120 | bool BrowseForFolder(LPBROWSEINFO lpbi, CSysString &resultPath); |
diff --git a/CPP/Windows/StdAfx.h b/CPP/Windows/StdAfx.h index 1766dfa..bd5084f 100644 --- a/CPP/Windows/StdAfx.h +++ b/CPP/Windows/StdAfx.h | |||
| @@ -1,7 +1,11 @@ | |||
| 1 | // StdAfx.h | 1 | // StdAfx.h |
| 2 | 2 | ||
| 3 | #ifndef __STDAFX_H | 3 | #ifndef ZIP7_INC_STDAFX_H |
| 4 | #define __STDAFX_H | 4 | #define ZIP7_INC_STDAFX_H |
| 5 | |||
| 6 | #if defined(_MSC_VER) && _MSC_VER >= 1800 | ||
| 7 | #pragma warning(disable : 4464) // relative include path contains '..' | ||
| 8 | #endif | ||
| 5 | 9 | ||
| 6 | #include "../Common/Common.h" | 10 | #include "../Common/Common.h" |
| 7 | 11 | ||
diff --git a/CPP/Windows/Synchronization.cpp b/CPP/Windows/Synchronization.cpp index fbf919d..d5542af 100644 --- a/CPP/Windows/Synchronization.cpp +++ b/CPP/Windows/Synchronization.cpp | |||
| @@ -19,6 +19,30 @@ namespace NSynchronization { | |||
| 19 | DWORD WaitForMultipleObjects(DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout); | 19 | DWORD WaitForMultipleObjects(DWORD count, const HANDLE *handles, BOOL wait_all, DWORD timeout); |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | /* clang: we need to place some virtual functions in cpp file to rid off the warning: | ||
| 23 | 'CBaseHandle_WFMO' has no out-of-line virtual method definitions; | ||
| 24 | its vtable will be emitted in every translation unit */ | ||
| 25 | CBaseHandle_WFMO::~CBaseHandle_WFMO() | ||
| 26 | { | ||
| 27 | } | ||
| 28 | |||
| 29 | bool CBaseEvent_WFMO::IsSignaledAndUpdate() | ||
| 30 | { | ||
| 31 | if (this->_state == false) | ||
| 32 | return false; | ||
| 33 | if (this->_manual_reset == false) | ||
| 34 | this->_state = false; | ||
| 35 | return true; | ||
| 36 | } | ||
| 37 | |||
| 38 | bool CSemaphore_WFMO::IsSignaledAndUpdate() | ||
| 39 | { | ||
| 40 | if (this->_count == 0) | ||
| 41 | return false; | ||
| 42 | this->_count--; | ||
| 43 | return true; | ||
| 44 | } | ||
| 45 | |||
| 22 | DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles) | 46 | DWORD WINAPI WaitForMultiObj_Any_Infinite(DWORD count, const CHandle_WFMO *handles) |
| 23 | { | 47 | { |
| 24 | if (count < 1) | 48 | if (count < 1) |
diff --git a/CPP/Windows/Synchronization.h b/CPP/Windows/Synchronization.h index 7d2e8d2..afd03d2 100644 --- a/CPP/Windows/Synchronization.h +++ b/CPP/Windows/Synchronization.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Synchronization.h | 1 | // Windows/Synchronization.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_SYNCHRONIZATION_H | 3 | #ifndef ZIP7_INC_WINDOWS_SYNCHRONIZATION_H |
| 4 | #define __WINDOWS_SYNCHRONIZATION_H | 4 | #define ZIP7_INC_WINDOWS_SYNCHRONIZATION_H |
| 5 | 5 | ||
| 6 | #include "../../C/Threads.h" | 6 | #include "../../C/Threads.h" |
| 7 | 7 | ||
| @@ -32,14 +32,14 @@ public: | |||
| 32 | WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES sa = NULL) | 32 | WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL, LPSECURITY_ATTRIBUTES sa = NULL) |
| 33 | { | 33 | { |
| 34 | _object = ::CreateEvent(sa, BoolToBOOL(manualReset), BoolToBOOL(initiallyOwn), name); | 34 | _object = ::CreateEvent(sa, BoolToBOOL(manualReset), BoolToBOOL(initiallyOwn), name); |
| 35 | if (name == NULL && _object != 0) | 35 | if (name == NULL && _object != NULL) |
| 36 | return 0; | 36 | return 0; |
| 37 | return ::GetLastError(); | 37 | return ::GetLastError(); |
| 38 | } | 38 | } |
| 39 | WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) | 39 | WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) |
| 40 | { | 40 | { |
| 41 | _object = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name); | 41 | _object = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name); |
| 42 | if (_object != 0) | 42 | if (_object != NULL) |
| 43 | return 0; | 43 | return 0; |
| 44 | return ::GetLastError(); | 44 | return ::GetLastError(); |
| 45 | } | 45 | } |
| @@ -227,8 +227,8 @@ public: | |||
| 227 | } | 227 | } |
| 228 | WRes Create() | 228 | WRes Create() |
| 229 | { | 229 | { |
| 230 | RINOK(::pthread_mutex_init(&_mutex, 0)); | 230 | RINOK(::pthread_mutex_init(&_mutex, NULL)) |
| 231 | WRes ret = ::pthread_cond_init(&_cond, 0); | 231 | const WRes ret = ::pthread_cond_init(&_cond, NULL); |
| 232 | _isValid = 1; | 232 | _isValid = 1; |
| 233 | return ret; | 233 | return ret; |
| 234 | } | 234 | } |
| @@ -246,8 +246,8 @@ public: | |||
| 246 | } | 246 | } |
| 247 | WRes LeaveAndSignal() | 247 | WRes LeaveAndSignal() |
| 248 | { | 248 | { |
| 249 | WRes res1 = ::pthread_cond_broadcast(&_cond); | 249 | const WRes res1 = ::pthread_cond_broadcast(&_cond); |
| 250 | WRes res2 = ::pthread_mutex_unlock(&_mutex); | 250 | const WRes res2 = ::pthread_mutex_unlock(&_mutex); |
| 251 | return (res2 ? res2 : res1); | 251 | return (res2 ? res2 : res1); |
| 252 | } | 252 | } |
| 253 | }; | 253 | }; |
| @@ -268,6 +268,7 @@ struct CBaseHandle_WFMO MY_UNCOPYABLE | |||
| 268 | CSynchro *_sync; | 268 | CSynchro *_sync; |
| 269 | 269 | ||
| 270 | CBaseHandle_WFMO(): _sync(NULL) {} | 270 | CBaseHandle_WFMO(): _sync(NULL) {} |
| 271 | virtual ~CBaseHandle_WFMO(); | ||
| 271 | 272 | ||
| 272 | operator CHandle_WFMO() { return this; } | 273 | operator CHandle_WFMO() { return this; } |
| 273 | virtual bool IsSignaledAndUpdate() = 0; | 274 | virtual bool IsSignaledAndUpdate() = 0; |
| @@ -283,7 +284,7 @@ public: | |||
| 283 | 284 | ||
| 284 | // bool IsCreated() { return (this->_sync != NULL); } | 285 | // bool IsCreated() { return (this->_sync != NULL); } |
| 285 | // CBaseEvent_WFMO() { ; } | 286 | // CBaseEvent_WFMO() { ; } |
| 286 | ~CBaseEvent_WFMO() { Close(); } | 287 | // ~CBaseEvent_WFMO() Z7_override { Close(); } |
| 287 | 288 | ||
| 288 | WRes Close() { this->_sync = NULL; return 0; } | 289 | WRes Close() { this->_sync = NULL; return 0; } |
| 289 | 290 | ||
| @@ -299,37 +300,30 @@ public: | |||
| 299 | 300 | ||
| 300 | WRes Set() | 301 | WRes Set() |
| 301 | { | 302 | { |
| 302 | RINOK(this->_sync->Enter()); | 303 | RINOK(this->_sync->Enter()) |
| 303 | this->_state = true; | 304 | this->_state = true; |
| 304 | return this->_sync->LeaveAndSignal(); | 305 | return this->_sync->LeaveAndSignal(); |
| 305 | } | 306 | } |
| 306 | 307 | ||
| 307 | WRes Reset() | 308 | WRes Reset() |
| 308 | { | 309 | { |
| 309 | RINOK(this->_sync->Enter()); | 310 | RINOK(this->_sync->Enter()) |
| 310 | this->_state = false; | 311 | this->_state = false; |
| 311 | return this->_sync->Leave(); | 312 | return this->_sync->Leave(); |
| 312 | } | 313 | } |
| 313 | 314 | ||
| 314 | virtual bool IsSignaledAndUpdate() | 315 | virtual bool IsSignaledAndUpdate() Z7_override; |
| 315 | { | ||
| 316 | if (this->_state == false) | ||
| 317 | return false; | ||
| 318 | if (this->_manual_reset == false) | ||
| 319 | this->_state = false; | ||
| 320 | return true; | ||
| 321 | } | ||
| 322 | }; | 316 | }; |
| 323 | 317 | ||
| 324 | 318 | ||
| 325 | class CManualResetEvent_WFMO: public CBaseEvent_WFMO | 319 | class CManualResetEvent_WFMO Z7_final: public CBaseEvent_WFMO |
| 326 | { | 320 | { |
| 327 | public: | 321 | public: |
| 328 | WRes Create(CSynchro *sync, bool initiallyOwn = false) { return CBaseEvent_WFMO::Create(sync, true, initiallyOwn); } | 322 | WRes Create(CSynchro *sync, bool initiallyOwn = false) { return CBaseEvent_WFMO::Create(sync, true, initiallyOwn); } |
| 329 | }; | 323 | }; |
| 330 | 324 | ||
| 331 | 325 | ||
| 332 | class CAutoResetEvent_WFMO: public CBaseEvent_WFMO | 326 | class CAutoResetEvent_WFMO Z7_final: public CBaseEvent_WFMO |
| 333 | { | 327 | { |
| 334 | public: | 328 | public: |
| 335 | WRes Create(CSynchro *sync) { return CBaseEvent_WFMO::Create(sync, false, false); } | 329 | WRes Create(CSynchro *sync) { return CBaseEvent_WFMO::Create(sync, false, false); } |
| @@ -340,7 +334,7 @@ public: | |||
| 340 | }; | 334 | }; |
| 341 | 335 | ||
| 342 | 336 | ||
| 343 | class CSemaphore_WFMO : public CBaseHandle_WFMO | 337 | class CSemaphore_WFMO Z7_final: public CBaseHandle_WFMO |
| 344 | { | 338 | { |
| 345 | UInt32 _count; | 339 | UInt32 _count; |
| 346 | UInt32 _maxCount; | 340 | UInt32 _maxCount; |
| @@ -365,11 +359,11 @@ public: | |||
| 365 | if (releaseCount < 1) | 359 | if (releaseCount < 1) |
| 366 | return EINVAL; | 360 | return EINVAL; |
| 367 | 361 | ||
| 368 | RINOK(this->_sync->Enter()); | 362 | RINOK(this->_sync->Enter()) |
| 369 | UInt32 newCount = this->_count + releaseCount; | 363 | UInt32 newCount = this->_count + releaseCount; |
| 370 | if (newCount > this->_maxCount) | 364 | if (newCount > this->_maxCount) |
| 371 | { | 365 | { |
| 372 | RINOK(this->_sync->Leave()); | 366 | RINOK(this->_sync->Leave()) |
| 373 | return ERROR_TOO_MANY_POSTS; // EINVAL | 367 | return ERROR_TOO_MANY_POSTS; // EINVAL |
| 374 | } | 368 | } |
| 375 | this->_count = newCount; | 369 | this->_count = newCount; |
| @@ -377,13 +371,7 @@ public: | |||
| 377 | return this->_sync->LeaveAndSignal(); | 371 | return this->_sync->LeaveAndSignal(); |
| 378 | } | 372 | } |
| 379 | 373 | ||
| 380 | virtual bool IsSignaledAndUpdate() | 374 | virtual bool IsSignaledAndUpdate() Z7_override; |
| 381 | { | ||
| 382 | if (this->_count == 0) | ||
| 383 | return false; | ||
| 384 | this->_count--; | ||
| 385 | return true; | ||
| 386 | } | ||
| 387 | }; | 375 | }; |
| 388 | 376 | ||
| 389 | #endif // _WIN32 | 377 | #endif // _WIN32 |
diff --git a/CPP/Windows/System.cpp b/CPP/Windows/System.cpp index 3a14b77..dbe287a 100644 --- a/CPP/Windows/System.cpp +++ b/CPP/Windows/System.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #ifndef _WIN32 | 5 | #ifndef _WIN32 |
| 6 | #include <unistd.h> | 6 | #include <unistd.h> |
| 7 | #include <limits.h> | ||
| 7 | #ifdef __APPLE__ | 8 | #ifdef __APPLE__ |
| 8 | #include <sys/sysctl.h> | 9 | #include <sys/sysctl.h> |
| 9 | #else | 10 | #else |
| @@ -74,7 +75,7 @@ BOOL CProcessAffinity::Get() | |||
| 74 | return TRUE; | 75 | return TRUE; |
| 75 | */ | 76 | */ |
| 76 | 77 | ||
| 77 | #ifdef _7ZIP_AFFINITY_SUPPORTED | 78 | #ifdef Z7_AFFINITY_SUPPORTED |
| 78 | 79 | ||
| 79 | // numSysThreads = sysconf(_SC_NPROCESSORS_ONLN); // The number of processors currently online | 80 | // numSysThreads = sysconf(_SC_NPROCESSORS_ONLN); // The number of processors currently online |
| 80 | if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0) | 81 | if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0) |
| @@ -93,7 +94,7 @@ BOOL CProcessAffinity::Get() | |||
| 93 | 94 | ||
| 94 | UInt32 GetNumberOfProcessors() | 95 | UInt32 GetNumberOfProcessors() |
| 95 | { | 96 | { |
| 96 | #ifndef _7ZIP_ST | 97 | #ifndef Z7_ST |
| 97 | long n = sysconf(_SC_NPROCESSORS_CONF); // The number of processors configured | 98 | long n = sysconf(_SC_NPROCESSORS_CONF); // The number of processors configured |
| 98 | if (n < 1) | 99 | if (n < 1) |
| 99 | n = 1; | 100 | n = 1; |
| @@ -110,7 +111,8 @@ UInt32 GetNumberOfProcessors() | |||
| 110 | 111 | ||
| 111 | #ifndef UNDER_CE | 112 | #ifndef UNDER_CE |
| 112 | 113 | ||
| 113 | #if !defined(_WIN64) && defined(__GNUC__) | 114 | #if !defined(_WIN64) && \ |
| 115 | (defined(__MINGW32_VERSION) || defined(Z7_OLD_WIN_SDK)) | ||
| 114 | 116 | ||
| 115 | typedef struct _MY_MEMORYSTATUSEX { | 117 | typedef struct _MY_MEMORYSTATUSEX { |
| 116 | DWORD dwLength; | 118 | DWORD dwLength; |
| @@ -131,7 +133,7 @@ typedef struct _MY_MEMORYSTATUSEX { | |||
| 131 | 133 | ||
| 132 | #endif | 134 | #endif |
| 133 | 135 | ||
| 134 | typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer); | 136 | typedef BOOL (WINAPI *Func_GlobalMemoryStatusEx)(MY_LPMEMORYSTATUSEX lpBuffer); |
| 135 | 137 | ||
| 136 | #endif // !UNDER_CE | 138 | #endif // !UNDER_CE |
| 137 | 139 | ||
| @@ -155,9 +157,11 @@ bool GetRamSize(UInt64 &size) | |||
| 155 | #else | 157 | #else |
| 156 | 158 | ||
| 157 | #ifndef UNDER_CE | 159 | #ifndef UNDER_CE |
| 158 | GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) | 160 | const |
| 159 | (void *)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "GlobalMemoryStatusEx"); | 161 | Func_GlobalMemoryStatusEx fn = Z7_GET_PROC_ADDRESS( |
| 160 | if (globalMemoryStatusEx && globalMemoryStatusEx(&stat)) | 162 | Func_GlobalMemoryStatusEx, ::GetModuleHandleA("kernel32.dll"), |
| 163 | "GlobalMemoryStatusEx"); | ||
| 164 | if (fn && fn(&stat)) | ||
| 161 | { | 165 | { |
| 162 | size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); | 166 | size = MyMin(stat.ullTotalVirtual, stat.ullTotalPhys); |
| 163 | return true; | 167 | return true; |
| @@ -231,4 +235,44 @@ bool GetRamSize(UInt64 &size) | |||
| 231 | 235 | ||
| 232 | #endif | 236 | #endif |
| 233 | 237 | ||
| 238 | |||
| 239 | unsigned long Get_File_OPEN_MAX() | ||
| 240 | { | ||
| 241 | #ifdef _WIN32 | ||
| 242 | return (1 << 24) - (1 << 16); // ~16M handles | ||
| 243 | #else | ||
| 244 | // some linux versions have default open file limit for user process of 1024 files. | ||
| 245 | long n = sysconf(_SC_OPEN_MAX); | ||
| 246 | // n = -1; // for debug | ||
| 247 | // n = 9; // for debug | ||
| 248 | if (n < 1) | ||
| 249 | { | ||
| 250 | // n = OPEN_MAX; // ??? | ||
| 251 | // n = FOPEN_MAX; // = 16 : <stdio.h> | ||
| 252 | #ifdef _POSIX_OPEN_MAX | ||
| 253 | n = _POSIX_OPEN_MAX; // = 20 : <limits.h> | ||
| 254 | #else | ||
| 255 | n = 30; // our limit | ||
| 256 | #endif | ||
| 257 | } | ||
| 258 | return (unsigned long)n; | ||
| 259 | #endif | ||
| 260 | } | ||
| 261 | |||
| 262 | unsigned Get_File_OPEN_MAX_Reduced_for_3_tasks() | ||
| 263 | { | ||
| 264 | unsigned long numFiles_OPEN_MAX = NSystem::Get_File_OPEN_MAX(); | ||
| 265 | const unsigned delta = 10; // the reserve for another internal needs of process | ||
| 266 | if (numFiles_OPEN_MAX > delta) | ||
| 267 | numFiles_OPEN_MAX -= delta; | ||
| 268 | else | ||
| 269 | numFiles_OPEN_MAX = 1; | ||
| 270 | numFiles_OPEN_MAX /= 3; // we suppose that we have up to 3 tasks in total for multiple file processing | ||
| 271 | numFiles_OPEN_MAX = MyMax(numFiles_OPEN_MAX, (unsigned long)3); | ||
| 272 | unsigned n = (UInt32)(UInt32)-1; | ||
| 273 | if (n > numFiles_OPEN_MAX) | ||
| 274 | n = (unsigned)numFiles_OPEN_MAX; | ||
| 275 | return n; | ||
| 276 | } | ||
| 277 | |||
| 234 | }} | 278 | }} |
diff --git a/CPP/Windows/System.h b/CPP/Windows/System.h index 23cb0da..0650007 100644 --- a/CPP/Windows/System.h +++ b/CPP/Windows/System.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/System.h | 1 | // Windows/System.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_SYSTEM_H | 3 | #ifndef ZIP7_INC_WINDOWS_SYSTEM_H |
| 4 | #define __WINDOWS_SYSTEM_H | 4 | #define ZIP7_INC_WINDOWS_SYSTEM_H |
| 5 | 5 | ||
| 6 | #ifndef _WIN32 | 6 | #ifndef _WIN32 |
| 7 | // #include <sched.h> | 7 | // #include <sched.h> |
| @@ -9,11 +9,11 @@ | |||
| 9 | #endif | 9 | #endif |
| 10 | 10 | ||
| 11 | #include "../Common/MyTypes.h" | 11 | #include "../Common/MyTypes.h" |
| 12 | #include "../Common/MyWindows.h" | ||
| 12 | 13 | ||
| 13 | namespace NWindows { | 14 | namespace NWindows { |
| 14 | namespace NSystem { | 15 | namespace NSystem { |
| 15 | 16 | ||
| 16 | |||
| 17 | #ifdef _WIN32 | 17 | #ifdef _WIN32 |
| 18 | 18 | ||
| 19 | UInt32 CountAffinity(DWORD_PTR mask); | 19 | UInt32 CountAffinity(DWORD_PTR mask); |
| @@ -64,7 +64,7 @@ struct CProcessAffinity | |||
| 64 | UInt32 GetNumSystemThreads() const { return (UInt32)numSysThreads; } | 64 | UInt32 GetNumSystemThreads() const { return (UInt32)numSysThreads; } |
| 65 | BOOL Get(); | 65 | BOOL Get(); |
| 66 | 66 | ||
| 67 | #ifdef _7ZIP_AFFINITY_SUPPORTED | 67 | #ifdef Z7_AFFINITY_SUPPORTED |
| 68 | 68 | ||
| 69 | CCpuSet cpu_set; | 69 | CCpuSet cpu_set; |
| 70 | 70 | ||
| @@ -86,7 +86,7 @@ struct CProcessAffinity | |||
| 86 | return sched_setaffinity(0, sizeof(cpu_set), &cpu_set) == 0; | 86 | return sched_setaffinity(0, sizeof(cpu_set), &cpu_set) == 0; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | #else | 89 | #else // Z7_AFFINITY_SUPPORTED |
| 90 | 90 | ||
| 91 | void InitST() | 91 | void InitST() |
| 92 | { | 92 | { |
| @@ -114,16 +114,19 @@ struct CProcessAffinity | |||
| 114 | return FALSE; | 114 | return FALSE; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | #endif | 117 | #endif // Z7_AFFINITY_SUPPORTED |
| 118 | }; | 118 | }; |
| 119 | 119 | ||
| 120 | #endif | 120 | #endif // _WIN32 |
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | UInt32 GetNumberOfProcessors(); | 123 | UInt32 GetNumberOfProcessors(); |
| 124 | 124 | ||
| 125 | bool GetRamSize(UInt64 &size); // returns false, if unknown ram size | 125 | bool GetRamSize(UInt64 &size); // returns false, if unknown ram size |
| 126 | 126 | ||
| 127 | unsigned long Get_File_OPEN_MAX(); | ||
| 128 | unsigned Get_File_OPEN_MAX_Reduced_for_3_tasks(); | ||
| 129 | |||
| 127 | }} | 130 | }} |
| 128 | 131 | ||
| 129 | #endif | 132 | #endif |
diff --git a/CPP/Windows/SystemInfo.cpp b/CPP/Windows/SystemInfo.cpp index d882a8e..6bafc80 100644 --- a/CPP/Windows/SystemInfo.cpp +++ b/CPP/Windows/SystemInfo.cpp | |||
| @@ -102,38 +102,44 @@ static void PrintHex(AString &s, UInt64 v) | |||
| 102 | 102 | ||
| 103 | #ifdef MY_CPU_X86_OR_AMD64 | 103 | #ifdef MY_CPU_X86_OR_AMD64 |
| 104 | 104 | ||
| 105 | Z7_NO_INLINE | ||
| 105 | static void PrintCpuChars(AString &s, UInt32 v) | 106 | static void PrintCpuChars(AString &s, UInt32 v) |
| 106 | { | 107 | { |
| 107 | for (int j = 0; j < 4; j++) | 108 | for (unsigned j = 0; j < 4; j++) |
| 108 | { | 109 | { |
| 109 | Byte b = (Byte)(v & 0xFF); | 110 | Byte b = (Byte)(v & 0xFF); |
| 110 | v >>= 8; | 111 | v >>= 8; |
| 111 | if (b == 0) | 112 | if (b == 0) |
| 112 | break; | 113 | break; |
| 113 | s += (char)b; | 114 | if (b >= 0x20 && b <= 0x7f) |
| 115 | s += (char)b; | ||
| 116 | else | ||
| 117 | { | ||
| 118 | s += '['; | ||
| 119 | char temp[16]; | ||
| 120 | ConvertUInt32ToHex(b, temp); | ||
| 121 | s += temp; | ||
| 122 | s += ']'; | ||
| 123 | } | ||
| 114 | } | 124 | } |
| 115 | } | 125 | } |
| 116 | 126 | ||
| 117 | 127 | ||
| 118 | static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver) | 128 | static void x86cpuid_to_String(AString &s) |
| 119 | { | 129 | { |
| 120 | s.Empty(); | 130 | s.Empty(); |
| 121 | 131 | ||
| 122 | UInt32 maxFunc2 = 0; | 132 | UInt32 a[4]; |
| 123 | UInt32 t[3]; | 133 | // cpuid was called already. So we don't check for cpuid availability here |
| 134 | z7_x86_cpuid(a, 0x80000000); | ||
| 124 | 135 | ||
| 125 | MyCPUID(0x80000000, &maxFunc2, &t[0], &t[1], &t[2]); | 136 | if (a[0] >= 0x80000004) // if (maxFunc2 >= hi+4) the full name is available |
| 126 | |||
| 127 | bool fullNameIsAvail = (maxFunc2 >= 0x80000004); | ||
| 128 | |||
| 129 | if (fullNameIsAvail) | ||
| 130 | { | 137 | { |
| 131 | for (unsigned i = 0; i < 3; i++) | 138 | for (unsigned i = 0; i < 3; i++) |
| 132 | { | 139 | { |
| 133 | UInt32 d[4] = { 0 }; | 140 | z7_x86_cpuid(a, 0x80000002 + i); |
| 134 | MyCPUID(0x80000002 + i, &d[0], &d[1], &d[2], &d[3]); | ||
| 135 | for (unsigned j = 0; j < 4; j++) | 141 | for (unsigned j = 0; j < 4; j++) |
| 136 | PrintCpuChars(s, d[j]); | 142 | PrintCpuChars(s, a[j]); |
| 137 | } | 143 | } |
| 138 | } | 144 | } |
| 139 | 145 | ||
| @@ -141,16 +147,14 @@ static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver) | |||
| 141 | 147 | ||
| 142 | if (s.IsEmpty()) | 148 | if (s.IsEmpty()) |
| 143 | { | 149 | { |
| 144 | for (int i = 0; i < 3; i++) | 150 | z7_x86_cpuid(a, 0); |
| 145 | PrintCpuChars(s, c.vendor[i]); | 151 | for (unsigned i = 1; i < 4; i++) |
| 152 | { | ||
| 153 | const unsigned j = (i ^ (i >> 1)); | ||
| 154 | PrintCpuChars(s, a[j]); | ||
| 155 | } | ||
| 146 | s.Trim(); | 156 | s.Trim(); |
| 147 | } | 157 | } |
| 148 | |||
| 149 | { | ||
| 150 | char temp[32]; | ||
| 151 | ConvertUInt32ToHex(c.ver, temp); | ||
| 152 | ver += temp; | ||
| 153 | } | ||
| 154 | } | 158 | } |
| 155 | 159 | ||
| 156 | /* | 160 | /* |
| @@ -184,7 +188,7 @@ static void x86cpuid_all_to_String(AString &s) | |||
| 184 | { | 188 | { |
| 185 | char temp[32]; | 189 | char temp[32]; |
| 186 | ConvertUInt32ToHex8Digits(d[i], temp); | 190 | ConvertUInt32ToHex8Digits(d[i], temp); |
| 187 | s += " "; | 191 | s.Add_Space(); |
| 188 | s += temp; | 192 | s += temp; |
| 189 | } | 193 | } |
| 190 | } | 194 | } |
| @@ -215,12 +219,12 @@ static const char * const k_PROCESSOR_ARCHITECTURE[] = | |||
| 215 | , "ARM32_ON_WIN64" | 219 | , "ARM32_ON_WIN64" |
| 216 | }; | 220 | }; |
| 217 | 221 | ||
| 218 | #define MY__PROCESSOR_ARCHITECTURE_INTEL 0 | 222 | #define Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL 0 |
| 219 | #define MY__PROCESSOR_ARCHITECTURE_AMD64 9 | 223 | #define Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 9 |
| 220 | 224 | ||
| 221 | 225 | ||
| 222 | #define MY__PROCESSOR_INTEL_PENTIUM 586 | 226 | #define Z7_WIN_PROCESSOR_INTEL_PENTIUM 586 |
| 223 | #define MY__PROCESSOR_AMD_X8664 8664 | 227 | #define Z7_WIN_PROCESSOR_AMD_X8664 8664 |
| 224 | 228 | ||
| 225 | /* | 229 | /* |
| 226 | static const CUInt32PCharPair k_PROCESSOR[] = | 230 | static const CUInt32PCharPair k_PROCESSOR[] = |
| @@ -303,19 +307,20 @@ static const char * const k_PF[] = | |||
| 303 | #endif | 307 | #endif |
| 304 | 308 | ||
| 305 | 309 | ||
| 306 | #ifdef _WIN32 | 310 | static void PrintPage(AString &s, UInt64 v) |
| 307 | |||
| 308 | static void PrintPage(AString &s, UInt32 v) | ||
| 309 | { | 311 | { |
| 310 | if ((v & 0x3FF) == 0) | 312 | const char *t = "B"; |
| 313 | if ((v & 0x3ff) == 0) | ||
| 311 | { | 314 | { |
| 312 | s.Add_UInt32(v >> 10); | 315 | v >>= 10; |
| 313 | s += "K"; | 316 | t = "KB"; |
| 314 | } | 317 | } |
| 315 | else | 318 | s.Add_UInt64(v); |
| 316 | s.Add_UInt32(v >> 10); | 319 | s += t; |
| 317 | } | 320 | } |
| 318 | 321 | ||
| 322 | #ifdef _WIN32 | ||
| 323 | |||
| 319 | static AString TypeToString2(const char * const table[], unsigned num, UInt32 value) | 324 | static AString TypeToString2(const char * const table[], unsigned num, UInt32 value) |
| 320 | { | 325 | { |
| 321 | char sz[16]; | 326 | char sz[16]; |
| @@ -330,7 +335,7 @@ static AString TypeToString2(const char * const table[], unsigned num, UInt32 va | |||
| 330 | return (AString)p; | 335 | return (AString)p; |
| 331 | } | 336 | } |
| 332 | 337 | ||
| 333 | // #if defined(_7ZIP_LARGE_PAGES) || defined(_WIN32) | 338 | // #if defined(Z7_LARGE_PAGES) || defined(_WIN32) |
| 334 | // #ifdef _WIN32 | 339 | // #ifdef _WIN32 |
| 335 | void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v) | 340 | void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v) |
| 336 | { | 341 | { |
| @@ -342,32 +347,32 @@ void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v) | |||
| 342 | }}}} | 347 | }}}} |
| 343 | else | 348 | else |
| 344 | { | 349 | { |
| 350 | // s += "0x"; | ||
| 345 | PrintHex(s, v); | 351 | PrintHex(s, v); |
| 346 | return; | 352 | return; |
| 347 | } | 353 | } |
| 348 | char temp[32]; | 354 | s.Add_UInt64(v); |
| 349 | ConvertUInt64ToString(v, temp); | ||
| 350 | s += temp; | ||
| 351 | if (c) | 355 | if (c) |
| 352 | s += c; | 356 | s += c; |
| 357 | s += 'B'; | ||
| 353 | } | 358 | } |
| 354 | // #endif | 359 | // #endif |
| 355 | // #endif | 360 | // #endif |
| 356 | 361 | ||
| 357 | static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si) | 362 | static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si) |
| 358 | { | 363 | { |
| 359 | s += TypeToString2(k_PROCESSOR_ARCHITECTURE, ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture); | 364 | s += TypeToString2(k_PROCESSOR_ARCHITECTURE, Z7_ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture); |
| 360 | 365 | ||
| 361 | if (!( (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == MY__PROCESSOR_INTEL_PENTIUM) | 366 | if (!( (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == Z7_WIN_PROCESSOR_INTEL_PENTIUM) |
| 362 | || (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == MY__PROCESSOR_AMD_X8664))) | 367 | || (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == Z7_WIN_PROCESSOR_AMD_X8664))) |
| 363 | { | 368 | { |
| 364 | s += " "; | 369 | s.Add_Space(); |
| 365 | // s += TypePairToString(k_PROCESSOR, ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType); | 370 | // s += TypePairToString(k_PROCESSOR, Z7_ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType); |
| 366 | s.Add_UInt32(si.dwProcessorType); | 371 | s.Add_UInt32(si.dwProcessorType); |
| 367 | } | 372 | } |
| 368 | s += " "; | 373 | s.Add_Space(); |
| 369 | PrintHex(s, si.wProcessorLevel); | 374 | PrintHex(s, si.wProcessorLevel); |
| 370 | s += "."; | 375 | s.Add_Dot(); |
| 371 | PrintHex(s, si.wProcessorRevision); | 376 | PrintHex(s, si.wProcessorRevision); |
| 372 | if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors)) | 377 | if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors)) |
| 373 | if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8) | 378 | if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8) |
| @@ -387,9 +392,9 @@ static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si) | |||
| 387 | s += " gran:"; | 392 | s += " gran:"; |
| 388 | PrintPage(s, si.dwAllocationGranularity); | 393 | PrintPage(s, si.dwAllocationGranularity); |
| 389 | } | 394 | } |
| 390 | s += " "; | 395 | s.Add_Space(); |
| 391 | 396 | ||
| 392 | DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress; | 397 | const DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress; |
| 393 | UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1; | 398 | UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1; |
| 394 | const UInt32 kReserveSize = ((UInt32)1 << 16); | 399 | const UInt32 kReserveSize = ((UInt32)1 << 16); |
| 395 | if (minAdd != kReserveSize) | 400 | if (minAdd != kReserveSize) |
| @@ -419,7 +424,7 @@ static void Add_sysctlbyname_to_String(const char *name, AString &s) | |||
| 419 | { | 424 | { |
| 420 | size_t bufSize = 256; | 425 | size_t bufSize = 256; |
| 421 | char buf[256]; | 426 | char buf[256]; |
| 422 | if (My_sysctlbyname_Get(name, &buf, &bufSize) == 0) | 427 | if (z7_sysctlbyname_Get(name, &buf, &bufSize) == 0) |
| 423 | s += buf; | 428 | s += buf; |
| 424 | } | 429 | } |
| 425 | #endif | 430 | #endif |
| @@ -440,12 +445,14 @@ void GetSysInfo(AString &s1, AString &s2) | |||
| 440 | } | 445 | } |
| 441 | 446 | ||
| 442 | #if !defined(_WIN64) && !defined(UNDER_CE) | 447 | #if !defined(_WIN64) && !defined(UNDER_CE) |
| 443 | Func_GetNativeSystemInfo fn_GetNativeSystemInfo = (Func_GetNativeSystemInfo)(void *)GetProcAddress( | 448 | const |
| 444 | GetModuleHandleA("kernel32.dll"), "GetNativeSystemInfo"); | 449 | Func_GetNativeSystemInfo fn = Z7_GET_PROC_ADDRESS( |
| 445 | if (fn_GetNativeSystemInfo) | 450 | Func_GetNativeSystemInfo, GetModuleHandleA("kernel32.dll"), |
| 451 | "GetNativeSystemInfo"); | ||
| 452 | if (fn) | ||
| 446 | { | 453 | { |
| 447 | SYSTEM_INFO si2; | 454 | SYSTEM_INFO si2; |
| 448 | fn_GetNativeSystemInfo(&si2); | 455 | fn(&si2); |
| 449 | // if (memcmp(&si, &si2, sizeof(si)) != 0) | 456 | // if (memcmp(&si, &si2, sizeof(si)) != 0) |
| 450 | { | 457 | { |
| 451 | // s += " - "; | 458 | // s += " - "; |
| @@ -500,18 +507,20 @@ void CCpuName::Fill() | |||
| 500 | 507 | ||
| 501 | #ifdef MY_CPU_X86_OR_AMD64 | 508 | #ifdef MY_CPU_X86_OR_AMD64 |
| 502 | { | 509 | { |
| 503 | Cx86cpuid cpuid; | 510 | #if !defined(MY_CPU_AMD64) |
| 504 | if (x86cpuid_CheckAndRead(&cpuid)) | 511 | if (!z7_x86_cpuid_GetMaxFunc()) |
| 505 | { | 512 | s += "x86"; |
| 506 | x86cpuid_to_String(cpuid, s, Revision); | ||
| 507 | } | ||
| 508 | else | 513 | else |
| 509 | { | ||
| 510 | #ifdef MY_CPU_AMD64 | ||
| 511 | s += "x64"; | ||
| 512 | #else | ||
| 513 | s += "x86"; | ||
| 514 | #endif | 514 | #endif |
| 515 | { | ||
| 516 | x86cpuid_to_String(s); | ||
| 517 | { | ||
| 518 | UInt32 a[4]; | ||
| 519 | z7_x86_cpuid(a, 1); | ||
| 520 | char temp[16]; | ||
| 521 | ConvertUInt32ToHex(a[0], temp); | ||
| 522 | Revision += temp; | ||
| 523 | } | ||
| 515 | } | 524 | } |
| 516 | } | 525 | } |
| 517 | #elif defined(__APPLE__) | 526 | #elif defined(__APPLE__) |
| @@ -534,12 +543,12 @@ void CCpuName::Fill() | |||
| 534 | { | 543 | { |
| 535 | AString s2; | 544 | AString s2; |
| 536 | UInt32 v = 0; | 545 | UInt32 v = 0; |
| 537 | if (My_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0) | 546 | if (z7_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0) |
| 538 | { | 547 | { |
| 539 | s2.Add_UInt32(v); | 548 | s2.Add_UInt32(v); |
| 540 | s2 += 'C'; | 549 | s2 += 'C'; |
| 541 | } | 550 | } |
| 542 | if (My_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0) | 551 | if (z7_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0) |
| 543 | { | 552 | { |
| 544 | s2.Add_UInt32(v); | 553 | s2.Add_UInt32(v); |
| 545 | s2 += 'T'; | 554 | s2 += 'T'; |
| @@ -561,7 +570,7 @@ void CCpuName::Fill() | |||
| 561 | LONG res[2]; | 570 | LONG res[2]; |
| 562 | CByteBuffer bufs[2]; | 571 | CByteBuffer bufs[2]; |
| 563 | { | 572 | { |
| 564 | for (int i = 0; i < 2; i++) | 573 | for (unsigned i = 0; i < 2; i++) |
| 565 | { | 574 | { |
| 566 | UInt32 size = 0; | 575 | UInt32 size = 0; |
| 567 | res[i] = key.QueryValue(i == 0 ? | 576 | res[i] = key.QueryValue(i == 0 ? |
| @@ -574,7 +583,7 @@ void CCpuName::Fill() | |||
| 574 | } | 583 | } |
| 575 | if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS) | 584 | if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS) |
| 576 | { | 585 | { |
| 577 | for (int i = 0; i < 2; i++) | 586 | for (unsigned i = 0; i < 2; i++) |
| 578 | { | 587 | { |
| 579 | if (i == 1) | 588 | if (i == 1) |
| 580 | Microcode += "->"; | 589 | Microcode += "->"; |
| @@ -598,7 +607,7 @@ void CCpuName::Fill() | |||
| 598 | #endif | 607 | #endif |
| 599 | 608 | ||
| 600 | 609 | ||
| 601 | #ifdef _7ZIP_LARGE_PAGES | 610 | #ifdef Z7_LARGE_PAGES |
| 602 | Add_LargePages_String(LargePages); | 611 | Add_LargePages_String(LargePages); |
| 603 | #endif | 612 | #endif |
| 604 | } | 613 | } |
| @@ -608,7 +617,7 @@ void AddCpuFeatures(AString &s) | |||
| 608 | { | 617 | { |
| 609 | #ifdef _WIN32 | 618 | #ifdef _WIN32 |
| 610 | // const unsigned kNumFeatures_Extra = 32; // we check also for unknown features | 619 | // const unsigned kNumFeatures_Extra = 32; // we check also for unknown features |
| 611 | // const unsigned kNumFeatures = ARRAY_SIZE(k_PF) + kNumFeatures_Extra; | 620 | // const unsigned kNumFeatures = Z7_ARRAY_SIZE(k_PF) + kNumFeatures_Extra; |
| 612 | const unsigned kNumFeatures = 64; | 621 | const unsigned kNumFeatures = 64; |
| 613 | UInt64 flags = 0; | 622 | UInt64 flags = 0; |
| 614 | for (unsigned i = 0; i < kNumFeatures; i++) | 623 | for (unsigned i = 0; i < kNumFeatures; i++) |
| @@ -617,7 +626,7 @@ void AddCpuFeatures(AString &s) | |||
| 617 | { | 626 | { |
| 618 | flags += (UInt64)1 << i; | 627 | flags += (UInt64)1 << i; |
| 619 | // s.Add_Space_if_NotEmpty(); | 628 | // s.Add_Space_if_NotEmpty(); |
| 620 | // s += TypeToString2(k_PF, ARRAY_SIZE(k_PF), i); | 629 | // s += TypeToString2(k_PF, Z7_ARRAY_SIZE(k_PF), i); |
| 621 | } | 630 | } |
| 622 | } | 631 | } |
| 623 | s.Add_OptSpaced("f:"); | 632 | s.Add_OptSpaced("f:"); |
| @@ -626,11 +635,10 @@ void AddCpuFeatures(AString &s) | |||
| 626 | #elif defined(__APPLE__) | 635 | #elif defined(__APPLE__) |
| 627 | { | 636 | { |
| 628 | UInt32 v = 0; | 637 | UInt32 v = 0; |
| 629 | if (My_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0) | 638 | if (z7_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0) |
| 630 | { | 639 | { |
| 631 | s += "PageSize:"; | 640 | s.Add_OptSpaced("PageSize:"); |
| 632 | s.Add_UInt32(v >> 10); | 641 | PrintPage(s, v); |
| 633 | s += "KB"; | ||
| 634 | } | 642 | } |
| 635 | } | 643 | } |
| 636 | 644 | ||
| @@ -639,10 +647,8 @@ void AddCpuFeatures(AString &s) | |||
| 639 | const long v = sysconf(_SC_PAGESIZE); | 647 | const long v = sysconf(_SC_PAGESIZE); |
| 640 | if (v != -1) | 648 | if (v != -1) |
| 641 | { | 649 | { |
| 642 | s.Add_Space_if_NotEmpty(); | 650 | s.Add_OptSpaced("PageSize:"); |
| 643 | s += "PageSize:"; | 651 | PrintPage(s, (unsigned long)v); |
| 644 | s.Add_UInt32((UInt32)(v >> 10)); | ||
| 645 | s += "KB"; | ||
| 646 | } | 652 | } |
| 647 | 653 | ||
| 648 | #if !defined(_AIX) | 654 | #if !defined(_AIX) |
| @@ -659,11 +665,11 @@ void AddCpuFeatures(AString &s) | |||
| 659 | const int pos = s2.Find('['); | 665 | const int pos = s2.Find('['); |
| 660 | if (pos >= 0) | 666 | if (pos >= 0) |
| 661 | { | 667 | { |
| 662 | const int pos2 = s2.Find(']', pos + 1); | 668 | const int pos2 = s2.Find(']', (unsigned)pos + 1); |
| 663 | if (pos2 >= 0) | 669 | if (pos2 >= 0) |
| 664 | { | 670 | { |
| 665 | s2.DeleteFrom(pos2); | 671 | s2.DeleteFrom((unsigned)pos2); |
| 666 | s2.DeleteFrontal(pos + 1); | 672 | s2.DeleteFrontal((unsigned)pos + 1); |
| 667 | } | 673 | } |
| 668 | } | 674 | } |
| 669 | s += s2; | 675 | s += s2; |
| @@ -722,10 +728,13 @@ EXTERN_C_END | |||
| 722 | 728 | ||
| 723 | static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi) | 729 | static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi) |
| 724 | { | 730 | { |
| 725 | HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); | 731 | const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); |
| 726 | if (!ntdll) | 732 | if (!ntdll) |
| 727 | return FALSE; | 733 | return FALSE; |
| 728 | Func_RtlGetVersion func = (Func_RtlGetVersion)(void *)GetProcAddress(ntdll, "RtlGetVersion"); | 734 | const |
| 735 | Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS( | ||
| 736 | Func_RtlGetVersion, ntdll, | ||
| 737 | "RtlGetVersion"); | ||
| 729 | if (!func) | 738 | if (!func) |
| 730 | return FALSE; | 739 | return FALSE; |
| 731 | func(vi); | 740 | func(vi); |
| @@ -752,18 +761,18 @@ void GetOsInfoText(AString &sRes) | |||
| 752 | s += "Windows"; | 761 | s += "Windows"; |
| 753 | if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) | 762 | if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) |
| 754 | s.Add_UInt32(vi.dwPlatformId); | 763 | s.Add_UInt32(vi.dwPlatformId); |
| 755 | s += " "; s.Add_UInt32(vi.dwMajorVersion); | 764 | s.Add_Space(); s.Add_UInt32(vi.dwMajorVersion); |
| 756 | s += "."; s.Add_UInt32(vi.dwMinorVersion); | 765 | s.Add_Dot(); s.Add_UInt32(vi.dwMinorVersion); |
| 757 | s += " "; s.Add_UInt32(vi.dwBuildNumber); | 766 | s.Add_Space(); s.Add_UInt32(vi.dwBuildNumber); |
| 758 | 767 | ||
| 759 | if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0) | 768 | if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0) |
| 760 | { | 769 | { |
| 761 | s += " SP:"; s.Add_UInt32(vi.wServicePackMajor); | 770 | s += " SP:"; s.Add_UInt32(vi.wServicePackMajor); |
| 762 | s += "."; s.Add_UInt32(vi.wServicePackMinor); | 771 | s.Add_Dot(); s.Add_UInt32(vi.wServicePackMinor); |
| 763 | } | 772 | } |
| 764 | // s += " Suite:"; PrintHex(s, vi.wSuiteMask); | 773 | // s += " Suite:"; PrintHex(s, vi.wSuiteMask); |
| 765 | // s += " Type:"; s.Add_UInt32(vi.wProductType); | 774 | // s += " Type:"; s.Add_UInt32(vi.wProductType); |
| 766 | // s += " "; s += GetOemString(vi.szCSDVersion); | 775 | // s.Add_Space(); s += GetOemString(vi.szCSDVersion); |
| 767 | } | 776 | } |
| 768 | /* | 777 | /* |
| 769 | { | 778 | { |
| @@ -793,6 +802,17 @@ void GetOsInfoText(AString &sRes) | |||
| 793 | #endif // _WIN32 | 802 | #endif // _WIN32 |
| 794 | 803 | ||
| 795 | sRes += s; | 804 | sRes += s; |
| 805 | #ifdef MY_CPU_X86_OR_AMD64 | ||
| 806 | { | ||
| 807 | AString s2; | ||
| 808 | GetVirtCpuid(s2); | ||
| 809 | if (!s2.IsEmpty()) | ||
| 810 | { | ||
| 811 | sRes += " : "; | ||
| 812 | sRes += s2; | ||
| 813 | } | ||
| 814 | } | ||
| 815 | #endif | ||
| 796 | } | 816 | } |
| 797 | 817 | ||
| 798 | 818 | ||
| @@ -875,6 +895,61 @@ void GetCpuName_MultiLine(AString &s) | |||
| 875 | } | 895 | } |
| 876 | } | 896 | } |
| 877 | 897 | ||
| 898 | |||
| 899 | #ifdef MY_CPU_X86_OR_AMD64 | ||
| 900 | |||
| 901 | void GetVirtCpuid(AString &s) | ||
| 902 | { | ||
| 903 | const UInt32 kHv = 0x40000000; | ||
| 904 | |||
| 905 | Z7_IF_X86_CPUID_SUPPORTED | ||
| 906 | { | ||
| 907 | UInt32 a[4]; | ||
| 908 | z7_x86_cpuid(a, kHv); | ||
| 909 | |||
| 910 | if (a[0] < kHv || a[0] >= kHv + (1 << 16)) | ||
| 911 | return; | ||
| 912 | { | ||
| 913 | { | ||
| 914 | for (unsigned j = 1; j < 4; j++) | ||
| 915 | PrintCpuChars(s, a[j]); | ||
| 916 | } | ||
| 917 | } | ||
| 918 | if (a[0] >= kHv + 1) | ||
| 919 | { | ||
| 920 | UInt32 d[4]; | ||
| 921 | z7_x86_cpuid(d, kHv + 1); | ||
| 922 | s += " : "; | ||
| 923 | PrintCpuChars(s, d[0]); | ||
| 924 | if (a[0] >= kHv + 2) | ||
| 925 | { | ||
| 926 | z7_x86_cpuid(d, kHv + 2); | ||
| 927 | s += " : "; | ||
| 928 | s.Add_UInt32(d[1] >> 16); | ||
| 929 | s.Add_Dot(); s.Add_UInt32(d[1] & 0xffff); | ||
| 930 | s.Add_Dot(); s.Add_UInt32(d[0]); | ||
| 931 | s.Add_Dot(); s.Add_UInt32(d[2]); | ||
| 932 | s.Add_Dot(); s.Add_UInt32(d[3] >> 24); | ||
| 933 | s.Add_Dot(); s.Add_UInt32(d[3] & 0xffffff); | ||
| 934 | } | ||
| 935 | /* | ||
| 936 | if (a[0] >= kHv + 5) | ||
| 937 | { | ||
| 938 | z7_x86_cpuid(d, kHv + 5); | ||
| 939 | s += " : "; | ||
| 940 | s.Add_UInt32(d[0]); | ||
| 941 | s += "p"; | ||
| 942 | s.Add_UInt32(d[1]); | ||
| 943 | s += "t"; | ||
| 944 | } | ||
| 945 | */ | ||
| 946 | } | ||
| 947 | } | ||
| 948 | } | ||
| 949 | |||
| 950 | #endif | ||
| 951 | |||
| 952 | |||
| 878 | void GetCompiler(AString &s) | 953 | void GetCompiler(AString &s) |
| 879 | { | 954 | { |
| 880 | #ifdef __VERSION__ | 955 | #ifdef __VERSION__ |
| @@ -884,28 +959,28 @@ void GetCompiler(AString &s) | |||
| 884 | #ifdef __GNUC__ | 959 | #ifdef __GNUC__ |
| 885 | s += " GCC "; | 960 | s += " GCC "; |
| 886 | s.Add_UInt32(__GNUC__); | 961 | s.Add_UInt32(__GNUC__); |
| 887 | s += '.'; | 962 | s.Add_Dot(); |
| 888 | s.Add_UInt32(__GNUC_MINOR__); | 963 | s.Add_UInt32(__GNUC_MINOR__); |
| 889 | s += '.'; | 964 | s.Add_Dot(); |
| 890 | s.Add_UInt32(__GNUC_PATCHLEVEL__); | 965 | s.Add_UInt32(__GNUC_PATCHLEVEL__); |
| 891 | #endif | 966 | #endif |
| 892 | 967 | ||
| 893 | #ifdef __clang__ | 968 | #ifdef __clang__ |
| 894 | s += " CLANG "; | 969 | s += " CLANG "; |
| 895 | s.Add_UInt32(__clang_major__); | 970 | s.Add_UInt32(__clang_major__); |
| 896 | s += '.'; | 971 | s.Add_Dot(); |
| 897 | s.Add_UInt32(__clang_minor__); | 972 | s.Add_UInt32(__clang_minor__); |
| 898 | #endif | 973 | #endif |
| 899 | 974 | ||
| 900 | #ifdef __xlC__ | 975 | #ifdef __xlC__ |
| 901 | s += " XLC "; | 976 | s += " XLC "; |
| 902 | s.Add_UInt32(__xlC__ >> 8); | 977 | s.Add_UInt32(__xlC__ >> 8); |
| 903 | s += '.'; | 978 | s.Add_Dot(); |
| 904 | s.Add_UInt32(__xlC__ & 0xFF); | 979 | s.Add_UInt32(__xlC__ & 0xFF); |
| 905 | #ifdef __xlC_ver__ | 980 | #ifdef __xlC_ver__ |
| 906 | s += '.'; | 981 | s.Add_Dot(); |
| 907 | s.Add_UInt32(__xlC_ver__ >> 8); | 982 | s.Add_UInt32(__xlC_ver__ >> 8); |
| 908 | s += '.'; | 983 | s.Add_Dot(); |
| 909 | s.Add_UInt32(__xlC_ver__ & 0xFF); | 984 | s.Add_UInt32(__xlC_ver__ & 0xFF); |
| 910 | #endif | 985 | #endif |
| 911 | #endif | 986 | #endif |
| @@ -914,4 +989,34 @@ void GetCompiler(AString &s) | |||
| 914 | s += " MSC "; | 989 | s += " MSC "; |
| 915 | s.Add_UInt32(_MSC_VER); | 990 | s.Add_UInt32(_MSC_VER); |
| 916 | #endif | 991 | #endif |
| 992 | |||
| 993 | #if defined(__AVX2__) | ||
| 994 | #define MY_CPU_COMPILE_ISA "AVX2" | ||
| 995 | #elif defined(__AVX__) | ||
| 996 | #define MY_CPU_COMPILE_ISA "AVX" | ||
| 997 | #elif defined(__SSE2__) | ||
| 998 | #define MY_CPU_COMPILE_ISA "SSE2" | ||
| 999 | #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 2) | ||
| 1000 | #define MY_CPU_COMPILE_ISA "SSE2" | ||
| 1001 | #elif defined(__SSE__) | ||
| 1002 | #define MY_CPU_COMPILE_ISA "SSE" | ||
| 1003 | #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 1) | ||
| 1004 | #define MY_CPU_COMPILE_ISA "SSE" | ||
| 1005 | #elif defined(__i686__) | ||
| 1006 | #define MY_CPU_COMPILE_ISA "i686" | ||
| 1007 | #elif defined(__i586__) | ||
| 1008 | #define MY_CPU_COMPILE_ISA "i586" | ||
| 1009 | #elif defined(__i486__) | ||
| 1010 | #define MY_CPU_COMPILE_ISA "i486" | ||
| 1011 | #elif defined(__i386__) | ||
| 1012 | #define MY_CPU_COMPILE_ISA "i386" | ||
| 1013 | #elif defined(_M_IX86_FP) | ||
| 1014 | #define MY_CPU_COMPILE_ISA "IA32" | ||
| 1015 | #endif | ||
| 1016 | |||
| 1017 | |||
| 1018 | #ifdef MY_CPU_COMPILE_ISA | ||
| 1019 | s += ':'; | ||
| 1020 | s.Add_OptSpaced(MY_CPU_COMPILE_ISA); | ||
| 1021 | #endif | ||
| 917 | } | 1022 | } |
diff --git a/CPP/Windows/SystemInfo.h b/CPP/Windows/SystemInfo.h index e941d0a..c2e2e3b 100644 --- a/CPP/Windows/SystemInfo.h +++ b/CPP/Windows/SystemInfo.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/SystemInfo.h | 1 | // Windows/SystemInfo.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_SYSTEM_INFO_H | 3 | #ifndef ZIP7_INC_WINDOWS_SYSTEM_INFO_H |
| 4 | #define __WINDOWS_SYSTEM_INFO_H | 4 | #define ZIP7_INC_WINDOWS_SYSTEM_INFO_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyString.h" | 6 | #include "../Common/MyString.h" |
| 7 | 7 | ||
| @@ -14,5 +14,6 @@ void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v); | |||
| 14 | void Add_LargePages_String(AString &s); | 14 | void Add_LargePages_String(AString &s); |
| 15 | 15 | ||
| 16 | void GetCompiler(AString &s); | 16 | void GetCompiler(AString &s); |
| 17 | void GetVirtCpuid(AString &s); | ||
| 17 | 18 | ||
| 18 | #endif | 19 | #endif |
diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h index 5fca173..d72f64c 100644 --- a/CPP/Windows/Thread.h +++ b/CPP/Windows/Thread.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Thread.h | 1 | // Windows/Thread.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_THREAD_H | 3 | #ifndef ZIP7_INC_WINDOWS_THREAD_H |
| 4 | #define __WINDOWS_THREAD_H | 4 | #define ZIP7_INC_WINDOWS_THREAD_H |
| 5 | 5 | ||
| 6 | #include "../../C/Threads.h" | 6 | #include "../../C/Threads.h" |
| 7 | 7 | ||
| @@ -13,7 +13,7 @@ class CThread MY_UNCOPYABLE | |||
| 13 | { | 13 | { |
| 14 | ::CThread thread; | 14 | ::CThread thread; |
| 15 | public: | 15 | public: |
| 16 | CThread() { Thread_Construct(&thread); } | 16 | CThread() { Thread_CONSTRUCT(&thread) } |
| 17 | ~CThread() { Close(); } | 17 | ~CThread() { Close(); } |
| 18 | bool IsCreated() { return Thread_WasCreated(&thread) != 0; } | 18 | bool IsCreated() { return Thread_WasCreated(&thread) != 0; } |
| 19 | WRes Close() { return Thread_Close(&thread); } | 19 | WRes Close() { return Thread_Close(&thread); } |
diff --git a/CPP/Windows/TimeUtils.cpp b/CPP/Windows/TimeUtils.cpp index 77d2c51..e80ae13 100644 --- a/CPP/Windows/TimeUtils.cpp +++ b/CPP/Windows/TimeUtils.cpp | |||
| @@ -258,7 +258,7 @@ void GetCurUtc_FiTime(CFiTime &ft) throw() | |||
| 258 | 258 | ||
| 259 | FiTime_Clear(ft); | 259 | FiTime_Clear(ft); |
| 260 | struct timeval now; | 260 | struct timeval now; |
| 261 | if (gettimeofday(&now, 0 ) == 0) | 261 | if (gettimeofday(&now, NULL) == 0) |
| 262 | { | 262 | { |
| 263 | ft.tv_sec = now.tv_sec; | 263 | ft.tv_sec = now.tv_sec; |
| 264 | ft.tv_nsec = now.tv_usec * 1000; | 264 | ft.tv_nsec = now.tv_usec * 1000; |
| @@ -272,7 +272,7 @@ void GetCurUtcFileTime(FILETIME &ft) throw() | |||
| 272 | { | 272 | { |
| 273 | UInt64 v = 0; | 273 | UInt64 v = 0; |
| 274 | struct timeval now; | 274 | struct timeval now; |
| 275 | if (gettimeofday(&now, 0 ) == 0) | 275 | if (gettimeofday(&now, NULL) == 0) |
| 276 | { | 276 | { |
| 277 | v = ((UInt64)now.tv_sec + kUnixTimeOffset) * | 277 | v = ((UInt64)now.tv_sec + kUnixTimeOffset) * |
| 278 | kNumTimeQuantumsInSecond + (UInt64)now.tv_usec * 10; | 278 | kNumTimeQuantumsInSecond + (UInt64)now.tv_usec * 10; |
diff --git a/CPP/Windows/TimeUtils.h b/CPP/Windows/TimeUtils.h index 60ee739..4a9d0f2 100644 --- a/CPP/Windows/TimeUtils.h +++ b/CPP/Windows/TimeUtils.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/TimeUtils.h | 1 | // Windows/TimeUtils.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_TIME_UTILS_H | 3 | #ifndef ZIP7_INC_WINDOWS_TIME_UTILS_H |
| 4 | #define __WINDOWS_TIME_UTILS_H | 4 | #define ZIP7_INC_WINDOWS_TIME_UTILS_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyTypes.h" |
| 7 | #include "../Common/MyWindows.h" | 7 | #include "../Common/MyWindows.h" |
diff --git a/CPP/Windows/Window.cpp b/CPP/Windows/Window.cpp index 32af4aa..102c503 100644 --- a/CPP/Windows/Window.cpp +++ b/CPP/Windows/Window.cpp | |||
| @@ -111,7 +111,7 @@ bool MySetWindowText(HWND wnd, LPCWSTR s) | |||
| 111 | } | 111 | } |
| 112 | #endif | 112 | #endif |
| 113 | 113 | ||
| 114 | bool CWindow::GetText(CSysString &s) | 114 | bool CWindow::GetText(CSysString &s) const |
| 115 | { | 115 | { |
| 116 | s.Empty(); | 116 | s.Empty(); |
| 117 | unsigned len = (unsigned)GetTextLength(); | 117 | unsigned len = (unsigned)GetTextLength(); |
| @@ -119,7 +119,7 @@ bool CWindow::GetText(CSysString &s) | |||
| 119 | return (::GetLastError() == ERROR_SUCCESS); | 119 | return (::GetLastError() == ERROR_SUCCESS); |
| 120 | TCHAR *p = s.GetBuf(len); | 120 | TCHAR *p = s.GetBuf(len); |
| 121 | { | 121 | { |
| 122 | unsigned len2 = (unsigned)GetText(p, (int)(len + 1)); | 122 | const unsigned len2 = (unsigned)GetText(p, (int)(len + 1)); |
| 123 | if (len > len2) | 123 | if (len > len2) |
| 124 | len = len2; | 124 | len = len2; |
| 125 | } | 125 | } |
| @@ -130,7 +130,7 @@ bool CWindow::GetText(CSysString &s) | |||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | #ifndef _UNICODE | 132 | #ifndef _UNICODE |
| 133 | bool CWindow::GetText(UString &s) | 133 | bool CWindow::GetText(UString &s) const |
| 134 | { | 134 | { |
| 135 | if (g_IsNT) | 135 | if (g_IsNT) |
| 136 | { | 136 | { |
| @@ -140,7 +140,7 @@ bool CWindow::GetText(UString &s) | |||
| 140 | return (::GetLastError() == ERROR_SUCCESS); | 140 | return (::GetLastError() == ERROR_SUCCESS); |
| 141 | wchar_t *p = s.GetBuf(len); | 141 | wchar_t *p = s.GetBuf(len); |
| 142 | { | 142 | { |
| 143 | unsigned len2 = (unsigned)GetWindowTextW(_window, p, (int)(len + 1)); | 143 | const unsigned len2 = (unsigned)GetWindowTextW(_window, p, (int)(len + 1)); |
| 144 | if (len > len2) | 144 | if (len > len2) |
| 145 | len = len2; | 145 | len = len2; |
| 146 | } | 146 | } |
| @@ -150,7 +150,7 @@ bool CWindow::GetText(UString &s) | |||
| 150 | return true; | 150 | return true; |
| 151 | } | 151 | } |
| 152 | CSysString sysString; | 152 | CSysString sysString; |
| 153 | bool result = GetText(sysString); | 153 | const bool result = GetText(sysString); |
| 154 | MultiByteToUnicodeString2(s, sysString); | 154 | MultiByteToUnicodeString2(s, sysString); |
| 155 | return result; | 155 | return result; |
| 156 | } | 156 | } |
diff --git a/CPP/Windows/Window.h b/CPP/Windows/Window.h index 83726c7..a99143b 100644 --- a/CPP/Windows/Window.h +++ b/CPP/Windows/Window.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Windows/Window.h | 1 | // Windows/Window.h |
| 2 | 2 | ||
| 3 | #ifndef __WINDOWS_WINDOW_H | 3 | #ifndef ZIP7_INC_WINDOWS_WINDOW_H |
| 4 | #define __WINDOWS_WINDOW_H | 4 | #define ZIP7_INC_WINDOWS_WINDOW_H |
| 5 | 5 | ||
| 6 | #include "../Common/MyWindows.h" | 6 | #include "../Common/MyWindows.h" |
| 7 | #include "../Common/MyString.h" | 7 | #include "../Common/MyString.h" |
| @@ -9,23 +9,100 @@ | |||
| 9 | #include "Defs.h" | 9 | #include "Defs.h" |
| 10 | 10 | ||
| 11 | #ifndef UNDER_CE | 11 | #ifndef UNDER_CE |
| 12 | #ifdef WM_CHANGEUISTATE | ||
| 13 | #define Z7_WIN_WM_CHANGEUISTATE WM_CHANGEUISTATE | ||
| 14 | #define Z7_WIN_WM_UPDATEUISTATE WM_UPDATEUISTATE | ||
| 15 | #define Z7_WIN_WM_QUERYUISTATE WM_QUERYUISTATE | ||
| 16 | #else | ||
| 17 | // these are defined for (_WIN32_WINNT >= 0x0500): | ||
| 18 | #define Z7_WIN_WM_CHANGEUISTATE 0x0127 | ||
| 19 | #define Z7_WIN_WM_UPDATEUISTATE 0x0128 | ||
| 20 | #define Z7_WIN_WM_QUERYUISTATE 0x0129 | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #ifdef UIS_SET | ||
| 12 | 24 | ||
| 13 | #define MY__WM_CHANGEUISTATE 0x0127 | 25 | #define Z7_WIN_UIS_SET UIS_SET |
| 14 | #define MY__WM_UPDATEUISTATE 0x0128 | 26 | #define Z7_WIN_UIS_CLEAR UIS_CLEAR |
| 15 | #define MY__WM_QUERYUISTATE 0x0129 | 27 | #define Z7_WIN_UIS_INITIALIZE UIS_INITIALIZE |
| 16 | 28 | ||
| 29 | #define Z7_WIN_UISF_HIDEFOCUS UISF_HIDEFOCUS | ||
| 30 | #define Z7_WIN_UISF_HIDEACCEL UISF_HIDEACCEL | ||
| 31 | |||
| 32 | #else | ||
| 33 | // these are defined for (_WIN32_WINNT >= 0x0500): | ||
| 17 | // LOWORD(wParam) values in WM_*UISTATE | 34 | // LOWORD(wParam) values in WM_*UISTATE |
| 18 | #define MY__UIS_SET 1 | 35 | #define Z7_WIN_UIS_SET 1 |
| 19 | #define MY__UIS_CLEAR 2 | 36 | #define Z7_WIN_UIS_CLEAR 2 |
| 20 | #define MY__UIS_INITIALIZE 3 | 37 | #define Z7_WIN_UIS_INITIALIZE 3 |
| 21 | 38 | ||
| 22 | // HIWORD(wParam) values in WM_*UISTATE | 39 | // HIWORD(wParam) values in WM_*UISTATE |
| 23 | #define MY__UISF_HIDEFOCUS 0x1 | 40 | #define Z7_WIN_UISF_HIDEFOCUS 0x1 |
| 24 | #define MY__UISF_HIDEACCEL 0x2 | 41 | #define Z7_WIN_UISF_HIDEACCEL 0x2 |
| 25 | #define MY__UISF_ACTIVE 0x4 | 42 | // defined for for (_WIN32_WINNT >= 0x0501): |
| 43 | // #define Z7_WIN_UISF_ACTIVE 0x4 | ||
| 26 | 44 | ||
| 27 | #endif | 45 | #endif |
| 28 | 46 | ||
| 47 | #endif // UNDER_CE | ||
| 48 | |||
| 49 | |||
| 50 | #ifdef Z7_OLD_WIN_SDK | ||
| 51 | |||
| 52 | // #define VK_OEM_1 0xBA // ';:' for US | ||
| 53 | #define VK_OEM_PLUS 0xBB // '+' any country | ||
| 54 | // #define VK_OEM_COMMA 0xBC // ',' any country | ||
| 55 | #define VK_OEM_MINUS 0xBD // '-' any country | ||
| 56 | // #define VK_OEM_PERIOD 0xBE // '.' any country | ||
| 57 | // #define VK_OEM_2 0xBF // '/?' for US | ||
| 58 | // #define VK_OEM_3 0xC0 // '`~' for US | ||
| 59 | |||
| 60 | // #ifndef GWLP_USERDATA | ||
| 61 | #define GWLP_WNDPROC (-4) | ||
| 62 | #define GWLP_USERDATA (-21) | ||
| 63 | // #endif | ||
| 64 | #define DWLP_MSGRESULT 0 | ||
| 65 | // #define DWLP_DLGPROC DWLP_MSGRESULT + sizeof(LRESULT) | ||
| 66 | // #define DWLP_USER DWLP_DLGPROC + sizeof(DLGPROC) | ||
| 67 | |||
| 68 | #define BTNS_BUTTON TBSTYLE_BUTTON // 0x0000 | ||
| 69 | |||
| 70 | /* | ||
| 71 | vc6 defines INT_PTR via long: | ||
| 72 | typedef long INT_PTR, *PINT_PTR; | ||
| 73 | typedef unsigned long UINT_PTR, *PUINT_PTR; | ||
| 74 | but newer sdk (sdk2003+) defines INT_PTR via int: | ||
| 75 | typedef _W64 int INT_PTR, *PINT_PTR; | ||
| 76 | typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; | ||
| 77 | */ | ||
| 78 | |||
| 79 | #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0) | ||
| 80 | |||
| 81 | #define GetWindowLongPtrA GetWindowLongA | ||
| 82 | #define GetWindowLongPtrW GetWindowLongW | ||
| 83 | #ifdef UNICODE | ||
| 84 | #define GetWindowLongPtr GetWindowLongPtrW | ||
| 85 | #else | ||
| 86 | #define GetWindowLongPtr GetWindowLongPtrA | ||
| 87 | #endif // !UNICODE | ||
| 88 | |||
| 89 | #define SetWindowLongPtrA SetWindowLongA | ||
| 90 | #define SetWindowLongPtrW SetWindowLongW | ||
| 91 | #ifdef UNICODE | ||
| 92 | #define SetWindowLongPtr SetWindowLongPtrW | ||
| 93 | #else | ||
| 94 | #define SetWindowLongPtr SetWindowLongPtrA | ||
| 95 | #endif // !UNICODE | ||
| 96 | |||
| 97 | #define ListView_SetCheckState(hwndLV, i, fCheck) \ | ||
| 98 | ListView_SetItemState(hwndLV, i, INDEXTOSTATEIMAGEMASK((fCheck)?2:1), LVIS_STATEIMAGEMASK) | ||
| 99 | |||
| 100 | #endif // Z7_OLD_WIN_SDK | ||
| 101 | |||
| 102 | inline bool LRESULTToBool(LRESULT v) { return (v != FALSE); } | ||
| 103 | |||
| 104 | #define MY_int_TO_WPARAM(i) ((WPARAM)(INT_PTR)(i)) | ||
| 105 | |||
| 29 | namespace NWindows { | 106 | namespace NWindows { |
| 30 | 107 | ||
| 31 | inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass) | 108 | inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass) |
| @@ -52,12 +129,13 @@ bool MySetWindowText(HWND wnd, LPCWSTR s); | |||
| 52 | 129 | ||
| 53 | class CWindow | 130 | class CWindow |
| 54 | { | 131 | { |
| 132 | Z7_CLASS_NO_COPY(CWindow) | ||
| 55 | private: | 133 | private: |
| 56 | // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags); | 134 | // bool ModifyStyleBase(int styleOffset, DWORD remove, DWORD add, UINT flags); |
| 57 | protected: | 135 | protected: |
| 58 | HWND _window; | 136 | HWND _window; |
| 59 | public: | 137 | public: |
| 60 | CWindow(HWND newWindow = NULL): _window(newWindow){}; | 138 | CWindow(HWND newWindow = NULL): _window(newWindow) {} |
| 61 | CWindow& operator=(HWND newWindow) | 139 | CWindow& operator=(HWND newWindow) |
| 62 | { | 140 | { |
| 63 | _window = newWindow; | 141 | _window = newWindow; |
| @@ -174,6 +252,7 @@ public: | |||
| 174 | void SetRedraw(bool redraw = true) { SendMsg(WM_SETREDRAW, (WPARAM)BoolToBOOL(redraw), 0); } | 252 | void SetRedraw(bool redraw = true) { SendMsg(WM_SETREDRAW, (WPARAM)BoolToBOOL(redraw), 0); } |
| 175 | 253 | ||
| 176 | LONG_PTR SetStyle(LONG_PTR style) { return SetLongPtr(GWL_STYLE, style); } | 254 | LONG_PTR SetStyle(LONG_PTR style) { return SetLongPtr(GWL_STYLE, style); } |
| 255 | // LONG_PTR SetStyle(DWORD style) { return SetLongPtr(GWL_STYLE, (LONG_PTR)style); } | ||
| 177 | LONG_PTR GetStyle() const { return GetLongPtr(GWL_STYLE); } | 256 | LONG_PTR GetStyle() const { return GetLongPtr(GWL_STYLE); } |
| 178 | // bool MyIsMaximized() const { return ((GetStyle() & WS_MAXIMIZE) != 0); } | 257 | // bool MyIsMaximized() const { return ((GetStyle() & WS_MAXIMIZE) != 0); } |
| 179 | 258 | ||
| @@ -246,19 +325,19 @@ public: | |||
| 246 | { return GetWindowTextLength(_window); } | 325 | { return GetWindowTextLength(_window); } |
| 247 | int GetText(LPTSTR string, int maxCount) const | 326 | int GetText(LPTSTR string, int maxCount) const |
| 248 | { return GetWindowText(_window, string, maxCount); } | 327 | { return GetWindowText(_window, string, maxCount); } |
| 249 | bool GetText(CSysString &s); | 328 | bool GetText(CSysString &s) const; |
| 250 | #ifndef _UNICODE | 329 | #ifndef _UNICODE |
| 251 | /* | 330 | /* |
| 252 | UINT GetText(LPWSTR string, int maxCount) const | 331 | UINT GetText(LPWSTR string, int maxCount) const |
| 253 | { return GetWindowTextW(_window, string, maxCount); } | 332 | { return GetWindowTextW(_window, string, maxCount); } |
| 254 | */ | 333 | */ |
| 255 | bool GetText(UString &s); | 334 | bool GetText(UString &s) const; |
| 256 | #endif | 335 | #endif |
| 257 | 336 | ||
| 258 | bool Enable(bool enable) | 337 | bool Enable(bool enable) |
| 259 | { return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); } | 338 | { return BOOLToBool(::EnableWindow(_window, BoolToBOOL(enable))); } |
| 260 | 339 | ||
| 261 | bool IsEnabled() | 340 | bool IsEnabled() const |
| 262 | { return BOOLToBool(::IsWindowEnabled(_window)); } | 341 | { return BOOLToBool(::IsWindowEnabled(_window)); } |
| 263 | 342 | ||
| 264 | #ifndef UNDER_CE | 343 | #ifndef UNDER_CE |
| @@ -266,7 +345,7 @@ public: | |||
| 266 | { return ::GetSystemMenu(_window, BoolToBOOL(revert)); } | 345 | { return ::GetSystemMenu(_window, BoolToBOOL(revert)); } |
| 267 | #endif | 346 | #endif |
| 268 | 347 | ||
| 269 | UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = 0) | 348 | UINT_PTR SetTimer(UINT_PTR idEvent, UINT elapse, TIMERPROC timerFunc = NULL) |
| 270 | { return ::SetTimer(_window, idEvent, elapse, timerFunc); } | 349 | { return ::SetTimer(_window, idEvent, elapse, timerFunc); } |
| 271 | bool KillTimer(UINT_PTR idEvent) | 350 | bool KillTimer(UINT_PTR idEvent) |
| 272 | {return BOOLToBool(::KillTimer(_window, idEvent)); } | 351 | {return BOOLToBool(::KillTimer(_window, idEvent)); } |
