From fbe76102e941b9f1edaf236788e42678f05fdf9a Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:08:06 +0200 Subject: 3.9 --- shared/file_handling.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 shared/file_handling.h (limited to 'shared/file_handling.h') diff --git a/shared/file_handling.h b/shared/file_handling.h new file mode 100644 index 00000000..36bf976f --- /dev/null +++ b/shared/file_handling.h @@ -0,0 +1,105 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** +// +#ifndef FILE_HANDLING_H_INCLUDED +#define FILE_HANDLING_H_INCLUDED + +#include "zstring.h" +#include "file_error.h" +#include + +#ifdef FFS_WIN +#include "shadow.h" +#endif + + +namespace ffs3 +{ +Zstring getFormattedDirectoryName(const Zstring& dirname); + +bool fileExists( const Zstring& filename); //throw() replaces wxFileExists()! +bool dirExists( const Zstring& dirname); //throw() replaces wxDirExists(): optional 'cause wxDirExists treats symlinks correctly +bool symlinkExists( const Zstring& objname); //throw() check whether a symbolic link exists +bool somethingExists(const Zstring& objname); //throw() check whether any object with this name exists + +//check whether two folders are located on the same (logical) volume +//left and right directories NEED NOT yet exist! volume prefix is sufficient! path may end with PATH_SEPARATOR +enum ResponseSameVol +{ + VOLUME_SAME, + VOLUME_DIFFERENT, + VOLUME_CANT_SAY +}; +ResponseSameVol onSameVolume(const Zstring& folderLeft, const Zstring& folderRight); //throw() + +//copy file or directory create/last change date, +void copyFileTimes(const Zstring& sourceDir, const Zstring& targetDir, bool derefSymlinks); //throw (FileError) + +//copy filesystem permissions: probably requires admin rights +void copyObjectPermissions(const Zstring& source, const Zstring& target, bool derefSymlinks); //throw FileError(); + +//symlink handling: always evaluate target +wxULongLong getFilesize(const Zstring& filename); //throw (FileError) + + +//file handling +void removeFile(const Zstring& filename); //throw (FileError) +void removeDirectory(const Zstring& directory); //throw (FileError) + + +struct MoveFileCallback //callback functionality +{ + virtual ~MoveFileCallback() {} + + enum Response + { + CONTINUE, + CANCEL + }; + virtual Response requestUiRefresh() = 0; //DON'T throw exceptions here, at least in Windows build! +}; + +//rename file or directory: no copying!!! +void renameFile(const Zstring& oldName, const Zstring& newName); //throw (FileError); + +//move source to target; expectations: target not existing, all super-directories of target exist +void moveFile(const Zstring& sourceFile, const Zstring& targetFile, MoveFileCallback* callback = NULL); //throw (FileError); + +//move source to target including subdirectories +//"ignoreExistingDirs": existing directories will be enhanced as long as this is possible without overwriting files +void moveDirectory(const Zstring& sourceDir, const Zstring& targetDir, bool ignoreExistingDirs, MoveFileCallback* callback = NULL); //throw (FileError); + +//creates superdirectories automatically: +void createDirectory(const Zstring& directory, const Zstring& templateDir, bool copyDirectorySymLinks, bool copyFilePermissions); //throw (FileError); +void createDirectory(const Zstring& directory); //throw (FileError); -> function overload avoids default parameter ambiguity issues! + +struct CopyFileCallback //callback functionality +{ + virtual ~CopyFileCallback() {} + + enum Response + { + CONTINUE, + CANCEL + }; + virtual Response updateCopyStatus(const wxULongLong& totalBytesTransferred) = 0; //DON'T throw exceptions here, at least in Windows build! +}; + +void copyFile(const Zstring& sourceFile, //throw (FileError); + const Zstring& targetFile, + bool copyFileSymLinks, + bool copyFilePermissions, +#ifdef FFS_WIN + shadow::ShadowCopy* shadowCopyHandler, //supply handler for making shadow copies, may be NULL +#endif + CopyFileCallback* callback); //may be NULL +//Note: it MAY happen that copyFile() leaves temp files behind, e.g. temporary network drop. +// => clean them up at an appropriate time (automatically set sync directions to delete them). They have the following ending: +const Zstring TEMP_FILE_ENDING = DefaultStr(".ffs_tmp"); +} + + +#endif //FILE_HANDLING_H_INCLUDED -- cgit