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