#pragma once

namespace TempOrdnerLeeren {

	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>
	/// Zusammenfassung für Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	internal: System::Windows::Forms::Button^  Button1;
	protected: 

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		void InitializeComponent(void)
		{
			this->Button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// Button1
			// 
			this->Button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->Button1->Location = System::Drawing::Point(92, 117);
			this->Button1->Margin = System::Windows::Forms::Padding(4);
			this->Button1->Name = L"Button1";
			this->Button1->Size = System::Drawing::Size(100, 28);
			this->Button1->TabIndex = 2;
			this->Button1->Text = L"Leeren";
			this->Button1->UseVisualStyleBackColor = true;
			this->Button1->Click += gcnew System::EventHandler(this, &Form1::Button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->Button1);
			this->Name = L"Form1";
			this->Text = L"Temp-Ordner leeren";
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Button1_Click(System::Object^  sender, System::EventArgs^  e) {
					array<String^>^ dateien = Directory::GetFiles(Path::GetTempPath());
					array<String^>^ ordner = Directory::GetDirectories(Path::GetTempPath());

					for each (String^ o in ordner)
					{
						try
						{
							Directory::Delete(o, true);
						}
						catch (Exception^ ex)
						{
							MessageBox::Show(ex->Message);
						}
					}

					for each (String^ d in dateien)
					{
						try
						{
							File::Delete(d);
						}
						catch (Exception^ ex)
						{
							MessageBox::Show(ex->Message);
						}
					}
				}
	};
}

