Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F123493
FileSystemSourceFile.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
FileSystemSourceFile.cpp
View Options
#include
<echo/FileSystem/FileSystemSourceFile.h>
#include
<echo/FileSystem/FileReferenceFile.h>
#ifndef ECHO_PLATFORM_ANDROID
#include
<boost/filesystem.hpp>
#endif
#include
<iostream>
namespace
Echo
{
FileSystemSourceFile
::
FileSystemSourceFile
(
const
std
::
string
&
identifier
)
:
FileSystemSource
(
identifier
)
{
}
FileSystemSourceFile
::~
FileSystemSourceFile
()
{
}
File
FileSystemSourceFile
::
Open
(
const
std
::
string
&
fileName
,
File
::
OpenMode
openMode
)
{
std
::
string
fullName
=
GetCurrentDirectory
()
+
fileName
;
std
::
ios_base
::
openmode
mode
=
std
::
ios_base
::
binary
;
//app (append) Set the stream's position indicator to the end of the stream before each output operation.
//ate (at end) Set the stream's position indicator to the end of the stream on opening.
//binary (binary) Consider stream as binary rather than text.
//in (input) Allow input operations on the stream.
//out (output) Allow output operations on the stream.
//trunc (truncate) Any current content is discarded, assuming a length of zero on opening.
if
(
openMode
!=
File
::
OpenModes
::
READ
)
{
#ifdef ECHO_PLATFORM_LINUX
using
namespace
boost
;
try
{
filesystem
::
path
p
;
p
/=
fullName
.
c_str
();
std
::
string
parent_path
=
p
.
parent_path
().
c_str
();
if
(
!
parent_path
.
empty
()
&&
!
filesystem
::
exists
(
p
.
parent_path
())
&&
!
filesystem
::
create_directories
(
parent_path
))
{
std
::
cout
<<
"Failed to create directories for writing "
<<
fullName
<<
std
::
endl
;
}
}
catch
(
boost
::
filesystem
::
filesystem_error
&
)
{
std
::
cout
<<
"Failed to create directories for writing "
<<
fullName
<<
std
::
endl
;
}
#endif
}
switch
(
openMode
)
{
case
File
::
OpenModes
::
READ
:
mode
|=
std
::
ios_base
::
in
;
break
;
case
File
::
OpenModes
::
WRITE
:
mode
|=
std
::
ios_base
::
out
|
std
::
ios_base
::
trunc
;
break
;
case
File
::
OpenModes
::
APPEND
:
mode
|=
std
::
ios_base
::
out
|
std
::
ios_base
::
app
;
break
;
case
File
::
OpenModes
::
READ_WRITE
:
mode
|=
std
::
ios_base
::
in
|
std
::
ios_base
::
out
;
break
;
case
File
::
OpenModes
::
READ_APPEND
:
mode
|=
std
::
ios_base
::
in
|
std
::
ios_base
::
app
;
break
;
}
shared_ptr
<
FileReferenceFile
>
fileReference
(
new
FileReferenceFile
(
*
this
,
fullName
.
c_str
(),
mode
));
if
(
!
fileReference
->
mFile
.
good
())
{
return
File
(
fullName
);
}
return
File
(
fullName
,
fileReference
);
}
bool
FileSystemSourceFile
::
DeleteFile
(
const
std
::
string
&
fileName
)
{
#ifdef ECHO_PLATFORM_LINUX
using
namespace
boost
;
try
{
filesystem
::
path
p
;
p
/=
fileName
.
c_str
();
filesystem
::
remove
(
p
);
return
true
;
}
catch
(
boost
::
filesystem
::
filesystem_error
&
e
)
{
std
::
cout
<<
"Failed to delete file: '"
<<
fileName
<<
"' reason: "
<<
e
.
what
()
<<
std
::
endl
;
}
#endif
return
false
;
}
bool
FileSystemSourceFile
::
FileExists
(
const
std
::
string
&
fileName
)
{
#ifdef ECHO_PLATFORM_LINUX
using
namespace
boost
;
try
{
filesystem
::
path
p
;
p
/=
fileName
.
c_str
();
return
filesystem
::
exists
(
p
);
}
catch
(
boost
::
filesystem
::
filesystem_error
&
e
)
{
std
::
cout
<<
"Failed to delete file: '"
<<
fileName
<<
"' reason: "
<<
e
.
what
()
<<
std
::
endl
;
}
#endif
return
FileSystemSource
::
FileExists
(
fileName
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Jan 16, 1:15 AM (13 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72117
Default Alt Text
FileSystemSourceFile.cpp (3 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment