Skip to content

Commit 3ea6383

Browse files
committed
Work on downloads
1 parent 34beb79 commit 3ea6383

File tree

4 files changed

+110
-60
lines changed

4 files changed

+110
-60
lines changed

SmartImage 3/Mode/Shell/Assets/UI.Styles.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#region
55

6+
using System.Runtime.Caching;
67
using AngleSharp.Dom;
78
using Terminal.Gui;
89
using Attribute = Terminal.Gui.Attribute;
@@ -19,7 +20,6 @@ internal static partial class UI
1920
internal static readonly Attribute Atr_Green_Black = Attribute.Make(Color.Green, Color.Black);
2021
internal static readonly Attribute Atr_Green_White = Attribute.Make(Color.Green, Color.White);
2122
internal static readonly Attribute Atr_Green_Gray = Attribute.Make(Color.Green, Color.Gray);
22-
internal static readonly Attribute Atr_Green_DarkGray = Attribute.Make(Color.Green, Color.DarkGray);
2323
internal static readonly Attribute Atr_BrightGreen_White = Attribute.Make(Color.BrightGreen, Color.White);
2424
internal static readonly Attribute Atr_BrightGreen_Gray = Attribute.Make(Color.BrightGreen, Color.Gray);
2525
internal static readonly Attribute Atr_BrightRed_White = Attribute.Make(Color.BrightRed, Color.White);
@@ -50,16 +50,13 @@ internal static partial class UI
5050
internal static readonly Attribute Atr_Gray_Black = Attribute.Make(Color.Gray, Color.Black);
5151
internal static readonly Attribute Atr_DarkGray_Blue = Attribute.Make(Color.DarkGray, Color.Blue);
5252
internal static readonly Attribute Atr_DarkGray_Black = Attribute.Make(Color.DarkGray, Color.Black);
53-
private static readonly Attribute Atr_BrightBlue_Black = Attribute.Make(Color.BrightBlue, Color.Black);
54-
private static readonly Attribute Atr_Blue_Black = Attribute.Make(Color.Blue, Color.Black);
55-
private static readonly Attribute Atr_Brown_Black = Attribute.Make(Color.Brown, Color.Black);
5653
private static readonly Attribute Atr_DarkGray_White = Attribute.Make(Color.DarkGray, Color.White);
5754
internal static readonly Attribute Atr_Black_DarkGray = Attribute.Make(Color.Black, Color.DarkGray);
5855
internal static readonly Attribute Atr_Black_Gray = Attribute.Make(Color.Black, Color.Gray);
5956
internal static readonly Attribute Atr_Brown_Gray = Attribute.Make(Color.Brown, Color.Gray);
6057
internal static readonly Attribute Atr_Brown_DarkGray = Attribute.Make(Color.Brown, Color.DarkGray);
61-
internal static readonly Attribute Atr_Yellow_DarkGray = Attribute.Make(Color.BrightYellow, Color.DarkGray);
62-
internal static readonly Attribute Atr_Yellow_White = Attribute.Make(Color.Brown, Color.White);
58+
internal static readonly Attribute Atr_Yellow_DarkGray = Attribute.Make(Color.BrightYellow, Color.DarkGray);
59+
internal static readonly Attribute Atr_Yellow_White = Attribute.Make(Color.Brown, Color.White);
6360

6461
internal static readonly ColorScheme Cs_Err = Make(Atr_BrightRed_White, disabled: Atr_BrightRed_Gray);
6562
internal static readonly ColorScheme Cs_Ok = Make(Atr_BrightGreen_White, disabled: Atr_BrightGreen_Gray);
@@ -122,8 +119,6 @@ internal static partial class UI
122119
Focus = Atr_BrightRed_White
123120
};
124121

