Advertisement
xqp

Symlink

xqp
Dec 27th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.04 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <string>
  4. #include <msclr\marshal_cppstd.h>
  5. #define WINVER 0x0600
  6. #define _WIN32_WINNT 0x0600
  7. #include <windows.h>
  8. #pragma once
  9.  
  10. namespace SymlinkGenerator {
  11.  
  12.     using namespace System;
  13.     using namespace System::ComponentModel;
  14.     using namespace System::Collections;
  15.     using namespace System::Windows::Forms;
  16.     using namespace System::Data;
  17.     using namespace System::Drawing;
  18.  
  19.     /// <summary>
  20.     /// Zusammenfassung für MyForm
  21.     /// </summary>
  22.     public ref class MyForm : public System::Windows::Forms::Form
  23.     {
  24.     public:
  25.         MyForm(void)
  26.         {
  27.             InitializeComponent();
  28.             //
  29.             //TODO: Konstruktorcode hier hinzufügen.
  30.             //
  31.         }
  32.  
  33.     protected:
  34.         /// <summary>
  35.         /// Verwendete Ressourcen bereinigen.
  36.         /// </summary>
  37.         ~MyForm()
  38.         {
  39.             if (components)
  40.             {
  41.                 delete components;
  42.             }
  43.         }
  44.     private: String^ sSourcePath;
  45.     private: System::Windows::Forms::Button^  btnCreateSymlinks;
  46.     private: System::Windows::Forms::Label^  lblInfo;
  47.              String^ sDestinationPath;
  48.  
  49.     public: void SetSourcePath(String^ a) {
  50.         sSourcePath = a;
  51.     }
  52.    
  53.     public: void SetDestinationPath(String^ a) {
  54.         sDestinationPath = a;
  55.     }
  56.  
  57.     public: String^ GetSourcePath() {
  58.         return sSourcePath;
  59.     }
  60.  
  61.     public: String^ GetDestinationPath() {
  62.         return sDestinationPath;
  63.     }
  64.  
  65.     private: System::Windows::Forms::Button^  btnSourcePath;
  66.     protected:
  67.     private: System::Windows::Forms::Label^  lblSourcePath;
  68.     private: System::Windows::Forms::Button^  btnDestinationPath;
  69.     private: System::Windows::Forms::Label^  lblDestinationPath;
  70.  
  71.     private:
  72.         /// <summary>
  73.         /// Erforderliche Designervariable.
  74.         /// </summary>
  75.         System::ComponentModel::Container ^components;
  76.  
  77. #pragma region Windows Form Designer generated code
  78.         /// <summary>
  79.         /// Erforderliche Methode für die Designerunterstützung.
  80.         /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
  81.         /// </summary>
  82.         void InitializeComponent(void)
  83.         {
  84.             this->btnSourcePath = (gcnew System::Windows::Forms::Button());
  85.             this->lblSourcePath = (gcnew System::Windows::Forms::Label());
  86.             this->btnDestinationPath = (gcnew System::Windows::Forms::Button());
  87.             this->lblDestinationPath = (gcnew System::Windows::Forms::Label());
  88.             this->btnCreateSymlinks = (gcnew System::Windows::Forms::Button());
  89.             this->lblInfo = (gcnew System::Windows::Forms::Label());
  90.             this->SuspendLayout();
  91.             //
  92.             // btnSourcePath
  93.             //
  94.             this->btnSourcePath->Location = System::Drawing::Point(394, 48);
  95.             this->btnSourcePath->Name = L"btnSourcePath";
  96.             this->btnSourcePath->Size = System::Drawing::Size(192, 53);
  97.             this->btnSourcePath->TabIndex = 0;
  98.             this->btnSourcePath->Text = L"Source Path";
  99.             this->btnSourcePath->UseVisualStyleBackColor = true;
  100.             this->btnSourcePath->Click += gcnew System::EventHandler(this, &MyForm::btnSourcePath_Click);
  101.             //
  102.             // lblSourcePath
  103.             //
  104.             this->lblSourcePath->AutoSize = true;
  105.             this->lblSourcePath->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  106.             this->lblSourcePath->Location = System::Drawing::Point(49, 68);
  107.             this->lblSourcePath->Name = L"lblSourcePath";
  108.             this->lblSourcePath->Size = System::Drawing::Size(2, 15);
  109.             this->lblSourcePath->TabIndex = 1;
  110.             //
  111.             // btnDestinationPath
  112.             //
  113.             this->btnDestinationPath->Location = System::Drawing::Point(394, 147);
  114.             this->btnDestinationPath->Name = L"btnDestinationPath";
  115.             this->btnDestinationPath->Size = System::Drawing::Size(192, 53);
  116.             this->btnDestinationPath->TabIndex = 2;
  117.             this->btnDestinationPath->Text = L"Destination Path";
  118.             this->btnDestinationPath->UseVisualStyleBackColor = true;
  119.             this->btnDestinationPath->Click += gcnew System::EventHandler(this, &MyForm::btnDestinationPath_Click);
  120.             //
  121.             // lblDestinationPath
  122.             //
  123.             this->lblDestinationPath->AutoSize = true;
  124.             this->lblDestinationPath->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  125.             this->lblDestinationPath->Location = System::Drawing::Point(49, 167);
  126.             this->lblDestinationPath->Name = L"lblDestinationPath";
  127.             this->lblDestinationPath->Size = System::Drawing::Size(2, 15);
  128.             this->lblDestinationPath->TabIndex = 3;
  129.             //
  130.             // btnCreateSymlinks
  131.             //
  132.             this->btnCreateSymlinks->Location = System::Drawing::Point(94, 251);
  133.             this->btnCreateSymlinks->Name = L"btnCreateSymlinks";
  134.             this->btnCreateSymlinks->Size = System::Drawing::Size(433, 100);
  135.             this->btnCreateSymlinks->TabIndex = 4;
  136.             this->btnCreateSymlinks->Text = L"Symlinks erstellen...";
  137.             this->btnCreateSymlinks->UseVisualStyleBackColor = true;
  138.             this->btnCreateSymlinks->Click += gcnew System::EventHandler(this, &MyForm::btnCreateSymlinks_Click);
  139.             //
  140.             // lblInfo
  141.             //
  142.             this->lblInfo->AutoSize = true;
  143.             this->lblInfo->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
  144.             this->lblInfo->Location = System::Drawing::Point(49, 387);
  145.             this->lblInfo->Name = L"lblInfo";
  146.             this->lblInfo->Size = System::Drawing::Size(2, 15);
  147.             this->lblInfo->TabIndex = 5;
  148.             //
  149.             // MyForm
  150.             //
  151.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  152.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  153.             this->ClientSize = System::Drawing::Size(638, 448);
  154.             this->Controls->Add(this->lblInfo);
  155.             this->Controls->Add(this->btnCreateSymlinks);
  156.             this->Controls->Add(this->lblDestinationPath);
  157.             this->Controls->Add(this->btnDestinationPath);
  158.             this->Controls->Add(this->lblSourcePath);
  159.             this->Controls->Add(this->btnSourcePath);
  160.             this->Name = L"MyForm";
  161.             this->Text = L"Symlink Generator";
  162.             this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  163.             this->ResumeLayout(false);
  164.             this->PerformLayout();
  165.  
  166.         }
  167. #pragma endregion
  168.     private: System::Void btnSourcePath_Click(System::Object^  sender, System::EventArgs^  e) {
  169.  
  170.         FolderBrowserDialog^ SourceFolderDialog;
  171.         SourceFolderDialog = gcnew System::Windows::Forms::FolderBrowserDialog;
  172.  
  173.         System::Windows::Forms::DialogResult result = SourceFolderDialog->ShowDialog();
  174.         if (result == System::Windows::Forms::DialogResult::OK)
  175.         {
  176.             String^ path = SourceFolderDialog->SelectedPath;
  177.             SetSourcePath(path);
  178.             lblSourcePath->Text = path;
  179.            
  180.         }
  181.  
  182.     }
  183.     private: System::Void btnDestinationPath_Click(System::Object^  sender, System::EventArgs^  e) {
  184.  
  185.         FolderBrowserDialog^ DestinationFolderDialog;
  186.         DestinationFolderDialog = gcnew System::Windows::Forms::FolderBrowserDialog;
  187.  
  188.         System::Windows::Forms::DialogResult result = DestinationFolderDialog->ShowDialog();
  189.         if (result == System::Windows::Forms::DialogResult::OK)
  190.         {
  191.             String^ path = DestinationFolderDialog->SelectedPath;
  192.             SetDestinationPath(path);
  193.             lblDestinationPath->Text = path;
  194.  
  195.         }
  196.     }
  197. private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
  198. }
  199. private: System::Void btnCreateSymlinks_Click(System::Object^  sender, System::EventArgs^  e) {
  200.     String^ pathSource = GetSourcePath();
  201.     String^ pathDest = GetDestinationPath();
  202.     String^ folder = System::IO::Path::GetFileName(pathSource);
  203.     lblInfo->Text = pathSource + " -> " + pathDest + "" + folder;
  204.  
  205. }
  206. };
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement