Subversion Repositories WoWGM

Rev

Rev 31 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 tristanc 1
#include "pch.h"
2
#pragma hdrstop
3
 
4
#include "OsFile.h"
5
 
6
bool OsFileExists(char *fileName)
7
{
8
	DWORD dwFileAttributes = GetFileAttributesA(fileName);
9
	return (dwFileAttributes != INVALID_FILE_ATTRIBUTES && !(dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
10
}
11
 
12
bool OsDirectoryExists(char *directory)
13
{
14
	DWORD dwFileAttributes = GetFileAttributesA(directory);
15
	return (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
16
}
17
 
18
HANDLE OsCreateFile(char	*fileName,
19
					DWORD	desiredAccess,
20
					DWORD	shareMode,
21
					DWORD	createDisposition,
22
					DWORD	flagsAndAttributes,
23
					HANDLE	extendedFileType)
24
{
25
	HANDLE result;
26
	int length = MultiByteToWideChar(CP_UTF8, 0, fileName, -1, NULL, 0);
27
	LPWSTR fileNameW = new wchar_t[length];
28
	MultiByteToWideChar(CP_UTF8, 0, fileName, -1, fileNameW, length);
29
	result = CreateFileW(fileNameW, desiredAccess, shareMode, 0, createDisposition, flagsAndAttributes, extendedFileType);
30
	delete[] fileNameW;
31
	return result;
32
}
33
 
34
BOOL OsReadFile(HANDLE hFile, void *buffer, DWORD bytesToRead, DWORD *bytesRead)
35
{
36
	return ReadFile(hFile, buffer, bytesToRead, bytesRead, 0);
37
}
38
 
39
DWORD OsSetFilePointer(HANDLE hFile, DWORD moveMethod, LONG distanceToMove)
40
{
41
	DWORD result;
42
	LONG distanceToMoveHigh;
43
 
44
	distanceToMoveHigh = HIWORD(distanceToMove);
45
	result = SetFilePointer(hFile, distanceToMove, &distanceToMoveHigh, moveMethod);
46
	if (result == -1)
47
	{
48
		DWORD error = GetLastError();	/* TODO: Do something here? */
49
		result = -1;
50
	}
51
	return result;
52
}
53
 
54
BOOL OsWriteFile(HANDLE hFile, const void *buffer, DWORD bytesToWrite, DWORD *bytesWritten)
55
{
56
	return WriteFile(hFile, buffer, bytesToWrite, bytesWritten, 0);
57
}
58
 
59
void OsCloseFile(HANDLE hFile)
60
{
61
	CloseHandle(hFile);
62
}