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:
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 
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 
65     ULONG __stdcall AddRef() {
66         return InterlockedIncrement(&refcount);
67     }
68 
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     INT_PTR CALLBACK StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
96     void ShowStats(HWND hwndDlg, uint64_t devid);
97     void ResetStats(HWND hwndDlg);
98 
99     btrfs_device* devices;
100     bool readonly;
101     BtrfsBalance* balance;
102     BTRFS_UUID uuid;
103     bool uuid_set;
104 
105 private:
106     LONG refcount;
107     bool ignore;
108     STGMEDIUM stgm;
109     bool stgm_set;
110     wstring fn;
111     uint64_t stats_dev;
112 };
113