Загрузка данных
#pragma once
namespace VPN {
using namespace System;
using namespace System.ComponentModel;
using namespace System.Collections;
using namespace System.Windows::Forms;
using namespace System.Data;
using namespace System.Drawing;
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
}
protected:
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ txtLink;
private: System::Windows::Forms::ListBox^ lstServers;
private: System::Windows::Forms::Button^ btnImport;
private: System::Windows::Forms::Button^ btnConnect;
private: System::Windows::Forms::Button^ btnDisconnect;
private: System::Windows::Forms::Label^ lblStatus;
private: System::Diagnostics::Process^ vpnProcess;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->txtLink = (gcnew System::Windows::Forms::TextBox());
this->lstServers = (gcnew System::Windows::Forms::ListBox());
this->btnImport = (gcnew System::Windows::Forms::Button());
this->btnConnect = (gcnew System::Windows::Forms::Button());
this->btnDisconnect = (gcnew System::Windows::Forms::Button());
this->lblStatus = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// txtLink
//
this->txtLink->Location = System::Drawing::Point(12, 12);
this->txtLink->Name = L"txtLink";
this->txtLink->Size = System::Drawing::Size(360, 20);
this->txtLink->TabIndex = 0;
//
// btnImport
//
this->btnImport->Location = System::Drawing::Point(12, 38);
this->btnImport->Name = L"btnImport";
this->btnImport->Size = System::Drawing::Size(360, 23);
this->btnImport->TabIndex = 1;
this->btnImport->Text = L"Импортировать ссылку";
this->btnImport->UseVisualStyleBackColor = true;
this->btnImport->Click += gcnew System::EventHandler(this, &MyForm::btnImport_Click);
//
// lstServers
//
this->lstServers->FormattingEnabled = true;
this->lstServers->Location = System::Drawing::Point(12, 75);
this->lstServers->Name = L"lstServers";
this->lstServers->Size = System::Drawing::Size(360, 95);
this->lstServers->TabIndex = 2;
//
// btnConnect
//
this->btnConnect->Location = System::Drawing::Point(12, 185);
this->btnConnect->Name = L"btnConnect";
this->btnConnect->Size = System::Drawing::Size(170, 30);
this->btnConnect->TabIndex = 3;
this->btnConnect->Text = L"ПОДКЛЮЧИТЬСЯ";
this->btnConnect->UseVisualStyleBackColor = true;
this->btnConnect->Click += gcnew System::EventHandler(this, &MyForm::btnConnect_Click);
//
// btnDisconnect
//
this->btnDisconnect->Location = System::Drawing::Point(202, 185);
this->btnDisconnect->Name = L"btnDisconnect";
this->btnDisconnect->Size = System::Drawing::Size(170, 30);
this->btnDisconnect->TabIndex = 4;
this->btnDisconnect->Text = L"ОТКЛЮЧИТЬ";
this->btnDisconnect->UseVisualStyleBackColor = true;
this->btnDisconnect->Click += gcnew System::EventHandler(this, &MyForm::btnDisconnect_Click);
//
// lblStatus
//
this->lblStatus->AutoSize = true;
this->lblStatus->Location = System::Drawing::Point(12, 230);
this->lblStatus->Name = L"lblStatus";
this->lblStatus->Size = System::Drawing::Size(103, 13);
this->lblStatus->TabIndex = 5;
this->lblStatus->Text = L"Статус: Отключено";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(384, 261);
this->Controls->Add(this->lblStatus);
this->Controls->Add(this->btnDisconnect);
this->Controls->Add(this->btnConnect);
this->Controls->Add(this->lstServers);
this->Controls->Add(this->btnImport);
this->Controls->Add(this->txtLink);
this->Name = L"MyForm";
this->Text = L"VPN Configurator";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// Логика кнопок
private: System::Void btnImport_Click(System::Object^ sender, System::EventArgs^ e) {
String^ link = txtLink->Text->Trim();
if (String::IsNullOrEmpty(link)) {
MessageBox::Show("Вставьте ссылку!");
return;
}
int count = lstServers->Items->Count + 1;
lstServers->Items->Add("Сервер №" + count + " (" + link->Substring(0, Math::Min(link->Length, 10)) + "...)");
txtLink->Clear();
}
private: System::Void btnConnect_Click(System::Object^ sender, System::EventArgs^ e) {
if (lstServers->SelectedItem == nullptr) {
MessageBox::Show("Выберите сервер!");
return;
}
if (vpnProcess != nullptr && !vpnProcess->HasExited) {
MessageBox::Show("VPN уже запущен!");
return;
}
String^ exePath = System::IO::Path::Combine(Application::StartupPath, "ss-local.exe");
if (!System::IO::File::Exists(exePath)) {
MessageBox::Show("Положите ss-local.exe рядом с программой!");
return;
}
try {
vpnProcess = gcnew System::Diagnostics::Process();
vpnProcess->StartInfo->FileName = exePath;
vpnProcess->StartInfo->Arguments = "-u \"" + txtLink->Text + "\"";
vpnProcess->StartInfo->CreateNoWindow = true;
vpnProcess->StartInfo->UseShellExecute = false;
vpnProcess->Start();
lblStatus->Text = "Статус: ПОДКЛЮЧЕНО";
}
catch (Exception^ ex) {
MessageBox::Show("Ошибка: " + ex->Message);
}
}
private: System::Void btnDisconnect_Click(System::Object^ sender, System::EventArgs^ e) {
if (vpnProcess != nullptr && !vpnProcess->HasExited) {
vpnProcess->Kill();
vpnProcess->Close();
vpnProcess = nullptr;
lblStatus->Text = "Статус: Отключено";
}
}
};
}