Subversion Repositories WoWGM

Rev

Rev 3 | Rev 32 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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