2011-08-19 18:59:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
|
|
|
|
2011-08-19 23:46:07 +00:00
|
|
|
#include "StringUtils.h"
|
|
|
|
|
2011-08-19 18:59:21 +00:00
|
|
|
class FileOps
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class IOException : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2011-08-19 23:46:07 +00:00
|
|
|
IOException(const std::string& error);
|
2011-08-19 20:03:10 +00:00
|
|
|
|
2011-08-19 18:59:21 +00:00
|
|
|
virtual ~IOException() throw ();
|
|
|
|
|
2011-08-19 20:03:10 +00:00
|
|
|
virtual const char* what() const throw ()
|
|
|
|
{
|
|
|
|
return m_error.c_str();
|
|
|
|
}
|
2011-08-19 18:59:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_error;
|
2011-08-19 23:46:07 +00:00
|
|
|
int m_errno;
|
2011-08-19 18:59:21 +00:00
|
|
|
};
|
|
|
|
|
2011-08-22 09:01:25 +00:00
|
|
|
enum QtFilePermission
|
|
|
|
{
|
|
|
|
ReadOwner = 0x4000,
|
|
|
|
WriteOwner = 0x2000,
|
|
|
|
ExecOwner = 0x1000,
|
|
|
|
ReadUser = 0x0400,
|
|
|
|
WriteUser = 0x0200,
|
|
|
|
ExecUser = 0x0100,
|
|
|
|
ReadGroup = 0x0040,
|
|
|
|
WriteGroup = 0x0020,
|
|
|
|
ExecGroup = 0x0010,
|
|
|
|
ReadOther = 0x0004,
|
|
|
|
WriteOther = 0x0002,
|
|
|
|
ExecOther = 0x0001
|
|
|
|
};
|
|
|
|
|
2011-08-26 11:55:09 +00:00
|
|
|
/** Remove a file. Throws an exception if the file
|
|
|
|
* could not be removed.
|
|
|
|
*
|
|
|
|
* On Unix, a file can be removed even if it is in use if the user
|
|
|
|
* has the necessary permissions. removeFile() tries to simulate
|
|
|
|
* this behavior on Windows. If a file cannot be removed on Windows
|
|
|
|
* because it is in use it will be moved to a temporary directory and
|
|
|
|
* scheduled for deletion on the next restart.
|
|
|
|
*/
|
|
|
|
static void removeFile(const char* src) throw (IOException);
|
|
|
|
|
2011-08-22 09:01:25 +00:00
|
|
|
static void setQtPermissions(const char* path, int permissions) throw (IOException);
|
2011-08-19 18:59:21 +00:00
|
|
|
static bool fileExists(const char* path) throw (IOException);
|
|
|
|
static void moveFile(const char* src, const char* dest) throw (IOException);
|
|
|
|
static void extractFromZip(const char* zipFile, const char* src, const char* dest) throw (IOException);
|
|
|
|
static void mkdir(const char* dir) throw (IOException);
|
|
|
|
static void rmdir(const char* dir) throw (IOException);
|
|
|
|
static void createSymLink(const char* link, const char* target) throw (IOException);
|
2011-08-19 20:03:10 +00:00
|
|
|
static void touch(const char* path) throw (IOException);
|
2011-08-21 23:30:40 +00:00
|
|
|
static std::string fileName(const char* path);
|
2011-08-19 20:03:10 +00:00
|
|
|
static std::string dirname(const char* path);
|
2011-08-20 11:11:05 +00:00
|
|
|
static void rmdirRecursive(const char* dir) throw (IOException);
|
2011-08-21 20:50:20 +00:00
|
|
|
static std::string canonicalPath(const char* path);
|
2011-08-26 11:55:09 +00:00
|
|
|
static std::string tempPath();
|
2011-08-22 09:01:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static int toUnixPermissions(int qtPermissions);
|
2011-08-26 11:55:09 +00:00
|
|
|
|
|
|
|
// returns a copy of the path 'str' with Windows-style '\'
|
|
|
|
// dir separators converted to Unix-style '/' separators
|
|
|
|
static std::string toUnixPathSeparators(const std::string& str);
|
2011-08-19 18:59:21 +00:00
|
|
|
};
|
|
|
|
|