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

#include <TFile.h>

Inheritance diagram for TFileManager:
TSingleton< TFileManager >

Classes

class  TSysPathIter
 

Public Member Functions

 TFileManager ()
 
 ~TFileManager ()
 
void Destroy ()
 
void MountFileSystem (TFileSystem *a_pFileSystem)
 
TFileCreateFile (const TString8 &a_strName, TFILEMODE flags)
 
TBOOL GetFileInfo (const TString8 &a_strPath, TNativeFileInfo &a_rNativeInfo)
 
TFileSystemFindFileSystem (const TString8 &name)
 
TString8 MakeAbsolutePath (const TString8 &a_rcRelativePath) const
 
void SetSystemPath (const TString8 &name)
 
- Public Member Functions inherited from TSingleton< TFileManager >
 TSingleton (const TSingleton &)=delete
 
 TSingleton (const TSingleton &&)=delete
 
TSingletonoperator= (const TSingleton &)=delete
 
TSingletonoperator= (const TSingleton &&)=delete
 

Static Public Member Functions

static TFileSystemFindFileSystem (TDList< TFileSystem > &list, const TString8 &name)
 
static TBOOL Create ()
 
static void FileSystemRelease ()
 
static void FileSystemWait ()
 
- Static Public Member Functions inherited from TSingleton< TFileManager >
static TFORCEINLINE TFileManagerCreateSingleton (Args &&... args)
 
static TFORCEINLINE D * CreateSingleton (Args &&... args)
 
static TFORCEINLINE void DestroySingleton ()
 
static TFORCEINLINE TFileManagerGetSingletonSafe ()
 
static TFORCEINLINE TBOOL IsSingletonCreated ()
 
static TFORCEINLINE TFileManagerGetSingleton ()
 

Static Public Attributes

static TMutex ms_oMutex
 

Additional Inherited Members

- Protected Member Functions inherited from TSingleton< TFileManager >
TFORCEINLINE TSingleton ()
 
TFORCEINLINE ~TSingleton ()
 
- Static Protected Attributes inherited from TSingleton< TFileManager >
static TFileManagerms_pSingleton
 

Detailed Description

Definition at line 233 of file TFile.h.

Constructor & Destructor Documentation

◆ TFileManager()

TFileManager::TFileManager ( )

Definition at line 24 of file TFileManager.cpp.

25 : m_WorkingDirectory( "/" ), m_ValidatedCount( 0 )
26{
27 InvalidateSystemPath();
28}

◆ ~TFileManager()

TFileManager::~TFileManager ( )

Definition at line 30 of file TFileManager.cpp.

31{
32 Destroy();
33}

Member Function Documentation

◆ Create()

TBOOL TFileManager::Create ( )
static

Definition at line 15 of file TFileManager_Win.cpp.

16{
17 CreateCommon();
18 auto fileManager = TFileManager::GetSingletonSafe();
19
20 CHAR currentDir[ 0x200 ];
21 DWORD dirLength = GetCurrentDirectoryA( sizeof( currentDir ), currentDir );
22 TASSERT( dirLength > 0, "The directory's length is 0" );
23
24 ( new TNativeFileSystem( "local" ) )->SetPrefix( currentDir );
25 ( new TNativeFileSystem( "abs" ) )->SetPrefix( "" );
26 ( new TNativeFileSystem( "null" ) )->SetPrefix( "" );
27
28 fileManager->SetSystemPath( "local" );
29
30 return TTRUE;
31}
#define TASSERT(X,...)
Definition Defines.h:138
#define TTRUE
Definition Typedefs.h:25
static TFORCEINLINE TFileManager * GetSingletonSafe()
Definition TSingleton.h:37

◆ CreateFile()

TFile * TFileManager::CreateFile ( const TString8 & a_strName,
TFILEMODE flags )

Definition at line 99 of file TFileManager.cpp.

100{
101 TASSERT( a_sName.Length() > 0, "Name can't be empty" );
102
103 ValidateSystemPath();
104 TINT pos = a_sName.Find( ':', 0 );
105
106 if ( pos >= 0 )
107 {
108 TString8 fsName;
109 TString8 fileName;
110
111 fsName.Copy( a_sName, pos );
112 fileName.Copy( a_sName.GetString( pos + 1 ) );
113
114 TFileSystem* pFileSystem = FindFileSystem( fsName );
115
116 if ( pFileSystem != TNULL )
117 {
118 return pFileSystem->CreateFile( fileName, flags );
119 }
120 }
121
122 T2_FOREACH( m_Validated, pFileSystem )
123 {
124 TFile* pFile = pFileSystem->CreateFile( a_sName, flags );
125
126 if ( pFile != TNULL )
127 {
128 return pFile;
129 }
130 }
131
132 return TNULL;
133}
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
virtual TFile * CreateFile(const TString8 &a_rcFileName, TFILEMODE a_eFileMode)=0
Creates file.
TFileSystem * FindFileSystem(const TString8 &name)
void Copy(const TString8 &src, TINT size=-1)
Definition TString8.h:32

◆ Destroy()

void TFileManager::Destroy ( )

Definition at line 36 of file TFileManager.cpp.

