3 * Riven-Wahrk - a reimplementation of the game Riven, by Cyan
4 * Copyright (C) 2010 Tyler Genter <tylergenter@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 mmap_file_t
*riven::mmap_file (const std::string
&path
) {
26 mmap_file_t
*f
= new mmap_file_t
;
29 ofstruct
.cBytes
= sizeof (OFSTRUCT
);
30 HANDLE hFile
= (void*) OpenFile (path
.c_str(), &ofstruct
, OF_READ
);
32 HANDLE hfileMapping
= CreateFileMapping (hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
34 // this is likely to fail, especially on a 32-bit os, since we usually
35 // end up mapping a file that is 600 mb, and the address space is
37 f
->data
= (uint8_t*) MapViewOfFile (hfileMapping
, FILE_MAP_READ
, 0, 0, 0);
39 std::string temp
= "Error mapping " + path
+ " into address space.";
41 MessageBox (NULL
, temp
.c_str(), "Riven-Wahrk", MB_ICONERROR
);
44 return f
; // return NULL on error
48 void riven::munmap_file (mmap_file_t
*) {
56 void riven::list_disks (std::vector
<std::string
> &disks
) {
61 SetErrorMode (SEM_FAILCRITICALERRORS
);
62 GetLogicalDriveStrings (512, drive
);
64 while (path
[0] != 0) {
65 if (GetDriveType (path
) == DRIVE_CDROM
) {
66 disks
.push_back (std::string (path
));
68 path
+= strlen (path
) + 1;
74 std::string
riven::find_file (const std::string
&dir
, const std::string
&path
) {
77 std::string res
= dir
+ "\\" + path
;
79 FILE *file
= fopen (res
.c_str(), "r");