mirror of
https://github.com/aaru-dps/Aaru.Compression.Native.git
synced 2025-12-16 19:24:31 +00:00
Update to lzma 23.01.
This commit is contained in:
139
3rdparty/lzma/CPP/Windows/FileFind.h
vendored
139
3rdparty/lzma/CPP/Windows/FileFind.h
vendored
@@ -1,7 +1,7 @@
|
||||
// Windows/FileFind.h
|
||||
|
||||
#ifndef __WINDOWS_FILE_FIND_H
|
||||
#define __WINDOWS_FILE_FIND_H
|
||||
#ifndef ZIP7_INC_WINDOWS_FILE_FIND_H
|
||||
#define ZIP7_INC_WINDOWS_FILE_FIND_H
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/stat.h>
|
||||
@@ -9,10 +9,14 @@
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include "../Common/MyLinux.h"
|
||||
#include "../Common/MyString.h"
|
||||
#include "../Common/MyWindows.h"
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
#include "FileIO.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NFind {
|
||||
@@ -32,6 +36,7 @@ bool DoesFileOrDirExist(CFSTR name);
|
||||
|
||||
DWORD GetFileAttrib(CFSTR path);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
namespace NAttributes
|
||||
{
|
||||
@@ -42,21 +47,38 @@ namespace NAttributes
|
||||
inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
|
||||
inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
|
||||
inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
|
||||
|
||||
inline UInt32 Get_PosixMode_From_WinAttrib(DWORD attrib)
|
||||
{
|
||||
UInt32 v = IsDir(attrib) ? MY_LIN_S_IFDIR : MY_LIN_S_IFREG;
|
||||
/* 21.06: as WSL we allow write permissions (0222) for directories even for (FILE_ATTRIBUTE_READONLY).
|
||||
So extracting at Linux will be allowed to write files inside (0777) directories. */
|
||||
v |= ((IsReadOnly(attrib) && !IsDir(attrib)) ? 0555 : 0777);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode);
|
||||
|
||||
#endif
|
||||
|
||||
class CFileInfoBase
|
||||
{
|
||||
#ifdef _WIN32
|
||||
bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
|
||||
#endif
|
||||
public:
|
||||
UInt64 Size;
|
||||
FILETIME CTime;
|
||||
FILETIME ATime;
|
||||
FILETIME MTime;
|
||||
CFiTime CTime;
|
||||
CFiTime ATime;
|
||||
CFiTime MTime;
|
||||
#ifdef _WIN32
|
||||
DWORD Attrib;
|
||||
bool IsAltStream;
|
||||
bool IsDevice;
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
#ifdef UNDER_CE
|
||||
DWORD ObjectID;
|
||||
@@ -64,24 +86,25 @@ public:
|
||||
UINT32 ReparseTag;
|
||||
#endif
|
||||
*/
|
||||
#else
|
||||
dev_t dev;
|
||||
#else
|
||||
dev_t dev; /* ID of device containing file */
|
||||
ino_t ino;
|
||||
nlink_t nlink;
|
||||
mode_t mode;
|
||||
nlink_t nlink;
|
||||
uid_t uid; /* user ID of owner */
|
||||
gid_t gid; /* group ID of owner */
|
||||
dev_t rdev; /* device ID (defined, if S_ISCHR(mode) || S_ISBLK(mode)) */
|
||||
// bool Use_lstat;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CFileInfoBase() { ClearBase(); }
|
||||
void ClearBase() throw();
|
||||
|
||||
void SetAsDir()
|
||||
{
|
||||
Attrib = FILE_ATTRIBUTE_DIRECTORY;
|
||||
#ifndef _WIN32
|
||||
Attrib |= (FILE_ATTRIBUTE_UNIX_EXTENSION + (S_IFDIR << 16));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
bool Fill_From_ByHandleFileInfo(CFSTR path);
|
||||
void SetAsDir() { Attrib = FILE_ATTRIBUTE_DIRECTORY; } // |= (FILE_ATTRIBUTE_UNIX_EXTENSION + (S_IFDIR << 16));
|
||||
void SetAsFile() { Attrib = 0; }
|
||||
|
||||
bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
|
||||
bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
|
||||
@@ -96,13 +119,42 @@ public:
|
||||
bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
|
||||
bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
|
||||
|
||||
#ifndef _WIN32
|
||||
bool IsPosixLink() const
|
||||
UInt32 GetWinAttrib() const { return Attrib; }
|
||||
UInt32 GetPosixAttrib() const
|
||||
{
|
||||
const UInt32 mod = Attrib >> 16;
|
||||
return S_ISLNK(mod);
|
||||
return NAttributes::Get_PosixMode_From_WinAttrib(Attrib);
|
||||
}
|
||||
bool Has_Attrib_ReparsePoint() const { return (Attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0; }
|
||||
|
||||
#else
|
||||
|
||||
UInt32 GetPosixAttrib() const { return mode; }
|
||||
UInt32 GetWinAttrib() const { return Get_WinAttribPosix_From_PosixMode(mode); }
|
||||
|
||||
bool IsDir() const { return S_ISDIR(mode); }
|
||||
void SetAsDir() { mode = S_IFDIR; }
|
||||
void SetAsFile() { mode = S_IFREG; }
|
||||
|
||||
bool IsReadOnly() const
|
||||
{
|
||||
// does linux support writing to ReadOnly files?
|
||||
if ((mode & 0222) == 0) // S_IWUSR in p7zip
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsPosixLink() const { return S_ISLNK(mode); }
|
||||
|
||||
#endif
|
||||
|
||||
bool IsOsSymLink() const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return HasReparsePoint();
|
||||
#else
|
||||
return IsPosixLink();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct CFileInfo: public CFileInfoBase
|
||||
@@ -117,7 +169,7 @@ struct CFileInfo: public CFileInfoBase
|
||||
bool Find_FollowLink(CFSTR path) { return Find(path, true); }
|
||||
|
||||
#ifdef _WIN32
|
||||
bool Fill_From_ByHandleFileInfo(CFSTR path);
|
||||
// bool Fill_From_ByHandleFileInfo(CFSTR path);
|
||||
// bool FollowReparse(CFSTR path, bool isDir);
|
||||
#else
|
||||
bool Find_DontFill_Name(CFSTR path, bool followLink = false);
|
||||
@@ -197,7 +249,15 @@ class CFindChangeNotification MY_UNCOPYABLE
|
||||
HANDLE _handle;
|
||||
public:
|
||||
operator HANDLE () { return _handle; }
|
||||
bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
|
||||
bool IsHandleAllocated() const
|
||||
{
|
||||
/* at least on win2000/XP (undocumented):
|
||||
if pathName is "" or NULL,
|
||||
FindFirstChangeNotification() could return NULL.
|
||||
So we check for INVALID_HANDLE_VALUE and NULL.
|
||||
*/
|
||||
return _handle != INVALID_HANDLE_VALUE && _handle != NULL;
|
||||
}
|
||||
CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
|
||||
~CFindChangeNotification() { Close(); }
|
||||
bool Close() throw();
|
||||
@@ -223,13 +283,15 @@ struct CDirEntry
|
||||
#endif
|
||||
FString Name;
|
||||
|
||||
/*
|
||||
#if !defined(_AIX)
|
||||
bool IsDir() const
|
||||
{
|
||||
// DT_DIR is
|
||||
// (Type == DT_UNKNOWN) on some systems
|
||||
return Type == DT_DIR;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
bool IsDots() const throw();
|
||||
};
|
||||
@@ -246,7 +308,22 @@ public:
|
||||
void SetDirPrefix(const FString &dirPrefix);
|
||||
|
||||
bool Next(CDirEntry &fileInfo, bool &found);
|
||||
bool Fill_FileInfo(const CDirEntry &de, CFileInfo &fileInfo, bool followLink);
|
||||
bool Fill_FileInfo(const CDirEntry &de, CFileInfo &fileInfo, bool followLink) const;
|
||||
bool DirEntry_IsDir(const CDirEntry &de, bool followLink) const
|
||||
{
|
||||
#if !defined(_AIX)
|
||||
if (de.Type == DT_DIR)
|
||||
return true;
|
||||
if (de.Type != DT_UNKNOWN)
|
||||
return false;
|
||||
#endif
|
||||
CFileInfo fileInfo;
|
||||
if (Fill_FileInfo(de, fileInfo, followLink))
|
||||
{
|
||||
return fileInfo.IsDir();
|
||||
}
|
||||
return false; // change it
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -261,16 +338,8 @@ inline UInt32 Get_WinAttrib_From_PosixMode(UInt32 mode)
|
||||
}
|
||||
*/
|
||||
|
||||
UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode);
|
||||
|
||||
// UInt32 Get_WinAttrib_From_stat(const struct stat &st);
|
||||
#if defined(_AIX)
|
||||
#define MY_ST_TIMESPEC st_timespec
|
||||
#else
|
||||
#define MY_ST_TIMESPEC timespec
|
||||
#endif
|
||||
|
||||
void timespec_To_FILETIME(const MY_ST_TIMESPEC &ts, FILETIME &ft);
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user