| 1 | #pragma once |
|---|
| 2 | |
|---|
| 3 | using namespace System; |
|---|
| 4 | using namespace System::ComponentModel; |
|---|
| 5 | using namespace System::Collections; |
|---|
| 6 | using namespace System::Windows::Forms; |
|---|
| 7 | using namespace System::Data; |
|---|
| 8 | using namespace System::Drawing; |
|---|
| 9 | using namespace System::Threading; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | namespace EraserCtxMenu { |
|---|
| 13 | |
|---|
| 14 | /// <summary> |
|---|
| 15 | /// Summary for SecureMove |
|---|
| 16 | /// |
|---|
| 17 | /// WARNING: If you change the name of this class, you will need to change the |
|---|
| 18 | /// 'Resource File Name' property for the managed resource compiler tool |
|---|
| 19 | /// associated with all .resx files this class depends on. Otherwise, |
|---|
| 20 | /// the designers will not be able to interact properly with localized |
|---|
| 21 | /// resources associated with this form. |
|---|
| 22 | /// </summary> |
|---|
| 23 | public ref class SecureMove : public System::Windows::Forms::Form |
|---|
| 24 | { |
|---|
| 25 | public: |
|---|
| 26 | SecureMove(void) |
|---|
| 27 | { |
|---|
| 28 | InitializeComponent(); |
|---|
| 29 | // |
|---|
| 30 | //TODO: Add the constructor code here |
|---|
| 31 | // |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | protected: |
|---|
| 35 | /// <summary> |
|---|
| 36 | /// Clean up any resources being used. |
|---|
| 37 | /// </summary> |
|---|
| 38 | ~SecureMove() |
|---|
| 39 | { |
|---|
| 40 | if (components) |
|---|
| 41 | { |
|---|
| 42 | delete components; |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | private: System::Windows::Forms::ProgressBar^ progressBar1; |
|---|
| 46 | protected: |
|---|
| 47 | private: System::Windows::Forms::Button^ cancel; |
|---|
| 48 | private: System::Windows::Forms::PictureBox^ pictureBox1; |
|---|
| 49 | private: System::Windows::Forms::Label^ fromLabel; |
|---|
| 50 | private: System::Windows::Forms::Label^ toLabel; |
|---|
| 51 | private: System::Windows::Forms::TextBox^ textBoxFrom; |
|---|
| 52 | private: System::Windows::Forms::TextBox^ textBoxTo; |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | private: System::Windows::Forms::Button^ openBrowserBtn; |
|---|
| 56 | private: System::Windows::Forms::Button^ saveBrowserBtn; |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | private: System::Windows::Forms::OpenFileDialog^ openFileDialog1; |
|---|
| 61 | private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1; |
|---|
| 62 | private: System::Windows::Forms::Button^ start; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | private: |
|---|
| 73 | /// <summary> |
|---|
| 74 | /// Required designer variable. |
|---|
| 75 | /// </summary> |
|---|
| 76 | System::ComponentModel::Container ^components; |
|---|
| 77 | |
|---|
| 78 | #pragma region Windows Form Designer generated code |
|---|
| 79 | /// <summary> |
|---|
| 80 | /// Required method for Designer support - do not modify |
|---|
| 81 | /// the contents of this method with the code editor. |
|---|
| 82 | /// </summary> |
|---|
| 83 | void InitializeComponent(void) |
|---|
| 84 | { |
|---|
| 85 | this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar()); |
|---|
| 86 | this->cancel = (gcnew System::Windows::Forms::Button()); |
|---|
| 87 | this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); |
|---|
| 88 | this->fromLabel = (gcnew System::Windows::Forms::Label()); |
|---|
| 89 | this->toLabel = (gcnew System::Windows::Forms::Label()); |
|---|
| 90 | this->textBoxFrom = (gcnew System::Windows::Forms::TextBox()); |
|---|
| 91 | this->textBoxTo = (gcnew System::Windows::Forms::TextBox()); |
|---|
| 92 | this->openBrowserBtn = (gcnew System::Windows::Forms::Button()); |
|---|
| 93 | this->saveBrowserBtn = (gcnew System::Windows::Forms::Button()); |
|---|
| 94 | this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog()); |
|---|
| 95 | this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog()); |
|---|
| 96 | this->start = (gcnew System::Windows::Forms::Button()); |
|---|
| 97 | (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); |
|---|
| 98 | this->SuspendLayout(); |
|---|
| 99 | // |
|---|
| 100 | // progressBar1 |
|---|
| 101 | // |
|---|
| 102 | this->progressBar1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left) |
|---|
| 103 | | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 104 | this->progressBar1->Location = System::Drawing::Point(12, 153); |
|---|
| 105 | this->progressBar1->Name = L"progressBar1"; |
|---|
| 106 | this->progressBar1->Size = System::Drawing::Size(286, 20); |
|---|
| 107 | this->progressBar1->TabIndex = 0; |
|---|
| 108 | // |
|---|
| 109 | // cancel |
|---|
| 110 | // |
|---|
| 111 | this->cancel->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 112 | this->cancel->Location = System::Drawing::Point(385, 151); |
|---|
| 113 | this->cancel->Name = L"cancel"; |
|---|
| 114 | this->cancel->Size = System::Drawing::Size(75, 23); |
|---|
| 115 | this->cancel->TabIndex = 1; |
|---|
| 116 | this->cancel->Text = L"&Cancel"; |
|---|
| 117 | this->cancel->UseVisualStyleBackColor = true; |
|---|
| 118 | // |
|---|
| 119 | // pictureBox1 |
|---|
| 120 | // |
|---|
| 121 | this->pictureBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) |
|---|
| 122 | | System::Windows::Forms::AnchorStyles::Left) |
|---|
| 123 | | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 124 | this->pictureBox1->Location = System::Drawing::Point(12, 12); |
|---|
| 125 | this->pictureBox1->Name = L"pictureBox1"; |
|---|
| 126 | this->pictureBox1->Size = System::Drawing::Size(146, 133); |
|---|
| 127 | this->pictureBox1->TabIndex = 2; |
|---|
| 128 | this->pictureBox1->TabStop = false; |
|---|
| 129 | // |
|---|
| 130 | // fromLabel |
|---|
| 131 | // |
|---|
| 132 | this->fromLabel->AutoSize = true; |
|---|
| 133 | this->fromLabel->Location = System::Drawing::Point(172, 12); |
|---|
| 134 | this->fromLabel->Name = L"fromLabel"; |
|---|
| 135 | this->fromLabel->Size = System::Drawing::Size(60, 13); |
|---|
| 136 | this->fromLabel->TabIndex = 4; |
|---|
| 137 | this->fromLabel->Text = L"Move from:"; |
|---|
| 138 | // |
|---|
| 139 | // toLabel |
|---|
| 140 | // |
|---|
| 141 | this->toLabel->AutoSize = true; |
|---|
| 142 | this->toLabel->Location = System::Drawing::Point(172, 61); |
|---|
| 143 | this->toLabel->Name = L"toLabel"; |
|---|
| 144 | this->toLabel->Size = System::Drawing::Size(49, 13); |
|---|
| 145 | this->toLabel->TabIndex = 5; |
|---|
| 146 | this->toLabel->Text = L"Move to:"; |
|---|
| 147 | // |
|---|
| 148 | // textBoxFrom |
|---|
| 149 | // |
|---|
| 150 | this->textBoxFrom->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left) |
|---|
| 151 | | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 152 | this->textBoxFrom->Location = System::Drawing::Point(193, 28); |
|---|
| 153 | this->textBoxFrom->Name = L"textBoxFrom"; |
|---|
| 154 | this->textBoxFrom->Size = System::Drawing::Size(226, 20); |
|---|
| 155 | this->textBoxFrom->TabIndex = 6; |
|---|
| 156 | // |
|---|
| 157 | // textBoxTo |
|---|
| 158 | // |
|---|
| 159 | this->textBoxTo->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left) |
|---|
| 160 | | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 161 | this->textBoxTo->Location = System::Drawing::Point(193, 77); |
|---|
| 162 | this->textBoxTo->Name = L"textBoxTo"; |
|---|
| 163 | this->textBoxTo->Size = System::Drawing::Size(226, 20); |
|---|
| 164 | this->textBoxTo->TabIndex = 7; |
|---|
| 165 | // |
|---|
| 166 | // openBrowserBtn |
|---|
| 167 | // |
|---|
| 168 | this->openBrowserBtn->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 169 | this->openBrowserBtn->Location = System::Drawing::Point(425, 26); |
|---|
| 170 | this->openBrowserBtn->Name = L"openBrowserBtn"; |
|---|
| 171 | this->openBrowserBtn->Size = System::Drawing::Size(35, 23); |
|---|
| 172 | this->openBrowserBtn->TabIndex = 8; |
|---|
| 173 | this->openBrowserBtn->Text = L"..."; |
|---|
| 174 | this->openBrowserBtn->UseVisualStyleBackColor = true; |
|---|
| 175 | this->openBrowserBtn->Click += gcnew System::EventHandler(this, &SecureMove::openBrowserBtn_Click); |
|---|
| 176 | // |
|---|
| 177 | // saveBrowserBtn |
|---|
| 178 | // |
|---|
| 179 | this->saveBrowserBtn->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right)); |
|---|
| 180 | this->saveBrowserBtn->Location = System::Drawing::Point(425, 75); |
|---|
| 181 | this->saveBrowserBtn->Name = L"saveBrowserBtn"; |
|---|
| 182 | this->saveBrowserBtn->Size = System::Drawing::Size(35, 23); |
|---|
| 183 | this->saveBrowserBtn->TabIndex = 9; |
|---|
| 184 | this->saveBrowserBtn->Text = L"..."; |
|---|
| 185 | this->saveBrowserBtn->UseVisualStyleBackColor = true; |
|---|
| 186 | this->saveBrowserBtn->Click += gcnew System::EventHandler(this, &SecureMove::saveBrowserBtn_Click); |
|---|
| 187 | // |
|---|
| 188 | // openFileDialog1 |
|---|
| 189 | // |
|---|
| 190 | this->openFileDialog1->FileName = L"openFileDialog1"; |
|---|
| 191 | // |
|---|
| 192 | // start |
|---|
| 193 | // |
|---|
| 194 | this->start->Location = System::Drawing::Point(312, 155); |
|---|
| 195 | this->start->Name = L"start"; |
|---|
| 196 | this->start->Size = System::Drawing::Size(75, 23); |
|---|
| 197 | this->start->TabIndex = 10; |
|---|
| 198 | this->start->Text = L"&Start"; |
|---|
| 199 | this->start->UseVisualStyleBackColor = true; |
|---|
| 200 | this->start->Click += gcnew System::EventHandler(this, &SecureMove::start_Click); |
|---|
| 201 | // |
|---|
| 202 | // SecureMove |
|---|
| 203 | // |
|---|
| 204 | this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); |
|---|
| 205 | this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; |
|---|
| 206 | this->ClientSize = System::Drawing::Size(472, 186); |
|---|
| 207 | this->Controls->Add(this->start); |
|---|
| 208 | this->Controls->Add(this->saveBrowserBtn); |
|---|
| 209 | this->Controls->Add(this->openBrowserBtn); |
|---|
| 210 | this->Controls->Add(this->textBoxTo); |
|---|
| 211 | this->Controls->Add(this->textBoxFrom); |
|---|
| 212 | this->Controls->Add(this->toLabel); |
|---|
| 213 | this->Controls->Add(this->fromLabel); |
|---|
| 214 | this->Controls->Add(this->pictureBox1); |
|---|
| 215 | this->Controls->Add(this->cancel); |
|---|
| 216 | this->Controls->Add(this->progressBar1); |
|---|
| 217 | this->Name = L"SecureMove"; |
|---|
| 218 | this->Text = L"SecureMove"; |
|---|
| 219 | (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); |
|---|
| 220 | this->ResumeLayout(false); |
|---|
| 221 | this->PerformLayout(); |
|---|
| 222 | |
|---|
| 223 | } |
|---|
| 224 | #pragma endregion |
|---|
| 225 | |
|---|
| 226 | private: String ^dst; |
|---|
| 227 | private: String ^src; |
|---|
| 228 | void Move() |
|---|
| 229 | { |
|---|
| 230 | IO::FileStream ^sf, ^df; |
|---|
| 231 | int read = 0; |
|---|
| 232 | int progress = 0; |
|---|
| 233 | |
|---|
| 234 | // here it is best to do the move manually |
|---|
| 235 | // as we have to hold locks to the both of |
|---|
| 236 | // the files simultaniously. |
|---|
| 237 | try |
|---|
| 238 | { |
|---|
| 239 | try |
|---|
| 240 | { |
|---|
| 241 | sf = gcnew IO::FileStream(src, IO::FileMode::Open, |
|---|
| 242 | IO::FileAccess::Read, |
|---|
| 243 | IO::FileShare::None); |
|---|
| 244 | |
|---|
| 245 | df = gcnew IO::FileStream(dst, IO::FileMode::CreateNew, |
|---|
| 246 | IO::FileAccess::Write, |
|---|
| 247 | IO::FileShare::None); |
|---|
| 248 | |
|---|
| 249 | do |
|---|
| 250 | { |
|---|
| 251 | array<Byte,1> ^buffer = gcnew array<Byte,1>(65536); |
|---|
| 252 | read = sf->Read(buffer, 0, buffer->Length); |
|---|
| 253 | df->Write(buffer, 0, read); |
|---|
| 254 | progress = (sf->Position * 100) / sf->Length; |
|---|
| 255 | |
|---|
| 256 | } while((read != 0) && (sf->Position == sf->Length)); |
|---|
| 257 | |
|---|
| 258 | array<String^> ^src_array = gcnew array<String^>(1); |
|---|
| 259 | src_array[0] = src; |
|---|
| 260 | |
|---|
| 261 | // EraseFiles( src_array ); |
|---|
| 262 | } |
|---|
| 263 | catch(IO::IOException ^ex) |
|---|
| 264 | { |
|---|
| 265 | // some error handling |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | finally |
|---|
| 269 | { |
|---|
| 270 | sf->Close(); |
|---|
| 271 | df->Close(); |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | private: System::Void openBrowserBtn_Click(System::Object^ sender, System::EventArgs^ e) |
|---|
| 275 | { |
|---|
| 276 | if(openFileDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) |
|---|
| 277 | { |
|---|
| 278 | textBoxFrom->Text = openFileDialog1->FileName; |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | private: System::Void saveBrowserBtn_Click(System::Object^ sender, System::EventArgs^ e) |
|---|
| 282 | { |
|---|
| 283 | if(saveFileDialog1->ShowDialog() == Windows::Forms::DialogResult::OK) |
|---|
| 284 | { |
|---|
| 285 | textBoxTo->Text = saveFileDialog1->FileName; |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | private: System::Void updateUI() |
|---|
| 290 | { |
|---|
| 291 | if(state == RUNNING) |
|---|
| 292 | start->Text = L"&Pause"; |
|---|
| 293 | else |
|---|
| 294 | start->Text = L"&Start"; |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | private: System::Void start_Click(System::Object^ sender, System::EventArgs^ e) |
|---|
| 298 | { |
|---|
| 299 | if(state == RUNNING) |
|---|
| 300 | { |
|---|
| 301 | // pause |
|---|
| 302 | if(thread->ThreadState != ThreadState::Aborted) |
|---|
| 303 | thread->Suspend(); |
|---|
| 304 | } |
|---|
| 305 | else if(state == NOT_RUNNING) |
|---|
| 306 | { |
|---|
| 307 | // start |
|---|
| 308 | if(thread->ThreadState == ThreadState::Stopped) |
|---|
| 309 | { |
|---|
| 310 | // resume |
|---|
| 311 | thread->Resume(); |
|---|
| 312 | thread->Start(); |
|---|
| 313 | } |
|---|
| 314 | else if(thread->ThreadState == ThreadState::Aborted || |
|---|
| 315 | thread->ThreadState == ThreadState::Unstarted) |
|---|
| 316 | { |
|---|
| 317 | // start a new thread |
|---|
| 318 | thread = gcnew System::Threading::Thread |
|---|
| 319 | ( |
|---|
| 320 | gcnew ThreadStart( gcnew Object( this ), |
|---|
| 321 | gcnew IntPtr( Move ) ) |
|---|
| 322 | ); |
|---|
| 323 | |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | updateUI(); |
|---|
| 327 | |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | private: static const bool RUNNING = true; |
|---|
| 331 | private: static const bool NOT_RUNNING = false; |
|---|
| 332 | private: bool state; |
|---|
| 333 | private: System::Threading::Thread ^thread ; |
|---|
| 334 | }; |
|---|
| 335 | } |
|---|