mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: Path ops GetFileAttributesEx -> GetFileAttributesExW (thanks Tom!)
This commit is contained in:
parent
7d1df1620c
commit
3be35ae11e
2 changed files with 13 additions and 24 deletions
|
|
@ -12,7 +12,7 @@ CONSOLE_APP_MAIN
|
|||
ASSERT(!FileExists(testdir));
|
||||
ASSERT(!DirectoryExists(testdir + "q24312"));
|
||||
|
||||
String path = AppendFileName(testdir, "test.txt");
|
||||
String path = AppendFileName(testdir, "testík.txt");
|
||||
Time tm0 = GetSysTime();
|
||||
SaveFile(path, "test");
|
||||
ASSERT(FileExists(path));
|
||||
|
|
@ -24,6 +24,7 @@ CONSOLE_APP_MAIN
|
|||
|
||||
Time tm = GetFileTime(path);
|
||||
DDUMP(tm);
|
||||
ASSERT(tm == FileGetTime(path));
|
||||
|
||||
ASSERT(tm >= tm0 && tm <= GetSysTime());
|
||||
|
||||
|
|
|
|||
|
|
@ -714,26 +714,9 @@ int Compare_FileTime(const FileTime& fa, const FileTime& fb)
|
|||
}
|
||||
#endif
|
||||
|
||||
Time FileGetTime(const char *filename)
|
||||
static bool sGetFileAttrs(const char *path, WIN32_FILE_ATTRIBUTE_DATA& wfad)
|
||||
{
|
||||
#if defined(PLATFORM_WIN32)
|
||||
HANDLE handle;
|
||||
handle = CreateFileW(ToSystemCharsetW(filename), GENERIC_READ,
|
||||
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if(handle == INVALID_HANDLE_VALUE)
|
||||
return Null;
|
||||
FileTime ft;
|
||||
bool res = GetFileTime(handle, 0, 0, &ft);
|
||||
CloseHandle(handle);
|
||||
return res ? Time(ft) : Time(Null);
|
||||
#elif defined(PLATFORM_POSIX)
|
||||
struct stat st;
|
||||
if(stat(ToSystemCharset(filename), &st))
|
||||
return Null;
|
||||
return Time(st.st_mtime);
|
||||
#else
|
||||
#error
|
||||
#endif//PLATFORM
|
||||
return GetFileAttributesExW(ToSystemCharsetW(path), GetFileExInfoStandard, &wfad);
|
||||
}
|
||||
|
||||
FileTime GetFileTime(const char *filename)
|
||||
|
|
@ -741,7 +724,7 @@ FileTime GetFileTime(const char *filename)
|
|||
#if defined(PLATFORM_WIN32)
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
static FileTime ft0;
|
||||
return GetFileAttributesEx(filename, GetFileExInfoStandard, &wfad) ? wfad.ftLastWriteTime : ft0;
|
||||
return sGetFileAttrs(filename, wfad) ? wfad.ftLastWriteTime : ft0;
|
||||
#elif defined(PLATFORM_POSIX)
|
||||
struct stat st;
|
||||
if(stat(ToSystemCharset(filename), &st))
|
||||
|
|
@ -752,11 +735,16 @@ FileTime GetFileTime(const char *filename)
|
|||
#endif//PLATFORM
|
||||
}
|
||||
|
||||
Time FileGetTime(const char *path)
|
||||
{
|
||||
return Time(GetFileTime(path));
|
||||
}
|
||||
|
||||
int64 GetFileLength(const char *path) {
|
||||
#if defined(PLATFORM_WIN32)
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
static FileTime ft0;
|
||||
return GetFileAttributesEx(path, GetFileExInfoStandard, &wfad) ? MAKEQWORD(wfad.nFileSizeLow, wfad.nFileSizeHigh) : -1;
|
||||
return sGetFileAttrs(path, wfad) ? MAKEQWORD(wfad.nFileSizeLow, wfad.nFileSizeHigh) : -1;
|
||||
#elif defined(PLATFORM_POSIX)
|
||||
struct stat st;
|
||||
return stat(ToSystemCharset(path), &st) ? -1 : st.st_size;
|
||||
|
|
@ -770,7 +758,7 @@ bool FileExists(const char *path)
|
|||
#if defined(PLATFORM_WIN32)
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
static FileTime ft0;
|
||||
return GetFileAttributesEx(path, GetFileExInfoStandard, &wfad) && !(wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
return sGetFileAttrs(path, wfad) && !(wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#elif defined(PLATFORM_POSIX)
|
||||
struct stat st;
|
||||
return stat(ToSystemCharset(path), &st) ? false : S_ISREG(st.st_mode);
|
||||
|
|
@ -784,7 +772,7 @@ bool DirectoryExists(const char *path)
|
|||
#if defined(PLATFORM_WIN32)
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
static FileTime ft0;
|
||||
return GetFileAttributesEx(path, GetFileExInfoStandard, &wfad) && (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
return sGetFileAttrs(path, wfad) && (wfad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#elif defined(PLATFORM_POSIX)
|
||||
struct stat st;
|
||||
return stat(ToSystemCharset(path), &st) ? false : S_ISDIR(st.st_mode);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue