1 /* Copyright (c) Mark Harmstone 2016-17
2  *
3  * This file is part of WinBtrfs.
4  *
5  * WinBtrfs is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public Licence as published by
7  * the Free Software Foundation, either version 3 of the Licence, or
8  * (at your option) any later version.
9  *
10  * WinBtrfs is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public Licence for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public Licence
16  * along with WinBtrfs.  If not, see <http://www.gnu.org/licenses/>. */
17 
18 #pragma once
19 
20 #include <shlobj.h>
21 #ifndef __REACTOS__
22 #include "../btrfsioctl.h"
23 #include "../btrfs.h"
24 #else
25 #include "btrfsioctl.h"
26 #include "btrfs.h"
27 #endif
28 #include "balance.h"
29 #include "scrub.h"
30 
31 extern LONG objs_loaded;
32 
33 class BtrfsVolPropSheet : public IShellExtInit, IShellPropSheetExt {
34 public:
BtrfsVolPropSheet()35     BtrfsVolPropSheet() {
36         refcount = 0;
37         ignore = true;
38         stgm_set = false;
39         devices = nullptr;
40 
41         InterlockedIncrement(&objs_loaded);
42 
43         balance = nullptr;
44     }
45 
~BtrfsVolPropSheet()46     virtual ~BtrfsVolPropSheet() {
47         if (stgm_set) {
48             GlobalUnlock(stgm.hGlobal);
49             ReleaseStgMedium(&stgm);
50         }
51 
52         if (devices)
53             free(devices);
54 
55         InterlockedDecrement(&objs_loaded);
56 
57         if (balance)
58             delete balance;
59     }
60 
61     // IUnknown
62 
63     HRESULT __stdcall QueryInterface(REFIID riid, void **ppObj);
64 
AddRef()65     ULONG __stdcall AddRef() {
66         return InterlockedIncrement(&refcount);
67     }
68 
Release()69     ULONG __stdcall Release() {
70         LONG rc = InterlockedDecrement(&refcount);
71 
72         if (rc == 0)
73             delete this;
74 
75         return rc;
76     }
77 
78     // IShellExtInit
79 
80     virtual HRESULT __stdcall Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID);
81 
82     // IShellPropSheetExt
83 
84     virtual HRESULT __stdcall AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam);
85     virtual HRESULT __stdcall ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam);
86 
87     void FormatUsage(HWND hwndDlg, wstring& s, btrfs_usage* usage);
88     void RefreshUsage(HWND hwndDlg);
89     void ShowUsage(HWND hwndDlg);
90     INT_PTR CALLBACK UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
91     void RefreshDevList(HWND devlist);
92     INT_PTR CALLBACK DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
93     void ShowDevices(HWND hwndDlg);
94     void ShowScrub(HWND hwndDlg);
95     void ShowChangeDriveLetter(HWND hwndDlg);
96     INT_PTR CALLBACK StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
97     void ShowStats(HWND hwndDlg, uint64_t devid);
98     void ResetStats(HWND hwndDlg);
99 
100     btrfs_device* devices;
101     bool readonly;
102     BtrfsBalance* balance;
103     BTRFS_UUID uuid;
104     bool uuid_set;
105 
106 private:
107     LONG refcount;
108     bool ignore;
109     STGMEDIUM stgm;
110     bool stgm_set;
111     wstring fn;
112     uint64_t stats_dev;
113 };
114 
115 class BtrfsChangeDriveLetter {
116 public:
BtrfsChangeDriveLetter(HWND hwnd,const wstring_view & fn)117     BtrfsChangeDriveLetter(HWND hwnd, const wstring_view& fn) : hwnd(hwnd), fn(fn) {
118     }
119 
120     void show();
121     INT_PTR DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
122 
123 private:
124     void do_change(HWND hwndDlg);
125 
126     HWND hwnd;
127     wstring fn;
128     vector<wchar_t> letters;
129 };
130