summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Kernel/OVR_FileFILE.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-21 21:19:34 +0100
committerSven Gothel <[email protected]>2015-03-21 21:19:34 +0100
commite490c3c7f7bb5461cfa78a214827aa534fb43a3e (patch)
treeb86b0291ef529ec6b75cc548d73599fa9c283cd6 /LibOVR/Src/Kernel/OVR_FileFILE.cpp
parent05bb4364bfd9930fb1902efec86446ef035ee07a (diff)
Bump OculusVR RIFT SDK to 0.4.4
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_FileFILE.cpp')
-rw-r--r--LibOVR/Src/Kernel/OVR_FileFILE.cpp88
1 files changed, 51 insertions, 37 deletions
diff --git a/LibOVR/Src/Kernel/OVR_FileFILE.cpp b/LibOVR/Src/Kernel/OVR_FileFILE.cpp
index 8478086..9b2123f 100644
--- a/LibOVR/Src/Kernel/OVR_FileFILE.cpp
+++ b/LibOVR/Src/Kernel/OVR_FileFILE.cpp
@@ -6,16 +6,16 @@ Content : File wrapper class implementation (Win32)
Created : April 5, 1999
Authors : Michael Antonov
-Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
+Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
-Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
+Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
-http://www.oculusvr.com/licenses/LICENSE-3.1
+http://www.oculusvr.com/licenses/LICENSE-3.2
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
@@ -60,7 +60,8 @@ static int SFerror ()
return FileConstants::Error_IOError;
};
-#ifdef OVR_OS_WIN32
+#if defined(OVR_OS_WIN32)
+#define WIN32_LEAN_AND_MEAN
#include "windows.h"
// A simple helper class to disable/enable system error mode, if necessary
// Disabling happens conditionally only if a drive name is involved
@@ -73,16 +74,20 @@ public:
{
if (pfileName && (pfileName[0]!=0) && pfileName[1]==':')
{
- Disabled = 1;
+ Disabled = TRUE;
OldMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
}
else
+ {
Disabled = 0;
+ OldMode = 0;
+ }
}
~SysErrorModeDisabler()
{
- if (Disabled) ::SetErrorMode(OldMode);
+ if (Disabled)
+ ::SetErrorMode(OldMode);
}
};
#else
@@ -121,25 +126,31 @@ protected:
int LastOp;
#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
- UByte* pFileTestBuffer;
+ uint8_t* pFileTestBuffer;
unsigned FileTestLength;
unsigned TestPos; // File pointer position during tests.
#endif
public:
- FILEFile()
+ FILEFile() :
+ FileName(),
+ Opened(false),
+ fs(NULL),
+ OpenFlags(0),
+ ErrorCode(0),
+ LastOp(0)
+ #ifdef OVR_FILE_VERIFY_SEEK_ERRORS
+ ,pFileTestBuffer(NULL)
+ ,FileTestLength(0)
+ ,TestPos(0)
+ #endif
{
- Opened = 0; FileName = "";
-
-#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
- pFileTestBuffer =0;
- FileTestLength =0;
- TestPos =0;
-#endif
}
+
// Initialize file by opening it
FILEFile(const String& fileName, int flags, int Mode);
+
// The 'pfileName' should be encoded as UTF-8 to support international file names.
FILEFile(const char* pfileName, int flags, int Mode);
@@ -157,21 +168,21 @@ public:
// Return position / file size
virtual int Tell();
- virtual SInt64 LTell();
+ virtual int64_t LTell();
virtual int GetLength();
- virtual SInt64 LGetLength();
+ virtual int64_t LGetLength();
// virtual bool Stat(FileStats *pfs);
virtual int GetErrorCode();
// ** Stream implementation & I/O
- virtual int Write(const UByte *pbuffer, int numBytes);
- virtual int Read(UByte *pbuffer, int numBytes);
+ virtual int Write(const uint8_t *pbuffer, int numBytes);
+ virtual int Read(uint8_t *pbuffer, int numBytes);
virtual int SkipBytes(int numBytes);
virtual int BytesAvailable();
virtual bool Flush();
virtual int Seek(int offset, int origin);
- virtual SInt64 LSeek(SInt64 offset, int origin);
+ virtual int64_t LSeek(int64_t offset, int origin);
virtual int CopyFromStream(File *pStream, int byteSize);
virtual bool Close();
@@ -218,7 +229,7 @@ void FILEFile::init()
else if (OpenFlags & Open_Write)
omode = "r+b";
-#ifdef OVR_OS_WIN32
+#if defined(OVR_OS_MS)
SysErrorModeDisabler disabler(FileName.ToCStr());
#endif
@@ -248,7 +259,7 @@ void FILEFile::init()
fseek(fs, 0, SEEK_END);
FileTestLength = ftell(fs);
fseek(fs, 0, SEEK_SET);
- pFileTestBuffer = (UByte*)OVR_ALLOC(FileTestLength);
+ pFileTestBuffer = (uint8_t*)OVR_ALLOC(FileTestLength);
if (pFileTestBuffer)
{
OVR_ASSERT(FileTestLength == (unsigned)Read(pFileTestBuffer, FileTestLength));
@@ -293,9 +304,9 @@ int FILEFile::Tell()
return pos;
}
-SInt64 FILEFile::LTell()
+int64_t FILEFile::LTell()
{
- SInt64 pos = ftell(fs);
+ int64_t pos = ftell(fs);
if (pos < 0)
ErrorCode = SFerror();
return pos;
@@ -313,13 +324,13 @@ int FILEFile::GetLength()
}
return -1;
}
-SInt64 FILEFile::LGetLength()
+int64_t FILEFile::LGetLength()
{
- SInt64 pos = LTell();
+ int64_t pos = LTell();
if (pos >= 0)
{
LSeek (0, Seek_End);
- SInt64 size = LTell();
+ int64_t size = LTell();
LSeek (pos, Seek_Set);
return size;
}
@@ -332,7 +343,7 @@ int FILEFile::GetErrorCode()
}
// ** Stream implementation & I/O
-int FILEFile::Write(const UByte *pbuffer, int numBytes)
+int FILEFile::Write(const uint8_t *pbuffer, int numBytes)
{
if (LastOp && LastOp != Open_Write)
fflush(fs);
@@ -349,7 +360,7 @@ int FILEFile::Write(const UByte *pbuffer, int numBytes)
return written;
}
-int FILEFile::Read(UByte *pbuffer, int numBytes)
+int FILEFile::Read(uint8_t *pbuffer, int numBytes)
{
if (LastOp && LastOp != Open_Read)
fflush(fs);
@@ -362,7 +373,7 @@ int FILEFile::Read(UByte *pbuffer, int numBytes)
if (read > 0)
{
// Read-in data must match our pre-loaded buffer data!
- UByte* pcompareBuffer = pFileTestBuffer + TestPos;
+ uint8_t* pcompareBuffer = pFileTestBuffer + TestPos;
for (int i=0; i< read; i++)
{
OVR_ASSERT(pcompareBuffer[i] == pbuffer[i]);
@@ -380,8 +391,8 @@ int FILEFile::Read(UByte *pbuffer, int numBytes)
// Seeks ahead to skip bytes
int FILEFile::SkipBytes(int numBytes)
{
- SInt64 pos = LTell();
- SInt64 newPos = LSeek(numBytes, Seek_Cur);
+ int64_t pos = LTell();
+ int64_t newPos = LSeek(numBytes, Seek_Cur);
// Return -1 for major error
if ((pos==-1) || (newPos==-1))
@@ -396,8 +407,8 @@ int FILEFile::SkipBytes(int numBytes)
// Return # of bytes till EOF
int FILEFile::BytesAvailable()
{
- SInt64 pos = LTell();
- SInt64 endPos = LGetLength();
+ int64_t pos = LTell();
+ int64_t endPos = LGetLength();
// Return -1 for major error
if ((pos==-1) || (endPos==-1))
@@ -452,14 +463,14 @@ int FILEFile::Seek(int offset, int origin)
return (int)Tell();
}
-SInt64 FILEFile::LSeek(SInt64 offset, int origin)
+int64_t FILEFile::LSeek(int64_t offset, int origin)
{
return Seek((int)offset,origin);
}
int FILEFile::CopyFromStream(File *pstream, int byteSize)
{
- UByte buff[0x4000];
+ uint8_t* buff = new uint8_t[0x4000];
int count = 0;
int szRequest, szRead, szWritten;
@@ -477,6 +488,9 @@ int FILEFile::CopyFromStream(File *pstream, int byteSize)
if (szWritten < szRequest)
break;
}
+
+ delete[] buff;
+
return count;
}
@@ -570,7 +584,7 @@ Ptr<File> FileFILEOpen(const String& path, int flags, int mode)
// Helper function: obtain file information time.
bool SysFile::GetFileStat(FileStat* pfileStat, const String& path)
{
-#if defined(OVR_OS_WIN32)
+#if defined(OVR_OS_MS)
// 64-bit implementation on Windows.
struct __stat64 fileStat;
// Stat returns 0 for success.