nuclear@0: /************************************************************************** nuclear@0: nuclear@0: Filename : OVR_SysFile.cpp nuclear@0: Content : File wrapper class implementation (Win32) nuclear@0: nuclear@0: Created : April 5, 1999 nuclear@0: Authors : Michael Antonov nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: **************************************************************************/ nuclear@0: nuclear@0: #define GFILE_CXX nuclear@0: nuclear@0: // Standard C library (Captain Obvious guarantees!) nuclear@0: #include nuclear@0: nuclear@0: #include "OVR_SysFile.h" nuclear@0: #include "OVR_Log.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: // This is - a dummy file that fails on all calls. nuclear@0: nuclear@0: class UnopenedFile : public File nuclear@0: { nuclear@0: public: nuclear@0: UnopenedFile() { } nuclear@0: ~UnopenedFile() { } nuclear@0: nuclear@0: virtual const char* GetFilePath() { return 0; } nuclear@0: nuclear@0: // ** File Information nuclear@0: virtual bool IsValid() { return 0; } nuclear@0: virtual bool IsWritable() { return 0; } nuclear@0: nuclear@0: // Return position / file size nuclear@0: virtual int Tell() { return 0; } nuclear@0: virtual int64_t LTell() { return 0; } nuclear@0: virtual int GetLength() { return 0; } nuclear@0: virtual int64_t LGetLength() { return 0; } nuclear@0: nuclear@0: // virtual bool Stat(FileStats *pfs) { return 0; } nuclear@0: virtual int GetErrorCode() { return Error_FileNotFound; } nuclear@0: nuclear@0: // ** Stream implementation & I/O nuclear@0: virtual int Write(const uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; } nuclear@0: virtual int Read(uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; } nuclear@0: virtual int SkipBytes(int /*numBytes*/) { return 0; } nuclear@0: virtual int BytesAvailable() { return 0; } nuclear@0: virtual bool Flush() { return 0; } nuclear@0: virtual int Seek(int /*offset*/, int /*origin*/) { return -1; } nuclear@0: virtual int64_t LSeek(int64_t /*offset*/, int /*origin*/) { return -1; } nuclear@0: nuclear@0: virtual int CopyFromStream(File * /*pstream*/, int /*byteSize*/) { return -1; } nuclear@0: virtual bool Close() { return 0; } nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: nuclear@0: // ***** System File nuclear@0: nuclear@0: // System file is created to access objects on file system directly nuclear@0: // This file can refer directly to path nuclear@0: nuclear@0: // ** Constructor nuclear@0: SysFile::SysFile() : DelegatedFile(0) nuclear@0: { nuclear@0: pFile = *new UnopenedFile; nuclear@0: } nuclear@0: nuclear@0: Ptr FileFILEOpen(const String& path, int flags, int mode); nuclear@0: nuclear@0: // Opens a file nuclear@0: SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0) nuclear@0: { nuclear@0: Open(path, flags, mode); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // ** Open & management nuclear@0: // Will fail if file's already open nuclear@0: bool SysFile::Open(const String& path, int flags, int mode) nuclear@0: { nuclear@0: pFile = FileFILEOpen(path, flags, mode); nuclear@0: if ((!pFile) || (!pFile->IsValid())) nuclear@0: { nuclear@0: pFile = *new UnopenedFile; nuclear@0: OVR_DEBUG_LOG(("Failed to open file: %s", path.ToCStr())); nuclear@0: return 0; nuclear@0: } nuclear@0: //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing nuclear@0: if (flags & Open_Buffered) nuclear@0: pFile = *new BufferedFile(pFile); nuclear@0: return 1; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // ** Overrides nuclear@0: nuclear@0: int SysFile::GetErrorCode() nuclear@0: { nuclear@0: return pFile ? pFile->GetErrorCode() : Error_FileNotFound; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // Overrides to provide re-open support nuclear@0: bool SysFile::IsValid() nuclear@0: { nuclear@0: return pFile && pFile->IsValid(); nuclear@0: } nuclear@0: bool SysFile::Close() nuclear@0: { nuclear@0: if (IsValid()) nuclear@0: { nuclear@0: DelegatedFile::Close(); nuclear@0: pFile = *new UnopenedFile; nuclear@0: return 1; nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: } // OVR