PageRenderTime 6ms CodeModel.GetById 81ms app.highlight 182ms RepoModel.GetById 39ms 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//---------------------------------------------------------------------------
  32#define NO_WIN32_LEAN_AND_MEAN

  33#include <vcl.h>

  34#pragma hdrstop

  35#include <tchar.h>

  36#include <SysUtils.hpp>

  37#include <stdio.h>

  38#include <htmlhelp.h>

  39
  40#include "ConfigForm.h"

  41#include "AboutUnit.h"

  42#include "HireUnit.h"

  43
  44
  45//---------------------------------------------------------------------------
  46#pragma package(smart_init)

  47#pragma resource "*.dfm"

  48TConfigurationForm *ConfigurationForm = NULL;
  49
  50#ifndef min

  51#define min(a,b) (a)<(b)? (a):(b)

  52#endif

  53
  54#ifndef CLAMP

  55#define CLAMP(var,min,max)\

  56if((var) > (max)) (var) = (max);\
  57if((var) < (min)) (var) = (min);
  58#endif

  59
  60#define LONG_MAX_PATH 2048

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

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