1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (c) Mark Harmstone 2016-17
 *
 * This file is part of WinBtrfs.
 *
 * WinBtrfs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public Licence as published by
 * the Free Software Foundation, either version 3 of the Licence, or
 * (at your option) any later version.
 *
 * WinBtrfs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public Licence for more details.
 *
 * You should have received a copy of the GNU Lesser General Public Licence
 * along with WinBtrfs.  If not, see <http://www.gnu.org/licenses/>. */

#pragma once

#include <shlobj.h>
#ifndef __REACTOS__
#include "../btrfsioctl.h"
#include "../btrfs.h"
#else
#include "btrfsioctl.h"
#include "btrfs.h"
#endif
#include "balance.h"
#include "scrub.h"

extern LONG objs_loaded;

class BtrfsVolPropSheet : public IShellExtInit, IShellPropSheetExt {
public:
    BtrfsVolPropSheet() {<--- Member variable 'BtrfsVolPropSheet::readonly' is not initialized in the constructor.<--- Member variable 'BtrfsVolPropSheet::uuid_set' is not initialized in the constructor.<--- Member variable 'BtrfsVolPropSheet::stats_dev' is not initialized in the constructor.
        refcount = 0;
        ignore = true;
        stgm_set = false;
        devices = nullptr;

        InterlockedIncrement(&objs_loaded);

        balance = nullptr;
    }

    virtual ~BtrfsVolPropSheet() {
        if (stgm_set) {
            GlobalUnlock(stgm.hGlobal);
            ReleaseStgMedium(&stgm);
        }

        if (devices)
            free(devices);

        InterlockedDecrement(&objs_loaded);

        if (balance)
            delete balance;
    }

    // IUnknown

    HRESULT __stdcall QueryInterface(REFIID riid, void **ppObj);

    ULONG __stdcall AddRef() {
        return InterlockedIncrement(&refcount);
    }

    ULONG __stdcall Release() {
        LONG rc = InterlockedDecrement(&refcount);

        if (rc == 0)
            delete this;

        return rc;
    }

    // IShellExtInit

    virtual HRESULT __stdcall Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID);

    // IShellPropSheetExt

    virtual HRESULT __stdcall AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam);
    virtual HRESULT __stdcall ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam);

    void FormatUsage(HWND hwndDlg, wstring& s, btrfs_usage* usage);
    void RefreshUsage(HWND hwndDlg);
    void ShowUsage(HWND hwndDlg);
    INT_PTR CALLBACK UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    void RefreshDevList(HWND devlist);
    INT_PTR CALLBACK DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    void ShowDevices(HWND hwndDlg);
    void ShowScrub(HWND hwndDlg);
    void ShowChangeDriveLetter(HWND hwndDlg);
    INT_PTR CALLBACK StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
    void ShowStats(HWND hwndDlg, uint64_t devid);
    void ResetStats(HWND hwndDlg);

    btrfs_device* devices;
    bool readonly;
    BtrfsBalance* balance;
    BTRFS_UUID uuid;
    bool uuid_set;

private:
    LONG refcount;
    bool ignore;
    STGMEDIUM stgm;
    bool stgm_set;
    wstring fn;
    uint64_t stats_dev;
};

class BtrfsChangeDriveLetter {
public:
    BtrfsChangeDriveLetter(HWND hwnd, const wstring_view& fn) : hwnd(hwnd), fn(fn) {
    }

    void show();
    INT_PTR DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
    void do_change(HWND hwndDlg);

    HWND hwnd;
    wstring fn;
    vector<wchar_t> letters;
};