#pragma once

namespace WindowsFormApplication1 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::IO;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ListBox^  listBox1;
	protected: 
	private: System::Windows::Forms::ListBox^  listBox2;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->listBox1 = (gcnew System::Windows::Forms::ListBox());
			this->listBox2 = (gcnew System::Windows::Forms::ListBox());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// listBox1
			// 
			this->listBox1->FormattingEnabled = true;
			this->listBox1->Location = System::Drawing::Point(12, 12);
			this->listBox1->Name = L"listBox1";
			this->listBox1->Size = System::Drawing::Size(370, 290);
			this->listBox1->TabIndex = 0;
			this->listBox1->Click += gcnew System::EventHandler(this, &Form1::listBox1_Click);
			// 
			// listBox2
			// 
			this->listBox2->FormattingEnabled = true;
			this->listBox2->Location = System::Drawing::Point(469, 12);
			this->listBox2->Name = L"listBox2";
			this->listBox2->Size = System::Drawing::Size(370, 290);
			this->listBox2->TabIndex = 1;
			this->listBox2->Click += gcnew System::EventHandler(this, &Form1::listBox2_Click);
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(388, 75);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 2;
			this->button1->Text = L"Kopuj ->";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(388, 104);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(75, 23);
			this->button2->TabIndex = 3;
			this->button2->Text = L"<- Kopiuj";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(388, 176);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(75, 23);
			this->button3->TabIndex = 4;
			this->button3->Text = L"Kasuj ->";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(388, 205);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(75, 23);
			this->button4->TabIndex = 5;
			this->button4->Text = L"<- Kasuj";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(16, 326);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(35, 13);
			this->label1->TabIndex = 6;
			this->label1->Text = L"label1";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(473, 324);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(35, 13);
			this->label2->TabIndex = 7;
			this->label2->Text = L"label2";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(862, 354);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->listBox2);
			this->Controls->Add(this->listBox1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

		DirectoryInfo^ AktFold1;
		DirectoryInfo^ AktFold2;
		private: System::String^ OpisPlikuFormat;
        private: System::String^ OpisFolderuFormat;

				 private: System::Void KopiujPlik(System::String^ zrodlo, System::String^ cel) {
System::Windows::Forms::DialogResult odp;
if (File::Exists(cel)) {
    odp = 
    MessageBox::Show(L"Plik docelowy istneje, czy napisać?",L"Plik istnieje",
    MessageBoxButtons::YesNo,MessageBoxIcon::Question);
}
if (odp==System::Windows::Forms::DialogResult::Yes) File::Copy(zrodlo,cel,1);
 else 
File::Copy(zrodlo,cel);
 }


	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 System::String^ PlikZrodlo = listBox1->SelectedItem->ToString()->Remove(30); //nazwa pliku ze spacjami 
KopiujPlik(AktFold1->FullName+"\\"+PlikZrodlo->Trim(),AktFold2->FullName+"\\"+PlikZrodlo->Trim()); //po skopowaniu wyswietl folder
WyswietlFold(listBox2,AktFold2);

			 }
			 
    private: System::String^ FormatWpisFolder(DirectoryInfo^ folder) {
			OpisFolderuFormat="";
		    OpisFolderuFormat+=folder->Name;
					  //spacje po nazwie folderu
            System::Int32 spacje;
            spacje=30-folder->Name->Length;
            for (int sp=0;sp<spacje;sp++)
               OpisFolderuFormat+=" ";
            spacje=3;
            for (int sp=0;sp<spacje;sp++)
            OpisFolderuFormat+=" ";
            //SUB-DIR
            OpisFolderuFormat+="SUB-DIR";
            return OpisFolderuFormat;
			 }
	private: System::String^ FormatWpisPlik(FileInfo^ plik) {OpisPlikuFormat="";
       //nazwa pliku jeśli wieksza od 30 znakow to przytnij
       if (plik->Name->Length>30)
          OpisPlikuFormat+=plik->Name->Remove(30);
       if (plik->Name->Length<30)
          OpisPlikuFormat+=plik->Name;
       System::Int32 spacje;
       spacje=30-plik->Name->Length;
       for (int sp=0;sp<spacje;sp++)
         OpisPlikuFormat+=" ";
       //rozmiar 
       System::Int64 rozmiar=plik->Length;
       System::String^ Rozmiar_String;
       //konwersja na rozmiar tekstowo wraz z jednostką
 if (rozmiar<1024)
        Rozmiar_String=((System::Double)plik->Length).ToString()+"B";
 if ((rozmiar>=1024)&&(rozmiar<=1048576))
        Rozmiar_String=((System::Double)plik->Length/1024).ToString("F2")+"KB";
 if (rozmiar>1048576)
        Rozmiar_String=((System::Double)plik->Length/1048576).ToString("F2")+"MB";
//spacje przed rozmiarem pliku - dopiero teraz wiadomo ile zajmnie rozmiar
spacje=10-Rozmiar_String->Length;
 for (int sp=0;sp<spacje;sp++)
     OpisPlikuFormat+=" ";
OpisPlikuFormat+=Rozmiar_String;
return OpisPlikuFormat;
			 }
