-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathConfig.cpp
1346 lines (1036 loc) · 42.7 KB
/
Config.cpp
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** CDex - Open Source Digital Audio CD Extractor
**
** Copyright (C) 2006 - 2007 Georgy Berdyshev
** Copyright (C) 1999 - 2007 Albert L. Faber
**
** http://cdexos.sourceforge.net/
** http://sourceforge.net/projects/cdexos
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "Config.h"
#include "Ini.h"
#include "FileVersion.h"
#include "EncoderObjectFactory.h"
#include <mmsystem.h>
#include <direct.h>
#include <math.h>
#include <limits.h>
#include "DriveOffset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define NUMDEFAULTSITES 4
// Define a global instance of CConfig
CConfig g_config;
CRemoteSites g_RemoteSites;
CGenreTable g_GenreTable;
INITTRACE( _T( "Config" ) );
struct PasswordStruct
{
int nUserName;
char lpszUserName[80];
int nPassword;
char lpszPassword[80];
int nUserKey;
int nPasswordKey;
};
// Good old Create dir with recursion
int MyCreateDir(CUString strDir)
{
CUString strDirToCreate;
if (strDir[strDir.GetLength()-1] == _T( '\\' ) )
strDir=strDir.Left(strDir.GetLength()-1);
if ( _wchdir( strDir )!=0)
{
int nPos=strDir.ReverseFind( _T( '\\' ) );
if (nPos>=0)
{
// Are we at the root level yet
if (strDir.ReverseFind( _W( ':' ) ) != nPos - 1 )
{
strDirToCreate = strDir.Mid( nPos + 1, strDir.GetLength() );
// Recursion
MyCreateDir( strDir.Left( nPos ) );
}
else
{
strDirToCreate=strDir;
}
}
}
strDirToCreate.TrimLeft();
strDirToCreate.TrimRight();
// Create recursivly the directories
CUStringConvert strCnv;
if ( 0 == _tmkdir( strCnv.ToT( strDirToCreate ) ) )
{
if ( 0 == _tchdir( strCnv.ToT( strDirToCreate ) ) )
{
return 0;
}
}
return -1;
}
CADebug::CADebug()
{
}
CADebug::CADebug(CUString& strFileName,BOOL bDelete)
{
Open( strFileName, bDelete );
}
CADebug::~CADebug()
{
Close();
}
void CADebug::Open( CUString& strFileName, BOOL bDelete )
{
// Open output file
m_strFileName = strFileName;
// Have to delete the OldFile first?
if ( bDelete )
{
CUStringConvert strCnv;
DeleteFile( strCnv.ToT( m_strFileName ) );
}
}
void CADebug::Close()
{
if ( m_pFile )
{
fclose( m_pFile );
}
m_pFile = NULL;
}
void CADebug::DumpBinaray(LPBYTE pbtBuffer,int nSize)
{
int nIdx=0;
int i;
m_pFile = CDexOpenFile( m_strFileName, _W( "a+" ) );
if (m_pFile==NULL)
{
CDexMessageBox( _W( "Can't open output file" ) );
return;
}
while (nIdx<nSize)
{
int nToDo=min(nSize-nIdx,16);
for (i=0;i<nToDo;i++,nIdx++)
{
fprintf(m_pFile,"%02x ",pbtBuffer[nIdx]);
}
fprintf(m_pFile,"\n");
}
if (m_pFile)
fclose(m_pFile);
}
void CADebug::printf(const char* pzFormat, ...)
{
CUStringConvert strCnv;
m_pFile = CDexOpenFile( m_strFileName, _W( "a+" ) );
if (m_pFile==NULL)
{
CDexMessageBox( _W( "Can't open output file" ) );
return;
}
BOOL bLogFile=TRUE;
char szBuffer[1024];
va_list ap;
va_start(ap, pzFormat);
_vsnprintf(szBuffer, 1000, pzFormat, ap);
// Dump it to the file
fprintf(m_pFile,"%s",szBuffer);
va_end(ap);
if (m_pFile)
fclose(m_pFile);
}
void FAR PASCAL EXPORT ErrorCallBackFunc(char* lpszFile,int nLine,char* lpszError)
{
CTime myTime=CTime::GetCurrentTime();
FILE* fpError=NULL;
// Open error log file
CUStringConvert strCnv;
fpError = CDexOpenFile( g_config.GetAppPath() + _W( "\\CDexErrorLog.txt" ), _W( "a" ) );
if (fpError==NULL)
{
CDexMessageBox( _W( "Can't open CDexErrorLog.txt file" ) );
return;
}
CUString strFileName( lpszFile, CP_UTF8 );
int nPos=strFileName.ReverseFind( _W( '\\' ) );
if (nPos)
strFileName=strFileName.Right(strFileName.GetLength()-nPos-1);
CUString strLog,strTmp;
strTmp.Format( _W( "Error occured in CDex version %s" ), (LPCWSTR)g_config.GetVersion());
strLog=strTmp;
strTmp.Format( _W( "date %04d:%02d:%02d " ),myTime.GetYear(),myTime.GetMonth(),myTime.GetDay());
strLog+=strTmp;
strTmp.Format( _W( "time %02d:%02d:%02d " ),myTime.GetHour(),myTime.GetMinute(),myTime.GetSecond());
strLog+=strTmp;
strTmp.Format( _W( "Error:%s (file:%s line %05d)" ),lpszError,strFileName,nLine);
strLog+=strTmp;
fprintf( fpError, "%s\n" , strCnv.ToUTF8( strLog ) );
fclose( fpError );
}
CConfig::CConfig()
{
ENTRY_TRACE( _T( "CConfig::CConfig()" ) );
// Get CDex version
CFileVersion myVersion;
TCHAR lpszModuleFileName[MAX_PATH];
GetModuleFileName( NULL,
lpszModuleFileName,
_countof( lpszModuleFileName ) );
myVersion.Open( lpszModuleFileName );
m_strVersion=myVersion.GetProductVersion();
m_strMP3OutputDir = _T( "" );
m_strCnvOutputDir = _T( "" );
m_strRecOutputDir = _T( "" );
m_strWAVInputDir = _T( "" );
m_strMP3InputDir = _T( "" );
m_strPlayDir = _T( "" );
m_bNormTrack = FALSE;
m_bRiffWav = FALSE;
m_bRetainWavFile = FALSE;
m_bWinEncoder = TRUE;
m_bCDDBLongDirNames = TRUE;
m_bPLSPlayList = FALSE;
m_bM3UPlayList = FALSE;
m_bSaveToLocCDDB = TRUE;
m_bSaveToCDPlayer = FALSE;
m_nThreadPriority = THREAD_PRIORITY_NORMAL;
m_strCDDBPath = _T( "" );
m_strWinampDBPath = _T( "" );
m_nCDDBProxyPort = 80;
m_nCDDBTimeOut = 20;
m_nCDDBUseProxy = FALSE;
m_nCDDBUseAuthentication= FALSE;
m_bCDDBAutoConnect = FALSE;
m_nFNBufferSize = 64000;
m_nPCopyEncType = 0;
m_bFileOpenRecursive= FALSE;
#ifdef _DEBUG
m_strEmailAddress = _T( "[email protected]" );
#else
m_strEmailAddress = _T( "" );
#endif
m_strProxyAddress = _T( "" );
m_strFileFormat=CUString( _T( "%1\\%2\\%7-%4" ) );
m_strPlsFileFormat=CUString( _T( "%1\\%2\\playlist" ) );
m_nLocalCDDBType = WINDOWSTYPECDDB;
m_strAppPath = GetCDexAppPath();
m_bDumpToc = FALSE;
m_bDelWavAfterConv = FALSE;
m_nLowNormLevel = 90;
m_nHighNormLevel = 98;
m_nLNormFactor = 90;
m_nHNormFactor = 98;
m_nEncoderType = 0;
m_strID3Comment = _W( "" );
m_strID3EncodedBy = _W( "" );
m_strCDDBHSubmitAddr = _W( "freedb.freedb.org" );
m_strCDDBESubmitAddr = _W( "[email protected]" );
m_strCDDBESubmitServer= _W( "" );
m_nCDDBSubmitVia = 1;
m_nID3Version = ID3_VERSION_2;
m_strRILC = _T( "5F 5F 5F 5F 5F 5F 5F 5F 5F 20" );
m_cSplitTrackChar = _T( '/' );
m_bSplitTrackName = FALSE;
m_bAutoRip = FALSE;
m_bEjectWhenFinished = FALSE;
m_bAutoShutDown = FALSE;
m_bKeepDirLayout = TRUE;
m_bSelectAllCDTracks = TRUE;
m_nOverwriteExisting = 0;
m_nRecordingDevice = 0;
m_nID3V2TrackNumber = ID3TRKNRTTYPE_T;
m_bCDDBWriteAsDosFile = FALSE;
m_bCDPlayDigital = FALSE;
m_bRecordAddSeqNr = TRUE;
m_bRecordEncoderType = ENCODER_FIXED_WAV;
TCHAR lpszTemp[ MAX_PATH + 1] = { _T( '\0' ),};
GetTempPath(_countof(lpszTemp), lpszTemp);
m_strTempDir = CUString( lpszTemp );
m_strIniFileName = _W( "CDex.ini" );
m_strProfileName = _W( "" );
m_strLanguage = _W( "english" );
m_bUseStatusServer = FALSE;
m_strStatusServer = _T("localhost" );
m_nStatusServerPort = 4242;
// setup the ini filename
g_config.GetIni().SetIniFileName( g_config.GetIniFileName() );
EXIT_TRACE( _T( "CConfig::CConfig()" ) );
}
void CConfig::Save()
{
ENTRY_TRACE( _T( "CConfig::Save()" ) );
#ifdef UNICODE
g_config.GetIni().SetBom();
#endif
// Save MP3 Parameters
g_config.GetIni().SetValue( _T( "General" ), _T( "MP3OutputDir" ), m_strMP3OutputDir );
g_config.GetIni().SetValue( _T( "General" ), _T( "CnvOutputDir" ), m_strCnvOutputDir );
g_config.GetIni().SetValue( _T( "General" ), _T( "RecOutputDir" ), m_strRecOutputDir );
g_config.GetIni().SetValue( _T( "General" ), _T( "bNormTrack" ), m_bNormTrack );
g_config.GetIni().SetValue( _T( "General" ), _T( "OutputRiffWavaFile" ), m_bRiffWav );
g_config.GetIni().SetValue( _T( "General" ), _T( "RetainWavFile" ), m_bRetainWavFile );
g_config.GetIni().SetValue( _T( "General" ), _T( "WinEncoder" ), m_bWinEncoder );
g_config.GetIni().SetValue( _T( "General" ), _T( "FNBufferSize" ), m_nFNBufferSize );
g_config.GetIni().SetValue( _T( "General" ), _T( "MP3InputDir" ), m_strMP3InputDir );
g_config.GetIni().SetValue( _T( "General" ), _T( "PlayDir" ), m_strPlayDir );
// WAV settings
g_config.GetIni().SetValue( _T( "General" ), _T( "WAVInputDir" ), m_strWAVInputDir );
g_config.GetIni().SetValue( _T( "General" ), _T( "DeleteWAVAfterConversion" ), m_bDelWavAfterConv );
// Save CD Device parameters
g_config.GetIni().SetValue( _T( "General" ), _T( "M3UPlayList" ), m_bM3UPlayList );
g_config.GetIni().SetValue( _T( "General" ), _T( "PLSPlayList" ), m_bPLSPlayList );
// CDDB stuff
g_config.GetIni().SetValue( _T( "General" ), _T( "CDDBPath" ), m_strCDDBPath );
g_config.GetIni().SetValue( _T( "General" ), _T( "WinampDBPath" ), m_strWinampDBPath );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDDDEmailAddress" ), m_strEmailAddress );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDDDProxyAddress" ), m_strProxyAddress );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBUseProxy" ), m_nCDDBUseProxy );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBUseAuthentication" ), m_nCDDBUseAuthentication );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBProxyPort" ), m_nCDDBProxyPort );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBTimeOut" ), m_nCDDBTimeOut );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBLongDirNames" ), m_bCDDBLongDirNames );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDBBAutoConnect" ), m_bCDDBAutoConnect );
g_config.GetIni().SetValue( _T( "General" ), _T( "AutoRip" ), m_bAutoRip );
g_config.GetIni().SetValue( _T( "General" ), _T( "SplitTrackName" ), m_bSplitTrackName );
g_config.GetIni().SetValue( _T( "General" ), _T( "SplitTrackChar" ), (int)m_cSplitTrackChar );
g_config.GetIni().SetValue( _T( "General" ), _T( "EjectWhenFinished" ), m_bEjectWhenFinished );
g_config.GetIni().SetValue( _T( "General" ), _T( "SelectAllCDTracks" ), m_bSelectAllCDTracks );
g_config.GetIni().SetValue( _T( "General" ), _T( "AutoShutDown" ), m_bAutoShutDown );
g_config.GetIni().SetValue( _T( "General" ), _T( "KeepDirLayout" ), m_bKeepDirLayout );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDDBWriteAsDosFile" ), m_bCDDBWriteAsDosFile );
g_config.GetIni().SetValue( _T( "General" ), _T( "CDPlayDigital" ), m_bCDPlayDigital );
g_config.GetIni().SetValue( _T( "General" ), _T( "RecordAddSeqNr" ), m_bRecordAddSeqNr );
g_config.GetIni().SetValue( _T( "General" ), _T( "RecordEncoderType" ), m_bRecordEncoderType );
// temp directory
g_config.GetIni().SetValue( _T( "General" ), _T( "TempDir" ), m_strTempDir );
// Write Proxy stuff if authentication is enabled
if ( m_nCDDBUseAuthentication )
{
int i;
int nVersion=001;
int nKey;
int nLength;
int nSkip;
int nIndex=0;
// Write version number
g_config.GetIni().SetValue( _T( "ProxyAuthentication" ), _T( "Version" ), nVersion );
// Write User Name
g_config.GetIni().SetValue( _T( "ProxyAuthentication" ), _T( "UserName" ), m_strCDDBProxyUser );
// Create buffer string
INT pBuffer[ 255 ];
// Initialize pseudo random generator
srand( GetTickCount() );
// Generate encryption key
//#define DEBUG_PWD
#ifdef DEBUG_PWD
nKey = 5367;
m_strCDDBProxyPassword = _T( "testpwd" );
#else
nKey=rand();
#endif
// Store key in buffer zero
pBuffer[ nIndex++ ] =nKey;
// Get the length of Proxy User name
nLength=m_strCDDBProxyPassword.GetLength();
// Store length in buffer one
pBuffer[nIndex++]=nLength ^ (int)sqrt((double)abs(nKey)+100);
int nSum=0;
// determine a skip value between 3..10 bo
nSkip=(nLength + nKey)&7 + 3;
// Generate nSkip keys and keep track of sum
for (i=0;i<nSkip;i++,nIndex++)
{
// Re-initialize pseudo random generator
srand(GetTickCount()+pBuffer[i]);
// Do a rand in order to generate a better key
rand();
#ifdef DEBUG_PWD
pBuffer[nIndex]=500;
#else
// Generate random number, store in buffer
pBuffer[nIndex]=rand();
#endif
// Add generated number to sum
nSum+=pBuffer[nIndex];
}
// Write encrypted password into buffer
for (i=0;i<nLength;i++,nIndex++)
{
// Store nLength in Byte one
pBuffer[nIndex]= (int)(m_strCDDBProxyPassword.GetAt(i)) ^ (nSum^ (int)sqrt((double)abs(pBuffer[nIndex-1]+pBuffer[nIndex-2])+3454));
}
// Write length of buffer
g_config.GetIni().SetValue( _T( "ProxyAuthentication" ),
_T( "PasswordLength" ),
nIndex );
// Write buffer
for (i=0;i<nIndex;i++)
{
CUString strKey;
strKey.Format( _W( "Password%03d" ), i );
g_config.GetIni().SetValue( _T( "ProxyAuthentication" ),
strKey,
pBuffer[i] );
}
}
g_config.GetIni().SetValue( _W("General" ), _W( "FileFormatString" ),m_strFileFormat);
g_config.GetIni().SetValue( _W("General" ), _W( "PlsFileFormatString" ),m_strPlsFileFormat);
g_config.GetIni().SetValue( _W("General" ), _W( "LocalCDDBType" ),m_nLocalCDDBType);
g_config.GetIni().SetValue( _W("General" ), _W( "SaveToCDPlayer" ),m_bSaveToCDPlayer);
g_config.GetIni().SetValue( _W("General" ), _W( "SaveToLocalCDDB" ),m_bSaveToLocCDDB);
g_config.GetIni().SetValue( _W("General" ), _W( "PCopyEncType" ),m_nPCopyEncType);
g_config.GetIni().SetValue( _W("General" ), _W( "NormLowLevel" ),m_nLowNormLevel);
g_config.GetIni().SetValue( _W("General" ), _W( "NormHighLevel" ),m_nHighNormLevel);
g_config.GetIni().SetValue( _W("General" ), _W( "LNormFactor" ),m_nLNormFactor);
g_config.GetIni().SetValue( _W("General" ), _W( "HNormFactor" ),m_nHNormFactor);
g_config.GetIni().SetValue( _W("General" ), _W( "EncoderType" ),m_nEncoderType);
g_config.GetIni().SetValue( _W("General" ), _W( "ExtEncPath" ),m_strExtEncPath);
g_config.GetIni().SetValue( _W("General" ), _W( "ExtEncOpts" ),m_strExtEncOpts);
g_config.GetIni().SetValue( _W("General" ), _W( "TagPictureComment" ),m_strTagPictureComment);
g_config.GetIni().SetValue( _W("General" ), _W( "TagPictureFile" ),m_strTagPictureFile);
g_config.GetIni().SetValue( _W("General" ), _W( "AddTagPicture" ),m_bAddTagPicture );
g_config.GetIni().SetValue( _W("General" ), _W( "ThreadPriority" ),m_nThreadPriority);
g_config.GetIni().SetValue( _W("General" ), _W( "CDDBSubmitVia" ),m_nCDDBSubmitVia);
g_config.GetIni().SetValue( _W("General" ), _W( "ID3Version" ),m_nID3Version);
g_config.GetIni().SetValue( _W("General" ), _W( "ID3EncodedBy" ),m_strID3EncodedBy); // Hydra
g_config.GetIni().SetValue( _W("General" ), _W( "ID3Comment" ),m_strID3Comment);
g_config.GetIni().SetValue( _W("CDDB" ), _W( "CDDBESubmitAddr" ),m_strCDDBESubmitAddr);
g_config.GetIni().SetValue( _W("CDDB" ), _W( "CDDBHSubmitAddr" ),m_strCDDBHSubmitAddr);
g_config.GetIni().SetValue( _W("CDDB" ), _W( "CDDBESubmitServer" ),m_strCDDBESubmitServer);
g_config.GetIni().SetValue( _W("General" ), _W( "RILC" ),m_strRILC);
g_config.GetIni().SetValue( _W("General" ), _W( "OverwriteExisting" ),m_nOverwriteExisting);
g_config.GetIni().SetValue( _W("General" ), _W( "FileOpenRecursive" ),m_bFileOpenRecursive);
g_config.GetIni().SetValue( _W("General" ), _W( "RecordingDevice" ),m_nRecordingDevice);
g_config.GetIni().SetValue( _W("General" ), _W( "ID3V2TrackNumber" ),m_nID3V2TrackNumber);
g_config.GetIni().SetValue( _W("General" ), _W( "ProfileName" ),m_strProfileName);
g_config.GetIni().SetValue( _W("General" ), _W( "Language" ),m_strLanguage);
// Status notification settings
g_config.GetIni().SetValue( _W("StatusNotification" ), _W( "UseStatusServer" ), m_bUseStatusServer );
g_config.GetIni().SetValue( _W("StatusNotification" ), _W( "StatusServer" ), m_strStatusServer );
g_config.GetIni().SetValue( _W("StatusNotification" ), _W( "StatusServerPort" ), m_nStatusServerPort );
// Save the remote site info
g_RemoteSites.Save();
// Save CD-ROM settings
SaveCDRomSettings();
// Flush ini file
CUStringConvert strCnv;
WritePrivateProfileString( NULL, NULL, NULL, strCnv.ToT( g_config.GetIniFileName() ) );
// copy profile
if ( !m_strProfileName.IsEmpty() )
{
// backup current settings to active profile name
CDexCopyFile( GetIniFileName(),
GetAppPath() + _W("\\") + m_strProfileName + PROFILE_EXTENTION,
FALSE );
}
EXIT_TRACE( _T( "CConfig::Save()" ) );
}
void CConfig::Load()
{
ENTRY_TRACE( _T( "CConfig::Load()" ) );
// Flush ini file
CUStringConvert strCnv;
WritePrivateProfileString( NULL, NULL, NULL, strCnv.ToT( g_config.GetIniFileName() ) );
// Load MP3 Parameters
m_bNormTrack =g_config.GetIni().GetValue( _T("General" ), _T( "bNormTrack" ),m_bNormTrack);
m_bRiffWav =g_config.GetIni().GetValue( _T("General" ), _T( "OutputRiffWavaFile" ),m_bRiffWav);
m_bRetainWavFile =g_config.GetIni().GetValue( _T("General" ), _T( "RetainWavFile" ),m_bRetainWavFile);
m_bWinEncoder =g_config.GetIni().GetValue( _T("General" ), _T( "WinEncoder" ),m_bWinEncoder);
m_nFNBufferSize =g_config.GetIni().GetValue( _T("General" ), _T( "FNBufferSize" ),m_nFNBufferSize);
m_strMP3OutputDir= g_config.GetIni().GetValue( _T("General" ), _T( "MP3OutputDir" ),m_strMP3OutputDir);
m_strCnvOutputDir= g_config.GetIni().GetValue( _T("General" ), _T( "CnvOutputDir" ),m_strCnvOutputDir);
m_strRecOutputDir= g_config.GetIni().GetValue( _T("General" ), _T( "RecOutputDir" ),m_strRecOutputDir);
m_strMP3InputDir= g_config.GetIni().GetValue( _T("General" ), _T( "MP3InputDir" ),m_strMP3InputDir);
m_strPlayDir= g_config.GetIni().GetValue( _T("General" ), _T( "PlayDir" ),m_strPlayDir);
// WAV settings
m_strWAVInputDir= g_config.GetIni().GetValue( _T("General" ), _T( "WAVInputDir" ),m_strWAVInputDir);
m_bDelWavAfterConv= g_config.GetIni().GetValue( _T("General" ), _T( "DeleteWAVAfterConversion" ),m_bDelWavAfterConv);
m_bM3UPlayList= g_config.GetIni().GetValue( _T("General" ), _T( "M3UPlayList" ),m_bM3UPlayList);
m_bPLSPlayList= g_config.GetIni().GetValue( _T("General" ), _T( "PLSPlayList" ),m_bPLSPlayList);
m_bAutoRip= g_config.GetIni().GetValue( _T("General" ), _T( "AutoRip" ),m_bAutoRip);
m_bSplitTrackName= g_config.GetIni().GetValue( _T("General" ), _T( "SplitTrackName" ),m_bSplitTrackName);
m_cSplitTrackChar= (CHAR)g_config.GetIni().GetValue( _T("General" ), _T( "SplitTrackChar" ),m_cSplitTrackChar);
m_bEjectWhenFinished= g_config.GetIni().GetValue( _T("General" ), _T( "EjectWhenFinished" ),m_bEjectWhenFinished);
m_bSelectAllCDTracks= g_config.GetIni().GetValue( _T("General" ), _T( "SelectAllCDTracks" ),m_bSelectAllCDTracks);
m_bAutoShutDown= g_config.GetIni().GetValue( _T("General" ), _T( "AutoShutDown" ),m_bAutoShutDown);
m_bKeepDirLayout= g_config.GetIni().GetValue( _T("General" ), _T( "KeepDirLayout" ),m_bKeepDirLayout);
m_nThreadPriority= g_config.GetIni().GetValue( _T("General" ), _T( "ThreadPriority" ),m_nThreadPriority);
m_strTempDir= g_config.GetIni().GetValue( _T("General" ), _T( "TempDir" ),m_strTempDir);
m_bCDDBWriteAsDosFile= g_config.GetIni().GetValue( _T("General" ), _T( "CDDBWriteAsDosFile" ),m_bCDDBWriteAsDosFile);
m_bCDPlayDigital= g_config.GetIni().GetValue( _T("General" ), _T( "CDPlayDigital" ),m_bCDPlayDigital);
m_bRecordAddSeqNr= g_config.GetIni().GetValue( _T("General" ), _T( "RecordAddSeqNr" ),m_bRecordAddSeqNr);
m_bRecordEncoderType= g_config.GetIni().GetValue( _T("General" ), _T( "RecordEncoderType" ),m_bRecordEncoderType);
if ( m_strCnvOutputDir.IsEmpty() )
m_strCnvOutputDir=GetAppPath()+ _W( "\\my music\\");
if (m_strRecOutputDir.IsEmpty())
m_strRecOutputDir=GetAppPath()+ _W( "\\my music\\" );
if (m_strMP3OutputDir.IsEmpty())
m_strMP3OutputDir=GetAppPath()+ _W( "\\my music\\" );
if (m_strMP3InputDir.IsEmpty())
m_strMP3InputDir=GetAppPath()+ _W( "\\my music\\" );
if (m_strWAVInputDir.IsEmpty())
m_strWAVInputDir=GetAppPath()+ _W( "\\my music\\" );
if (m_strPlayDir.IsEmpty())
m_strPlayDir=GetAppPath() + _W( "\\my music\\" );
// CDDB stuff
m_strCDDBPath = g_config.GetIni().GetValue( _T("General" ), _T( "CDDBPath" ),m_strCDDBPath);
if (m_strCDDBPath.IsEmpty())
{
m_strCDDBPath = GetAppPath() + _W( "\\LocalCDDB\\");
}
m_strWinampDBPath = FormatDirName( g_config.GetIni().GetValue( _T("General" ), _T( "WinampDBPath" ), m_strWinampDBPath) );
// Add trailing back space
m_strCDDBPath = FormatDirName( m_strCDDBPath );
m_nCDDBUseProxy= g_config.GetIni().GetValue( _T("General" ), _T( "CDBBUseProxy" ),m_nCDDBUseProxy);
m_nCDDBUseAuthentication=g_config.GetIni().GetValue( _T("General" ), _T( "CDBBUseAuthentication" ),m_nCDDBUseAuthentication);
m_nCDDBProxyPort= g_config.GetIni().GetValue( _T("General" ), _T( "CDBBProxyPort" ),m_nCDDBProxyPort);
m_nCDDBTimeOut= g_config.GetIni().GetValue( _T("General" ), _T( "CDBBTimeOut" ),m_nCDDBTimeOut);
m_bCDDBAutoConnect= g_config.GetIni().GetValue( _T("General" ), _T( "CDBBAutoConnect" ),m_bCDDBAutoConnect);
// Status notification settings
m_bUseStatusServer = g_config.GetIni().GetValue( _T("StatusNotification" ), _T( "UseStatusServer" ), m_bUseStatusServer );
m_strStatusServer = g_config.GetIni().GetValue( _T("StatusNotification" ), _T( "StatusServer" ), m_strStatusServer );
m_nStatusServerPort = g_config.GetIni().GetValue( _T("StatusNotification" ), _T( "StatusServerPort" ), m_nStatusServerPort );
// Read Proxy stuff if authentication is enabled
if (m_nCDDBUseAuthentication)
{
int i;
int nVersion=001;
int nKey;
int nLength;
int nSkip;
int nIndex=0;
int nBufferLength=0;
int nSum=0;
// Create buffer string
INT pBuffer[255];
// Clear memory of buffer
memset(pBuffer,0x00,sizeof(pBuffer));
// Read version number
//nVersion=g_config.GetIni().GetValue( _T("ProxyAuthentication" ), _T( "Version" ),nVersion);
// Read User Name
m_strCDDBProxyUser=g_config.GetIni().GetValue( _T("ProxyAuthentication" ), _T( "UserName" ),m_strCDDBProxyUser);
// Read buffer length
nBufferLength=g_config.GetIni().GetValue( _T("ProxyAuthentication" ), _T( "PasswordLength" ),nBufferLength);
// Read buffer
for (i=0;i<nBufferLength;i++)
{
CUString strKey;
strKey.Format( _W( "Password%03d" ), i );
pBuffer[ i ] = g_config.GetIni().GetValue( _T( "ProxyAuthentication" ),
strKey,
pBuffer[ i ] );
}
// Get main encryption key
nKey=pBuffer[nIndex++];
// Get length of string back
nLength=pBuffer[nIndex++] ^ (int)sqrt((double)abs(nKey)+100);
// determine a skip value between 3..10
nSkip=(nLength + nKey)&7 + 3;
// Generate nSkip keys and keep track of sum
for (i=0;i<nSkip;i++,nIndex++)
{
// Add generated number to sum
nSum+=pBuffer[nIndex];
}
char lpszTemp[80];
int iTemp;
// Clear result string
memset(lpszTemp,0x00,sizeof(lpszTemp));
// Decypher encrypted password
for (i=0;i<nLength;i++,nIndex++)
{
// Decypher character
iTemp=pBuffer[nIndex] ^ (nSum^(int)sqrt((double)abs(pBuffer[nIndex-1]+pBuffer[nIndex-2])+3454));
lpszTemp[i]= (char)iTemp;
}
//
m_strCDDBProxyPassword = CUString( lpszTemp, CP_UTF8);
}
m_bCDDBLongDirNames=g_config.GetIni().GetValue( _W("General" ), _W( "CDBBLongDirNames" ),m_bCDDBLongDirNames);
m_nLocalCDDBType= g_config.GetIni().GetValue( _W("General" ), _W( "LocalCDDBType" ),m_nLocalCDDBType);
m_bSaveToCDPlayer= g_config.GetIni().GetValue( _W("General" ), _W( "SaveToCDPlayer" ),m_bSaveToCDPlayer);
m_bSaveToLocCDDB= g_config.GetIni().GetValue( _W("General" ), _W( "SaveToLocalCDDB" ),m_bSaveToLocCDDB);
m_strEmailAddress= g_config.GetIni().GetValue( _W("General" ), _W( "CDDDEmailAddress" ),m_strEmailAddress);
m_strProxyAddress= g_config.GetIni().GetValue( _W("General" ), _W( "CDDDProxyAddress" ),m_strProxyAddress);
m_nPCopyEncType= g_config.GetIni().GetValue( _W("General" ), _W( "PCopyEncType" ),m_nPCopyEncType);
m_nLowNormLevel= g_config.GetIni().GetValue( _W("General" ), _W( "NormLowLevel" ),m_nLowNormLevel);
m_nHighNormLevel= g_config.GetIni().GetValue( _W("General" ), _W( "NormHighLevel" ),m_nHighNormLevel);
m_nLNormFactor= g_config.GetIni().GetValue( _W("General" ), _W( "LNormFactor" ),m_nLNormFactor);
m_nHNormFactor= g_config.GetIni().GetValue( _W("General" ), _W( "HNormFactor" ),m_nHNormFactor);
m_nEncoderType= g_config.GetIni().GetValue( _W("General" ), _W( "EncoderType" ),m_nEncoderType);
m_strExtEncPath= g_config.GetIni().GetValue( _W("General" ), _W( "ExtEncPath" ),m_strExtEncPath);
m_strExtEncOpts= g_config.GetIni().GetValue( _W("General" ), _W( "ExtEncOpts" ),m_strExtEncOpts);
m_strTagPictureComment = g_config.GetIni().GetValue( _W("General" ), _W( "TagPictureComment" ),m_strTagPictureComment);
m_strTagPictureFile = g_config.GetIni().GetValue( _W("General" ), _W( "TagPictureFile" ),m_strTagPictureFile);
m_bAddTagPicture = g_config.GetIni().GetValue( _W("General" ), _W( "AddTagPicture" ),m_bAddTagPicture );
m_nCDDBSubmitVia= g_config.GetIni().GetValue( _W("General" ), _W( "CDDBSubmitVia" ),m_nCDDBSubmitVia);
m_nID3Version= g_config.GetIni().GetValue( _W("General" ), _W( "ID3Version" ),m_nID3Version);
m_strID3EncodedBy= g_config.GetIni().GetValue( _W("General" ), _W( "ID3EncodedBy" ),m_strID3EncodedBy);
m_strID3Comment= g_config.GetIni().GetValue( _W("General" ), _W( "ID3Comment" ),m_strID3Comment);
m_strCDDBESubmitAddr=g_config.GetIni().GetValue( _W("CDDB" ), _W( "CDDBESubmitAddr" ),m_strCDDBESubmitAddr);
m_strCDDBHSubmitAddr=g_config.GetIni().GetValue( _W("CDDB" ), _W( "CDDBHSubmitAddr" ),m_strCDDBHSubmitAddr);
m_strCDDBESubmitServer=g_config.GetIni().GetValue( _W("CDDB" ), _W( "CDDBESubmitServer" ),m_strCDDBESubmitServer);
m_strRILC =g_config.GetIni().GetValue( _W("General" ), _W( "RILC" ),m_strRILC);
m_nOverwriteExisting= g_config.GetIni().GetValue( _W("General" ), _W( "OverwriteExisting" ),m_nOverwriteExisting);
m_bFileOpenRecursive= g_config.GetIni().GetValue( _W("General" ), _W( "FileOpenRecursive" ),m_bFileOpenRecursive);
m_nRecordingDevice= g_config.GetIni().GetValue( _W("General" ), _W( "RecordingDevice" ),m_nRecordingDevice);
m_nID3V2TrackNumber= ID3TRKNRTTYPE( g_config.GetIni().GetValue( _W("General" ), _W( "ID3V2TrackNumber" ), m_nID3V2TrackNumber ) );
m_strProfileName= g_config.GetIni().GetValue( _W("General" ), _W( "ProfileName" ),m_strProfileName);
m_strLanguage= g_config.GetIni().GetValue( _W("General" ), _W( "Language" ),m_strLanguage);
// DEBUG STUFF
m_bDumpToc= g_config.GetIni().GetValue( _W("General" ), _W( "DumpToc" ),m_bDumpToc);
// m_nSepChar=g_config.GetIni().GetValue( _W("General" ), _W( "SepCharacter" ),m_nSepChar);
CUString strTmp;
// Get the string
m_strFileFormat=g_config.GetIni().GetValue( _W("General" ), _W( "FileFormatString" ),m_strFileFormat);
m_strPlsFileFormat=g_config.GetIni().GetValue( _W("General" ), _W( "PlsFileFormatString" ),m_strPlsFileFormat);
// Load the remote site info
g_RemoteSites.Load();
// Create the local CDDB path
DoesDirExist( GetCDDBPath(), FALSE );
EXIT_TRACE( _T( "CConfig::Load()" ) );
}
CDEX_ERR DoesDirExist(CUString& strDirTest,BOOL bVerbose)
{
if (strDirTest.IsEmpty())
return TRUE;
// current dir
TCHAR lpszCurDir[ MAX_PATH + 1 ] = { _T( '\0' ),};
// Get current directory
_tgetcwd( lpszCurDir, _countof( lpszCurDir ) );
// Does the dir exist
CUStringConvert strCnv;
if ( _tchdir( strCnv.ToT( strDirTest ) ) != 0 )
{
if (!bVerbose)
{
if (MyCreateDir(strDirTest)!=0)
{
// return to current directory
_tchdir( lpszCurDir );
return CDEX_OK;
}
}
else
{
CUString strTmp;
strTmp.Format( _W( "The output directory %s does not exist\n\rWoul you like to create it" ), (LPCWSTR)strDirTest );
if (CDexMessageBox( strTmp, MB_YESNO ) == IDYES )
{
if (MyCreateDir(strDirTest)!=0)
{
// return to current directory
_tchdir( lpszCurDir );
return CDEX_OK;
}
}
else
{
_tchdir( lpszCurDir );
return CDEX_ERROR;
}
}
}
// return to current directory
_tchdir( lpszCurDir );
// Return that directory does exist
return CDEX_OK;
}
// CONSTRUCTOR
CRemoteSites::CRemoteSites()
{
// Start Fresh
ClearAll();
// Always add the default servers
AddDefaultSites();
}
// DESTRUCTOR
CRemoteSites::~CRemoteSites()
{
}
// ASSIGNMENT OPERATOR
CRemoteSites& CRemoteSites::operator=(const CRemoteSites& rhs)
{
// Avoid self assignment
if (this!= &rhs)
{
m_vRemoteSites = rhs.m_vRemoteSites;
m_nActiveSite = rhs.m_nActiveSite;
}
return *this;
}
// COPY CONSTRUCTOR
CRemoteSites::CRemoteSites(const CRemoteSites& rhs)
{
m_vRemoteSites = rhs.m_vRemoteSites;
m_nActiveSite = rhs.m_nActiveSite;
}
// AddSite
void CRemoteSites::AddSite( CUString strAddress,
CUString strLocation,
CUString strPath,
int nPort,
int nProtocol,
int nEditable)
{
// Create a new CRemoteSiteInfo class on the stack
CRemoteSiteInfo newSite;
// Fill in the information
newSite.m_strAddress=strAddress;
newSite.m_strLocation=strLocation;
newSite.m_strPath=strPath;
newSite.m_nPort=nPort;
newSite.m_nProtocol=nProtocol;
newSite.m_nEditable=nEditable;
// Add it to the array of RemoteSites
m_vRemoteSites.push_back(newSite);
}
// Edit Site information
void CRemoteSites::SetSite( int iIndex,
CUString strAddress,
CUString strLocation,
CUString strPath,
int nPort,
int nProtocol)
{
// Edit the information
m_vRemoteSites[iIndex].m_strAddress=strAddress;
m_vRemoteSites[iIndex].m_strLocation=strLocation;
m_vRemoteSites[iIndex].m_strPath=strPath;
m_vRemoteSites[iIndex].m_nPort=nPort;
m_vRemoteSites[iIndex].m_nProtocol=nProtocol;
}
// Clear All Sites
void CRemoteSites::ClearAll()
{
m_vRemoteSites.clear();
m_nActiveSite=0;
}
void CRemoteSites::AddDefaultSites()
{
// This site (both CDDB protocl as well as HTTP protocol are ALWAYS available)
// The http protocol site
AddSite( _T("freedb.freedb.org" ), _T( "freedb, Random freedb server" ), _T( "/~cddb/cddb.cgi" ),80,OPTIONS_CDDB_USEHTTP );
// The cddp protocol site
AddSite( _T("freedb.freedb.org" ), _T( "freedb, freedb, Random freedb server" ), _T( "-" ),888,OPTIONS_CDDB_USETCPIP );
// The http protocol site
// AddSite( _T("cddb.cddb.com" ), _T( "Carmel, IN USA" ), _T( "/~cddb/cddb.cgi" ),80,OPTIONS_CDDB_USEHTTP );
// The cddp protocol site
// AddSite( _T("cddb.cddb.com" ), _T( "Carmel, IN USA" ), _T( "-" ),888,OPTIONS_CDDB_USETCPIP );
}
// Save Site to INI file
void CRemoteSites::Save()
{
CUString strCDDBServer( _W( "CDDB Servers" ) );
// Get the number of remote servers
int nNumSites=m_vRemoteSites.size();
// Save number of entries
g_config.GetIni().SetValue( strCDDBServer, _T( "NumSites" ),nNumSites);
g_config.GetIni().SetValue( strCDDBServer, _T( "ActiveSite" ),m_nActiveSite);
// Save all entries to INI file
for (int i=0; i<nNumSites; i++ )
{
CUString strIndex;