1c2c66affSColin Finck /* Copyright (c) Mark Harmstone 2016-17 2c2c66affSColin Finck * 3c2c66affSColin Finck * This file is part of WinBtrfs. 4c2c66affSColin Finck * 5c2c66affSColin Finck * WinBtrfs is free software: you can redistribute it and/or modify 6c2c66affSColin Finck * it under the terms of the GNU Lesser General Public Licence as published by 7c2c66affSColin Finck * the Free Software Foundation, either version 3 of the Licence, or 8c2c66affSColin Finck * (at your option) any later version. 9c2c66affSColin Finck * 10c2c66affSColin Finck * WinBtrfs is distributed in the hope that it will be useful, 11c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of 12c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13c2c66affSColin Finck * GNU Lesser General Public Licence for more details. 14c2c66affSColin Finck * 15c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public Licence 16c2c66affSColin Finck * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */ 17c2c66affSColin Finck 18b28272c5SAmine Khaldi #pragma once 19b28272c5SAmine Khaldi 20c2c66affSColin Finck #include <shlobj.h> 21c2c66affSColin Finck #include <deque> 22c2c66affSColin Finck #ifndef __REACTOS__ 23c2c66affSColin Finck #include "../btrfsioctl.h" 24c2c66affSColin Finck #else 25c2c66affSColin Finck #include "btrfsioctl.h" 26c2c66affSColin Finck #endif 27c2c66affSColin Finck 28c2c66affSColin Finck #ifndef S_IRUSR 29c2c66affSColin Finck #define S_IRUSR 0000400 30c2c66affSColin Finck #endif 31c2c66affSColin Finck 32c2c66affSColin Finck #ifndef S_IWUSR 33c2c66affSColin Finck #define S_IWUSR 0000200 34c2c66affSColin Finck #endif 35c2c66affSColin Finck 36c2c66affSColin Finck #ifndef S_IXUSR 37c2c66affSColin Finck #define S_IXUSR 0000100 38c2c66affSColin Finck #endif 39c2c66affSColin Finck 40c2c66affSColin Finck #ifndef S_IRGRP 41c2c66affSColin Finck #define S_IRGRP (S_IRUSR >> 3) 42c2c66affSColin Finck #endif 43c2c66affSColin Finck 44c2c66affSColin Finck #ifndef S_IWGRP 45c2c66affSColin Finck #define S_IWGRP (S_IWUSR >> 3) 46c2c66affSColin Finck #endif 47c2c66affSColin Finck 48c2c66affSColin Finck #ifndef S_IXGRP 49c2c66affSColin Finck #define S_IXGRP (S_IXUSR >> 3) 50c2c66affSColin Finck #endif 51c2c66affSColin Finck 52c2c66affSColin Finck #ifndef S_IROTH 53c2c66affSColin Finck #define S_IROTH (S_IRGRP >> 3) 54c2c66affSColin Finck #endif 55c2c66affSColin Finck 56c2c66affSColin Finck #ifndef S_IWOTH 57c2c66affSColin Finck #define S_IWOTH (S_IWGRP >> 3) 58c2c66affSColin Finck #endif 59c2c66affSColin Finck 60c2c66affSColin Finck #ifndef S_IXOTH 61c2c66affSColin Finck #define S_IXOTH (S_IXGRP >> 3) 62c2c66affSColin Finck #endif 63c2c66affSColin Finck 64c2c66affSColin Finck #ifndef S_ISUID 65c2c66affSColin Finck #define S_ISUID 0004000 66c2c66affSColin Finck #endif 67c2c66affSColin Finck 68c2c66affSColin Finck #ifndef S_ISGID 69c2c66affSColin Finck #define S_ISGID 0002000 70c2c66affSColin Finck #endif 71c2c66affSColin Finck 72c2c66affSColin Finck #ifndef S_ISVTX 73c2c66affSColin Finck #define S_ISVTX 0001000 74c2c66affSColin Finck #endif 75c2c66affSColin Finck 76c2c66affSColin Finck #define BTRFS_INODE_NODATASUM 0x001 77c2c66affSColin Finck #define BTRFS_INODE_NODATACOW 0x002 78c2c66affSColin Finck #define BTRFS_INODE_READONLY 0x004 79c2c66affSColin Finck #define BTRFS_INODE_NOCOMPRESS 0x008 80c2c66affSColin Finck #define BTRFS_INODE_PREALLOC 0x010 81c2c66affSColin Finck #define BTRFS_INODE_SYNC 0x020 82c2c66affSColin Finck #define BTRFS_INODE_IMMUTABLE 0x040 83c2c66affSColin Finck #define BTRFS_INODE_APPEND 0x080 84c2c66affSColin Finck #define BTRFS_INODE_NODUMP 0x100 85c2c66affSColin Finck #define BTRFS_INODE_NOATIME 0x200 86c2c66affSColin Finck #define BTRFS_INODE_DIRSYNC 0x400 87c2c66affSColin Finck #define BTRFS_INODE_COMPRESS 0x800 88c2c66affSColin Finck 89c2c66affSColin Finck extern LONG objs_loaded; 90c2c66affSColin Finck 91c2c66affSColin Finck class BtrfsPropSheet : public IShellExtInit, IShellPropSheetExt { 92c2c66affSColin Finck public: BtrfsPropSheet()93c2c66affSColin Finck BtrfsPropSheet() { 94c2c66affSColin Finck refcount = 0; 957b718d36SPierre Schweitzer ignore = true; 967b718d36SPierre Schweitzer stgm_set = false; 977b718d36SPierre Schweitzer readonly = false; 987b718d36SPierre Schweitzer flags_changed = false; 997b718d36SPierre Schweitzer perms_changed = false; 1007b718d36SPierre Schweitzer uid_changed = false; 1017b718d36SPierre Schweitzer gid_changed = false; 1027b718d36SPierre Schweitzer compress_type_changed = false; 1037b718d36SPierre Schweitzer ro_changed = false; 1047b718d36SPierre Schweitzer can_change_perms = false; 1057b718d36SPierre Schweitzer show_admin_button = false; 1067b718d36SPierre Schweitzer thread = nullptr; 107c2c66affSColin Finck mode = mode_set = 0; 108c2c66affSColin Finck flags = flags_set = 0; 1097b718d36SPierre Schweitzer has_subvols = false; 110c2c66affSColin Finck filename = L""; 111c2c66affSColin Finck 1127b718d36SPierre Schweitzer sizes[0] = sizes[1] = sizes[2] = sizes[3] = sizes[4] = 0; 1137b718d36SPierre Schweitzer totalsize = allocsize = sparsesize = 0; 114*aed50d7eSPierre Schweitzer num_extents = 0; 115*aed50d7eSPierre Schweitzer sector_size = 0; 1167b718d36SPierre Schweitzer size_format[0] = 0; 1177b718d36SPierre Schweitzer cr_format[0] = 0; 118*aed50d7eSPierre Schweitzer frag_format[0] = 0; 119c2c66affSColin Finck 120c2c66affSColin Finck InterlockedIncrement(&objs_loaded); 121c2c66affSColin Finck } 122c2c66affSColin Finck ~BtrfsPropSheet()123c2c66affSColin Finck virtual ~BtrfsPropSheet() { 124c2c66affSColin Finck if (stgm_set) { 125c2c66affSColin Finck GlobalUnlock(stgm.hGlobal); 126c2c66affSColin Finck ReleaseStgMedium(&stgm); 127c2c66affSColin Finck } 128c2c66affSColin Finck 129c2c66affSColin Finck InterlockedDecrement(&objs_loaded); 130c2c66affSColin Finck } 131c2c66affSColin Finck 132c2c66affSColin Finck // IUnknown 133c2c66affSColin Finck 134c2c66affSColin Finck HRESULT __stdcall QueryInterface(REFIID riid, void **ppObj); 135c2c66affSColin Finck AddRef()136c2c66affSColin Finck ULONG __stdcall AddRef() { 137c2c66affSColin Finck return InterlockedIncrement(&refcount); 138c2c66affSColin Finck } 139c2c66affSColin Finck Release()140c2c66affSColin Finck ULONG __stdcall Release() { 141c2c66affSColin Finck LONG rc = InterlockedDecrement(&refcount); 142c2c66affSColin Finck 143c2c66affSColin Finck if (rc == 0) 144c2c66affSColin Finck delete this; 145c2c66affSColin Finck 146c2c66affSColin Finck return rc; 147c2c66affSColin Finck } 148c2c66affSColin Finck 149c2c66affSColin Finck // IShellExtInit 150c2c66affSColin Finck 151c2c66affSColin Finck virtual HRESULT __stdcall Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID); 152c2c66affSColin Finck 153c2c66affSColin Finck // IShellPropSheetExt 154c2c66affSColin Finck 155c2c66affSColin Finck virtual HRESULT __stdcall AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam); 156c2c66affSColin Finck virtual HRESULT __stdcall ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam); 157c2c66affSColin Finck 158c2c66affSColin Finck void init_propsheet(HWND hwndDlg); 1597b718d36SPierre Schweitzer void change_inode_flag(HWND hDlg, uint64_t flag, UINT state); 160c2c66affSColin Finck void change_perm_flag(HWND hDlg, ULONG perm, UINT state); 1617b718d36SPierre Schweitzer void change_uid(HWND hDlg, uint32_t uid); 1627b718d36SPierre Schweitzer void change_gid(HWND hDlg, uint32_t gid); 163c2c66affSColin Finck void apply_changes(HWND hDlg); 164c2c66affSColin Finck void set_size_on_disk(HWND hwndDlg); 165c2c66affSColin Finck DWORD search_list_thread(); 1667b718d36SPierre Schweitzer void do_search(const wstring& fn); 167c2c66affSColin Finck void update_size_details_dialog(HWND hDlg); 168c2c66affSColin Finck void open_as_admin(HWND hwndDlg); 1697b718d36SPierre Schweitzer void set_cmdline(const wstring& cmdline); 170c2c66affSColin Finck 1717b718d36SPierre Schweitzer bool readonly; 1727b718d36SPierre Schweitzer bool can_change_perms; 1737b718d36SPierre Schweitzer bool can_change_nocow; 174*aed50d7eSPierre Schweitzer WCHAR size_format[255], cr_format[255], frag_format[255]; 175c2c66affSColin Finck HANDLE thread; 1767b718d36SPierre Schweitzer uint32_t min_mode, max_mode, mode, mode_set; 1777b718d36SPierre Schweitzer uint64_t min_flags, max_flags, flags, flags_set; 1787b718d36SPierre Schweitzer uint64_t subvol, inode, rdev; 1797b718d36SPierre Schweitzer uint8_t type, min_compression_type, max_compression_type, compress_type; 1807b718d36SPierre Schweitzer uint32_t uid, gid; 1817b718d36SPierre Schweitzer bool various_subvols, various_inodes, various_types, various_uids, various_gids, compress_type_changed, has_subvols, 182c2c66affSColin Finck ro_subvol, various_ro, ro_changed, show_admin_button; 183c2c66affSColin Finck 184c2c66affSColin Finck private: 185c2c66affSColin Finck LONG refcount; 1867b718d36SPierre Schweitzer bool ignore; 187c2c66affSColin Finck STGMEDIUM stgm; 1887b718d36SPierre Schweitzer bool stgm_set; 1897b718d36SPierre Schweitzer bool flags_changed, perms_changed, uid_changed, gid_changed; 190*aed50d7eSPierre Schweitzer uint64_t sizes[5], totalsize, allocsize, sparsesize, num_extents; 1917b718d36SPierre Schweitzer deque<wstring> search_list; 1927b718d36SPierre Schweitzer wstring filename; 193*aed50d7eSPierre Schweitzer uint32_t sector_size; 194c2c66affSColin Finck 1957b718d36SPierre Schweitzer void apply_changes_file(HWND hDlg, const wstring& fn); 1967b718d36SPierre Schweitzer HRESULT check_file(const wstring& fn, UINT i, UINT num_files, UINT* sv); 197c2c66affSColin Finck HRESULT load_file_list(); 198c2c66affSColin Finck }; 199