//---------------------------------------------------------------------------
void __fastcall LoadFormPos(TForm *Form,
                            const AnsiString IniFileName,
                            const AnsiString SectionName,
                            const AnsiString KeyName)
{
    TIniFile   *IniFile;
    AnsiString sWindowPositions;

    if (IniFileName.Length() == 0)
        return;

    // Create inifile object => Open ini file
    IniFile = new TIniFile(IniFileName);

    // Formatage par défaut de la ligne de la section window
    sWindowPositions.SetLength(256);
    WindowPosToStr(sWindowPositions.c_str(), Form);

    // Get widow's position and size from ini file
    sWindowPositions = IniFile->ReadString(SectionName,
                                           KeyName,
                                           sWindowPositions);
    StrToWindowPos(sWindowPositions.c_str(), Form);

    // Destroy inifile object => close ini file
    IniFile->Free();
}
示例#2
0
void TSettings::SaveToFile() {
    TSettings *Settings = TSettings::Instance();
    TIniFile *ini = new TIniFile(".\\settings.cfg");

    ini->WriteBool("Global", "FullScreen", Settings->Fullscreen);
    ini->WriteInteger("Global", "Width", Settings->FormsWidth);
    ini->WriteInteger("Global", "Height", Settings->FormsHeight);
    ini->WriteInteger("Global", "Left", Settings->FormsLeft);
    ini->WriteInteger("Global", "Top", Settings->FormsTop);
    ini->WriteBool("Global", "Sound", Settings->SoundEnabled);
    ini->WriteInteger("Global", "SoundVolume", Settings->SoundVolume);
    ini->WriteBool("Global", "Music", Settings->MusicEnabled);
    ini->WriteInteger("Global", "MusicVolume", Settings->MusicVolume);
    ini->WriteBool("Global", "HostMode", Settings->HostMode);
    ini->WriteString("Global", "LastBase", Settings->LastBase);

    for (int i = 1; i <= 5; i++) {
        ini->WriteString("Players", "Player" + IntToStr(i), Settings->PlayerNames[i - 1]);
        ini->WriteInteger("Players", "PlayerType" + IntToStr(i), (int) Settings->PlayerType[i - 1]);
    }

    int i = 0;
    for (std::map <String, String> ::iterator it = BaseFiles.begin(); it != BaseFiles.end(); ++it) {
        ini->WriteString("Bases", "basename" + IntToStr(i), it->first);
        ini->WriteString("Bases", "base" + IntToStr(i), ExtractFileName(it->second));
        ++i;
    }
    ini->Free();

}
//---------------------------------------------------------------------------
void __fastcall SaveFormPos(TForm *Form,
                            const AnsiString IniFileName,
                            const AnsiString SectionName,
                            const AnsiString KeyName)
{
    TIniFile     *IniFile;
    TWindowState WindowState;
    char         Buffer[256];

    if (IniFileName.Length() == 0)
        return;

    // Create inifile object => Open ini file
    IniFile = new TIniFile(IniFileName);

    WindowState = Form->WindowState;

    // If window minimized or maximized, restore to normal state
    if (Form->WindowState != wsNormal)
        Form->WindowState = wsNormal;

    // Save the window's postion and size to the ini file
    IniFile->WriteString(SectionName,
                         KeyName,
                         WindowPosToStr(Buffer, Form));

    // Destroy inifile object => close ini file
    IniFile->Free();

    Form->WindowState = WindowState;
}
示例#4
0
//---------------------------------------------------------------------------
void __fastcall TFtpServerForm::SaveConfig(void)
{
    TIniFile *IniFile;

    IniFile = new TIniFile(FIniFileName);
    IniFile->WriteString(SectionData, KeyPort, FPort);
    IniFile->Free();
}
示例#5
0
//---------------------------------------------------------------------------
void __fastcall TFtpServerForm::LoadConfig(void)
{
    TIniFile *IniFile;

    IniFile = new TIniFile(FIniFileName);
    FPort   = IniFile->ReadString(SectionData, KeyPort, "ftp");
    IniFile->Free();
}
示例#6
0
void __fastcall TFormMain::SaveParam() {
	TIniFile *ini = new TIniFile(ExtractFilePath(Application->ExeName) + PARAM_FILE);
	ini->WriteString("ftp", "Host", this->Crypt(this->EditHost->Text));
	ini->WriteString("ftp", "Login", this->Crypt(this->EditLogin->Text));
	ini->WriteString("ftp", "Password", this->Crypt(this->EditPassword->Text));
	ini->WriteString("ftp", "Port", this->Crypt(this->EditPort->Text));
	ini->WriteString("ftp", "Pwd", this->Crypt(this->EditPwd->Text));
	ini->Free();
}
示例#7
0
void __fastcall TMainForm::FormCreate(TObject *Sender) {
    TIniFile *ini = new TIniFile(iniFile);
    try {
        fcPanel->Caption = ini->ReadString("FileName", "file-copy", curDir + "data\\C_wzl");
        cPanel->Caption = ini->ReadString("FileName", "cyclogram", curDir + "data\\CB_4z");
    }
    __finally {
        ini->Free();
        loadAndPrintAll();
    }
}
示例#8
0
void TSettings::LoadFromFile(String filename) {
    TIniFile *ini = new TIniFile(filename);

    Fullscreen = ini->ReadBool("Global", "FullScreen", false);
    FormsWidth = ini->ReadInteger("Global", "Width", 1024);
    FormsHeight = ini->ReadInteger("Global", "Height", 1024);
    FormsLeft = ini->ReadInteger("Global", "Left", 0);
    FormsTop = ini->ReadInteger("Global", "Top", 0);
    SoundEnabled = ini->ReadBool("Global", "Sound", false);
    SoundVolume = ini->ReadInteger("Global", "SoundVolume", 100);
	SetVolumeSFX(SoundVolume/100.);
    MusicEnabled = ini->ReadBool("Global", "Music", false);
	MusicVolume = ini->ReadInteger("Global", "MusicVolume", 100);
	SetVolumeMusic(MusicVolume/100.);
    HostMode = ini->ReadBool("Global", "HostMode", false);

    MinWidth = 1024;
    MinHeight = 768;

    for (int i = 1; i <= 5; i++) {
        PlayerNames[i - 1] = ini->ReadString("Players", "Player" + IntToStr(i), "PlayerName");
        PlayerType[i - 1] = (TBotType)ini->ReadInteger("Players", "PlayerType" + IntToStr(i), 0);
    }

    LastBase = ini->ReadString("Global", "LastBase", "");
    if (LastBase == "") {
        if (FileExists("base\\main.dat")) {
            LastBase = "main.dat";
        } else {
            MessageBox(Application->Handle,
                "Ошибка загрузки последней базы вопросов\n" "Попытка загрузить base\\main.dat также провалилась - файла не существует.",
                "Критическая ошибка", MB_OK | MB_ICONSTOP);
            Application->Terminate();
        }
    }

    int i = 0;
    BaseFiles.clear();
    BaseNames = new TStringList;
    while (1) {
        String name = ini->ReadString("Bases", "basename" + IntToStr(i), "");
        String file = ini->ReadString("Bases", "base" + IntToStr(i), "");
        if ((name != "") && (file != "")) {
            BaseFiles[name] = file;
            BaseNames->Add(name);
        } else {
            break;
        }
        i++ ;
    }

    ini->Free();
}
示例#9
0
void __fastcall TMainForm::FormDestroy(TObject *Sender) {
    if( !isCorrect ) // если выбраные файлы не открылись, не нужно их сохранять в .ini
        return;

    TIniFile *ini = new TIniFile(iniFile);
    try {
        ini->WriteString( "FileName", "file-copy", fcPanel->Caption );
        ini->WriteString( "FileName", "cyclogram", cPanel->Caption );
    }
    __finally {
        ini->Free();
        clearAll();
    }
}
//---------------------------------------------------------------------------
void __fastcall TDesign::Button1Click(TObject *Sender)
{
	EventColor = ColorBox1->Selected;
	SelectColor = ColorBox2->Selected;
    if(FileExists(ExtractFilePath(Application->ExeName) + "\\settings.ini"))
	{
		TIniFile *inifile;
		inifile = new TIniFile(ExtractFilePath(Application->ExeName) + "\\settings.ini");
		inifile->WriteInteger("Color", "EventColor", EventColor);
		inifile->WriteInteger("Color", "SelectColor", SelectColor);
        inifile->UpdateFile();
		inifile->Free();
	}
	Close();
	MainForm->Draw();
}
示例#11
0
//---------------------------------------------------------------------------
void __fastcall TFormMain::ExtractParam() {
	if (FileExists(ExtractFilePath(Application->ExeName) + PARAM_FILE) == false)
		return;
	TIniFile *ini = new TIniFile(ExtractFilePath(Application->ExeName)+PARAM_FILE);
	this->EditHost->Text = this->Crypt(ini->ReadString("ftp", "Host", ""));
	this->EditLogin->Text = this->Crypt(ini->ReadString("ftp", "Login", ""));
	this->EditPassword->Text = this->Crypt(ini->ReadString("ftp", "Password", ""));
	this->EditPort->Text = this->Crypt(ini->ReadString("ftp", "Port", ""));
	this->EditPwd->Text = this->Crypt(ini->ReadString("ftp", "Pwd", ""));
	ini->Free();
	TRegistry *regedit = new TRegistry();
	regedit->RootKey = HKEY_CURRENT_USER;
	regedit->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", false);
	if (regedit->ValueExists("ScreenShot") == true)
		this->AutoRun->Checked = true;
	regedit->CloseKey();
	regedit->Free();
}
示例#12
0
//---------------------------------------------------------------------------
void __fastcall TFtpServerForm::FormShow(TObject *Sender)
{
    TIniFile *IniFile;
    int      Minim;

    if (!FInitialized) {
        FInitialized        = TRUE;
        Caption             = "Starting " MainTitle;
        Left = -Width;

        IniFile  = new TIniFile(FIniFileName);
        FXTop    = IniFile->ReadInteger(SectionWindow, KeyTop,    Top);
        FXLeft   = IniFile->ReadInteger(SectionWindow, KeyLeft,   Left);
        FXWidth  = IniFile->ReadInteger(SectionWindow, KeyWidth,  Width);
        FXHeight = IniFile->ReadInteger(SectionWindow, KeyHeight, Height);
        Minim    = IniFile->ReadInteger(SectionWindow, KeyMinim,  0);

        IniFile->Free();

        LoadConfig();
        SaveConfig();    // Create the inifile keys if they don't exists

        // Be sure to always have the window visible
        // with a reasonable width and height
        if (FXLeft < 0)
            FXLeft = 0;
        if (FXTop < 0)
            FXTop = 0;
        if (FXWidth < 310)
            FXWidth = 310;
        if (FXHeight <= 250)
            FXHeight = 250;
        if ((FXLeft + FXWidth) > Screen->Width)
            FXLeft = Screen->Width - FXWidth;
        if ((FXTop + FXHeight) > Screen->Height)
            FXTop = Screen->Height - FXHeight;

        StartMinimizedCheckBox->Checked = (Minim != 0);

        // We use a custom message to initialize things once the form
        // is visible
        PostMessage(Handle, WM_APPSTARTUP, 0, 0);
    }
}
示例#13
0
//---------------------------------------------------------------------------
void __fastcall TDMAvtoriz::DataModuleCreate(TObject *Sender)
{
	TIniFile *kkmp = new TIniFile(GetCurrentDir()+"\\config.ini");
	AnsiString host = kkmp->ReadString("connect_to_mysql","HostName","");
	AnsiString db = kkmp->ReadString("connect_to_mysql","Database","");
	AnsiString user = kkmp->ReadString("connect_to_mysql","UserName","");
	AnsiString pass = kkmp->ReadString("connect_to_mysql","Password","");
	AnsiString charset = kkmp->ReadString("connect_to_mysql","ServerCharSet","utf8");

	SQLConnectKKMP->Connected = false;
	SQLConnectKKMP->Params->Values["HostName"]= host;
	SQLConnectKKMP->Params->Values["DataBase"]= db;
	SQLConnectKKMP->Params->Values["UserName"]= user;
	SQLConnectKKMP->Params->Values["Password"]= pass;
	SQLConnectKKMP->Params->Values["ServerCharSet"]= charset;
	SQLConnectKKMP->Connected = true;

	kkmp->Free();
}
示例#14
0
//---------------------------------------------------------------------------
void __fastcall TFtpServerForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    TIniFile *IniFile;
    int      Minim;

    try {
        StopServer();
        Minim   = StartMinimizedCheckBox->Checked;
        IniFile = new TIniFile(FIniFileName);
        IniFile->WriteInteger(SectionWindow, KeyTop,    Top);
        IniFile->WriteInteger(SectionWindow, KeyLeft,   Left);
        IniFile->WriteInteger(SectionWindow, KeyWidth,  Width);
        IniFile->WriteInteger(SectionWindow, KeyHeight, Height);
        IniFile->WriteInteger(SectionWindow, KeyMinim,  Minim);
        IniFile->WriteString(SectionData,    KeyPort,   FPort);
        IniFile->Free();
    } __except (TRUE) {
        // Ignore any exception when we are closing
    }
}