argh, clean out copy
[supertux.git] / src / unison / src / vfs / FileSystem.cpp
1 //          Copyright Timothy Goya 2007.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <unison/vfs/FileSystem.hpp>
7
8 #include <fstream>
9
10 #include <physfs.h>
11
12 namespace Unison
13 {
14    namespace VFS
15    {
16       FileSystem::FileSystem()
17       {
18 #if __USE_POSIX
19          std::ifstream cmdline("/proc/self/cmdline");
20          std::string argv0;
21          std::getline(cmdline, argv0, '\0');
22          PHYSFS_init(argv0.c_str());
23 #else
24          PHYSFS_init(0);
25 #endif
26       }
27
28       FileSystem::~FileSystem()
29       {
30          PHYSFS_deinit();
31       }
32
33       void FileSystem::follow_sym_links(bool follow)
34       {
35          PHYSFS_permitSymbolicLinks(follow);
36       }
37
38       std::string FileSystem::get_dir_sep()
39       {
40          return PHYSFS_getDirSeparator();
41       }
42
43       std::string FileSystem::get_base_dir()
44       {
45          return PHYSFS_getBaseDir();
46       }
47
48       std::string FileSystem::get_user_dir()
49       {
50          return PHYSFS_getUserDir();
51       }
52
53       std::string FileSystem::get_write_dir()
54       {
55          return PHYSFS_getWriteDir();
56       }
57
58       void FileSystem::set_write_dir(const std::string &write_dir)
59       {
60          PHYSFS_setWriteDir(write_dir.c_str());
61       }
62
63       void FileSystem::mount(const std::string &path, const std::string &mount_point, bool append)
64       {
65          PHYSFS_mount(path.c_str(), mount_point.c_str(), append);
66       }
67
68       void FileSystem::umount(const std::string &path)
69       {
70          PHYSFS_removeFromSearchPath(path.c_str());
71       }
72
73       std::vector<std::string> FileSystem::get_search_path()
74       {
75          std::vector<std::string> paths;
76          char **search_path = PHYSFS_getSearchPath();
77          for(char **iter = search_path;*iter;++iter)
78          {
79             paths.push_back(*iter);
80          }
81          PHYSFS_freeList(search_path);
82          return paths;
83       }
84
85       std::string FileSystem::get_mount_point(const std::string &path)
86       {
87          return PHYSFS_getMountPoint(path.c_str());
88       }
89
90       void FileSystem::mkdir(const std::string &dir)
91       {
92          PHYSFS_mkdir(dir.c_str());
93       }
94
95       void FileSystem::rm(const std::string &filename)
96       {
97          PHYSFS_delete(filename.c_str());
98       }
99
100       std::vector<std::string> FileSystem::ls(const std::string &path)
101       {
102          std::vector<std::string> files;
103          char **physfs_files = PHYSFS_enumerateFiles(path.c_str());
104          for(char **iter = physfs_files;*iter;++iter)
105          {
106             files.push_back(*iter);
107          }
108          PHYSFS_freeList(physfs_files);
109          return files;
110       }
111
112       bool FileSystem::exists(const std::string &filename)
113       {
114          return PHYSFS_exists(filename.c_str());
115       }
116
117       bool FileSystem::is_dir(const std::string &filename)
118       {
119          return PHYSFS_isDirectory(filename.c_str());
120       }
121
122       std::string FileSystem::get_real_dir(const std::string &filename)
123       {
124          return PHYSFS_getRealDir(filename.c_str());
125       }
126    }
127 }