summaryrefslogtreecommitdiff
path: root/src/ToolBox/superpmi/superpmi/filecache.h
blob: 876100ec6e490229a94017621f9744edd0a48fdf (plain)
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

// TODO-Cleanup: this class is unused

//----------------------------------------------------------
// FileCache.h - very simple read ahead/ReadFile abstraction
//----------------------------------------------------------
#ifndef _FileCache
#define _FileCache

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define CACHE_THIS_FILE 0xFF

class FileCache
{
public:
    static HANDLE CreateFileA(_In_ LPCSTR lpFileName,
                              _In_ DWORD dwDesiredAccess,
                              _In_ DWORD dwShareMode,
                              _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
                              _In_ DWORD dwCreationDisposition,
                              _In_ DWORD dwFlagsAndAttributes,
                              _In_opt_ HANDLE hTemplateFile);

    static HANDLE CreateFileW(_In_ LPCWSTR lpFileName,
                              _In_ DWORD dwDesiredAccess,
                              _In_ DWORD dwShareMode,
                              _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
                              _In_ DWORD dwCreationDisposition,
                              _In_ DWORD dwFlagsAndAttributes,
                              _In_opt_ HANDLE hTemplateFile);

    static BOOL ReadFile(_In_ HANDLE hFile,
                         _Out_writes_bytes_to_opt_(nNumberOfBytesToRead, *lpNumberOfBytesRead) __out_data_source(FILE)
                             LPVOID lpBuffer,
                         _In_ DWORD nNumberOfBytesToRead,
                         _Out_opt_ LPDWORD lpNumberOfBytesRead,
                         _Inout_opt_ LPOVERLAPPED lpOverlapped);

    static BOOL WriteFile(_In_ HANDLE                                         hFile,
                          _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer,
                          _In_ DWORD nNumberOfBytesToWrite,
                          _Out_opt_ LPDWORD lpNumberOfBytesWritten,
                          _Inout_opt_ LPOVERLAPPED lpOverlapped);

    static BOOL CloseHandle(_In_ HANDLE hObject);

    static __int64 GetFilePos(HANDLE hFile);

private:
    static HANDLE       cachedHandle;
    static bool         openAsCache;
    static BYTE*        rawBuff;
    static unsigned int offset;
    static unsigned int length;
    static __int64      fileoffset;
};
#endif