Planeshift
fileutil.h
Go to the documentation of this file.
1 /*
2 * fileutil.h by Matthias Braun <matze@braunis.de>
3 *
4 * Copyright (C) 2002 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 /* This file contains
21 * Utility functions to access the filesystem in a platform
22 * independant way. It would be nicer to use vfs here, but vfs is too limited
23 * for our needs (testing for file/directory, file permissions) */
24 
25 #ifndef __FILEUTIL_H__
26 #define __FILEUTIL_H__
27 
28 #include <psstdint.h>
29 #include <iutil/vfs.h>
30 #include <csutil/refcount.h>
31 
32 struct iVFS;
33 
38 class FileStat : public csRefCount
39 {
40 public:
41  enum Type
42  {
45  };
46 
48  bool link;
49  bool executable;
50  uint32_t size;
51  char* target;
52  bool readonly;
53  unsigned short mode;
54  short uid;
55  short gid;
56 
58  { target = NULL; }
60  { delete[] target; }
61 };
62 
63 
64 class FileUtil
65 {
66 private:
67  csRef<iVFS> vfs;
68 public:
69  FileUtil(iVFS* vfs);
70  ~FileUtil();
71  /* Tests if the file exists and returns data about the file. */
72  csPtr<FileStat> StatFile(const char* path);
73 
74  bool RemoveFile(const char* filename, bool silent = false);
75 
76  /* Creates a directory, given a vfs path (/this/). */
77  void MakeDirectory(const char* directory);
78 
79  /* Copies a file. */
80  bool CopyFile(csString from, csString to, bool vfsPath, bool executable, bool silent = false, bool copyPermissions = true);
81 
82  /* Moves a file */
83  inline void MoveFile(csString from, csString to, bool vfsPath, bool executable, bool silent = false)
84  {
85  CopyFile(from, to, vfsPath, executable, silent);
86  RemoveFile(from, silent);
87  }
88 
89  /* Returns true is the file at the specified path is executable. */
90  bool isExecutable(const char* path);
91 
92  /* Sets all permissions on a file. */
93  void SetPermissions(const char* path, FileStat* fs);
94 };
95 
98 #endif // __FILEUTIL_H__
bool executable
Definition: fileutil.h:49
short uid
Definition: fileutil.h:54
Type type
Definition: fileutil.h:47
void MoveFile(csString from, csString to, bool vfsPath, bool executable, bool silent=false)
Definition: fileutil.h:83
FileStat()
Definition: fileutil.h:57
char * target
Definition: fileutil.h:51
unsigned short mode
Definition: fileutil.h:53
short gid
Definition: fileutil.h:55
~FileStat()
Definition: fileutil.h:59
bool readonly
Definition: fileutil.h:52
bool link
Definition: fileutil.h:48
uint32_t size
Definition: fileutil.h:50