Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfx_fileaccess_windows.cpp
Go to the documentation of this file.
1
// Copyright 2014 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxcrt/cfx_fileaccess_windows.h"
8
9
#
include
<
memory
>
10
11
#
include
"core/fxcrt/fx_stream.h"
12
#
include
"core/fxcrt/fx_string.h"
13
14
// static
15
std::unique_ptr<FileAccessIface>
FileAccessIface
::Create() {
16
return
std
::make_unique<CFX_FileAccess_Windows>();
17
}
18
19
CFX_FileAccess_Windows::
CFX_FileAccess_Windows
() =
default
;
20
21
CFX_FileAccess_Windows::~
CFX_FileAccess_Windows
() {
22
Close
(
)
;
23
}
24
25
bool
CFX_FileAccess_Windows::
Open
(
ByteStringView
fileName) {
26
if
(m_hFile)
27
return
false
;
28
29
WideString
wname =
WideString
::
FromUTF8
(
fileName
)
;
30
m_hFile = ::CreateFileW(wname.c_str(), GENERIC_READ,
31
FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr
,
32
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr
);
33
if
(m_hFile == INVALID_HANDLE_VALUE)
34
m_hFile =
nullptr
;
35
36
return
!!m_hFile;
37
}
38
39
void
CFX_FileAccess_Windows::
Close
() {
40
if
(!m_hFile)
41
return
;
42
43
::CloseHandle(m_hFile);
44
m_hFile =
nullptr
;
45
}
46
47
FX_FILESIZE
CFX_FileAccess_Windows::
GetSize
()
const
{
48
if
(!m_hFile)
49
return
0;
50
51
LARGE_INTEGER size = {};
52
if
(!::GetFileSizeEx(m_hFile, &size))
53
return
0;
54
55
return
(
FX_FILESIZE
)size.QuadPart;
56
}
57
58
FX_FILESIZE
CFX_FileAccess_Windows::
GetPosition
()
const
{
59
if
(!m_hFile)
60
return
(
FX_FILESIZE
)-1;
61
62
LARGE_INTEGER dist = {};
63
LARGE_INTEGER newPos = {};
64
if
(!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_CURRENT))
65
return
(
FX_FILESIZE
)-1;
66
67
return
(
FX_FILESIZE
)newPos.QuadPart;
68
}
69
70
FX_FILESIZE
CFX_FileAccess_Windows::
SetPosition
(
FX_FILESIZE
pos) {
71
if
(!m_hFile)
72
return
(
FX_FILESIZE
)-1;
73
74
LARGE_INTEGER dist;
75
dist.QuadPart = pos;
76
LARGE_INTEGER newPos = {};
77
if
(!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN))
78
return
(
FX_FILESIZE
)-1;
79
80
return
(
FX_FILESIZE
)newPos.QuadPart;
81
}
82
83
size_t
CFX_FileAccess_Windows::
Read
(pdfium::span<uint8_t> buffer) {
84
if
(!m_hFile)
85
return
0;
86
87
size_t szRead = 0;
88
if
(!::ReadFile(m_hFile, buffer.data(), (DWORD)buffer.size(),
89
(LPDWORD)&szRead,
nullptr
)) {
90
return
0;
91
}
92
return
szRead;
93
}
94
95
size_t
CFX_FileAccess_Windows::
Write
(pdfium::span<
const
uint8_t> buffer) {
96
if
(!m_hFile)
97
return
0;
98
99
size_t szWrite = 0;
100
if
(!::WriteFile(m_hFile, buffer.data(), (DWORD)buffer.size(),
101
(LPDWORD)&szWrite,
nullptr
)) {
102
return
0;
103
}
104
return
szWrite;
105
}
106
107
size_t
CFX_FileAccess_Windows::
ReadPos
(pdfium::span<uint8_t> buffer,
108
FX_FILESIZE
pos) {
109
if
(!m_hFile)
110
return
0;
111
112
if
(pos >=
GetSize
(
)
)
113
return
0;
114
115
if
(
SetPosition
(
pos
)
== (
FX_FILESIZE
)-1)
116
return
0;
117
118
return
Read(buffer);
119
}
120
121
bool
CFX_FileAccess_Windows::
Flush
() {
122
if
(!m_hFile)
123
return
false
;
124
125
return
!!::FlushFileBuffers(m_hFile);
126
}
127
128
bool
CFX_FileAccess_Windows::
Truncate
(
FX_FILESIZE
szFile) {
129
if
(
SetPosition
(
szFile
)
== (
FX_FILESIZE
)-1)
130
return
false
;
131
132
return
!!::SetEndOfFile(m_hFile);
133
}
CFX_FileAccess_Windows::CFX_FileAccess_Windows
CFX_FileAccess_Windows()
CFX_FileAccess_Windows::ReadPos
size_t ReadPos(pdfium::span< uint8_t > buffer, FX_FILESIZE pos) override
Definition
cfx_fileaccess_windows.cpp:107
CFX_FileAccess_Windows::Open
bool Open(ByteStringView fileName) override
Definition
cfx_fileaccess_windows.cpp:25
CFX_FileAccess_Windows::Write
size_t Write(pdfium::span< const uint8_t > buffer) override
Definition
cfx_fileaccess_windows.cpp:95
CFX_FileAccess_Windows::Read
size_t Read(pdfium::span< uint8_t > buffer) override
Definition
cfx_fileaccess_windows.cpp:83
CFX_FileAccess_Windows::GetSize
FX_FILESIZE GetSize() const override
Definition
cfx_fileaccess_windows.cpp:47
CFX_FileAccess_Windows::Close
void Close() override
Definition
cfx_fileaccess_windows.cpp:39
CFX_FileAccess_Windows::SetPosition
FX_FILESIZE SetPosition(FX_FILESIZE pos) override
Definition
cfx_fileaccess_windows.cpp:70
CFX_FileAccess_Windows::Flush
bool Flush() override
Definition
cfx_fileaccess_windows.cpp:121
CFX_FileAccess_Windows::GetPosition
FX_FILESIZE GetPosition() const override
Definition
cfx_fileaccess_windows.cpp:58
CFX_FileAccess_Windows::Truncate
bool Truncate(FX_FILESIZE szFile) override
Definition
cfx_fileaccess_windows.cpp:128
CFX_FileAccess_Windows::~CFX_FileAccess_Windows
~CFX_FileAccess_Windows() override
Definition
cfx_fileaccess_windows.cpp:21
FileAccessIface
Definition
fileaccess_iface.h:15
fxcrt::WideString::FromUTF8
static WideString FromUTF8(ByteStringView str)
Definition
widestring.cpp:738
FX_FILESIZE
#define FX_FILESIZE
Definition
fx_types.h:19
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
ByteStringView
fxcrt::ByteStringView ByteStringView
Definition
string_view_template.h:325
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
cfx_fileaccess_windows.cpp
Generated on
for Qt by
1.18.0