summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/unix/CPP/Windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/7zip/unix/CPP/Windows')
-rw-r--r--src/libs/7zip/unix/CPP/Windows/DLL.cpp44
-rw-r--r--src/libs/7zip/unix/CPP/Windows/DLL.h24
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Defs.h1
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Error.cpp58
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Error.h33
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileDir.cpp898
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileDir.h134
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileFind.cpp467
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileFind.h115
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileIO.cpp41
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileIO.h7
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileName.cpp37
-rw-r--r--src/libs/7zip/unix/CPP/Windows/FileName.h8
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Handle.h37
-rw-r--r--src/libs/7zip/unix/CPP/Windows/NtCheck.h44
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariant.cpp105
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariant.h97
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariantConv.cpp99
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariantConv.h30
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariantConversions.cpp139
-rw-r--r--src/libs/7zip/unix/CPP/Windows/PropVariantConversions.h14
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Registry.cpp313
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Registry.h113
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Synchronization.cpp2
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Synchronization.h14
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Synchronization2.h12
-rw-r--r--src/libs/7zip/unix/CPP/Windows/System.cpp2
-rw-r--r--src/libs/7zip/unix/CPP/Windows/System.h2
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Thread.h2
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Time.cpp68
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Time.h21
-rw-r--r--src/libs/7zip/unix/CPP/Windows/TimeUtils.cpp203
-rw-r--r--src/libs/7zip/unix/CPP/Windows/TimeUtils.h23
-rw-r--r--src/libs/7zip/unix/CPP/Windows/Windows.pri24
34 files changed, 1414 insertions, 1817 deletions
diff --git a/src/libs/7zip/unix/CPP/Windows/DLL.cpp b/src/libs/7zip/unix/CPP/Windows/DLL.cpp
index 5f76cc5e2..345153cb2 100644
--- a/src/libs/7zip/unix/CPP/Windows/DLL.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/DLL.cpp
@@ -28,14 +28,9 @@
namespace NWindows {
namespace NDLL {
-CLibrary::~CLibrary()
-{
- Free();
-}
-
bool CLibrary::Free()
{
-TRACEN((printf("CLibrary::Free(%p)\n",(void *)_module)))
+TRACEN((printf("CLibrary::Free(this=%p,%p)\n",(void *)this,(void *)_module)))
if (_module == 0)
return true;
@@ -86,18 +81,11 @@ FARPROC CLibrary::GetProc(LPCSTR lpProcName) const
return local_GetProcAddress(_module,lpProcName);
}
-bool CLibrary::LoadOperations(HMODULE newModule)
+bool CLibrary::Load(LPCTSTR lpLibFileName)
{
- if (newModule == NULL)
- return false;
if(!Free())
return false;
- _module = newModule;
- return true;
-}
-bool CLibrary::Load(LPCTSTR lpLibFileName)
-{
void *handler = 0;
char name[MAX_PATHNAME_LEN+1];
#ifdef _UNICODE
@@ -106,14 +94,14 @@ bool CLibrary::Load(LPCTSTR lpLibFileName)
#else
strcpy(name,nameWindowToUnix(lpLibFileName));
#endif
-
+
// replace ".dll" with ".so"
size_t len = strlen(name);
if ((len >=4) && (strcmp(name+len-4,".dll") == 0)) {
strcpy(name+len-4,".so");
}
- TRACEN((printf("CLibrary::Load(%ls) => %s\n",lpLibFileName,name)))
+ TRACEN((printf("CLibrary::Load(this=%p,%ls) => %s\n",(void *)this,lpLibFileName,name)))
#ifdef __APPLE_CC__
NSObjectFileImage image;
@@ -184,10 +172,30 @@ TRACEN((printf("load_add_on(%s)=%d\n",p.Path(),(int)image)))
#else
printf("Can't load '%ls' (%s)\n", lpLibFileName,dlerror());
#endif
- }
+ }
+
+ _module = handler;
+ TRACEN((printf("CLibrary::Load(this=%p,%ls) => _module=%p\n",(void *)this,lpLibFileName,_module)))
- return LoadOperations(handler);
+ return true;
}
+#ifndef _SFX
+
+FString GetModuleDirPrefix()
+{
+ FString s;
+
+ const char *p7zip_home_dir = getenv("P7ZIP_HOME_DIR");
+ if (p7zip_home_dir) {
+ return MultiByteToUnicodeString(p7zip_home_dir,CP_ACP);
+ }
+
+ return FTEXT(".") FSTRING_PATH_SEPARATOR;
+}
+
+#endif
+
+
}}
diff --git a/src/libs/7zip/unix/CPP/Windows/DLL.h b/src/libs/7zip/unix/CPP/Windows/DLL.h
index 9b57bec8a..2e044ec59 100644
--- a/src/libs/7zip/unix/CPP/Windows/DLL.h
+++ b/src/libs/7zip/unix/CPP/Windows/DLL.h
@@ -6,7 +6,7 @@
#include "../Common/MyString.h"
typedef void * HMODULE;
-
+// #define LOAD_LIBRARY_AS_DATAFILE 0
typedef int (*FARPROC)();
namespace NWindows {
@@ -14,17 +14,14 @@ namespace NDLL {
class CLibrary
{
- bool LoadOperations(HMODULE newModule);
HMODULE _module;
public:
+ CLibrary(): _module(NULL) {};
+ ~CLibrary() { Free(); }
+
operator HMODULE() const { return _module; }
HMODULE* operator&() { return &_module; }
-
-
- CLibrary():_module(NULL) {};
- ~CLibrary();
-
- bool Free();
+ bool IsLoaded() const { return (_module != NULL); };
void Attach(HMODULE m)
{
@@ -38,11 +35,16 @@ public:
return m;
}
-
- bool Load(LPCTSTR fileName);
- FARPROC GetProc(LPCSTR procName) const;
+ bool Free();
+ // bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
+ bool Load(CFSTR path);
+ FARPROC GetProc(LPCSTR procName) const; // { return My_GetProcAddress(_module, procName); }
};
+bool MyGetModuleFileName(FString &path);
+
+FString GetModuleDirPrefix();
+
}}
#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/Defs.h b/src/libs/7zip/unix/CPP/Windows/Defs.h
index bad4e3552..b88df748d 100644
--- a/src/libs/7zip/unix/CPP/Windows/Defs.h
+++ b/src/libs/7zip/unix/CPP/Windows/Defs.h
@@ -3,6 +3,7 @@
#ifndef __WINDOWS_DEFS_H
#define __WINDOWS_DEFS_H
+#include "../myWindows/StdAfx.h"
#include "../Common/MyWindows.h"
// #ifdef _WIN32
diff --git a/src/libs/7zip/unix/CPP/Windows/Error.cpp b/src/libs/7zip/unix/CPP/Windows/Error.cpp
deleted file mode 100644
index 88008d711..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Error.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// Windows/Error.h
-
-#include "StdAfx.h"
-
-#include "Windows/Error.h"
-#include "Common/StringConvert.h"
-
-namespace NWindows {
-namespace NError {
-
-bool MyFormatMessage(DWORD messageID, CSysString &message)
-{
- const char * txt = 0;
- AString msg;
-
- switch(messageID) {
- case ERROR_NO_MORE_FILES : txt = "No more files"; break ;
- case E_NOTIMPL : txt = "E_NOTIMPL"; break ;
- case E_NOINTERFACE : txt = "E_NOINTERFACE"; break ;
- case E_ABORT : txt = "E_ABORT"; break ;
- case E_FAIL : txt = "E_FAIL"; break ;
- case STG_E_INVALIDFUNCTION : txt = "STG_E_INVALIDFUNCTION"; break ;
- case E_OUTOFMEMORY : txt = "E_OUTOFMEMORY"; break ;
- case E_INVALIDARG : txt = "E_INVALIDARG"; break ;
- default:
- txt = strerror(messageID);
- }
- if (txt) {
- msg = txt;
- } else {
- char msgBuf[256];
- snprintf(msgBuf,sizeof(msgBuf),"error #%x",(unsigned)messageID);
- msgBuf[sizeof(msgBuf)-1] = 0;
- msg = msgBuf;
- }
-
- msg += " ";
-
-#ifdef _UNICODE
- message = MultiByteToUnicodeString(msg);
-#else
- message = msg;
-#endif
- return true;
-}
-
-#ifndef _UNICODE
-bool MyFormatMessage(DWORD messageID, UString &message)
-{
- CSysString messageSys;
- bool result = MyFormatMessage(messageID, messageSys);
- message = GetUnicodeString(messageSys);
- return result;
-}
-#endif
-
-}}
-
diff --git a/src/libs/7zip/unix/CPP/Windows/Error.h b/src/libs/7zip/unix/CPP/Windows/Error.h
deleted file mode 100644
index 05b5cd0ea..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Error.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Windows/Error.h
-
-#ifndef __WINDOWS_ERROR_H
-#define __WINDOWS_ERROR_H
-
-#include "Common/MyString.h"
-
-namespace NWindows {
-namespace NError {
-
-bool MyFormatMessage(DWORD messageID, CSysString &message);
-inline CSysString MyFormatMessage(DWORD messageID)
-{
- CSysString message;
- MyFormatMessage(messageID, message);
- return message;
-}
-#ifdef _UNICODE
-inline UString MyFormatMessageW(DWORD messageID)
- { return MyFormatMessage(messageID); }
-#else
-bool MyFormatMessage(DWORD messageID, UString &message);
-inline UString MyFormatMessageW(DWORD messageID)
-{
- UString message;
- MyFormatMessage(messageID, message);
- return message;
-}
-#endif
-
-}}
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/FileDir.cpp b/src/libs/7zip/unix/CPP/Windows/FileDir.cpp
index 838f92d5b..9915bd8b8 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileDir.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/FileDir.cpp
@@ -2,10 +2,14 @@
#include "StdAfx.h"
+#ifndef _UNICODE
+#include "../Common/StringConvert.h"
+#endif
+
#include "FileDir.h"
-#include "FileName.h"
#include "FileFind.h"
-#include "Defs.h"
+#include "FileName.h"
+
#include "../Common/StringConvert.h"
#include "../Common/IntToString.h"
@@ -25,6 +29,10 @@
// #define TRACEN(u) u;
#define TRACEN(u) /* */
+int g_filedir = 1;
+
+static NWindows::NSynchronization::CCriticalSection g_CountCriticalSection;
+
class Umask
{
public:
@@ -34,10 +42,12 @@ class Umask
current_umask = umask (0); /* get and set the umask */
umask(current_umask); /* restore the umask */
mask = 0777 & (~current_umask);
- }
+ }
};
static Umask gbl_umask;
+extern BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds );
+
#ifdef _UNICODE
AString nameWindowToUnix2(LPCWSTR name) // FIXME : optimization ?
@@ -47,10 +57,7 @@ AString nameWindowToUnix2(LPCWSTR name) // FIXME : optimization ?
}
#endif
-extern BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds );
-
-#ifdef _UNICODE
-DWORD WINAPI GetFullPathName( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *lastpart ) { // FIXME
+DWORD WINAPI GetFullPathNameW( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *lastpart ) { // FIXME
if (name == 0) return 0;
DWORD name_len = lstrlen(name);
@@ -71,7 +78,7 @@ DWORD WINAPI GetFullPathName( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *la
*lastpart=ptr+1;
ptr++;
}
- TRACEN((printf("GetFullPathNameA(%s,%d,%ls,%ls)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,%ls,%ls)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
return ret;
}
if (isascii(name[0]) && (name[1] == ':')) { // FIXME isascii
@@ -89,14 +96,14 @@ DWORD WINAPI GetFullPathName( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *la
*lastpart=ptr+1;
ptr++;
}
- TRACEN((printf("GetFullPathNameA(%sl,%d,%ls,%ls)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,%ls,%ls)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
return ret;
}
// name is a relative pathname.
//
if (len < 2) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 2)\n",name, (int)len)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,)=0000 (case 2)\n",name, (int)len)))
return 0;
}
@@ -110,13 +117,13 @@ DWORD WINAPI GetFullPathName( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *la
if (cret) {
begin_len = strlen(begin);
}
-
+
if (begin_len >= 1) {
// strlen(begin) + strlen("/") + strlen(name)
ret = begin_len + 1 + name_len;
if (ret >= len) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 4)\n",name, (int)len)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,)=0000 (case 4)\n",name, (int)len)))
return 0;
}
UString wbegin = GetUnicodeString(begin);
@@ -131,136 +138,14 @@ DWORD WINAPI GetFullPathName( LPCTSTR name, DWORD len, LPTSTR buffer, LPTSTR *la
*lastpart=ptr+1;
ptr++;
}
- TRACEN((printf("GetFullPathNameA(%s,%d,%s,%s)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,%ls,%ls)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
} else {
ret = 0;
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 5)\n",name, (int)len)))
+ TRACEN((printf("GetFullPathNameA(%ls,%d,)=0000 (case 5)\n",name, (int)len)))
}
return ret;
}
-#endif
-
-#if 0
-DWORD WINAPI GetFullPathName( LPCSTR name, DWORD len, LPSTR buffer, LPSTR *lastpart ) {
- if (name == 0) return 0;
-
- DWORD name_len = strlen(name);
-
- if (name[0] == '/') {
- DWORD ret = name_len+2;
- if (ret >= len) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 0)\n",name, (int)len)))
- return 0;
- }
- strcpy(buffer,"c:");
- strcat(buffer,name);
-
- *lastpart=buffer;
- char *ptr=buffer;
- while (*ptr) {
- if (*ptr == '/')
- *lastpart=ptr+1;
- ptr++;
- }
- TRACEN((printf("GetFullPathNameA(%s,%d,%s,%s)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
- return ret;
- }
- if (isascii(name[0]) && (name[1] == ':')) {
- DWORD ret = name_len;
- if (ret >= len) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 1)\n",name, (int)len)))
- return 0;
- }
- strcpy(buffer,name);
-
- *lastpart=buffer;
- char *ptr=buffer;
- while (*ptr) {
- if (*ptr == '/')
- *lastpart=ptr+1;
- ptr++;
- }
- TRACEN((printf("GetFullPathNameA(%s,%d,%s,%s)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
- return ret;
- }
-
- // name is a relative pathname.
- //
- if (len < 2) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 2)\n",name, (int)len)))
- return 0;
- }
-
- DWORD ret = 0;
- char begin[MAX_PATHNAME_LEN];
- /* DWORD begin_len = GetCurrentDirectoryA(MAX_PATHNAME_LEN,begin); */
- DWORD begin_len = 0;
- begin[0]='c';
- begin[1]=':';
- char * cret = getcwd(begin+2, MAX_PATHNAME_LEN - 3);
- if (cret) {
- begin_len = strlen(begin);
- }
-
- if (begin_len >= 1) {
- // strlen(begin) + strlen("/") + strlen(name)
- ret = begin_len + 1 + name_len;
-
- if (ret >= len) {
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 4)\n",name, (int)len)))
- return 0;
- }
- strcpy(buffer,begin);
- strcat(buffer,"/");
- strcat(buffer,name);
-
- *lastpart=buffer + begin_len + 1;
- char *ptr=buffer;
- while (*ptr) {
- if (*ptr == '/')
- *lastpart=ptr+1;
- ptr++;
- }
- TRACEN((printf("GetFullPathNameA(%s,%d,%s,%s)=%d\n",name, (int)len,buffer, *lastpart,(int)ret)))
- } else {
- ret = 0;
- TRACEN((printf("GetFullPathNameA(%s,%d,)=0000 (case 5)\n",name, (int)len)))
- }
- return ret;
-}
-
-static BOOL WINAPI RemoveDirectory(LPCSTR path) {
- if (!path || !*path) {
- SetLastError(ERROR_PATH_NOT_FOUND);
- return FALSE;
- }
- const char * name = nameWindowToUnix(path);
- TRACEN((printf("RemoveDirectoryA(%s)\n",name)))
-
- if (rmdir( name ) != 0) {
- return FALSE;
- }
- return TRUE;
-}
-#endif
-
-#ifdef _UNICODE
-static BOOL WINAPI RemoveDirectory(LPCWSTR path) {
- if (!path || !*path) {
- SetLastError(ERROR_PATH_NOT_FOUND);
- return FALSE;
- }
- AString name = nameWindowToUnix2(path);
- TRACEN((printf("RemoveDirectoryA(%s)\n",(const char *)name)))
-
- if (rmdir( (const char *)name ) != 0) {
- return FALSE;
- }
- return TRUE;
-}
-#endif
-
static int copy_fd(int fin,int fout)
{
char buffer[16384];
@@ -297,6 +182,7 @@ static BOOL CopyFile(const char *src,const char *dst)
flags |= O_LARGEFILE;
#endif
+ // printf("##DBG CopyFile(%s,%s)\n",src,dst);
int fout = open(dst,O_CREAT | O_WRONLY | O_EXCL | flags, 0600);
if (fout != -1)
{
@@ -314,102 +200,76 @@ static BOOL CopyFile(const char *src,const char *dst)
return FALSE;
}
-/*****************************************************************************************/
+#ifndef _UNICODE
+extern bool g_IsNT;
+#endif
namespace NWindows {
namespace NFile {
-namespace NDirectory {
+// SetCurrentDirectory doesn't support \\?\ prefix
-bool MySetCurrentDirectory(LPCWSTR wpath)
-{
- AString path = UnicodeStringToMultiByte(wpath);
+#ifdef WIN_LONG_PATH
+bool GetLongPathBase(CFSTR fileName, UString &res);
+bool GetLongPath(CFSTR fileName, UString &res);
+#endif
- return chdir((const char*)path) == 0;
-}
+namespace NDir {
-#ifdef _UNICODE
-bool GetOnlyName(LPCTSTR fileName, CSysString &resultName)
-{
- int index;
- if (!MyGetFullPathName(fileName, resultName, index))
- return false;
- resultName = resultName.Mid(index);
- return true;
-}
-bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)
-{
- int index;
- if (!MyGetFullPathName(fileName, resultName, index))
- return false;
- resultName = resultName.Left(index);
- return true;
-}
-#endif
+#ifdef _WIN32
+#ifndef UNDER_CE
-bool MyGetCurrentDirectory(CSysString &resultPath)
+bool MyGetWindowsDirectory(FString &path)
{
- char begin[MAX_PATHNAME_LEN];
- begin[0]='c';
- begin[1]=':';
- char * cret = getcwd(begin+2, MAX_PATHNAME_LEN - 3);
- if (cret)
+ UINT needLength;
+ #ifndef _UNICODE
+ if (!g_IsNT)
{
-#ifdef _UNICODE
- resultPath = GetUnicodeString(begin);
-#else
- resultPath = begin;
-#endif
- return true;
+ TCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ needLength = ::GetWindowsDirectory(s, MAX_PATH + 1);
+ path = fas2fs(s);
}
- return false;
-}
-
-bool MyMoveFile( LPCTSTR fn1, LPCTSTR fn2 ) {
-#ifdef _UNICODE
- AString src = nameWindowToUnix2(fn1);
- AString dst = nameWindowToUnix2(fn2);
-#else
- const char * src = nameWindowToUnix(fn1);
- const char * dst = nameWindowToUnix(fn2);
-#endif
-
- TRACEN((printf("MoveFileW(%s,%s)\n",src,dst)))
-
- int ret = rename(src,dst);
- if (ret != 0)
+ else
+ #endif
{
- if (errno == EXDEV) // FIXED : bug #1112167 (Temporary directory must be on same partition as target)
- {
- BOOL bret = CopyFile(src,dst);
- if (bret == FALSE) return false;
-
- struct stat info_file;
- ret = stat(src,&info_file);
- if (ret == 0) {
- TRACEN((printf("##DBG chmod-1(%s,%o)\n",dst,(unsigned)info_file.st_mode & gbl_umask.mask)))
- ret = chmod(dst,info_file.st_mode & gbl_umask.mask);
- }
- if (ret == 0) {
- ret = unlink(src);
- }
- if (ret == 0) return true;
- }
- return false;
+ WCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ needLength = ::GetWindowsDirectoryW(s, MAX_PATH + 1);
+ path = us2fs(s);
}
- return true;
+ return (needLength > 0 && needLength <= MAX_PATH);
}
-bool MyRemoveDirectory(LPCTSTR pathName)
+
+bool MyGetSystemDirectory(FString &path)
{
- return BOOLToBool(::RemoveDirectory(pathName));
+ UINT needLength;
+ #ifndef _UNICODE
+ if (!g_IsNT)
+ {
+ TCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ needLength = ::GetSystemDirectory(s, MAX_PATH + 1);
+ path = fas2fs(s);
+ }
+ else
+ #endif
+ {
+ WCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ needLength = ::GetSystemDirectoryW(s, MAX_PATH + 1);
+ path = us2fs(s);
+ }
+ return (needLength > 0 && needLength <= MAX_PATH);
}
+#endif
+#endif // _WIN32
-bool SetDirTime(LPCWSTR fileName, const FILETIME * /* creationTime */ ,
- const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
+bool SetDirTime(CFSTR fileName, const FILETIME * /* cTime */ , const FILETIME *aTime, const FILETIME *mTime)
{
AString cfilename = UnicodeStringToMultiByte(fileName);
const char * unix_filename = nameWindowToUnix((const char *)cfilename);
@@ -427,22 +287,22 @@ bool SetDirTime(LPCWSTR fileName, const FILETIME * /* creationTime */ ,
buf.modtime = current_time;
}
- if (lpLastAccessTime)
+ if (aTime)
{
LARGE_INTEGER ltime;
DWORD dw;
- ltime.QuadPart = lpLastAccessTime->dwHighDateTime;
- ltime.QuadPart = (ltime.QuadPart << 32) | lpLastAccessTime->dwLowDateTime;
+ ltime.QuadPart = aTime->dwHighDateTime;
+ ltime.QuadPart = (ltime.QuadPart << 32) | aTime->dwLowDateTime;
RtlTimeToSecondsSince1970( &ltime, &dw );
buf.actime = dw;
}
- if (lpLastWriteTime)
+ if (mTime)
{
LARGE_INTEGER ltime;
DWORD dw;
- ltime.QuadPart = lpLastWriteTime->dwHighDateTime;
- ltime.QuadPart = (ltime.QuadPart << 32) | lpLastWriteTime->dwLowDateTime;
+ ltime.QuadPart = mTime->dwHighDateTime;
+ ltime.QuadPart = (ltime.QuadPart << 32) | mTime->dwLowDateTime;
RtlTimeToSecondsSince1970( &ltime, &dw );
buf.modtime = dw;
}
@@ -452,25 +312,20 @@ bool SetDirTime(LPCWSTR fileName, const FILETIME * /* creationTime */ ,
return true;
}
-#ifndef _UNICODE
-bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)
-{
- return MySetFileAttributes(UnicodeStringToMultiByte(fileName, CP_ACP), fileAttributes);
-}
-
-bool MyRemoveDirectory(LPCWSTR pathName)
-{
- return MyRemoveDirectory(UnicodeStringToMultiByte(pathName, CP_ACP));
-}
-
-bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)
-{
- UINT codePage = CP_ACP;
- return MyMoveFile(UnicodeStringToMultiByte(existFileName, codePage), UnicodeStringToMultiByte(newFileName, codePage));
+#ifdef WIN_LONG_PATH
+bool GetLongPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2)
+{
+ if (!GetLongPathBase(s1, d1) ||
+ !GetLongPathBase(s2, d2))
+ return false;
+ if (d1.IsEmpty() && d2.IsEmpty())
+ return false;
+ if (d1.IsEmpty()) d1 = fs2us(s1);
+ if (d2.IsEmpty()) d2 = fs2us(s2);
+ return true;
}
#endif
-
static int convert_to_symlink(const char * name) {
FILE *file = fopen(name,"rb");
if (file) {
@@ -482,17 +337,17 @@ static int convert_to_symlink(const char * name) {
if (ir == 0) {
ir = symlink(buf,name);
}
- return ir;
+ return ir;
}
}
return -1;
}
-bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
+bool SetFileAttrib(CFSTR fileName, DWORD fileAttributes)
{
if (!fileName) {
SetLastError(ERROR_PATH_NOT_FOUND);
- TRACEN((printf("MySetFileAttributes(NULL,%d) : false-1\n",fileAttributes)))
+ TRACEN((printf("SetFileAttrib(NULL,%d) : false-1\n",fileAttributes)))
return false;
}
#ifdef _UNICODE
@@ -504,14 +359,14 @@ bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
#ifdef ENV_HAVE_LSTAT
if (global_use_lstat) {
if(lstat(name,&stat_info)!=0) {
- TRACEN((printf("MySetFileAttributes(%s,%d) : false-2-1\n",name,fileAttributes)))
+ TRACEN((printf("SetFileAttrib(%s,%d) : false-2-1\n",(const char *)name,fileAttributes)))
return false;
}
} else
#endif
{
if(stat(name,&stat_info)!=0) {
- TRACEN((printf("MySetFileAttributes(%s,%d) : false-2-2\n",name,fileAttributes)))
+ TRACEN((printf("SetFileAttrib(%s,%d) : false-2-2\n",(const char *)name,fileAttributes)))
return false;
}
}
@@ -521,18 +376,18 @@ bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
#ifdef ENV_HAVE_LSTAT
if (S_ISLNK(stat_info.st_mode)) {
if ( convert_to_symlink(name) != 0) {
- TRACEN((printf("MySetFileAttributes(%s,%d) : false-3\n",name,fileAttributes)))
+ TRACEN((printf("SetFileAttrib(%s,%d) : false-3\n",(const char *)name,fileAttributes)))
return false;
}
} else
#endif
if (S_ISREG(stat_info.st_mode)) {
- TRACEN((printf("##DBG chmod-2(%s,%o)\n",name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
+ TRACEN((printf("##DBG chmod-2(%s,%o)\n",(const char *)name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
chmod(name,stat_info.st_mode & gbl_umask.mask);
} else if (S_ISDIR(stat_info.st_mode)) {
// user/7za must be able to create files in this directory
stat_info.st_mode |= (S_IRUSR | S_IWUSR | S_IXUSR);
- TRACEN((printf("##DBG chmod-3(%s,%o)\n",name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
+ TRACEN((printf("##DBG chmod-3(%s,%o)\n",(const char *)name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
chmod(name,stat_info.st_mode & gbl_umask.mask);
}
#ifdef ENV_HAVE_LSTAT
@@ -545,121 +400,123 @@ bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
/* Only Windows Attributes */
if( S_ISDIR(stat_info.st_mode)) {
/* Remark : FILE_ATTRIBUTE_READONLY ignored for directory. */
- TRACEN((printf("##DBG chmod-4(%s,%o)\n",name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
+ TRACEN((printf("##DBG chmod-4(%s,%o)\n",(const char *)name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
chmod(name,stat_info.st_mode & gbl_umask.mask);
} else {
if (fileAttributes & FILE_ATTRIBUTE_READONLY) stat_info.st_mode &= ~0222; /* octal!, clear write permission bits */
- TRACEN((printf("##DBG chmod-5(%s,%o)\n",name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
+ TRACEN((printf("##DBG chmod-5(%s,%o)\n",(const char *)name,(unsigned)stat_info.st_mode & gbl_umask.mask)))
chmod(name,stat_info.st_mode & gbl_umask.mask);
}
}
- TRACEN((printf("MySetFileAttributes(%s,%d) : true\n",name,fileAttributes)))
+ TRACEN((printf("SetFileAttrib(%s,%d) : true\n",(const char *)name,fileAttributes)))
return true;
}
-bool MyCreateDirectory(LPCTSTR pathName)
-{
- if (!pathName || !*pathName) {
+bool RemoveDir(CFSTR path)
+{
+ if (!path || !*path) {
SetLastError(ERROR_PATH_NOT_FOUND);
- return false;
+ return FALSE;
}
+ AString name = nameWindowToUnix2(path);
+ TRACEN((printf("RemoveDirectoryA(%s)\n",(const char *)name)))
+
+ if (rmdir( (const char *)name ) != 0) {
+ return FALSE;
+ }
+ return TRUE;
+}
+bool MyMoveFile(CFSTR existFileName, CFSTR newFileName)
+{
#ifdef _UNICODE
- AString name = nameWindowToUnix2(pathName);
+ AString src = nameWindowToUnix2(existFileName);
+ AString dst = nameWindowToUnix2(newFileName);
#else
- const char * name = nameWindowToUnix(pathName);
+ const char * src = nameWindowToUnix(existFileName);
+ const char * dst = nameWindowToUnix(newFileName);
#endif
- bool bret = false;
- if (mkdir( name, 0700 ) == 0) bret = true;
-
- TRACEN((printf("MyCreateDirectory(%s)=%d\n",name,(int)bret)))
- return bret;
-}
-#ifndef _UNICODE
-bool MyCreateDirectory(LPCWSTR pathName)
-{
- return MyCreateDirectory(UnicodeStringToMultiByte(pathName, CP_ACP));
-}
-#endif
+ TRACEN((printf("MyMoveFile(%s,%s)\n",(const char *)src,(const char *)dst)))
-bool CreateComplexDirectory(LPCTSTR _aPathName)
-{
- CSysString pathName = _aPathName;
- int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
- if (pos > 0 && pos == pathName.Length() - 1)
- {
- if (pathName.Length() == 3 && pathName[1] == ':')
- return true; // Disk folder;
- pathName.Delete(pos);
- }
- CSysString pathName2 = pathName;
- pos = pathName.Length();
- while(true)
+ int ret = rename(src,dst);
+ if (ret != 0)
{
- if(MyCreateDirectory(pathName))
- break;
- if(::GetLastError() == ERROR_ALREADY_EXISTS)
+ if (errno == EXDEV) // FIXED : bug #1112167 (Temporary directory must be on same partition as target)
{
-#ifdef _WIN32 // FIXED for supporting symbolic link instead of a directory
- NFind::CFileInfo fileInfo;
- if (!NFind::FindFile(pathName, fileInfo)) // For network folders
- return true;
- if (!fileInfo.IsDir())
- return false;
-#endif
- break;
+ BOOL bret = CopyFile(src,dst);
+ if (bret == FALSE) return false;
+
+ struct stat info_file;
+ ret = stat(src,&info_file);
+ if (ret == 0) {
+ TRACEN((printf("##DBG chmod-1(%s,%o)\n",(const char *)dst,(unsigned)info_file.st_mode & gbl_umask.mask)))
+ ret = chmod(dst,info_file.st_mode & gbl_umask.mask);
+ }
+ if (ret == 0) {
+ ret = unlink(src);
+ }
+ if (ret == 0) return true;
}
- pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
- if (pos < 0 || pos == 0)
- return false;
- if (pathName[pos - 1] == ':')
- return false;
- pathName = pathName.Left(pos);
- }
- pathName = pathName2;
- while(pos < pathName.Length())
- {
- pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);
- if (pos < 0)
- pos = pathName.Length();
- if(!MyCreateDirectory(pathName.Left(pos)))
- return false;
+ return false;
}
return true;
}
-#ifndef _UNICODE
+bool CreateDir(CFSTR path)
+{
+ if (!path || !*path) {
+ SetLastError(ERROR_PATH_NOT_FOUND);
+ return false;
+ }
-bool CreateComplexDirectory(LPCWSTR _aPathName)
+#ifdef _UNICODE
+ AString name = nameWindowToUnix2(path);
+#else
+ const char * name = nameWindowToUnix(path);
+#endif
+ bool bret = false;
+ if (mkdir( name, 0700 ) == 0) bret = true;
+
+ TRACEN((printf("CreateDir(%s)=%d\n",(const char *)name,(int)bret)))
+ return bret;
+}
+
+bool CreateComplexDir(CFSTR _aPathName)
{
- UString pathName = _aPathName;
- int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);
- if (pos > 0 && pos == pathName.Length() - 1)
+ AString name = nameWindowToUnix2(_aPathName);
+ TRACEN((printf("CreateComplexDir(%s)\n",(const char *)name)))
+
+
+ FString pathName = _aPathName;
+ int pos = pathName.ReverseFind(FCHAR_PATH_SEPARATOR);
+ if (pos > 0 && pos == pathName.Len() - 1)
{
- if (pathName.Length() == 3 && pathName[1] == L':')
+ if (pathName.Len() == 3 && pathName[1] == L':')
return true; // Disk folder;
pathName.Delete(pos);
}
- UString pathName2 = pathName;
- pos = pathName.Length();
- while(true)
+ FString pathName2 = pathName;
+ pos = pathName.Len();
+ TRACEN((printf("CreateComplexDir(%s) pathName2=%ls\n",(const char *)name,(CFSTR)pathName2)))
+ for (;;)
{
- if(MyCreateDirectory(pathName))
+ if (CreateDir(pathName))
break;
- if(::GetLastError() == ERROR_ALREADY_EXISTS)
+ TRACEN((printf("CreateComplexDir(%s) GetLastError=%d (ERROR_ALREADY_EXISTS=%d)\n",(const char *)name,::GetLastError(), ERROR_ALREADY_EXISTS)))
+ if (::GetLastError() == ERROR_ALREADY_EXISTS)
{
#ifdef _WIN32 // FIXED for supporting symbolic link instead of a directory
- NFind::CFileInfoW fileInfo;
- if (!NFind::FindFile(pathName, fileInfo)) // For network folders
+ NFind::CFileInfo fileInfo;
+ if (!fileInfo.Find(pathName)) // For network folders
return true;
if (!fileInfo.IsDir())
return false;
#endif
break;
}
- pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);
+ pos = pathName.ReverseFind(FCHAR_PATH_SEPARATOR);
if (pos < 0 || pos == 0)
return false;
if (pathName[pos - 1] == L':')
@@ -667,20 +524,18 @@ bool CreateComplexDirectory(LPCWSTR _aPathName)
pathName = pathName.Left(pos);
}
pathName = pathName2;
- while(pos < pathName.Length())
+ while (pos < pathName.Len())
{
- pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);
+ pos = pathName.Find(FCHAR_PATH_SEPARATOR, pos + 1);
if (pos < 0)
- pos = pathName.Length();
- if(!MyCreateDirectory(pathName.Left(pos)))
+ pos = pathName.Len();
+ if (!CreateDir(pathName.Left(pos)))
return false;
}
return true;
}
-#endif
-
-bool DeleteFileAlways(LPCTSTR name)
+bool DeleteFileAlways(CFSTR name)
{
if (!name || !*name) {
SetLastError(ERROR_PATH_NOT_FOUND);
@@ -693,235 +548,344 @@ bool DeleteFileAlways(LPCTSTR name)
#endif
bool bret = false;
if (remove(unixname) == 0) bret = true;
- TRACEN((printf("DeleteFileAlways(%s)=%d\n",unixname,(int)bret)))
+ TRACEN((printf("DeleteFileAlways(%s)=%d\n",(const char *)unixname,(int)bret)))
return bret;
}
-#ifndef _UNICODE
-bool DeleteFileAlways(LPCWSTR name)
-{
- return DeleteFileAlways(UnicodeStringToMultiByte(name, CP_ACP));
+bool RemoveDirWithSubItems(const FString &path)
+{
+ bool needRemoveSubItems = true;
+ {
+ NFind::CFileInfo fi;
+ if (!fi.Find(path))
+ return false;
+ if (!fi.IsDir())
+ {
+ ::SetLastError(ERROR_DIRECTORY);
+ return false;
+ }
+ if (fi.HasReparsePoint())
+ needRemoveSubItems = false;
+ }
+
+ if (needRemoveSubItems)
+ {
+ FString s = path;
+ s += FCHAR_PATH_SEPARATOR;
+ unsigned prefixSize = s.Len();
+ s += FCHAR_ANY_MASK;
+ NFind::CEnumerator enumerator(s);
+ NFind::CFileInfo fi;
+ while (enumerator.Next(fi))
+ {
+ s.DeleteFrom(prefixSize);
+ s += fi.Name;
+ if (fi.IsDir())
+ {
+ if (!RemoveDirWithSubItems(s))
+ return false;
+ }
+ else if (!DeleteFileAlways(s))
+ return false;
+ }
+ }
+
+ if (!SetFileAttrib(path, 0))
+ return false;
+ return RemoveDir(path);
}
-#endif
-static bool RemoveDirectorySubItems2(const UString &pathPrefix, const NFind::CFileInfoW &fileInfo)
+bool RemoveDirectoryWithSubItems(const FString &path); // FIXME
+static bool RemoveDirectorySubItems2(const FString pathPrefix, const NFind::CFileInfo &fileInfo)
{
if (fileInfo.IsDir())
return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);
return DeleteFileAlways(pathPrefix + fileInfo.Name);
}
-
-bool RemoveDirectoryWithSubItems(const UString &path)
+bool RemoveDirectoryWithSubItems(const FString &path)
{
- NFind::CFileInfoW fileInfo;
- UString pathPrefix = path + NName::kDirDelimiter;
+ NFind::CFileInfo fileInfo;
+ FString pathPrefix = path + FCHAR_PATH_SEPARATOR;
{
- NFind::CEnumeratorW enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));
+ NFind::CEnumerator enumerator(pathPrefix + FCHAR_ANY_MASK);
while (enumerator.Next(fileInfo))
if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))
return false;
}
- if (!MySetFileAttributes(path, 0))
+ if (!SetFileAttrib(path, 0))
return false;
- return MyRemoveDirectory(path);
+ return RemoveDir(path);
}
-#ifndef _WIN32_WCE
+#ifdef UNDER_CE
-bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,
- int &fileNamePartStartIndex)
+bool MyGetFullPathName(CFSTR fileName, FString &resFullPath)
{
- LPTSTR fileNamePointer = 0;
- LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);
- DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1,
- buffer, &fileNamePointer);
- resultPath.ReleaseBuffer();
- if (needLength == 0 || needLength >= MAX_PATH)
- return false;
- if (fileNamePointer == 0)
- fileNamePartStartIndex = lstrlen(fileName);
- else
- fileNamePartStartIndex = fileNamePointer - buffer;
+ resFullPath = fileName;
return true;
}
-#ifndef _UNICODE
-bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,
- int &fileNamePartStartIndex)
-{
- const UINT currentPage = CP_ACP;
- CSysString sysPath;
- if (!MyGetFullPathName(UnicodeStringToMultiByte(fileName,
- currentPage), sysPath, fileNamePartStartIndex))
- return false;
- UString resultPath1 = MultiByteToUnicodeString(
- sysPath.Left(fileNamePartStartIndex), currentPage);
- UString resultPath2 = MultiByteToUnicodeString(
- sysPath.Mid(fileNamePartStartIndex), currentPage);
- fileNamePartStartIndex = resultPath1.Length();
- resultPath = resultPath1 + resultPath2;
- return true;
-}
-#endif
+#else
+#ifdef WIN_LONG_PATH
-bool MyGetFullPathName(LPCTSTR fileName, CSysString &path)
+static FString GetLastPart(CFSTR path)
{
- int index;
- return MyGetFullPathName(fileName, path, index);
+ int i = MyStringLen(path);
+ for (; i > 0; i--)
+ {
+ FChar c = path[i - 1];
+ if (c == FCHAR_PATH_SEPARATOR || c == '/')
+ break;
+ }
+ return path + i;
}
-#ifndef _UNICODE
-bool MyGetFullPathName(LPCWSTR fileName, UString &path)
+static void AddTrailingDots(CFSTR oldPath, FString &newPath)
{
- int index;
- return MyGetFullPathName(fileName, path, index);
+ int len = MyStringLen(oldPath);
+ int i;
+ for (i = len; i > 0 && oldPath[i - 1] == '.'; i--);
+ if (i == 0 || i == len)
+ return;
+ FString oldName = GetLastPart(oldPath);
+ FString newName = GetLastPart(newPath);
+ int nonDotsLen = oldName.Len() - (len - i);
+ if (nonDotsLen == 0 || newName.CompareNoCase(oldName.Left(nonDotsLen)) != 0)
+ return;
+ for (; i != len; i++)
+ newPath += '.';
}
-#endif
#endif
-/* needed to find .DLL/.so and SFX */
-bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath)
+
+bool MyGetFullPathName(CFSTR fileName, FString &resFullPath)
{
- if (path != 0) {
- printf("NOT EXPECTED : MySearchPath : path != NULL\n");
- exit(EXIT_FAILURE);
+ resFullPath.Empty();
+ #ifndef _UNICODE
+ if (!g_IsNT)
+ {
+ TCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ LPTSTR fileNamePointer = 0;
+ DWORD needLength = ::GetFullPathName(fs2fas(fileName), MAX_PATH + 1, s, &fileNamePointer);
+ if (needLength == 0 || needLength > MAX_PATH)
+ return false;
+ resFullPath = fas2fs(s);
+ return true;
}
-
- if (extension != 0) {
- printf("NOT EXPECTED : MySearchPath : extension != NULL\n");
- exit(EXIT_FAILURE);
+ else
+ #endif
+ {
+ LPWSTR fileNamePointer = 0;
+ WCHAR s[MAX_PATH + 2];
+ s[0] = 0;
+ DWORD needLength = ::GetFullPathNameW(fs2us(fileName), MAX_PATH + 1, s, &fileNamePointer);
+ if (needLength == 0)
+ return false;
+ if (needLength <= MAX_PATH)
+ {
+ resFullPath = us2fs(s);
+ return true;
+ }
+ #ifdef WIN_LONG_PATH
+ needLength++;
+ UString temp;
+ LPWSTR buffer = temp.GetBuffer(needLength + 1);
+ buffer[0] = 0;
+ DWORD needLength2 = ::GetFullPathNameW(fs2us(fileName), needLength, buffer, &fileNamePointer);
+ temp.ReleaseBuffer();
+ if (needLength2 > 0 && needLength2 <= needLength)
+ {
+ resFullPath = us2fs(temp);
+ AddTrailingDots(fileName, resFullPath);
+ return true;
+ }
+ #endif
+ return false;
}
+}
- if (fileName == 0) {
- printf("NOT EXPECTED : MySearchPath : fileName == NULL\n");
- exit(EXIT_FAILURE);
- }
+bool SetCurrentDir(CFSTR path)
+{
+ AString apath = UnicodeStringToMultiByte(path);
- const char *p7zip_home_dir = getenv("P7ZIP_HOME_DIR");
- if (p7zip_home_dir) {
- AString file_path = p7zip_home_dir;
- file_path += UnicodeStringToMultiByte(fileName, CP_ACP);
+ return chdir((const char*)apath) == 0;
+}
- TRACEN((printf("MySearchPath() fopen(%s)\n",(const char *)file_path)))
- FILE *file = fopen((const char *)file_path,"r");
- if (file) {
- // file is found
- fclose(file);
- resultPath = MultiByteToUnicodeString(file_path, CP_ACP);
- return true;
- }
+bool GetCurrentDir(FString &path)
+{
+ char begin[MAX_PATHNAME_LEN];
+ begin[0]='c';
+ begin[1]=':';
+ char * cret = getcwd(begin+2, MAX_PATHNAME_LEN - 3);
+ if (cret)
+ {
+#ifdef _UNICODE
+ path = GetUnicodeString(begin);
+#else
+ path = begin;
+#endif
+ return true;
}
return false;
}
-#ifndef _UNICODE
-bool MyGetTempPath(CSysString &path)
-{
- path = "c:/tmp/"; // final '/' is needed
- return true;
-}
#endif
-bool MyGetTempPath(UString &path)
+bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName)
{
- path = L"c:/tmp/"; // final '/' is needed
- return true;
+ bool res = MyGetFullPathName(path, resDirPrefix);
+ if (!res)
+ resDirPrefix = path;
+ int pos = resDirPrefix.ReverseFind(FCHAR_PATH_SEPARATOR);
+ resFileName = resDirPrefix.Ptr(pos + 1);
+ resDirPrefix.DeleteFrom(pos + 1);
+ return res;
}
-static NSynchronization::CCriticalSection g_CountCriticalSection;
+bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix)
+{
+ FString resFileName;
+ return GetFullPathAndSplit(path, resDirPrefix, resFileName);
+}
-static CSysString CSysConvertUInt32ToString(UInt32 value)
+bool MyGetTempPath(FString &path)
{
- TCHAR buffer[32];
- ConvertUInt32ToString(value, buffer);
- return buffer;
+ path = L"c:/tmp/"; // final '/' is needed
+ return true;
}
-UINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)
+static bool CreateTempFile(CFSTR prefix, bool addRandom, FString &path, NIO::COutFile *outFile)
{
+#ifdef _WIN32
+ UInt32 d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId();
+#else
static UInt32 memo_count = 0;
UInt32 count;
g_CountCriticalSection.Enter();
count = memo_count++;
g_CountCriticalSection.Leave();
-
- Remove();
-/* UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH)); */
UINT number = (UINT)getpid();
- resultPath = dirPath;
- resultPath += prefix;
- resultPath += TEXT('#');
- resultPath += CSysConvertUInt32ToString(number);
- resultPath += TEXT('@');
- resultPath += CSysConvertUInt32ToString(count);
- resultPath += TEXT(".tmp");
-
- _fileName = resultPath;
+ UInt32 d = (GetTickCount() << 12) ^ (count << 14) ^ number;
+#endif
+ for (unsigned i = 0; i < 100; i++)
+ {
+ path = prefix;
+ if (addRandom)
+ {
+ FChar s[16];
+ UInt32 value = d;
+ unsigned k;
+ for (k = 0; k < 8; k++)
+ {
+ unsigned t = value & 0xF;
+ value >>= 4;
+ s[k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
+ }
+ s[k] = '\0';
+ if (outFile)
+ path += FChar('.');
+ path += s;
+ UInt32 step = GetTickCount() + 2;
+ if (step == 0)
+ step = 1;
+ d += step;
+ }
+ addRandom = true;
+ if (outFile)
+ path += FTEXT(".tmp");
+ if (NFind::DoesFileOrDirExist(path))
+ {
+ SetLastError(ERROR_ALREADY_EXISTS);
+ continue;
+ }
+ if (outFile)
+ {
+ if (outFile->Create(path, false))
+ return true;
+ }
+ else
+ {
+ if (CreateDir(path))
+ return true;
+ }
+ DWORD error = GetLastError();
+ if (error != ERROR_FILE_EXISTS &&
+ error != ERROR_ALREADY_EXISTS)
+ break;
+ }
+ path.Empty();
+ return false;
+}
+
+bool CTempFile::Create(CFSTR prefix, NIO::COutFile *outFile)
+{
+ if (!Remove())
+ return false;
+ if (!CreateTempFile(prefix, false, _path, outFile))
+ return false;
_mustBeDeleted = true;
-
- return number;
+ return true;
}
-bool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)
+bool CTempFile::CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile)
{
- CSysString tempPath;
+ if (!Remove())
+ return false;
+ FString tempPath;
if (!MyGetTempPath(tempPath))
return false;
- if (Create(tempPath, prefix, resultPath) != 0)
- return true;
- return false;
+ if (!CreateTempFile(tempPath + namePrefix, true, _path, outFile))
+ return false;
+ _mustBeDeleted = true;
+ return true;
}
-
bool CTempFile::Remove()
{
if (!_mustBeDeleted)
return true;
- _mustBeDeleted = !DeleteFileAlways(_fileName);
+ _mustBeDeleted = !DeleteFileAlways(_path);
return !_mustBeDeleted;
}
-bool CreateTempDirectory(LPCWSTR prefix, UString &dirName)
+bool CTempFile::MoveTo(CFSTR name, bool deleteDestBefore)
{
- /*
- CSysString prefix = tempPath + prefixChars;
- CRandom random;
- random.Init();
- */
- for (;;)
- {
- {
- CTempFileW tempFile;
- if (!tempFile.Create(prefix, dirName))
- return false;
- if (!tempFile.Remove())
+ if (deleteDestBefore)
+ if (NFind::DoesFileExist(name))
+ if (!DeleteFileAlways(name))
return false;
- }
- /*
- UINT32 randomNumber = random.Generate();
- TCHAR randomNumberString[32];
- _stprintf(randomNumberString, _T("%04X"), randomNumber);
- dirName = prefix + randomNumberString;
- */
- if (NFind::DoesFileOrDirExist(dirName))
- continue;
- if (MyCreateDirectory(dirName))
- return true;
- if (::GetLastError() != ERROR_ALREADY_EXISTS)
- return false;
- }
+ DisableDeleting();
+ return MyMoveFile(_path, name);
}
-bool CTempDirectory::Create(LPCTSTR prefix)
+bool CTempDir::Create(CFSTR prefix)
{
- Remove();
- return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));
+ if (!Remove())
+ return false;
+ FString tempPath;
+ if (!MyGetTempPath(tempPath))
+ return false;
+ if (!CreateTempFile(tempPath + prefix, true, _path, NULL))
+ return false;
+ _mustBeDeleted = true;
+ return true;
}
+bool CTempDir::Remove()
+{
+ if (!_mustBeDeleted)
+ return true;
+ _mustBeDeleted = !RemoveDirectoryWithSubItems(_path);
+ return !_mustBeDeleted;
+}
}}}
+
+
+
diff --git a/src/libs/7zip/unix/CPP/Windows/FileDir.h b/src/libs/7zip/unix/CPP/Windows/FileDir.h
index a7cfbaf8d..02d3e5a57 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileDir.h
+++ b/src/libs/7zip/unix/CPP/Windows/FileDir.h
@@ -1,114 +1,96 @@
// Windows/FileDir.h
-#ifndef __WINDOWS_FILEDIR_H
-#define __WINDOWS_FILEDIR_H
+#ifndef __WINDOWS_FILE_DIR_H
+#define __WINDOWS_FILE_DIR_H
#include "../Common/MyString.h"
-#include "Defs.h"
-/* GetFullPathName for 7zAES.cpp */
-DWORD WINAPI GetFullPathName( LPCSTR name, DWORD len, LPSTR buffer, LPSTR *lastpart );
+#include "FileIO.h"
namespace NWindows {
namespace NFile {
-namespace NDirectory {
+namespace NDir {
-bool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);
+bool GetWindowsDir(FString &path);
+bool GetSystemDir(FString &path);
-bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);
-#ifndef _UNICODE
-bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);
-#endif
+bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
+bool SetFileAttrib(CFSTR path, DWORD attrib);
+bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
-bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);
-#ifndef _UNICODE
-bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);
+#ifndef UNDER_CE
+bool MyCreateHardLink(CFSTR newFileName, CFSTR existFileName);
#endif
-bool MyRemoveDirectory(LPCTSTR pathName);
-#ifndef _UNICODE
-bool MyRemoveDirectory(LPCWSTR pathName);
-#endif
+bool RemoveDir(CFSTR path);
+bool CreateDir(CFSTR path);
+bool CreateComplexDir(CFSTR path);
+bool DeleteFileAlways(CFSTR name);
+bool RemoveDirWithSubItems(const FString &path);
-bool MyCreateDirectory(LPCTSTR pathName);
-bool CreateComplexDirectory(LPCTSTR pathName);
-#ifndef _UNICODE
-bool MyCreateDirectory(LPCWSTR pathName);
-bool CreateComplexDirectory(LPCWSTR pathName);
-#endif
+bool MyGetFullPathName(CFSTR path, FString &resFullPath);
+bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
+bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
-bool DeleteFileAlways(LPCTSTR name);
-#ifndef _UNICODE
-bool DeleteFileAlways(LPCWSTR name);
-#endif
-bool RemoveDirectoryWithSubItems(const UString &path);
-
-#ifndef _WIN32_WCE
-bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,
- int &fileNamePartStartIndex);
-bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);
-bool GetOnlyName(LPCTSTR fileName, CSysString &resultName);
-bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);
-#ifndef _UNICODE
-bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,
- int &fileNamePartStartIndex);
-bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);
-#endif
-
-#endif
+#ifndef UNDER_CE
-bool MySetCurrentDirectory(LPCWSTR path);
-bool MyGetCurrentDirectory(CSysString &resultPath);
+bool SetCurrentDir(CFSTR path);
+bool GetCurrentDir(FString &resultPath);
-bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath);
-
-bool MyGetTempPath(CSysString &resultPath);
-#ifndef _UNICODE
-bool MyGetTempPath(UString &resultPath);
#endif
+bool MyGetTempPath(FString &resultPath);
+
class CTempFile
{
bool _mustBeDeleted;
- CSysString _fileName;
+ FString _path;
+ void DisableDeleting() { _mustBeDeleted = false; }
public:
CTempFile(): _mustBeDeleted(false) {}
~CTempFile() { Remove(); }
- void DisableDeleting() { _mustBeDeleted = false; }
- UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);
- bool Create(LPCTSTR prefix, CSysString &resultPath);
+ const FString &GetPath() const { return _path; }
+ bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
+ bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
bool Remove();
+ bool MoveTo(CFSTR name, bool deleteDestBefore);
};
-#ifdef _UNICODE
-typedef CTempFile CTempFileW;
-#endif
-
-bool CreateTempDirectory(LPCWSTR prefixChars, UString &dirName);
-
-class CTempDirectory
+class CTempDir
{
bool _mustBeDeleted;
- CSysString _tempDir;
+ FString _path;
public:
- const CSysString &GetPath() const { return _tempDir; }
- CTempDirectory(): _mustBeDeleted(false) {}
- ~CTempDirectory() { Remove(); }
- bool Create(LPCTSTR prefix) ;
- bool Remove()
- {
- if (!_mustBeDeleted)
- return true;
- _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);
- return (!_mustBeDeleted);
- }
+ CTempDir(): _mustBeDeleted(false) {}
+ ~CTempDir() { Remove(); }
+ const FString &GetPath() const { return _path; }
void DisableDeleting() { _mustBeDeleted = false; }
+ bool Create(CFSTR namePrefix) ;
+ bool Remove();
};
-#ifdef _UNICODE
-typedef CTempDirectory CTempDirectoryW;
-#endif
+#if !defined(UNDER_CE)
+class CCurrentDirRestorer
+{
+ FString _path;
+public:
+ bool NeedRestore;
+ CCurrentDirRestorer(): NeedRestore(true)
+ {
+ GetCurrentDir(_path);
+ }
+ ~CCurrentDirRestorer()
+ {
+ if (!NeedRestore)
+ return;
+ FString s;
+ if (GetCurrentDir(s))
+ if (s != _path)
+ SetCurrentDir(_path);
+ }
+};
+#endif
}}}
diff --git a/src/libs/7zip/unix/CPP/Windows/FileFind.cpp b/src/libs/7zip/unix/CPP/Windows/FileFind.cpp
index 9e526a233..eb2f93835 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileFind.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/FileFind.cpp
@@ -3,8 +3,15 @@
#include "StdAfx.h"
#include "FileFind.h"
+#include "FileIO.h"
+
#include "../Common/StringConvert.h"
+
+#ifndef _UNICODE
+extern bool g_IsNT;
+#endif
+
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
@@ -32,9 +39,9 @@ void my_windows_split_path(const AString &p_path, AString &dir , AString &base)
base = ".";
else
base = p_path;
- } else if ((pos+1) < p_path.Length()) {
+ } else if ((pos+1) < p_path.Len()) {
// true separator
- base = p_path.Mid(pos+1);
+ base = p_path.Ptr(pos+1);
while ((pos >= 1) && (p_path[pos-1] == '/'))
pos--;
if (pos == 0)
@@ -69,9 +76,9 @@ static void my_windows_split_path(const UString &p_path, UString &dir , UString
base = L".";
else
base = p_path;
- } else if ((pos+1) < p_path.Length()) {
+ } else if ((pos+1) < p_path.Len()) {
// true separator
- base = p_path.Mid(pos+1);
+ base = p_path.Ptr(pos+1);
while ((pos >= 1) && (p_path[pos-1] == L'/'))
pos--;
if (pos == 0)
@@ -128,30 +135,71 @@ static int filter_pattern(const char *string , const char *pattern , int flags_n
return 0;
}
-
namespace NWindows {
namespace NFile {
-namespace NFind {
-static const TCHAR kDot = TEXT('.');
+#ifdef SUPPORT_DEVICE_FILE
+bool IsDeviceName(CFSTR n);
+#endif
+
+#if defined(WIN_LONG_PATH)
+bool GetLongPath(CFSTR fileName, UString &res);
+#endif
+
+namespace NFind {
bool CFileInfo::IsDots() const
-{
+{
if (!IsDir() || Name.IsEmpty())
return false;
- if (Name[0] != kDot)
+ if (Name[0] != FTEXT('.'))
return false;
- return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
+ return Name.Len() == 1 || (Name.Len() == 2 && Name[1] == FTEXT('.'));
}
-bool CFileInfoW::IsDots() const
-{
- if (!IsDir() || Name.IsEmpty())
- return false;
- if (Name[0] != kDot)
- return false;
- return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
+#define WIN_FD_TO_MY_FI(fi, fd) \
+ fi.Attrib = fd.dwFileAttributes; \
+ fi.CTime = fd.ftCreationTime; \
+ fi.ATime = fd.ftLastAccessTime; \
+ fi.MTime = fd.ftLastWriteTime; \
+ fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; \
+ fi.IsDevice = false;
+
+ /*
+ #ifdef UNDER_CE
+ fi.ObjectID = fd.dwOID;
+ #else
+ fi.ReparseTag = fd.dwReserved0;
+ #endif
+ */
+
+#ifndef _UNICODE
+
+static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
+
+static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
+{
+ WIN_FD_TO_MY_FI(fi, fd);
+ fi.Name = fas2fs(fd.cFileName);
}
+#endif
+
+////////////////////////////////
+// CFindFile
+
+bool CFindFile::Close()
+{
+ if(_dirp == 0)
+ return true;
+ int ret = closedir(_dirp);
+ if (ret == 0)
+ {
+ _dirp = 0;
+ return true;
+ }
+ return false;
+}
+
static bool originalFilename(const UString & src, AString & res)
{
@@ -170,15 +218,13 @@ static bool originalFilename(const UString & src, AString & res)
return true;
}
-
-
// Warning this function cannot update "fileInfo.Name"
-static int fillin_CFileInfo(CFileInfo &fileInfo,const char *filename) {
+static int fillin_CFileInfo(CFileInfo &fileInfo,const char *filename,bool ignoreLink) {
struct stat stat_info;
int ret;
#ifdef ENV_HAVE_LSTAT
- if (global_use_lstat) {
+ if ( (global_use_lstat) && (ignoreLink == false)) {
ret = lstat(filename,&stat_info);
} else
#endif
@@ -186,6 +232,9 @@ static int fillin_CFileInfo(CFileInfo &fileInfo,const char *filename) {
ret = stat(filename,&stat_info);
}
+ // printf("fillin_CFileInfo(%s,%d)=%d mode=%o\n",filename,(int)ignoreLink,ret,(unsigned)stat_info.st_mode);
+
+
if (ret != 0) return ret;
/* FIXME : FILE_ATTRIBUTE_HIDDEN ? */
@@ -214,7 +263,7 @@ static int fillin_CFileInfo(CFileInfo &fileInfo,const char *filename) {
return 0;
}
-static int fillin_CFileInfo(CFileInfo &fileInfo,const char *dir,const char *name) {
+static int fillin_CFileInfo(CFileInfo &fi,const char *dir,const char *name,bool ignoreLink) {
char filename[MAX_PATHNAME_LEN];
size_t dir_len = strlen(dir);
size_t name_len = strlen(name);
@@ -231,9 +280,13 @@ static int fillin_CFileInfo(CFileInfo &fileInfo,const char *dir,const char *name
filename[dir_len] = CHAR_PATH_SEPARATOR;
memcpy(filename+(dir_len+1),name,name_len+1); // copy also final '\0'
- fileInfo.Name = name;
+#ifdef _UNICODE
+ fi.Name = GetUnicodeString(name, CP_ACP);
+#else
+ fi.Name = name;
+#endif
- int ret = fillin_CFileInfo(fileInfo,filename);
+ int ret = fillin_CFileInfo(fi,filename,ignoreLink);
if (ret != 0) {
AString err_msg = "stat error for ";
err_msg += filename;
@@ -245,36 +298,22 @@ static int fillin_CFileInfo(CFileInfo &fileInfo,const char *dir,const char *name
return ret;
}
-////////////////////////////////
-// CFindFile
-
-bool CFindFile::Close()
-{
-
- if(_dirp == 0)
- return true;
- int ret = closedir(_dirp);
- if (ret == 0)
- {
- _dirp = 0;
- return true;
- }
- return false;
-}
-
-// bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
-bool CFindFile::FindFirst(LPCSTR wildcard, CFileInfo &fileInfo)
+bool CFindFile::FindFirst(CFSTR cfWildcard, CFileInfo &fi, bool ignoreLink)
{
if (!Close())
return false;
+ AString Awildcard = UnicodeStringToMultiByte(cfWildcard, CP_ACP);
+ const char * wildcard = (const char *)Awildcard;
+
+
if ((!wildcard) || (wildcard[0]==0)) {
SetLastError(ERROR_PATH_NOT_FOUND);
return false;
}
-
+
my_windows_split_path(nameWindowToUnix(wildcard),_directory,_pattern);
-
+
TRACEN((printf("CFindFile::FindFirst : %s (dirname=%s,pattern=%s)\n",wildcard,(const char *)_directory,(const char *)_pattern)))
_dirp = ::opendir((const char *)_directory);
@@ -296,7 +335,7 @@ bool CFindFile::FindFirst(LPCSTR wildcard, CFileInfo &fileInfo)
struct dirent *dp;
while ((dp = readdir(_dirp)) != NULL) {
if (filter_pattern(dp->d_name,(const char *)_pattern,0) == 1) {
- int retf = fillin_CFileInfo(fileInfo,(const char *)_directory,dp->d_name);
+ int retf = fillin_CFileInfo(fi,(const char *)_directory,dp->d_name,ignoreLink);
if (retf)
{
TRACEN((printf("CFindFile::FindFirst : closedir-1(dirp=%p)\n",_dirp)))
@@ -315,29 +354,10 @@ bool CFindFile::FindFirst(LPCSTR wildcard, CFileInfo &fileInfo)
_dirp = 0;
SetLastError( ERROR_NO_MORE_FILES );
return false;
-}
-bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
-{
- if (!Close())
- return false;
- CFileInfo fileInfo0;
- AString Awildcard = UnicodeStringToMultiByte(wildcard, CP_ACP);
- bool bret = FindFirst((LPCSTR)Awildcard, fileInfo0);
- if (bret)
- {
- fileInfo.Attrib = fileInfo0.Attrib;
- fileInfo.CTime = fileInfo0.CTime;
- fileInfo.ATime = fileInfo0.ATime;
- fileInfo.MTime = fileInfo0.MTime;
- fileInfo.Size = fileInfo0.Size;
- fileInfo.IsDevice = fileInfo0.IsDevice;
- fileInfo.Name = GetUnicodeString(fileInfo0.Name, CP_ACP);
- }
- return bret;
}
-bool CFindFile::FindNext(CFileInfo &fileInfo)
+bool CFindFile::FindNext(CFileInfo &fi)
{
if (_dirp == 0)
{
@@ -348,7 +368,7 @@ bool CFindFile::FindNext(CFileInfo &fileInfo)
struct dirent *dp;
while ((dp = readdir(_dirp)) != NULL) {
if (filter_pattern(dp->d_name,(const char *)_pattern,0) == 1) {
- int retf = fillin_CFileInfo(fileInfo,(const char *)_directory,dp->d_name);
+ int retf = fillin_CFileInfo(fi,(const char *)_directory,dp->d_name,false);
if (retf)
{
TRACEN((printf("FindNextFileA -%s- ret_handle=FALSE (errno=%d)\n",dp->d_name,errno)))
@@ -364,46 +384,18 @@ bool CFindFile::FindNext(CFileInfo &fileInfo)
return false;
}
-bool CFindFile::FindNext(CFileInfoW &fileInfo)
-{
- CFileInfo fileInfo0;
- bool bret = FindNext(fileInfo0);
- if (bret)
- {
- fileInfo.Attrib = fileInfo0.Attrib;
- fileInfo.CTime = fileInfo0.CTime;
- fileInfo.ATime = fileInfo0.ATime;
- fileInfo.MTime = fileInfo0.MTime;
- fileInfo.Size = fileInfo0.Size;
- fileInfo.IsDevice = fileInfo0.IsDevice;
- fileInfo.Name = GetUnicodeString(fileInfo0.Name, CP_ACP);
- }
- return bret;
-}
+#define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0;
-bool CFileInfo::Find(LPCSTR wildcard)
+void CFileInfoBase::Clear()
{
- #ifdef SUPPORT_DEVICE_FILE
- if (IsDeviceName(wildcard))
- {
- Clear();
- IsDevice = true;
- NIO::CInFile inFile;
- if (!inFile.Open(wildcard))
- return false;
- Name = wildcard + 4;
- if (inFile.LengthDefined)
- Size = inFile.Length;
- return true;
- }
- #endif
- CFindFile finder;
- return finder.FindFirst(wildcard, *this);
+ Size = 0;
+ MY_CLEAR_FILETIME(CTime);
+ MY_CLEAR_FILETIME(ATime);
+ MY_CLEAR_FILETIME(MTime);
+ Attrib = 0;
}
-
-// #ifndef _UNICODE
-bool CFileInfoW::Find(LPCWSTR wildcard)
+bool CFileInfo::Find(CFSTR wildcard, bool ignoreLink)
{
#ifdef SUPPORT_DEVICE_FILE
if (IsDeviceName(wildcard))
@@ -420,148 +412,88 @@ bool CFileInfoW::Find(LPCWSTR wildcard)
}
#endif
CFindFile finder;
- return finder.FindFirst(wildcard, *this);
-}
-// #endif
-
-bool FindFile(LPCSTR wildcard, CFileInfo &fileInfo)
-{
- // CFindFile finder;
- // return finder.FindFirst(wildcard, fileInfo);
- AString dir,base;
- my_windows_split_path(wildcard, dir , base);
- int ret = fillin_CFileInfo(fileInfo,nameWindowToUnix(wildcard));
- fileInfo.Name = base;
- TRACEN((printf("FindFile(%s,CFileInfo) ret=%d\n",wildcard,ret)))
- return (ret == 0);
-}
-
-bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)
-{
- // CFindFile finder;
- // return finder.FindFirst(wildcard, fileInfo);
- AString name = UnicodeStringToMultiByte(wildcard, CP_ACP);
- CFileInfo fileInfo0;
- int ret = fillin_CFileInfo(fileInfo0,nameWindowToUnix((const char *)name));
- TRACEN((printf("FindFile-1(%s,CFileInfo) ret=%d\n",(const char *)name,ret)))
- if (ret != 0)
+ if (finder.FindFirst(wildcard, *this,ignoreLink))
+ return true;
+ #ifdef _WIN32
{
- // Try to recover the original filename
- AString resultString;
- bool is_good = originalFilename(wildcard, resultString);
- if (is_good) {
- ret = fillin_CFileInfo(fileInfo0,nameWindowToUnix((const char *)resultString));
- TRACEN((printf("FindFile-2(%s,CFileInfo) ret=%d\n",(const char *)resultString,ret)))
+ DWORD lastError = GetLastError();
+ if (lastError == ERROR_BAD_NETPATH || lastError == ERROR_FILE_NOT_FOUND)
+ {
+ int len = MyStringLen(wildcard);
+ if (len > 2 && wildcard[0] == '\\' && wildcard[1] == '\\')
+ {
+ int pos = FindCharPosInString(wildcard + 2, FTEXT('\\'));
+ if (pos >= 0)
+ {
+ pos += 2 + 1;
+ len -= pos;
+ CFSTR remString = wildcard + pos;
+ int pos2 = FindCharPosInString(remString, FTEXT('\\'));
+ FString s = wildcard;
+ if (pos2 < 0 || pos2 == len - 1)
+ {
+ FString s = wildcard;
+ if (pos2 < 0)
+ {
+ pos2 = len;
+ s += FTEXT('\\');
+ }
+ s += FCHAR_ANY_MASK;
+ if (finder.FindFirst(s, *this))
+ if (Name == FTEXT("."))
+ {
+ Name.SetFrom(s.Ptr(pos), pos2);
+ return true;
+ }
+ ::SetLastError(lastError);
+ }
+ }
+ }
}
}
- if (ret == 0)
- {
- UString dir,base;
- my_windows_split_path(wildcard, dir , base);
- fileInfo.Attrib = fileInfo0.Attrib;
- fileInfo.CTime = fileInfo0.CTime;
- fileInfo.ATime = fileInfo0.ATime;
- fileInfo.MTime = fileInfo0.MTime;
- fileInfo.Size = fileInfo0.Size;
- fileInfo.Name = base;
- }
- return (ret == 0);
+ #endif
+ return false;
}
-bool DoesFileExist(LPCSTR name) // FIXME
+bool DoesFileExist(CFSTR name)
{
CFileInfo fi;
- int ret = fillin_CFileInfo(fi,nameWindowToUnix(name));
- TRACEN((printf("DoesFileExist(%s) ret=%d\n",name,ret)))
- return (ret == 0) && !fi.IsDir();;
+ return fi.Find(name) && !fi.IsDir();
}
-bool DoesDirExist(LPCSTR name) // FIXME
+bool DoesDirExist(CFSTR name)
{
CFileInfo fi;
- int ret = fillin_CFileInfo(fi,nameWindowToUnix(name));
- TRACEN((printf("DoesDirExist(%s) ret=%d\n",name,ret)))
- return (ret == 0) && fi.IsDir();;
-}
-
-bool DoesFileOrDirExist(LPCSTR name)
-{
- CFileInfo fileInfo;
- int ret = fillin_CFileInfo(fileInfo,nameWindowToUnix(name));
- TRACEN((printf("DoesFileOrDirExist(%s) ret=%d\n",name,ret)))
- return (ret == 0);
-}
-
-bool DoesFileExist(LPCWSTR name)
-{
- AString Aname = UnicodeStringToMultiByte(name, CP_ACP);
- bool bret = DoesFileExist((LPCSTR)Aname);
- if (bret) return bret;
-
- // Try to recover the original filename
- AString resultString;
- bool is_good = originalFilename(name, resultString);
- if (is_good) {
- bret = DoesFileExist((const char *)resultString);
- }
- return bret;
-}
-
-bool DoesDirExist(LPCWSTR name)
-{
- AString Aname = UnicodeStringToMultiByte(name, CP_ACP);
- bool bret = DoesDirExist((LPCSTR)Aname);
- if (bret) return bret;
-
- // Try to recover the original filename
- AString resultString;
- bool is_good = originalFilename(name, resultString);
- if (is_good) {
- bret = DoesDirExist((const char *)resultString);
- }
- return bret;
+ return fi.Find(name) && fi.IsDir();
}
-
-bool DoesFileOrDirExist(LPCWSTR name)
+bool DoesFileOrDirExist(CFSTR name)
{
- AString Aname = UnicodeStringToMultiByte(name, CP_ACP);
- bool bret = DoesFileOrDirExist((LPCSTR)Aname);
- if (bret) return bret;
-
- // Try to recover the original filename
- AString resultString;
- bool is_good = originalFilename(name, resultString);
- if (is_good) {
- bret = DoesFileOrDirExist((const char *)resultString);
- }
- return bret;
+ CFileInfo fi;
+ return fi.Find(name);
}
-/////////////////////////////////////
-// CEnumerator
-
-bool CEnumerator::NextAny(CFileInfo &fileInfo)
+bool CEnumerator::NextAny(CFileInfo &fi)
{
- if(_findFile.IsHandleAllocated())
- return _findFile.FindNext(fileInfo);
+ if (_findFile.IsHandleAllocated())
+ return _findFile.FindNext(fi);
else
- return _findFile.FindFirst(_wildcard, fileInfo);
+ return _findFile.FindFirst(_wildcard, fi);
}
-bool CEnumerator::Next(CFileInfo &fileInfo)
+bool CEnumerator::Next(CFileInfo &fi)
{
- while(true)
+ for (;;)
{
- if(!NextAny(fileInfo))
+ if (!NextAny(fi))
return false;
- if(!fileInfo.IsDots())
+ if (!fi.IsDots())
return true;
}
}
-bool CEnumerator::Next(CFileInfo &fileInfo, bool &found)
+bool CEnumerator::Next(CFileInfo &fi, bool &found)
{
- if (Next(fileInfo))
+ if (Next(fi))
{
found = true;
return true;
@@ -570,35 +502,100 @@ bool CEnumerator::Next(CFileInfo &fileInfo, bool &found)
return (::GetLastError() == ERROR_NO_MORE_FILES);
}
-bool CEnumeratorW::NextAny(CFileInfoW &fileInfo)
+////////////////////////////////
+// CFindChangeNotification
+// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.
+
+#ifdef _WIN32
+bool CFindChangeNotification::Close()
{
- if(_findFile.IsHandleAllocated())
- return _findFile.FindNext(fileInfo);
- else
- return _findFile.FindFirst(_wildcard, fileInfo);
+ if (!IsHandleAllocated())
+ return true;
+ if (!::FindCloseChangeNotification(_handle))
+ return false;
+ _handle = INVALID_HANDLE_VALUE;
+ return true;
}
-bool CEnumeratorW::Next(CFileInfoW &fileInfo)
+HANDLE CFindChangeNotification::FindFirst(CFSTR pathName, bool watchSubtree, DWORD notifyFilter)
{
- while(true)
+ #ifndef _UNICODE
+ if (!g_IsNT)
+ _handle = ::FindFirstChangeNotification(fs2fas(pathName), BoolToBOOL(watchSubtree), notifyFilter);
+ else
+ #endif
{
- if(!NextAny(fileInfo))
- return false;
- if(!fileInfo.IsDots())
- return true;
+ _handle = ::FindFirstChangeNotificationW(fs2us(pathName), BoolToBOOL(watchSubtree), notifyFilter);
+ #ifdef WIN_LONG_PATH
+ if (!IsHandleAllocated())
+ {
+ UString longPath;
+ if (GetLongPath(pathName, longPath))
+ _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
+ }
+ #endif
}
+ return _handle;
}
-bool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)
+#ifndef UNDER_CE
+
+bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings)
{
- if (Next(fileInfo))
+ driveStrings.Clear();
+ #ifndef _UNICODE
+ if (!g_IsNT)
{
- found = true;
- return true;
+ driveStrings.Clear();
+ UINT32 size = GetLogicalDriveStrings(0, NULL);
+ if (size == 0)
+ return false;
+ AString buf;
+ UINT32 newSize = GetLogicalDriveStrings(size, buf.GetBuffer(size));
+ if (newSize == 0 || newSize > size)
+ return false;
+ AString s;
+ for (UINT32 i = 0; i < newSize; i++)
+ {
+ char c = buf[i];
+ if (c == '\0')
+ {
+ driveStrings.Add(fas2fs(s));
+ s.Empty();
+ }
+ else
+ s += c;
+ }
+ return s.IsEmpty();
+ }
+ else
+ #endif
+ {
+ UINT32 size = GetLogicalDriveStringsW(0, NULL);
+ if (size == 0)
+ return false;
+ UString buf;
+ UINT32 newSize = GetLogicalDriveStringsW(size, buf.GetBuffer(size));
+ if (newSize == 0 || newSize > size)
+ return false;
+ UString s;
+ for (UINT32 i = 0; i < newSize; i++)
+ {
+ WCHAR c = buf[i];
+ if (c == L'\0')
+ {
+ driveStrings.Add(us2fs(s));
+ s.Empty();
+ }
+ else
+ s += c;
+ }
+ return s.IsEmpty();
}
- found = false;
- return (::GetLastError() == ERROR_NO_MORE_FILES);
}
+#endif
+
+#endif // _WIN32
}}}
diff --git a/src/libs/7zip/unix/CPP/Windows/FileFind.h b/src/libs/7zip/unix/CPP/Windows/FileFind.h
index a1fd0f072..06435bb3d 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileFind.h
+++ b/src/libs/7zip/unix/CPP/Windows/FileFind.h
@@ -1,10 +1,10 @@
// Windows/FileFind.h
-#ifndef __WINDOWS_FILEFIND_H
-#define __WINDOWS_FILEFIND_H
+#ifndef __WINDOWS_FILE_FIND_H
+#define __WINDOWS_FILE_FIND_H
#include "../Common/MyString.h"
-#include "FileName.h"
+#include "../Common/MyTypes.h"
#include "Defs.h"
#include <sys/types.h> /* for DIR */
@@ -26,8 +26,10 @@ namespace NAttributes
}
class CFileInfoBase
-{
- bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
+{
+ bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
+protected:
+ void Clear();
public:
UInt64 Size;
FILETIME CTime;
@@ -35,92 +37,87 @@ public:
FILETIME MTime;
DWORD Attrib;
bool IsDevice;
-
+
+ /*
+ #ifdef UNDER_CE
+ DWORD ObjectID;
+ #else
+ UINT32 ReparseTag;
+ #endif
+ */
+
+ bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
+ bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
+ bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }
+ bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }
+ bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }
+ bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }
+ bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }
+ bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }
+ bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
+ bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
+ bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
};
-class CFileInfo: public CFileInfoBase
-{
-public:
- AString Name; // FIXME CSysString Name;
- bool IsDots() const;
- bool Find(LPCSTR wildcard);
-};
+struct CFileInfo: public CFileInfoBase
+{
+ FString Name;
-// FIXME #ifdef _UNICODE
-// typedef CFileInfo CFileInfoW;
-// #else
-class CFileInfoW: public CFileInfoBase
-{
-public:
- UString Name;
bool IsDots() const;
- bool Find(LPCWSTR wildcard);
+ bool Find(CFSTR wildcard, bool ignoreLink = false);
};
-// #endif
class CFindFile
{
friend class CEnumerator;
DIR *_dirp;
AString _pattern;
- AString _directory;
+ AString _directory;
public:
- bool IsHandleAllocated() const { return (_dirp != 0); }
+ bool IsHandleAllocated() const { return (_dirp != 0); }
CFindFile(): _dirp(0) {}
- ~CFindFile() { Close(); }
- // bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
- bool FindFirst(LPCSTR wildcard, CFileInfo &fileInfo);
+ ~CFindFile() { Close(); }
+ bool FindFirst(CFSTR wildcard, CFileInfo &fileInfo, bool ignoreLink = false);
bool FindNext(CFileInfo &fileInfo);
- // FIXME #ifndef _UNICODE
- bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
- bool FindNext(CFileInfoW &fileInfo);
- // FIXME #endif
bool Close();
};
-bool FindFile(LPCSTR wildcard, CFileInfo &fileInfo);
-
-bool DoesFileExist(LPCSTR name);
-bool DoesDirExist(LPCTSTR name);
-bool DoesFileOrDirExist(LPCSTR name);
-// #ifndef _UNICODE
-bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
-bool DoesFileExist(LPCWSTR name);
-bool DoesDirExist(LPCWSTR name);
-bool DoesFileOrDirExist(LPCWSTR name);
-// #endif
+bool DoesFileExist(CFSTR name);
+bool DoesDirExist(CFSTR name);
+bool DoesFileOrDirExist(CFSTR name);
class CEnumerator
{
CFindFile _findFile;
- AString _wildcard; // FIXME CSysString _wildcard;
+ FString _wildcard;
+
bool NextAny(CFileInfo &fileInfo);
public:
- CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
- // FIXME CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
- CEnumerator(const AString &wildcard): _wildcard(wildcard) {}
+ CEnumerator(const FString &wildcard): _wildcard(wildcard) {}
bool Next(CFileInfo &fileInfo);
bool Next(CFileInfo &fileInfo, bool &found);
};
-// FIXME #ifdef _UNICODE
-// typedef CEnumerator CEnumeratorW;
-// #else
-class CEnumeratorW
+#ifdef _WIN32
+class CFindChangeNotification
{
- CFindFile _findFile;
- UString _wildcard;
- bool NextAny(CFileInfoW &fileInfo);
+ HANDLE _handle;
public:
- CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
- CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
- bool Next(CFileInfoW &fileInfo);
- bool Next(CFileInfoW &fileInfo, bool &found);
+ operator HANDLE () { return _handle; }
+ bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
+ CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
+ ~CFindChangeNotification() { Close(); }
+ bool Close();
+ HANDLE FindFirst(CFSTR pathName, bool watchSubtree, DWORD notifyFilter);
+ bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }
};
-// FIXME #endif
+#endif
+
+#ifndef UNDER_CE
+bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings);
+#endif
}}}
#endif
-
diff --git a/src/libs/7zip/unix/CPP/Windows/FileIO.cpp b/src/libs/7zip/unix/CPP/Windows/FileIO.cpp
index 5080579fe..5da074a0f 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileIO.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/FileIO.cpp
@@ -37,10 +37,10 @@ CFileBase::~CFileBase()
}
bool CFileBase::Create(LPCSTR filename, DWORD dwDesiredAccess,
- DWORD /*dwShareMode*/, DWORD dwCreationDisposition, DWORD /*dwFlagsAndAttributes*/,bool ignoreSymbolicLink)
+ DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,bool ignoreSymbolicLink)
{
Close();
-
+
int flags = 0;
const char * name = nameWindowToUnix(filename);
@@ -98,7 +98,7 @@ bool CFileBase::Create(LPCSTR filename, DWORD dwDesiredAccess,
UString ustr = MultiByteToUnicodeString(AString(name), 0);
AString resultString;
int is_good = 1;
- for (int i = 0; i < ustr.Length(); i++)
+ for (int i = 0; i < ustr.Len(); i++)
{
if (ustr[i] >= 256) {
is_good = 0;
@@ -126,7 +126,7 @@ bool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes,bool ignoreSymbolicLink)
{
Close();
- return Create(UnicodeStringToMultiByte(fileName, CP_ACP),
+ return Create(UnicodeStringToMultiByte(fileName, CP_ACP),
desiredAccess, shareMode, creationDisposition, flagsAndAttributes,ignoreSymbolicLink);
}
@@ -180,7 +180,7 @@ bool CFileBase::GetLength(UINT64 &length) const
return false;
}
-#ifdef ENV_HAVE_LSTAT
+#ifdef ENV_HAVE_LSTAT
if (_fd == FD_LINK) {
length = _size;
return true;
@@ -254,24 +254,24 @@ bool CFileBase::Seek(UINT64 position, UINT64 &newPosition)
/////////////////////////
// CInFile
-bool CInFile::Open(LPCTSTR fileName, DWORD shareMode,
+bool CInFile::Open(LPCTSTR fileName, DWORD shareMode,
DWORD creationDisposition, DWORD flagsAndAttributes)
{
- return Create(fileName, GENERIC_READ, shareMode,
+ return Create(fileName, GENERIC_READ, shareMode,
creationDisposition, flagsAndAttributes);
}
bool CInFile::Open(LPCTSTR fileName,bool ignoreSymbolicLink)
{
- return Create(fileName, GENERIC_READ , FILE_SHARE_READ, OPEN_EXISTING,
+ return Create(fileName, GENERIC_READ , FILE_SHARE_READ, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,ignoreSymbolicLink);
}
#ifndef _UNICODE
-bool CInFile::Open(LPCWSTR fileName, DWORD shareMode,
+bool CInFile::Open(LPCWSTR fileName, DWORD shareMode,
DWORD creationDisposition, DWORD flagsAndAttributes)
{
- return Create(fileName, GENERIC_READ, shareMode,
+ return Create(fileName, GENERIC_READ, shareMode,
creationDisposition, flagsAndAttributes);
}
@@ -282,8 +282,8 @@ bool CInFile::Open(LPCWSTR fileName,bool ignoreSymbolicLink)
#endif
// ReadFile and WriteFile functions in Windows have BUG:
-// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
-// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
+// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
+// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
// (Insufficient system resources exist to complete the requested service).
// static UINT32 kChunkSizeMax = (1 << 24);
@@ -339,10 +339,10 @@ bool CInFile::Read(void *buffer, UINT32 bytesToRead, UINT32 &bytesRead)
/////////////////////////
// COutFile
-bool COutFile::Open(LPCTSTR fileName, DWORD shareMode,
+bool COutFile::Open(LPCTSTR fileName, DWORD shareMode,
DWORD creationDisposition, DWORD flagsAndAttributes)
{
- return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
+ return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
creationDisposition, flagsAndAttributes);
}
@@ -351,7 +351,7 @@ static inline DWORD GetCreationDisposition(bool createAlways)
bool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)
{
- return Open(fileName, FILE_SHARE_READ,
+ return Open(fileName, FILE_SHARE_READ,
creationDisposition, FILE_ATTRIBUTE_NORMAL);
}
@@ -360,18 +360,23 @@ bool COutFile::Create(LPCTSTR fileName, bool createAlways)
return Open(fileName, GetCreationDisposition(createAlways));
}
+bool COutFile::CreateAlways(LPCTSTR fileName, DWORD /* flagsAndAttributes */ )
+{
+ return Open(fileName, true); // FIXME
+}
+
#ifndef _UNICODE
-bool COutFile::Open(LPCWSTR fileName, DWORD shareMode,
+bool COutFile::Open(LPCWSTR fileName, DWORD shareMode,
DWORD creationDisposition, DWORD flagsAndAttributes)
{
- return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
+ return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
creationDisposition, flagsAndAttributes);
}
bool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)
{
- return Open(fileName, FILE_SHARE_READ,
+ return Open(fileName, FILE_SHARE_READ,
creationDisposition, FILE_ATTRIBUTE_NORMAL);
}
diff --git a/src/libs/7zip/unix/CPP/Windows/FileIO.h b/src/libs/7zip/unix/CPP/Windows/FileIO.h
index 4aa84c053..a262e5610 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileIO.h
+++ b/src/libs/7zip/unix/CPP/Windows/FileIO.h
@@ -15,12 +15,6 @@
#define FILE_END SEEK_END
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
-#define CREATE_NEW 1
-#define CREATE_ALWAYS 2
-#define OPEN_EXISTING 3
-#define OPEN_ALWAYS 4
-/* #define TRUNCATE_EXISTING 5 */
-
#endif
namespace NWindows {
@@ -83,6 +77,7 @@ public:
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool Open(LPCTSTR fileName, DWORD creationDisposition);
bool Create(LPCTSTR fileName, bool createAlways);
+ bool CreateAlways(LPCTSTR fileName, DWORD flagsAndAttributes);
#ifndef _UNICODE
bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
diff --git a/src/libs/7zip/unix/CPP/Windows/FileName.cpp b/src/libs/7zip/unix/CPP/Windows/FileName.cpp
index 8443a4af9..b726976fe 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileName.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/FileName.cpp
@@ -5,15 +5,25 @@
#include "Windows/FileName.h"
#include "Common/Wildcard.h"
+// FIXME
+namespace NWindows {
+namespace NFile {
+namespace NDir {
+bool MyGetFullPathName(CFSTR path, FString &resFullPath);
+}}}
+
namespace NWindows {
namespace NFile {
namespace NName {
+bool IsAbsolutePath(const wchar_t *s) { return s[0] == WCHAR_PATH_SEPARATOR; } // FIXME
+
+
void NormalizeDirPathPrefix(CSysString &dirPath)
{
if (dirPath.IsEmpty())
return;
- if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)
+ if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Len() - 1)
dirPath += kDirDelimiter;
}
@@ -22,29 +32,16 @@ void NormalizeDirPathPrefix(UString &dirPath)
{
if (dirPath.IsEmpty())
return;
- if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)
- dirPath += wchar_t(kDirDelimiter);
+ if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Len() - 1)
+ dirPath += wchar_t(kDirDelimiter);
}
#endif
-const wchar_t kExtensionDelimiter = L'.';
-
-void SplitNameToPureNameAndExtension(const UString &fullName,
- UString &pureName, UString &extensionDelimiter, UString &extension)
+bool GetFullPath(CFSTR dirPrefix, CFSTR s, FString &res)
{
- int index = fullName.ReverseFind(kExtensionDelimiter);
- if (index < 0)
- {
- pureName = fullName;
- extensionDelimiter.Empty();
- extension.Empty();
- }
- else
- {
- pureName = fullName.Left(index);
- extensionDelimiter = kExtensionDelimiter;
- extension = fullName.Mid(index + 1);
- }
+ res = FString(dirPrefix) + FString(s);
+
+ return true;
}
}}}
diff --git a/src/libs/7zip/unix/CPP/Windows/FileName.h b/src/libs/7zip/unix/CPP/Windows/FileName.h
index d98079026..19c585fc9 100644
--- a/src/libs/7zip/unix/CPP/Windows/FileName.h
+++ b/src/libs/7zip/unix/CPP/Windows/FileName.h
@@ -3,7 +3,7 @@
#ifndef __WINDOWS_FILENAME_H
#define __WINDOWS_FILENAME_H
-#include "../../C/Types.h"
+#include "../../C/7zTypes.h"
#include "../Common/MyString.h"
@@ -19,8 +19,10 @@ void NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with
void NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\'
#endif
-void SplitNameToPureNameAndExtension(const UString &fullName,
- UString &pureName, UString &extensionDelimiter, UString &extension);
+bool IsAbsolutePath(const wchar_t *s);
+
+bool GetFullPath(CFSTR dirPrefix, CFSTR path, FString &fullPath);
+// FIXME bool GetFullPath(CFSTR path, FString &fullPath);
}}}
diff --git a/src/libs/7zip/unix/CPP/Windows/Handle.h b/src/libs/7zip/unix/CPP/Windows/Handle.h
deleted file mode 100644
index 0791b4acd..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Handle.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Windows/Handle.h
-
-#ifndef __WINDOWS_HANDLE_H
-#define __WINDOWS_HANDLE_H
-
-namespace NWindows {
-
-class CHandle
-{
-protected:
- HANDLE _handle;
-public:
- operator HANDLE() { return _handle; }
- CHandle(): _handle(NULL) {}
- ~CHandle() { Close(); }
- bool Close()
- {
- if (_handle == NULL)
- return true;
- if (!::CloseHandle(_handle))
- return false;
- _handle = NULL;
- return true;
- }
- void Attach(HANDLE handle)
- { _handle = handle; }
- HANDLE Detach()
- {
- HANDLE handle = _handle;
- _handle = NULL;
- return handle;
- }
-};
-
-}
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/NtCheck.h b/src/libs/7zip/unix/CPP/Windows/NtCheck.h
deleted file mode 100644
index e56318f00..000000000
--- a/src/libs/7zip/unix/CPP/Windows/NtCheck.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Windows/NtCheck.h
-
-#ifndef __WINDOWS_NT_CHECK_H
-#define __WINDOWS_NT_CHECK_H
-
-#ifdef _WIN32
-
-#if !defined(_WIN64) && !defined(UNDER_CE)
-static inline bool IsItWindowsNT()
-{
- OSVERSIONINFO vi;
- vi.dwOSVersionInfoSize = sizeof(vi);
- return (::GetVersionEx(&vi) && vi.dwPlatformId == VER_PLATFORM_WIN32_NT);
-}
-#endif
-
-#ifndef _UNICODE
- #if defined(_WIN64) || defined(UNDER_CE)
- bool g_IsNT = true;
- #define SET_IS_NT
- #else
- bool g_IsNT = false;
- #define SET_IS_NT g_IsNT = IsItWindowsNT();
- #endif
- #define NT_CHECK_ACTION
- // #define NT_CHECK_ACTION { NT_CHECK_FAIL_ACTION }
-#else
- #if !defined(_WIN64) && !defined(UNDER_CE)
- #define NT_CHECK_ACTION if (!IsItWindowsNT()) { NT_CHECK_FAIL_ACTION }
- #else
- #define NT_CHECK_ACTION
- #endif
- #define SET_IS_NT
-#endif
-
-#define NT_CHECK NT_CHECK_ACTION SET_IS_NT
-
-#else
-
-#define NT_CHECK
-
-#endif
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariant.cpp b/src/libs/7zip/unix/CPP/Windows/PropVariant.cpp
index 90212e08f..d16f576cc 100644
--- a/src/libs/7zip/unix/CPP/Windows/PropVariant.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/PropVariant.cpp
@@ -2,13 +2,43 @@
#include "StdAfx.h"
-#include "PropVariant.h"
-
#include "../Common/Defs.h"
+#include "PropVariant.h"
+
namespace NWindows {
namespace NCOM {
+HRESULT PropVarEm_Alloc_Bstr(PROPVARIANT *p, unsigned numChars) throw()
+{
+ p->bstrVal = ::SysAllocStringLen(0, numChars);
+ if (!p->bstrVal)
+ {
+ p->vt = VT_ERROR;
+ p->scode = E_OUTOFMEMORY;
+ return E_OUTOFMEMORY;
+ }
+ p->vt = VT_BSTR;
+ return S_OK;
+}
+
+HRESULT PropVarEm_Set_Str(PROPVARIANT *p, const char *s) throw()
+{
+ UINT len = (UINT)strlen(s);
+ p->bstrVal = ::SysAllocStringLen(0, len);
+ if (!p->bstrVal)
+ {
+ p->vt = VT_ERROR;
+ p->scode = E_OUTOFMEMORY;
+ return E_OUTOFMEMORY;
+ }
+ p->vt = VT_BSTR;
+ BSTR dest = p->bstrVal;
+ for (UINT i = 0; i <= len; i++)
+ dest[i] = s[i];
+ return S_OK;
+}
+
CPropVariant::CPropVariant(const PROPVARIANT &varSrc)
{
vt = VT_EMPTY;
@@ -58,7 +88,7 @@ CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
vt = VT_BSTR;
wReserved1 = 0;
bstrVal = ::SysAllocString(lpszSrc);
- if (bstrVal == NULL && lpszSrc != NULL)
+ if (!bstrVal && lpszSrc)
{
throw kMemException;
// vt = VT_ERROR;
@@ -67,15 +97,14 @@ CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
return *this;
}
-
CPropVariant& CPropVariant::operator=(const char *s)
{
InternalClear();
vt = VT_BSTR;
wReserved1 = 0;
UINT len = (UINT)strlen(s);
- bstrVal = ::SysAllocStringByteLen(0, (UINT)len * sizeof(OLECHAR));
- if (bstrVal == NULL)
+ bstrVal = ::SysAllocStringLen(0, len);
+ if (!bstrVal)
{
throw kMemException;
// vt = VT_ERROR;
@@ -89,7 +118,7 @@ CPropVariant& CPropVariant::operator=(const char *s)
return *this;
}
-CPropVariant& CPropVariant::operator=(bool bSrc)
+CPropVariant& CPropVariant::operator=(bool bSrc) throw()
{
if (vt != VT_BOOL)
{
@@ -100,22 +129,40 @@ CPropVariant& CPropVariant::operator=(bool bSrc)
return *this;
}
+BSTR CPropVariant::AllocBstr(unsigned numChars)
+{
+ if (vt != VT_EMPTY)
+ InternalClear();
+ vt = VT_BSTR;
+ wReserved1 = 0;
+ bstrVal = ::SysAllocStringLen(0, numChars);
+ if (!bstrVal)
+ {
+ throw kMemException;
+ // vt = VT_ERROR;
+ // scode = E_OUTOFMEMORY;
+ }
+ return bstrVal;
+}
+
#define SET_PROP_FUNC(type, id, dest) \
- CPropVariant& CPropVariant::operator=(type value) \
+ CPropVariant& CPropVariant::operator=(type value) throw() \
{ if (vt != id) { InternalClear(); vt = id; } \
dest = value; return *this; }
SET_PROP_FUNC(Byte, VT_UI1, bVal)
-SET_PROP_FUNC(Int16, VT_I2, iVal)
+// SET_PROP_FUNC(Int16, VT_I2, iVal)
SET_PROP_FUNC(Int32, VT_I4, lVal)
SET_PROP_FUNC(UInt32, VT_UI4, ulVal)
SET_PROP_FUNC(UInt64, VT_UI8, uhVal.QuadPart)
+SET_PROP_FUNC(Int64, VT_I8, hVal.QuadPart)
SET_PROP_FUNC(const FILETIME &, VT_FILETIME, filetime)
-static HRESULT MyPropVariantClear(PROPVARIANT *prop)
+HRESULT PropVariant_Clear(PROPVARIANT *prop) throw()
{
- switch(prop->vt)
+ switch (prop->vt)
{
+ case VT_EMPTY:
case VT_UI1:
case VT_I1:
case VT_I2:
@@ -134,17 +181,24 @@ static HRESULT MyPropVariantClear(PROPVARIANT *prop)
case VT_DATE:
prop->vt = VT_EMPTY;
prop->wReserved1 = 0;
+ prop->wReserved2 = 0;
+ prop->wReserved3 = 0;
+ prop->uhVal.QuadPart = 0;
return S_OK;
}
return ::VariantClear((VARIANTARG *)prop);
+ // return ::PropVariantClear(prop);
+ // PropVariantClear can clear VT_BLOB.
}
-HRESULT CPropVariant::Clear()
+HRESULT CPropVariant::Clear() throw()
{
- return MyPropVariantClear(this);
+ if (vt == VT_EMPTY)
+ return S_OK;
+ return PropVariant_Clear(this);
}
-HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)
+HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) throw()
{
::VariantClear((tagVARIANT *)this);
switch(pSrc->vt)
@@ -172,7 +226,7 @@ HRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)
}
-HRESULT CPropVariant::Attach(PROPVARIANT *pSrc)
+HRESULT CPropVariant::Attach(PROPVARIANT *pSrc) throw()
{
HRESULT hr = Clear();
if (FAILED(hr))
@@ -182,18 +236,23 @@ HRESULT CPropVariant::Attach(PROPVARIANT *pSrc)
return S_OK;
}
-HRESULT CPropVariant::Detach(PROPVARIANT *pDest)
+HRESULT CPropVariant::Detach(PROPVARIANT *pDest) throw()
{
- HRESULT hr = MyPropVariantClear(pDest);
- if (FAILED(hr))
- return hr;
+ if (pDest->vt != VT_EMPTY)
+ {
+ HRESULT hr = PropVariant_Clear(pDest);
+ if (FAILED(hr))
+ return hr;
+ }
memcpy(pDest, this, sizeof(PROPVARIANT));
vt = VT_EMPTY;
return S_OK;
}
-HRESULT CPropVariant::InternalClear()
+HRESULT CPropVariant::InternalClear() throw()
{
+ if (vt == VT_EMPTY)
+ return S_OK;
HRESULT hr = Clear();
if (FAILED(hr))
{
@@ -215,7 +274,7 @@ void CPropVariant::InternalCopy(const PROPVARIANT *pSrc)
}
}
-int CPropVariant::Compare(const CPropVariant &a)
+int CPropVariant::Compare(const CPropVariant &a) throw()
{
if (vt != a.vt)
return MyCompare(vt, a.vt);
@@ -233,9 +292,7 @@ int CPropVariant::Compare(const CPropVariant &a)
case VT_UI8: return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);
case VT_BOOL: return -MyCompare(boolVal, a.boolVal);
case VT_FILETIME: return ::CompareFileTime(&filetime, &a.filetime);
- case VT_BSTR:
- return 0; // Not implemented
- // return MyCompare(aPropVarint.cVal);
+ case VT_BSTR: return 0; // Not implemented
default: return 0;
}
}
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariant.h b/src/libs/7zip/unix/CPP/Windows/PropVariant.h
index d018034eb..d71b85e1d 100644
--- a/src/libs/7zip/unix/CPP/Windows/PropVariant.h
+++ b/src/libs/7zip/unix/CPP/Windows/PropVariant.h
@@ -1,29 +1,73 @@
// Windows/PropVariant.h
-#ifndef __WINDOWS_PROPVARIANT_H
-#define __WINDOWS_PROPVARIANT_H
+#ifndef __WINDOWS_PROP_VARIANT_H
+#define __WINDOWS_PROP_VARIANT_H
+#include "../Common/MyTypes.h"
#include "../Common/MyWindows.h"
-#include "../Common/Types.h"
namespace NWindows {
namespace NCOM {
+HRESULT PropVariant_Clear(PROPVARIANT *p) throw();
+
+HRESULT PropVarEm_Alloc_Bstr(PROPVARIANT *p, unsigned numChars) throw();
+HRESULT PropVarEm_Set_Str(PROPVARIANT *p, const char *s) throw();
+
+inline void PropVarEm_Set_UInt32(PROPVARIANT *p, UInt32 v) throw()
+{
+ p->vt = VT_UI4;
+ p->ulVal = v;
+}
+
+inline void PropVarEm_Set_UInt64(PROPVARIANT *p, UInt64 v) throw()
+{
+ p->vt = VT_UI8;
+ p->uhVal.QuadPart = v;
+}
+
+inline void PropVarEm_Set_FileTime64(PROPVARIANT *p, UInt64 v) throw()
+{
+ p->vt = VT_FILETIME;
+ p->filetime.dwLowDateTime = (DWORD)v;
+ p->filetime.dwHighDateTime = (DWORD)(v >> 32);
+}
+
+inline void PropVarEm_Set_Bool(PROPVARIANT *p, bool b) throw()
+{
+ p->vt = VT_BOOL;
+ p->boolVal = (b ? VARIANT_TRUE : VARIANT_FALSE);
+}
+
+
class CPropVariant : public tagPROPVARIANT
{
public:
- CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }
- ~CPropVariant() { Clear(); }
+ CPropVariant()
+ {
+ vt = VT_EMPTY;
+ wReserved1 = 0;
+ // wReserved2 = 0;
+ // wReserved3 = 0;
+ // uhVal.QuadPart = 0;
+ bstrVal = 0;
+ }
+ ~CPropVariant() throw() { Clear(); }
CPropVariant(const PROPVARIANT &varSrc);
CPropVariant(const CPropVariant &varSrc);
CPropVariant(BSTR bstrSrc);
CPropVariant(LPCOLESTR lpszSrc);
CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };
CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }
- CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }
- CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }
+
+private:
+ CPropVariant(Int16 value); // { vt = VT_I2; wReserved1 = 0; iVal = value; }
+ CPropVariant(Int32 value); // { vt = VT_I4; wReserved1 = 0; lVal = value; }
+
+public:
CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }
CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal.QuadPart = value; }
+ CPropVariant(Int64 value) { vt = VT_I8; wReserved1 = 0; hVal.QuadPart = value; }
CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }
CPropVariant& operator=(const CPropVariant &varSrc);
@@ -31,24 +75,31 @@ public:
CPropVariant& operator=(BSTR bstrSrc);
CPropVariant& operator=(LPCOLESTR lpszSrc);
CPropVariant& operator=(const char *s);
- CPropVariant& operator=(bool bSrc);
- CPropVariant& operator=(Byte value);
- CPropVariant& operator=(Int16 value);
- CPropVariant& operator=(Int32 value);
- CPropVariant& operator=(UInt32 value);
- CPropVariant& operator=(Int64 value);
- CPropVariant& operator=(UInt64 value);
- CPropVariant& operator=(const FILETIME &value);
-
- HRESULT Clear();
- HRESULT Copy(const PROPVARIANT *pSrc);
- HRESULT Attach(PROPVARIANT *pSrc);
- HRESULT Detach(PROPVARIANT *pDest);
-
- HRESULT InternalClear();
+
+ CPropVariant& operator=(bool bSrc) throw();
+ CPropVariant& operator=(Byte value) throw();
+
+private:
+ CPropVariant& operator=(Int16 value) throw();
+
+public:
+ CPropVariant& operator=(Int32 value) throw();
+ CPropVariant& operator=(UInt32 value) throw();
+ CPropVariant& operator=(UInt64 value) throw();
+ CPropVariant& operator=(Int64 value) throw();
+ CPropVariant& operator=(const FILETIME &value) throw();
+
+ BSTR AllocBstr(unsigned numChars);
+
+ HRESULT Clear() throw();
+ HRESULT Copy(const PROPVARIANT *pSrc) throw();
+ HRESULT Attach(PROPVARIANT *pSrc) throw();
+ HRESULT Detach(PROPVARIANT *pDest) throw();
+
+ HRESULT InternalClear() throw();
void InternalCopy(const PROPVARIANT *pSrc);
- int Compare(const CPropVariant &a1);
+ int Compare(const CPropVariant &a) throw();
};
}}
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariantConv.cpp b/src/libs/7zip/unix/CPP/Windows/PropVariantConv.cpp
new file mode 100644
index 000000000..dfb93d6d6
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/Windows/PropVariantConv.cpp
@@ -0,0 +1,99 @@
+// PropVariantConvert.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/IntToString.h"
+
+#include "Defs.h"
+#include "PropVariantConv.h"
+
+#define UINT_TO_STR_2(c, val) { s[0] = (c); s[1] = (char)('0' + (val) / 10); s[2] = (char)('0' + (val) % 10); s += 3; }
+
+bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) throw()
+{
+ SYSTEMTIME st;
+ if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
+ {
+ *s = 0;
+ return false;
+ }
+ unsigned val = st.wYear;
+ if (val >= 10000)
+ {
+ *s++ = (char)('0' + val / 10000);
+ val %= 10000;
+ }
+ {
+ s[3] = (char)('0' + val % 10); val /= 10;
+ s[2] = (char)('0' + val % 10); val /= 10;
+ s[1] = (char)('0' + val % 10);
+ s[0] = (char)('0' + val / 10);
+ s += 4;
+ }
+ UINT_TO_STR_2('-', st.wMonth);
+ UINT_TO_STR_2('-', st.wDay);
+ if (includeTime)
+ {
+ UINT_TO_STR_2(' ', st.wHour);
+ UINT_TO_STR_2(':', st.wMinute);
+ if (includeSeconds)
+ UINT_TO_STR_2(':', st.wSecond);
+ }
+ *s = 0;
+ return true;
+}
+
+void ConvertFileTimeToString(const FILETIME &ft, wchar_t *dest, bool includeTime, bool includeSeconds) throw()
+{
+ char s[32];
+ ConvertFileTimeToString(ft, s, includeTime, includeSeconds);
+ for (unsigned i = 0;; i++)
+ {
+ unsigned char c = s[i];
+ dest[i] = c;
+ if (c == 0)
+ return;
+ }
+}
+
+void ConvertPropVariantToShortString(const PROPVARIANT &prop, char *dest) throw()
+{
+ *dest = 0;
+ switch (prop.vt)
+ {
+ case VT_EMPTY: return;
+ case VT_BSTR: dest[0] = '?'; dest[1] = 0; return;
+ case VT_UI1: ConvertUInt32ToString(prop.bVal, dest); return;
+ case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
+ case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
+ case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
+ case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
+ // case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
+ case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
+ case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
+ case VT_I8: ConvertInt64ToString(prop.hVal.QuadPart, dest); return;
+ case VT_BOOL: dest[0] = VARIANT_BOOLToBool(prop.boolVal) ? '+' : '-'; dest[1] = 0; return;
+ default: dest[0] = '?'; dest[1] = ':'; ConvertUInt64ToString(prop.vt, dest + 2);
+ }
+}
+
+void ConvertPropVariantToShortString(const PROPVARIANT &prop, wchar_t *dest) throw()
+{
+ *dest = 0;
+ switch (prop.vt)
+ {
+ case VT_EMPTY: return;
+ case VT_BSTR: dest[0] = '?'; dest[1] = 0; return;
+ case VT_UI1: ConvertUInt32ToString(prop.bVal, dest); return;
+ case VT_UI2: ConvertUInt32ToString(prop.uiVal, dest); return;
+ case VT_UI4: ConvertUInt32ToString(prop.ulVal, dest); return;
+ case VT_UI8: ConvertUInt64ToString(prop.uhVal.QuadPart, dest); return;
+ case VT_FILETIME: ConvertFileTimeToString(prop.filetime, dest, true, true); return;
+ // case VT_I1: return ConvertInt64ToString(prop.cVal, dest); return;
+ case VT_I2: ConvertInt64ToString(prop.iVal, dest); return;
+ case VT_I4: ConvertInt64ToString(prop.lVal, dest); return;
+ case VT_I8: ConvertInt64ToString(prop.hVal.QuadPart, dest); return;
+ case VT_BOOL: dest[0] = VARIANT_BOOLToBool(prop.boolVal) ? '+' : '-'; dest[1] = 0; return;
+ default: dest[0] = '?'; dest[1] = ':'; ConvertUInt32ToString(prop.vt, dest + 2);
+ }
+}
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariantConv.h b/src/libs/7zip/unix/CPP/Windows/PropVariantConv.h
new file mode 100644
index 000000000..5d26357f0
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/Windows/PropVariantConv.h
@@ -0,0 +1,30 @@
+// Windows/PropVariantConv.h
+
+#ifndef __PROP_VARIANT_CONV_H
+#define __PROP_VARIANT_CONV_H
+
+#include "../Common/MyTypes.h"
+
+// provide at least 32 bytes for buffer including zero-end
+bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true) throw();
+void ConvertFileTimeToString(const FILETIME &ft, wchar_t *s, bool includeTime = true, bool includeSeconds = true) throw();
+
+// provide at least 32 bytes for buffer including zero-end
+// don't send VT_BSTR to these functions
+void ConvertPropVariantToShortString(const PROPVARIANT &prop, char *dest) throw();
+void ConvertPropVariantToShortString(const PROPVARIANT &prop, wchar_t *dest) throw();
+
+inline bool ConvertPropVariantToUInt64(const PROPVARIANT &prop, UInt64 &value)
+{
+ switch (prop.vt)
+ {
+ case VT_UI8: value = (UInt64)prop.uhVal.QuadPart; return true;
+ case VT_UI4: value = prop.ulVal; return true;
+ case VT_UI2: value = prop.uiVal; return true;
+ case VT_UI1: value = prop.bVal; return true;
+ case VT_EMPTY: return false;
+ default: throw 151199;
+ }
+}
+
+#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.cpp b/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.cpp
deleted file mode 100644
index abd5b46c4..000000000
--- a/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-// PropVariantConversions.cpp
-
-#include "StdAfx.h"
-
-#include "Common/IntToString.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/Defs.h"
-
-#include "PropVariantConversions.h"
-
-static UString ConvertUInt64ToString(UInt64 value)
-{
- wchar_t buffer[32];
- ConvertUInt64ToString(value, buffer);
- return buffer;
-}
-
-static UString ConvertInt64ToString(Int64 value)
-{
- wchar_t buffer[32];
- ConvertInt64ToString(value, buffer);
- return buffer;
-}
-
-#ifdef _WIN32
-static char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)
-{
- if (c != 0)
- *s++ = c;
- char temp[16];
- int pos = 0;
- do
- {
- temp[pos++] = (char)('0' + value % 10);
- value /= 10;
- }
- while (value != 0);
- int i;
- for (i = 0; i < numPos - pos; i++)
- *s++ = '0';
- do
- *s++ = temp[--pos];
- while (pos > 0);
- *s = '\0';
- return s;
-}
-#endif
-
-bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)
-{
-#ifdef _WIN32
- s[0] = '\0';
- SYSTEMTIME st;
- if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
- return false;
- s = UIntToStringSpec(0, st.wYear, s, 4);
- s = UIntToStringSpec('-', st.wMonth, s, 2);
- s = UIntToStringSpec('-', st.wDay, s, 2);
- if (includeTime)
- {
- s = UIntToStringSpec(' ', st.wHour, s, 2);
- s = UIntToStringSpec(':', st.wMinute, s, 2);
- if (includeSeconds)
- UIntToStringSpec(':', st.wSecond, s, 2);
- }
- /*
- sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
- if (includeTime)
- {
- sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute);
- if (includeSeconds)
- sprintf(s + strlen(s), ":%02d", st.wSecond);
- }
- */
-#else
- BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds );
-
- LARGE_INTEGER ltime;
-
- ltime.QuadPart = ft.dwHighDateTime;
- ltime.QuadPart = (ltime.QuadPart << 32) | ft.dwLowDateTime;
-
- DWORD dw;
- RtlTimeToSecondsSince1970(&ltime, &dw );
- time_t timep = (time_t)dw;
-
- struct tm * date = localtime(&timep);
-
- sprintf(s, "%04d-%02d-%02d", date->tm_year+1900, date->tm_mon+1,date->tm_mday);
- if (includeTime)
- {
- sprintf(s + strlen(s), " %02d:%02d", date->tm_hour,date->tm_min);
- if (includeSeconds)
- sprintf(s + strlen(s), ":%02d", date->tm_sec);
- }
-#endif
- return true;
-}
-
-UString ConvertFileTimeToString(const FILETIME &ft, bool includeTime, bool includeSeconds)
-{
- char s[32];
- ConvertFileTimeToString(ft, s, includeTime, includeSeconds);
- return GetUnicodeString(s);
-}
-
-
-UString ConvertPropVariantToString(const PROPVARIANT &prop)
-{
- switch (prop.vt)
- {
- case VT_EMPTY: return UString();
- case VT_BSTR: return prop.bstrVal;
- case VT_UI1: return ConvertUInt64ToString(prop.bVal);
- case VT_UI2: return ConvertUInt64ToString(prop.uiVal);
- case VT_UI4: return ConvertUInt64ToString(prop.ulVal);
- case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);
- case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);
- // case VT_I1: return ConvertInt64ToString(prop.cVal);
- case VT_I2: return ConvertInt64ToString(prop.iVal);
- case VT_I4: return ConvertInt64ToString(prop.lVal);
- case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);
- case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L"+" : L"-";
- default: throw 150245;
- }
-}
-
-UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)
-{
- switch (prop.vt)
- {
- case VT_UI1: return prop.bVal;
- case VT_UI2: return prop.uiVal;
- case VT_UI4: return prop.ulVal;
- case VT_UI8: return (UInt64)prop.uhVal.QuadPart;
- default: throw 151199;
- }
-}
diff --git a/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.h b/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.h
deleted file mode 100644
index 3de4dedb3..000000000
--- a/src/libs/7zip/unix/CPP/Windows/PropVariantConversions.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Windows/PropVariantConversions.h
-
-#ifndef __PROP_VARIANT_CONVERSIONS_H
-#define __PROP_VARIANT_CONVERSIONS_H
-
-#include "Common/MyString.h"
-#include "Common/Types.h"
-
-bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);
-UString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);
-UString ConvertPropVariantToString(const PROPVARIANT &prop);
-UInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop);
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/Registry.cpp b/src/libs/7zip/unix/CPP/Windows/Registry.cpp
deleted file mode 100644
index 74e255df4..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Registry.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-// Windows/Registry.cpp
-
-#include "StdAfx.h"
-
-#ifndef _UNICODE
-#include "Common/StringConvert.h"
-#endif
-#include "Windows/Registry.h"
-
-#include <wx/config.h>
-
-class HKEY_Impl
-{
- public:
- wxString path;
- HKEY_Impl(wxString a) : path(a) {}
-};
-
-namespace NWindows {
-namespace NRegistry {
-
-#define ERROR_SET_VALUE (E_INVALIDARG) // FIXME
-#define ERROR_GET_VALUE (E_INVALIDARG) // FIXME
-#define PROGRAM_NAME L"p7zip"
-
-static wxConfig * g_config = 0;
-static int g_config_ref = 0;
-
-static void configAddRef() {
- if (g_config == 0) {
- g_config = new wxConfig(PROGRAM_NAME);
- g_config->Flush(true);
- wxConfigBase::Set(g_config);
- }
- g_config_ref++;
-}
-
-static void configSubRef() {
- if (g_config_ref >= 1)
- {
- g_config_ref--;
- if (g_config_ref == 0) {
- delete g_config;
- g_config = 0;
- wxConfigBase::Set(NULL);
- } else {
- g_config->Flush(true);
- }
- }
-}
-
- LONG CKey::Close()
- {
- if (_object)
- {
- configSubRef();
- delete _object;
- }
- _object = 0;
- return ERROR_SUCCESS;
- }
-
- LONG CKey::Create(HKEY parentKey, LPCTSTR keyName)
- {
- Close();
-
- configAddRef();
-
- wxString path;
-
- if (parentKey == HKEY_CURRENT_USER) {
- path=L"/" + wxString(keyName);
- } else {
- path = parentKey->path + L"/" + wxString(keyName);
- }
- _object = new HKEY_Impl(path);
- return ERROR_SUCCESS;
- }
- LONG CKey::Open(HKEY parentKey, LPCTSTR keyName, REGSAM accessMask)
- {
- Close();
-
- configAddRef();
-
- wxString path;
-
- if (parentKey == HKEY_CURRENT_USER) {
- path=L"/" + wxString(keyName);
- } else {
- path = parentKey->path + L"/" + wxString(keyName);
- }
- _object = new HKEY_Impl(path);
- return ERROR_SUCCESS;
- }
-
- LONG CKey::RecurseDeleteKey(LPCTSTR subKeyName)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->DeleteGroup(subKeyName);
- if (ret) return ERROR_SUCCESS;
- return ERROR_GET_VALUE;
- }
-
- LONG CKey::DeleteValue(LPCTSTR name)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->DeleteEntry(name);
- if (ret) return ERROR_SUCCESS;
- return ERROR_GET_VALUE;
- }
-
- LONG CKey::QueryValue(LPCTSTR name, UInt32 &value)
- {
- g_config->SetPath(_object->path);
- long val;
- bool ret = g_config->Read(name,&val);
- if (ret) {
- value = (UInt32)val;
- return ERROR_SUCCESS;
- }
- return ERROR_GET_VALUE;
- }
-
- LONG CKey::QueryValue(LPCTSTR name, bool &value)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->Read(name,&value);
- if (ret) return ERROR_SUCCESS;
- return ERROR_GET_VALUE;
- }
-
- LONG CKey::QueryValue(LPCTSTR name, CSysString &value)
- {
- g_config->SetPath(_object->path);
- wxString val;
- bool ret = g_config->Read(name,&val);
- if (ret) {
- value = val;
- return ERROR_SUCCESS;
- }
- return ERROR_GET_VALUE;
- }
-
-LONG CKey::GetValue_IfOk(LPCTSTR name, UInt32 &value)
-{
- UInt32 newVal;
- LONG res = QueryValue(name, newVal);
- if (res == ERROR_SUCCESS)
- value = newVal;
- return res;
-}
-
-LONG CKey::GetValue_IfOk(LPCTSTR name, bool &value)
-{
- bool newVal;
- LONG res = QueryValue(name, newVal);
- if (res == ERROR_SUCCESS)
- value = newVal;
- return res;
-}
-
-
- LONG CKey::SetValue(LPCTSTR valueName, UInt32 value)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->Write(valueName,(long)value);
- if (ret == true) return ERROR_SUCCESS;
- return ERROR_SET_VALUE;
- }
- LONG CKey::SetValue(LPCTSTR valueName, bool value)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->Write(valueName,value);
- if (ret == true) return ERROR_SUCCESS;
- return ERROR_SET_VALUE;
- }
- LONG CKey::SetValue(LPCTSTR valueName, LPCTSTR value)
- {
- g_config->SetPath(_object->path);
- bool ret = g_config->Write(valueName,value);
- if (ret == true) return ERROR_SUCCESS;
- return ERROR_SET_VALUE;
- }
-
- LONG CKey::SetValue(LPCTSTR name, const void *value, UInt32 size)
- {
- static char hexa[] = "0123456789ABCDEF";
- /* FIXME
- MYASSERT(value != NULL);
- MYASSERT(_object != NULL);
- return RegSetValueEx(_object, name, NULL, REG_BINARY, (const BYTE *)value, size);
- */
- BYTE *buf = (BYTE *)value;
- wxString str;
- for(UInt32 i=0;i<size;i++)
- {
- str += hexa[ (buf[i]>>4) & 0x0f];
- str += hexa[ buf[i] & 0x0f];
- }
- return SetValue(name,(LPCTSTR)str);
- }
-
- LONG CKey::EnumKeys(CSysStringVector &keyNames)
- {
- g_config->SetPath(_object->path);
- keyNames.Clear();
- // enumeration variables
- wxString str;
- long dummy;
- bool bCont = g_config->GetFirstEntry(str, dummy);
- while ( bCont ) {
- keyNames.Add((const TCHAR *)str);
- bCont = g_config->GetNextEntry(str, dummy);
- }
-
- // now all groups...
- bCont = g_config->GetFirstGroup(str, dummy);
- while ( bCont ) {
- keyNames.Add((const TCHAR *)str);
- bCont = g_config->GetNextGroup(str, dummy);
- }
- return ERROR_SUCCESS;
- }
-
- LONG CKey::QueryValue(LPCTSTR name, void *value, UInt32 &dataSize)
- {
- g_config->SetPath(_object->path);
- wxString str;
- bool ret = g_config->Read(name,&str);
- if (ret == false) return ERROR_GET_VALUE;
-
- size_t l = str.Len() / 2;
- if (l > dataSize) l = dataSize;
- else dataSize=l;
-
- BYTE *buf = (BYTE *)value;
- for(UInt32 i=0;i<dataSize;i++)
- {
- char cval[3];
- cval[0] = (char)str[2*i];
- cval[1] = (char)str[2*i+1];
- cval[2] = 0;
- unsigned uval = 0;
- sscanf(cval,"%x",&uval);
- buf[i]=(BYTE)uval;
- }
-
- return ERROR_SUCCESS;
- }
-
-
- LONG CKey::QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize)
- {
- g_config->SetPath(_object->path);
- wxString str;
- bool ret = g_config->Read(name,&str);
- if (ret == false) return ERROR_GET_VALUE;
-
- dataSize = str.Len() / 2;
- value.SetCapacity(dataSize);
- return QueryValue(name, (BYTE *)value, dataSize);
- }
-
-
-LONG CKey::SetValue_Strings(LPCTSTR valueName, const UStringVector &strings)
-{
- UInt32 numChars = 0;
- int i;
- for (i = 0; i < strings.Size(); i++)
- numChars += strings[i].Length() + 1;
- CBuffer<wchar_t> buffer;
- buffer.SetCapacity(numChars);
- int pos = 0;
- for (i = 0; i < strings.Size(); i++)
- {
- const UString &s = strings[i];
- MyStringCopy((wchar_t *)buffer + pos, (const wchar_t *)s);
- pos += s.Length() + 1;
- }
- return SetValue(valueName, buffer, numChars * sizeof(wchar_t));
-}
-
-LONG CKey::GetValue_Strings(LPCTSTR valueName, UStringVector &strings)
-{
- strings.Clear();
- CByteBuffer buffer;
- UInt32 dataSize;
- LONG res = QueryValue(valueName, buffer, dataSize);
- if (res != ERROR_SUCCESS)
- return res;
- if (dataSize % sizeof(wchar_t) != 0)
- return E_FAIL;
- const wchar_t *data = (const wchar_t *)(const Byte *)buffer;
- int numChars = dataSize / sizeof(wchar_t);
- UString s;
- for (int i = 0; i < numChars; i++)
- {
- wchar_t c = data[i];
- if (c == 0)
- {
- strings.Add(s);
- s.Empty();
- }
- else
- s += c;
- }
- return res;
-}
-
-
-}
-}
-
diff --git a/src/libs/7zip/unix/CPP/Windows/Registry.h b/src/libs/7zip/unix/CPP/Windows/Registry.h
deleted file mode 100644
index a9078751f..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Registry.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Windows/Registry.h
-
-#ifndef __WINDOWS_REGISTRY_H
-#define __WINDOWS_REGISTRY_H
-
-#include "Common/Buffer.h"
-#include "Common/MyString.h"
-#include "Common/Types.h"
-
-#ifndef _WIN32
-class HKEY_Impl;
-
-typedef HKEY_Impl * HKEY;
-
-/*
-#define HKEY_CLASSES_ROOT ((HKEY) 0x80000000)
-#define HKEY_LOCAL_MACHINE ((HKEY) 0x80000002)
-#define HKEY_USERS ((HKEY) 0x80000003)
-#define HKEY_PERFORMANCE_DATA ((HKEY) 0x80000004)
-#define HKEY_CURRENT_CONFIG ((HKEY) 0x80000005)
-#define HKEY_DYN_DATA ((HKEY) 0x80000006)
-*/
-#define HKEY_CURRENT_USER ((HKEY) 0x80000001)
-
-
-typedef DWORD REGSAM;
-#define ERROR_SUCCESS (0)
-#define KEY_READ (0x1234) // FIXME
-#define KEY_ALL_ACCESS (~0) // FIXME
-
-/* ------------------------------ end registry ------------------------------ */
-
-#endif
-
-namespace NWindows {
-namespace NRegistry {
-
-const TCHAR kKeyNameDelimiter = TEXT(CHAR_PATH_SEPARATOR);
-
-// LONG SetValue(HKEY parentKey, LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value);
-
-class CKey
-{
- HKEY _object;
-public:
- CKey(): _object(NULL) {}
- ~CKey() { Close(); }
-
- operator HKEY() const { return _object; }
-
- #if 0
- HKEY Detach();
- void Attach(HKEY key);
- LONG Create(HKEY parentKey, LPCTSTR keyName,
- LPTSTR keyClass = REG_NONE, DWORD options = REG_OPTION_NON_VOLATILE,
- REGSAM accessMask = KEY_ALL_ACCESS,
- LPSECURITY_ATTRIBUTES securityAttributes = NULL,
- LPDWORD disposition = NULL);
- LONG Open(HKEY parentKey, LPCTSTR keyName,
- REGSAM accessMask = KEY_ALL_ACCESS);
-#endif // #if 0
- LONG Create(HKEY parentKey, LPCTSTR keyName);
- LONG Open(HKEY parentKey, LPCTSTR keyName,
- REGSAM accessMask = KEY_ALL_ACCESS);
-
- LONG Close();
-
- LONG DeleteSubKey(LPCTSTR subKeyName);
- LONG RecurseDeleteKey(LPCTSTR subKeyName);
-
- LONG DeleteValue(LPCTSTR name);
- #ifndef _UNICODE
- LONG DeleteValue(LPCWSTR name);
- #endif
-
- LONG SetValue(LPCTSTR valueName, UInt32 value);
- LONG SetValue(LPCTSTR valueName, bool value);
- LONG SetValue(LPCTSTR valueName, LPCTSTR value);
- // LONG SetValue(LPCTSTR valueName, const CSysString &value);
- #ifndef _UNICODE
- LONG SetValue(LPCWSTR name, LPCWSTR value);
- // LONG SetValue(LPCWSTR name, const UString &value);
- #endif
-
- LONG SetValue(LPCTSTR name, const void *value, UInt32 size);
-
- LONG SetValue_Strings(LPCTSTR valueName, const UStringVector &strings);
- LONG GetValue_Strings(LPCTSTR valueName, UStringVector &strings);
-
- LONG SetKeyValue(LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value);
-
- LONG QueryValue(LPCTSTR name, UInt32 &value);
- LONG QueryValue(LPCTSTR name, bool &value);
- LONG QueryValue(LPCTSTR name, LPTSTR value, UInt32 &dataSize);
- LONG QueryValue(LPCTSTR name, CSysString &value);
-
- LONG GetValue_IfOk(LPCTSTR name, UInt32 &value);
- LONG GetValue_IfOk(LPCTSTR name, bool &value);
-
- #ifndef _UNICODE
- LONG QueryValue(LPCWSTR name, LPWSTR value, UInt32 &dataSize);
- LONG QueryValue(LPCWSTR name, UString &value);
- #endif
-
- LONG QueryValue(LPCTSTR name, void *value, UInt32 &dataSize);
- LONG QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize);
-
- LONG EnumKeys(CSysStringVector &keyNames);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/Synchronization.cpp b/src/libs/7zip/unix/CPP/Windows/Synchronization.cpp
index 8130f9ac3..4be33e1e9 100644
--- a/src/libs/7zip/unix/CPP/Windows/Synchronization.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/Synchronization.cpp
@@ -73,7 +73,7 @@ namespace NSynchronization {
}
_isValid = false;
}
- void CSynchro::Enter() {
+ void CSynchro::Enter() {
TRACEN((printf("\nT%d : E1-CSynchro::Enter(%p)\n",(int)pthread_self(),(void *)&_object)))
int ret = ::pthread_mutex_lock(&_object);
if (ret != 0) {
diff --git a/src/libs/7zip/unix/CPP/Windows/Synchronization.h b/src/libs/7zip/unix/CPP/Windows/Synchronization.h
index df3c693a7..1c45a1b78 100644
--- a/src/libs/7zip/unix/CPP/Windows/Synchronization.h
+++ b/src/libs/7zip/unix/CPP/Windows/Synchronization.h
@@ -5,8 +5,8 @@
#include "Defs.h"
-extern "C"
-{
+extern "C"
+{
#include "../../C/Threads.h"
}
@@ -18,7 +18,7 @@ namespace NWindows {
namespace NSynchronization {
class Uncopyable {
-protected:
+protected:
Uncopyable() {} // allow construction
~Uncopyable() {} // and destruction of derived objects...
private:
@@ -125,8 +125,8 @@ public:
return 0;
return ::GetLastError();
}
- WRes Release()
- {
+ WRes Release()
+ {
return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();
}
};
@@ -134,7 +134,7 @@ class CMutexLock
{
CMutex *_object;
public:
- CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }
+ CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }
~CMutexLock() { _object->Release(); }
};
#endif
@@ -173,7 +173,7 @@ class CCriticalSectionLock : private Uncopyable
CCriticalSection *_object;
void Unlock() { _object->Leave(); }
public:
- CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }
+ CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }
~CCriticalSectionLock() { Unlock(); }
};
diff --git a/src/libs/7zip/unix/CPP/Windows/Synchronization2.h b/src/libs/7zip/unix/CPP/Windows/Synchronization2.h
index d86b49dee..ff8f7a752 100644
--- a/src/libs/7zip/unix/CPP/Windows/Synchronization2.h
+++ b/src/libs/7zip/unix/CPP/Windows/Synchronization2.h
@@ -29,7 +29,7 @@ public:
~CSynchro() {}
void Enter() { Lock(); }
void Leave() { Unlock(); }
- void WaitCond() {
+ void WaitCond() {
_waiting[index_waiting++] = find_thread(NULL); // _waiting.push_back(find_thread(NULL));
thread_id sender;
Unlock();
@@ -84,16 +84,16 @@ public:
::pthread_mutex_init(&_object,0);
::pthread_cond_init(&_cond,0);
}
- void Enter() {
+ void Enter() {
::pthread_mutex_lock(&_object);
}
void Leave() {
::pthread_mutex_unlock(&_object);
}
- void WaitCond() {
+ void WaitCond() {
::pthread_cond_wait(&_cond, &_object);
}
- void LeaveAndSignal() {
+ void LeaveAndSignal() {
::pthread_cond_broadcast(&_cond);
::pthread_mutex_unlock(&_object);
}
@@ -119,7 +119,7 @@ class CBaseEventWFMO : public CBaseHandleWFMO
public:
bool IsCreated() { return (this->_sync != 0); }
- CBaseEventWFMO() { this->_sync = 0; }
+ CBaseEventWFMO() { this->_sync = 0; }
~CBaseEventWFMO() { Close(); }
WRes Close() { this->_sync = 0; return S_OK; }
@@ -178,7 +178,7 @@ class CSemaphoreWFMO : public CBaseHandleWFMO
LONG _maxCount;
public:
- CSemaphoreWFMO() : _count(0), _maxCount(0) { this->_sync=0;}
+ CSemaphoreWFMO() : _count(0), _maxCount(0) { this->_sync=0;}
WRes Create(CSynchro *sync,LONG initiallyCount, LONG maxCount)
{
if ((initiallyCount < 0) || (initiallyCount > maxCount) || (maxCount < 1)) return S_FALSE;
diff --git a/src/libs/7zip/unix/CPP/Windows/System.cpp b/src/libs/7zip/unix/CPP/Windows/System.cpp
index b63ebec79..55e723c40 100644
--- a/src/libs/7zip/unix/CPP/Windows/System.cpp
+++ b/src/libs/7zip/unix/CPP/Windows/System.cpp
@@ -20,7 +20,7 @@
#endif
-#include "Common/Types.h"
+#include "Common/MyTypes.h"
namespace NWindows
{
diff --git a/src/libs/7zip/unix/CPP/Windows/System.h b/src/libs/7zip/unix/CPP/Windows/System.h
index e0067158f..4133a7b30 100644
--- a/src/libs/7zip/unix/CPP/Windows/System.h
+++ b/src/libs/7zip/unix/CPP/Windows/System.h
@@ -3,7 +3,7 @@
#ifndef __WINDOWS_SYSTEM_H
#define __WINDOWS_SYSTEM_H
-#include "../Common/Types.h"
+#include "../Common/MyTypes.h"
namespace NWindows {
namespace NSystem {
diff --git a/src/libs/7zip/unix/CPP/Windows/Thread.h b/src/libs/7zip/unix/CPP/Windows/Thread.h
index ed72507f4..944f19744 100644
--- a/src/libs/7zip/unix/CPP/Windows/Thread.h
+++ b/src/libs/7zip/unix/CPP/Windows/Thread.h
@@ -23,7 +23,7 @@ public:
WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
{ return Thread_Create(&thread, startAddress, parameter); }
WRes Wait() { return Thread_Wait(&thread); }
-
+
#ifdef _WIN32
operator HANDLE() { return thread; }
void Attach(HANDLE handle) { thread = handle; }
diff --git a/src/libs/7zip/unix/CPP/Windows/Time.cpp b/src/libs/7zip/unix/CPP/Windows/Time.cpp
deleted file mode 100644
index b58de6fe1..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Time.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-// Windows/Time.cpp
-
-#include "StdAfx.h"
-
-#include "Time.h"
-#include "Windows/Defs.h"
-
-namespace NWindows {
-namespace NTime {
-
-static const UInt32 kFileTimeStartYear = 1601;
-
-static const UInt32 kNumTimeQuantumsInSecond = 10000000;
-static const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;
-
-void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)
-{
- UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;
- fileTime.dwLowDateTime = (DWORD)v;
- fileTime.dwHighDateTime = (DWORD)(v >> 32);
-}
-
-bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)
-{
- UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
- if (winTime < kUnixTimeStartValue)
- {
- unixTime = 0;
- return false;
- }
- winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;
- if (winTime > 0xFFFFFFFF)
- {
- unixTime = 0xFFFFFFFF;
- return false;
- }
- unixTime = (UInt32)winTime;
- return true;
-}
-
-bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
- unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)
-{
- resSeconds = 0;
- if (year < kFileTimeStartYear || year >= 10000 || month < 1 || month > 12 ||
- day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)
- return false;
- UInt32 numYears = year - kFileTimeStartYear;
- UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;
- Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
- ms[1] = 29;
- month--;
- for (unsigned i = 0; i < month; i++)
- numDays += ms[i];
- numDays += day - 1;
- resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;
- return true;
-}
-
-void GetCurUtcFileTime(FILETIME &ft)
-{
- SYSTEMTIME st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
-}
-
-}}
diff --git a/src/libs/7zip/unix/CPP/Windows/Time.h b/src/libs/7zip/unix/CPP/Windows/Time.h
deleted file mode 100644
index 6f510b22b..000000000
--- a/src/libs/7zip/unix/CPP/Windows/Time.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Windows/Time.h
-
-#ifndef __WINDOWS_TIME_H
-#define __WINDOWS_TIME_H
-
-#include "Common/Types.h"
-
-namespace NWindows {
-namespace NTime {
-
-bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);
-bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);
-void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);
-bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);
-bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
- unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);
-void GetCurUtcFileTime(FILETIME &ft);
-
-}}
-
-#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/TimeUtils.cpp b/src/libs/7zip/unix/CPP/Windows/TimeUtils.cpp
new file mode 100644
index 000000000..7ef44d9cc
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/Windows/TimeUtils.cpp
@@ -0,0 +1,203 @@
+// Windows/TimeUtils.cpp
+
+#include "StdAfx.h"
+
+#include "Defs.h"
+#include "TimeUtils.h"
+
+namespace NWindows {
+namespace NTime {
+
+static const UInt32 kNumTimeQuantumsInSecond = 10000000;
+static const UInt32 kFileTimeStartYear = 1601;
+static const UInt32 kDosTimeStartYear = 1980;
+static const UInt32 kUnixTimeStartYear = 1970;
+static const UInt64 kUnixTimeOffset =
+ (UInt64)60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear));
+static const UInt64 kNumSecondsInFileTime = (UInt64)(Int64)-1 / kNumTimeQuantumsInSecond;
+
+bool DosTimeToFileTime(UInt32 dosTime, FILETIME &ft) throw()
+{
+ #if defined(_WIN32) && !defined(UNDER_CE)
+ return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &ft));
+ #else
+ ft.dwLowDateTime = 0;
+ ft.dwHighDateTime = 0;
+ UInt64 res;
+ if (!GetSecondsSince1601(kDosTimeStartYear + (dosTime >> 25), (dosTime >> 21) & 0xF, (dosTime >> 16) & 0x1F,
+ (dosTime >> 11) & 0x1F, (dosTime >> 5) & 0x3F, (dosTime & 0x1F) * 2, res))
+ return false;
+ res *= kNumTimeQuantumsInSecond;
+ ft.dwLowDateTime = (UInt32)res;
+ ft.dwHighDateTime = (UInt32)(res >> 32);
+ return true;
+ #endif
+}
+
+static const UInt32 kHighDosTime = 0xFF9FBF7D;
+static const UInt32 kLowDosTime = 0x210000;
+
+#define PERIOD_4 (4 * 365 + 1)
+#define PERIOD_100 (PERIOD_4 * 25 - 1)
+#define PERIOD_400 (PERIOD_100 * 4 + 1)
+
+bool FileTimeToDosTime(const FILETIME &ft, UInt32 &dosTime) throw()
+{
+ #if defined(_WIN32) && !defined(UNDER_CE)
+
+ WORD datePart, timePart;
+ if (!::FileTimeToDosDateTime(&ft, &datePart, &timePart))
+ {
+ dosTime = (ft.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;
+ return false;
+ }
+ dosTime = (((UInt32)datePart) << 16) + timePart;
+
+ #else
+
+ unsigned year, mon, day, hour, min, sec;
+ UInt64 v64 = ft.dwLowDateTime | ((UInt64)ft.dwHighDateTime << 32);
+ Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ unsigned temp;
+ UInt32 v;
+ v64 += (kNumTimeQuantumsInSecond * 2 - 1);
+ v64 /= kNumTimeQuantumsInSecond;
+ sec = (unsigned)(v64 % 60);
+ v64 /= 60;
+ min = (unsigned)(v64 % 60);
+ v64 /= 60;
+ hour = (unsigned)(v64 % 24);
+ v64 /= 24;
+
+ v = (UInt32)v64;
+
+ year = (unsigned)(kFileTimeStartYear + v / PERIOD_400 * 400);
+ v %= PERIOD_400;
+
+ temp = (unsigned)(v / PERIOD_100);
+ if (temp == 4)
+ temp = 3;
+ year += temp * 100;
+ v -= temp * PERIOD_100;
+
+ temp = v / PERIOD_4;
+ if (temp == 25)
+ temp = 24;
+ year += temp * 4;
+ v -= temp * PERIOD_4;
+
+ temp = v / 365;
+ if (temp == 4)
+ temp = 3;
+ year += temp;
+ v -= temp * 365;
+
+ if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
+ ms[1] = 29;
+ for (mon = 1; mon <= 12; mon++)
+ {
+ unsigned s = ms[mon - 1];
+ if (v < s)
+ break;
+ v -= s;
+ }
+ day = (unsigned)v + 1;
+
+ dosTime = kLowDosTime;
+ if (year < kDosTimeStartYear)
+ return false;
+ year -= kDosTimeStartYear;
+ dosTime = kHighDosTime;
+ if (year >= 128)
+ return false;
+ dosTime = (year << 25) | (mon << 21) | (day << 16) | (hour << 11) | (min << 5) | (sec >> 1);
+ #endif
+ return true;
+}
+
+void UnixTimeToFileTime(UInt32 unixTime, FILETIME &ft) throw()
+{
+ UInt64 v = (kUnixTimeOffset + (UInt64)unixTime) * kNumTimeQuantumsInSecond;
+ ft.dwLowDateTime = (DWORD)v;
+ ft.dwHighDateTime = (DWORD)(v >> 32);
+}
+
+bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &ft) throw()
+{
+ if (unixTime > kNumSecondsInFileTime - kUnixTimeOffset)
+ {
+ ft.dwLowDateTime = ft.dwHighDateTime = (UInt32)(Int32)-1;
+ return false;
+ }
+ Int64 v = (Int64)kUnixTimeOffset + unixTime;
+ if (v < 0)
+ {
+ ft.dwLowDateTime = ft.dwHighDateTime = 0;
+ return false;
+ }
+ UInt64 v2 = (UInt64)v * kNumTimeQuantumsInSecond;
+ ft.dwLowDateTime = (DWORD)v2;
+ ft.dwHighDateTime = (DWORD)(v2 >> 32);
+ return true;
+}
+
+Int64 FileTimeToUnixTime64(const FILETIME &ft) throw()
+{
+ UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+ return (Int64)(winTime / kNumTimeQuantumsInSecond) - kUnixTimeOffset;
+}
+
+bool FileTimeToUnixTime(const FILETIME &ft, UInt32 &unixTime) throw()
+{
+ UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
+ winTime /= kNumTimeQuantumsInSecond;
+ if (winTime < kUnixTimeOffset)
+ {
+ unixTime = 0;
+ return false;
+ }
+ winTime -= kUnixTimeOffset;
+ if (winTime > 0xFFFFFFFF)
+ {
+ unixTime = 0xFFFFFFFF;
+ return false;
+ }
+ unixTime = (UInt32)winTime;
+ return true;
+}
+
+bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
+ unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw()
+{
+ resSeconds = 0;
+ if (year < kFileTimeStartYear || year >= 10000 || month < 1 || month > 12 ||
+ day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)
+ return false;
+ UInt32 numYears = year - kFileTimeStartYear;
+ UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;
+ Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
+ ms[1] = 29;
+ month--;
+ for (unsigned i = 0; i < month; i++)
+ numDays += ms[i];
+ numDays += day - 1;
+ resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;
+ return true;
+}
+
+void GetCurUtcFileTime(FILETIME &ft) throw()
+{
+ // Both variants provide same low resolution on WinXP: about 15 ms.
+ // But GetSystemTimeAsFileTime is much faster.
+
+ #ifdef UNDER_CE
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &ft);
+ #else
+ GetSystemTimeAsFileTime(&ft);
+ #endif
+}
+
+}}
diff --git a/src/libs/7zip/unix/CPP/Windows/TimeUtils.h b/src/libs/7zip/unix/CPP/Windows/TimeUtils.h
new file mode 100644
index 000000000..2967214e6
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/Windows/TimeUtils.h
@@ -0,0 +1,23 @@
+// Windows/TimeUtils.h
+
+#ifndef __WINDOWS_TIME_UTILS_H
+#define __WINDOWS_TIME_UTILS_H
+
+#include "../Common/MyTypes.h"
+
+namespace NWindows {
+namespace NTime {
+
+bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime) throw();
+bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime) throw();
+void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime) throw();
+bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &fileTime) throw();
+bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw();
+Int64 FileTimeToUnixTime64(const FILETIME &ft) throw();
+bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
+ unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw();
+void GetCurUtcFileTime(FILETIME &ft) throw();
+
+}}
+
+#endif
diff --git a/src/libs/7zip/unix/CPP/Windows/Windows.pri b/src/libs/7zip/unix/CPP/Windows/Windows.pri
new file mode 100644
index 000000000..117fb37b3
--- /dev/null
+++ b/src/libs/7zip/unix/CPP/Windows/Windows.pri
@@ -0,0 +1,24 @@
+HEADERS += $$7ZIP_BASE/CPP/Windows/DLL.h \
+ $$7ZIP_BASE/CPP/Windows/Defs.h \
+ $$7ZIP_BASE/CPP/Windows/FileDir.h \
+ $$7ZIP_BASE/CPP/Windows/FileFind.h \
+ $$7ZIP_BASE/CPP/Windows/FileIO.h \
+ $$7ZIP_BASE/CPP/Windows/FileName.h \
+ $$7ZIP_BASE/CPP/Windows/PropVariant.h \
+ $$7ZIP_BASE/CPP/Windows/PropVariantConv.h \
+ $$7ZIP_BASE/CPP/Windows/Synchronization.h \
+ $$7ZIP_BASE/CPP/Windows/Synchronization2.h \
+ $$7ZIP_BASE/CPP/Windows/System.h \
+ $$7ZIP_BASE/CPP/Windows/Thread.h \
+ $$7ZIP_BASE/CPP/Windows/TimeUtils.h
+
+SOURCES += $$7ZIP_BASE/CPP/Windows/DLL.cpp \
+ $$7ZIP_BASE/CPP/Windows/FileDir.cpp \
+ $$7ZIP_BASE/CPP/Windows/FileFind.cpp \
+ $$7ZIP_BASE/CPP/Windows/FileIO.cpp \
+ $$7ZIP_BASE/CPP/Windows/FileName.cpp \
+ $$7ZIP_BASE/CPP/Windows/PropVariant.cpp \
+ $$7ZIP_BASE/CPP/Windows/PropVariantConv.cpp \
+ $$7ZIP_BASE/CPP/Windows/Synchronization.cpp \
+ $$7ZIP_BASE/CPP/Windows/System.cpp \
+ $$7ZIP_BASE/CPP/Windows/TimeUtils.cpp