-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit2.cpp
95 lines (87 loc) · 3.47 KB
/
Unit2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "IniFiles.hpp"
#include "Registry.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TSettingsForm *SettingsForm;
TIniFile* Settings;
//---------------------------------------------------------------------------
__fastcall TSettingsForm::TSettingsForm(TComponent* Owner)
: TForm(Owner)
{
if (not FileExists(ExtractFilePath(Application->ExeName)+"WebView2Loader.dll")) {
Application->MessageBox(L"Отсутствует WebView2Loader.dll", Application->Title.c_str(), MB_OK | MB_ICONEXCLAMATION);
Application->Terminate();
}
Settings = new TIniFile(ExtractFilePath(Application->ExeName) + "settings.ini");
if (Settings->ReadBool("Main", "Started", false) == true) {
MainForm->Domain = SelectDomain(Settings->ReadInteger("Main", "CountryIndex", 0));
bool minimized = false;
if (Settings->ReadBool("Main", "AutoMinimize", false) == true) minimized = true;
MainForm->OneStart(minimized);
SettingsForm->Close();
}
else
SettingsForm->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TSettingsForm::SaveButtonClick(TObject *Sender)
{
Settings = new TIniFile(ExtractFilePath(Application->ExeName) + "settings.ini");
Settings->WriteBool("Main", "Started", true);
Settings->WriteInteger("Main", "CountryIndex", CBox->ItemIndex);
Settings->WriteBool("Main", "AutoRun", AutorunBox->Checked);
Settings->WriteBool("Main", "AutoMinimize", MinimizeBox->Checked);
if (AutorunBox->Checked == true) {
TRegistry *reg = new TRegistry();
reg->RootKey = HKEY_CURRENT_USER;
reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
reg->WriteString("HH Resumes Updater", Application->ExeName);
reg->CloseKey();
} else {
TRegistry *reg = new TRegistry();
reg->RootKey = HKEY_CURRENT_USER;
reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
reg->DeleteValue("HH Resumes Updater");
reg->CloseKey();
}
MainForm->Domain = SelectDomain(CBox->ItemIndex);
MainForm->OneStart(false);
SettingsForm->Close();
}
//---------------------------------------------------------------------------
String TSettingsForm::SelectDomain(int index)
{
String dm = "https://hh.ru/";
switch (index) {
case 0: dm = "https://hh.ru/"; break;
case 1: dm = "https://hh.kz/"; break;
case 2: dm = "https://rabota.by/"; break;
case 3: dm = "https://hh.uz/"; break;
case 4: dm = "https://hh1.az/"; break;
case 5: dm = "https://headhunter.ge/"; break;
case 6: dm = "https://headhunter.kg/"; break;
}
return dm;
}
//---------------------------------------------------------------------------
void __fastcall TSettingsForm::FormShow(TObject *Sender)
{
Settings = new TIniFile(ExtractFilePath(Application->ExeName) + "settings.ini");
CBox->ItemIndex = Settings->ReadInteger("Main", "CountryIndex", 0);
AutorunBox->Checked = Settings->ReadBool("Main", "AutoRun", 0);
MinimizeBox->Checked = Settings->ReadBool("Main", "AutoMinimize", 0);
}
//---------------------------------------------------------------------------
void __fastcall TSettingsForm::FormClose(TObject *Sender, TCloseAction &Action)
{
if (Settings->ReadBool("Main", "Started", false) == false) {
Application->Terminate();
}
}
//---------------------------------------------------------------------------