MCPcopy Create free account
hub / github.com/demoth/jake2 / FOpenFile

Method FOpenFile

qcommon/src/main/java/jake2/qcommon/filesystem/FS.java:215–270  ·  view source on GitHub ↗

FOpenFile Finds the file in the search path. returns a RadomAccesFile. Used for streaming data out of either a pak file or a separate file. @return null in case of error

(String filename)

Source from the content-addressed store, hash-verified

213 * @return null in case of error
214 */
215 public static QuakeFile FOpenFile(String filename) {
216
217
218 try {
219 // used for tools
220 // todo: unify with other code
221 if (filename.startsWith("/")) {
222 final File file = new File(filename);
223 return new QuakeFile(file, "r", false, file.length());
224 }
225
226 // check for links first
227 for (filelink_t link : fs_links) {
228 if (filename.startsWith(link.from)) {
229 File file = new File(link.to + filename.substring(link.from.length()));
230 if (file.canRead()) {
231 return new QuakeFile(file, "r", false, file.length());
232 }
233 }
234 }
235
236 //
237 // search through the path, one element at a time
238 //
239 for (SearchPath searchPath : searchPaths) {
240 if (searchPath.pack != null) {
241 packfile_t fileInPak = searchPath.pack.files.get(filename.toLowerCase());
242
243 if (fileInPak != null) {
244 // found it!
245 File file = new File(searchPath.pack.filename);
246 if (!file.canRead())
247 Com.Error(Defines.ERR_FATAL, "Couldn't reopen " + searchPath.pack.filename + '\n');
248 if (searchPath.pack.handle == null || !searchPath.pack.handle.getFD().valid()) {
249 // hold the pakfile handle open
250 searchPath.pack.handle = new RandomAccessFile(searchPath.pack.filename, "r");
251 }
252 // open a new file on the pakfile
253
254 QuakeFile qf = new QuakeFile(file, "r", true, fileInPak.filelen);
255 qf.seek(fileInPak.filepos);
256 return qf;
257 }
258
259 } else {
260 File file = new File(searchPath.filename + '/' + filename);
261 if (file.exists() && file.canRead()) {
262 return new QuakeFile(file, "r", false, file.length());
263 }
264 }
265 }
266 } catch (Exception e) {
267 Com.Printf("Could not open the file " + filename + " due to " + e.getMessage() + '\n');
268 }
269 return null;
270 }
271
272 // read in blocks of 64k

Callers 3

SV_BeginDownload_fMethod · 0.95
FileExistsMethod · 0.95
LoadFileMethod · 0.95

Calls 3

ErrorMethod · 0.95
PrintfMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected