bool FileCopy(const char *oldname, const char *newname) { #if defined(PLATFORM_WIN32) if(IsWinNT()) return UnicodeWin32().CopyFileW(ToSystemCharsetW(oldname), ToSystemCharsetW(newname), false); else return CopyFile(ToSystemCharset(oldname), ToSystemCharset(newname), false); #elif defined(PLATFORM_POSIX) FileIn fi(oldname); if(!fi.IsOpen()) return false; FileOut fo(newname); if(!fo.IsOpen()) return false; CopyStream(fo, fi, fi.GetLeft()); fi.Close(); fo.Close(); if(fo.IsError()) { unlink(newname); return false; } FileSetTime(newname, FileGetTime(oldname)); return true; #else #error #endif//PLATFORM }
bool FileMove(const char *oldname, const char *newname) { #if defined(PLATFORM_WIN32) if(IsWinNT()) return !!UnicodeWin32().MoveFileW(ToSystemCharsetW(oldname), ToSystemCharsetW(newname)); else return !!MoveFile(ToSystemCharset(oldname), ToSystemCharset(newname)); #elif defined(PLATFORM_POSIX) return !rename(ToSystemCharset(oldname), ToSystemCharset(newname)); #else #error #endif//PLATFORM }
bool DirectoryCreate(const char *path) { if(IsWinNT()) return !!UnicodeWin32().CreateDirectoryW(ToSystemCharsetW(path), 0); else return !!CreateDirectory(ToSystemCharset(path), 0); }
bool SetFileTime(const char *filename, FileTime ft) { #if defined(PLATFORM_WIN32) HANDLE handle; if(IsWinNT()) handle = UnicodeWin32().CreateFileW(ToSystemCharsetW(filename), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); else handle = CreateFile(ToSystemCharset(filename), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if(handle == INVALID_HANDLE_VALUE) return false; bool res = SetFileTime(handle, 0, 0, &ft); CloseHandle(handle); return res; #elif defined(PLATFORM_POSIX) struct utimbuf ub; ub.actime = ub.modtime = ft; return !utime(ToSystemCharset(filename), &ub); #else #error #endif//PLATFORM }
FileTime GetFileTime(const char *filename) { #if defined(PLATFORM_WIN32) HANDLE handle; if(IsWinNT()) handle = UnicodeWin32().CreateFileW(ToSystemCharsetW(filename), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); else handle = CreateFile(ToSystemCharset(filename), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); FileTime ft0; memset(&ft0, 0, sizeof(ft0)); if(handle == INVALID_HANDLE_VALUE) return ft0; FileTime ft; bool res = GetFileTime(handle, 0, 0, &ft); CloseHandle(handle); return res ? ft : ft0; #elif defined(PLATFORM_POSIX) struct stat st; if(stat(ToSystemCharset(filename), &st)) return 0; return st.st_mtime; #else #error #endif//PLATFORM }
static bool sGetSymLinkPath0(const char *linkpath, String *path) { bool ret = false; HRESULT hres; IShellLink* psl; IPersistFile* ppf; CoInitialize(NULL); hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (PVOID *) &psl); if(SUCCEEDED(hres)) { hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf); if(SUCCEEDED(hres)) { hres = ppf->Load(ToSystemCharsetW(linkpath), STGM_READ); if(SUCCEEDED(hres)) if(path) { char fileW[_MAX_PATH] = {0}; psl->GetPath(fileW, _MAX_PATH, NULL, 0); *path = FromSystemCharset(fileW); } else ret = true; ppf->Release(); } psl->Release(); } CoUninitialize(); return ret; }
bool DirectoryDelete(const char *dirname) { #if defined(PLATFORM_WIN32) if(IsWinNT()) return !!UnicodeWin32().RemoveDirectoryW(ToSystemCharsetW(dirname)); else return !!RemoveDirectory(ToSystemCharset(dirname)); #elif defined(PLATFORM_POSIX) return !rmdir(ToSystemCharset(dirname)); #else #error #endif//PLATFORM }
bool FileDelete(const char *filename) { #if defined(PLATFORM_WIN32) if(IsWinNT()) return !!UnicodeWin32().DeleteFileW(ToSystemCharsetW(filename)); else return !!DeleteFile(ToSystemCharset(filename)); #elif defined(PLATFORM_POSIX) return !unlink(ToSystemCharset(filename)); #else #error #endif//PLATFORM }
bool FindFile::Search(const char *name) { pattern = GetFileName(name); path = NormalizePath(GetFileDirectory(name)); Close(); if(w) handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w); else handle = FindFirstFile(ToSystemCharset(name), a); if(handle == INVALID_HANDLE_VALUE) return false; if(!PatternMatch(pattern, GetName())) return Next(); return true; }
String GetFullPath(const char *file) { #ifdef PLATFORM_WIN32 if(IsWinNT()) { String ufn = FromUnixName(file); wchar h[MAX_PATH]; UnicodeWin32().GetFullPathNameW(ToSystemCharsetW(ufn), MAX_PATH, h, 0); return FromSystemCharsetW(h); } else { String ufn = FromUnixName(file); char h[MAX_PATH]; GetFullPathName(ToSystemCharset(ufn), MAX_PATH, h, 0); return FromSystemCharset(h); } #else return NormalizePath(file); #endif }
bool FileStream::Open(const char *name, dword mode) { LLOG("Open " << name << " mode: " << mode); Close(); int iomode = mode & ~SHAREMASK; if(IsWinNT()) handle = UnicodeWin32().CreateFileW(ToSystemCharsetW(name), iomode == READ ? GENERIC_READ : GENERIC_READ|GENERIC_WRITE, (mode & NOREADSHARE ? 0 : FILE_SHARE_READ) | (mode & NOWRITESHARE ? 0 : FILE_SHARE_WRITE) | (mode & DELETESHARE ? FILE_SHARE_DELETE : 0), NULL, iomode == READ ? OPEN_EXISTING : iomode == CREATE ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL ); else handle = CreateFile(ToSystemCharset(name), iomode == READ ? GENERIC_READ : GENERIC_READ|GENERIC_WRITE, (mode & NOREADSHARE ? 0 : FILE_SHARE_READ) | (mode & NOWRITESHARE ? 0 : FILE_SHARE_WRITE) | (mode & DELETESHARE ? FILE_SHARE_DELETE : 0), NULL, iomode == READ ? OPEN_EXISTING : iomode == CREATE ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL ); if(handle == INVALID_HANDLE_VALUE) { SetError(); return FALSE; } dword fsz_lo, fsz_hi; fsz_lo = ::GetFileSize(handle, &fsz_hi); int64 fsz; if(fsz_lo == 0xffffffff && GetLastError() != NO_ERROR) fsz = 0; else fsz = fsz_lo | (int64(fsz_hi) << 32); OpenInit(iomode, fsz); LLOG("OPEN " << handle); return TRUE; }