OpenBarnyard
 
Loading...
Searching...
No Matches
TNativeFileSystem Class Reference

#include <TNativeFile_Win.h>

Inheritance diagram for TNativeFileSystem:
TFileSystem TGenericDList::TNode

Public Member Functions

 TNativeFileSystem (const TCHAR *name)
 
virtual ~TNativeFileSystem ()
 
virtual TFileCreateFile (const TString8 &a_rcFileName, TFILEMODE a_eFileMode) OVERRIDE
 Creates file.
 
virtual void DestroyFile (TFile *a_pFile) OVERRIDE
 Destroys specified file.
 
virtual TBOOL RemoveFile (const TString8 &a_rcFileName) OVERRIDE
 Removes specified file.
 
virtual TString8 MakeInternalPath (const TString8 &a_rcPath) OVERRIDE
 Not documented.
 
virtual TBOOL GetFirstFile (const TString8 &a_rcPath, TString8 &a_rOutFileName, TFINDFILE a_ui8Flags) OVERRIDE
 Finds out what's the first file at the specified path.
 
virtual TBOOL GetNextFile (TString8 &a_rOutFileName, TFINDFILE a_ui8Flags) OVERRIDE
 Not documented.
 
virtual TBOOL MakeDirectory (const TString8 &a_rcDirectory)
 
- Public Member Functions inherited from TFileSystem
 TFileSystem (const TCHAR *a_szName)
 
 TFileSystem (const TFileSystem &other)
 
virtual ~TFileSystem ()=default
 
virtual void SetPrefix (const TString8 &a_rcPrefix)
 Sets the directory prefix to work with.
 
virtual TBOOL ToNative (const TString8 &a_rcPath, TNativeFileInfo &a_rOutInfo)
 Fetches info about the path and returns internal path.
 
void UnmountFileSystem ()
 Unmounts this file system from the TFileManager.
 
const TString8GetName () const
 
const TString8GetPrefix () const
 
TFileSystemoperator= (TFileSystem &a_rFileSystem)
 
- Public Member Functions inherited from TGenericDList::TNode
template<typename T>
T * As ()
 
void Remove ()
 
void InsertAfter (TNode *a_pNode)
 
void InsertBefore (TNode *a_pNode)
 
TBOOL IsLinked () const
 

Additional Inherited Members

- Public Types inherited from TGenericDList::TNode
enum  TUninitialised { Unitiailised }
 
- Public Attributes inherited from TGenericDList::TNode
friend TGenericDList
 
- Protected Member Functions inherited from TGenericDList::TNode
 TNode ()
 
 TNode (TUninitialised)
 
 ~TNode ()
 
TNodeNext () const
 
TNodePrev () const
 
- Protected Attributes inherited from TFileSystem
TString8 m_Name
 
TString8 m_Prefix
 
TFileLookupHandle m_NextFileHandle
 
- Protected Attributes inherited from TGenericDList::TNode
TNodem_pNext
 
TNodem_pPrev
 

Detailed Description

Definition at line 6 of file TNativeFile_Win.h.

Constructor & Destructor Documentation

◆ TNativeFileSystem()

TNativeFileSystem::TNativeFileSystem ( const TCHAR * name)

Definition at line 19 of file TNativeFile_Win.cpp.

20 : TFileSystem( name )
21{
22 m_NextFileHandle = INVALID_HANDLE_VALUE;
24}
TFileSystem(const TCHAR *a_szName)
TFileLookupHandle m_NextFileHandle
Definition TFile.h:124
void MountFileSystem(TFileSystem *a_pFileSystem)
static TFORCEINLINE TFileManager * GetSingletonSafe()
Definition TSingleton.h:37

◆ ~TNativeFileSystem()

TNativeFileSystem::~TNativeFileSystem ( )
virtual

Definition at line 26 of file TNativeFile_Win.cpp.

27{
29}
void UnmountFileSystem()
Unmounts this file system from the TFileManager.
Definition TFile.h:114

Member Function Documentation

◆ CreateFile()

TFile * TNativeFileSystem::CreateFile ( const TString8 & a_rcFileName,
TFILEMODE a_eFileMode )
virtual

Creates file.

Parameters
a_rcFileNamepath to the file to open
a_eFileModemode to open the file with
Returns
pointer to the opened file or TNULL if couldn't open

Implements TFileSystem.

Definition at line 31 of file TNativeFile_Win.cpp.

32{
33 TNativeFile* nativeFile = new TNativeFile( this );
34
35 if ( !nativeFile->Open( a_rcFileName, a_eFileMode ) )
36 {
37 delete nativeFile;
38 return TNULL;
39 }
40
41 return nativeFile;
42}
#define TNULL
Definition Typedefs.h:23
TBOOL Open(const TString8 &a_FileName, TFILEMODE a_Mode)

◆ DestroyFile()

void TNativeFileSystem::DestroyFile ( TFile * a_pFile)
virtual

Destroys specified file.

Implements TFileSystem.

Definition at line 44 of file TNativeFile_Win.cpp.

45{
46 if ( file != TNULL )
47 {
48 TSTATICCAST( TNativeFile, file )->Close();
49 delete file;
50 }
51}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69

◆ GetFirstFile()

TBOOL TNativeFileSystem::GetFirstFile ( const TString8 & a_rcPath,
TString8 & a_rOutFileName,
TFINDFILE a_ui8Flags )
virtual

