FileIO.h 2.51 KB

#ifndef __FILE_IO_H__
#define __FILE_IO_H__

#include "AnubisSupport.h"
#include "CMString.h"

#ifdef WIN32
#include <windows.h>
#include <stdio.h>
#endif
#if defined(__BEOS__) || defined (_LINUX_)
#define ENV_PATH_SEPARATOR ':'
#elif defined(WIN32)
#define ENV_PATH_SEPARATOR ';'
#endif

#if defined(__BEOS__) || defined (_LINUX_)
#define FILE_SEPARATOR '/'
#elif defined(WIN32)
#define FILE_SEPARATOR '\\'
#endif

USING_NAMESPACE(CM);
  /** 
    * Give the file separator character for the host operating system 
    * @return slash character under Linux, BeOS/Zeta and anti-slash character for Windows
    */
char FileSeparator(void);

  /** 
    * Normalization of filename path, consist to transform any given wrong fileseparator to 
    * right format for the host operating system. For example under linux if you give 
    * the next filepath  /usr/local\myfile the result of normalization will be
    * /usr/local/myfile 
    *	@pathName filepath to normalize
    */
#ifdef __cplusplus
extern "C" {
#endif
void NormalizeFileName(char *pathName);
#ifdef __cplusplus
}
#endif

String GetFileName(String pathName);
  /** 
    * 
    */
CM::String GetProgramRootDir(const char * argv0);

  /** provide the current user dir of host OS
    * 
    */
CM::String GetUserDir(void);

  /** 
    * Check the existence of the file
    * @param fileToCheck 
    * @return true if the file exist otherwise false
    */
bool FileExist(CM::String fileToCheck);

  /*
   *	Make a recursive copy from source directory to destination
   *  @param srcDir from where we copy
   *  @param destDir 
   */
bool RecursiveCopy(const String &srcDir, const String &destDir);

  /*
   *	create all given directories
   *  @param directory path to create
   *  @param mean the above directory have filename at the end
   */
int CreateAllDirectories(const char*   directory, bool haveFile );

#ifdef WIN32
int CM_CopyDir(const String& sourceDirPath, const String& destDirPath, const String &filter, bool recursive);
int CM_CopyFileDir(const String &sourceDirPath, const String &destDirPath, const String &filter);
int CM_CopyFile(const String& srcFile, const String& desFile);

//File utils functions
void CM_TimetToFileTime( time_t t, LPFILETIME pft );
void CM_FileTimeToTime( time_t& t, LPFILETIME pft );
bool CM_SetModificationTime(const char* file_name, const time_t aModificationTime);
bool CM_SetAccessTime(const char* file_name, const time_t aAccessTime);
void CM_SetAllTime(FILE* srcFile, FILE* dstFile);

#endif

char *GetWorkingDirectory(char *buf, int sz);
String GetCwd();

#endif