PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/zmatrix/Config/ConfigForm.cpp

https://github.com/kovrov/scrap
C++ | 2553 lines | 2065 code | 323 blank | 165 comment | 447 complexity | 0dc1ed942dae39baa3abc83abb6fbf9c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*!=========================================================================
  2. //
  3. // Program: ZMatrix
  4. // Module: $RCSfile: ConfigForm.cpp,v $
  5. // Language: C/C++
  6. // Date: $Date: 2003/05/12 07:43:56 $
  7. // Version: $Revision: 1.21 $
  8. //
  9. // Copyright (c) 2001-2002 Z. Shaker
  10. // All rights reserved.
  11. // See License.txt for details.
  12. //
  13. // This file is part of ZMatrix.
  14. //
  15. // ZMatrix is free software; you can redistribute it and/or modify
  16. // it under the terms of the GNU General Public License as published by
  17. // the Free Software Foundation; either version 2 of the License, or
  18. // (at your option) any later version.
  19. //
  20. // ZMatrix is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. // GNU General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU General Public License
  26. // along with ZMatrix; if not, write to the Free Software
  27. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. //
  29. //=========================================================================*/
  30. //---------------------------------------------------------------------------
  31. #define NO_WIN32_LEAN_AND_MEAN
  32. #include <vcl.h>
  33. #pragma hdrstop
  34. #include <tchar.h>
  35. #include <SysUtils.hpp>
  36. #include <stdio.h>
  37. #include <htmlhelp.h>
  38. #include "ConfigForm.h"
  39. #include "AboutUnit.h"
  40. #include "HireUnit.h"
  41. //---------------------------------------------------------------------------
  42. #pragma package(smart_init)
  43. #pragma resource "*.dfm"
  44. TConfigurationForm *ConfigurationForm = NULL;
  45. #ifndef min
  46. #define min(a,b) (a)<(b)? (a):(b)
  47. #endif
  48. #ifndef CLAMP
  49. #define CLAMP(var,min,max)\
  50. if((var) > (max)) (var) = (max);\
  51. if((var) < (min)) (var) = (min);
  52. #endif
  53. #define LONG_MAX_PATH 2048
  54. //---------------------------------------------------------------------------
  55. extern "C" void __stdcall LaunchAboutForm(void *Parent)
  56. {
  57. static bool AlreadyLaunched = false;
  58. if(!AlreadyLaunched)
  59. {
  60. AlreadyLaunched = true;
  61. if(AboutForm == NULL)
  62. {
  63. AboutForm = new TAboutForm((TComponent *)Parent);
  64. }
  65. AboutForm->ShowModal();
  66. if(AboutForm != NULL)
  67. {
  68. delete AboutForm;
  69. AboutForm = NULL;
  70. }
  71. AlreadyLaunched = false;
  72. }
  73. }
  74. //---------------------------------------------------------------------------
  75. extern "C" void __stdcall LaunchHireForm(void *Parent)
  76. {
  77. static bool AlreadyLaunched = false;
  78. if(!AlreadyLaunched)
  79. {
  80. AlreadyLaunched = true;
  81. if(HireForm == NULL)
  82. {
  83. HireForm = new THireForm((TComponent *)Parent);
  84. }
  85. HireForm->ShowModal();
  86. if(HireForm != NULL)
  87. {
  88. delete HireForm;
  89. HireForm = NULL;
  90. }
  91. AlreadyLaunched = false;
  92. }
  93. }
  94. //---------------------------------------------------------------------------
  95. extern "C" int __stdcall LaunchConfigForm(IzsMatrix *Matrix,unsigned int &RefreshTime,DWORD &Priority)
  96. {
  97. //zsMatrix Matrix(NULL,NULL);
  98. int returnValue;
  99. ConfigurationForm = new TConfigurationForm(NULL,Matrix,&RefreshTime,&Priority);
  100. returnValue = ConfigurationForm->ShowModal();
  101. delete ConfigurationForm;
  102. ConfigurationForm = NULL;
  103. if(returnValue == mrOk)
  104. return true;
  105. return false;
  106. }
  107. //---------------------------------------------------------------------------
  108. int __stdcall SaveConfigToFile(IzsMatrix *Matrix,unsigned int RefreshTime,DWORD Priority,_TCHAR *FileName)
  109. {
  110. if((Matrix == NULL) || (FileName == NULL))
  111. {
  112. return 0;
  113. }
  114. AnsiString SectionName;
  115. AnsiString ValueName;
  116. TIniFile *OutFile = new TIniFile(ExpandFileName(AnsiString(FileName)));
  117. //TIniFile *OutFile = new TIniFile(AnsiString(FileName));
  118. SectionName = "General";
  119. ValueName = "ConfigFileFormatVersion";
  120. OutFile->WriteString(SectionName,ValueName,"1.0");
  121. ValueName = "MaxStream";
  122. OutFile->WriteInteger(SectionName,ValueName,Matrix->GetMaxStream());
  123. ValueName = "SpeedVariance";
  124. OutFile->WriteInteger(SectionName,ValueName,Matrix->GetSpeedVariance());
  125. ValueName = "MonotonousCleanupEnabled";
  126. OutFile->WriteBool(SectionName,ValueName,Matrix->GetMonotonousCleanupEnabled());
  127. ValueName = "BackTrace";
  128. OutFile->WriteInteger(SectionName,ValueName,Matrix->GetBackTrace());
  129. ValueName = "RandomizedCleanupEnabled";
  130. OutFile->WriteBool(SectionName,ValueName,Matrix->GetRandomizedCleanupEnabled());
  131. ValueName = "Leading";
  132. OutFile->WriteInteger(SectionName,ValueName,Matrix->GetLeading());
  133. ValueName = "SpacePad";
  134. OutFile->WriteInteger(SectionName,ValueName,Matrix->GetSpacePad());
  135. ValueName = "RefreshTime";
  136. OutFile->WriteInteger(SectionName,ValueName,RefreshTime);
  137. ValueName = "PriorityClass";
  138. AnsiString PriorityName;
  139. switch(Priority)
  140. {
  141. case(ABOVE_NORMAL_PRIORITY_CLASS): PriorityName = "ABOVE_NORMAL_PRIORITY_CLASS"; break;
  142. case(BELOW_NORMAL_PRIORITY_CLASS): PriorityName = "BELOW_NORMAL_PRIORITY_CLASS"; break;
  143. case(HIGH_PRIORITY_CLASS): PriorityName = "HIGH_PRIORITY_CLASS"; break;
  144. case(IDLE_PRIORITY_CLASS): PriorityName = "IDLE_PRIORITY_CLASS"; break;
  145. case(NORMAL_PRIORITY_CLASS): PriorityName = "NORMAL_PRIORITY_CLASS"; break;
  146. default: PriorityName = "IDLE_PRIORITY_CLASS"; break;
  147. }
  148. OutFile->WriteString(SectionName,ValueName,PriorityName);
  149. ValueName = "SpecialStringStreamProbability";
  150. OutFile->WriteFloat(SectionName,ValueName,Matrix->GetSpecialStringStreamProbability());
  151. SectionName = "Text";
  152. LOGFONT LogFont;
  153. GetObject(Matrix->GetFont(),sizeof(LOGFONT),&LogFont);
  154. WriteLogFontToConfigFile(OutFile,SectionName,LogFont);
  155. ValueName = "CharSet";
  156. AnsiString CharSet;
  157. ConvertCharSetToAnsiString(Matrix->GetValidCharSet(),Matrix->GetNumCharsInSet(),CharSet);
  158. OutFile->WriteString(SectionName,ValueName,CharSet);
  159. SectionName = "SpecialText";
  160. GetObject(Matrix->GetSpecialStringFont(),sizeof(LOGFONT),&LogFont);
  161. WriteLogFontToConfigFile(OutFile,SectionName,LogFont);
  162. ValueName = "Strings";
  163. AnsiString SpecialStrings;
  164. vector<tstring> SpecialStringVec;
  165. SpecialStringVec.resize(Matrix->GetNumSpecialStringsInSet());
  166. unsigned int i = 0;
  167. for(vector<tstring>::iterator iter = SpecialStringVec.begin();
  168. iter != SpecialStringVec.end();
  169. ++iter, ++i)
  170. {
  171. iter->assign(Matrix->GetValidSpecialString(i));
  172. }
  173. ConvertSpecialStringsToAnsiString(SpecialStringVec,SpecialStrings,CONFIG_FILE_SPECIAL_STRING_DELIMITER);
  174. OutFile->WriteString(SectionName,ValueName,SpecialStrings);
  175. SectionName = "Colors";
  176. ValueName = "FGColor";
  177. BYTE R,G,B,A;
  178. Matrix->GetColor(R,G,B,A);
  179. AnsiString ForegroundColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  180. OutFile->WriteString(SectionName,ValueName,ForegroundColor);
  181. ValueName = "FadeColor";
  182. Matrix->GetFadeColor(R,G,B,A);
  183. AnsiString FadeColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  184. OutFile->WriteString(SectionName,ValueName,FadeColor);
  185. ValueName = "BGColor";
  186. Matrix->GetBGColor(R,G,B,A);
  187. AnsiString BackgroundColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  188. OutFile->WriteString(SectionName,ValueName,BackgroundColor);
  189. ValueName = "SpecialStringFGColor";
  190. Matrix->GetSpecialStringColor(R,G,B,A);
  191. AnsiString SpecialStringForegroundColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  192. OutFile->WriteString(SectionName,ValueName,SpecialStringForegroundColor);
  193. ValueName = "SpecialStringFadeColor";
  194. Matrix->GetSpecialStringFadeColor(R,G,B,A);
  195. AnsiString SpecialStringFadeColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  196. OutFile->WriteString(SectionName,ValueName,SpecialStringFadeColor);
  197. ValueName = "SpecialStringBGColor";
  198. Matrix->GetSpecialStringBGColor(R,G,B,A);
  199. AnsiString SpecialStringBackgroundColor = "{" + AnsiString(R) + "," + AnsiString(G) + "," + AnsiString(B) + "," + AnsiString(A) + "}";
  200. OutFile->WriteString(SectionName,ValueName,SpecialStringBackgroundColor);
  201. ValueName = "BGMode";
  202. TBGMode BGMode = Matrix->GetBGMode();
  203. AnsiString BGModeString;
  204. switch(BGMode)
  205. {
  206. case(bgmodeColor):
  207. {
  208. BGModeString = "bgmodeColor";
  209. }
  210. break;
  211. default:
  212. case(bgmodeBitmap):
  213. {
  214. BGModeString = "bgmodeBitmap";
  215. }
  216. break;
  217. }
  218. OutFile->WriteString(SectionName,ValueName,BGModeString);
  219. ValueName = "BlendMode";
  220. TBlendMode BlendMode = Matrix->GetBlendMode();
  221. AnsiString BlendModeString;
  222. switch(BlendMode)
  223. {
  224. case(blendmodeOR):
  225. {
  226. BlendModeString = "blendmodeOR";
  227. }
  228. break;
  229. case(blendmodeAND):
  230. {
  231. BlendModeString = "blendmodeAND";
  232. }
  233. break;
  234. default:
  235. case(blendmodeXOR):
  236. {
  237. BlendModeString = "blendmodeXOR";
  238. }
  239. break;
  240. }
  241. OutFile->WriteString(SectionName,ValueName,BlendModeString);
  242. delete OutFile;
  243. return 1;
  244. }
  245. //---------------------------------------------------------------------------
  246. int __stdcall LoadConfigFromFile(IzsMatrix *Matrix,unsigned int &RefreshTime,DWORD &Priority,_TCHAR *FileName)
  247. {
  248. if((Matrix == NULL) || (FileName == NULL))
  249. {
  250. return 0;
  251. }
  252. AnsiString SectionName;
  253. AnsiString ValueName;
  254. TMemIniFile *InFile = new TMemIniFile(ExpandFileName(AnsiString(FileName)));
  255. //TMemIniFile *InFile = new TMemIniFile(AnsiString(FileName));
  256. SectionName = "General";
  257. ValueName = "MaxStream";
  258. Matrix->SetMaxStream(InFile->ReadInteger(SectionName,ValueName,Matrix->GetMaxStream()));
  259. ValueName = "SpeedVariance";
  260. Matrix->SetSpeedVariance(InFile->ReadInteger(SectionName,ValueName,Matrix->GetSpeedVariance()));
  261. ValueName = "MonotonousCleanupEnabled";
  262. Matrix->SetMonotonousCleanupEnabled(InFile->ReadBool(SectionName,ValueName,Matrix->GetMonotonousCleanupEnabled()));
  263. ValueName = "BackTrace";
  264. Matrix->SetBackTrace(InFile->ReadInteger(SectionName,ValueName,Matrix->GetBackTrace()));
  265. ValueName = "RandomizedCleanupEnabled";
  266. Matrix->SetRandomizedCleanupEnabled(InFile->ReadBool(SectionName,ValueName,Matrix->GetRandomizedCleanupEnabled()));
  267. ValueName = "Leading";
  268. Matrix->SetLeading(InFile->ReadInteger(SectionName,ValueName,Matrix->GetLeading()));
  269. ValueName = "SpacePad";
  270. Matrix->SetSpacePad(InFile->ReadInteger(SectionName,ValueName,Matrix->GetSpacePad()));
  271. ValueName = "RefreshTime";
  272. RefreshTime = InFile->ReadInteger(SectionName,ValueName,RefreshTime);
  273. ValueName = "PriorityClass";
  274. AnsiString PriorityName = InFile->ReadString(SectionName,ValueName,"IDLE_PRIORITY_CLASS");
  275. if(PriorityName == "ABOVE_NORMAL_PRIORITY_CLASS")
  276. {
  277. Priority = ABOVE_NORMAL_PRIORITY_CLASS;
  278. }
  279. else if(PriorityName == "BELOW_NORMAL_PRIORITY_CLASS")
  280. {
  281. Priority = BELOW_NORMAL_PRIORITY_CLASS;
  282. }
  283. else if(PriorityName == "HIGH_PRIORITY_CLASS")
  284. {
  285. Priority = HIGH_PRIORITY_CLASS;
  286. }
  287. else if(PriorityName == "IDLE_PRIORITY_CLASS")
  288. {
  289. Priority = IDLE_PRIORITY_CLASS;
  290. }
  291. else if(PriorityName == "NORMAL_PRIORITY_CLASS")
  292. {
  293. Priority = NORMAL_PRIORITY_CLASS;
  294. }
  295. else
  296. {
  297. Priority = IDLE_PRIORITY_CLASS;
  298. }
  299. ValueName = "SpecialStringStreamProbability";
  300. Matrix->SetSpecialStringStreamProbability(InFile->ReadFloat(SectionName,ValueName,Matrix->GetSpecialStringStreamProbability()));
  301. SectionName = "Text";
  302. LOGFONT LogFont;
  303. ReadLogFontFromConfigFile(InFile,SectionName,LogFont);
  304. Matrix->SetLogFont(LogFont);
  305. ValueName = "CharSet";
  306. AnsiString CharSetInString = InFile->ReadString(SectionName,ValueName,"*");
  307. std::vector<_TCHAR> CharSet;
  308. ConvertAnsiStringToCharSet(CharSet,CharSetInString);
  309. if(CharSet.empty())
  310. {
  311. Matrix->ClearValidCharSet();
  312. }
  313. else
  314. {
  315. const _TCHAR *CharSetPointer = &(CharSet.front());
  316. unsigned int CharSetSize = CharSet.size();
  317. Matrix->SetValidCharSet(CharSetPointer,CharSetSize);
  318. }
  319. SectionName = "SpecialText";
  320. ReadLogFontFromConfigFile(InFile,SectionName,LogFont);
  321. Matrix->SetSpecialStringLogFont(LogFont);
  322. ValueName = "Strings";
  323. AnsiString SpecialStringsInString = InFile->ReadString(SectionName,ValueName,"The matrix has you");
  324. std::vector<tstring> SpecialStringVec;
  325. ConvertAnsiStringToSpecialStrings(SpecialStringVec,SpecialStringsInString,CONFIG_FILE_SPECIAL_STRING_DELIMITER);
  326. if(SpecialStringVec.empty())
  327. {
  328. Matrix->ClearValidSpecialStringSet();
  329. }
  330. else
  331. {
  332. unsigned int SpecialStringArraySize = SpecialStringVec.size();
  333. const _TCHAR * /*const*/ *SpecialStringArray = new const _TCHAR *[SpecialStringArraySize];
  334. for(unsigned int i = 0; i < SpecialStringArraySize; i++)
  335. {
  336. SpecialStringArray[i] = SpecialStringVec[i].c_str();
  337. }
  338. Matrix->SetValidSpecialStringSet(SpecialStringArray,SpecialStringArraySize);
  339. delete[] SpecialStringArray;
  340. }
  341. SectionName = "Colors";
  342. ValueName = "FGColor";
  343. int IntR = 150,IntG = 255,IntB = 100,IntA = 255;
  344. AnsiString ForegroundColorString = InFile->ReadString(SectionName,ValueName,"{150,255,100,255}");
  345. sscanf(ForegroundColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  346. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  347. Matrix->SetColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  348. ValueName = "FadeColor";
  349. IntR = 0,IntG = 0,IntB = 0,IntA = 0;
  350. AnsiString FadeColorString = InFile->ReadString(SectionName,ValueName,"{50,85,33,128}");
  351. sscanf(FadeColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  352. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  353. Matrix->SetFadeColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  354. ValueName = "BGColor";
  355. IntR = 0,IntG = 0,IntB = 0,IntA = 0;
  356. AnsiString BackgroundColorString = InFile->ReadString(SectionName,ValueName,"{0,0,0,0}");
  357. sscanf(BackgroundColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  358. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  359. Matrix->SetBGColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  360. ValueName = "SpecialStringFGColor";
  361. IntR = 150,IntG = 255,IntB = 100,IntA = 255;
  362. AnsiString SpecialStringForegroundColorString = InFile->ReadString(SectionName,ValueName,"{150,255,100,255}");
  363. sscanf(SpecialStringForegroundColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  364. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  365. Matrix->SetSpecialStringColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  366. ValueName = "SpecialStringFadeColor";
  367. IntR = 0,IntG = 0,IntB = 0,IntA = 0;
  368. AnsiString SpecialStringFadeColorString = InFile->ReadString(SectionName,ValueName,"{50,85,33,128}");
  369. sscanf(SpecialStringFadeColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  370. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  371. Matrix->SetSpecialStringFadeColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  372. ValueName = "SpecialStringBGColor";
  373. IntR = 0,IntG = 0,IntB = 0,IntA = 0;
  374. AnsiString SpecialStringBackgroundColorString = InFile->ReadString(SectionName,ValueName,"{0,0,0,0}");
  375. sscanf(SpecialStringBackgroundColorString.c_str(),"{%d,%d,%d,%d}",&IntR,&IntG,&IntB,&IntA);
  376. CLAMP(IntR,0,255);CLAMP(IntG,0,255);CLAMP(IntB,0,255);CLAMP(IntA,0,255);
  377. Matrix->SetSpecialStringBGColor((BYTE)IntR,(BYTE)IntG,(BYTE)IntB,(BYTE)IntA);
  378. ValueName = "BGMode";
  379. TBGMode BGMode;
  380. AnsiString BGModeString = InFile->ReadString(SectionName,ValueName,"bgmodeBitmap");
  381. if(BGModeString == "bgmodeColor")
  382. {
  383. BGMode = bgmodeColor;
  384. }
  385. else
  386. {
  387. BGMode = bgmodeBitmap;
  388. }
  389. Matrix->SetBGMode(BGMode);
  390. ValueName = "BlendMode";
  391. TBlendMode BlendMode;
  392. AnsiString BlendModeString = InFile->ReadString(SectionName,ValueName,"blendmodeXOR");
  393. if(BlendModeString == "blendmodeOR")
  394. {
  395. BlendMode = blendmodeOR;
  396. }
  397. else if(BlendModeString == "blendmodeAND")
  398. {
  399. BlendMode = blendmodeAND;
  400. }
  401. else
  402. {
  403. BlendMode = blendmodeXOR;
  404. }
  405. Matrix->SetBlendMode(BlendMode);
  406. delete InFile;
  407. return 1;
  408. }
  409. //---------------------------------------------------------------------------
  410. int WriteLogFontToConfigFile(TCustomIniFile *OutFile,const AnsiString SectionName,const LOGFONT &LogFont)
  411. {
  412. if(OutFile == NULL)
  413. {
  414. return 0;
  415. }
  416. AnsiString ValueName;
  417. ValueName = "FontHeight";
  418. OutFile->WriteInteger(SectionName,ValueName,LogFont.lfHeight);
  419. ValueName = "FontWidth";
  420. OutFile->WriteInteger(SectionName,ValueName,LogFont.lfWidth);
  421. ValueName = "FontEscapement";
  422. OutFile->WriteInteger(SectionName,ValueName,LogFont.lfEscapement);
  423. ValueName = "FontOrientation";
  424. OutFile->WriteInteger(SectionName,ValueName,LogFont.lfOrientation);
  425. ValueName = "FontWeight";
  426. OutFile->WriteInteger(SectionName,ValueName,LogFont.lfWeight);
  427. ValueName = "FontItalic";
  428. OutFile->WriteBool(SectionName,ValueName,(LogFont.lfItalic == TRUE));
  429. ValueName = "FontUnderline";
  430. OutFile->WriteBool(SectionName,ValueName,(LogFont.lfUnderline == TRUE));
  431. ValueName = "FontStrikeOut";
  432. OutFile->WriteBool(SectionName,ValueName,(LogFont.lfStrikeOut == TRUE));
  433. ValueName = "FontCharSet";
  434. AnsiString CharSetName;
  435. switch(LogFont.lfCharSet)
  436. {
  437. case(ANSI_CHARSET): CharSetName = "ANSI_CHARSET"; break;
  438. case(BALTIC_CHARSET): CharSetName = "BALTIC_CHARSET"; break;
  439. case(CHINESEBIG5_CHARSET): CharSetName = "CHINESEBIG5_CHARSET"; break;
  440. case(EASTEUROPE_CHARSET): CharSetName = "EASTEUROPE_CHARSET"; break;
  441. case(GB2312_CHARSET): CharSetName = "GB2312_CHARSET"; break;
  442. case(GREEK_CHARSET): CharSetName = "GREEK_CHARSET"; break;
  443. case(HANGUL_CHARSET): CharSetName = "HANGUL_CHARSET"; break;
  444. case(MAC_CHARSET): CharSetName = "MAC_CHARSET"; break;
  445. case(OEM_CHARSET): CharSetName = "OEM_CHARSET"; break;
  446. case(RUSSIAN_CHARSET): CharSetName = "RUSSIAN_CHARSET"; break;
  447. case(SHIFTJIS_CHARSET): CharSetName = "SHIFTJIS_CHARSET"; break;
  448. case(SYMBOL_CHARSET): CharSetName = "SYMBOL_CHARSET"; break;
  449. case(TURKISH_CHARSET): CharSetName = "TURKISH_CHARSET"; break;
  450. case(JOHAB_CHARSET): CharSetName = "JOHAB_CHARSET"; break;
  451. case(HEBREW_CHARSET): CharSetName = "HEBREW_CHARSET"; break;
  452. case(ARABIC_CHARSET): CharSetName = "ARABIC_CHARSET"; break;
  453. case(THAI_CHARSET): CharSetName = "THAI_CHARSET"; break;
  454. default: CharSetName = "DEFAULT_CHARSET"; break;
  455. }
  456. OutFile->WriteString(SectionName,ValueName,CharSetName);
  457. ValueName = "FontOutPrecision";
  458. AnsiString OutPrecisionName;
  459. switch(LogFont.lfOutPrecision)
  460. {
  461. case(OUT_DEVICE_PRECIS): OutPrecisionName = "OUT_DEVICE_PRECIS"; break;
  462. case(OUT_OUTLINE_PRECIS): OutPrecisionName = "OUT_OUTLINE_PRECIS"; break;
  463. case(OUT_RASTER_PRECIS): OutPrecisionName = "OUT_RASTER_PRECIS"; break;
  464. case(OUT_STRING_PRECIS): OutPrecisionName = "OUT_STRING_PRECIS"; break;
  465. case(OUT_STROKE_PRECIS): OutPrecisionName = "OUT_STROKE_PRECIS"; break;
  466. case(OUT_TT_ONLY_PRECIS): OutPrecisionName = "OUT_TT_ONLY_PRECIS"; break;
  467. case(OUT_TT_PRECIS): OutPrecisionName = "OUT_TT_PRECIS"; break;
  468. default: OutPrecisionName = "OUT_DEFAULT_PRECIS"; break;
  469. }
  470. OutFile->WriteString(SectionName,ValueName,OutPrecisionName);
  471. ValueName = "FontClipPrecision";
  472. AnsiString ClipPrecisionName;
  473. switch(LogFont.lfClipPrecision)
  474. {
  475. case(CLIP_STROKE_PRECIS): ClipPrecisionName = "CLIP_STROKE_PRECIS"; break;
  476. case(CLIP_EMBEDDED): ClipPrecisionName = "CLIP_EMBEDDED"; break;
  477. case(CLIP_LH_ANGLES): ClipPrecisionName = "CLIP_LH_ANGLES"; break;
  478. default: ClipPrecisionName = "CLIP_DEFAULT_PRECIS"; break;
  479. }
  480. OutFile->WriteString(SectionName,ValueName,ClipPrecisionName);
  481. ValueName = "FontQuality";
  482. AnsiString QualityName;
  483. switch(LogFont.lfQuality)
  484. {
  485. case(DRAFT_QUALITY): QualityName = "DRAFT_QUALITY"; break;
  486. case(PROOF_QUALITY): QualityName = "PROOF_QUALITY"; break;
  487. default: QualityName = "DEFAULT_QUALITY"; break;
  488. }
  489. OutFile->WriteString(SectionName,ValueName,QualityName);
  490. ValueName = "FontPitch";
  491. AnsiString PitchName;
  492. if(LogFont.lfPitchAndFamily & FIXED_PITCH)
  493. {
  494. PitchName = "FIXED_PITCH";
  495. }
  496. else if(LogFont.lfPitchAndFamily & VARIABLE_PITCH)
  497. {
  498. PitchName = "VARIABLE_PITCH";
  499. }
  500. else
  501. {
  502. PitchName = "DEFAULT_PITCH";
  503. }
  504. OutFile->WriteString(SectionName,ValueName,PitchName);
  505. ValueName = "FontFamily";
  506. AnsiString FamilyName;
  507. if(LogFont.lfPitchAndFamily & FF_DECORATIVE)
  508. {
  509. FamilyName = "FF_DECORATIVE";
  510. }
  511. else if(LogFont.lfPitchAndFamily & FF_MODERN)
  512. {
  513. FamilyName = "FF_MODERN";
  514. }
  515. else if(LogFont.lfPitchAndFamily & FF_ROMAN)
  516. {
  517. FamilyName = "FF_ROMAN";
  518. }
  519. else if(LogFont.lfPitchAndFamily & FF_SCRIPT)
  520. {
  521. FamilyName = "FF_SCRIPT";
  522. }
  523. else if(LogFont.lfPitchAndFamily & FF_SWISS)
  524. {
  525. FamilyName = "FF_SWISS";
  526. }
  527. else
  528. {
  529. FamilyName = "FF_DONTCARE";
  530. }
  531. OutFile->WriteString(SectionName,ValueName,FamilyName);
  532. ValueName = "FontName";
  533. OutFile->WriteString(SectionName,ValueName,AnsiString(LogFont.lfFaceName));
  534. return 1;
  535. }
  536. //---------------------------------------------------------------------------
  537. int ReadLogFontFromConfigFile(TCustomIniFile *InFile,const AnsiString SectionName,LOGFONT &LogFont)
  538. {
  539. if(InFile == NULL)
  540. {
  541. return 0;
  542. }
  543. AnsiString ValueName;
  544. LogFont.lfHeight = 12;
  545. LogFont.lfWidth = 0;
  546. LogFont.lfEscapement = 0;
  547. LogFont.lfOrientation = 0;
  548. LogFont.lfWeight = 400;
  549. LogFont.lfItalic = FALSE;
  550. LogFont.lfUnderline = FALSE;
  551. LogFont.lfStrikeOut = FALSE;
  552. ValueName = "FontHeight";
  553. LogFont.lfHeight = InFile->ReadInteger(SectionName,ValueName,LogFont.lfHeight);
  554. ValueName = "FontWidth";
  555. LogFont.lfWidth = InFile->ReadInteger(SectionName,ValueName,LogFont.lfWidth);
  556. ValueName = "FontEscapement";
  557. LogFont.lfEscapement = InFile->ReadInteger(SectionName,ValueName,LogFont.lfEscapement);
  558. ValueName = "FontOrientation";
  559. LogFont.lfOrientation = InFile->ReadInteger(SectionName,ValueName,LogFont.lfOrientation);
  560. ValueName = "FontWeight";
  561. LogFont.lfWeight = InFile->ReadInteger(SectionName,ValueName,LogFont.lfWeight);
  562. ValueName = "FontItalic";
  563. LogFont.lfItalic = InFile->ReadBool(SectionName,ValueName,(LogFont.lfItalic == TRUE));
  564. ValueName = "FontUnderline";
  565. LogFont.lfUnderline = InFile->ReadBool(SectionName,ValueName,(LogFont.lfUnderline == TRUE));
  566. ValueName = "FontStrikeOut";
  567. LogFont.lfStrikeOut = InFile->ReadBool(SectionName,ValueName,(LogFont.lfStrikeOut == TRUE));
  568. ValueName = "FontCharSet";
  569. AnsiString CharSetName = InFile->ReadString(SectionName,ValueName,"DEFAULT_CHARSET");
  570. if(CharSetName == "ANSI_CHARSET")
  571. {
  572. LogFont.lfCharSet = ANSI_CHARSET;
  573. }
  574. else if(CharSetName == "BALTIC_CHARSET")
  575. {
  576. LogFont.lfCharSet = BALTIC_CHARSET;
  577. }
  578. else if(CharSetName == "CHINESEBIG5_CHARSET")
  579. {
  580. LogFont.lfCharSet = CHINESEBIG5_CHARSET;
  581. }
  582. else if(CharSetName == "EASTEUROPE_CHARSET")
  583. {
  584. LogFont.lfCharSet = EASTEUROPE_CHARSET;
  585. }
  586. else if(CharSetName == "GB2312_CHARSET")
  587. {
  588. LogFont.lfCharSet = GB2312_CHARSET;
  589. }
  590. else if(CharSetName == "GREEK_CHARSET")
  591. {
  592. LogFont.lfCharSet = GREEK_CHARSET;
  593. }
  594. else if(CharSetName == "HANGUL_CHARSET")
  595. {
  596. LogFont.lfCharSet = HANGUL_CHARSET;
  597. }
  598. else if(CharSetName == "MAC_CHARSET")
  599. {
  600. LogFont.lfCharSet = MAC_CHARSET;
  601. }
  602. else if(CharSetName == "OEM_CHARSET")
  603. {
  604. LogFont.lfCharSet = OEM_CHARSET;
  605. }
  606. else if(CharSetName == "RUSSIAN_CHARSET")
  607. {
  608. LogFont.lfCharSet = RUSSIAN_CHARSET;
  609. }
  610. else if(CharSetName == "SHIFTJIS_CHARSET")
  611. {
  612. LogFont.lfCharSet = SHIFTJIS_CHARSET;
  613. }
  614. else if(CharSetName == "SYMBOL_CHARSET")
  615. {
  616. LogFont.lfCharSet = SYMBOL_CHARSET;
  617. }
  618. else if(CharSetName == "TURKISH_CHARSET")
  619. {
  620. LogFont.lfCharSet = TURKISH_CHARSET;
  621. }
  622. else if(CharSetName == "JOHAB_CHARSET")
  623. {
  624. LogFont.lfCharSet = JOHAB_CHARSET;
  625. }
  626. else if(CharSetName == "HEBREW_CHARSET")
  627. {
  628. LogFont.lfCharSet = HEBREW_CHARSET;
  629. }
  630. else if(CharSetName == "ARABIC_CHARSET")
  631. {
  632. LogFont.lfCharSet = ARABIC_CHARSET;
  633. }
  634. else if(CharSetName == "THAI_CHARSET")
  635. {
  636. LogFont.lfCharSet = THAI_CHARSET;
  637. }
  638. else
  639. {
  640. LogFont.lfCharSet = DEFAULT_CHARSET;
  641. }
  642. ValueName = "FontOutPrecision";
  643. AnsiString OutPrecisionName = InFile->ReadString(SectionName,ValueName,"OUT_DEFAULT_PRECIS");
  644. if(OutPrecisionName == "OUT_DEVICE_PRECIS")
  645. {
  646. LogFont.lfOutPrecision = OUT_DEVICE_PRECIS;
  647. }
  648. else if(OutPrecisionName == "OUT_OUTLINE_PRECIS")
  649. {
  650. LogFont.lfOutPrecision = OUT_OUTLINE_PRECIS;
  651. }
  652. else if(OutPrecisionName == "OUT_RASTER_PRECIS")
  653. {
  654. LogFont.lfOutPrecision = OUT_RASTER_PRECIS;
  655. }
  656. else if(OutPrecisionName == "OUT_STRING_PRECIS")
  657. {
  658. LogFont.lfOutPrecision = OUT_STRING_PRECIS;
  659. }
  660. else if(OutPrecisionName == "OUT_STROKE_PRECIS")
  661. {
  662. LogFont.lfOutPrecision = OUT_STROKE_PRECIS;
  663. }
  664. else if(OutPrecisionName == "OUT_TT_ONLY_PRECIS")
  665. {
  666. LogFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  667. }
  668. else if(OutPrecisionName == "OUT_TT_PRECIS")
  669. {
  670. LogFont.lfOutPrecision = OUT_TT_PRECIS;
  671. }
  672. else
  673. {
  674. LogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
  675. }
  676. ValueName = "FontClipPrecision";
  677. AnsiString ClipPrecisionName = InFile->ReadString(SectionName,ValueName,"CLIP_DEFAULT_PRECIS");
  678. if(ClipPrecisionName == "CLIP_STROKE_PRECIS")
  679. {
  680. LogFont.lfClipPrecision = CLIP_STROKE_PRECIS;
  681. }
  682. else if(ClipPrecisionName == "CLIP_EMBEDDED")
  683. {
  684. LogFont.lfClipPrecision = CLIP_EMBEDDED;
  685. }
  686. else if(ClipPrecisionName == "CLIP_LH_ANGLES")
  687. {
  688. LogFont.lfClipPrecision = CLIP_LH_ANGLES;
  689. }
  690. else
  691. {
  692. LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  693. }
  694. ValueName = "FontQuality";
  695. AnsiString QualityName = InFile->ReadString(SectionName,ValueName,"DEFAULT_QUALITY");
  696. if(QualityName == "DRAFT_QUALITY")
  697. {
  698. LogFont.lfQuality = DRAFT_QUALITY;
  699. }
  700. else if(QualityName == "PROOF_QUALITY")
  701. {
  702. LogFont.lfQuality = PROOF_QUALITY;
  703. }
  704. else
  705. {
  706. LogFont.lfQuality = DEFAULT_QUALITY;
  707. }
  708. ValueName = "FontPitch";
  709. AnsiString PitchName = InFile->ReadString(SectionName,ValueName,"DEFAULT_PITCH");
  710. if(PitchName == "FIXED_PITCH")
  711. {
  712. LogFont.lfPitchAndFamily = FIXED_PITCH;
  713. }
  714. else if (PitchName == "VARIABLE_PITCH")
  715. {
  716. LogFont.lfPitchAndFamily = VARIABLE_PITCH;
  717. }
  718. else
  719. {
  720. LogFont.lfPitchAndFamily = DEFAULT_PITCH;
  721. }
  722. ValueName = "FontFamily";
  723. AnsiString FamilyName = InFile->ReadString(SectionName,ValueName,"FF_DONTCARE");
  724. if(FamilyName == "FF_DECORATIVE")
  725. {
  726. LogFont.lfPitchAndFamily |= FF_DECORATIVE;
  727. }
  728. else if(FamilyName == "FF_MODERN")
  729. {
  730. LogFont.lfPitchAndFamily |= FF_MODERN;
  731. }
  732. else if(FamilyName == "FF_ROMAN")
  733. {
  734. LogFont.lfPitchAndFamily |= FF_ROMAN;
  735. }
  736. else if(FamilyName == "FF_SCRIPT")
  737. {
  738. LogFont.lfPitchAndFamily |= FF_SCRIPT;
  739. }
  740. else if(FamilyName == "FF_SWISS")
  741. {
  742. LogFont.lfPitchAndFamily |= FF_SWISS;
  743. }
  744. else
  745. {
  746. LogFont.lfPitchAndFamily |= FF_DONTCARE;
  747. }
  748. ValueName = "FontName";
  749. AnsiString FontNameString = InFile->ReadString(SectionName,ValueName,"Terminal");
  750. #ifdef _UNICODE
  751. snwprintf(LogFont.lfFaceName,LF_FACESIZE - 1,_TEXT("%S"),FontNameString.c_str());
  752. #else
  753. snprintf(LogFont.lfFaceName,LF_FACESIZE - 1,"%s",FontNameString.c_str());
  754. #endif
  755. LogFont.lfFaceName[LF_FACESIZE - 1] = (_TCHAR)'\0';
  756. return 1;
  757. }
  758. //---------------------------------------------------------------------------
  759. int ConvertCharSetToAnsiString(const _TCHAR *CharSet,const unsigned int &CharSetSize,AnsiString &OutString)
  760. {
  761. OutString.SetLength(0);
  762. static char HexBuff[16];
  763. unsigned int i;
  764. bool NeedsTrailingCleanup = false;
  765. for(i = 0; i < CharSetSize; i++)
  766. {
  767. if((CharSet[i] == '\t') || (CharSet[i] == ' ') || (CharSet[i] == '\r') ||
  768. (CharSet[i] == '\f') || (CharSet[i] == '\n') || (CharSet[i] == '\0')
  769. )
  770. {
  771. }
  772. else if(CharSet[i] == ',')
  773. {
  774. OutString+= AnsiString("\\,, ");
  775. NeedsTrailingCleanup = true;
  776. }
  777. else if(CharSet[i] == '\\')
  778. {
  779. OutString+= AnsiString("\\\\, ");
  780. NeedsTrailingCleanup = true;
  781. }
  782. else if(CharSet[i] < 256)
  783. {
  784. if(_istprint(CharSet[i]))
  785. {
  786. OutString+= AnsiString((char)CharSet[i]) + AnsiString(", ");
  787. NeedsTrailingCleanup = true;
  788. }
  789. }
  790. else
  791. {
  792. if(_istprint(CharSet[i]))
  793. {
  794. sprintf(HexBuff,"\\0x%X, ",(unsigned int)CharSet[i]);
  795. OutString+= AnsiString(HexBuff);
  796. NeedsTrailingCleanup = true;
  797. }
  798. }
  799. }
  800. if(NeedsTrailingCleanup)
  801. {
  802. int DeleteStartIndex = OutString.Length() + 1;
  803. while((DeleteStartIndex > 1) &&
  804. ((OutString[DeleteStartIndex - 1] == ' ') || (OutString[DeleteStartIndex - 1] == ',')))
  805. {
  806. DeleteStartIndex--;
  807. }
  808. OutString.Delete(DeleteStartIndex,OutString.Length());
  809. }
  810. return 1;
  811. }
  812. //---------------------------------------------------------------------------
  813. int ConvertCharSetToWideString(const _TCHAR *CharSet,const unsigned int &CharSetSize,WideString &OutString)
  814. {
  815. OutString.SetLength(0);
  816. unsigned int i;
  817. bool NeedsTrailingCleanup = false;
  818. for(i = 0; i < CharSetSize; i++)
  819. {
  820. if((CharSet[i] == '\t') || (CharSet[i] == ' ') || (CharSet[i] == '\r') ||
  821. (CharSet[i] == '\f') || (CharSet[i] == '\n') || (CharSet[i] == '\0')
  822. )
  823. {
  824. }
  825. else if(CharSet[i] == ',')
  826. {
  827. OutString+= WideString("\\,, ");
  828. NeedsTrailingCleanup = true;
  829. }
  830. else if(CharSet[i] == '\\')
  831. {
  832. OutString+= WideString("\\\\, ");
  833. NeedsTrailingCleanup = true;
  834. }
  835. else
  836. {
  837. if(_istprint(CharSet[i]))
  838. {
  839. OutString+= WideString((wchar_t)CharSet[i]) + WideString(", ");
  840. NeedsTrailingCleanup = true;
  841. }
  842. }
  843. }
  844. if(NeedsTrailingCleanup)
  845. {
  846. int DeleteStartIndex = OutString.Length() + 1;
  847. while((DeleteStartIndex > 1) &&
  848. ((OutString[DeleteStartIndex - 1] == ' ') || (OutString[DeleteStartIndex - 1] == ',')))
  849. {
  850. DeleteStartIndex--;
  851. }
  852. OutString.Delete(DeleteStartIndex,OutString.Length());
  853. }
  854. return 1;
  855. }
  856. //---------------------------------------------------------------------------
  857. int ConvertAnsiStringToCharSet(std::vector<_TCHAR> &CharSet,const AnsiString &InString)
  858. {
  859. int i = 0;
  860. int j;
  861. char TempBuff[16];
  862. char TempChar;
  863. int TextLength = InString.Length();
  864. int TempInt;
  865. CharSet.clear();
  866. char *MemoCString = InString.c_str();
  867. if(MemoCString == NULL)
  868. {
  869. return 1;
  870. }
  871. while(MemoCString[i] != '\0')
  872. {
  873. TempChar = MemoCString[i];
  874. if((TempChar == ' ') || (TempChar == '\t') || (TempChar == '\n') ||
  875. (TempChar == ',') || (TempChar == '\r') || (TempChar == '\f') )
  876. {
  877. i++;
  878. }
  879. else if(TempChar == '\\')
  880. {
  881. //if at least 3 more chars after the backslash, and the two immediately following are 0 and x (any case)
  882. if((TextLength > (i + 3)) && (MemoCString[i+1] == '0') &&
  883. ((MemoCString[i+2] == 'x') || (MemoCString[i+2] == 'X'))
  884. )
  885. {
  886. //officially over \0x , so we can update i
  887. i+=3;
  888. j = 0;
  889. while((j < 4) && (MemoCString[i+j] != ' ') &&
  890. (MemoCString[i+j] != '\t') &&
  891. (MemoCString[i+j] != '\r') &&
  892. (MemoCString[i+j] != '\f') &&
  893. (MemoCString[i+j] != '\n') &&
  894. (MemoCString[i+j] != ',') &&
  895. ( ((MemoCString[i+j] >= '0') && (MemoCString[i+j] <= '9')) ||
  896. ((MemoCString[i+j] >= 'A') && (MemoCString[i+j] <= 'F')) ||
  897. ((MemoCString[i+j] >= 'a') && (MemoCString[i+j] <= 'f'))
  898. )
  899. )
  900. {
  901. TempBuff[j] = MemoCString[i+j];
  902. j++;
  903. }
  904. TempBuff[j] = '\0';
  905. i+= j;
  906. if(sscanf(TempBuff,"%x",&TempInt))
  907. {
  908. if(_istprint((_TCHAR)TempInt))
  909. {
  910. CharSet.push_back((_TCHAR)TempInt);
  911. }
  912. }
  913. }
  914. //if at least 1 more char after the backslash, and the immediately following is backslash
  915. else if((TextLength > (i + 1)) && (MemoCString[i+1] == '\\'))
  916. {
  917. CharSet.push_back(_TEXT('\\'));
  918. i+=2;
  919. }
  920. //if at least 1 more char after the backslash, and the immediately following is comma
  921. else if((TextLength > (i + 1)) && (MemoCString[i+1] == ','))
  922. {
  923. CharSet.push_back(_TEXT(','));
  924. i+=2;
  925. }
  926. else
  927. {
  928. i++;
  929. }
  930. }
  931. else
  932. {
  933. if(_istprint((_TCHAR)TempChar))
  934. {
  935. CharSet.push_back((_TCHAR)TempChar);
  936. }
  937. i++;
  938. }
  939. }
  940. return CharSet.size();
  941. }
  942. //---------------------------------------------------------------------------
  943. int ConvertWideStringToCharSet(std::vector<_TCHAR> &CharSet,const WideString &InString)
  944. {
  945. int i = 0;
  946. int j;
  947. wchar_t TempBuff[16];
  948. wchar_t TempChar;
  949. int TextLength = InString.Length();
  950. int TempInt;
  951. CharSet.clear();
  952. BSTR MemoCString = InString.c_bstr();
  953. if(MemoCString == NULL)
  954. {
  955. return 1;
  956. }
  957. while(MemoCString[i] != '\0')
  958. {
  959. TempChar = MemoCString[i];
  960. if((TempChar == ' ') || (TempChar == '\t') || (TempChar == '\n') ||
  961. (TempChar == ',') || (TempChar == '\r') || (TempChar == '\f') )
  962. {
  963. i++;
  964. }
  965. else if(TempChar == '\\')
  966. {
  967. //if at least 3 more chars after the backslash, and the two immediately following are 0 and x (any case)
  968. if((TextLength > (i + 3)) && (MemoCString[i+1] == '0') &&
  969. ((MemoCString[i+2] == 'x') || (MemoCString[i+2] == 'X'))
  970. )
  971. {
  972. //officially over \0x , so we can update i
  973. i+=3;
  974. j = 0;
  975. while((j < 4) && (MemoCString[i+j] != ' ') &&
  976. (MemoCString[i+j] != '\t') &&
  977. (MemoCString[i+j] != '\r') &&
  978. (MemoCString[i+j] != '\f') &&
  979. (MemoCString[i+j] != '\n') &&
  980. (MemoCString[i+j] != ',') &&
  981. ( ((MemoCString[i+j] >= '0') && (MemoCString[i+j] <= '9')) ||
  982. ((MemoCString[i+j] >= 'A') && (MemoCString[i+j] <= 'F')) ||
  983. ((MemoCString[i+j] >= 'a') && (MemoCString[i+j] <= 'f'))
  984. )
  985. )
  986. {
  987. TempBuff[j] = MemoCString[i+j];
  988. j++;
  989. }
  990. TempBuff[j] = '\0';
  991. i+= j;
  992. if(swscanf(TempBuff,L"%x",&TempInt))
  993. {
  994. if(_istprint((_TCHAR)TempInt))
  995. {
  996. CharSet.push_back((_TCHAR)TempInt);
  997. }
  998. }
  999. }
  1000. //if at least 1 more char after the backslash, and the immediately following is backslash
  1001. else if((TextLength > (i + 1)) && (MemoCString[i+1] == '\\'))
  1002. {
  1003. CharSet.push_back(_TEXT('\\'));
  1004. i+=2;
  1005. }
  1006. //if at least 1 more char after the backslash, and the immediately following is comma
  1007. else if((TextLength > (i + 1)) && (MemoCString[i+1] == ','))
  1008. {
  1009. CharSet.push_back(_TEXT(','));
  1010. i+=2;
  1011. }
  1012. else
  1013. {
  1014. i++;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. if(_istprint((_TCHAR)TempChar))
  1020. {
  1021. CharSet.push_back((_TCHAR)TempChar);
  1022. }
  1023. i++;
  1024. }
  1025. }
  1026. return CharSet.size();
  1027. }
  1028. //---------------------------------------------------------------------------
  1029. int ConvertSpecialStringsToAnsiString(const std::vector<tstring> &SpecialStrings,AnsiString &OutString, _TCHAR Delimiter)
  1030. {
  1031. OutString.SetLength(0);
  1032. static char HexBuff[16];
  1033. unsigned int i, j;
  1034. AnsiString DelimiterReplacement;
  1035. if(Delimiter == '\n')
  1036. {
  1037. DelimiterReplacement = "\\n";
  1038. }
  1039. else
  1040. {
  1041. DelimiterReplacement = "\\";
  1042. DelimiterReplacement += (char)Delimiter;
  1043. }
  1044. for(i = 0; i < SpecialStrings.size(); i++)
  1045. {
  1046. for(j = 0; j < SpecialStrings[i].length(); j++)
  1047. {
  1048. _TCHAR CurrentChar = SpecialStrings[i][j];
  1049. if((CurrentChar == '\0')
  1050. )
  1051. {
  1052. }
  1053. else if(CurrentChar == Delimiter)
  1054. {
  1055. OutString+= DelimiterReplacement;
  1056. }
  1057. else if(CurrentChar == '\\')
  1058. {
  1059. OutString+= AnsiString("\\\\");
  1060. }
  1061. else if(CurrentChar < 256)
  1062. {
  1063. if(_istprint(CurrentChar))
  1064. {
  1065. OutString+= AnsiString((char)CurrentChar);
  1066. }
  1067. }
  1068. else
  1069. {
  1070. if(_istprint(CurrentChar))
  1071. {
  1072. sprintf(HexBuff,"\\0x%X",(unsigned int)CurrentChar);
  1073. OutString+= AnsiString(HexBuff);
  1074. }
  1075. }
  1076. }
  1077. if(i < (SpecialStrings.size() - 1))
  1078. {
  1079. OutString+= (char)Delimiter;
  1080. }
  1081. }
  1082. return 1;
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. int ConvertSpecialStringsToWideString(const std::vector<tstring> &SpecialStrings,WideString &OutString, _TCHAR Delimiter)
  1086. {
  1087. OutString.SetLength(0);
  1088. unsigned int i, j;
  1089. AnsiString DelimiterReplacement;
  1090. if(Delimiter == '\n')
  1091. {
  1092. DelimiterReplacement = "\\n";
  1093. }
  1094. else
  1095. {
  1096. DelimiterReplacement = "\\";
  1097. DelimiterReplacement += Delimiter;
  1098. }
  1099. for(i = 0; i < SpecialStrings.size(); i++)
  1100. {
  1101. for(j = 0; j < SpecialStrings[i].length(); j++)
  1102. {
  1103. _TCHAR CurrentChar = SpecialStrings[i][j];
  1104. if((CurrentChar == '\0')
  1105. )
  1106. {
  1107. }
  1108. else if(CurrentChar == Delimiter)
  1109. {
  1110. OutString+= DelimiterReplacement;
  1111. }
  1112. else if(CurrentChar == '\\')
  1113. {
  1114. OutString+= AnsiString("\\\\");
  1115. }
  1116. else
  1117. {
  1118. if(_istprint(CurrentChar))
  1119. {
  1120. OutString+= AnsiString((char)CurrentChar);
  1121. }
  1122. }
  1123. }
  1124. if(i < (SpecialStrings.size() - 1))
  1125. {
  1126. OutString+= WideString(Delimiter);
  1127. }
  1128. }
  1129. return 1;
  1130. }
  1131. //---------------------------------------------------------------------------
  1132. int ConvertAnsiStringToSpecialStrings(std::vector<tstring> &SpecialStrings,const AnsiString &InString, _TCHAR Delimiter)
  1133. {
  1134. int i = 0;
  1135. int j;
  1136. char TempBuff[16];
  1137. char TempChar;
  1138. int TextLength = InString.Length();
  1139. int TempInt;
  1140. SpecialStrings.clear();
  1141. tstring CurrentString;
  1142. char *MemoCString = InString.c_str();
  1143. if(MemoCString == NULL)
  1144. {
  1145. return 1;
  1146. }
  1147. while(MemoCString[i] != '\0')
  1148. {
  1149. TempChar = MemoCString[i];
  1150. if(TempChar == Delimiter)
  1151. {
  1152. if(CurrentString.length() > 0)
  1153. {
  1154. SpecialStrings.push_back(CurrentString);
  1155. CurrentString.resize(0);
  1156. }
  1157. i++;
  1158. }
  1159. else if(TempChar == '\\')
  1160. {
  1161. if((TextLength > (i + 1)) && (MemoCString[i+1] == Delimiter))
  1162. {
  1163. CurrentString.append(1,(_TCHAR)MemoCString[i+1]);
  1164. i+=2;
  1165. }
  1166. //if at least 3 more chars after the backslash, and the two immediately following are 0 and x (any case)
  1167. else
  1168. if((TextLength > (i + 3)) && (MemoCString[i+1] == '0') &&
  1169. ((MemoCString[i+2] == 'x') || (MemoCString[i+2] == 'X'))
  1170. )
  1171. {
  1172. //officially over \0x , so we can update i
  1173. i+=3;
  1174. j = 0;
  1175. while((j < 4) && (MemoCString[i+j] != Delimiter) &&
  1176. ( ((MemoCString[i+j] >= '0') && (MemoCString[i+j] <= '9')) ||
  1177. ((MemoCString[i+j] >= 'A') && (MemoCString[i+j] <= 'F')) ||
  1178. ((MemoCString[i+j] >= 'a') && (MemoCString[i+j] <= 'f'))
  1179. )
  1180. )
  1181. {
  1182. TempBuff[j] = MemoCString[i+j];
  1183. j++;
  1184. }
  1185. TempBuff[j] = '\0';
  1186. i+= j;
  1187. if(sscanf(TempBuff,"%x",&TempInt))
  1188. {
  1189. if(((_TCHAR)TempInt) == Delimiter)
  1190. {
  1191. if(CurrentString.length() > 0)
  1192. {
  1193. SpecialStrings.push_back(CurrentString);
  1194. CurrentString.resize(0);
  1195. }
  1196. }
  1197. else if(_istprint((_TCHAR)TempInt))
  1198. {
  1199. CurrentString.append(1,(_TCHAR)TempInt);
  1200. }
  1201. }
  1202. }
  1203. else
  1204. {
  1205. i++;
  1206. }
  1207. }
  1208. else
  1209. {
  1210. if(_istprint((_TCHAR)TempChar))
  1211. {
  1212. CurrentString.append(1,(_TCHAR)TempChar);
  1213. }
  1214. i++;
  1215. }
  1216. }
  1217. if(CurrentString.length() > 0)
  1218. {
  1219. SpecialStrings.push_back(CurrentString);
  1220. CurrentString.resize(0);
  1221. }
  1222. return 1;
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. int ConvertWideStringToSpecialStrings(std::vector<tstring> &SpecialStrings,const WideString &InString, _TCHAR Delimiter)
  1226. {
  1227. int i = 0;
  1228. int j;
  1229. wchar_t TempBuff[16];
  1230. wchar_t TempChar;
  1231. int TextLength = InString.Length();
  1232. int TempInt;
  1233. SpecialStrings.clear();
  1234. tstring CurrentString;
  1235. BSTR MemoCString = InString.c_bstr();
  1236. if(MemoCString == NULL)
  1237. {
  1238. return 1;
  1239. }
  1240. while(MemoCString[i] != '\0')
  1241. {
  1242. TempChar = MemoCString[i];
  1243. if(TempChar == Delimiter)
  1244. {
  1245. if(CurrentString.length() > 0)
  1246. {
  1247. SpecialStrings.push_back(CurrentString);
  1248. CurrentString.resize(0);
  1249. }
  1250. i++;
  1251. }
  1252. else if(TempChar == '\\')
  1253. {
  1254. if((TextLength > (i + 1)) && (MemoCString[i+1] == Delimiter))
  1255. {
  1256. CurrentString.append(1,(_TCHAR)MemoCString[i+1]);
  1257. i+=2;
  1258. }
  1259. //if at least 3 more chars after the backslash, and the two immediately following are 0 and x (any case)
  1260. else
  1261. if((TextLength > (i + 3)) && (MemoCString[i+1] == '0') &&
  1262. ((MemoCString[i+2] == 'x') || (MemoCString[i+2] == 'X'))
  1263. )
  1264. {
  1265. //officially over \0x , so we can update i
  1266. i+=3;
  1267. j = 0;
  1268. while((j < 4) && (MemoCString[i+j] != Delimiter) &&
  1269. ( ((MemoCString[i+j] >= '0') && (MemoCString[i+j] <= '9')) ||
  1270. ((MemoCString[i+j] >= 'A') && (MemoCString[i+j] <= 'F')) ||
  1271. ((MemoCString[i+j] >= 'a') && (MemoCString[i+j] <= 'f'))
  1272. )
  1273. )
  1274. {
  1275. TempBuff[j] = MemoCString[i+j];
  1276. j++;
  1277. }
  1278. TempBuff[j] = '\0';
  1279. i+= j;
  1280. if(swscanf(TempBuff,L"%x",&TempInt))
  1281. {
  1282. if(((_TCHAR)TempInt) == Delimiter)
  1283. {
  1284. if(CurrentString.length() > 0)
  1285. {
  1286. SpecialStrings.push_back(CurrentString);
  1287. CurrentString.resize(0);
  1288. }
  1289. }
  1290. else if(_istprint((_TCHAR)TempInt))
  1291. {
  1292. CurrentString.append(1,(_TCHAR)TempInt);
  1293. }
  1294. }
  1295. }
  1296. else
  1297. {
  1298. i++;
  1299. }
  1300. }
  1301. else
  1302. {
  1303. if(_istprint((_TCHAR)TempChar))
  1304. {
  1305. CurrentString.append(1,(_TCHAR)TempChar);
  1306. }
  1307. i++;
  1308. }
  1309. }
  1310. if(CurrentString.length() > 0)
  1311. {
  1312. SpecialStrings.push_back(CurrentString);
  1313. CurrentString.resize(0);
  1314. }
  1315. return 1;
  1316. }
  1317. //---------------------------------------------------------------------------
  1318. void TConfigurationForm::SetFormMaxStream(int NewFormMaxStream)
  1319. {
  1320. CLAMP(NewFormMaxStream,this->MaxStreamTrackBar->Min,this->MaxStreamTrackBar->Max);
  1321. this->MaxStreamTrackBar->Position = NewFormMaxStream;
  1322. this->MaxStreamWidgetUpDown->Position = NewFormMaxStream;
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void TConfigurationForm::SetFormSpeedVariance(int NewFormSpeedVariance)
  1326. {
  1327. CLAMP(NewFormSpeedVariance,this->SpeedVarianceTrackBar->Min,this->SpeedVarianceTrackBar->Max);
  1328. this->SpeedVarianceTrackBar->Position = NewFormSpeedVariance;
  1329. this->SpeedVarianceWidgetUpDown->Position = NewFormSpeedVariance;
  1330. }
  1331. //---------------------------------------------------------------------------
  1332. void TConfigurationForm::SetFormMonotonousCleanupEnabled(bool Enabled)
  1333. {
  1334. this->MonotonousCleanupEnabledCheckBox->Checked = Enabled;
  1335. if(Enabled)
  1336. {
  1337. this->EnableBackTraceConfig();
  1338. }
  1339. else
  1340. {
  1341. this->DisableBackTraceConfig();
  1342. }
  1343. }
  1344. //---------------------------------------------------------------------------
  1345. void TConfigurationForm::SetFormBackTrace(int NewFormBackTrace)
  1346. {
  1347. CLAMP(NewFormBackTrace,this->BackTraceTrackBar->Min,this->BackTraceTrackBar->Max);
  1348. this->BackTraceTrackBar->Position = NewFormBackTrace;
  1349. this->BackTraceWidgetUpDown->Position = NewFormBackTrace;
  1350. }
  1351. //---------------------------------------------------------------------------
  1352. void TConfigurationForm::SetFormRandomizedCleanupEnabled(bool Enabled)
  1353. {
  1354. this->RandomizedCleanupEnabledCheck

Large files files are truncated, but you can click here to view the full file