-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass map.cpp
executable file
·79 lines (65 loc) · 2 KB
/
class map.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Include statements
#include <windows.h>
#include <windef.h>
#include <atlstr.h>
#include <shlobj.h>
#include "resource.h"
#include "program.h"
#include "class.h"
#include "function.h"
// Global objects
extern handleitem Handle;
// Open the file at path and find out how big it is
bool mapitem::openfile(read path) {
// Open the file
file = CreateFile(
LongPath(path), // Path and file name
GENERIC_READ, // Get read-only access
FILE_SHARE_READ, // Allow other calls and processes to read the file while it's open
NULL,
OPEN_EXISTING, // Don't create a file
FILE_FLAG_SEQUENTIAL_SCAN, // We plan to read the file front to end
NULL);
if (file == INVALID_HANDLE_VALUE) return false;
// Find out how big it is
DWORD high = 0;
DWORD low = GetFileSize(file, &high);
size = Combine(high, low);
// Everything worked
return true;
}
// Map the file into memory
bool mapitem::openmap() {
// Open the map
map = CreateFileMapping(
file, // Handle to open file
NULL,
PAGE_READONLY, // Read-only access
0, // Map the whole file
0,
NULL); // Don't specify a name for the object
if (!map) return false; // Can't map a 0 byte file
// Everything worked
return true;
}
// Set the view on the first or next chunk of the file
// Returns false on error or done
bool mapitem::set() {
// The last time we clipped out the final block
if (i + s == size) return false;
// Set i and s to clip out the next block
i = i + s;
s = VIEWSIZE;
if (i + s > size) s = size - i; // The last block may be smaller
// Change the view
if (view && view != INVALID_HANDLE_VALUE) UnmapViewOfFile(view);
view = MapViewOfFile(
map, // Handle to open map
FILE_MAP_READ, // Read-only access
High(i), // Offset high
Low(i), // Offset low
Low(s)); // Number of bytes to map
if (!view) return false;
// Everything worked
return true;
}