00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
#include <wx/wxprec.h>
00028
00029
#ifdef __BORLANDC__
00030
#pragma hdrstop
00031
#endif
00032
00033
#ifndef WX_PRECOMP
00034
00035
#include <wx/wx.h>
00036
#endif
00037
00038
#include <wx/file.h>
00039
#include <wx/filename.h>
00040
#include <wx/config.h>
00041
#include <wx/fileconf.h>
00042
#include <wx/tokenzr.h>
00043
#include <wx/txtstrm.h>
00044
00045
#ifdef __WINDOWS__
00046
#include <windows.h>
00047
#include <shlobj.h>
00048
00049
#if defined(__CYGWIN__) || defined(__MINGW32__)
00050
00051
00052
#define SHGFP_TYPE_CURRENT 0
00053
#define SHGFP_TYPE_DEFAULT 1
00054
#endif // __CYGWIN__
00055
#endif // __WINDOWS__
00056
00057
#include "appprefs.hpp"
00058
#include "comdefs.hpp"
00059
#include "cmdlnopt.hpp"
00060
#include "osdep.hpp"
00061
00062
#include "compat.hpp"
00063
00064
00065
00066
using namespace std;
00067
00068
00069
00070
00071
00072
00073
static wxString
addPathSeparatorAtEnd(wxString dirName);
00074
static bool dirExists(
const wxString& dirName,
bool create);
00075
#if defined(__WINDOWS__)
00076
static wxString getFolderPath(
int folder);
00077
#endif // defined(__WINDOWS__)
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 PreferenceValue::PreferenceValue()
00090 {
00091
_valueType = ptNotDefined;
00092
_value.
valLong = NULL;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102 void PreferenceValue::clone(
const PreferenceValue& source)
00103 {
00104
if (
this != &source)
00105 {
00106
00107
cleanup();
00108
00109
00110 this->
_valueType = source.
_valueType;
00111
switch (
_valueType)
00112 {
00113
case ptLong :
00114
_value.
valLong =
new long(*(source.
_value.
valLong));
00115
break;
00116
case ptString :
00117
_value.
valString =
new wxString(*(source.
_value.
valString));
00118
break;
00119
case ptDouble :
00120
_value.
valDouble =
new double(*(source.
_value.
valDouble));
00121
break;
00122
case ptBoolean :
00123
_value.
valBool =
new bool(*(source.
_value.
valBool));
00124
break;
00125
case ptRect :
00126
_value.
valRect =
new wxRect(*(source.
_value.
valRect));
00127
break;
00128
case ptPoint :
00129
_value.
valPoint =
new wxPoint(*(source.
_value.
valPoint));
00130
break;
00131
case ptSize :
00132
_value.
valSize =
new wxSize(*(source.
_value.
valSize));
00133
break;
00134
default :
00135
_value.
valLong = NULL;
00136 }
00137 this->
_cfgKey = source.
_cfgKey;
00138 }
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148 PreferenceValue::PreferenceValue(
const PreferenceValue& source)
00149 {
00150
_valueType = ptNotDefined;
00151
_value.
valLong = NULL;
00152
clone(source);
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 PreferenceValue&
PreferenceValue::operator=(
const PreferenceValue& source)
00164 {
00165
clone(source);
00166
return *
this;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 PreferenceValue::PreferenceValue(
const long value,
const wxString& cfgKey,
const bool initFromCfgFile)
00182 {
00183
_valueType = ptLong;
00184
_value.
valLong =
new long(value);
00185
_cfgKey = cfgKey;
00186
00187
if (!cfgKey.empty() && initFromCfgFile)
00188 wxConfig::Get()->Read(cfgKey,
_value.
valLong);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 PreferenceValue::PreferenceValue(
const wxString& value,
const wxString& cfgKey,
const bool initFromCfgFile)
00203 {
00204
_valueType = ptString;
00205
_value.
valString =
new wxString(value);
00206
_cfgKey = cfgKey;
00207
00208
if (!cfgKey.empty() && initFromCfgFile)
00209 wxConfig::Get()->Read(cfgKey,
_value.
valString);
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 PreferenceValue::PreferenceValue(
const double value,
const wxString& cfgKey,
const bool initFromCfgFile)
00224 {
00225
_valueType = ptDouble;
00226
_value.
valDouble =
new double(value);
00227
_cfgKey = cfgKey;
00228
00229
if (!cfgKey.empty() && initFromCfgFile)
00230 wxConfig::Get()->Read(cfgKey,
_value.
valDouble);
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 PreferenceValue::PreferenceValue(
const bool value,
const wxString& cfgKey,
const bool initFromCfgFile)
00245 {
00246
_valueType = ptBoolean;
00247
_value.
valBool =
new bool(value);
00248
_cfgKey = cfgKey;
00249
00250
if (!cfgKey.empty() && initFromCfgFile)
00251 wxConfig::Get()->Read(cfgKey,
_value.
valBool);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 PreferenceValue::PreferenceValue(
const wxRect& value,
const wxString& cfgKey,
const bool initFromCfgFile)
00266 {
00267
_valueType = ptRect;
00268
_value.
valRect =
new wxRect(value);
00269
_cfgKey = cfgKey;
00270
00271
if (!cfgKey.empty() && initFromCfgFile)
00272
read(cfgKey,
_value.
valRect);
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 PreferenceValue::PreferenceValue(
const wxPoint& value,
const wxString& cfgKey,
const bool initFromCfgFile)
00287 {
00288
_valueType = ptPoint;
00289
_value.
valPoint =
new wxPoint(value);
00290
_cfgKey = cfgKey;
00291
00292
if (!cfgKey.empty() && initFromCfgFile)
00293
read(cfgKey,
_value.
valPoint);
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 PreferenceValue::PreferenceValue(
const wxSize& value,
const wxString& cfgKey,
const bool initFromCfgFile)
00308 {
00309
_valueType = ptSize;
00310
_value.
valSize =
new wxSize(value);
00311
_cfgKey = cfgKey;
00312
00313
if (!cfgKey.empty() && initFromCfgFile)
00314
read(cfgKey,
_value.
valSize);
00315 }
00316
00317
00318
00319
00320
00321
00322 PreferenceValue::~PreferenceValue()
00323 {
00324
cleanup();
00325 }
00326
00327
00328
00329
00330
00331
00332 void PreferenceValue::cleanup()
00333 {
00334
switch (
_valueType)
00335 {
00336
case ptLong :
00337
delete _value.
valLong;
00338
break;
00339
case ptString :
00340
delete _value.
valString;
00341
break;
00342
case ptDouble :
00343
delete _value.
valDouble;
00344
break;
00345
case ptBoolean :
00346
delete _value.
valBool;
00347
break;
00348
case ptRect :
00349
delete _value.
valRect;
00350
break;
00351
case ptPoint :
00352
delete _value.
valPoint;
00353
break;
00354
case ptSize :
00355
delete _value.
valSize;
00356
break;
00357 }
00358
_valueType = ptNotDefined;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 wxString
PreferenceValue::getConfigKey()
const
00370
{
00371
return _cfgKey;
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 bool PreferenceValue::get(
long& value)
const
00384
{
00385
if (
_valueType == ptLong)
00386 {
00387 value = *(
_value.
valLong);
00388
return true;
00389 }
00390
else
00391
return false;
00392 }
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 bool PreferenceValue::set(
const long newValue)
00409 {
00410
if (
_valueType == ptLong)
00411 {
00412 *(
_value.
valLong) = newValue;
00413
if (
_cfgKey.empty())
00414
return true;
00415
else
00416
return wxConfig::Get()->Write(
_cfgKey, newValue);
00417 }
00418
else
00419
return false;
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 bool PreferenceValue::get(wxString& value)
const
00432
{
00433
if (
_valueType == ptString)
00434 {
00435 value = *(
_value.
valString);
00436
return true;
00437 }
00438
else
00439
return false;
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 bool PreferenceValue::set(
const wxString& newValue)
00457 {
00458
if (
_valueType == ptString)
00459 {
00460 *(
_value.
valString) = newValue;
00461
if (
_cfgKey.empty())
00462
return true;
00463
else
00464
return wxConfig::Get()->Write(
_cfgKey, newValue);
00465 }
00466
else
00467
return false;
00468 }
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 bool PreferenceValue::get(
double& value)
const
00480
{
00481
if (
_valueType == ptDouble)
00482 {
00483 value = *(
_value.
valDouble);
00484
return true;
00485 }
00486
else
00487
return false;
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 bool PreferenceValue::set(
const double newValue)
00505 {
00506
if (
_valueType == ptDouble)
00507 {
00508 *(
_value.
valDouble) = newValue;
00509
if (
_cfgKey.empty())
00510
return true;
00511
else
00512
return wxConfig::Get()->Write(
_cfgKey, newValue);
00513 }
00514
else
00515
return false;
00516 }
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 bool PreferenceValue::get(
bool& value)
const
00528
{
00529
if (
_valueType == ptBoolean)
00530 {
00531 value = *(
_value.
valBool);
00532
return true;
00533 }
00534
else
00535
return false;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 bool PreferenceValue::set(
const bool newValue)
00553 {
00554
if (
_valueType == ptBoolean)
00555 {
00556 *(
_value.
valBool) = newValue;
00557
if (
_cfgKey.empty())
00558
return true;
00559
else
00560
return wxConfig::Get()->Write(
_cfgKey, newValue);
00561 }
00562
else
00563
return false;
00564 }
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575 bool PreferenceValue::get(wxRect& value)
const
00576
{
00577
if (
_valueType == ptRect)
00578 {
00579 value = *(
_value.
valRect);
00580
return true;
00581 }
00582
else
00583
return false;
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600 bool PreferenceValue::set(
const wxRect& newValue)
00601 {
00602
if (
_valueType == ptRect)
00603 {
00604 *(
_value.
valRect) = newValue;
00605
if (
_cfgKey.empty())
00606
return true;
00607
else
00608 {
00609 wxString r;
00610 r.Printf(wxT(
"%d,%d,%d,%d"), newValue.GetX(), newValue.GetY(),
00611 newValue.GetWidth(), newValue.GetHeight());
00612
return wxConfig::Get()->Write(
_cfgKey, r);
00613 }
00614 }
00615
else
00616
return false;
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 bool PreferenceValue::get(wxPoint& value)
const
00629
{
00630
if (
_valueType == ptPoint)
00631 {
00632 value = *(
_value.
valPoint);
00633
return true;
00634 }
00635
else
00636
return false;
00637 }
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 bool PreferenceValue::set(
const wxPoint& newValue)
00654 {
00655
if (
_valueType == ptPoint)
00656 {
00657 *(
_value.
valPoint) = newValue;
00658
if (
_cfgKey.empty())
00659
return true;
00660
else
00661 {
00662 wxString r;
00663 r.Printf(wxT(
"%d,%d"), newValue.x, newValue.y);
00664
return wxConfig::Get()->Write(
_cfgKey, r);
00665 }
00666 }
00667
else
00668
return false;
00669 }
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680 bool PreferenceValue::get(wxSize& value)
const
00681
{
00682
if (
_valueType == ptSize)
00683 {
00684 value = *(
_value.
valSize);
00685
return true;
00686 }
00687
else
00688
return false;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705 bool PreferenceValue::set(
const wxSize& newValue)
00706 {
00707
if (
_valueType == ptSize)
00708 {
00709 *(
_value.
valSize) = newValue;
00710
if (
_cfgKey.empty())
00711
return true;
00712
else
00713 {
00714 wxString r;
00715 r.Printf(wxT(
"%d,%d"), newValue.GetWidth(), newValue.GetHeight());
00716
return wxConfig::Get()->Write(
_cfgKey, r);
00717 }
00718 }
00719
else
00720
return false;
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 bool PreferenceValue::read(
const wxString& key, wxRect* r, wxConfigBase* cfg)
00737 {
00738
00739 wxConfigBase* c = (cfg != NULL) ? cfg : wxConfig::Get();
00740
00741
00742 wxString res = c->Read(key, wxEmptyString);
00743
if (res.empty())
00744
return false;
00745
else
00746 {
00747
00748 wxStringTokenizer st(res, wxT(
","));
00749
if (st.CountTokens() != 4)
00750
return false;
00751
else
00752 {
00753
bool ok =
true;
00754
int res[4];
00755
int i = 0;
00756
long l;
00757
while (ok && st.HasMoreTokens())
00758 {
00759 wxString s = st.GetNextToken();
00760
if (s.ToLong(&l))
00761 res[i++] = static_cast<int>(l);
00762
else
00763 ok =
false;
00764 }
00765
if (ok)
00766 {
00767 r->SetX(res[0]);
00768 r->SetY(res[1]);
00769 r->SetWidth(res[2]);
00770 r->SetHeight(res[3]);
00771 }
00772
return ok;
00773 }
00774 }
00775 }
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790 wxRect
PreferenceValue::read(
const wxString& key,
const wxRect& def, wxConfigBase* cfg)
00791 {
00792 wxRect r;
00793
00794
if (
read(key, &r, cfg))
00795
return r;
00796
else
00797
return def;
00798 }
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 bool PreferenceValue::read(
const wxString& key, wxPoint* r, wxConfigBase* cfg)
00814 {
00815
00816 wxConfigBase* c = (cfg != NULL) ? cfg : wxConfig::Get();
00817
00818
00819 wxString res = c->Read(key, wxEmptyString);
00820
if (res.empty())
00821
return false;
00822
else
00823 {
00824
00825 wxStringTokenizer st(res, wxT(
","));
00826
if (st.CountTokens() != 2)
00827
return false;
00828
else
00829 {
00830
bool ok =
true;
00831
int res[2];
00832
int i = 0;
00833
long l;
00834
while (ok && st.HasMoreTokens())
00835 {
00836 wxString s = st.GetNextToken();
00837
if (s.ToLong(&l))
00838 res[i++] = static_cast<int>(l);
00839
else
00840 ok =
false;
00841 }
00842
if (ok)
00843 {
00844 r->x = res[0];
00845 r->y = res[1];
00846 }
00847
return ok;
00848 }
00849 }
00850 }
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865 wxPoint
PreferenceValue::read(
const wxString& key,
const wxPoint& def, wxConfigBase* cfg)
00866 {
00867 wxPoint r;
00868
00869
if (
read(key, &r, cfg))
00870
return r;
00871
else
00872
return def;
00873 }
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888 bool PreferenceValue::read(
const wxString& key, wxSize* r, wxConfigBase* cfg)
00889 {
00890
00891 wxConfigBase* c = (cfg != NULL) ? cfg : wxConfig::Get();
00892
00893
00894 wxString res = c->Read(key, wxEmptyString);
00895
if (res.empty())
00896
return false;
00897
else
00898 {
00899
00900 wxStringTokenizer st(res, wxT(
","));
00901
if (st.CountTokens() != 2)
00902
return false;
00903
else
00904 {
00905
bool ok =
true;
00906
int res[2];
00907
int i = 0;
00908
long l;
00909
while (ok && st.HasMoreTokens())
00910 {
00911 wxString s = st.GetNextToken();
00912
if (s.ToLong(&l))
00913 res[i++] = static_cast<int>(l);
00914
else
00915 ok =
false;
00916 }
00917
if (ok)
00918 {
00919 r->SetWidth(res[0]);
00920 r->SetHeight(res[1]);
00921 }
00922
return ok;
00923 }
00924 }
00925 }
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 wxSize
PreferenceValue::read(
const wxString& key,
const wxSize& def, wxConfigBase* cfg)
00941 {
00942 wxSize r;
00943
00944
if (
read(key, &r, cfg))
00945
return r;
00946
else
00947
return def;
00948 }
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958 AppPrefs*
AppPrefs::global = NULL;
00959 wxString
AppPrefs::configDir;
00960 wxString
AppPrefs::configFileName;
00961
00962
00963
00964
00965
00966
00967 AppPrefs::AppPrefs()
00968 {
00969
init();
00970 }
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983 void AppPrefs::init()
00984 {
00985 wxString path;
00986
00987
00988
00989
prefs.insert(HashPrefs::value_type(prGUI_CONF_WINDOW_SIZE,
PreferenceValue(wxSize(-1, -1), wxT(
"GUI/ConfigDlg/WindowSize"))));
00990
prefs.insert(HashPrefs::value_type(prGUI_CONF_SASH_POSITION,
PreferenceValue(100L, wxT(
"GUI/ConfigDlg/SashPosition"))));
00991
00992
00993 path = wxT(
"GUI/Main/");
00994 wxRect r =
getDefaultMainWindowRect();
00995
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SAVE_WINDOW_POSITION,
PreferenceValue(
true, path + wxT(
"SaveWindowPosition"))));
00996
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SAVE_WINDOW_SIZE,
PreferenceValue(
true, path + wxT(
"SaveWindowSize"))));
00997
prefs.insert(HashPrefs::value_type(prGUI_MAIN_WINDOW_POSITION,
PreferenceValue(wxPoint(r.GetX(), r.GetY()), path + wxT(
"WindowPosition"))));
00998
prefs.insert(HashPrefs::value_type(prGUI_MAIN_WINDOW_SIZE,
PreferenceValue(wxSize(r.GetWidth(), r.GetHeight()), path + wxT(
"WindowSize"))));
00999
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SHOW_TOOLBAR,
PreferenceValue(
true, path + wxT(
"ShowToolbar"))));
01000
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SHOW_STATUSBAR,
PreferenceValue(
true, path + wxT(
"ShowStatusbar"))));
01001
prefs.insert(HashPrefs::value_type(prGUI_MAIN_LAST_DIRECTORY,
PreferenceValue(wxString(), path + wxT(
"LastDirectory"))));
01002
01003
01004 path = wxT(
"GUI/Main/ChecksumsList/");
01005
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_SAVECOLUMNTOSORT,
PreferenceValue(
false, path + wxT(
"SaveColumnToSort"))));
01006
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COLUMNTOSORT,
PreferenceValue(0L, path + wxT(
"ColumnToSort"))));
01007
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COLUMNSORTORDER,
PreferenceValue(0L, path + wxT(
"SaveColumnSortOrder"))));
01008
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_SAVECOLUMNSWIDTHS,
PreferenceValue(
true, path + wxT(
"SaveColumnsWidths"))));
01009
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_DIRSINABSOLUTEPATH,
PreferenceValue(
false, path + wxT(
"DirsInAbsolutePath"))));
01010
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_UPPERCASE,
PreferenceValue(
true, path + wxT(
"Uppercase"))));
01011
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_HRULES,
PreferenceValue(
false, path + wxT(
"HRules"))));
01012
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_VRULES,
PreferenceValue(
false, path + wxT(
"VRules"))));
01013
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_FILENAME_WIDTH,
PreferenceValue(150L, path + wxT(
"ColumnWidthFileName"))));
01014
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_DIRECTORY_WIDTH,
PreferenceValue(150L, path + wxT(
"ColumnWidthDirectory"))));
01015
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_CHECKSUM_WIDTH,
PreferenceValue(150L, path + wxT(
"ColumnWidthChecksumValue"))));
01016
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_STATE_WIDTH,
PreferenceValue(150L, path + wxT(
"ColumnWidthState"))));
01017
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_FIRST,
PreferenceValue(0L, path + wxT(
"ColumnFirst"))));
01018
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_SECOND,
PreferenceValue(1L, path + wxT(
"ColumnSecond"))));
01019
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_THIRD,
PreferenceValue(2L, path + wxT(
"ColumnThird"))));
01020
prefs.insert(HashPrefs::value_type(prGUI_MAIN_SUMS_COL_FOURTH,
PreferenceValue(3L, path + wxT(
"ColumnFourth"))));
01021
01022
01023
prefs.insert(HashPrefs::value_type(prGUI_NEWFILE_LAST_DIRECTORY,
PreferenceValue(wxString(), wxT(
"GUI/NewFile/LastDirectory"))));
01024
prefs.insert(HashPrefs::value_type(prGUI_NEWFILE_LAST_FILETYPE,
PreferenceValue(0L, wxT(
"GUI/NewFile/LastFileType"))));
01025
01026
01027 path = wxT(
"GUI/Behavior/");
01028
prefs.insert(HashPrefs::value_type(prGUI_AUTO_CHECK_ON_OPEN,
PreferenceValue(
true, path + wxT(
"AutoCheckOnOpen"))));
01029
prefs.insert(HashPrefs::value_type(prGUI_DLG_SUMUP_CHECK,
PreferenceValue(
false, path + wxT(
"DlgSumUpCheck"))));
01030
prefs.insert(HashPrefs::value_type(prGUI_WARN_ON_INVALID_WHEN_SAVING,
PreferenceValue(
true, path + wxT(
"WarnOnInvalidWhenSaving"))));
01031
01032
01033 path = wxT(
"GUI/CommandLine/");
01034
prefs.insert(HashPrefs::value_type(prGUI_CLN_VERIFY_DONT_SHOW_GUI,
PreferenceValue(
false, path + wxT(
"DontShowWhenAllCorrect"))));
01035
prefs.insert(HashPrefs::value_type(prGUI_CLN_APPEND_SHOW_GUI,
PreferenceValue(static_cast<long>(clgOnWarning), path + wxT(
"AppendShowGUI"))));
01036
prefs.insert(HashPrefs::value_type(prGUI_CLN_CREATE_SHOW_GUI,
PreferenceValue(static_cast<long>(clgOnWarning), path + wxT(
"CreateShowGUI"))));
01037
01038
01039 path = wxT(
"ChecksumsFiles/SFV/");
01040
prefs.insert(HashPrefs::value_type(prSFV_READ_PATH_SEPARATOR,
PreferenceValue(static_cast<long>(wxPATH_NATIVE), path + wxT(
"ReadPathSeparator"))));
01041
prefs.insert(HashPrefs::value_type(prSFV_WRITE_GEN_AND_DATE,
PreferenceValue(
true, path + wxT(
"WriteGeneratorAndDate"))));
01042
prefs.insert(HashPrefs::value_type(prSFV_IDENTIFY_AS,
PreferenceValue(wxString(), path + wxT(
"IdentifyAs/Generator"))));
01043
prefs.insert(HashPrefs::value_type(prSFV_WRITE_FILE_SIZE_AND_DATE,
PreferenceValue(
true, path + wxT(
"WriteFileSizeAndDate"))));
01044
prefs.insert(HashPrefs::value_type(prSFV_WRITE_PATH_SEPARATOR,
PreferenceValue(static_cast<long>(wxPATH_WIN), path + wxT(
"WritePathSeparator"))));
01045
prefs.insert(HashPrefs::value_type(prSFV_WRITE_EOL,
PreferenceValue(static_cast<long>(wxEOL_DOS), path + wxT(
"WriteEndOfLine"))));
01046
01047
01048 path = wxT(
"ChecksumsFiles/MD5/");
01049
prefs.insert(HashPrefs::value_type(prMD5_READ_PATH_SEPARATOR,
PreferenceValue(static_cast<long>(wxPATH_NATIVE), path + wxT(
"ReadPathSeparator"))));
01050
prefs.insert(HashPrefs::value_type(prMD5_WRITE_GEN_AND_DATE,
PreferenceValue(
false, path + wxT(
"WriteGeneratorAndDate"))));
01051
prefs.insert(HashPrefs::value_type(prMD5_WRITE_FILE_SIZE_AND_DATE,
PreferenceValue(
false, path + wxT(
"WriteFileSizeAndDate"))));
01052
prefs.insert(HashPrefs::value_type(prMD5_WRITE_PATH_SEPARATOR,
PreferenceValue(static_cast<long>(wxPATH_UNIX), path + wxT(
"WritePathSeparator"))));
01053
prefs.insert(HashPrefs::value_type(prMD5_WRITE_EOL,
PreferenceValue(static_cast<long>(wxEOL_UNIX), path + wxT(
"WriteEndOfLine"))));
01054
01055
01056
prefs.insert(HashPrefs::value_type(prENGINE_READ_BUFFER,
PreferenceValue(0xFFFFL, wxT(
"Engine/ReadBuffer"))));
01057
01058
01059
prefs.insert(HashPrefs::value_type(prLANGUAGE_NAME,
PreferenceValue(wxString(), wxT(
"Language/Name"))));
01060
01061
01062 path = wxT(
"GUI/MultiCheck/");
01063
prefs.insert(HashPrefs::value_type(prMC_WINDOW_SIZE,
PreferenceValue(wxSize(-1, -1), path + wxT(
"WindowSize"))));
01064
prefs.insert(HashPrefs::value_type(prMC_GLOBAL_SUMMARY,
PreferenceValue(
true, path + wxT(
"GlobalSummary"))));
01065
prefs.insert(HashPrefs::value_type(prMC_CHECKSUMS_FILE_SUMMARY,
PreferenceValue(
true, path + wxT(
"ChecksumsFileSummary"))));
01066
prefs.insert(HashPrefs::value_type(prMC_FILE_STATE,
PreferenceValue(
false, path + wxT(
"FileState"))));
01067
prefs.insert(HashPrefs::value_type(prMC_NO_CORRECT_FILE_STATE,
PreferenceValue(
true, path + wxT(
"NoCorrectFileState"))));
01068
prefs.insert(HashPrefs::value_type(prMC_NORMAL_COLOUR,
PreferenceValue(0x000000L, path + wxT(
"NormalColour"))));
01069
prefs.insert(HashPrefs::value_type(prMC_SUCCESS_COLOUR,
PreferenceValue(0x008000L, path + wxT(
"SuccessColour"))));
01070
prefs.insert(HashPrefs::value_type(prMC_WARNING_COLOUR,
PreferenceValue(0xFF8000L, path + wxT(
"WarningColour"))));
01071
prefs.insert(HashPrefs::value_type(prMC_ERROR_COLOUR,
PreferenceValue(0x800000L, path + wxT(
"ErrorColour"))));
01072
01073
01074
01075 path = wxT(
"GUI/BatchCreation/");
01076
prefs.insert(HashPrefs::value_type(prBC_WINDOW_SIZE,
PreferenceValue(wxSize(-1, -1), path + wxT(
"WindowSize"))));
01077
prefs.insert(HashPrefs::value_type(prBC_OVERWRITE_WHEN_CKFILE_EXISTS,
PreferenceValue(
false, path + wxT(
"OvrCkFileWhenItExists"))));
01078
prefs.insert(HashPrefs::value_type(prBC_REPLACE_FILE_EXTENSION,
PreferenceValue(
true, path + wxT(
"ReplaceExtension"))));
01079
prefs.insert(HashPrefs::value_type(prBC_VERBOSITY_LEVEL,
PreferenceValue(2L, path + wxT(
"VerbosityLevel"))));
01080
prefs.insert(HashPrefs::value_type(prBC_NORMAL_COLOUR,
PreferenceValue(0x000000L, path + wxT(
"NormalColour"))));
01081
prefs.insert(HashPrefs::value_type(prBC_SUCCESS_COLOUR,
PreferenceValue(0x008000L, path + wxT(
"SuccessColour"))));
01082
prefs.insert(HashPrefs::value_type(prBC_WARNING_COLOUR,
PreferenceValue(0xFF8000L, path + wxT(
"WarningColour"))));
01083
prefs.insert(HashPrefs::value_type(prBC_ERROR_COLOUR,
PreferenceValue(0x800000L, path + wxT(
"ErrorColour"))));
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093 void AppPrefs::clone(
const AppPrefs& source)
01094 {
01095
if (
this != &source)
01096 this->
prefs = source.
prefs;
01097 }
01098
01099
01100
01101
01102
01103
01104
01105
01106 AppPrefs::AppPrefs(
const AppPrefs& source)
01107 {
01108
clone(source);
01109 }
01110
01111
01112
01113
01114
01115
01116
01117
01118 AppPrefs&
AppPrefs::operator=(
const AppPrefs& source)
01119 {
01120
clone(source);
01121
return *
this;
01122 }
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134 wxString
AppPrefs::getConfigKey(
const int key)
const
01135
{
01136 wxString res;
01137
01138 HashPrefs::const_iterator it =
prefs.find(key);
01139
if (it !=
prefs.end())
01140 res = it->second.getConfigKey();
01141
01142
return res;
01143 }
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155 bool AppPrefs::read(
const int key, wxString& str)
const
01156
{
01157 HashPrefs::const_iterator it =
prefs.find(key);
01158
if (it ==
prefs.end())
01159
return false;
01160
else
01161
return it->second.get(str);
01162 }
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174 wxString
AppPrefs::readString(
const int key,
const wxString& def)
const
01175
{
01176 wxString res;
01177
01178
if (
read(key, res))
01179
return res;
01180
else
01181
return def;
01182 }
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194 bool AppPrefs::read(
const int key,
long& l)
const
01195
{
01196 HashPrefs::const_iterator it =
prefs.find(key);
01197
if (it ==
prefs.end())
01198
return false;
01199
else
01200
return it->second.get(l);
01201 }
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213 long AppPrefs::readLong(
const int key,
const long def)
const
01214
{
01215
long res;
01216
01217
if (
read(key, res))
01218
return res;
01219
else
01220
return def;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233 bool AppPrefs::read(
const int key,
double& d)
const
01234
{
01235 HashPrefs::const_iterator it =
prefs.find(key);
01236
if (it ==
prefs.end())
01237
return false;
01238
else
01239
return it->second.get(d);
01240 }
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252 double AppPrefs::readDouble(
const int key,
const double def)
const
01253
{
01254
double res;
01255
01256
if (
read(key, res))
01257
return res;
01258
else
01259
return def;
01260 }
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 bool AppPrefs::read(
const int key,
bool& b)
const
01273
{
01274 HashPrefs::const_iterator it =
prefs.find(key);
01275
if (it ==
prefs.end())
01276
return false;
01277
else
01278
return it->second.get(b);
01279 }
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291 bool AppPrefs::readBool(
const int key,
const bool def)
const
01292
{
01293
bool res;
01294
01295
if (
read(key, res))
01296
return res;
01297
else
01298
return def;
01299 }
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 bool AppPrefs::read(
const int key, wxRect& r)
const
01312
{
01313 HashPrefs::const_iterator it =
prefs.find(key);
01314
if (it ==
prefs.end())
01315
return false;
01316
else
01317
return it->second.get(r);
01318 }
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330 wxRect
AppPrefs::readRect(
const int key,
const wxRect& def)
const
01331
{
01332 wxRect res;
01333
01334
if (
read(key, res))
01335
return res;
01336
else
01337
return def;
01338 }
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350 bool AppPrefs::read(
const int key, wxPoint& p)
const
01351
{
01352 HashPrefs::const_iterator it =
prefs.find(key);
01353
if (it ==
prefs.end())
01354
return false;
01355
else
01356
return it->second.get(p);
01357 }
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369 wxPoint
AppPrefs::readPoint(
const int key,
const wxPoint& def)
const
01370
{
01371 wxPoint res;
01372
01373
if (
read(key, res))
01374
return res;
01375
else
01376
return def;
01377 }
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389 bool AppPrefs::read(
const int key, wxSize& s)
const
01390
{
01391 HashPrefs::const_iterator it =
prefs.find(key);
01392
if (it ==
prefs.end())
01393
return false;
01394
else
01395
return it->second.get(s);
01396 }
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408 wxSize
AppPrefs::readSize(
const int key,
const wxSize& def)
const
01409
{
01410 wxSize res;
01411
01412
if (
read(key, res))
01413
return res;
01414
else
01415
return def;
01416 }
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428 bool AppPrefs::write(
const int key,
const wxString& str)
01429 {
01430 HashPrefs::iterator it =
prefs.find(key);
01431
if (it ==
prefs.end())
01432
return false;
01433
else
01434
return it->second.set(str);
01435 }
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447 bool AppPrefs::write(
const int key,
const long l)
01448 {
01449 HashPrefs::iterator it =
prefs.find(key);
01450
if (it ==
prefs.end())
01451
return false;
01452
else
01453
return it->second.set(l);
01454 }
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 bool AppPrefs::write(
const int key,
const double d)
01467 {
01468 HashPrefs::iterator it =
prefs.find(key);
01469
if (it ==
prefs.end())
01470
return false;
01471
else
01472
return it->second.set(d);
01473 }
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485 bool AppPrefs::write(
const int key,
const bool b)
01486 {
01487 HashPrefs::iterator it =
prefs.find(key);
01488
if (it ==
prefs.end())
01489
return false;
01490
else
01491
return it->second.set(b);
01492 }
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504 bool AppPrefs::write(
const int key,
const wxRect& r)
01505 {
01506 HashPrefs::iterator it =
prefs.find(key);
01507
if (it ==
prefs.end())
01508
return false;
01509
else
01510
return it->second.set(r);
01511 }
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523 bool AppPrefs::write(
const int key,
const wxPoint& p)
01524 {
01525 HashPrefs::iterator it =
prefs.find(key);
01526
if (it ==
prefs.end())
01527
return false;
01528
else
01529
return it->second.set(p);
01530 }
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542 bool AppPrefs::write(
const int key,
const wxSize& s)
01543 {
01544 HashPrefs::iterator it =
prefs.find(key);
01545
if (it ==
prefs.end())
01546
return false;
01547
else
01548
return it->second.set(s);
01549 }
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561 AppPrefs*
AppPrefs::get()
01562 {
01563
if (
global == NULL)
01564
global =
new AppPrefs();
01565
01566
return global;
01567 }
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578 AppPrefs*
AppPrefs::set(
AppPrefs* pAppPrefs)
01579 {
01580
AppPrefs* old =
global;
01581 global = pAppPrefs;
01582
return old;
01583 }
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596 void AppPrefs::cleanupGlobal()
01597 {
01598
AppPrefs* old =
set(NULL);
01599
if (old != NULL)
01600
delete old;
01601 }
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611 wxString
AppPrefs::getConfigDir()
01612 {
01613
if (!
configDir.empty())
01614
return configDir;
01615
01616 wxString path;
01617 wxString configDirName;
01618
#if defined(__UNIX__) && !defined(__WINDOWS__)
01619
configDirName = wxT(
'.') +
getConfigDirName();
01620
#else
01621
configDirName =
getConfigDirName();
01622
#endif // __UNIX__
01623
01624
#ifdef __WINDOWS__
01625
01626
if (!(path = getFolderPath(CSIDL_COMMON_APPDATA)).empty())
01627 {
01628 path =
addPathSeparatorAtEnd(path) + configDirName;
01629
01630
if (!(wxFile::Access(
addPathSeparatorAtEnd(path) +
getConfigFileName(), wxFile::read) &&
01631 wxFile::Access(
addPathSeparatorAtEnd(path) +
getConfigFileName(), wxFile::write)))
01632 path.clear();
01633 }
01634
01635
if (path.empty())
01636 {
01637 path = getFolderPath(CSIDL_APPDATA);
01638
if (!
dirExists(path,
false))
01639 path.clear();
01640
else
01641 {
01642 path =
addPathSeparatorAtEnd(path) + configDirName;
01643
if (!
dirExists(path,
true))
01644 path.clear();
01645 }
01646 }
01647
01648
if (path.empty())
01649 {
01650 path = getFolderPath(CSIDL_LOCAL_APPDATA);
01651
if (!
dirExists(path,
false))
01652 path.clear();
01653
else
01654 {
01655 path =
addPathSeparatorAtEnd(path) + configDirName;
01656
if (!
dirExists(path,
true))
01657 path.clear();
01658 }
01659 }
01660
#endif
01661
01662
01663
if (path.empty())
01664
if (::wxGetEnv(wxT(
"HOME"), &path))
01665 {
01666 path =
addPathSeparatorAtEnd(path) + configDirName;
01667
if (!
dirExists(path,
true))
01668 path.clear();
01669 }
01670
01671
if (!path.empty())
01672
configDir = path;
01673
01674
return configDir;
01675 }
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685 wxString
AppPrefs::getConfigFileName()
01686 {
01687
if (
configFileName.empty())
01688
configFileName = wxString(wxT(
APP_NAME)) + wxT(
".ini");
01689
01690
return configFileName;
01691 }
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702 wxString
AppPrefs::getLanguagesFileName()
01703 {
01704
return wxT(
"languages.ini");
01705 }
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715 wxString
AppPrefs::getConfigDirName()
01716 {
01717
return wxString(wxT(
APP_NAME));
01718 }
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728 wxString
AppPrefs::getConfigPathName()
01729 {
01730
return addPathSeparatorAtEnd(
getConfigDir()) +
getConfigFileName();
01731 }
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742 wxString
AppPrefs::getLanguagesPathName()
01743 {
01744 wxString res;
01745 size_t i;
01746
01747
01748
01749 wxString langIni =
getLanguagesFileName();
01750 wxArrayString paths = ::getResourcesPaths();
01751
01752
01753
01754
for (i = 0; i < paths.GetCount(); i++)
01755 {
01756 wxFileName fn(paths[i], langIni);
01757 paths[i] = fn.GetFullPath();
01758 }
01759
01760 wxString langsRC;
01761
if (::wxGetEnv(wxT(
"WXCKSUMS_LANGS_RC"), &langsRC))
01762
01763
01764 paths.Insert(langsRC, 0);
01765
01766 i = 0;
01767
while (res.IsEmpty() && i < paths.GetCount())
01768 {
01769
if (wxFile::Access(paths[i], wxFile::read))
01770 res = paths[i];
01771
else
01772 i++;
01773 }
01774
01775
return res;
01776 }
01777
01778
01779
01780
01781
01782
01783
01784
01785 wxRect
AppPrefs::getDefaultMainWindowRect()
01786 {
01787
int h, w;
01788 wxRect r;
01789
01790
01791 ::wxDisplaySize(&w, &h);
01792 r.SetWidth(static_cast<int>(w * 0.625));
01793 r.SetHeight(static_cast<int>(h * 0.625));
01794 r.SetX((w - r.GetWidth()) / 2);
01795 r.SetY((h - r.GetHeight()) / 2);
01796
01797
return r;
01798 }
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811 wxString
AppPrefs::getUserDocumentsDirName()
01812 {
01813 wxString path;
01814
01815
01816
if (::wxGetEnv(wxT(
"HOME"), &path))
01817
if (::wxDirExists(path))
01818
return path;
01819
01820
#ifdef __WINDOWS__
01821
path = getFolderPath(CSIDL_PERSONAL);
01822
if (::wxDirExists(path))
01823
return path;
01824
#endif // __WINDOWS__
01825
01826
return wxEmptyString;
01827 }
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844 static wxString
addPathSeparatorAtEnd(wxString dirName)
01845 {
01846
if (dirName.empty())
01847
return dirName;
01848
01849 wxChar pathSep = wxFileName::GetPathSeparator();
01850
if (dirName[dirName.size() - 1] != pathSep)
01851 dirName += pathSep;
01852
01853
return dirName;
01854 }
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874 static bool dirExists(
const wxString& dirName,
bool create)
01875 {
01876
if (wxDirExists(dirName))
01877
return true;
01878
else
01879
if (create)
01880
if (wxFileExists(dirName))
01881
return false;
01882
else
01883
return wxMkdir(dirName);
01884
else
01885
return false;
01886 }
01887
01888
01889
01890
#ifdef __WINDOWS__
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
static wxString getFolderPath(
int folder)
01901 {
01902 TCHAR szPath[MAX_PATH];
01903 wxString res;
01904
01905
if (SUCCEEDED(SHGetFolderPath(NULL, folder, NULL, SHGFP_TYPE_CURRENT, szPath)))
01906 res = szPath;
01907
01908
return res;
01909 }
01910
01911
#endif // __WINDOWS__