MCPcopy Create free account
hub / github.com/StrongPC123/Far-Cry-1-Source-Full / StartRead

Method StartRead

CrySystem/RefReadStreamProxy.cpp:147–269  ·  view source on GitHub ↗

the interface for the actual stream returns true if the read has been started and no further attempts to do so are required returns false if couldn't start,and retry is required nMemQuota is the max number of bytes to allocate from the Engine's "Big Heap" for the piece of file that is read. Pass a big value to let it allocate as much as it wants.

Source from the content-addressed store, hash-verified

145// nMemQuota is the max number of bytes to allocate from the Engine's "Big Heap" for the piece of file
146// that is read. Pass a big value to let it allocate as much as it wants.
147bool CRefReadStreamProxy::StartRead (unsigned nMemQuota)
148{
149 if (m_bError || m_bFinished || m_bPending)
150 {
151 // Why this assert happened?
152 //---------------------------
153 // THe stream read was automatically initiated, while the stream is marked as
154 // having been read, being read, or failed, i.e. it can't be restarted again.
155
156 // This can generally happen when the read has been started, and immediately aborted,
157 // while being put on hold. When there are enough IO resources to start reading it,
158 // we detect that it's been already aborted and don't restart it.
159 // This is the only known reason for that.
160 assert (m_nIOError == ERROR_USER_ABORT);
161 return true; // invalid call, no need to retry
162 }
163
164 if (!m_pStream->Activate())
165 {
166 OnFinishRead(ERROR_CANT_OPEN_FILE); // can't open file
167 return true; // no need to retry
168 }
169
170 if (m_pStream->IsError())
171 {
172 OnFinishRead(ERROR_REFSTREAM_ERROR); // file is invalid
173 return true;
174 }
175
176 if (m_Params.nOffset >= m_pStream->GetFileSize())
177 {
178 // offset out of range
179 OnFinishRead(ERROR_OFFSET_OUT_OF_RANGE);
180 return true;
181 }
182
183 if (m_Params.nSize > m_pStream->GetFileSize())
184 {
185 OnFinishRead(ERROR_SIZE_OUT_OF_RANGE);
186 return true;
187 }
188
189 if (m_Params.nSize == 0)
190 {
191 // by default, we read the whole file
192 m_Params.nSize = m_pStream->GetFileSize() - m_Params.nOffset;
193 }
194 else
195 if (m_Params.nOffset + m_Params.nSize > m_pStream->GetFileSize())
196 {
197 // it's impossible to read the specified region of the file
198 OnFinishRead(ERROR_REGION_OUT_OF_RANGE);
199 return true;
200 }
201
202 if (!m_pBuffer)
203 {
204 if (nMemQuota < m_Params.nSize)

Callers

nothing calls this directly

Calls 13

GetPakVarsMethod · 0.80
GetEngineMethod · 0.80
isOverlappedMethod · 0.80
minFunction · 0.50
ActivateMethod · 0.45
IsErrorMethod · 0.45
GetFileSizeMethod · 0.45
AllocMethod · 0.45
GetFileMethod · 0.45
GetPakMethod · 0.45
AddRefMethod · 0.45
StreamOnProgressMethod · 0.45

Tested by

no test coverage detected