00001 /*
00002 File: FileName.h
00003
00004 Function: Provides a file spec + related ops.
00005 Assumed representation is path:file:extension.
00006
00007 Author: Andrew Willmott, (c) 1996-1999
00008 */
00009
00010 #ifndef __FileName__
00011 #define __FileName__
00012
00013 #include "cl/String.h"
00014 #include "cl/Flags.h"
00015 #include <stdio.h>
00016
00017 class FileName
00019 {
00020 public:
00021 FileName() : path(), name(), extension(), flags() {};
00022
00023 FileName &SetPath(StrConst path);
00025 FileName &SetRelPath(StrConst path);
00032 String GetPath() const;
00034
00035 StrConst GetFile() const
00037 { return(name); };
00038 StrConst GetExtension() const
00040 { return(extension); };
00041 StrConst GetDir() const
00043 { return(path); };
00044
00045 FileName &SetFile(StrConst file)
00047 { name = file; return(SELF); };
00048 FileName &SetExtension(StrConst ext)
00050 { extension = ext; return(SELF); };
00051 FileName &SetDir(StrConst dir)
00053 { path = dir; return(SELF); };
00054
00055 Void AddExtension(StrConst ext);
00058 Void RemoveExtension();
00062 Bool Exists() const;
00063 Bool IsReadable() const;
00064 Bool IsWritable() const;
00065 Long GetTimeStamp() const;
00066
00067 FILE *FOpen(StrConst permissions) const
00069 { return(fopen(GetPath(), permissions)); };
00070
00071 Int FindFileExtension(StrConst extensions[],
00072 Bool allowCompressed = true);
00075 FileName &MakeUnique();
00082 Int DecompressSetup();
00084 Void DecompressCleanup();
00086 Void AddCompExt();
00088
00089 Flags32 flags;
00090
00091 protected:
00092 String path;
00093 String name;
00094 String extension;
00095 };
00096
00097 String TempPath();
00098
00099 enum FN_Flags
00100 {
00101 FN_Gzipped = 0x0001,
00102 FN_Bz2ed = 0x0002,
00103 FN_Compress = 0x0004,
00104
00105 FN_IsCompressed = 0x000F
00106 };
00107
00108 enum FN_Err
00109 {
00110 kFileNotFound = -1,
00111 kBadExtension = -2
00112 };
00113
00114 #endif