QuickImage – Diff between revs 1 and 2
?pathlinks?
Rev 1 | Rev 2 | |||
---|---|---|---|---|
Line 15... | Line 15... | |||
15 | using System.Threading.Tasks; |
15 | using System.Threading.Tasks; |
|
16 | using System.Threading.Tasks.Dataflow; |
16 | using System.Threading.Tasks.Dataflow; |
|
17 | using System.Windows.Forms; |
17 | using System.Windows.Forms; |
|
18 | using Configuration; |
18 | using Configuration; |
|
19 | using ImageMagick; |
19 | using ImageMagick; |
|
- | 20 | using ImageMagick.Factories; |
||
20 | using Microsoft.WindowsAPICodePack.Dialogs; |
21 | using Microsoft.WindowsAPICodePack.Dialogs; |
|
21 | using MimeDetective.Storage; |
22 | using MimeDetective.Storage; |
|
22 | using NetSparkleUpdater; |
23 | using NetSparkleUpdater; |
|
23 | using NetSparkleUpdater.Enums; |
24 | using NetSparkleUpdater.Enums; |
|
24 | using NetSparkleUpdater.SignatureVerifiers; |
25 | using NetSparkleUpdater.SignatureVerifiers; |
|
Line 161... | Line 162... | |||
161 | _sparkle = new SparkleUpdater("https://quickimage.grimore.org/update/appcast.xml", |
162 | _sparkle = new SparkleUpdater("https://quickimage.grimore.org/update/appcast.xml", |
|
162 | new Ed25519Checker(SecurityMode.Strict, "LonrgxVjSF0GnY4hzwlRJnLkaxnDn2ikdmOifILzLJY=")) |
163 | new Ed25519Checker(SecurityMode.Strict, "LonrgxVjSF0GnY4hzwlRJnLkaxnDn2ikdmOifILzLJY=")) |
|
163 | { |
164 | { |
|
164 | UIFactory = new UIFactory(icon), |
165 | UIFactory = new UIFactory(icon), |
|
165 | RelaunchAfterUpdate = true, |
166 | RelaunchAfterUpdate = true, |
|
166 | SecurityProtocolType = SecurityProtocolType.Tls12, |
167 | //SecurityProtocolType = SecurityProtocolType.Tls12, |
|
167 | ShowsUIOnMainThread = false, |
168 | //ShowsUIOnMainThread = false, |
|
168 | LogWriter = new LogWriter(true) |
169 | LogWriter = new LogWriter(LogWriterOutputMode.None) |
|
169 | }; |
170 | }; |
|
170 | _sparkle.StartLoop(true, true); |
171 | _sparkle.StartLoop(true, true); |
|
Line 171... | Line 172... | |||
171 | |
172 | |
|
172 | _quickImageDatabase = new QuickImageDatabase(_cancellationToken); |
173 | _quickImageDatabase = new QuickImageDatabase(_cancellationToken); |
|
Line 1784... | Line 1785... | |||
1784 | |
1785 | |
|
1785 | try |
1786 | try |
|
1786 | { |
1787 | { |
|
Line 1787... | Line 1788... | |||
1787 | var mime = await magicMime.GetMimeType(item.Name, cancellationToken); |
1788 | var mime = await magicMime.GetMimeType(item.Name, cancellationToken); |
|
- | 1789 | |
||
1788 | |
1790 | if (Configuration.SupportedFormats.IsSupportedImage(mime)) |
|
1789 | if (Configuration.SupportedFormats.IsSupportedImage(mime)) |
1791 | { |
|
1790 | if (!await _tagManager.AddIptcKeywords(item.Name, keywords, cancellationToken)) |
1792 | if (!await _tagManager.AddIptcKeywords(item.Name, keywords, cancellationToken)) |
|
1791 | { |
1793 | { |
|
1792 | progress.Report(new ImageListViewItemProgressFailure<ListViewItem>(item, |
1794 | progress.Report(new ImageListViewItemProgressFailure<ListViewItem>(item, |
|
1793 | new ArgumentException(MethodBase.GetCurrentMethod()?.Name))); |
1795 | new ArgumentException(MethodBase.GetCurrentMethod()?.Name))); |
|
- | 1796 | continue; |
||
Line 1794... | Line 1797... | |||
1794 | continue; |
1797 | } |
|
1795 | } |
1798 | } |
|
1796 | |
1799 | |
|
1797 | if (!await _quickImageDatabase.AddTagsAsync(item.Name, keywords, cancellationToken)) |
1800 | if (!await _quickImageDatabase.AddTagsAsync(item.Name, keywords, cancellationToken)) |
|
Line 2182... | Line 2185... | |||
2182 | catch (Exception exception) |
2185 | catch (Exception exception) |
|
2183 | { |
2186 | { |
|
2184 | Log.Error(exception, "Could not identify file."); |
2187 | Log.Error(exception, "Could not identify file."); |
|
2185 | } |
2188 | } |
|
Line 2186... | Line 2189... | |||
2186 | |
2189 | |
|
- | 2190 | if (mime == null) |
||
- | 2191 | { |
||
- | 2192 | continue; |
||
Line 2187... | Line 2193... | |||
2187 | if (mime == null) continue; |
2193 | } |
|
2188 | |
2194 | |
|
Line 2189... | Line 2195... | |||
2189 | yield return (File: file, Data: memoryStream, Mime: mime.Definition); |
2195 | yield return (File: file, Data: memoryStream, Mime: mime.Definition); |
|
Line 2307... | Line 2313... | |||
2307 | default: |
2313 | default: |
|
2308 | return new Configuration.Configuration(); |
2314 | return new Configuration.Configuration(); |
|
2309 | } |
2315 | } |
|
2310 | } |
2316 | } |
|
Line 2311... | Line 2317... | |||
2311 | |
2317 | |
|
2312 | private static async Task<Bitmap> CreateThumbnail(Stream file, int width, int height, |
2318 | private static async Task<Bitmap> CreateThumbnail(Stream file, uint width, uint height, |
|
2313 | CancellationToken cancellationToken) |
2319 | CancellationToken cancellationToken) |
|
2314 | { |
2320 | { |
|
2315 | using var memoryStream = new MemoryStream(); |
2321 | using var memoryStream = new MemoryStream(); |
|
2316 | using var imageCollection = |
2322 | using var imageCollection = |
|
Line 2319... | Line 2325... | |||
2319 | |
2325 | |
|
2320 | var scaleHeight = width / (float)frame.Height; |
2326 | var scaleHeight = width / (float)frame.Height; |
|
2321 | var scaleWidth = height / (float)frame.Width; |
2327 | var scaleWidth = height / (float)frame.Width; |
|
Line 2322... | Line 2328... | |||
2322 | var scale = Math.Min(scaleHeight, scaleWidth); |
2328 | var scale = Math.Min(scaleHeight, scaleWidth); |
|
2323 | |
2329 | |
|
Line 2324... | Line 2330... | |||
2324 | width = (int)(frame.Width * scale); |
2330 | width = (uint)(frame.Width * scale); |
|
2325 | height = (int)(frame.Height * scale); |
2331 | height = (uint)(frame.Height * scale); |
|
Line 2326... | Line 2332... | |||
2326 | |
2332 | |
|
Line 2369... | Line 2375... | |||
2369 | |
2375 | |
|
Line 2370... | Line 2376... | |||
2370 | #endregion |
2376 | #endregion |
|
Line 2371... | Line 2377... | |||
2371 | |
2377 | |
|
2372 | #region Event Handlers |
2378 | #region Event Handlers |
|
2373 | |
2379 | |
|
Line 2374... | Line 2380... | |||
2374 | private async void toolStripTextBox1_KeyUp(object sender, KeyEventArgs e) |
2380 | private void toolStripTextBox1_KeyUp(object sender, KeyEventArgs e) |
|
2375 | { |
2381 | { |
|
Line 2408... | Line 2414... | |||
2408 | tagListView.BeginUpdate(); |
2414 | tagListView.BeginUpdate(); |
|
2409 | if (tagListView.Items.ContainsKey(tag)) |
2415 | if (tagListView.Items.ContainsKey(tag)) |
|
2410 | { |
2416 | { |
|
2411 | tagListView.Items[tag].Checked = true; |
2417 | tagListView.Items[tag].Checked = true; |
|
2412 | tagListView.EndUpdate(); |
2418 | tagListView.EndUpdate(); |
|
- | 2419 | |
||
- | 2420 | _sortScheduledContinuation.Schedule(TimeSpan.FromMilliseconds(1000), () => |
||
- | 2421 | { |
||
- | 2422 | tagListView.BeginUpdate(); |
||
- | 2423 | tagListView.Sort(); |
||
- | 2424 | tagListView.EndUpdate(); |
||
- | 2425 | }, _formTaskScheduler, _cancellationToken); |
||
2413 | continue; |
2426 | continue; |
|
2414 | } |
2427 | } |
|
Line 2415... | Line 2428... | |||
2415 | |
2428 | |
|
2416 | tagListView.Items.Add(new ListViewItem(tag) { Name = tag }); |
2429 | tagListView.Items.Add(new ListViewItem(tag) { Name = tag }); |
|
2417 | tagListView.Items[tag].Checked = true; |
2430 | tagListView.Items[tag].Checked = true; |
|
- | 2431 | tagListView.EndUpdate(); |
||
- | 2432 | |
||
- | 2433 | _sortScheduledContinuation.Schedule(TimeSpan.FromMilliseconds(1000), () => |
||
- | 2434 | { |
||
- | 2435 | tagListView.BeginUpdate(); |
||
- | 2436 | tagListView.Sort(); |
||
- | 2437 | tagListView.EndUpdate(); |
||
2418 | tagListView.EndUpdate(); |
2438 | }, _formTaskScheduler, _cancellationToken); |
|
2419 | } |
2439 | } |
|
2420 | break; |
2440 | break; |
|
2421 | case ImageListViewItemProgressFailure<ListViewItem> imageListViewItemProgressFailure: |
2441 | case ImageListViewItemProgressFailure<ListViewItem> imageListViewItemProgressFailure: |
|
2422 | break; |
2442 | break; |
|
Line 3424... | Line 3444... | |||
3424 | { |
3444 | { |
|
3425 | try |
3445 | try |
|
3426 | { |
3446 | { |
|
3427 | var mime = await _magicMime.GetMimeType(file, _cancellationToken); |
3447 | var mime = await _magicMime.GetMimeType(file, _cancellationToken); |
|
Line 3428... | Line 3448... | |||
3428 | |
3448 | |
|
- | 3449 | if (Configuration.SupportedFormats.IsSupportedVideo(mime)) |
||
- | 3450 | { |
||
- | 3451 | return file; |
||
- | 3452 | } |
||
3429 | if (Configuration.SupportedFormats.IsSupportedVideo(mime)) return file; |
3453 | |
|
- | 3454 | if (!Configuration.SupportedFormats.IsSupportedImage(mime)) |
||
- | 3455 | { |
||
- | 3456 | throw new ArgumentException(); |
||
- | 3457 | } |
||
3430 | if (!Configuration.SupportedFormats.IsSupportedImage(mime)) throw new ArgumentException(); |
3458 | |
|
- | 3459 | if (!await _tagManager.StripIptcProfile(file, _cancellationToken)) |
||
- | 3460 | { |
||
- | 3461 | throw new ArgumentException(); |
||
3431 | if (!await _tagManager.StripIptcProfile(file, _cancellationToken)) throw new ArgumentException(); |
3462 | } |
|
3432 | } |
3463 | } |
|
3433 | catch |
3464 | catch |
|
3434 | { |
3465 | { |
|
3435 | this.InvokeIfRequired(form => |
3466 | this.InvokeIfRequired(form => |
|
Line 3570... | Line 3601... | |||
3570 | }); |
3601 | }); |
|
3571 | } |
3602 | } |
|
Line 3572... | Line 3603... | |||
3572 | |
3603 | |
|
3573 | private void imageListView_DragOver(object sender, DragEventArgs e) |
3604 | private void imageListView_DragOver(object sender, DragEventArgs e) |
|
- | 3605 | { |
||
- | 3606 | } |
||
- | 3607 | |
||
- | 3608 | private async void nameToolStripMenuItem_Click(object sender, EventArgs e) |
||
- | 3609 | { |
||
3574 | { |
3610 | await SortImageListView(new NameImageListViewItemSorter()); |
|
Line 3575... | Line 3611... | |||
3575 | } |
3611 | } |
|
3576 | |
3612 | |
|
3577 | private async void ascendingToolStripMenuItem_Click(object sender, EventArgs e) |
3613 | private async void ascendingToolStripMenuItem_Click(object sender, EventArgs e) |
|
Line 3840... | Line 3876... | |||
3840 | // disable menu items not related to list view items |
3876 | // disable menu items not related to list view items |
|
3841 | ToggleMenuItemsRecursive(directoryToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
3877 | ToggleMenuItemsRecursive(directoryToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
|
3842 | ToggleMenuItemsRecursive(fileToolStripMenuItem1, MenuItemsToggleOperation.DISABLE); |
3878 | ToggleMenuItemsRecursive(fileToolStripMenuItem1, MenuItemsToggleOperation.DISABLE); |
|
3843 | ToggleMenuItemsRecursive(imageToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
3879 | ToggleMenuItemsRecursive(imageToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
|
3844 | ToggleMenuItemsRecursive(taggingToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
3880 | ToggleMenuItemsRecursive(taggingToolStripMenuItem, MenuItemsToggleOperation.DISABLE); |
|
3845 | } |
3881 | } |
|
3846 | } |
3882 | } |
|
3847 | } |
3883 | } |
|
3848 | |
3884 | |