Add release packaging and automatic update support
This commit is contained in:
parent
94cd6b984b
commit
f971c374f8
20 changed files with 722 additions and 16 deletions
|
|
@ -13,7 +13,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
public sealed class MainWindow:Window
|
||||
public sealed partial class MainWindow:Window
|
||||
{
|
||||
Project? project;string projectDirectory="";CancellationTokenSource? cancellation;bool busy,refreshing,saving;
|
||||
readonly SemaphoreSlim saveGate=new(1);
|
||||
|
|
@ -65,7 +65,7 @@ public sealed class MainWindow:Window
|
|||
var header=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(22,0,22,2)};Grid.SetRow(header,1);
|
||||
var heading=new StackPanel{Orientation=Orientation.Horizontal,Spacing=12,VerticalAlignment=VerticalAlignment.Center};title.MinWidth=140;title.MaxWidth=330;title.TextTrimming=TextTrimming.CharacterEllipsis;title.VerticalAlignment=subtitle.VerticalAlignment=VerticalAlignment.Center;heading.Children.Add(title);heading.Children.Add(subtitle);header.Children.Add(heading);
|
||||
var toolbar=new WrapPanel{Orientation=Orientation.Horizontal,HorizontalAlignment=HorizontalAlignment.Right,VerticalAlignment=VerticalAlignment.Center};
|
||||
foreach(var b in new[]{analyze,export}){b.Margin=new(8,1,0,1);toolbar.Children.Add(b);}Grid.SetColumn(toolbar,1);header.Children.Add(toolbar);headerSurface.Children.Add(header);
|
||||
foreach(var b in new[]{analyze,export,settingsButton}){b.Margin=new(8,1,0,1);toolbar.Children.Add(b);}Grid.SetColumn(toolbar,1);header.Children.Add(toolbar);headerSurface.Children.Add(header);
|
||||
var scope=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(20,7,20,7)};
|
||||
sessions.ItemTemplate=new FuncDataTemplate<string>((text,_)=>SessionRow(text??""));sessions.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};scope.Children.Add(sessions);
|
||||
var stats=new StackPanel{Orientation=Orientation.Horizontal,Spacing=28,VerticalAlignment=VerticalAlignment.Center};
|
||||
|
|
@ -96,13 +96,13 @@ public sealed class MainWindow:Window
|
|||
spatial.IsCheckedChanged+=(_,_)=>{preview.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison();
|
||||
KeyDown+=async(_,e)=>
|
||||
{
|
||||
if(busy||e.Source is TextBox)return;
|
||||
if(busy||updates.Applying||e.Source is TextBox)return;
|
||||
if(e.Key==Key.J){Move(-1);e.Handled=true;}if(e.Key==Key.K){Move(1);e.Handled=true;}
|
||||
if(e.Key is Key.D1 or Key.NumPad1){await Override(Verdict.Keep);e.Handled=true;}if(e.Key is Key.D2 or Key.NumPad2){await Override(Verdict.Review);e.Handled=true;}if(e.Key is Key.D3 or Key.NumPad3){await Override(Verdict.Reject);e.Handled=true;}
|
||||
if(e.Key==Key.Z&&e.KeyModifiers.HasFlag(KeyModifiers.Control)&&undo.Count>0){var item=undo.Pop();item.Frame.Override=item.Verdict;item.Frame.Note=item.Note;item.Frame.ReviewedAt=item.At;await Save();RefreshFrames(item.Frame);e.Handled=true;}
|
||||
};
|
||||
Closing+=(_,e)=>{if(busy){e.Cancel=true;cancellation?.Cancel();status.Text="Stopping safely; close again when finished";}};
|
||||
Closed+=(_,_)=>{preview.Dispose();comparison.Dispose();};ShowEmpty();
|
||||
Closed+=(_,_)=>{preview.Dispose();comparison.Dispose();};ShowEmpty();InitializeUpdates();
|
||||
}
|
||||
static Button Button(string text,bool primary=false)=>new(){Content=text,Padding=new(12,7),CornerRadius=new(2),Background=primary?Palette.Accent:Palette.Raised,Foreground=primary?Palette.Background:Palette.Text};
|
||||
static Border Panel(Control child)=>new(){Background=Palette.Panel,BorderBrush=Palette.Line,BorderThickness=new(.5),CornerRadius=new(2),ClipToBounds=true,Child=child};
|
||||
|
|
@ -232,7 +232,7 @@ public sealed class MainWindow:Window
|
|||
void Move(int step){if(visible.Count==0)return;int index=selected==null?0:visible.IndexOf(selected);var f=visible[Math.Clamp(index+step,0,visible.Count-1)];frames.SelectedItem=f;frames.ScrollIntoView(f);}
|
||||
async Task Override(Verdict? verdict,bool advance=true)
|
||||
{
|
||||
if(selected==null||busy||saving)return;var f=selected;int index=visible.IndexOf(f);undo.Push((f,f.Override,f.Note,f.ReviewedAt));f.Override=verdict;f.ReviewedAt=DateTime.UtcNow;
|
||||
if(selected==null||busy||saving||updates.Applying)return;var f=selected;int index=visible.IndexOf(f);undo.Push((f,f.Override,f.Note,f.ReviewedAt));f.Override=verdict;f.ReviewedAt=DateTime.UtcNow;
|
||||
if(!await Save()){var previous=undo.Pop();f.Override=previous.Verdict;f.Note=previous.Note;f.ReviewedAt=previous.At;RefreshFrames(f);status.Text="Review could not be saved; decision restored";return;}
|
||||
var next=advance?visible.ElementAtOrDefault(index+1)??visible.ElementAtOrDefault(index-1):f;RefreshFrames(next);status.Text="Manual decision saved · Ctrl+Z to undo";
|
||||
}
|
||||
|
|
@ -241,19 +241,20 @@ public sealed class MainWindow:Window
|
|||
if(project==null)return false;await saveGate.WaitAsync();saving=true;analyze.IsEnabled=export.IsEnabled=false;
|
||||
try{var p=project;var directory=projectDirectory;await Task.Run(()=>ProjectStore.Save(p,directory));return true;}
|
||||
catch(Exception e){await Message("Could not save project",e.Message);return false;}
|
||||
finally{saving=false;analyze.IsEnabled=!busy;export.IsEnabled=!busy&&project.Complete;saveGate.Release();}
|
||||
finally{saving=false;analyze.IsEnabled=!busy&&!updates.Applying;export.IsEnabled=!busy&&!updates.Applying&&project.Complete;saveGate.Release();}
|
||||
}
|
||||
async Task<string?> Folder(string title)
|
||||
{var result=await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions{Title=title,AllowMultiple=false});return result.FirstOrDefault()?.TryGetLocalPath();}
|
||||
void Busy(bool value){busy=value;analyze.IsEnabled=!value;export.IsEnabled=!value&&project?.Complete==true;frames.IsEnabled=sessions.IsEnabled=chart.IsEnabled=filter.IsEnabled=sort.IsEnabled=metric.IsEnabled=!value;inspector.IsEnabled=!value;stop.IsVisible=progress.IsVisible=value;}
|
||||
async Task Analyze()
|
||||
{
|
||||
if(busy||saving||updates.Applying)return;
|
||||
string? source=project?.Source;
|
||||
if(source!=null)
|
||||
{
|
||||
bool same=await Confirm("Analyze lights","Reanalyze the current source folder using cached measurements, or choose another folder?","Current source","Choose folder");if(!same)source=null;
|
||||
}
|
||||
source??=await Folder("Choose a folder containing raw FITS lights");if(source==null)return;
|
||||
source??=await Folder("Choose a folder containing raw FITS lights");if(source==null||updates.Applying)return;
|
||||
if(project?.Source!=source)
|
||||
{
|
||||
string hash=Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(source)))[..16];
|
||||
|
|
@ -261,10 +262,10 @@ public sealed class MainWindow:Window
|
|||
project=File.Exists(System.IO.Path.Combine(projectDirectory,"project.json"))?ProjectStore.Load(projectDirectory):null;
|
||||
}
|
||||
Busy(true);cancellation=new();progress.Value=0;
|
||||
var updates=new Progress<ProgressInfo>(p=>{progress.Value=p.Total==0?0:100.0*p.Done/p.Total;status.Text=$"{p.Stage} · {p.Done:N0} / {p.Total:N0} · {p.File}";});
|
||||
var analysisProgress=new Progress<ProgressInfo>(p=>{progress.Value=p.Total==0?0:100.0*p.Done/p.Total;status.Text=$"{p.Stage} · {p.Done:N0} / {p.Total:N0} · {p.File}";});
|
||||
try
|
||||
{
|
||||
var previous=project;await Task.Run(async()=>project=await new Analyzer().AnalyzeAsync(source,projectDirectory,previous,updates,cancellation.Token));LoadProject(projectDirectory);
|
||||
var previous=project;await Task.Run(async()=>project=await new Analyzer().AnalyzeAsync(source,projectDirectory,previous,analysisProgress,cancellation.Token));LoadProject(projectDirectory);
|
||||
}
|
||||
catch(OperationCanceledException){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Cancelled · completed measurements saved; reanalyze to resume";}
|
||||
catch(ResourcePressureException e){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Paused safely for RAM pressure · completed measurements saved";await Message("RAM headroom unavailable",e.Message);}
|
||||
|
|
@ -273,7 +274,7 @@ public sealed class MainWindow:Window
|
|||
}
|
||||
async Task ExportAccepted()
|
||||
{
|
||||
if(project?.Complete!=true)return;
|
||||
if(project?.Complete!=true||busy||saving||updates.Applying)return;
|
||||
var options=new Window{Title="Export accepted lights",Width=470,SizeToContent=SizeToContent.Height,CanResize=false,WindowStartupLocation=WindowStartupLocation.CenterOwner,Background=Palette.Panel};
|
||||
var layout=new StackPanel{Margin=new(24),Spacing=14};layout.Children.Add(Palette.Label("Prepare lights for Siril",21));layout.Children.Add(new TextBlock{Text="KEEP frames are included. Originals are opened read-only. Select an empty output folder outside your input tree.",TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});
|
||||
var scopes=new List<(string Name,List<Frame> Frames)>();
|
||||
|
|
@ -282,7 +283,7 @@ public sealed class MainWindow:Window
|
|||
scopes.Add(("Entire project · separate target folders",project.Frames));
|
||||
var scope=new ComboBox{ItemsSource=scopes.Select(x=>x.Name).ToArray(),SelectedIndex=sessions.SelectedIndex>0?0:scopes.Count-1,HorizontalAlignment=HorizontalAlignment.Stretch};layout.Children.Add(Palette.Label("EXPORT SCOPE",10,Palette.Muted));layout.Children.Add(scope);
|
||||
var include=new CheckBox{Content="Also include unresolved REVIEW frames",IsChecked=false};var links=new CheckBox{Content="Use hardlinks when available (copy fallback)",IsChecked=true};layout.Children.Add(include);layout.Children.Add(links);layout.Children.Add(new TextBlock{Text="Hardlinks share source bytes. Use Siril to read and process these inputs into separate outputs. Choose copies if another tool may overwrite input files.",FontSize=11,TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});var buttons=new WrapPanel();var go=Button("Choose output folder",true);var cancel=Button("Cancel");cancel.Margin=new(8,0,0,0);buttons.Children.Add(go);buttons.Children.Add(cancel);layout.Children.Add(buttons);options.Content=layout;go.Click+=(_,_)=>options.Close(true);cancel.Click+=(_,_)=>options.Close(false);
|
||||
if(!await options.ShowDialog<bool>(this))return;string? output=await Folder("Choose an empty output folder for accepted lights");if(output==null)return;
|
||||
if(!await options.ShowDialog<bool>(this))return;string? output=await Folder("Choose an empty output folder for accepted lights");if(output==null||updates.Applying)return;
|
||||
var exportProject=new Project{Name=project.Name,Source=project.Source,Complete=project.Complete,Frames=scopes[scope.SelectedIndex].Frames};
|
||||
Busy(true);cancellation=new();try{var result=await Export.AcceptedAsync(exportProject,output,include.IsChecked==true,links.IsChecked==true,new Progress<ProgressInfo>(p=>{progress.Value=100.0*p.Done/Math.Max(1,p.Total);status.Text=$"{p.Stage} · {p.Done}/{p.Total}";}),cancellation.Token);status.Text=$"Export complete · {result.Linked} hardlinks, {result.Copied} copies · {output}";}
|
||||
catch(OperationCanceledException){status.Text="Export cancelled · completed output files retained; choose a new empty folder to retry";}catch(Exception e){await Message("Export could not finish",e.Message);}finally{Busy(false);cancellation.Dispose();cancellation=null;}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue