Welcome to mirror list, hosted at ThFree Co, Russian Federation.

options.h « windirstat - github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 434f005c83f2609a88cec208e7f36fb5141cdf20 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// options.h - Declaration of CRegistryUser, COptions and CPersistence
//
// WinDirStat - Directory Statistics
// Copyright (C) 2003-2005 Bernhard Seifert
// Copyright (C) 2004-2017 WinDirStat Team (windirstat.net)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

#ifndef __WDS_OPTIONS_H__
#define __WDS_OPTIONS_H__
#pragma once

#ifndef __NOT_WDS
#include "treemap.h"
#endif // __NOT_WDS
#include <common/wds_constants.h>
#include <common/SimpleIni.h>
#include <atlbase.h> // CRegKey
#include <memory>

#ifndef __NOT_WDS
class COptions;

enum REFRESHPOLICY
{
    RP_NO_REFRESH,
    RP_REFRESH_THIS_ENTRY,
    RP_REFRESH_THIS_ENTRYS_PARENT,
    // RP_ASSUME_ENTRY_HAS_BEEN_DELETED, // feature not implemented.
    REFRESHPOLICYCOUNT
};

struct USERDEFINEDCLEANUP
{
    bool enabled;
    bool virginTitle;
    CString title;
    bool worksForDrives;
    bool worksForDirectories;
    bool worksForFilesFolder;
    bool worksForFiles;
    bool worksForUncPaths;
    CString commandLine;
    bool recurseIntoSubdirectories;
    bool askForConfirmation;
    bool showConsoleWindow;
    bool waitForCompletion;
    REFRESHPOLICY refreshPolicy;
};
#endif // __NOT_WDS

#define USERDEFINEDCLEANUPCOUNT 10

#define TREELISTCOLORCOUNT 8

// Base interface for retrieving/storing configuration
// The ctor of derived classes is allowed to throw an HRESULT if something
// goes wrong.
class ICfgStorage
{
public:
    virtual void setString(LPCTSTR section, LPCTSTR entry, LPCTSTR value) = 0;
    virtual CString getString(LPCTSTR section, LPCTSTR entry, LPCTSTR defaultValue) = 0;

    virtual void setInt(LPCTSTR section, LPCTSTR entry, int value) = 0;
    virtual int getInt(LPCTSTR section, LPCTSTR entry, int defaultValue) = 0;

    virtual void setUint(LPCTSTR section, LPCTSTR entry, unsigned int value) = 0;
    virtual unsigned int getUint(LPCTSTR section, LPCTSTR entry, unsigned int defaultValue) = 0;

    virtual void setBool(LPCTSTR section, LPCTSTR entry, bool value) = 0;
    virtual bool getBool(LPCTSTR section, LPCTSTR entry, bool defaultValue) = 0;

    virtual void flush() = 0;
    virtual long getLastError() const = 0;
};

class CRegistryStg : public ICfgStorage
{
    CRegistryStg(); // hide
    CRegistryStg& operator=(const CRegistryStg&); // hide
public:
    CRegistryStg(HKEY hKeyParent, LPCTSTR lpszKeyName);

    virtual void setString(LPCTSTR section, LPCTSTR entry, LPCTSTR value);
    virtual CString getString(LPCTSTR section, LPCTSTR entry, LPCTSTR defaultValue);

    virtual void setInt(LPCTSTR section, LPCTSTR entry, int value);
    virtual int getInt(LPCTSTR section, LPCTSTR entry, int defaultValue);

    virtual void setUint(LPCTSTR section, LPCTSTR entry, unsigned int value);
    virtual unsigned int getUint(LPCTSTR section, LPCTSTR entry, unsigned int defaultValue);

    virtual void setBool(LPCTSTR section, LPCTSTR entry, bool value);
    virtual bool getBool(LPCTSTR section, LPCTSTR entry, bool defaultValue);

    virtual void flush();
    virtual long getLastError() const;

private:
    mutable long m_lastError;
    REGSAM const m_sam;
    HKEY m_parentKey;
    CString m_lpszKeyName;

    CRegKey m_key;
};

class CIniFileStg : public ICfgStorage
{
    CIniFileStg(); // hide
    CIniFileStg& operator=(const CIniFileStg&); // hide
public:
    CIniFileStg(LPCTSTR lpszFilePath);
    ~CIniFileStg();

    virtual void setString(LPCTSTR section, LPCTSTR entry, LPCTSTR value);
    virtual CString getString(LPCTSTR section, LPCTSTR entry, LPCTSTR defaultValue);

    virtual void setInt(LPCTSTR section, LPCTSTR entry, int value);
    virtual int getInt(LPCTSTR section, LPCTSTR entry, int defaultValue);

    virtual void setUint(LPCTSTR section, LPCTSTR entry, unsigned int value);
    virtual unsigned int getUint(LPCTSTR section, LPCTSTR entry, unsigned int defaultValue);

    virtual void setBool(LPCTSTR section, LPCTSTR entry, bool value);
    virtual bool getBool(LPCTSTR section, LPCTSTR entry, bool defaultValue);

    virtual void flush();
    virtual long getLastError() const;

private:
    mutable long m_lastError;
    CString m_lpszFilePath;
    CSimpleIni m_ini;

    static HRESULT siErrorToHR_(SI_Error err);
};

// It's an aggregate, but provides the same interface
class CConfigStorage : public ICfgStorage
{
public:
    // primary *must* be given, secondary is optional
    CConfigStorage(ICfgStorage* primary, ICfgStorage* secondary);
    ~CConfigStorage();

    virtual void setString(LPCTSTR section, LPCTSTR entry, LPCTSTR value);
    virtual CString getString(LPCTSTR section, LPCTSTR entry, LPCTSTR defaultValue);

    virtual void setInt(LPCTSTR section, LPCTSTR entry, int value);
    virtual int getInt(LPCTSTR section, LPCTSTR entry, int defaultValue);

    virtual void setUint(LPCTSTR section, LPCTSTR entry, unsigned int value);
    virtual unsigned int getUint(LPCTSTR section, LPCTSTR entry, unsigned int defaultValue);

    virtual void setBool(LPCTSTR section, LPCTSTR entry, bool value);
    virtual bool getBool(LPCTSTR section, LPCTSTR entry, bool defaultValue);

private:
    std::auto_ptr<ICfgStorage> m_primaryStore;
    std::auto_ptr<ICfgStorage> m_secondaryStore;
};

class CRegistryUser
{
public:
    static void setProfileString(LPCTSTR section, LPCTSTR entry, LPCTSTR value);
    static CString getProfileString(LPCTSTR section, LPCTSTR entry, LPCTSTR defaultValue = wds::strEmpty);

    static void setProfileInt(LPCTSTR section, LPCTSTR entry, int value);
    static int getProfileInt(LPCTSTR section, LPCTSTR entry, int defaultValue);

    static void setProfileBool(LPCTSTR section, LPCTSTR entry, bool value);
    static bool getProfileBool(LPCTSTR section, LPCTSTR entry, bool defaultValue);

    static void checkRange(int& value, int min, int max);
    static void checkRange(unsigned int& value, unsigned int min, unsigned int max);
};


#ifndef __NOT_WDS
//
// CPersistence. Reads from and writes to the registry all the persistent settings
// like window position, column order etc.
//
class CPersistence: private CRegistryUser
{
public:
    static bool GetShowFreeSpace();
    static void SetShowFreeSpace(bool show);

    static bool GetShowUnknown();
    static void SetShowUnknown(bool show);

    static bool GetShowFileTypes();
    static void SetShowFileTypes(bool show);

    static bool GetShowTreemap();
    static void SetShowTreemap(bool show);

    static bool GetShowToolbar();
    static void SetShowToolbar(bool show);

    static bool GetShowStatusbar();
    static void SetShowStatusbar(bool show);

    static void GetMainWindowPlacement(/* [in/out] */ WINDOWPLACEMENT& wp);
    static void SetMainWindowPlacement(const WINDOWPLACEMENT& wp);

    static void SetSplitterPos(LPCTSTR name, bool valid, double userpos);
    static void GetSplitterPos(LPCTSTR name, bool& valid, double& userpos);

    static void SetColumnOrder(LPCTSTR name, const CArray<int, int>& arr);
    static void GetColumnOrder(LPCTSTR name, /* in/out */ CArray<int, int>& arr);

    static void SetColumnWidths(LPCTSTR name, const CArray<int, int>& arr);
    static void GetColumnWidths(LPCTSTR name, /* in/out */ CArray<int, int>& arr);

    static void SetDialogRectangle(LPCTSTR name, const CRect& rc);
    static void GetDialogRectangle(LPCTSTR name, CRect& rc);

//   static void SetSorting(LPCTSTR name, int column1, bool ascending1, int column2, bool ascending2);
//   static void GetSorting(LPCTSTR name, int columnCount, int& column1, bool& ascending1, int& column2, bool& ascending2);

    static int GetConfigPage(int max);
    static void SetConfigPage(int page);

    static void GetConfigPosition(/* in/out */ CPoint& pt);
    static void SetConfigPosition(CPoint pt);

    static CString GetBarStateSection();

    static int GetSelectDrivesRadio();
    static void SetSelectDrivesRadio(int radio);

    static CString GetSelectDrivesFolder();
    static void SetSelectDrivesFolder(LPCTSTR folder);

    static void GetSelectDrivesDrives(CStringArray& drives);
    static void SetSelectDrivesDrives(const CStringArray& drives);

    static bool GetShowDeleteWarning();
    static void SetShowDeleteWarning(bool show);

private:
    static void SetArray(LPCTSTR entry, const CArray<int, int>& arr);
    static void GetArray(LPCTSTR entry, /* in/out */ CArray<int, int>& arr);
    static void SetRect(LPCTSTR entry, const CRect& rc);
    static void GetRect(LPCTSTR entry, CRect& rc);
    static void SanitizeRect(CRect& rc);

    static CString EncodeWindowPlacement(const WINDOWPLACEMENT& wp);
    static void DecodeWindowPlacement(const CString& s, WINDOWPLACEMENT& wp);
    static CString MakeSplitterPosEntry(LPCTSTR name);
    static CString MakeColumnOrderEntry(LPCTSTR name);
    static CString MakeColumnWidthsEntry(LPCTSTR name);
    //static CString MakeSortingColumnEntry(LPCTSTR name, int n);
    //static CString MakeSortingAscendingEntry(LPCTSTR name, int n);
    static CString MakeDialogRectangleEntry(LPCTSTR name);


};

//
// CLanguageOptions. Is separated from COptions because it
// must be loaded earlier.
//

class CLanguageOptions: private CRegistryUser
{
public:
    static LANGID GetLanguage();
    static void SetLanguage(LANGID langid);
};

// m_pszProfileName|m_pszRegistryKey
// CWinApp::SetRegistryKey
// CWinApp::DelRegTree
// CWinApp::WriteProfileBinary


//
// COptions. Represents all the data which can be viewed
// and modified in the "Configure WinDirStat" dialog.
//

// COptions is a singleton.
COptions *GetOptions();

class COptions: private CRegistryUser
{
public:
    COptions();

    void LoadFromRegistry();
    void SaveToRegistry();

    bool IsListGrid();
    void SetListGrid(bool show);

    bool IsListStripes();
    void SetListStripes(bool show);

    bool IsListFullRowSelection();
    void SetListFullRowSelection(bool show);

    void GetTreelistColors(COLORREF color[TREELISTCOLORCOUNT]);
    void SetTreelistColors(const COLORREF color[TREELISTCOLORCOUNT]);
    COLORREF GetTreelistColor(int i);

    int GetTreelistColorCount();
    void SetTreelistColorCount(int count);

    bool IsHumanFormat();
    void SetHumanFormat(bool human);

    bool IsPacmanAnimation();
    void SetPacmanAnimation(bool animate);

    bool IsShowTimeSpent();
    void SetShowTimeSpent(bool show);

    COLORREF GetTreemapHighlightColor();
    void SetTreemapHighlightColor(COLORREF color);

    const CTreemap::Options *GetTreemapOptions();
    void SetTreemapOptions(const CTreemap::Options& options);

    bool IsFollowMountPoints();
    void SetFollowMountPoints(bool follow);

    // Option to ignore junction points which are not volume mount points
    bool IsFollowJunctionPoints();
    void SetFollowJunctionPoints(bool ignore);

    // Option to use CDirStatApp::m_langid for date/time and number formatting
    bool IsUseWdsLocale();
    void SetUseWdsLocale(bool use);

    // Option to ignore hidden files and folders
    bool IsSkipHidden();
    void SetSkipHidden(bool skip);

    void GetUserDefinedCleanups(USERDEFINEDCLEANUP udc[USERDEFINEDCLEANUPCOUNT]);
    void SetUserDefinedCleanups(const USERDEFINEDCLEANUP udc[USERDEFINEDCLEANUPCOUNT]);

    void GetEnabledUserDefinedCleanups(CArray<int, int>& indices);
    bool IsUserDefinedCleanupEnabled(int i);
    const USERDEFINEDCLEANUP *GetUserDefinedCleanup(int i);

    CString GetReportSubject();
    CString GetReportDefaultSubject();
    void SetReportSubject(LPCTSTR subject);

    CString GetReportPrefix();
    CString GetReportDefaultPrefix();
    void SetReportPrefix(LPCTSTR prefix);

    CString GetReportSuffix();
    CString GetReportDefaultSuffix();
    void SetReportSuffix(LPCTSTR suffix);

private:
    void ReadUserDefinedCleanup(int i);
    void SaveUserDefinedCleanup(int i);
    void ReadTreemapOptions();
    void SaveTreemapOptions();

    bool m_listGrid;
    bool m_listStripes;
    bool m_listFullRowSelection;
    COLORREF m_treelistColor[TREELISTCOLORCOUNT];
    int m_treelistColorCount;
    bool m_humanFormat;
    bool m_pacmanAnimation;
    bool m_showTimeSpent;
    COLORREF m_treemapHighlightColor;

    CTreemap::Options m_treemapOptions;

    bool m_followMountPoints;
    bool m_followJunctionPoints;
    bool m_useWdsLocale;
    bool m_skipHidden;

    USERDEFINEDCLEANUP m_userDefinedCleanup[USERDEFINEDCLEANUPCOUNT];

    CString m_reportSubject;
    CString m_reportPrefix;
    CString m_reportSuffix;
};
#endif // __NOT_WDS

#endif // __WDS_OPTIONS_H__