Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace CLRC {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Collections::Generic;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::IO;
- /// <summary>
- /// Сводка для Form1
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
- protected:
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::ListBox^ listBox1;
- private: System::Windows::Forms::TextBox^ applet;
- private: System::Windows::Forms::Button^ add;
- private: System::Windows::Forms::Button^ clr;
- public:static List<String^>^ applets; //создаем статичный динамический массив строк
- private: System::Windows::Forms::TextBox^ TextFiles;
- public:
- public:
- private:
- /// <summary>
- /// Требуется переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Обязательный метод для поддержки конструктора - не изменяйте
- /// содержимое данного метода при помощи редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
- this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->listBox1 = (gcnew System::Windows::Forms::ListBox());
- this->applet = (gcnew System::Windows::Forms::TextBox());
- this->add = (gcnew System::Windows::Forms::Button());
- this->clr = (gcnew System::Windows::Forms::Button());
- this->TextFiles = (gcnew System::Windows::Forms::TextBox());
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(12, 12);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(75, 23);
- this->button1->TabIndex = 0;
- this->button1->Text = L"Создать";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // listBox1
- //
- this->listBox1->FormattingEnabled = true;
- this->listBox1->Location = System::Drawing::Point(12, 77);
- this->listBox1->Name = L"listBox1";
- this->listBox1->Size = System::Drawing::Size(260, 173);
- this->listBox1->TabIndex = 1;
- //
- // applet
- //
- this->applet->Location = System::Drawing::Point(93, 14);
- this->applet->Name = L"applet";
- this->applet->Size = System::Drawing::Size(95, 20);
- this->applet->TabIndex = 2;
- this->applet->Text = L"applet";
- //
- // add
- //
- this->add->Location = System::Drawing::Point(194, 11);
- this->add->Name = L"add";
- this->add->Size = System::Drawing::Size(35, 23);
- this->add->TabIndex = 3;
- this->add->Text = L"add";
- this->add->UseVisualStyleBackColor = true;
- this->add->Click += gcnew System::EventHandler(this, &Form1::add_Click1);
- //
- // clr
- //
- this->clr->Location = System::Drawing::Point(235, 11);
- this->clr->Name = L"clr";
- this->clr->Size = System::Drawing::Size(35, 23);
- this->clr->TabIndex = 4;
- this->clr->Text = L"clr";
- this->clr->UseVisualStyleBackColor = true;
- this->clr->Click += gcnew System::EventHandler(this, &Form1::clr_Click);
- //
- // TextFiles
- //
- this->TextFiles->Location = System::Drawing::Point(13, 42);
- this->TextFiles->Name = L"TextFiles";
- this->TextFiles->Size = System::Drawing::Size(257, 20);
- this->TextFiles->TabIndex = 5;
- this->TextFiles->Text = L"maplist.txt";
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->AutoSize = true;
- this->ClientSize = System::Drawing::Size(284, 262);
- this->Controls->Add(this->TextFiles);
- this->Controls->Add(this->clr);
- this->Controls->Add(this->add);
- this->Controls->Add(this->applet);
- this->Controls->Add(this->listBox1);
- this->Controls->Add(this->button1);
- this->ForeColor = System::Drawing::Color::CornflowerBlue;
- this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
- this->Name = L"Form1";
- this->Text = L"MapListGenerator";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- listBox1->Items->Clear(); //очищаем листбокс от предидущей сессии
- array<String^>^ Dirs = Directory::GetDirectories(Directory::GetCurrentDirectory()); // сздаем динамический массив строк с названиями папок в данной дирректории
- if(!Directory::GetCurrentDirectory()->Contains(L"cstrike")){ // если приложение не расположено в папке cstrike - выходим
- MessageBox::Show(this,L"Расположите приложение в папке cstike!",L"Ошибка");
- return;
- }
- for each(String^ path in Dirs){ // проходимся по всему массиву папок
- if(path->Contains(L"maps"))
- {
- /*
- если находим папку с картами, залазим в нее, собираем все карты.
- затем ищем по апплетам названия карт. затем создаем файлы из листбокса.
- записываем в них названия карт. сохраняем их и выходим из метода.
- */
- array<String^>^ Files = Directory::GetFiles(path);
- array<StreamWriter^>^ MapList = gcnew array<StreamWriter^>(TextFiles->Text->Split(',')->Length == 0 ? 1 : TextFiles->Text->Split(',')->Length);
- if(TextFiles->Text->Contains(L",")){
- int iCounter = 0;
- for each(String^ MapName in TextFiles->Text->Split(',')){
- if(File::Exists(MapName)) File::Delete(MapName);
- MapList[iCounter++] = File::CreateText(MapName);
- }
- } else {
- MapList[0] = File::CreateText(TextFiles->Text);
- }
- int Less = Files[0]->Length;
- for each(String^ Map in Files)
- {
- if(Map->Contains(L".bsp")){
- bool isMapContains = false;
- for each(String^ Applet in applets){
- if(Map->Contains(Applet))
- isMapContains = true;
- }
- if(!isMapContains) continue;
- if(Map->Length > Less) Less = Map->Length;
- listBox1->Width = Less * 6;
- Width = listBox1->Width + 40;
- listBox1->Items->Add(Map);
- for(int i=0;i<MapList->Length;i++) MapList[i]->WriteLine(Map->Split('\\')[Map->Split('\\')->Length - 1]->Split('.')[0]);
- }
- }
- for(int i=0;i<MapList->Length;i++)
- {
- MapList[i]->Flush();
- MapList[i]->Close();
- }
- if(!listBox1->Items->Count)
- MessageBox::Show(L"Список карт по заданным пораметрам провален.",L"Ошибка");
- }
- }
- return;
- }
- private: System::Void add_Click1(System::Object^ sender, System::EventArgs^ e) {
- if(!applets->Contains(applet->Text)){ // если апплета еще нет в списке поиска, продолжаем.
- applets->Add(applet->Text); // добавляем апплет в массив
- String^ AddedApplets = L"Applets: \n";
- for each(String^ App in applets)
- AddedApplets += App + L",\n";
- AddedApplets = AddedApplets->Insert(AddedApplets->LastIndexOf(L","),L".\0");;
- MessageBox::Show(AddedApplets);// выводим список введенных апплетов...
- } else {
- MessageBox::Show(L"Апплет уже находится в списке поиска!",L"Ошибка");
- }
- }
- private: System::Void clr_Click(System::Object^ sender, System::EventArgs^ e) {
- applets->Clear();
- MessageBox::Show(L"Список апплетов пуст.",L"Внимание");
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment