Пример #1
0
bool DirectoryCreate(const char *path)
{
	if(IsWinNT())
		return !!UnicodeWin32().CreateDirectoryW(ToSystemCharsetW(path), 0);
	else
		return !!CreateDirectory(ToSystemCharset(path), 0);
}
Пример #2
0
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
}
Пример #3
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
}
Пример #4
0
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
}
Пример #5
0
String GetLocaleInfoA(LCID lcid, LCTYPE lctype)
{
	if(IsWinNT()) {
		wchar cbuf[1000];
		UnicodeWin32().GetLocaleInfoW(lcid, lctype, cbuf, __countof(cbuf));
		return FromSystemCharsetW(cbuf);
	}
	else {
		char cbuf[1000];
		::GetLocaleInfoA(lcid, lctype, cbuf, __countof(cbuf));
		return FromSystemCharset(cbuf);
	}
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
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
}
Пример #9
0
String GetTempPath()
{
	if(IsWinNT()) {
		wchar h[MAX_PATH];
		UnicodeWin32().GetTempPathW(MAX_PATH, h);
		return FromSystemCharsetW(h);
	}
	else {
		char h[MAX_PATH];
		::GetTempPath(MAX_PATH, h);
		return FromSystemCharset(h);
	}
}
Пример #10
0
String GetWindowsDirectory() {
	if(IsWinNT()) {
		wchar temp[MAX_PATH];
		*temp = 0;
		UnicodeWin32().GetWindowsDirectoryW(temp, sizeof(temp));
		return FromSystemCharsetW(temp);
	}
	else {
		char temp[MAX_PATH];
		*temp = 0;
		::GetWindowsDirectory(temp, sizeof(temp));
		return FromSystemCharset(temp);
	}
}
Пример #11
0
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;
}
Пример #12
0
bool FindFile::Next0() {
	if(w) {
		if(!UnicodeWin32().FindNextFileW(handle, w)) {
			Close();
			return false;
		}
	}
	else {
		if(!FindNextFile(handle, a)) {
			Close();
			return false;
		}
	}
	return true;
}
Пример #13
0
String GetModuleFileName(HINSTANCE instance) {
#ifdef PLATFORM_WINCE
	wchar h[_MAX_PATH];
	GetModuleFileName(instance, h, _MAX_PATH);
	return FromSystemCharset(h);
#else
	if(IsWinNT()) {
		wchar h[_MAX_PATH];
		UnicodeWin32().GetModuleFileNameW(instance, h, _MAX_PATH);
		return FromSystemCharsetW(h);
	}
	else {
		char h[_MAX_PATH];
		GetModuleFileName(instance, h, _MAX_PATH);
		return FromSystemCharset(h);
	}
#endif
}
Пример #14
0
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
}
Пример #15
0
String GetCurrentDirectory() {
#if defined(PLATFORM_WIN32)
	if(IsWinNT()) {
		wchar h[MAX_PATH];
		UnicodeWin32().GetCurrentDirectoryW(MAX_PATH, h);
		return FromSystemCharsetW(h);
	}
	else {
		char h[MAX_PATH];
		::GetCurrentDirectory(MAX_PATH, h);
		return FromSystemCharset(h);
	}
#elif defined(PLATFORM_POSIX)
	char h[1024];
	return getcwd(h, 1024) ? FromSystemCharset(h) : String();
#else
#error GetCurrentDirectory not implemented for this platform, comment this line to get Null
	return Null;
#endif//PLATFORM
}
Пример #16
0
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;
}