private: System::Void WyswietlFold(ListBox^ lista, DirectoryInfo^ katalog)
{
	System::Drawing::Font^ czcionka = 
    gcnew System::Drawing::Font("Courier",10,FontStyle::Regular);
    lista->Font = czcionka;
    lista->Items->Clear();
	if (katalog->Parent) lista->Items->Add("(..)"); // znacznik do folderu nadrzednego
	array<DirectoryInfo^>^ foldery = katalog->GetDirectories();
    for (System::Int32 i=0;i<foldery->Length; i++) {
       lista->Items->Add(FormatWpisFolder(foldery[i]));
     }
	array<FileInfo^>^ pliki = katalog->GetFiles("*.*");
    for (System::Int32 i=0;i<pliki->Length; i++) {
    lista->Items->Add(FormatWpisPlik(pliki[i]));
    }



}

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    AktFold1 = gcnew DirectoryInfo("."); // punkt startowy to folder programu   
    AktFold2 = gcnew DirectoryInfo(".");
    WyswietlFold(listBox1,AktFold1);
    WyswietlFold(listBox2,AktFold2);
    label1->Text=AktFold1->FullName;
    label2->Text=AktFold2->FullName;

		 }
private: System::Void listBox1_Click(System::Object^  sender, System::EventArgs^  e) {
			   if (listBox1->SelectedItem->ToString()=="(..)") {
      AktFold1=AktFold1->Parent; //aktualny folder wyzej
      label1->Text=AktFold1->FullName;
      WyswietlFold(listBox1,AktFold1);
      return;} 
   if (listBox1->SelectedItem->ToString()->Contains("SUB-DIR")) {
      array<DirectoryInfo^>^ SubDir = AktFold1->GetDirectories(listBox1->
      SelectedItem->ToString()->Remove(30));
       //niby tablica ale i tak znajdzie tylko jeden folder o zaznaczonej nazwie 
       AktFold1=SubDir[0]; //aktualny folder nizej
       WyswietlFold(listBox1,AktFold1);
       label1->Text=AktFold1->FullName;
    }
		 }


		 
private: System::Void listBox2_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (listBox2->SelectedItem->ToString()=="(..)") {
       AktFold2=AktFold2->Parent; //aktualny folder wyzej
       label2->Text=AktFold2->FullName;
       WyswietlFold(listBox2,AktFold2);
       return; }
  if (listBox2->SelectedItem->ToString()->Contains("SUB-DIR")) {
       array<DirectoryInfo^>^ SubDir = AktFold2->GetDirectories(listBox2
       ->SelectedItem->ToString()->Remove(30));
       //niby tablica ale i tak znajdzie tylko jeden folder o zaznaczonej nazwie 
        AktFold2=SubDir[0]; //aktualny folder nizej
        WyswietlFold(listBox2,AktFold2);
        label2->Text=AktFold2->FullName;
    }


} 

		
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 System::String^ PlikZrodlo = listBox2->SelectedItem->ToString()->Remove(30); //nazwa pliku ze spacjami
KopiujPlik(AktFold2->FullName+"\\"+PlikZrodlo->Trim(),AktFold1->FullName+"\\"+PlikZrodlo->Trim()); //po skopowaniu wyswietl folder
WyswietlFold(listBox1,AktFold1);

		 }
		 private: System::Void SkasujPlik(System::String^ plik) {
 System::Windows::Forms::DialogResult odp = MessageBox::Show(L"Czy naprawde skasować pilk " +System::Environment::NewLine+plik,L"Potwierdzenie", MessageBoxButtons::YesNo,MessageBoxIcon::Question);;
  if (odp==System::Windows::Forms::DialogResult::Yes) File::Delete(plik);
}

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			  System::String^ PlikZrodlo = listBox2->SelectedItem->ToString()->Remove(30); //nazwa pliku ze spacjami
              SkasujPlik(AktFold2->FullName+"\\"+PlikZrodlo->Trim());
              WyswietlFold(listBox2,AktFold2);

		 }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			 System::String^ PlikZrodlo = listBox1->SelectedItem->ToString()->Remove(30); //nazwa pliku ze spacjami
             SkasujPlik(AktFold1->FullName+"\\"+PlikZrodlo->Trim());
             WyswietlFold(listBox1,AktFold1);

		 }
};
}