37{
38 {
39 auto pFileSystem = TFileManager::FindFileSystem( "mem" );
40 if ( pFileSystem ) delete pFileSystem;
41 }
42
43 {
44 auto pFileSystem = TFileManager::FindFileSystem( "null" );
45 if ( pFileSystem ) delete pFileSystem;
46 }
47
48 {
49 auto pFileSystem = TFileManager::FindFileSystem( "abs" );
50 if ( pFileSystem ) delete pFileSystem;
51 }
52
53 {
54 auto pFileSystem = TFileManager::FindFileSystem( "local" );
55 if ( pFileSystem ) delete pFileSystem;
56 }
57
58 DestroyCommon();
59}

◆ FileSystemRelease()

static void TFileManager::FileSystemRelease ( )
inlinestatic

Definition at line 285 of file TFile.h.

285{ ms_oMutex.Unlock(); }
static TMutex ms_oMutex
Definition TFile.h:253

◆ FileSystemWait()

static void TFileManager::FileSystemWait ( )
inlinestatic

Definition at line 286 of file TFile.h.

286{ ms_oMutex.Lock(); }

◆ FindFileSystem() [1/2]

TFileSystem * TFileManager::FindFileSystem ( const TString8 & name)

Definition at line 72 of file TFileManager.cpp.

73{
74 TFileSystem* pFileSystem = TFileManager::FindFileSystem( m_Validated, name );
75
76 if ( pFileSystem == TNULL )
77 {
78 pFileSystem = TFileManager::FindFileSystem( m_Invalidated, name );
79 }
80
81 return pFileSystem;
82}

◆ FindFileSystem() [2/2]

TFileSystem * TFileManager::FindFileSystem ( TDList< TFileSystem > & list,
const TString8 & name )
static

Definition at line 85 of file TFileManager.cpp.

86{
87 T2_FOREACH( a_rList, pFileSystem )
88 {
89 if ( pFileSystem->GetName() == name )
90 {
91 return pFileSystem;
92 }
93 }
94
95 return TNULL;
96}

◆ GetFileInfo()

TBOOL TFileManager::GetFileInfo ( const TString8 & a_strPath,
TNativeFileInfo & a_rNativeInfo )

Definition at line 136 of file TFileManager.cpp.

137{
138 TASSERT( a_strPath.Length() > 0, "Path can't be empty" );
139
140 ValidateSystemPath();
141 TINT pos = a_strPath.Find( ':', 0 );
142
143 if ( pos >= 0 )
144 {
145 TString8 fsName;
146 TString8 fileName;
147
148 fsName.Copy( a_strPath, pos );
149 fileName.Copy( a_strPath.GetString( pos + 1 ) );
150
151 TFileSystem* pFileSystem = FindFileSystem( fsName );
152
153 if ( pFileSystem != TNULL )
154 {
155 return pFileSystem->ToNative( fileName, a_rNativeInfo );
156 }
157 }
158
159 // If there are few validated file systems or even zero, create a file to know what filesystem we should use
160 if ( m_ValidatedCount != 1 )
161 {
162 TFile* pFile = CreateFile( a_strPath, TFILEMODE_READ | TFILEMODE_NOBUFFER );
163
164 if ( pFile != TNULL )
165 {
166 TFileSystem* pFileSystem = pFile->GetFileSystem();
167 pFileSystem->DestroyFile( pFile );
168
169 return pFileSystem->ToNative( a_strPath, a_rNativeInfo );
170 }
171
172 return TFALSE;
173 }
174
175 TFileSystem* pFileSystem = m_Validated.Begin();
176 return pFileSystem->ToNative( a_strPath, a_rNativeInfo );
177}
@ TFILEMODE_READ
Definition TFile.h:38
@ TFILEMODE_NOBUFFER
Definition TFile.h:42
#define TFALSE
Definition Typedefs.h:24
virtual void DestroyFile(TFile *a_pFile)=0
Destroys specified file.
virtual TBOOL ToNative(const TString8 &a_rcPath, TNativeFileInfo &a_rOutInfo)
Fetches info about the path and returns internal path.
TFileSystem * GetFileSystem() const
Definition TFile.h:216
TFile * CreateFile(const TString8 &a_strName, TFILEMODE flags)
TINT Find(TCHAR character, TINT pos=0) const
Definition TString8.cpp:107
TINT Length() const
Definition TString8.h:93
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286

◆ MakeAbsolutePath()

TString8 TFileManager::MakeAbsolutePath ( const TString8 & a_rcRelativePath) const

Definition at line 263 of file TFileManager.cpp.

264{
265 return TFile::ConcatPath( m_WorkingDirectory, a_rcRelativePath );
266}
static TString8 ConcatPath(const TString8 &a_rcPath1, const TString8 &a_rcPath2)
Definition TFile.cpp:48

◆ MountFileSystem()

void TFileManager::MountFileSystem ( TFileSystem * a_pFileSystem)

Definition at line 62 of file TFileManager.cpp.

63{
64 TASSERT( TFileManager::FindFileSystem( a_pFileSystem->GetName() ) == TNULL );
65 TASSERT( !a_pFileSystem->IsLinked() );
66
67 m_Invalidated.InsertTail( a_pFileSystem );
68 InvalidateSystemPath();
69}
const TString8 & GetName() const
Definition TFile.h:116
TBOOL IsLinked() const
Definition TDList.h:38

◆ SetSystemPath()

void TFileManager::SetSystemPath ( const TString8 & name)
inline

Definition at line 270 of file TFile.h.

271 {
272 m_SysPath = name;
273 InvalidateSystemPath();
274 }

Member Data Documentation

◆ ms_oMutex

TMutex TFileManager::ms_oMutex
inlinestatic

Definition at line 253 of file TFile.h.


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