OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdFile.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Lots of file helpers */
19 
20 #ifndef STDFILE_INCLUDED
21 #define STDFILE_INCLUDED
22 
27 bool CreatePath(const std::string &path);
28 
29 const char *GetWorkingDirectory();
30 bool SetWorkingDirectory(const char *szPath);
31 char *GetFilename(char *path);
32 char *GetFilenameWeb(char *path);
33 const char* GetFilenameOnly(const char *strFilename);
34 const char *GetC4Filename(const char *szPath); // returns path to file starting at first .c4*-directory
35 int GetTrailingNumber(const char *strString);
36 char *GetExtension(char *fname);
37 const char *GetFilename(const char *path);
38 const char *GetFilenameWeb(const char *path);
39 const char *GetExtension(const char *fname);
40 void DefaultExtension(char *szFileName, const char *szExtension);
41 void DefaultExtension(StdStrBuf *sFilename, const char *szExtension);
42 void EnforceExtension(char *szFileName, const char *szExtension);
43 void EnforceExtension(StdStrBuf *sFilename, const char *szExtension);
44 void RemoveExtension(char *szFileName);
45 void RemoveExtension(StdStrBuf *psFileName);
46 void AppendBackslash(char *szFileName);
47 void TruncateBackslash(char *szFilename);
48 void MakeTempFilename(char *szFileName);
49 void MakeTempFilename(StdStrBuf *sFileName);
50 bool WildcardListMatch(const char *szWildcardList, const char *szString); // match string in list like *.png|*.bmp
51 bool IsWildcardString(const char *szString); // does szString contain wildcard characters?
52 bool WildcardMatch(const char *szWildcard, const char *szString);
53 bool TruncatePath(char *szPath);
54 // szBuffer has to be of at least _MAX_PATH length.
55 bool GetParentPath(const char *szFilename, char *szBuffer);
56 bool GetParentPath(const char *szFilename, StdStrBuf *outBuf);
57 const char *GetRelativePathS(const char *strPath, const char *strRelativeTo);
58 bool IsGlobalPath(const char *szPath);
59 
60 bool DirectoryExists(const char *szFileName);
61 bool FileExists(const char *szFileName);
62 size_t FileSize(const char *fname);
63 size_t FileSize(int fdes);
64 int FileTime(const char *fname);
65 bool EraseFile(const char *szFileName);
66 bool RenameFile(const char *szFileName, const char *szNewFileName);
67 bool MakeOriginalFilename(char *szFilename);
68 void MakeFilenameFromTitle(char *szTitle);
69 
70 bool CopyDirectory(const char *szSource, const char *szTarget, bool fResetAttributes=false);
71 bool EraseDirectory(const char *szDirName);
72 
73 int ItemAttributes(const char *szItemName);
74 bool ItemIdentical(const char *szFilename1, const char *szFilename2);
75 inline bool ItemExists(const char *szItemName) { return FileExists(szItemName); }
76 bool RenameItem(const char *szItemName, const char *szNewItemName);
77 bool EraseItem(const char *szItemName);
78 bool CopyItem(const char *szSource, const char *szTarget, bool fResetAttributes=false);
79 bool CreateItem(const char *szItemname);
80 bool MoveItem(const char *szSource, const char *szTarget);
81 
82 int ForEachFile(const char *szDirName, bool (*fnCallback)(const char *));
83 
84 struct DirectoryIteratorP;
86 {
87  // Shallow copyable, ordered directory iterator
88 public:
89  DirectoryIterator(const char * dirname);
94 
95  const char * operator * () const;
96  const char *GetName() const { return **this; }
97  size_t GetFileSize() const;
98 
101  void Clear(); // put iterator into empty state and clear any cached directory listing
102  void Reset(const char * dirname, bool force_reread=false); // reset iterator to front of file list. re-read directory if it changed or force_reread is set.
103  void Reset(); // reset iterator to front of file list without re-reading directory
104 private:
105  void Read(const char *dirname);
106  friend struct DirectoryIteratorP;
107  typedef std::vector<std::pair<std::string, size_t>> FileList;
109  FileList::iterator iter;
110 };
111 
112 #endif // STDFILE_INCLUDED
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:855
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:227
const char * operator*() const
Definition: StdFile.cpp:1021
bool MakeOriginalFilename(char *szFilename)
bool CreateItem(const char *szItemname)
Definition: StdFile.cpp:815
void TruncateBackslash(char *szFilename)
Definition: StdFile.cpp:266
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
void EnforceExtension(char *szFileName, const char *szExtension)
Definition: StdFile.cpp:289
bool CopyItem(const char *szSource, const char *szTarget, bool fResetAttributes=false)
Definition: StdFile.cpp:831
bool TruncatePath(char *szPath)
Definition: StdFile.cpp:240
bool EraseDirectory(const char *szDirName)
Definition: StdFile.cpp:761
char * GetExtension(char *fname)
Definition: StdFile.cpp:121
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:211
void DefaultExtension(char *szFileName, const char *szExtension)
Definition: StdFile.cpp:274
DirectoryIterator & operator=(const DirectoryIterator &)
Definition: StdFile.cpp:886
size_t FileSize(const char *fname)
int FileTime(const char *fname)
bool SetWorkingDirectory(const char *szPath)
Definition: StdFile.cpp:623
int GetTrailingNumber(const char *strString)
Definition: StdFile.cpp:87
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:374
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:402
const char * GetC4Filename(const char *szPath)
Definition: StdFile.cpp:71
char * GetFilename(char *path)
Definition: StdFile.cpp:45
size_t GetFileSize() const
Definition: StdFile.cpp:1034
bool EraseFile(const char *szFileName)
bool FileExists(const char *szFileName)
void RemoveExtension(char *szFileName)
Definition: StdFile.cpp:306
const char * GetWorkingDirectory()
Definition: StdFile.cpp:603
bool DirectoryExists(const char *szFileName)
Definition: StdFile.cpp:684
bool RenameFile(const char *szFileName, const char *szNewFileName)
bool IsWildcardString(const char *szString)
Definition: StdFile.cpp:366
int ItemAttributes(const char *szItemName)
bool RenameItem(const char *szItemName, const char *szNewItemName)
Definition: StdFile.cpp:803
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
bool WildcardListMatch(const char *szWildcardList, const char *szString)
Definition: StdFile.cpp:351
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
void AppendBackslash(char *szFileName)
Definition: StdFile.cpp:257
int ForEachFile(const char *szDirName, bool(*fnCallback)(const char *))
Definition: StdFile.cpp:1043
DirectoryIterator & operator++()
Definition: StdFile.cpp:1014
bool MoveItem(const char *szSource, const char *szTarget)
Definition: StdFile.cpp:849
const char * GetName() const
Definition: StdFile.h:96
void MakeTempFilename(char *szFileName)
Definition: StdFile.cpp:323
char * GetFilenameWeb(char *path)
Definition: StdFile.cpp:104
const char * GetFilenameOnly(const char *strFilename)
Definition: StdFile.cpp:60
bool CopyDirectory(const char *szSource, const char *szTarget, bool fResetAttributes=false)
Definition: StdFile.cpp:713