54#include <wx/filename.h>
56#include <wx/wxcrtvararg.h>
57#include <wx/wfstream.h>
58#include <wx/txtstrm.h>
59#include <wx/zipstrm.h>
60#include <wx/tarstrm.h>
61#include <wx/zstream.h>
63#include <wx/version.h>
75#define m_pStream_Base ((wxStreamBase *)m_pStream)
76#define m_pStream_I ((wxFFileInputStream *)m_pStream)
77#define m_pStream_O ((wxFFileOutputStream *)m_pStream)
78#define m_pStream_IO ((wxFFileStream *)m_pStream)
98 Open(FileName, Mode, bBinary, Encoding);
117 if( !_FileName ) {
return(
false ); }
CSG_String FileName(_FileName);
138 m_pStream =
new wxFFileOutputStream(FileName.
c_str(), bBinary ?
"wb" :
"w");
142 m_pStream =
new wxFFileInputStream (FileName.
c_str(), bBinary ?
"rb" :
"r");
147 ? (bBinary ?
"r+b" :
"r+")
148 : (bBinary ?
"w+b" :
"w+")
297 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
298 va_list argptr; va_start(argptr, _Format);
299 int Result = String.PrintfV(_Format, argptr);
301 va_list argptr; va_start(argptr, Format);
302 int Result = String.PrintfV(Format, argptr);
322 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
323 va_list argptr; va_start(argptr, _Format);
324 int Result = String.PrintfV(_Format, argptr);
326 va_list argptr; va_start(argptr, Format);
327 int Result = String.PrintfV(Format, argptr);
342 :
m_pStream_IO->Read(Buffer, Size * Count).LastRead() / Size
382 wxString _Buffer(Buffer.
w_str());
384 const wxScopedCharBuffer s(_Buffer.mb_str(*((wxMBConv *)
m_pConvert)));
386 return(
Write((
void *)s.data(),
sizeof(
char), s.length()) );
423 wxTextInputStream Stream(*
m_pStream_I ,
" \t" ); s = Stream.ReadLine();
427 wxTextInputStream Stream(*
m_pStream_IO,
" \t" ); s = Stream.ReadLine();
447 if(
Read(&Value,
sizeof(Value)) == 1 )
465 return(
Write(&Value,
sizeof(Value)) ==
sizeof(Value) );
473 if(
Read(&Value,
sizeof(Value)) == 1 )
491 return(
Write(&Value,
sizeof(Value)) ==
sizeof(Value) );
501 if( isdigit(c) || strchr(
"-+", c) )
510 return( s.
asInt(Value) );
523 if( isdigit(c) || strchr(
"-+.,eE", c) )
527 while( !
is_EOF() && (isdigit(c =
Read_Char()) || strchr(
".,eE", c) || strchr(
"", c)) )
545 int c;
while( !
is_EOF() && (c =
Read_Char()) != Separator && c != EOF )
559 int Value;
return(
Scan(Value) ? Value : 0 );
564 double Value;
return(
Scan(Value) ? Value : 0.0 );
590 Open(FileName, Mode, Encoding);
604 if( !_FileName ) {
return(
false ); }
CSG_String FileName(_FileName);
665 wxArchiveEntry *pEntry;
667 while( (pEntry = ((wxArchiveInputStream *)
m_pStream)->GetNextEntry()) != NULL )
683 delete((wxZipEntry *)
m_Files[i]);
687 delete((wxTarEntry *)
m_Files[i]);
701 return(
is_Writing() && Name && ((wxArchiveOutputStream *)
m_pStream)->PutNextDirEntry(Name) );
709 wxArchiveEntry *pEntry = NULL;
713 pEntry =
new wxZipEntry(Name);
715 ((wxZipEntry *)pEntry)->SetIsText(bBinary ==
false);
717 #if wxCHECK_VERSION(3, 1, 1)
718 ((wxZipOutputStream *)
m_pStream)->SetFormat(wxZIP_FORMAT_ZIP64);
723 pEntry =
new wxTarEntry(Name);
726 if( ((wxArchiveOutputStream *)
m_pStream)->PutNextEntry(pEntry) )
742 return( ((wxArchiveEntry *)
m_Files[Index])->IsDir() );
753 if( ((wxArchiveInputStream *)
m_pStream)->OpenEntry(*(wxArchiveEntry *)
m_Files[Index]) )
771 if( !((wxArchiveEntry *)
m_Files[i])->GetName().Cmp(Name) )
788 wxString Name(((wxArchiveEntry *)
m_Files[Index])->GetName()); s = &Name;
808 const char Separator =
'\\';
810 const char Separator =
'/';
824 Directory += Separator;
865 #define UNZIP_BUFFER 4096
873 Stream.
Write(Buffer, 1, nBytes); Stream.
Flush();
895 return( wxZlibInputStream::CanHandleGZip() );
903 wxFFileInputStream Input(File.
c_str());
905 if( Input.IsOk() && Input.CanRead() )
911 Target = File +
".gz";
914 wxZlibOutputStream Output(
new wxFFileOutputStream(Target.
c_str()));
933 wxZlibInputStream Input(
new wxFFileInputStream(File.
c_str()));
935 if( Input.IsOk() && Input.CanRead() )
944 wxFFileOutputStream Output(Target.
c_str());
968 return( wxFileName::DirExists(Directory.
c_str()) );
979 return( wxFileName::Mkdir(Directory.
c_str(), wxS_DIR_DEFAULT, bFullPath ? wxPATH_MKDIR_FULL : 0) );
990 return( wxDir::Remove(Directory.
c_str(), bRecursive ? wxPATH_RMDIR_RECURSIVE : 0) );
996 wxString cwd = wxFileName::GetCwd();
1004 wxString fname = wxFileName::GetTempDir();
1012 List.
Clear(); wxDir Dir;
1014 if( Dir.Open(Directory.
c_str()) )
1018 if( Dir.GetFirst(&FileName, wxEmptyString, wxDIR_DIRS) )
1029 while( Dir.GetNext(&FileName) );
1039 List.
Clear(); wxDir Dir;
1041 if( Dir.Open(Directory.
c_str()) )
1045 if( Dir.GetFirst(&FileName, wxEmptyString, wxDIR_FILES) )
1054 while( Dir.GetNext(&FileName) );
1057 if( bRecursive && Dir.GetFirst(&FileName, wxEmptyString, wxDIR_DIRS) )
1063 while( Dir.GetNext(&FileName) );
1080 return( wxFileExists(FileName.
c_str()) );
1099 return(
CSG_String(wxFileName::CreateTempFileName(Prefix.
c_str()).wc_str()) );
1108 wxFileName fn(full_Path.
c_str());
1112 wxString s(fn.GetFullName());
return(
CSG_String(&s) );
1115 wxString s(fn.GetName());
return( &s );
1121 wxString s(wxFileName(full_Path.
c_str()).GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR));
1129 wxFileName fn(full_Path.
c_str());
1133 wxString s(fn.GetFullPath());
return( &s );
1139 wxFileName fn(full_Path.
c_str());
1141 fn.MakeRelativeTo(Directory.
c_str());
1143 wxString s(fn.GetFullPath());
return( &s );
1161 fn.SetExt (Extension.
c_str());
1168 wxString s(fn.GetFullPath());
return( &s );
1174 wxFileName a(wxString(Path1.
c_str())), b(wxString(Path2.
c_str()));
1176 return( a.SameAs(b) );
1188 if( FileName.
Length() > 0 )
1190 wxFileName fn(FileName.
c_str());
1192 fn.SetExt(Extension.
c_str());
1194 wxString s(fn.GetFullPath());
1207 wxFileName fn(FileName.
c_str());
1209 wxString s(fn.GetExt());
return( &s );
1224 return( wxGetEnv(Variable.
w_str(), NULL) );
1229 if( wxGetEnv(Variable.
w_str(), &s) )
1231 *Value = s.wc_str();
1242 return( wxSetEnv(Variable.
w_str(), Value.
w_str()) );
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &File, const CSG_String &Extension)
SAGA_API_DLL_EXPORT bool SG_Dir_Create(const CSG_String &Directory, bool bFullPath=false)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
SAGA_API_DLL_EXPORT bool SG_UI_Process_Set_Progress(int Position, int Range)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
SAGA_API_DLL_EXPORT bool SG_Dir_Exists(const CSG_String &Directory)
@ SG_FILE_ENCODING_UTF16LE
@ SG_FILE_ENCODING_UTF16BE
@ SG_FILE_ENCODING_UNDEFINED
@ SG_FILE_ENCODING_UTF32BE
@ SG_FILE_ENCODING_UTF32LE
SAGA_API_DLL_EXPORT void SG_Swap_Bytes(void *Buffer, int nBytes)
CSG_String SG_Dir_Get_Temp(void)
CSG_String SG_File_Get_Name_Temp(const CSG_String &Prefix)
bool SG_File_Cmp_Path(const CSG_String &Path1, const CSG_String &Path2)
bool SG_File_Exists(const CSG_String &FileName)
bool SG_Dir_Create(const CSG_String &Directory, bool bFullPath)
bool SG_Dir_List_Subdirectories(CSG_Strings &List, const CSG_String &Directory, bool bRecursive)
CSG_String SG_Dir_Get_Current(void)
CSG_String SG_File_Get_Path_Absolute(const CSG_String &full_Path)
CSG_String SG_File_Get_Extension(const CSG_String &FileName)
bool SG_File_Set_Extension(CSG_String &FileName, const CSG_String &Extension)
bool SG_Set_Environment(const CSG_String &Variable, const CSG_String &Value)
bool SG_Dir_Delete(const CSG_String &Directory, bool bRecursive)
bool SG_Dir_Exists(const CSG_String &Directory)
bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
bool SG_File_Delete(const CSG_String &FileName)
CSG_String SG_File_Get_Path(const CSG_String &full_Path)
CSG_String SG_File_Get_Path_Relative(const CSG_String &Directory, const CSG_String &full_Path)
CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
bool SG_Get_Environment(const CSG_String &Variable, CSG_String *Value)
bool SG_Dir_List_Files(CSG_Strings &List, const CSG_String &Directory, const CSG_String &Extension, bool bRecursive)
CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
bool Add_Directory(const SG_Char *Name)
bool Add_File(const SG_Char *Name, bool bBinary=true)
bool is_Directory(size_t Index)
bool Extract_All(const SG_Char *toDirectory=NULL)
size_t Get_File_Count(void)
bool Get_File(const SG_Char *Name)
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, int Encoding=SG_FILE_ENCODING_ANSI)
CSG_Array_Pointer m_Files
virtual ~CSG_Archive(void)
bool Extract(const SG_Char *File, const SG_Char *toFile=NULL)
char * Get_Data(int Offset=0) const
bool Seek(sLong Offset, int Origin=SG_FILE_START) const
double Read_Double(bool bBigEndian=false) const
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
int Read_Int(bool bBigEndian=false) const
bool Write_Int(int Value, bool bBigEndian=false)
bool Set_Encoding(int Encoding)
virtual const CSG_String & Get_File_Name(void) const
bool Seek_End(void) const
bool Read_Line(CSG_String &Line) const
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
int Printf(const char *Format,...)
CSG_String Scan_String(SG_Char Separator) const
bool is_Writing(void) const
int Read_Char(void) const
bool is_Reading(void) const
bool Seek_Start(void) const
bool Scan(int &Value) const
bool Write_Double(double Value, bool bBigEndian=false)
double Scan_Double(void) const
void On_Construction(void)
size_t Length(void) const
const char * b_str(void) const
const SG_Char * c_str(void) const
bool is_Empty(void) const
double asDouble(void) const
const wchar_t * w_str(void) const
int Get_Count(void) const
static CSG_String Uncompress(const CSG_String &File, const CSG_String &Target="")
static bool is_GZip_Supported(void)
static CSG_String Compress(const CSG_String &File, const CSG_String &Target="")