More Cleaning
fdd38981
Aaron Campf
committed
8 changed files
ArchiveDetailView.cs
/BExplorer/BetterExplorer/ArchiveView/ArchiveDetailView.cs
/BExplorer/BetterExplorer/ArchiveView/ArchiveDetailView.cs
ArchiveProcressScreen.cs
/BExplorer/BetterExplorer/ArchiveView/ArchiveProcressScreen.cs-56+111
/BExplorer/BetterExplorer/ArchiveView/ArchiveProcressScreen.cs
Add comment 7 //using Microsoft.WindowsAPICodePack.Dialogs;
Add comment 8 using SevenZip;
Add comment 9
Add comment 10 Minus  namespace BetterExplorer {
Add comment 10 Plus  namespace BetterExplorer
Add comment 11 Plus  {
Add comment 11 12
Add comment 12 Minus   public partial class ArchiveProcressScreen : Form {
Add comment 13 Plus   public partial class ArchiveProcressScreen : Form
Add comment 14 Plus   {
Add comment 13 15 private string tempPath;
Add comment 14 16 private readonly IList<string> _fileAndDirectoryFullPaths;
Add comment 15 17 private readonly string _archivePath;
Add comment 43 45 /// <param name="fastcompression">If you whan to compresss the files fast(only for compression)</param>
Add comment 44 46 /// <param name="password">(only for compression and if required)</param>
Add comment 45 47 /// <param name="compresstionlevel">How strong must the compression be (only for compression)</param>
Add comment 46 Minus   public ArchiveProcressScreen(IList<String> fileAndDirectoryFullPaths, string archivefullPath, ArchiveAction action, string archivename = null, OutArchiveFormat format = OutArchiveFormat.SevenZip, bool fastcompression = false, string password = null, CompressionLevel compresstionlevel = CompressionLevel.Normal) {
Add comment 48 Plus   public ArchiveProcressScreen(IList<String> fileAndDirectoryFullPaths, string archivefullPath, ArchiveAction action, string archivename = null, OutArchiveFormat format = OutArchiveFormat.SevenZip, bool fastcompression = false, string password = null, CompressionLevel compresstionlevel = CompressionLevel.Normal)
Add comment 49 Plus   {
Add comment 47 50 SevenZipBase.SetLibraryPath(IntPtr.Size == 8 ? "7z64.dll" : "7z32.dll");
Add comment 48 51 InitializeComponent();
Add comment 49 52 _fileAndDirectoryFullPaths = fileAndDirectoryFullPaths;
Add comment 55 58 _password = password;
Add comment 56 59 _fastcompression = fastcompression;
Add comment 57 60 _deltatotaal = pb_totaalfiles.Value += (int)(100 / fileAndDirectoryFullPaths.Count);
Add comment 58 Minus   tempPath = string.Format("{0}//7zip//", Path.GetTempPath());
Add comment 61 Plus   tempPath = $"{Path.GetTempPath()}//7zip//";
Add comment 59 62
Add comment 60 63 pb_compression.Value = 0;
Add comment 61 64 pb_totaalfiles.Value = 0;
Add comment 62 65 }
Add comment 63 66
Add comment 64 Minus   private void RemoveFile() {
Add comment 65 Minus   try {
Add comment 67 Plus   private void RemoveFile()
Add comment 68 Plus   {
Add comment 69 Plus   try
Add comment 70 Plus   {
Add comment 66 71 _sevenZipExtractor = new SevenZipExtractor(_archivePath);
Add comment 67 72 _sevenZipCompressor = new SevenZipCompressor(tempPath);
Add comment 68 73 _sevenZipCompressor.DirectoryStructure = true;
Add comment 75 80 _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;
Add comment 76 81
Add comment 77 82 var fileIndexDictionary = new Dictionary<int, string>();
Add comment 78 Minus   foreach (ArchiveFileInfo archiveFileInfo in _sevenZipExtractor.ArchiveFileData) {
Add comment 79 Minus   if (!archiveFileInfo.IsDirectory && _fileAndDirectoryFullPaths.Contains(archiveFileInfo.FileName)) {
Add comment 83 Plus   foreach (ArchiveFileInfo archiveFileInfo in _sevenZipExtractor.ArchiveFileData)
Add comment 84 Plus   {
Add comment 85 Plus   if (!archiveFileInfo.IsDirectory && _fileAndDirectoryFullPaths.Contains(archiveFileInfo.FileName))
Add comment 86 Plus   {
Add comment 80 87 fileIndexDictionary.Add(archiveFileInfo.Index, null);
Add comment 81 88 }
Add comment 82 89 }
Add comment 84 91 _sevenZipCompressor.ModifyArchive(_archivePath, fileIndexDictionary);
Add comment 85 92 Done();
Add comment 86 93 }
Add comment 87 Minus   catch (Exception ex) {
Add comment 94 Plus   catch (Exception ex)
Add comment 95 Plus   {
Add comment 88 96 /*
Add comment 89 97 var dialog = new TaskDialog();
Add comment 90 98 dialog.StandardButtons = TaskDialogStandardButtons.Ok;
Add comment 95 103 }
Add comment 96 104 }
Add comment 97 105
Add comment 98 Minus   private void Extract() {
Add comment 106 Plus   private void Extract()
Add comment 107 Plus   {
Add comment 99 108 //setup settings.
Add comment 100 Minus   foreach (var fullPath in _fileAndDirectoryFullPaths) {
Add comment 109 Plus   foreach (var fullPath in _fileAndDirectoryFullPaths)
Add comment 110 Plus   {
Add comment 101 111 _sevenZipExtractor = new SevenZipExtractor(fullPath);
Add comment 102 112 _sevenZipExtractor.PreserveDirectoryStructure = true;
Add comment 103 113
Add comment 115 125
Add comment 116 126 private delegate void FileInfoEvent(object sender, FileInfoEventArgs e);
Add comment 117 127
Add comment 118 Minus   private void FileExtractionFinished(object sender, FileInfoEventArgs e) {
Add comment 128 Plus   private void FileExtractionFinished(object sender, FileInfoEventArgs e)
Add comment 129 Plus   {
Add comment 119 130 //pb_totaalfiles.Invoke(new FileInfoEvent((object o, FileInfoEventArgs l) =>
Add comment 120 131 //{
Add comment 121 132 // pb_totaalfiles.Value += (int)(100 / _sevenZipExtractor.FilesCount);
Add comment 122 133 //}),sender,e);
Add comment 123 134
Add comment 124 Minus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) => {
Add comment 135 Plus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) =>
Add comment 136 Plus   {
Add comment 125 137 pb_compression.Value = 100;
Add comment 126 138 }), sender, e);
Add comment 127 139 }
Add comment 128 140
Add comment 129 Minus   private void FileExtractionStarted(object sender, FileInfoEventArgs e) {
Add comment 141 Plus   private void FileExtractionStarted(object sender, FileInfoEventArgs e)
Add comment 142 Plus   {
Add comment 130 143 //when the next file is being compressed.
Add comment 131 Minus   lbl_commpressing_file.Invoke(new FileInfoEvent((object o, FileInfoEventArgs l) => {
Add comment 144 Plus   lbl_commpressing_file.Invoke(new FileInfoEvent((object o, FileInfoEventArgs l) =>
Add comment 145 Plus   {
Add comment 132 146 lbl_commpressing_file.Text = String.Format(_commpressingFileName, l.FileInfo.FileName);
Add comment 133 147 }), sender, e);
Add comment 134 148
Add comment 135 Minus   pb_totaalfiles.Invoke(new FileInfoEvent((object o, FileInfoEventArgs l) => {
Add comment 149 Plus   pb_totaalfiles.Invoke(new FileInfoEvent((object o, FileInfoEventArgs l) =>
Add comment 150 Plus   {
Add comment 136 151 pb_totaalfiles.Value = l.PercentDone;
Add comment 137 152 }), sender, e);
Add comment 138 153
Add comment 139 Minus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) => {
Add comment 154 Plus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) =>
Add comment 155 Plus   {
Add comment 140 156 pb_compression.Value = 0;
Add comment 141 157 }), sender, e);
Add comment 142 158 }
Add comment 143 159
Add comment 144 160 private long bytesoffiles = 0;
Add comment 145 161
Add comment 146 Minus   private void Compress() {
Add comment 162 Plus   private void Compress()
Add comment 163 Plus   {
Add comment 147 164 //setup settings.
Add comment 148 Minus   try {
Add comment 165 Plus   try
Add comment 166 Plus   {
Add comment 149 167 _sevenZipCompressor = new SevenZipCompressor(tempPath);
Add comment 150 168 _sevenZipCompressor.ArchiveFormat = _format;
Add comment 151 169 _sevenZipCompressor.CompressionMethod = CompressionMethod.Default;
Add comment 160 178 _sevenZipCompressor.CompressionFinished += CompressionFinished;
Add comment 161 179 _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;
Add comment 162 180
Add comment 163 Minus   try {
Add comment 164 Minus   if (_password != null) {
Add comment 165 Minus   for (int i = 0; i < _fileAndDirectoryFullPaths.Count; i++) {
Add comment 181 Plus   try
Add comment 182 Plus   {
Add comment 183 Plus   if (_password != null)
Add comment 184 Plus   {
Add comment 185 Plus   for (int i = 0; i < _fileAndDirectoryFullPaths.Count; i++)
Add comment 186 Plus   {
Add comment 166 187 if (!Directory.Exists(_fileAndDirectoryFullPaths[i]))
Add comment 167 188 continue;
Add comment 168 189
Add comment 169 190 //Compress directories
Add comment 170 191 var strings = _fileAndDirectoryFullPaths[i].Split('/');
Add comment 171 Minus   if (_fileAndDirectoryFullPaths.Count == 1) {
Add comment 192 Plus   if (_fileAndDirectoryFullPaths.Count == 1)
Add comment 193 Plus   {
Add comment 172 194 _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
Add comment 173 195 String.Format("{0}/{1}.{2}",
Add comment 174 196 _archivePath,
Add comment 175 197 _archivename,
Add comment 176 198 SelectExtention(_format)));
Add comment 177 199 }
Add comment 178 Minus   else {
Add comment 200 Plus   else
Add comment 201 Plus   {
Add comment 179 202 _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
Add comment 180 203 String.Format("{0}/{1}_{3}.{2}",
Add comment 181 204 _archivePath,
Add comment 190 213 _fileAndDirectoryFullPaths.Remove(_fileAndDirectoryFullPaths[i]);
Add comment 191 214 }
Add comment 192 215 //compress files
Add comment 193 Minus   if (_fileAndDirectoryFullPaths.Count > 0) {
Add comment 216 Plus   if (_fileAndDirectoryFullPaths.Count > 0)
Add comment 217 Plus   {
Add comment 194 218 _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;
Add comment 195 219 _sevenZipCompressor.CompressFilesEncrypted(
Add comment 196 220 String.Format("{0}/{1}.{2}",
Add comment 201 225 _fileAndDirectoryFullPaths.ToArray());
Add comment 202 226 }
Add comment 203 227 }
Add comment 204 Minus   else {
Add comment 228 Plus   else
Add comment 229 Plus   {
Add comment 205 230 for (int i = 0; i < _fileAndDirectoryFullPaths.Count; i++)
Add comment 206 231 //var fullPath in _fileAndDirectoryFullPaths)
Add comment 207 232 {
Add comment 213 238
Add comment 214 239 //Compress directorys
Add comment 215 240 var strings = _fileAndDirectoryFullPaths[i].Split('/');
Add comment 216 Minus   if (_fileAndDirectoryFullPaths.Count == 1) {
Add comment 241 Plus   if (_fileAndDirectoryFullPaths.Count == 1)
Add comment 242 Plus   {
Add comment 217 243 _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
Add comment 218 244 String.Format("{0}/{1}.{2}",
Add comment 219 245 _archivePath,
Add comment 220 246 _archivename,
Add comment 221 247 SelectExtention(_format)));
Add comment 222 248 }
Add comment 223 Minus   else {
Add comment 249 Plus   else
Add comment 250 Plus   {
Add comment 224 251 _sevenZipCompressor.CompressDirectory(_fileAndDirectoryFullPaths[i],
Add comment 225 252 String.Format("{0}/{1}_{3}.{2}",
Add comment 226 253 _archivePath,
Add comment 237 264 _fileAndDirectoryFullPaths.Remove(_fileAndDirectoryFullPaths[i]);
Add comment 238 265 }
Add comment 239 266 //compress files.
Add comment 240 Minus   if (_fileAndDirectoryFullPaths.Count > 0) {
Add comment 267 Plus   if (_fileAndDirectoryFullPaths.Count > 0)
Add comment 268 Plus   {
Add comment 241 269 _sevenZipCompressor.FileCompressionFinished += FileCompressionFinished;
Add comment 242 270 _sevenZipCompressor.CompressFiles(
Add comment 243 271 String.Format("{0}/{1}.{2}",
Add comment 251 279 pb_totaalfiles.Invoke(new InvokeNone(() => { pb_totaalfiles.Value = 100; }));
Add comment 252 280 Done();
Add comment 253 281 }
Add comment 254 Minus   catch (ThreadInterruptedException) {
Add comment 282 Plus   catch (ThreadInterruptedException)
Add comment 283 Plus   {
Add comment 255 284 Dispose(true);
Add comment 256 285 }
Add comment 257 286 }
Add comment 258 Minus   catch (Exception ex) {
Add comment 287 Plus   catch (Exception ex)
Add comment 288 Plus   {
Add comment 259 289 /*
Add comment 260 290 var dialog = new TaskDialog();
Add comment 261 291 dialog.StandardButtons = TaskDialogStandardButtons.Ok;
Add comment 267 297
Add comment 268 298 public delegate void InvokeNone();
Add comment 269 299
Add comment 270 Minus   private void Done() {
Add comment 271 Minus   btn_cancel.Invoke(new InvokeNone(() => {
Add comment 300 Plus   private void Done()
Add comment 301 Plus   {
Add comment 302 Plus   btn_cancel.Invoke(new InvokeNone(() =>
Add comment 303 Plus   {
Add comment 272 304 btn_cancel.Click -= CancelCompression;
Add comment 273 305 btn_cancel.Click += Close;
Add comment 274 306 btn_cancel.Text = "Close";
Add comment 278 310 }));
Add comment 279 311 }
Add comment 280 312
Add comment 281 Minus   private string SelectExtention(OutArchiveFormat format) {
Add comment 282 Minus   switch (format) {
Add comment 313 Plus   private string SelectExtention(OutArchiveFormat format)
Add comment 314 Plus   {
Add comment 315 Plus   switch (format)
Add comment 316 Plus   {
Add comment 283 317 case OutArchiveFormat.Zip:
Add comment 284 318 return OutArchiveFormat.Zip.ToString().ToLower();
Add comment 285 319
Add comment 304 338
Add comment 305 339 public delegate void InvokeEvent(object sender, EventArgs e);
Add comment 306 340
Add comment 307 Minus   private void FileCompressionFinished(object sender, EventArgs e) {
Add comment 341 Plus   private void FileCompressionFinished(object sender, EventArgs e)
Add comment 342 Plus   {
Add comment 308 343 pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) => { pb_compression.Value = 100; }), sender, e);
Add comment 309 344 }
Add comment 310 345
Add comment 311 Minus   private void CompressionFinished(object sender, EventArgs e) {
Add comment 346 Plus   private void CompressionFinished(object sender, EventArgs e)
Add comment 347 Plus   {
Add comment 312 348 bool isExtract = (_action == ArchiveAction.Extract);
Add comment 313 349 pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) => { pb_compression.Value = 100; }), sender, e);
Add comment 314 Minus   lbl_commpressing_file.Invoke(new InvokeEvent((object o, EventArgs el) => {
Add comment 350 Plus   lbl_commpressing_file.Invoke(new InvokeEvent((object o, EventArgs el) =>
Add comment 351 Plus   {
Add comment 315 352 lbl_commpressing_file.Text = isExtract ? "Extracting Complete!" : "Compressing Complete!";
Add comment 316 353 }), sender, e);
Add comment 317 Minus   if (isExtract == true) {
Add comment 354 Plus   if (isExtract == true)
Add comment 355 Plus   {
Add comment 318 356 Done();
Add comment 319 357 ExtractionCompleted(sender, new ArchiveEventArgs(_archivePath));
Add comment 320 358 }
Add comment 321 Minus   else {
Add comment 359 Plus   else
Add comment 360 Plus   {
Add comment 322 361 CompressionCompleted(sender, new ArchiveEventArgs(_archivePath));
Add comment 323 362 }
Add comment 324 363
Add comment 330 369
Add comment 331 370 private delegate void ProgressEvent(object sender, ProgressEventArgs e);
Add comment 332 371
Add comment 333 Minus   private void Compressing(object sender, ProgressEventArgs e) {
Add comment 334 Minus   foreach (string item in _fileAndDirectoryFullPaths) {
Add comment 335 Minus   if (item.EndsWith(CurFileString)) {
Add comment 372 Plus   private void Compressing(object sender, ProgressEventArgs e)
Add comment 373 Plus   {
Add comment 374 Plus   foreach (string item in _fileAndDirectoryFullPaths)
Add comment 375 Plus   {
Add comment 376 Plus   if (item.EndsWith(CurFileString))
Add comment 377 Plus   {
Add comment 336 378 CurrentFile = new FileInfo(item);
Add comment 337 379 }
Add comment 338 380 }
Add comment 339 381
Add comment 340 382 //increes percentage from progressbar.
Add comment 341 Minus   pb_compression.Invoke(new ProgressEvent((object o, ProgressEventArgs l) => {
Add comment 383 Plus   pb_compression.Invoke(new ProgressEvent((object o, ProgressEventArgs l) =>
Add comment 384 Plus   {
Add comment 342 385 int FileProcentDone = (int)(((float)l.PercentDelta / (float)CurrentFile.Length) * 100);
Add comment 343 386 pb_compression.Value += FileProcentDone;
Add comment 344 387 }), sender, e);
Add comment 350 393
Add comment 351 394 private delegate void FileEvent(object sender, FileNameEventArgs e);
Add comment 352 395
Add comment 353 Minus   private void FileCompressionStarted(object sender, FileNameEventArgs e) {
Add comment 396 Plus   private void FileCompressionStarted(object sender, FileNameEventArgs e)
Add comment 397 Plus   {
Add comment 354 398 e.Cancel = IsCancel;
Add comment 355 399 inte++;
Add comment 356 400 CurFileString = e.FileName;
Add comment 357 401 //when the next file is being compressed.
Add comment 358 Minus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) => {
Add comment 402 Plus   pb_compression.Invoke(new InvokeEvent((object o, EventArgs l) =>
Add comment 403 Plus   {
Add comment 359 404 pb_compression.Value = 0;
Add comment 360 405 }), sender, e);
Add comment 361 406
Add comment 362 Minus   lbl_commpressing_file.Invoke(new FileEvent((object o, FileNameEventArgs l) => {
Add comment 407 Plus   lbl_commpressing_file.Invoke(new FileEvent((object o, FileNameEventArgs l) =>
Add comment 408 Plus   {
Add comment 363 409 lbl_commpressing_file.Text = String.Format(_commpressingFileName, l.FileName);
Add comment 364 410 }), sender, e);
Add comment 365 411
Add comment 366 Minus   pb_totaalfiles.Invoke(new FileEvent((object o, FileNameEventArgs l) => {
Add comment 412 Plus   pb_totaalfiles.Invoke(new FileEvent((object o, FileNameEventArgs l) =>
Add comment 413 Plus   {
Add comment 367 414 pb_totaalfiles.Value = l.PercentDone;
Add comment 368 415 }), sender, e);
Add comment 369 416 }
Add comment 370 417
Add comment 371 418 private bool IsCancel = false;
Add comment 372 419
Add comment 373 Minus   public void CancelCompression(object sender, EventArgs e) {
Add comment 420 Plus   public void CancelCompression(object sender, EventArgs e)
Add comment 421 Plus   {
Add comment 374 422 _thread.Abort();
Add comment 375 423
Add comment 376 424 IsCancel = true;
Add comment 381 429 //}
Add comment 382 430 }
Add comment 383 431
Add comment 384 Minus   public void Close(object sender, EventArgs e) {
Add comment 432 Plus   public void Close(object sender, EventArgs e)
Add comment 433 Plus   {
Add comment 385 434 Dispose(true);
Add comment 386 435 }
Add comment 387 436
Add comment 388 Minus   private void ArchiveProcressScreen_Shown(object sender, EventArgs e) {
Add comment 389 Minus   switch (_action) {
Add comment 437 Plus   private void ArchiveProcressScreen_Shown(object sender, EventArgs e)
Add comment 438 Plus   {
Add comment 439 Plus   switch (_action)
Add comment 440 Plus   {
Add comment 390 441 case ArchiveAction.Compress:
Add comment 391 442 _commpressingFileName = "Compressing \"{0}\"";
Add comment 392 443 lbl_compressing_to.Text = String.Format("Compressing to \"{0}\"", _archivePath);
Add comment 412 463 _thread.Start();
Add comment 413 464 }
Add comment 414 465
Add comment 415 Minus   private void _thread_ThreadException(SafeThread thrd, Exception ex) {
Add comment 466 Plus   private void _thread_ThreadException(SafeThread thrd, Exception ex)
Add comment 467 Plus   {
Add comment 416 468 }
Add comment 417 469 }
Add comment 418 470
Add comment 419 Minus   public class ArchiveEventArgs {
Add comment 471 Plus   public class ArchiveEventArgs
Add comment 472 Plus   {
Add comment 420 473
Add comment 421 474 public string OutputLocation { get; private set; }
Add comment 422 475
Add comment 423 476
Add comment 424 Minus   public ArchiveEventArgs(string output) {
Add comment 477 Plus   public ArchiveEventArgs(string output)
Add comment 478 Plus   {
Add comment 425 479 OutputLocation = output;
Add comment 426 480 }
Add comment 427 481
Add comment 428 482
Add comment 429 483 }
Add comment 430 484
Add comment 431 Minus   public enum ArchiveAction {
Add comment 485 Plus   public enum ArchiveAction
Add comment 486 Plus   {
Add comment 432 487 Compress,
Add comment 433 488 Extract,
Add comment 434 489 RemoveFile
PathStringCombiner.cs
/BExplorer/BetterExplorer/HelperClasses/PathStringCombiner.cs
/BExplorer/BetterExplorer/HelperClasses/PathStringCombiner.cs
App.xaml.cs
/BExplorer/BetterExplorer/App.xaml.cs
/BExplorer/BetterExplorer/App.xaml.cs
FolderSizeWindow.xaml.cs
/BExplorer/BetterExplorer/FolderSizeWindow.xaml.cs
/BExplorer/BetterExplorer/FolderSizeWindow.xaml.cs
MainWindow.xaml.cs
/BExplorer/BetterExplorer/MainWindow.xaml.cs
/BExplorer/BetterExplorer/MainWindow.xaml.cs
ResizeImage.xaml.cs
/BExplorer/BetterExplorer/ResizeImage.xaml.cs
/BExplorer/BetterExplorer/ResizeImage.xaml.cs
UnitTest1.vb
/TestProject/UnitTest1.vb
/TestProject/UnitTest1.vb