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)
6 #include <unison/vfs/FileSystem.hpp>
16 FileSystem::FileSystem()
19 std::ifstream cmdline("/proc/self/cmdline");
21 std::getline(cmdline, argv0, '\0');
22 PHYSFS_init(argv0.c_str());
28 FileSystem::~FileSystem()
33 void FileSystem::follow_sym_links(bool follow)
35 PHYSFS_permitSymbolicLinks(follow);
38 std::string FileSystem::get_dir_sep()
40 return PHYSFS_getDirSeparator();
43 std::string FileSystem::get_base_dir()
45 return PHYSFS_getBaseDir();
48 std::string FileSystem::get_user_dir()
50 return PHYSFS_getUserDir();
53 std::string FileSystem::get_write_dir()
55 return PHYSFS_getWriteDir();
58 void FileSystem::set_write_dir(const std::string &write_dir)
60 PHYSFS_setWriteDir(write_dir.c_str());
63 void FileSystem::mount(const std::string &path, const std::string &mount_point, bool append)
65 PHYSFS_mount(path.c_str(), mount_point.c_str(), append);
68 void FileSystem::umount(const std::string &path)
70 PHYSFS_removeFromSearchPath(path.c_str());
73 std::vector<std::string> FileSystem::get_search_path()
75 std::vector<std::string> paths;
76 char **search_path = PHYSFS_getSearchPath();
77 for(char **iter = search_path;*iter;++iter)
79 paths.push_back(*iter);
81 PHYSFS_freeList(search_path);
85 std::string FileSystem::get_mount_point(const std::string &path)
87 return PHYSFS_getMountPoint(path.c_str());
90 void FileSystem::mkdir(const std::string &dir)
92 PHYSFS_mkdir(dir.c_str());
95 void FileSystem::rm(const std::string &filename)
97 PHYSFS_delete(filename.c_str());
100 std::vector<std::string> FileSystem::ls(const std::string &path)
102 std::vector<std::string> files;
103 char **physfs_files = PHYSFS_enumerateFiles(path.c_str());
104 for(char **iter = physfs_files;*iter;++iter)
106 files.push_back(*iter);
108 PHYSFS_freeList(physfs_files);
112 bool FileSystem::exists(const std::string &filename)
114 return PHYSFS_exists(filename.c_str());
117 bool FileSystem::is_dir(const std::string &filename)
119 return PHYSFS_isDirectory(filename.c_str());
122 std::string FileSystem::get_real_dir(const std::string &filename)
124 return PHYSFS_getRealDir(filename.c_str());