QuickImage – Diff between revs 9 and 10

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 9 Rev 10
Line 2420... Line 2420...
2420 for (var i = 0; i < fileNames.Length; ++i) 2420 for (var i = 0; i < fileNames.Length; ++i)
2421 { 2421 {
2422 var memoryStream = data.GetFileContent(i); 2422 var memoryStream = data.GetFileContent(i);
2423 memoryStream.Position = 0L; 2423 memoryStream.Position = 0L;
Line -... Line 2424...
-   2424  
-   2425 MagicMimeFile mime;
-   2426 try
2424   2427 {
2425 var mime = magicMime.Identify(fileNames[i], memoryStream, cancellationToken); 2428 mime = magicMime.Identify(fileNames[i], memoryStream, cancellationToken);
2426   2429  
-   2430 if (mime == null)
-   2431 {
-   2432 continue;
-   2433 }
-   2434 }
2427 if (mime == null) 2435 catch(Exception exception)
-   2436 {
-   2437 Log.Error(exception, $"Could not determine mime type for file {fileNames[i]}.");
2428 { 2438  
2429 continue; 2439 continue;
Line 2430... Line 2440...
2430 } 2440 }
2431   2441  
Line 2454... Line 2464...
2454 if (!File.Exists(directoryFile)) 2464 if (!File.Exists(directoryFile))
2455 { 2465 {
2456 continue; 2466 continue;
2457 } 2467 }
Line 2458... Line 2468...
2458   2468  
Line 2459... Line 2469...
2459 string fileMimeType = await magicMime.GetMimeType(directoryFile, cancellationToken); 2469 var fileMimeType = await magicMime.GetMimeType(directoryFile, cancellationToken);
2460   2470  
2461 if (!configuration.SupportedFormats.IsSupported(fileMimeType)) 2471 if (!configuration.SupportedFormats.IsSupported(fileMimeType))
2462 { 2472 {
Line 2467... Line 2477...
2467 } 2477 }
Line 2468... Line 2478...
2468   2478  
2469 return; 2479 return;
Line 2470... Line 2480...
2470 } 2480 }
2471   2481  
2472 string entryMimeType = await magicMime.GetMimeType(entry, cancellationToken); 2482 var entryMimeType = await magicMime.GetMimeType(entry, cancellationToken);
2473 if (!configuration.SupportedFormats.IsSupported(entryMimeType)) 2483 if (!configuration.SupportedFormats.IsSupported(entryMimeType))
2474 { 2484 {
Line 3124... Line 3134...
3124 if (_editorForm != null) 3134 if (_editorForm != null)
3125 { 3135 {
3126 return; 3136 return;
3127 } 3137 }
Line -... Line 3138...
-   3138  
-   3139 try
3128   3140 {
3129 var mime = await _magicMime.GetMimeType(item.Name, _cancellationToken); 3141 var mime = await _magicMime.GetMimeType(item.Name, _cancellationToken);
3130 switch (mime) 3142 switch (mime)
3131 { 3143 {
3132 case "IMAGE/JPEG": 3144 case "IMAGE/JPEG":
3133 case "IMAGE/PNG": 3145 case "IMAGE/PNG":
3134 case "IMAGE/BMP": 3146 case "IMAGE/BMP":
3135 break; 3147 break;
-   3148 default:
-   3149 this.InvokeIfRequired(form =>
3136 default: 3150 {
-   3151 form.toolStripStatusLabel1.Text = $"Image format not supported for file {item.Name}";
3137 toolStripStatusLabel1.Text = $"Image format not supported for file {item.Name}"; 3152 });
-   3153 return;
-   3154 }
-   3155 }
-   3156 catch(Exception exception)
-   3157 {
-   3158 Log.Error(exception, $"Could not deterine image format for file {item.Name}");
3138 return; 3159 return;
Line 3139... Line 3160...
3139 } 3160 }
3140   3161  
3141 _editorForm = new EditorForm(item.Name, Configuration, _magicMime, _cancellationToken); 3162 _editorForm = new EditorForm(item.Name, Configuration, _magicMime, _cancellationToken);
Line 3452... Line 3473...
3452   3473  
3453 var inputBlock = new BufferBlock<ListViewItem>(new DataflowBlockOptions { CancellationToken = _cancellationToken }); 3474 var inputBlock = new BufferBlock<ListViewItem>(new DataflowBlockOptions { CancellationToken = _cancellationToken });
3454 var fileTransformBlock = 3475 var fileTransformBlock =
3455 new TransformBlock<ListViewItem, (string Source, string Path, string Name, string Mime, string Extension)>(async item => 3476 new TransformBlock<ListViewItem, (string Source, string Path, string Name, string Mime, string Extension)>(async item =>
-   3477 {
-   3478 string mimeType = string.Empty;
-   3479 try
3456 { 3480 {
-   3481 mimeType = await _magicMime.GetMimeType(item.Name, _cancellationToken);
-   3482 }
-   3483 catch (Exception exception)
-   3484 {
-   3485 Log.Error(exception, $"Could not determine image type for file {item.Name}");
3457 var mime = await _magicMime.GetMimeType(item.Name, _cancellationToken); 3486 }
3458   3487  
3459 var extension = Path.GetExtension(item.Name); 3488 var extension = Path.GetExtension(item.Name);
3460 var path = Path.GetTempPath(); 3489 var path = Path.GetTempPath();
3461 var file = Path.GetFileNameWithoutExtension(item.Name); 3490 var file = Path.GetFileNameWithoutExtension(item.Name);
3462 if (Configuration.OutboundDragDrop.RenameOnDragDrop) 3491 if (Configuration.OutboundDragDrop.RenameOnDragDrop)
3463 { 3492 {
3464 switch (Configuration.OutboundDragDrop.DragDropRenameMethod) 3493 switch (Configuration.OutboundDragDrop.DragDropRenameMethod)
3465 { 3494 {
3466 case DragDropRenameMethod.Random: 3495 case DragDropRenameMethod.Random:
3467 file = string.Join("", Enumerable.Repeat(0, 5).Select(n => (char)_random.Next('a', 'z' + 1))); 3496 file = string.Join("", Enumerable.Repeat(0, 5).Select(n => (char)_random.Next('a', 'z' + 1)));
3468 break; 3497 break;
3469 case DragDropRenameMethod.Timestamp: 3498 case DragDropRenameMethod.Timestamp:
3470 file = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}"; 3499 file = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}";
3471 break; 3500 break;
3472 } 3501 }
3473 } 3502 }
3474   3503  
3475 this.InvokeIfRequired(form => 3504 this.InvokeIfRequired(form =>
3476 { 3505 {
3477 form.toolStripStatusLabel1.Text = $"File {item.Name} scanned for drag and drop..."; 3506 form.toolStripStatusLabel1.Text = $"File {item.Name} scanned for drag and drop...";
3478 }); 3507 });
3479   3508  
-   3509 return (Source: item.Name, Path: path, Name: file, Mime: mimeType, Extension: extension);
-   3510  
3480 return (Source: item.Name, Path: path, Name: file, Mime: mime, Extension: extension); 3511  
Line 3481... Line 3512...
3481 }, new ExecutionDataflowBlockOptions { CancellationToken = _cancellationToken }); 3512 }, new ExecutionDataflowBlockOptions { CancellationToken = _cancellationToken });
3482   3513  
3483 #pragma warning disable CS4014 3514 #pragma warning disable CS4014
Line 4105... Line 4136...
4105 using var memoryStream = new MemoryStream(); 4136 using var memoryStream = new MemoryStream();
4106 using var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read); 4137 using var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
4107 await fileStream.CopyToAsync(memoryStream); 4138 await fileStream.CopyToAsync(memoryStream);
4108 memoryStream.Position = 0L; 4139 memoryStream.Position = 0L;
Line -... Line 4140...
-   4140  
-   4141 MagicMimeFile mime;
-   4142 try
4109   4143 {
-   4144 mime = _magicMime.Identify(file, memoryStream, _cancellationToken);
-   4145  
-   4146 if (mime == null)
-   4147 {
-   4148 break;
-   4149 }
-   4150 }
-   4151 catch (Exception exception)
-   4152 {
-   4153 Log.Error(exception, $"Could not determine mime type for file {file}.");
-   4154  
-   4155 break;
-   4156 }
4110 var mime = _magicMime.Identify(file, memoryStream, _cancellationToken); 4157  
4111 if (Configuration.SupportedFormats.IsSupportedVideo(mime.Definition.File.MimeType)) 4158 if (Configuration.SupportedFormats.IsSupportedVideo(mime.Definition.File.MimeType))
Line 4112... Line 4159...
4112 { 4159 {