diff options
Diffstat (limited to 'shared')
79 files changed, 427 insertions, 577 deletions
diff --git a/shared/IFileOperation/dll_main.cpp b/shared/IFileOperation/dll_main.cpp index 142e26a2..d23e5c48 100644 --- a/shared/IFileOperation/dll_main.cpp +++ b/shared/IFileOperation/dll_main.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // diff --git a/shared/IFileOperation/file_op.cpp b/shared/IFileOperation/file_op.cpp index cc8c58bc..b1b7f4cd 100644 --- a/shared/IFileOperation/file_op.cpp +++ b/shared/IFileOperation/file_op.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "file_op.h" diff --git a/shared/IFileOperation/file_op.h b/shared/IFileOperation/file_op.h index 97c75747..9842f0d6 100644 --- a/shared/IFileOperation/file_op.h +++ b/shared/IFileOperation/file_op.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef RECYCLER_DLL_H diff --git a/shared/ShadowCopy/dll_main.cpp b/shared/ShadowCopy/dll_main.cpp index 142e26a2..d23e5c48 100644 --- a/shared/ShadowCopy/dll_main.cpp +++ b/shared/ShadowCopy/dll_main.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // diff --git a/shared/ShadowCopy/shadow.cpp b/shared/ShadowCopy/shadow.cpp index a5c280e8..d536470a 100644 --- a/shared/ShadowCopy/shadow.cpp +++ b/shared/ShadowCopy/shadow.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "shadow.h" diff --git a/shared/ShadowCopy/shadow.h b/shared/ShadowCopy/shadow.h index f1100284..683a4e16 100644 --- a/shared/ShadowCopy/shadow.h +++ b/shared/ShadowCopy/shadow.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SHADOWCOPY_H diff --git a/shared/Taskbar_Seven/dll_main.cpp b/shared/Taskbar_Seven/dll_main.cpp index 142e26a2..d23e5c48 100644 --- a/shared/Taskbar_Seven/dll_main.cpp +++ b/shared/Taskbar_Seven/dll_main.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // diff --git a/shared/Taskbar_Seven/taskbar.cpp b/shared/Taskbar_Seven/taskbar.cpp index d1b1638c..c853eb5d 100644 --- a/shared/Taskbar_Seven/taskbar.cpp +++ b/shared/Taskbar_Seven/taskbar.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "taskbar.h" diff --git a/shared/Taskbar_Seven/taskbar.h b/shared/Taskbar_Seven/taskbar.h index 34e122c0..295cdbcd 100644 --- a/shared/Taskbar_Seven/taskbar.h +++ b/shared/Taskbar_Seven/taskbar.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef TASKBAR_SEVEN_DLL_H diff --git a/shared/app_main.cpp b/shared/app_main.cpp index 3d42212a..6b87cf45 100644 --- a/shared/app_main.cpp +++ b/shared/app_main.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "app_main.h" diff --git a/shared/app_main.h b/shared/app_main.h index 7e4fa7e7..bdfb9b08 100644 --- a/shared/app_main.h +++ b/shared/app_main.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef APPMAIN_H_INCLUDED diff --git a/shared/assert_static.h b/shared/assert_static.h index 9eb94f3c..d2bd0a3a 100644 --- a/shared/assert_static.h +++ b/shared/assert_static.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef ASSERTSTATIC_H_INCLUDED diff --git a/shared/build_info.h b/shared/build_info.h index 945284d2..e398a8a0 100644 --- a/shared/build_info.h +++ b/shared/build_info.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef BUILDINFO_H_INCLUDED diff --git a/shared/c_dll.h b/shared/c_dll.h index 4d485893..3941cc0e 100644 --- a/shared/c_dll.h +++ b/shared/c_dll.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef C_DLL_HEADER diff --git a/shared/check_exist.cpp b/shared/check_exist.cpp index 8bc629b5..97a25ec8 100644 --- a/shared/check_exist.cpp +++ b/shared/check_exist.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "check_exist.h" diff --git a/shared/check_exist.h b/shared/check_exist.h index 7e9cecd8..6ec5534c 100644 --- a/shared/check_exist.h +++ b/shared/check_exist.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef CHECKEXIST_H_INCLUDED diff --git a/shared/com_error.h b/shared/com_error.h index 73551f6e..30c7904f 100644 --- a/shared/com_error.h +++ b/shared/com_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef COM_ERROR_HEADER diff --git a/shared/com_ptr.h b/shared/com_ptr.h index 52a072fa..f8331220 100644 --- a/shared/com_ptr.h +++ b/shared/com_ptr.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SMART_COM_PTR_H diff --git a/shared/com_util.h b/shared/com_util.h index 22e2075f..a396fbee 100644 --- a/shared/com_util.h +++ b/shared/com_util.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef COM_UTILITY_HEADER diff --git a/shared/custom_button.cpp b/shared/custom_button.cpp index 7154814b..ea473fc2 100644 --- a/shared/custom_button.cpp +++ b/shared/custom_button.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "custom_button.h" diff --git a/shared/custom_button.h b/shared/custom_button.h index b50dd4da..63875e42 100644 --- a/shared/custom_button.h +++ b/shared/custom_button.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef CUSTOMBUTTON_H_INCLUDED diff --git a/shared/custom_combo_box.cpp b/shared/custom_combo_box.cpp index 18adb38a..a1f28b5c 100644 --- a/shared/custom_combo_box.cpp +++ b/shared/custom_combo_box.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "custom_combo_box.h" @@ -57,15 +57,15 @@ void CustomComboBox::OnKeyEvent(wxKeyEvent& event) const int selectedItem = this->GetCurrentSelection(); if (0 <= selectedItem && selectedItem < static_cast<int>(this->GetCount()) && #if wxCHECK_VERSION(2, 9, 1) - dropDownShown) + dropDownShown) #else - //what a mess...: - (GetValue() != GetString(selectedItem) || //avoid problems when a character shall be deleted instead of list item - GetValue() == wxEmptyString)) //exception: always allow removing empty entry + //what a mess...: + (GetValue() != GetString(selectedItem) || //avoid problems when a character shall be deleted instead of list item + GetValue() == wxEmptyString)) //exception: always allow removing empty entry #endif - { - //save old (selected) value: deletion seems to have influence on this - const wxString currentVal = this->GetValue(); + { + //save old (selected) value: deletion seems to have influence on this + const wxString currentVal = this->GetValue(); this->SetSelection(wxNOT_FOUND); //delete selected row diff --git a/shared/custom_combo_box.h b/shared/custom_combo_box.h index 28361a30..070790a6 100644 --- a/shared/custom_combo_box.h +++ b/shared/custom_combo_box.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef CUSTOMCOMBOBOX_H_INCLUDED @@ -31,10 +31,10 @@ private: void OnKeyEvent(wxKeyEvent& event); #if wxCHECK_VERSION(2, 9, 1) - void OnShowDropDown(wxCommandEvent& event); - void OnHideDropDown(wxCommandEvent& event); + void OnShowDropDown(wxCommandEvent& event); + void OnHideDropDown(wxCommandEvent& event); - bool dropDownShown; + bool dropDownShown; #endif }; diff --git a/shared/custom_tooltip.cpp b/shared/custom_tooltip.cpp index 5b4e5e40..f19f3822 100644 --- a/shared/custom_tooltip.cpp +++ b/shared/custom_tooltip.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "custom_tooltip.h" diff --git a/shared/custom_tooltip.h b/shared/custom_tooltip.h index c6bf6cd6..c5cb132b 100644 --- a/shared/custom_tooltip.h +++ b/shared/custom_tooltip.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef CUSTOMTOOLTIP_H_INCLUDED diff --git a/shared/debug_new.cpp b/shared/debug_new.cpp index 0c0c8b52..bb02b112 100644 --- a/shared/debug_new.cpp +++ b/shared/debug_new.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "debug_new.h" diff --git a/shared/debug_new.h b/shared/debug_new.h index e96b1e48..73591c45 100644 --- a/shared/debug_new.h +++ b/shared/debug_new.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef DEBUGNEW_H_INCLUDED diff --git a/shared/dir_name.cpp b/shared/dir_name.cpp index 28c1c413..4ae3ef2f 100644 --- a/shared/dir_name.cpp +++ b/shared/dir_name.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "dir_name.h" diff --git a/shared/dir_name.h b/shared/dir_name.h index 163caaad..ad0f2a52 100644 --- a/shared/dir_name.h +++ b/shared/dir_name.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef DRAGANDDROP_H_INCLUDED diff --git a/shared/disable_standby.h b/shared/disable_standby.h new file mode 100644 index 00000000..399d0b9c --- /dev/null +++ b/shared/disable_standby.h @@ -0,0 +1,30 @@ +#ifndef PREVENTSTANDBY_H_INCLUDED +#define PREVENTSTANDBY_H_INCLUDED + +#ifdef FFS_WIN +#include <wx/msw/wrapwin.h> //includes "windows.h" +#endif + +namespace util +{ +class DisableStandby +{ +public: + DisableStandby() + { +#ifdef FFS_WIN + ::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED /* | ES_AWAYMODE_REQUIRED*/ ); +#endif + } + + ~DisableStandby() + { +#ifdef FFS_WIN + ::SetThreadExecutionState(ES_CONTINUOUS); +#endif + } + +}; +} + +#endif // PREVENTSTANDBY_H_INCLUDED diff --git a/shared/dll_loader.cpp b/shared/dll_loader.cpp index 61a5a2fb..03b9bf6e 100644 --- a/shared/dll_loader.cpp +++ b/shared/dll_loader.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "dll_loader.h" diff --git a/shared/dll_loader.h b/shared/dll_loader.h index b3fa5218..24dd4f14 100644 --- a/shared/dll_loader.h +++ b/shared/dll_loader.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef DLLLOADER_H_INCLUDED diff --git a/shared/file_error.h b/shared/file_error.h index 2804e337..152062af 100644 --- a/shared/file_error.h +++ b/shared/file_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef FILEERROR_H_INCLUDED diff --git a/shared/file_handling.cpp b/shared/file_handling.cpp index b05b9cf8..10cab5ef 100644 --- a/shared/file_handling.cpp +++ b/shared/file_handling.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "file_handling.h" @@ -24,6 +24,7 @@ #include "symlink_target.h" #ifdef FFS_WIN +#include "privilege.h" #include "dll_loader.h" #include <wx/msw/wrapwin.h> //includes "windows.h" #include "long_path_prefix.h" @@ -209,16 +210,16 @@ bool ffs3::fileExists(const Zstring& filename) // we must use GetFileAttributes() instead of the ANSI C functions because // it can cope with network (UNC) paths unlike them const DWORD ret = ::GetFileAttributes(applyLongPathPrefix(filename).c_str()); - return (ret != INVALID_FILE_ATTRIBUTES) && !(ret & FILE_ATTRIBUTE_DIRECTORY); //returns true for (file-)symlinks also + return ret != INVALID_FILE_ATTRIBUTES && !(ret & FILE_ATTRIBUTE_DIRECTORY); //returns true for (file-)symlinks also #elif defined FFS_LINUX struct stat fileInfo; - return (::lstat(filename.c_str(), &fileInfo) == 0 && - (S_ISLNK(fileInfo.st_mode) || S_ISREG(fileInfo.st_mode))); //in Linux a symbolic link is neither file nor directory + return ::lstat(filename.c_str(), &fileInfo) == 0 && + (S_ISLNK(fileInfo.st_mode) || S_ISREG(fileInfo.st_mode)); //in Linux a symbolic link is neither file nor directory #endif } - +#include <wx/msgdlg.h> bool ffs3::dirExists(const Zstring& dirname) { //symbolic links (broken or not) are also treated as existing directories! @@ -226,13 +227,12 @@ bool ffs3::dirExists(const Zstring& dirname) // we must use GetFileAttributes() instead of the ANSI C functions because // it can cope with network (UNC) paths unlike them const DWORD ret = ::GetFileAttributes(applyLongPathPrefix(dirname).c_str()); - return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_DIRECTORY); //returns true for (dir-)symlinks also #elif defined FFS_LINUX struct stat dirInfo; - return (::lstat(dirname.c_str(), &dirInfo) == 0 && - (S_ISLNK(dirInfo.st_mode) || S_ISDIR(dirInfo.st_mode))); //in Linux a symbolic link is neither file nor directory + return ::lstat(dirname.c_str(), &dirInfo) == 0 && + (S_ISLNK(dirInfo.st_mode) || S_ISDIR(dirInfo.st_mode)); //in Linux a symbolic link is neither file nor directory #endif } @@ -241,12 +241,12 @@ bool ffs3::symlinkExists(const Zstring& objname) { #ifdef FFS_WIN const DWORD ret = ::GetFileAttributes(applyLongPathPrefix(objname).c_str()); - return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_REPARSE_POINT); + return ret != INVALID_FILE_ATTRIBUTES && (ret & FILE_ATTRIBUTE_REPARSE_POINT); #elif defined FFS_LINUX struct stat fileInfo; - return (::lstat(objname.c_str(), &fileInfo) == 0 && - S_ISLNK(fileInfo.st_mode)); //symbolic link + return ::lstat(objname.c_str(), &fileInfo) == 0 && + S_ISLNK(fileInfo.st_mode); //symbolic link #endif } @@ -592,18 +592,18 @@ bool fix8Dot3NameClash(const Zstring& oldName, const Zstring& newName) //throw //we detected an event where newName is in shortname format (although it is intended to be a long name) and //writing target file failed because another unrelated file happens to have the same short name - const Zstring newNameFullPathLong = newName.BeforeLast(common::FILE_NAME_SEPARATOR) + common::FILE_NAME_SEPARATOR + - fileNameLong; + const Zstring unrelatedPathLong = newName.BeforeLast(common::FILE_NAME_SEPARATOR) + common::FILE_NAME_SEPARATOR + + fileNameLong; //find another name in short format: this ensures the actual short name WILL be renamed as well! const Zstring parkedTarget = createTemp8Dot3Name(newName); //move already existing short name out of the way for now - renameFileInternal(newNameFullPathLong, parkedTarget); //throw (FileError, ErrorDifferentVolume); + renameFileInternal(unrelatedPathLong, parkedTarget); //throw (FileError, ErrorDifferentVolume); //DON'T call ffs3::renameFile() to avoid reentrance! //schedule cleanup; the file system should assign this unrelated file a new (unique) short name - Loki::ScopeGuard guard = Loki::MakeGuard(renameFileInternalNoThrow, parkedTarget, newNameFullPathLong);//equivalent to Boost.ScopeExit in this case + Loki::ScopeGuard guard = Loki::MakeGuard(renameFileInternalNoThrow, parkedTarget, unrelatedPathLong);//equivalent to Boost.ScopeExit in this case (void)guard; //silence warning "unused variable" renameFileInternal(oldName, newName); //the short filename name clash is solved, this should work now @@ -673,6 +673,10 @@ void ffs3::moveFile(const Zstring& sourceFile, const Zstring& targetFile, MoveFi wxT("\n\n") + _("Operation aborted!")); } + //support case-sensitive renaming + if (EqualFilename()(sourceFile, targetFile)) //difference in case only + return renameFile(sourceFile, targetFile); //throw (FileError, ErrorDifferentVolume); + if (somethingExists(targetFile)) //test file existence: e.g. Linux might silently overwrite existing symlinks throw FileError(wxString(_("Error moving file:")) + wxT("\n\"") + zToWx(sourceFile) + wxT("\" ->\n\"") + zToWx(targetFile) + wxT("\"") + wxT("\n\n") + _("Target file already existing!")); @@ -989,7 +993,10 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo throw FileError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted()); } - if ((sourceAttr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && deRefSymlinks) //we have a symlink AND need to dereference... + const bool isReparsePoint = (sourceAttr.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0; + const bool isDirectory = (sourceAttr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + + if (isReparsePoint && deRefSymlinks) //we have a symlink AND need to dereference... { HANDLE hSource = ::CreateFile(applyLongPathPrefix(sourceObj).c_str(), FILE_READ_ATTRIBUTES, @@ -1003,7 +1010,6 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo const wxString errorMessage = wxString(_("Error reading file attributes:")) + wxT("\n\"") + zToWx(sourceObj) + wxT("\""); throw FileError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted()); } - boost::shared_ptr<void> dummy(hSource, ::CloseHandle); if (!::GetFileTime(hSource, //__in HANDLE hFile, @@ -1023,7 +1029,7 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo } //####################################### DST hack ########################################### - if ((sourceAttr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) //dst hack not (yet) required for directories (symlinks implicitly checked by isFatDrive()) + if (!isDirectory) //dst hack not (yet) required for directories (symlinks implicitly checked by isFatDrive()) { if (dst::isFatDrive(sourceObj)) //throw() { @@ -1046,6 +1052,9 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo } + //privilege SE_BACKUP_NAME doesn't seem to be required here for symbolic links + //note: setting privileges requires admin rights! + HANDLE hTarget = ::CreateFile(applyLongPathPrefix(targetObj).c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, @@ -1071,7 +1080,7 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo } #ifndef NDEBUG //dst hack: verify data written - if (dst::isFatDrive(targetObj)) //throw() + if (dst::isFatDrive(targetObj) && !ffs3::dirExists(targetObj)) //throw() { WIN32_FILE_ATTRIBUTE_DATA debugeAttr = {}; assert(::GetFileAttributesEx(applyLongPathPrefix(targetObj).c_str(), //__in LPCTSTR lpFileName, @@ -1083,7 +1092,6 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo } #endif - #elif defined FFS_LINUX if (deRefSymlinks) { @@ -1099,7 +1107,7 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo newTimes.modtime = objInfo.st_mtime; //(try to) set new "last write time" - if (::utime(targetObj.c_str(), &newTimes) != 0) //return value not evalutated! + if (::utime(targetObj.c_str(), &newTimes) != 0) //return value not evaluated! { wxString errorMessage = wxString(_("Error changing modification time:")) + wxT("\n\"") + zToWx(targetObj) + wxT("\""); throw FileError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted()); @@ -1121,7 +1129,7 @@ void ffs3::copyFileTimes(const Zstring& sourceObj, const Zstring& targetObj, boo newTimes[1].tv_sec = objInfo.st_mtime; /* seconds */ newTimes[1].tv_usec = 0; /* microseconds */ - if (::lutimes(targetObj.c_str(), newTimes) != 0) //return value not evalutated! + if (::lutimes(targetObj.c_str(), newTimes) != 0) //return value not evaluated! { wxString errorMessage = wxString(_("Error changing modification time:")) + wxT("\n\"") + zToWx(targetObj) + wxT("\""); throw FileError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted()); @@ -1221,148 +1229,6 @@ void copySymlinkInternal(const Zstring& sourceLink, const Zstring& targetLink, b } -namespace ffs3 -{ -#ifdef FFS_WIN -class Privileges -{ -public: - static Privileges& getInstance() - { - static Privileges instance; - return instance; - } - - void ensureActive(LPCTSTR privilege) //throw FileError() - { - if (activePrivileges.find(privilege) != activePrivileges.end()) - return; //privilege already active - - if (privilegeIsActive(privilege)) //privilege was already active before starting this tool - activePrivileges.insert(std::make_pair(privilege, false)); - else - { - setPrivilege(privilege, true); - activePrivileges.insert(std::make_pair(privilege, true)); - } - } - -private: - Privileges() {} - Privileges(Privileges&); - void operator=(Privileges&); - - ~Privileges() //clean up: deactivate all privileges that have been activated by this application - { - for (PrivBuffType::const_iterator i = activePrivileges.begin(); i != activePrivileges.end(); ++i) - try - { - if (i->second) - Privileges::setPrivilege(i->first, false); - } - catch(...) {} - } - - static bool privilegeIsActive(LPCTSTR privilege); //throw FileError() - static void setPrivilege(LPCTSTR privilege, bool enable); //throw FileError() - - typedef std::map<Zstring, bool> PrivBuffType; //bool: enabled by this application - - PrivBuffType activePrivileges; -}; - - -bool Privileges::privilegeIsActive(LPCTSTR privilege) //throw FileError() -{ - HANDLE hToken = NULL; - if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle, - TOKEN_QUERY, //__in DWORD DesiredAccess, - &hToken)) //__out PHANDLE TokenHandle - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - boost::shared_ptr<void> dummy(hToken, ::CloseHandle); - - LUID luid = {0}; - if (!::LookupPrivilegeValue( - NULL, //__in_opt LPCTSTR lpSystemName, - privilege, //__in LPCTSTR lpName, - &luid )) //__out PLUID lpLuid - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - - PRIVILEGE_SET priv = {0}; - priv.PrivilegeCount = 1; - priv.Control = PRIVILEGE_SET_ALL_NECESSARY; - priv.Privilege[0].Luid = luid; - priv.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED; - - BOOL alreadyGranted = FALSE; - if (!::PrivilegeCheck( - hToken, //__in HANDLE ClientToken, - &priv, //__inout PPRIVILEGE_SET RequiredPrivileges, - &alreadyGranted)) //__out LPBOOL pfResult - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - - return alreadyGranted == TRUE; -} - - -void Privileges::setPrivilege(LPCTSTR privilege, bool enable) //throw FileError() -{ - HANDLE hToken = NULL; - if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle, - TOKEN_ADJUST_PRIVILEGES, //__in DWORD DesiredAccess, - &hToken)) //__out PHANDLE TokenHandle - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - boost::shared_ptr<void> dummy(hToken, ::CloseHandle); - - LUID luid = {0}; - if (!::LookupPrivilegeValue( - NULL, //__in_opt LPCTSTR lpSystemName, - privilege, //__in LPCTSTR lpName, - &luid )) //__out PLUID lpLuid - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - - TOKEN_PRIVILEGES tp = {0}; - tp.PrivilegeCount = 1; - tp.Privileges[0].Luid = luid; - tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0; - - if (!::AdjustTokenPrivileges( - hToken, //__in HANDLE TokenHandle, - false, //__in BOOL DisableAllPrivileges, - &tp, //__in_opt PTOKEN_PRIVILEGES NewState, - 0, //__in DWORD BufferLength, - NULL, //__out_opt PTOKEN_PRIVILEGES PreviousState, - NULL)) //__out_opt PDWORD ReturnLength - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } - - if (::GetLastError() == ERROR_NOT_ALL_ASSIGNED) //check although previous function returned with success! - { - const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); - throw FileError(errorMessage + ffs3::getLastErrorFormatted()); - } -} -#endif -} - - #ifdef HAVE_SELINUX //copy SELinux security context void copySecurityContext(const Zstring& source, const Zstring& target, bool derefSymlinks) //throw FileError() @@ -1415,10 +1281,12 @@ void copySecurityContext(const Zstring& source, const Zstring& target, bool dere #endif //HAVE_SELINUX -//copy permissions for files, directories or symbolic links +//copy permissions for files, directories or symbolic links: void ffs3::copyObjectPermissions(const Zstring& source, const Zstring& target, bool derefSymlinks) //throw FileError(); probably requires admin rights { #ifdef FFS_WIN + //setting privileges requires admin rights! + //enable privilege: required to read/write SACL information Privileges::getInstance().ensureActive(SE_SECURITY_NAME); //polling allowed... @@ -1480,12 +1348,12 @@ void ffs3::copyObjectPermissions(const Zstring& source, const Zstring& target, b const HANDLE hTarget = ::CreateFile( targetFmt.c_str(), // lpFileName - FILE_GENERIC_WRITE | WRITE_OWNER | WRITE_DAC | ACCESS_SYSTEM_SECURITY, // dwDesiredAccess: all four seem to be required!!! - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // dwShareMode - NULL, // lpSecurityAttributes - OPEN_EXISTING, // dwCreationDisposition - FILE_FLAG_BACKUP_SEMANTICS | (derefSymlinks ? 0 : FILE_FLAG_OPEN_REPARSE_POINT), // dwFlagsAndAttributes - NULL); // hTemplateFile + FILE_GENERIC_WRITE | WRITE_OWNER | WRITE_DAC | ACCESS_SYSTEM_SECURITY, // dwDesiredAccess: all four seem to be required!!! + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // dwShareMode + NULL, // lpSecurityAttributes + OPEN_EXISTING, // dwCreationDisposition + FILE_FLAG_BACKUP_SEMANTICS | (derefSymlinks ? 0 : FILE_FLAG_OPEN_REPARSE_POINT), // dwFlagsAndAttributes + NULL); // hTemplateFile if (hTarget == INVALID_HANDLE_VALUE) { const wxString errorMessage = wxString(_("Error copying file permissions:")) + wxT("\n\"") + zToWx(source) + wxT("\" ->\n\"") + zToWx(target) + wxT("\"") + wxT("\n\n"); @@ -2008,33 +1876,3 @@ void ffs3::copyFile(const Zstring& sourceFile, guardTargetFile.Dismiss(); //target has been created successfully! } #endif - - - -/* -#ifdef FFS_WIN -inline -Zstring getDriveName(const Zstring& directoryName) //GetVolume() doesn't work under Linux! -{ - const Zstring volumeName = wxFileName(directoryName.c_str()).GetVolume().c_str(); - if (volumeName.empty()) - return Zstring(); - - return volumeName + wxFileName::GetVolumeSeparator().c_str() + common::FILE_NAME_SEPARATOR; -} - - -bool ffs3::isFatDrive(const Zstring& directoryName) -{ - const Zstring driveName = getDriveName(directoryName); - if (driveName.empty()) - return false; - - wxChar fileSystem[32]; - if (!GetVolumeInformation(driveName.c_str(), NULL, 0, NULL, NULL, NULL, fileSystem, 32)) - return false; - - return Zstring(fileSystem).StartsWith(wxT("FAT")); -} -#endif //FFS_WIN -*/ diff --git a/shared/file_handling.h b/shared/file_handling.h index af20ccf8..4ec9c6d2 100644 --- a/shared/file_handling.h +++ b/shared/file_handling.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef FILE_HANDLING_H_INCLUDED diff --git a/shared/file_id.cpp b/shared/file_id.cpp index 0c8afa3d..7b091201 100644 --- a/shared/file_id.cpp +++ b/shared/file_id.cpp @@ -1,31 +1,45 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "file_id.h" #ifdef FFS_WIN -#include "assert_static.h" #include <wx/msw/wrapwin.h> //includes "windows.h" #include "long_path_prefix.h" #include <boost/shared_ptr.hpp> #elif defined FFS_LINUX +#include <sys/stat.h> #endif +namespace +{ +template <class T> +inline +std::string numberToString(T number) +{ + const char* rawBegin = reinterpret_cast<const char*>(&number); + return std::string(rawBegin, rawBegin + sizeof(number)); +} +} -#ifdef FFS_WIN -util::FileID util::retrieveFileID(const Zstring& filename) + +std::string util::retrieveFileID(const Zstring& filename) { - //ensure our DWORD_FFS really is the same as DWORD - assert_static(sizeof(util::FileID::DWORD_FFS) == sizeof(DWORD)); + std::string fileID; -//WARNING: CreateFile() is SLOW, while GetFileInformationByHandle() is quite cheap! +#ifdef FFS_WIN +//WARNING: CreateFile() is SLOW, while GetFileInformationByHandle() is cheap! //http://msdn.microsoft.com/en-us/library/aa363788(VS.85).aspx + + //privilege SE_BACKUP_NAME doesn't seem to be required here at all + //note: setting privileges requires admin rights! + const HANDLE hFile = ::CreateFile(ffs3::applyLongPathPrefix(filename).c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, @@ -37,37 +51,35 @@ util::FileID util::retrieveFileID(const Zstring& filename) { boost::shared_ptr<void> dummy(hFile, ::CloseHandle); - BY_HANDLE_FILE_INFORMATION info; - if (::GetFileInformationByHandle(hFile, &info)) + BY_HANDLE_FILE_INFORMATION fileInfo = {}; + if (::GetFileInformationByHandle(hFile, &fileInfo)) { - return util::FileID(info.dwVolumeSerialNumber, - info.nFileIndexHigh, - info.nFileIndexLow); + fileID += numberToString(fileInfo.dwVolumeSerialNumber); + fileID += numberToString(fileInfo.nFileIndexHigh); + fileID += numberToString(fileInfo.nFileIndexLow); } } - return util::FileID(); //empty ID -} - #elif defined FFS_LINUX -util::FileID util::retrieveFileID(const Zstring& filename) -{ - struct stat fileInfo; - if (::lstat(filename.c_str(), &fileInfo) == 0) //lstat() does not resolve symlinks - return util::FileID(fileInfo.st_dev, fileInfo.st_ino); + struct stat fileInfo = {}; + if (::lstat(filename.c_str(), &fileInfo) == 0) //lstat() does not follow symlinks + { + fileID += numberToString(fileInfo.st_dev); + fileID += numberToString(fileInfo.st_ino); + } +#endif - return util::FileID(); //empty ID + return fileID; } -#endif bool util::sameFileSpecified(const Zstring& file1, const Zstring& file2) { - const util::FileID id1 = retrieveFileID(file1); - const util::FileID id2 = retrieveFileID(file2); + const std::string id1 = retrieveFileID(file1); + const std::string id2 = retrieveFileID(file2); - if (id1 != FileID() && id2 != FileID()) - return id1 == id2; + if (id1.empty() || id2.empty()) + return false; - return false; + return id1 == id2; } diff --git a/shared/file_id.h b/shared/file_id.h index d00ca20a..2e94bf5a 100644 --- a/shared/file_id.h +++ b/shared/file_id.h @@ -1,62 +1,23 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef FILEID_H_INCLUDED #define FILEID_H_INCLUDED -#include <wx/stream.h> #include "zstring.h" +#include <string> -#ifdef FFS_WIN -#elif defined FFS_LINUX -#include <sys/stat.h> -#endif //unique file identifier namespace util { -class FileID -{ -public: - //standard copy constructor and assignment operator are okay! - - FileID(wxInputStream& stream); //read - void toStream(wxOutputStream& stream) const; //write - - bool isNull() const; - bool operator==(const FileID& rhs) const; - bool operator!=(const FileID& rhs) const; - bool operator<(const FileID& rhs) const; - - FileID(); -#ifdef FFS_WIN - typedef unsigned long DWORD_FFS; //we don't want do include "windows.h" or "<wx/msw/wrapwin.h>" here, do we? - - FileID(DWORD_FFS dwVolumeSN, - DWORD_FFS fileIndexHi, - DWORD_FFS fileIndexLo); -#elif defined FFS_LINUX - FileID(dev_t devId, - ino_t inId); -#endif -private: -#ifdef FFS_WIN - DWORD_FFS dwVolumeSerialNumber; - DWORD_FFS nFileIndexHigh; - DWORD_FFS nFileIndexLow; -#elif defined FFS_LINUX - dev_t deviceId; - ino_t inodeId; -#endif -}; - //get unique file id (symbolic link handling: opens the link!!!) -//error condition: returns FileID () -FileID retrieveFileID(const Zstring& filename); +//returns empty string on error! +std::string retrieveFileID(const Zstring& filename); //test whether two distinct paths point to the same file or directory: // true: paths point to same files/dirs @@ -64,137 +25,4 @@ FileID retrieveFileID(const Zstring& filename); bool sameFileSpecified(const Zstring& file1, const Zstring& file2); } - - - - - - - - - - - - - - - - - - -//---------------Inline Implementation--------------------------------------------------- -#ifdef FFS_WIN -inline -util::FileID::FileID() : - dwVolumeSerialNumber(0), - nFileIndexHigh(0), - nFileIndexLow(0) {} - -inline -util::FileID::FileID(DWORD_FFS dwVolumeSN, - DWORD_FFS fileIndexHi, - DWORD_FFS fileIndexLo) : - dwVolumeSerialNumber(dwVolumeSN), - nFileIndexHigh(fileIndexHi), - nFileIndexLow(fileIndexLo) {} - -inline -bool util::FileID::isNull() const -{ - return dwVolumeSerialNumber == 0 && - nFileIndexHigh == 0 && - nFileIndexLow == 0; -} - -inline -bool util::FileID::operator==(const FileID& rhs) const -{ - return dwVolumeSerialNumber == rhs.dwVolumeSerialNumber && - nFileIndexHigh == rhs.nFileIndexHigh && - nFileIndexLow == rhs.nFileIndexLow; -} - -inline -bool util::FileID::operator<(const FileID& rhs) const -{ - if (dwVolumeSerialNumber != rhs.dwVolumeSerialNumber) - return dwVolumeSerialNumber < rhs.dwVolumeSerialNumber; - - if (nFileIndexHigh != rhs.nFileIndexHigh) - return nFileIndexHigh < rhs.nFileIndexHigh; - - return nFileIndexLow < rhs.nFileIndexLow; -} - -inline -util::FileID::FileID(wxInputStream& stream) //read -{ - stream.Read(&dwVolumeSerialNumber, sizeof(dwVolumeSerialNumber)); - stream.Read(&nFileIndexHigh, sizeof(nFileIndexHigh)); - stream.Read(&nFileIndexLow, sizeof(nFileIndexLow)); -} - -inline -void util::FileID::toStream(wxOutputStream& stream) const //write -{ - stream.Write(&dwVolumeSerialNumber, sizeof(dwVolumeSerialNumber)); - stream.Write(&nFileIndexHigh, sizeof(nFileIndexHigh)); - stream.Write(&nFileIndexLow, sizeof(nFileIndexLow)); -} - -#elif defined FFS_LINUX -inline -util::FileID::FileID() : - deviceId(0), - inodeId(0) {} - -inline -util::FileID::FileID(dev_t devId, - ino_t inId) : - deviceId(devId), - inodeId(inId) {} - -inline -bool util::FileID::isNull() const -{ - return deviceId == 0 && - inodeId == 0; -} - -inline -bool util::FileID::operator==(const FileID& rhs) const -{ - return deviceId == rhs.deviceId && - inodeId == rhs.inodeId; -} - -inline -bool util::FileID::operator<(const FileID& rhs) const -{ - if (deviceId != rhs.deviceId) - return deviceId < rhs.deviceId; - - return inodeId < rhs.inodeId; -} - -inline -util::FileID::FileID(wxInputStream& stream) //read -{ - stream.Read(&deviceId, sizeof(deviceId)); - stream.Read(&inodeId, sizeof(inodeId)); -} - -inline -void util::FileID::toStream(wxOutputStream& stream) const //write -{ - stream.Write(&deviceId, sizeof(deviceId)); - stream.Write(&inodeId, sizeof(inodeId)); -} -#endif -inline -bool util::FileID::operator!=(const FileID& rhs) const -{ - return !(*this == rhs); -} - #endif // FILEID_H_INCLUDED diff --git a/shared/file_io.cpp b/shared/file_io.cpp index 78796bbe..b75b8a13 100644 --- a/shared/file_io.cpp +++ b/shared/file_io.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "file_io.h" @@ -61,7 +61,7 @@ FileInput::FileInput(const Zstring& filename) : //throw FileError() const DWORD lastError = ::GetLastError(); const wxString& errorMessage = wxString(_("Error opening file:")) + wxT("\n\"") + zToWx(filename_) + wxT("\"") + wxT("\n\n") + ffs3::getLastErrorFormatted(lastError); if (lastError == ERROR_FILE_NOT_FOUND || - lastError == ERROR_PATH_NOT_FOUND) + lastError == ERROR_PATH_NOT_FOUND) throw ErrorNotExisting(errorMessage); else throw FileError(errorMessage); diff --git a/shared/file_io.h b/shared/file_io.h index c3fb3f65..0781595b 100644 --- a/shared/file_io.h +++ b/shared/file_io.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef FILEIO_H_INCLUDED diff --git a/shared/file_traverser.cpp b/shared/file_traverser.cpp index f2b531e9..66242fa2 100644 --- a/shared/file_traverser.cpp +++ b/shared/file_traverser.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "file_traverser.h" @@ -170,7 +170,13 @@ private: { details.targetPath = getSymlinkRawTargetString(fullName); //throw (FileError) } - catch (FileError&) {} + catch (FileError& e) + { + (void)e; +#ifndef NDEBUG //show broken symlink / access errors in debug build! + sink.onError(e.msg()); +#endif + } details.lastWriteTimeRaw = getWin32TimeInformation(fileMetaData.ftLastWriteTime); details.dirLink = (fileMetaData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; //directory symlinks have this flag on Windows @@ -225,13 +231,12 @@ private: &fileMetaData)); // pointer to structure for data on found file const DWORD lastError = ::GetLastError(); - if (lastError == ERROR_NO_MORE_FILES) - return; //everything okay - - //else: we have a problem... report it: - const wxString errorMessage = wxString(_("Error traversing directory:")) + wxT("\n\"") + zToWx(directory) + wxT("\"") ; - sink.onError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted(lastError)); - return; + if (lastError != ERROR_NO_MORE_FILES) //this is fine + { + //else we have a problem... report it: + const wxString errorMessage = wxString(_("Error traversing directory:")) + wxT("\n\"") + zToWx(directory) + wxT("\"") ; + sink.onError(errorMessage + wxT("\n\n") + ffs3::getLastErrorFormatted(lastError)); + } #elif defined FFS_LINUX DIR* dirObj = ::opendir(directory.c_str()); //directory must NOT end with path separator, except "/" @@ -301,7 +306,12 @@ private: { details.targetPath = getSymlinkRawTargetString(fullName); //throw (FileError) } - catch (FileError&) {} + catch (FileError& e) + { +#ifndef NDEBUG //show broken symlink / access errors in debug build! + sink.onError(e.msg()); +#endif + } details.lastWriteTimeRaw = fileInfo.st_mtime; //UTC time(ANSI C format); unit: 1 second details.dirLink = ::stat(fullName.c_str(), &fileInfo) == 0 && S_ISDIR(fileInfo.st_mode); //S_ISDIR and S_ISLNK are mutually exclusive on Linux => need to follow link diff --git a/shared/file_traverser.h b/shared/file_traverser.h index 61237834..0e25886b 100644 --- a/shared/file_traverser.h +++ b/shared/file_traverser.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef FILETRAVERSER_H_INCLUDED diff --git a/shared/global_func.cpp b/shared/global_func.cpp index c3d76c57..fe741b22 100644 --- a/shared/global_func.cpp +++ b/shared/global_func.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "global_func.h" diff --git a/shared/global_func.h b/shared/global_func.h index 20221f63..169ad611 100644 --- a/shared/global_func.h +++ b/shared/global_func.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef GLOBALFUNCTIONS_H_INCLUDED diff --git a/shared/guid.cpp b/shared/guid.cpp index b20a1143..dcf63e60 100644 --- a/shared/guid.cpp +++ b/shared/guid.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "guid.h" @@ -12,59 +12,17 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" #endif + #include <boost/uuid/uuid_generators.hpp> + #ifdef __MINGW32__ #pragma GCC diagnostic pop #endif -#include <cassert> -#include <algorithm> -#include <vector> - -using namespace util; - - -struct UniqueId::IntData -{ - boost::uuids::uuid nativeRep; -}; - - -UniqueId::UniqueId() : pData(new IntData) -{ - pData->nativeRep = boost::uuids::random_generator()(); -} - - -bool UniqueId::operator==(const UniqueId rhs) const -{ - return pData->nativeRep == rhs.pData->nativeRep; -} - -bool UniqueId::operator<(const UniqueId rhs) const +std::string util::generateGUID() //creates a 16 byte GUID { - return pData->nativeRep < rhs.pData->nativeRep; -} - - -UniqueId::UniqueId(wxInputStream& stream) : //read - pData(new IntData) -{ - std::vector<char> rawData(boost::uuids::uuid::static_size()); - stream.Read(&rawData[0], rawData.size()); - - std::copy(rawData.begin(), rawData.end(), pData->nativeRep.begin()); -} - - -void UniqueId::toStream(wxOutputStream& stream) const //write -{ - std::vector<char> rawData; - std::copy(pData->nativeRep.begin(), pData->nativeRep.end(), std::back_inserter(rawData)); - - assert(boost::uuids::uuid::static_size() == rawData.size()); - - stream.Write(&rawData[0], rawData.size()); + boost::uuids::uuid nativeRep = boost::uuids::random_generator()(); + return std::string(nativeRep.begin(), nativeRep.end()); } diff --git a/shared/guid.h b/shared/guid.h index 49d2f008..166e9eb1 100644 --- a/shared/guid.h +++ b/shared/guid.h @@ -1,32 +1,18 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef GUID_H_INCLUDED #define GUID_H_INCLUDED -#include <wx/stream.h> -#include <boost/shared_ptr.hpp> +#include <string> + namespace util { -class UniqueId -{ -public: - UniqueId(); //create UUID - - UniqueId(wxInputStream& stream); //read - void toStream(wxOutputStream& stream) const; //write - - bool operator==(const UniqueId rhs) const; - bool operator<(const UniqueId rhs) const; - -private: - struct IntData; - boost::shared_ptr<IntData> pData; -}; +std::string generateGUID(); //creates a 16 byte GUID } diff --git a/shared/help_provider.cpp b/shared/help_provider.cpp index 0110934c..9b9e1bc6 100644 --- a/shared/help_provider.cpp +++ b/shared/help_provider.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "help_provider.h" @@ -21,8 +21,6 @@ public: wxT("FreeFileSync.chm")); #elif defined FFS_LINUX wxT("Help/FreeFileSync.hhp")); - - wxImage::AddHandler(new wxJPEGHandler); //ownership passed; display .jpg files correctly in Linux #endif } diff --git a/shared/help_provider.h b/shared/help_provider.h index b59f47a8..0fd9ab2f 100644 --- a/shared/help_provider.h +++ b/shared/help_provider.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef HELPPROVIDER_H_INCLUDED diff --git a/shared/localization.cpp b/shared/localization.cpp index ae9b5143..678767b9 100644 --- a/shared/localization.cpp +++ b/shared/localization.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "localization.h" @@ -48,7 +48,7 @@ const std::vector<ffs3::LocInfoLine>& LocalizationInfo::getMapping() namespace { - struct CompareByName : public std::binary_function<ffs3::LocInfoLine, ffs3::LocInfoLine, bool> +struct CompareByName : public std::binary_function<ffs3::LocInfoLine, ffs3::LocInfoLine, bool> { bool operator()(const ffs3::LocInfoLine& lhs, const ffs3::LocInfoLine& rhs) const { @@ -97,6 +97,13 @@ LocalizationInfo::LocalizationInfo() newEntry.languageFlag = wxT("spain.png"); locMapping.push_back(newEntry); + newEntry.languageID = wxLANGUAGE_GREEK; + newEntry.languageName = wxT("Ελληνικά"); + newEntry.languageFile = wxT("greek.lng"); + newEntry.translatorName = wxT("Γιώργος Γιαγλής"); + newEntry.languageFlag = wxT("greece.png"); + locMapping.push_back(newEntry); + newEntry.languageID = wxLANGUAGE_FRENCH; newEntry.languageName = wxT("Français"); newEntry.languageFile = wxT("french.lng"); @@ -299,6 +306,7 @@ int mapLanguageDialect(const int language) //case wxLANGUAGE_CZECH: //case wxLANGUAGE_FINNISH: + //case wxLANGUAGE_GREEK: //case wxLANGUAGE_JAPANESE: //case wxLANGUAGE_POLISH: //case wxLANGUAGE_SLOVENIAN: diff --git a/shared/localization.h b/shared/localization.h index 9435030d..40d71423 100644 --- a/shared/localization.h +++ b/shared/localization.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef MISC_H_INCLUDED diff --git a/shared/long_path_prefix.cpp b/shared/long_path_prefix.cpp index 1c17065c..3fb0703d 100644 --- a/shared/long_path_prefix.cpp +++ b/shared/long_path_prefix.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "long_path_prefix.h" diff --git a/shared/long_path_prefix.h b/shared/long_path_prefix.h index b14a17dc..df4c31ab 100644 --- a/shared/long_path_prefix.h +++ b/shared/long_path_prefix.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef LONGPATHPREFIX_H_INCLUDED diff --git a/shared/perf.h b/shared/perf.h index e4e279bb..4f955748 100644 --- a/shared/perf.h +++ b/shared/perf.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef DEBUG_PERF_HEADER diff --git a/shared/privilege.cpp b/shared/privilege.cpp new file mode 100644 index 00000000..16f9d385 --- /dev/null +++ b/shared/privilege.cpp @@ -0,0 +1,102 @@ +#include "privilege.h" +#include <wx/intl.h> +#include "system_func.h" +#include <boost/shared_ptr.hpp> + +using namespace ffs3; + + +Privileges& Privileges::getInstance() +{ + static Privileges instance; + return instance; +} + + +bool Privileges::privilegeIsActive(LPCTSTR privilege) //throw FileError() +{ + HANDLE hToken = NULL; + if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle, + TOKEN_QUERY, //__in DWORD DesiredAccess, + &hToken)) //__out PHANDLE TokenHandle + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + boost::shared_ptr<void> dummy(hToken, ::CloseHandle); + + LUID luid = {0}; + if (!::LookupPrivilegeValue( + NULL, //__in_opt LPCTSTR lpSystemName, + privilege, //__in LPCTSTR lpName, + &luid )) //__out PLUID lpLuid + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + + PRIVILEGE_SET priv = {0}; + priv.PrivilegeCount = 1; + priv.Control = PRIVILEGE_SET_ALL_NECESSARY; + priv.Privilege[0].Luid = luid; + priv.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED; + + BOOL alreadyGranted = FALSE; + if (!::PrivilegeCheck( + hToken, //__in HANDLE ClientToken, + &priv, //__inout PPRIVILEGE_SET RequiredPrivileges, + &alreadyGranted)) //__out LPBOOL pfResult + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + + return alreadyGranted == TRUE; +} + + +void Privileges::setPrivilege(LPCTSTR privilege, bool enable) //throw FileError() +{ + HANDLE hToken = NULL; + if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle, + TOKEN_ADJUST_PRIVILEGES, //__in DWORD DesiredAccess, + &hToken)) //__out PHANDLE TokenHandle + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + boost::shared_ptr<void> dummy(hToken, ::CloseHandle); + + LUID luid = {0}; + if (!::LookupPrivilegeValue( + NULL, //__in_opt LPCTSTR lpSystemName, + privilege, //__in LPCTSTR lpName, + &luid )) //__out PLUID lpLuid + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + + TOKEN_PRIVILEGES tp = {0}; + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0; + + if (!::AdjustTokenPrivileges( + hToken, //__in HANDLE TokenHandle, + false, //__in BOOL DisableAllPrivileges, + &tp, //__in_opt PTOKEN_PRIVILEGES NewState, + 0, //__in DWORD BufferLength, + NULL, //__out_opt PTOKEN_PRIVILEGES PreviousState, + NULL)) //__out_opt PDWORD ReturnLength + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } + + if (::GetLastError() == ERROR_NOT_ALL_ASSIGNED) //check although previous function returned with success! + { + const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"") + wxT("\n\n"); + throw FileError(errorMessage + ffs3::getLastErrorFormatted()); + } +} diff --git a/shared/privilege.h b/shared/privilege.h new file mode 100644 index 00000000..c5ec99c7 --- /dev/null +++ b/shared/privilege.h @@ -0,0 +1,59 @@ +#ifndef PRIVILEGE_H_INCLUDED +#define PRIVILEGE_H_INCLUDED + +#include <map> +#include "zstring.h" +#include "file_error.h" +#include <wx/msw/wrapwin.h> //includes "windows.h" + + +namespace ffs3 +{ +#ifdef FFS_WIN +class Privileges +{ +public: + static Privileges& getInstance(); + + void ensureActive(LPCTSTR privilege) //throw FileError() + { + if (activePrivileges.find(privilege) != activePrivileges.end()) + return; //privilege already active + + if (privilegeIsActive(privilege)) //privilege was already active before starting this tool + activePrivileges.insert(std::make_pair(privilege, false)); + else + { + setPrivilege(privilege, true); + activePrivileges.insert(std::make_pair(privilege, true)); + } + } + +private: + Privileges() {} + Privileges(Privileges&); + void operator=(Privileges&); + + ~Privileges() //clean up: deactivate all privileges that have been activated by this application + { + for (PrivBuffType::const_iterator i = activePrivileges.begin(); i != activePrivileges.end(); ++i) + try + { + if (i->second) + Privileges::setPrivilege(i->first, false); + } + catch(...) {} + } + + static bool privilegeIsActive(LPCTSTR privilege); //throw FileError() + static void setPrivilege(LPCTSTR privilege, bool enable); //throw FileError() + + typedef std::map<Zstring, bool> PrivBuffType; //bool: enabled by this application + + PrivBuffType activePrivileges; +}; +#endif +} + + +#endif // PRIVILEGE_H_INCLUDED diff --git a/shared/recycler.cpp b/shared/recycler.cpp index 2ee23462..4a0d7290 100644 --- a/shared/recycler.cpp +++ b/shared/recycler.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "recycler.h" diff --git a/shared/recycler.h b/shared/recycler.h index 7537e875..b9fc9719 100644 --- a/shared/recycler.h +++ b/shared/recycler.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef RECYCLER_H_INCLUDED diff --git a/shared/serialize.cpp b/shared/serialize.cpp index f5765d3d..f71207be 100644 --- a/shared/serialize.cpp +++ b/shared/serialize.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "serialize.h" @@ -13,13 +13,13 @@ using namespace util; void ReadInputStream::throwReadError() const //throw FileError() { throw ffs3::FileError(wxString(_("Error reading from synchronization database:")) + wxT(" \n") + - wxT("\"") + errorObjName_ + wxT("\"")); + wxT("\"") + errorObjName_ + wxT("\"")); } ReadInputStream::CharArray ReadInputStream::readArrayC() const { - const size_t byteCount = readNumberC<size_t>(); + const boost::uint32_t byteCount = readNumberC<boost::uint32_t>(); CharArray buffer(new std::vector<char>(byteCount)); if (byteCount > 0) { @@ -36,13 +36,13 @@ ReadInputStream::CharArray ReadInputStream::readArrayC() const void WriteOutputStream::throwWriteError() const //throw FileError() { throw ffs3::FileError(wxString(_("Error writing to synchronization database:")) + wxT(" \n") + - wxT("\"") + errorObjName_ + wxT("\"")); + wxT("\"") + errorObjName_ + wxT("\"")); } void WriteOutputStream::writeArrayC(const std::vector<char>& buffer) const { - writeNumberC<size_t>(buffer.size()); + writeNumberC<boost::uint32_t>(static_cast<boost::uint32_t>(buffer.size())); if (buffer.size() > 0) { stream_.Write(&buffer[0], buffer.size()); diff --git a/shared/serialize.h b/shared/serialize.h index 5f1d5fbf..8da0a449 100644 --- a/shared/serialize.h +++ b/shared/serialize.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SERIALIZE_H_INCLUDED @@ -37,7 +37,7 @@ protected: Zstring readStringC() const; //throw FileError(), checked read operation - typedef boost::shared_ptr<std::vector<char> > CharArray; + typedef boost::shared_ptr<std::vector<char> > CharArray; //there's no guarantee std::string has a ref-counted implementation... so use this "thing" CharArray readArrayC() const; //throw FileError() void check() const; @@ -129,7 +129,7 @@ void writeNumber(wxOutputStream& stream, T number) inline Zstring readString(wxInputStream& stream) { - const size_t strLength = readNumber<size_t>(stream); + const boost::uint32_t strLength = readNumber<boost::uint32_t>(stream); if (strLength <= 1000) { Zchar buffer[1000]; @@ -148,7 +148,7 @@ Zstring readString(wxInputStream& stream) inline void writeString(wxOutputStream& stream, const Zstring& str) { - writeNumber<size_t>(stream, str.length()); + writeNumber<boost::uint32_t>(stream, static_cast<boost::uint32_t>(str.length())); stream.Write(str.c_str(), sizeof(Zchar) * str.length()); } diff --git a/shared/shadow.cpp b/shared/shadow.cpp index 39f21d2a..5a70bb6e 100644 --- a/shared/shadow.cpp +++ b/shared/shadow.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "shadow.h" diff --git a/shared/shadow.h b/shared/shadow.h index 2be44b41..b122e59d 100644 --- a/shared/shadow.h +++ b/shared/shadow.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SHADOW_H_INCLUDED diff --git a/shared/standard_paths.cpp b/shared/standard_paths.cpp index 2bebe056..6f723ef7 100644 --- a/shared/standard_paths.cpp +++ b/shared/standard_paths.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "standard_paths.h" diff --git a/shared/standard_paths.h b/shared/standard_paths.h index 956cf81c..5ecae9a7 100644 --- a/shared/standard_paths.h +++ b/shared/standard_paths.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef STANDARDPATHS_H_INCLUDED diff --git a/shared/string_conv.h b/shared/string_conv.h index bb8f6c7e..85181d11 100644 --- a/shared/string_conv.h +++ b/shared/string_conv.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef STRINGCONV_H_INCLUDED diff --git a/shared/symlink_target.h b/shared/symlink_target.h index c68d5229..358f2913 100644 --- a/shared/symlink_target.h +++ b/shared/symlink_target.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SYMLINK_WIN_H_INCLUDED @@ -17,6 +17,7 @@ #ifdef FFS_WIN #include <wx/msw/wrapwin.h> //includes "windows.h" #include "WinIoCtl.h" +#include "privilege.h" #include "long_path_prefix.h" #elif defined FFS_LINUX @@ -60,7 +61,7 @@ typedef struct _REPARSE_DATA_BUFFER namespace { - //retrieve raw target data of symlink or junction +//retrieve raw target data of symlink or junction Zstring getSymlinkRawTargetString(const Zstring& linkPath) //throw (FileError) { using ffs3::zToWx; @@ -68,6 +69,13 @@ Zstring getSymlinkRawTargetString(const Zstring& linkPath) //throw (FileError) #ifdef FFS_WIN //FSCTL_GET_REPARSE_POINT: http://msdn.microsoft.com/en-us/library/aa364571(VS.85).aspx + try //setting privileges requires admin rights! This shall not cause an error in user mode! + { + //allow access to certain symbolic links/junctions + ffs3::Privileges::getInstance().ensureActive(SE_BACKUP_NAME); //throw FileError() + } + catch (...) {} + const HANDLE hLink = ::CreateFile(ffs3::applyLongPathPrefix(linkPath).c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, @@ -111,7 +119,7 @@ Zstring getSymlinkRawTargetString(const Zstring& linkPath) //throw (FileError) else if (reparseData.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { output = Zstring(reparseData.MountPointReparseBuffer.PathBuffer + reparseData.MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR), - reparseData.MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR)); + reparseData.MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR)); } else { diff --git a/shared/system_constants.h b/shared/system_constants.h index 7f34c467..6f89609e 100644 --- a/shared/system_constants.h +++ b/shared/system_constants.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SYSTEMCONSTANTS_H_INCLUDED diff --git a/shared/system_func.cpp b/shared/system_func.cpp index 4f60f724..430451e5 100644 --- a/shared/system_func.cpp +++ b/shared/system_func.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "system_func.h" diff --git a/shared/system_func.h b/shared/system_func.h index b15f4c0c..0bbd25d0 100644 --- a/shared/system_func.h +++ b/shared/system_func.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef SYSTEMFUNCTIONS_H_INCLUDED diff --git a/shared/taskbar.cpp b/shared/taskbar.cpp index f5f07c1e..881a1570 100644 --- a/shared/taskbar.cpp +++ b/shared/taskbar.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "taskbar.h" diff --git a/shared/taskbar.h b/shared/taskbar.h index acf2d6da..b41734b3 100644 --- a/shared/taskbar.h +++ b/shared/taskbar.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef TASKBARPROGRESS_H_INCLUDED diff --git a/shared/toggle_button.cpp b/shared/toggle_button.cpp index 2da64ee4..511822b1 100644 --- a/shared/toggle_button.cpp +++ b/shared/toggle_button.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "toggle_button.h" diff --git a/shared/toggle_button.h b/shared/toggle_button.h index a67d5fff..6613fdd4 100644 --- a/shared/toggle_button.h +++ b/shared/toggle_button.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef TOGGLEBUTTON_H_INCLUDED diff --git a/shared/util.cpp b/shared/util.cpp index 25c8c5e0..f115f8dc 100644 --- a/shared/util.cpp +++ b/shared/util.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "util.h" @@ -16,11 +16,22 @@ #include "system_func.h" #include "check_exist.h" #include "assert_static.h" +#include "system_constants.h" + #ifdef FFS_WIN #include <wx/msw/wrapwin.h> //includes "windows.h" #endif +wxString ffs3::extractJobName(const wxString& configFilename) +{ + using namespace common; + + const wxString shortName = configFilename.AfterLast(FILE_NAME_SEPARATOR); //returns the whole string if seperator not found + const wxString jobName = shortName.BeforeLast(wxChar('.')); //returns empty string if seperator not found + return jobName.IsEmpty() ? shortName : jobName; +} + wxString ffs3::formatFilesizeToShortString(const wxLongLong& filesize) { @@ -39,7 +50,7 @@ wxString ffs3::formatFilesizeToShortString(double filesize) if (filesize < 0) return _("Error"); - wxString output = _("%x Byte"); + wxString output = _("%x Bytes"); if (filesize > 999) { diff --git a/shared/util.h b/shared/util.h index 2495838c..90a73094 100644 --- a/shared/util.h +++ b/shared/util.h @@ -1,24 +1,26 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef UTIL_H_INCLUDED #define UTIL_H_INCLUDED -#include "../shared/zstring.h" #include <wx/string.h> #include <wx/longlong.h> -#include "../shared/global_func.h" #include <wx/textctrl.h> #include <wx/filepicker.h> #include <wx/combobox.h> #include <wx/scrolwin.h> +#include "zstring.h" +#include "global_func.h" namespace ffs3 { +wxString extractJobName(const wxString& configFilename); + wxString formatFilesizeToShortString(const wxLongLong& filesize); wxString formatFilesizeToShortString(const wxULongLong& filesize); wxString formatFilesizeToShortString(double filesize); diff --git a/shared/xml_base.cpp b/shared/xml_base.cpp index 3213786d..99d4d3ca 100644 --- a/shared/xml_base.cpp +++ b/shared/xml_base.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "xml_base.h" diff --git a/shared/xml_base.h b/shared/xml_base.h index 6d342b48..44650ec9 100644 --- a/shared/xml_base.h +++ b/shared/xml_base.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef XMLBASE_H_INCLUDED diff --git a/shared/xml_error.h b/shared/xml_error.h index bd5153cb..ea66af89 100644 --- a/shared/xml_error.h +++ b/shared/xml_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef XMLERROR_H_INCLUDED diff --git a/shared/zbase.h b/shared/zbase.h index 1caf0e44..c3d539a1 100644 --- a/shared/zbase.h +++ b/shared/zbase.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef Z_BASE_H_INCLUDED diff --git a/shared/zstring.cpp b/shared/zstring.cpp index 1a05831d..40590a90 100644 --- a/shared/zstring.cpp +++ b/shared/zstring.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #include "zstring.h" diff --git a/shared/zstring.h b/shared/zstring.h index a015dbe4..73e2f066 100644 --- a/shared/zstring.h +++ b/shared/zstring.h @@ -1,7 +1,7 @@ // ************************************************************************** // * 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) * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** // #ifndef ZSTRING_H_INCLUDED @@ -67,7 +67,7 @@ public: LeakChecker::instance().insert(newMem, size); //test Zbase for memory leaks return newMem; #else - return ::operator new(size); + return ::operator new(size); #endif } |