Pushok

C++CLI prog

Mar 5th, 2011
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.82 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace CLRC {
  4.  
  5.     using namespace System;
  6.     using namespace System::ComponentModel;
  7.     using namespace System::Collections;
  8.     using namespace System::Collections::Generic;
  9.     using namespace System::Windows::Forms;
  10.     using namespace System::Data;
  11.     using namespace System::Drawing;
  12.     using namespace System::IO;
  13.  
  14.     /// <summary>
  15.     /// Сводка для Form1
  16.     /// </summary>
  17.     public ref class Form1 : public System::Windows::Forms::Form
  18.     {
  19.     public:
  20.         Form1(void)
  21.         {
  22.             InitializeComponent();
  23.             //
  24.             //TODO: добавьте код конструктора
  25.             //
  26.         }
  27.  
  28.     protected:
  29.         /// <summary>
  30.         /// Освободить все используемые ресурсы.
  31.         /// </summary>
  32.         ~Form1()
  33.         {
  34.             if (components)
  35.             {
  36.                 delete components;
  37.             }
  38.         }
  39.     private: System::Windows::Forms::SaveFileDialog^  saveFileDialog1;
  40.     protected:
  41.     private: System::Windows::Forms::Button^  button1;
  42.     private: System::Windows::Forms::ListBox^  listBox1;
  43.     private: System::Windows::Forms::TextBox^  applet;
  44.     private: System::Windows::Forms::Button^  add;
  45.     private: System::Windows::Forms::Button^  clr;
  46.     public:static List<String^>^ applets; //создаем статичный динамический массив строк
  47.     private: System::Windows::Forms::TextBox^  TextFiles;
  48.     public:
  49.  
  50.     public:
  51.  
  52.     private:
  53.         /// <summary>
  54.         /// Требуется переменная конструктора.
  55.         /// </summary>
  56.         System::ComponentModel::Container ^components;
  57.  
  58. #pragma region Windows Form Designer generated code
  59.         /// <summary>
  60.         /// Обязательный метод для поддержки конструктора - не изменяйте
  61.         /// содержимое данного метода при помощи редактора кода.
  62.         /// </summary>
  63.         void InitializeComponent(void)
  64.         {
  65.             System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
  66.             this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
  67.             this->button1 = (gcnew System::Windows::Forms::Button());
  68.             this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  69.             this->applet = (gcnew System::Windows::Forms::TextBox());
  70.             this->add = (gcnew System::Windows::Forms::Button());
  71.             this->clr = (gcnew System::Windows::Forms::Button());
  72.             this->TextFiles = (gcnew System::Windows::Forms::TextBox());
  73.             this->SuspendLayout();
  74.             //
  75.             // button1
  76.             //
  77.             this->button1->Location = System::Drawing::Point(12, 12);
  78.             this->button1->Name = L"button1";
  79.             this->button1->Size = System::Drawing::Size(75, 23);
  80.             this->button1->TabIndex = 0;
  81.             this->button1->Text = L"Создать";
  82.             this->button1->UseVisualStyleBackColor = true;
  83.             this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  84.             //
  85.             // listBox1
  86.             //
  87.             this->listBox1->FormattingEnabled = true;
  88.             this->listBox1->Location = System::Drawing::Point(12, 77);
  89.             this->listBox1->Name = L"listBox1";
  90.             this->listBox1->Size = System::Drawing::Size(260, 173);
  91.             this->listBox1->TabIndex = 1;
  92.             //
  93.             // applet
  94.             //
  95.             this->applet->Location = System::Drawing::Point(93, 14);
  96.             this->applet->Name = L"applet";
  97.             this->applet->Size = System::Drawing::Size(95, 20);
  98.             this->applet->TabIndex = 2;
  99.             this->applet->Text = L"applet";
  100.             //
  101.             // add
  102.             //
  103.             this->add->Location = System::Drawing::Point(194, 11);
  104.             this->add->Name = L"add";
  105.             this->add->Size = System::Drawing::Size(35, 23);
  106.             this->add->TabIndex = 3;
  107.             this->add->Text = L"add";
  108.             this->add->UseVisualStyleBackColor = true;
  109.             this->add->Click += gcnew System::EventHandler(this, &Form1::add_Click1);
  110.             //
  111.             // clr
  112.             //
  113.             this->clr->Location = System::Drawing::Point(235, 11);
  114.             this->clr->Name = L"clr";
  115.             this->clr->Size = System::Drawing::Size(35, 23);
  116.             this->clr->TabIndex = 4;
  117.             this->clr->Text = L"clr";
  118.             this->clr->UseVisualStyleBackColor = true;
  119.             this->clr->Click += gcnew System::EventHandler(this, &Form1::clr_Click);
  120.             //
  121.             // TextFiles
  122.             //
  123.             this->TextFiles->Location = System::Drawing::Point(13, 42);
  124.             this->TextFiles->Name = L"TextFiles";
  125.             this->TextFiles->Size = System::Drawing::Size(257, 20);
  126.             this->TextFiles->TabIndex = 5;
  127.             this->TextFiles->Text = L"maplist.txt";
  128.             //
  129.             // Form1
  130.             //
  131.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  132.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  133.             this->AutoSize = true;
  134.             this->ClientSize = System::Drawing::Size(284, 262);
  135.             this->Controls->Add(this->TextFiles);
  136.             this->Controls->Add(this->clr);
  137.             this->Controls->Add(this->add);
  138.             this->Controls->Add(this->applet);
  139.             this->Controls->Add(this->listBox1);
  140.             this->Controls->Add(this->button1);
  141.             this->ForeColor = System::Drawing::Color::CornflowerBlue;
  142.             this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
  143.             this->Name = L"Form1";
  144.             this->Text = L"MapListGenerator";
  145.             this->ResumeLayout(false);
  146.             this->PerformLayout();
  147.  
  148.         }
  149. #pragma endregion
  150.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  151.                  
  152.                  listBox1->Items->Clear(); //очищаем листбокс от предидущей сессии
  153.  
  154.                  array<String^>^ Dirs = Directory::GetDirectories(Directory::GetCurrentDirectory()); // сздаем динамический массив строк с названиями папок в данной дирректории
  155.  
  156.                  if(!Directory::GetCurrentDirectory()->Contains(L"cstrike")){ // если приложение не расположено в папке cstrike - выходим
  157.                      MessageBox::Show(this,L"Расположите приложение в папке cstike!",L"Ошибка");
  158.                      return;
  159.                  }
  160.  
  161.                  for each(String^ path in Dirs){ // проходимся по всему массиву папок
  162.                      if(path->Contains(L"maps"))
  163.                      {
  164.                          /*
  165.                             если находим папку с картами, залазим в нее, собираем все карты.
  166.                             затем ищем по апплетам названия карт. затем создаем файлы из листбокса.
  167.                             записываем в них названия карт. сохраняем их и выходим из метода.
  168.                          */
  169.                          array<String^>^ Files = Directory::GetFiles(path);
  170.                          array<StreamWriter^>^ MapList = gcnew array<StreamWriter^>(TextFiles->Text->Split(',')->Length == 0 ? 1 : TextFiles->Text->Split(',')->Length);
  171.  
  172.                          if(TextFiles->Text->Contains(L",")){
  173.                             int iCounter = 0;
  174.                             for each(String^ MapName in TextFiles->Text->Split(',')){
  175.                                 if(File::Exists(MapName)) File::Delete(MapName);
  176.                                 MapList[iCounter++] = File::CreateText(MapName);
  177.                             }
  178.                          } else {
  179.                              MapList[0] = File::CreateText(TextFiles->Text);
  180.                          }
  181.  
  182.                          int Less = Files[0]->Length;
  183.                          for each(String^ Map in Files)
  184.                          {
  185.                              if(Map->Contains(L".bsp")){
  186.  
  187.                                 bool isMapContains = false;
  188.                                 for each(String^ Applet in applets){
  189.                                     if(Map->Contains(Applet))
  190.                                         isMapContains = true;
  191.                                 }
  192.  
  193.                                 if(!isMapContains) continue;
  194.  
  195.                                 if(Map->Length > Less) Less = Map->Length;
  196.                                 listBox1->Width = Less * 6;
  197.                                 Width = listBox1->Width + 40;
  198.                                 listBox1->Items->Add(Map);
  199.                                  
  200.                                 for(int i=0;i<MapList->Length;i++) MapList[i]->WriteLine(Map->Split('\\')[Map->Split('\\')->Length - 1]->Split('.')[0]);
  201.                                    
  202.                              }
  203.                          }
  204.  
  205.                          for(int i=0;i<MapList->Length;i++)
  206.                          {
  207.                              MapList[i]->Flush();
  208.                              MapList[i]->Close();
  209.                          }
  210.  
  211.                          if(!listBox1->Items->Count)
  212.                              MessageBox::Show(L"Список карт по заданным пораметрам провален.",L"Ошибка");
  213.                          
  214.                      }
  215.                  }
  216.                  return;
  217.              }
  218.  
  219. private: System::Void add_Click1(System::Object^  sender, System::EventArgs^  e) {
  220.              if(!applets->Contains(applet->Text)){ // если апплета еще нет в списке поиска, продолжаем.
  221.                  applets->Add(applet->Text); // добавляем апплет в массив
  222.                  String^ AddedApplets = L"Applets: \n";
  223.                  for each(String^ App in applets)
  224.                      AddedApplets += App + L",\n";
  225.  
  226.                  AddedApplets = AddedApplets->Insert(AddedApplets->LastIndexOf(L","),L".\0");;
  227.                  MessageBox::Show(AddedApplets);// выводим список введенных апплетов...
  228.              } else {
  229.                  MessageBox::Show(L"Апплет уже находится в списке поиска!",L"Ошибка");
  230.              }
  231.          }
  232.  
  233. private: System::Void clr_Click(System::Object^  sender, System::EventArgs^  e) {
  234.              applets->Clear();
  235.              MessageBox::Show(L"Список апплетов пуст.",L"Внимание");
  236.          }
  237. };
  238. }
Advertisement
Add Comment
Please, Sign In to add comment