125-
internal static readonly ColorScheme Cs_Btn5 = Make(Atr_Yellow_White, Atr_Yellow_DarkGray, Atr_DarkGray_White);
126-
127122
internal static readonly ColorScheme Cs_Elem2 = new()
128123
{
129124
Normal = Atr_White_Cyan,

SmartImage 3/Mode/Shell/Assets/UI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ internal static bool QueueProgress(CancellationTokenSource cts, ProgressBar pbr,
2828
while (state is CancellationToken { IsCancellationRequested: false }) {
2929
pbr.Pulse();
3030
f?.Invoke(state);
31+
Task.Delay(TimeSpan.FromSeconds(0.5));
3132
// Thread.Sleep(TimeSpan.FromMilliseconds(100));
3233
}
3334

34-
}, cts.Token, true);
35+
}, cts.Token);
3536
}
3637

3738
internal static Button CreateLinkButton(this Dialog d, string text, string? url = null, Action? urlAction = null)

SmartImage 3/Mode/Shell/ShellMode.Handlers.cs

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private void Cancel_Clicked()
244244
Application.MainLoop.RemoveIdle(m_runIdleTok);
245245
Tv_Results.SetFocus();
246246
Lbl_Status2.ColorScheme = UI.Cs_Lbl1;
247-
247+
248248
}
249249

250250
private void Delete_Clicked()
@@ -407,71 +407,125 @@ private async void OnResultKeyPress(View.KeyEventEventArgs eventArgs)
407407
var kek = eventArgs.KeyEvent.Key;
408408
Debug.WriteLine($"{eventArgs.KeyEvent} {eventArgs.KeyEvent.IsCtrl} {kek}");
409409
var k = kek & ~Key.CtrlMask;
410+
var (r, c) = (Tv_Results.SelectedRow, Tv_Results.SelectedColumn);
410411

411-
if (k == Key.S) {
412-
var (r, c) = (Tv_Results.SelectedRow, Tv_Results.SelectedColumn);
412+
// NOTE: Column 1 contains the URL
413+
c = 1;
414+
Url v = (Tv_Results.Table.Rows[r][c]).ToString();
413415

414-
// NOTE: Column 1 contains the URL
415-
c = 1;
416-
Url v = (Tv_Results.Table.Rows[r][c]).ToString();
416+
switch (k) {
417+
case Key.S:
418+
{
419+
if (await ScanResult(v)) return;
417420

418-
if (sx.Contains(v)) {
419-
Lbl_Status2.Text = $"Scanning...!";
420-
Lbl_Status2.SetNeedsDisplay();
421-
return;
421+
break;
422422
}
423-
else {
424-
Lbl_Status2.Text = $"Scanning started...!";
425-
Lbl_Status2.SetNeedsDisplay();
423+
case Key.D:
424+
if (sx.Contains(v)) {
425+
return;
426+
}
426427
sx.Add(v);
428+
Lbl_Status2.Text = "....";
429+
Pbr_Status.Pulse();
430+
var u = await UniSource.TryGetAsync(v, whitelist: FileType.Image);
427431

428-
}
432+
if (u != null && u.FileTypes.Any()) {
433+
var path = $"{v.PathSegments[^1]}";
434+
var path2 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), path);
429435

430-
if (Scanned.ContainsKey(v)) {
431-
//todo
432-
Lbl_Status2.Text = Scanned[v].Message;
433-
Lbl_Status2.SetNeedsDisplay();
434-
}
435-
else {
436-
UniSource[] urls = null;
436+
if (File.Exists(path2)) {
437+
goto open;
438+
}
437439

438-
urls = await NetUtil.ScanAsync(v);
440+
var f = File.OpenWrite(path2);
439441

440-
Scanned.TryAdd(v, new ResultMeta() { Url = v, Sources = urls, Message = "..." });
442+
if (u.Stream.CanSeek) {
443+
u.Stream.Position = 0;
441444

442-
Lbl_Status2.Text = Scanned[v].Message;
443-
Lbl_Status2.SetNeedsDisplay();
445+
}
444446

445-
var d = new Dialog()
446-
{
447-
Title = $"",
448-
AutoSize = false,
449-
Width = Dim.Percent(60),
450-
Height = Dim.Percent(55),
451-
// Height = UI.Dim_80_Pct,
452-
};
453-
454-
var lv = new ListView(Scanned[v].Sources.Select(e => $"{e.FileTypes[0]} {e.Value}").ToArray())
455-
{
456-
Width = Dim.Fill(),
457-
Height = Dim.Fill(),
447+
await u.Stream.CopyToAsync(f);
448+
// f.Close();
449+
f.Dispose();
450+
open:
451+
u.Dispose();
452+
Novus.OS.FileSystem.ExploreFile(path2);
453+
}
454+
else {
455+
Lbl_Status2.Text = $"Invalid";
456+
}
458457

459-
Border = new Border()
460-
{
461-
BorderStyle = BorderStyle.Rounded,
462-
BorderThickness = new Thickness(2)
463-
}
464-
};
465-
d.Add(lv);
466-
Application.Run(d);
458+
// Pbr_Status.Pulse();
467459

468-
// var rmi = Scanned[v];
469-
// Scanned[v] = urls;
470-
// Pbr_Status.Fraction = 0;
460+
var list = sx.ToList();
461+
var bx = list.Remove(v);
462+
sx = new(list);
471463

472-
}
464+
break;
473465
}
474466

475467
eventArgs.Handled = true;
476468
}
469+
470+
private static async Task<bool> ScanResult(Url v)
471+
{
472+
473+
if (sx.Contains(v)) {
474+
Lbl_Status2.Text = $"Scanning...!";
475+
Lbl_Status2.SetNeedsDisplay();
476+
return true;
477+
}
478+
else {
479+
Lbl_Status2.Text = $"Scanning started...!";
480+
Lbl_Status2.SetNeedsDisplay();
481+
sx.Add(v);
482+
483+
}
484+
485+
if (Scanned.ContainsKey(v)) {
486+
//todo
487+
Lbl_Status2.Text = Scanned[v].Message;
488+
Lbl_Status2.SetNeedsDisplay();
489+
}
490+
else {
491+
UniSource[] urls = null;
492+
493+
urls = await NetUtil.ScanAsync(v);
494+
495+
Scanned.TryAdd(v, new ResultMeta() { Url = v, Sources = urls, Message = "..." });
496+
497+
Lbl_Status2.Text = Scanned[v].Message;
498+
Lbl_Status2.SetNeedsDisplay();
499+
500+
var d = new Dialog()
501+
{
502+
Title = $"",
503+
AutoSize = false,
504+
Width = Dim.Percent(60),
505+
Height = Dim.Percent(55),
506+
// Height = UI.Dim_80_Pct,
507+
};
508+
509+
var lv = new ListView(Scanned[v].Sources.Select(e => $"{e.FileTypes[0]} {e.Value}").ToArray())
510+
{
511+
Width = Dim.Fill(),
512+
Height = Dim.Fill(),
513+
514+
Border = new Border()
515+
{
516+
BorderStyle = BorderStyle.Rounded,
517+
BorderThickness = new Thickness(2)
518+
}
519+
};
520+
d.Add(lv);
521+
Application.Run(d);
522+
523+
// var rmi = Scanned[v];
524+
// Scanned[v] = urls;
525+
// Pbr_Status.Fraction = 0;
526+
527+
}
528+
529+
return false;
530+
}
477531
}

SmartImage 3/SmartImage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
4646
<DefineConstants>DEBUG;TRACE;JETBRAINS_ANNOTATIONS</DefineConstants>
47-
<NoWarn>1701;1702;NU1608</NoWarn>
47+
<!-- <NoWarn>1701;1702;NU1608</NoWarn> -->
4848
</PropertyGroup>
4949
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
5050
<DefineConstants>TRACE;JETBRAINS_ANNOTATIONS</DefineConstants>

0 commit comments

Comments
 (0)