Finds out what's the first file at the specified path.

Reimplemented from TFileSystem.

Definition at line 90 of file TNativeFile_Win.cpp.

91{
92 TString8 strPath( a_rcPath );
93
94 // Okay... I know using TString8::Mid here is kinda original but that's how it works in the original
95 const char* pchFilter =
96 ( strPath.Mid( strPath.Length() - 1, 1 ).Compare( "\\" ) != 0 &&
97 strPath.Mid( strPath.Length() - 1, 1 ).Compare( "/" ) != 0 ) ?
98 "\\*" :
99 "*";
100
101 strPath += pchFilter;
102
103 WIN32_FIND_DATAA oFindData;
104 HANDLE hFirstFile = FindFirstFileA( strPath, &oFindData );
105 m_NextFileHandle = hFirstFile;
106
107 if ( hFirstFile != INVALID_HANDLE_VALUE )
108 {
109 TFINDFILE ui8MaskedFlags;
110
111 if ( oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
112 ui8MaskedFlags = a_ui8Flags & TFINDFILE_DIRECTORY;
113 else
114 ui8MaskedFlags = a_ui8Flags & TFINDFILE_FILE;
115
116 if ( ui8MaskedFlags != 0 )
117 {
118 a_rOutFileName = oFindData.cFileName;
119 return TTRUE;
120 }
121 }
122
123 return TFALSE;
124}
TUINT8 TFINDFILE
Definition TFile.h:45
@ TFINDFILE_DIRECTORY
Definition TFile.h:49
@ TFINDFILE_FILE
Definition TFile.h:48
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25

◆ GetNextFile()

TBOOL TNativeFileSystem::GetNextFile ( TString8 & a_rOutFileName,
TFINDFILE a_ui8Flags )
virtual

Not documented.

Reimplemented from TFileSystem.

Definition at line 131 of file TNativeFile_Win.cpp.

132{
133 WIN32_FIND_DATAA findFileData;
134
135 if ( m_NextFileHandle != INVALID_HANDLE_VALUE )
136 {
137 TBOOL bResult = FindNextFileA( m_NextFileHandle, &findFileData );
138 if ( !bResult )
139 {
140 m_NextFileHandle = INVALID_HANDLE_VALUE;
141 }
142 else if ( findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
143 {
144 if ( a_ui8Flags & TFINDFILE_DIRECTORY )
145 {
146 a_rOutFileName = findFileData.cFileName;
147 return TTRUE;
148 }
149 }
150 else if ( a_ui8Flags & TFINDFILE_FILE )
151 {
152 a_rOutFileName = findFileData.cFileName;
153 return TTRUE;
154 }
155 }
156
157 return TFALSE;
158}
bool TBOOL
Definition Typedefs.h:6

◆ MakeDirectory()

TBOOL TNativeFileSystem::MakeDirectory ( const TString8 & a_rcDirectory)
virtual

Definition at line 126 of file TNativeFile_Win.cpp.

127{
128 return CreateDirectoryA( string, TNULL );
129}

◆ MakeInternalPath()

TString8 TNativeFileSystem::MakeInternalPath ( const TString8 & a_rcPath)
virtual

Not documented.

Implements TFileSystem.

Definition at line 58 of file TNativeFile_Win.cpp.

59{
60 // Check if it's already an absolute path
61 if ( a_rcPath.Compare( "//", 2 ) == 0 ||
62 a_rcPath.Compare( "\\\\", 2 ) == 0 ||
63 ( a_rcPath.Length() >= 2 && a_rcPath[ 1 ] == ':' ) )
64 {
65 // Seems that the path is already an absolute path
66 TString8 strInternalPath = a_rcPath;
67 FixPathSlashes( strInternalPath );
68
69 return strInternalPath;
70 }
71
72 // It's definitely not an absolute path so let's make one
73 TString8 strInternalPath = m_Prefix;
74
75 // Remove slash at the end of the prefix
76 if ( strInternalPath.Length() > 0 )
77 {
78 TCHAR cLastChar = strInternalPath[ strInternalPath.Length() - 1 ];
79
80 if ( cLastChar == '/' || cLastChar == '\\' )
81 strInternalPath.Truncate( strInternalPath.Length() - 1 );
82 }
83
84 strInternalPath += TFileManager::GetSingleton()->MakeAbsolutePath( a_rcPath );
85 FixPathSlashes( strInternalPath );
86
87 return strInternalPath;
88}
void FixPathSlashes(TString8 &a_rPath)
char TCHAR
Definition Typedefs.h:20
TString8 m_Prefix
Definition TFile.h:123
TString8 MakeAbsolutePath(const TString8 &a_rcRelativePath) const
static TFORCEINLINE TFileManager * GetSingleton()
Definition TSingleton.h:49
TINT Compare(const TCHAR *a_szString, TINT a_iLength=-1) const
Definition TString8.cpp:362
void Truncate(TINT length)
Definition TString8.cpp:257
TINT Length() const
Definition TString8.h:93

◆ RemoveFile()

TBOOL TNativeFileSystem::RemoveFile ( const TString8 & a_rcFileName)
virtual

Removes specified file.

Reimplemented from TFileSystem.

Definition at line 53 of file TNativeFile_Win.cpp.

54{
55 return DeleteFileA( a_rcFileName ) != 0;
56}

The documentation for this class was generated from the following files: