rev |
line source |
nuclear@1
|
1 /**************************************************************************
|
nuclear@1
|
2
|
nuclear@1
|
3 Filename : OVR_SysFile.cpp
|
nuclear@1
|
4 Content : File wrapper class implementation (Win32)
|
nuclear@1
|
5
|
nuclear@1
|
6 Created : April 5, 1999
|
nuclear@1
|
7 Authors : Michael Antonov
|
nuclear@1
|
8
|
nuclear@1
|
9 Copyright : Copyright 2011 Oculus VR, Inc. All Rights reserved.
|
nuclear@1
|
10
|
nuclear@1
|
11 Use of this software is subject to the terms of the Oculus license
|
nuclear@1
|
12 agreement provided at the time of installation or download, or which
|
nuclear@1
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@1
|
14
|
nuclear@1
|
15 **************************************************************************/
|
nuclear@1
|
16
|
nuclear@1
|
17 #define GFILE_CXX
|
nuclear@1
|
18
|
nuclear@1
|
19 // Standard C library (Captain Obvious guarantees!)
|
nuclear@1
|
20 #include <stdio.h>
|
nuclear@1
|
21
|
nuclear@1
|
22 #include "OVR_SysFile.h"
|
nuclear@1
|
23
|
nuclear@1
|
24 namespace OVR {
|
nuclear@1
|
25
|
nuclear@1
|
26 // This is - a dummy file that fails on all calls.
|
nuclear@1
|
27
|
nuclear@1
|
28 class UnopenedFile : public File
|
nuclear@1
|
29 {
|
nuclear@1
|
30 public:
|
nuclear@1
|
31 UnopenedFile() { }
|
nuclear@1
|
32 ~UnopenedFile() { }
|
nuclear@1
|
33
|
nuclear@1
|
34 virtual const char* GetFilePath() { return 0; }
|
nuclear@1
|
35
|
nuclear@1
|
36 // ** File Information
|
nuclear@1
|
37 virtual bool IsValid() { return 0; }
|
nuclear@1
|
38 virtual bool IsWritable() { return 0; }
|
nuclear@1
|
39
|
nuclear@1
|
40 // Return position / file size
|
nuclear@1
|
41 virtual int Tell() { return 0; }
|
nuclear@1
|
42 virtual SInt64 LTell() { return 0; }
|
nuclear@1
|
43 virtual int GetLength() { return 0; }
|
nuclear@1
|
44 virtual SInt64 LGetLength() { return 0; }
|
nuclear@1
|
45
|
nuclear@1
|
46 // virtual bool Stat(FileStats *pfs) { return 0; }
|
nuclear@1
|
47 virtual int GetErrorCode() { return Error_FileNotFound; }
|
nuclear@1
|
48
|
nuclear@1
|
49 // ** Stream implementation & I/O
|
nuclear@1
|
50 virtual int Write(const UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
|
nuclear@1
|
51 virtual int Read(UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
|
nuclear@1
|
52 virtual int SkipBytes(int numBytes) { return 0; OVR_UNUSED(numBytes); }
|
nuclear@1
|
53 virtual int BytesAvailable() { return 0; }
|
nuclear@1
|
54 virtual bool Flush() { return 0; }
|
nuclear@1
|
55 virtual int Seek(int offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
|
nuclear@1
|
56 virtual SInt64 LSeek(SInt64 offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
|
nuclear@1
|
57
|
nuclear@1
|
58 virtual int CopyFromStream(File *pstream, int byteSize) { return -1; OVR_UNUSED2(pstream, byteSize); }
|
nuclear@1
|
59 virtual bool Close() { return 0; }
|
nuclear@1
|
60 };
|
nuclear@1
|
61
|
nuclear@1
|
62
|
nuclear@1
|
63
|
nuclear@1
|
64 // ***** System File
|
nuclear@1
|
65
|
nuclear@1
|
66 // System file is created to access objects on file system directly
|
nuclear@1
|
67 // This file can refer directly to path
|
nuclear@1
|
68
|
nuclear@1
|
69 // ** Constructor
|
nuclear@1
|
70 SysFile::SysFile() : DelegatedFile(0)
|
nuclear@1
|
71 {
|
nuclear@1
|
72 pFile = *new UnopenedFile;
|
nuclear@1
|
73 }
|
nuclear@1
|
74
|
nuclear@1
|
75 File* FileFILEOpen(const String& path, int flags, int mode);
|
nuclear@1
|
76
|
nuclear@1
|
77 // Opens a file
|
nuclear@1
|
78 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
|
nuclear@1
|
79 {
|
nuclear@1
|
80 Open(path, flags, mode);
|
nuclear@1
|
81 }
|
nuclear@1
|
82
|
nuclear@1
|
83
|
nuclear@1
|
84 // ** Open & management
|
nuclear@1
|
85 // Will fail if file's already open
|
nuclear@1
|
86 bool SysFile::Open(const String& path, int flags, int mode)
|
nuclear@1
|
87 {
|
nuclear@1
|
88 pFile = *FileFILEOpen(path, flags, mode);
|
nuclear@1
|
89 if ((!pFile) || (!pFile->IsValid()))
|
nuclear@1
|
90 {
|
nuclear@1
|
91 pFile = *new UnopenedFile;
|
nuclear@1
|
92 return 0;
|
nuclear@1
|
93 }
|
nuclear@1
|
94 //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
|
nuclear@1
|
95 if (flags & Open_Buffered)
|
nuclear@1
|
96 pFile = *new BufferedFile(pFile);
|
nuclear@1
|
97 return 1;
|
nuclear@1
|
98 }
|
nuclear@1
|
99
|
nuclear@1
|
100
|
nuclear@1
|
101 // ** Overrides
|
nuclear@1
|
102
|
nuclear@1
|
103 int SysFile::GetErrorCode()
|
nuclear@1
|
104 {
|
nuclear@1
|
105 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
|
nuclear@1
|
106 }
|
nuclear@1
|
107
|
nuclear@1
|
108
|
nuclear@1
|
109 // Overrides to provide re-open support
|
nuclear@1
|
110 bool SysFile::IsValid()
|
nuclear@1
|
111 {
|
nuclear@1
|
112 return pFile && pFile->IsValid();
|
nuclear@1
|
113 }
|
nuclear@1
|
114 bool SysFile::Close()
|
nuclear@1
|
115 {
|
nuclear@1
|
116 if (IsValid())
|
nuclear@1
|
117 {
|
nuclear@1
|
118 DelegatedFile::Close();
|
nuclear@1
|
119 pFile = *new UnopenedFile;
|
nuclear@1
|
120 return 1;
|
nuclear@1
|
121 }
|
nuclear@1
|
122 return 0;
|
nuclear@1
|
123 }
|
nuclear@1
|
124
|
nuclear@1
|
125 } // OVR
|