/** * Copyright Mikael Högdahl - triyana@users.sourceforge.net * * This source is distributed under the terms of the Q Public License version 1.0, * created by Trolltech (www.trolltech.com). */ #ifndef MHFile_h #define MHFile_h #include "MH.h" #include "MHString.h" class MHVector; /** * File wrapper object */ class MHFile : public MH { public: MHString aName; MHString aPath; MHString aFullName; int aSize; int aType; int aOwner; int aGroup; int aDate; bool aMode[9]; enum { IS_DIR = 1, IS_FILE = 2, IS_LINK = 4, IS_CHAR = 8, IS_BLOCK = 16, IS_SOCK = 32, IS_FIFO = 64, IS_OTHER = 128, IS_NONE = 256, ALL = 512, SORT_NAME = 0, SORT_TYPE, }; MHFile () {Set(0, 0);} MHFile (const char* fileName, const char* dir = ".") {Set(fileName, dir);} ~MHFile () {;} int Compare (const MH* o, int type) {if (type == SORT_TYPE) return compareType((MHFile*)o); else return compareName((MHFile*)o);} bool Delete (); bool Exist () {return aType != IS_NONE;} const char* FullName (); const char* GetFullName () {return aFullName();} bool IsDir () {return aType == IS_DIR;} bool IsFile () {return aType == IS_FILE;} bool Rename (MHFile* newFile) {return MHFile::Rename (aFullName(), newFile->aFullName());} int Size () {return aSize;} void Set (const char* fileName, const char* dir); void Set (MHFile* file) {Set(file->aName(), file->aPath());} void Touch (); static bool Copy (const char* from, const char* to); static int CountRows (const char* fileName); static bool Delete (const char* fileName) {MHFile f(fileName, ""); return f.Delete ();} static bool Exist (const char* fileName) {MHFile f(fileName, ""); return f.Exist ();} static int Glob (const char* dirName, const char* pattern, int type, MHVector* out); static bool IsDir (const char* fileName) {MHFile f(fileName, ""); return f.IsDir ();} static bool IsFile (const char* fileName) {MHFile f(fileName, ""); return f.IsFile ();} static int Size (const char* fileName) {MHFile f(fileName, ""); return f.aSize;} static char* Read (const char* fileName, int& size); static bool Rename (const char* from, const char* to); static void Write (const char* fileName, const char* buffer, int size, bool compress); private: static int aaInitCompress; int compareName (MHFile* file) {return strcmp(aName(), file->aName.Get());} int compareType (MHFile* file) {return (aType == file->aType) ? 0 : ((aType < file->aType) ? -1 : 1);} }; #endif