mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 08:23:42 -04:00
Export, plugin archive install, and herald cache race condition fixes (#82)
* WIP: Grid export and plugin extraction * Tweak export process * Check for recursion of the same assembly load. * Individual screens aren't always primary? * Wait for cache to be writable * Export selection only. * Update built xml docs * Ignore invalid archives. * Need to ensure task is started.
This commit is contained in:
@ -15,7 +15,8 @@ namespace Observatory.UI.ViewModels
|
||||
public class BasicUIViewModel : ViewModelBase
|
||||
{
|
||||
private ObservableCollection<object> basicUIGrid;
|
||||
|
||||
|
||||
public System.Collections.IList SelectedItems { get; set; }
|
||||
|
||||
public ObservableCollection<object> BasicUIGrid
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Observatory.Framework.Interfaces;
|
||||
using Observatory.UI.Models;
|
||||
using ReactiveUI;
|
||||
@ -114,6 +115,104 @@ namespace Observatory.UI.ViewModels
|
||||
Process.Start(githubOpen);
|
||||
}
|
||||
|
||||
public async void ExportGrid()
|
||||
{
|
||||
var exportFolder = Properties.Core.Default.ExportFolder;
|
||||
|
||||
if (string.IsNullOrEmpty(exportFolder))
|
||||
{
|
||||
exportFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
}
|
||||
|
||||
OpenFolderDialog openFolderDialog = new()
|
||||
{
|
||||
Directory = exportFolder
|
||||
};
|
||||
|
||||
var application = (IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current.ApplicationLifetime;
|
||||
|
||||
var selectedFolder = await openFolderDialog.ShowAsync(application.MainWindow);
|
||||
|
||||
if (!string.IsNullOrEmpty(selectedFolder))
|
||||
{
|
||||
Properties.Core.Default.ExportFolder = selectedFolder;
|
||||
Properties.Core.Default.Save();
|
||||
exportFolder = selectedFolder;
|
||||
|
||||
foreach (var tab in tabs.Where(t => t.Name != "Core"))
|
||||
{
|
||||
var ui = (BasicUIViewModel)tab.UI;
|
||||
List<object> selectedData;
|
||||
bool specificallySelected = ui.SelectedItems?.Count > 1;
|
||||
|
||||
if (specificallySelected)
|
||||
{
|
||||
selectedData = new();
|
||||
|
||||
foreach (var item in ui.SelectedItems)
|
||||
selectedData.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedData = ui.BasicUIGrid.ToList();
|
||||
}
|
||||
|
||||
var columns = selectedData[0].GetType().GetProperties();
|
||||
Dictionary<string, int> colSize = new();
|
||||
Dictionary<string, List<string>> colContent = new();
|
||||
|
||||
foreach (var column in columns)
|
||||
{
|
||||
colSize.Add(column.Name, 0);
|
||||
colContent.Add(column.Name, new());
|
||||
}
|
||||
|
||||
var lineType = selectedData[0].GetType();
|
||||
|
||||
foreach (var line in selectedData)
|
||||
{
|
||||
foreach (var column in colContent)
|
||||
{
|
||||
var cellValue = lineType.GetProperty(column.Key).GetValue(line)?.ToString() ?? string.Empty;
|
||||
column.Value.Add(cellValue);
|
||||
if (colSize[column.Key] < cellValue.Length)
|
||||
colSize[column.Key] = cellValue.Length;
|
||||
}
|
||||
}
|
||||
|
||||
System.Text.StringBuilder exportData = new();
|
||||
|
||||
|
||||
foreach (var colTitle in colContent.Keys)
|
||||
{
|
||||
if (colSize[colTitle] < colTitle.Length)
|
||||
colSize[colTitle] = colTitle.Length;
|
||||
|
||||
exportData.Append(colTitle.PadRight(colSize[colTitle]) + " ");
|
||||
}
|
||||
exportData.AppendLine();
|
||||
|
||||
for (int i = 0; i < colContent.First().Value.Count; i++)
|
||||
{
|
||||
foreach(var column in colContent)
|
||||
{
|
||||
if (column.Value[i].Length > 0 && !char.IsNumber(column.Value[i][0]) && column.Value[i].Count(char.IsLetter) / (float)column.Value[i].Length > 0.25)
|
||||
exportData.Append(column.Value[i].PadRight(colSize[column.Key]) + " ");
|
||||
else
|
||||
exportData.Append(column.Value[i].PadLeft(colSize[column.Key]) + " ");
|
||||
}
|
||||
exportData.AppendLine();
|
||||
}
|
||||
|
||||
string exportPath = $"{exportFolder}{System.IO.Path.DirectorySeparatorChar}Observatory Export - {DateTime.UtcNow:yyyyMMdd-HHmmss} - {tab.Name}.txt";
|
||||
|
||||
System.IO.File.WriteAllText(exportPath, exportData.ToString());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ToggleButtonText
|
||||
{
|
||||
get => toggleButtonText;
|
||||
@ -158,7 +257,7 @@ namespace Observatory.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckUpdate()
|
||||
private static bool CheckUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -179,15 +278,19 @@ namespace Observatory.UI.ViewModels
|
||||
|
||||
foreach (var release in releases)
|
||||
{
|
||||
var ver = release.GetProperty("tag_name").ToString()[1..].Split('.').Select(verString => int.Parse(verString)).ToArray();
|
||||
Version version = new(ver[0], ver[1], ver[2], ver[3]);
|
||||
if (version > System.Reflection.Assembly.GetEntryAssembly().GetName().Version)
|
||||
var tag = release.GetProperty("tag_name").ToString();
|
||||
var verstrings = tag[1..].Split('.');
|
||||
var ver = verstrings.Select(verString => { _ = int.TryParse(verString, out int ver); return ver; }).ToArray();
|
||||
if (ver.Length == 4)
|
||||
{
|
||||
return true;
|
||||
Version version = new(ver[0], ver[1], ver[2], ver[3]);
|
||||
if (version > System.Reflection.Assembly.GetEntryAssembly().GetName().Version)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -82,10 +82,11 @@ namespace Observatory.UI.Views
|
||||
SelectionMode = DataGridSelectionMode.Extended,
|
||||
GridLinesVisibility = DataGridGridLinesVisibility.Vertical,
|
||||
AutoGenerateColumns = true,
|
||||
IsReadOnly = true,
|
||||
IsReadOnly = true
|
||||
};
|
||||
dataGrid.AutoGeneratingColumn += ColumnGeneration;
|
||||
dataGrid.DataContextChanged += OnDataContextSet;
|
||||
dataGrid.SelectionChanged += OnSelectionChanged;
|
||||
uiPanel.Children.Clear();
|
||||
uiPanel.Children.Add(dataGrid);
|
||||
break;
|
||||
@ -103,6 +104,12 @@ namespace Observatory.UI.Views
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((Observatory.UI.ViewModels.BasicUIViewModel)dataGrid.DataContext).SelectedItems = dataGrid.SelectedItems;
|
||||
|
||||
}
|
||||
|
||||
private void OnDataContextSet(object sender, EventArgs e)
|
||||
{
|
||||
if (UIType != PluginUI.UIType.Basic || !(sender is DataGrid)) return;
|
||||
|
@ -73,6 +73,14 @@
|
||||
Cursor="Hand">
|
||||
Update Available
|
||||
</Button>
|
||||
<Button
|
||||
Name="export"
|
||||
Margin="10"
|
||||
FontSize="15"
|
||||
Command="{Binding ExportGrid}"
|
||||
Content="Export">
|
||||
Export
|
||||
</Button>
|
||||
<Button
|
||||
Name="ToggleMonitor"
|
||||
Margin="10"
|
||||
|
@ -130,7 +130,10 @@ namespace Observatory.UI.Views
|
||||
int corner = Properties.Core.Default.NativeNotifyCorner;
|
||||
|
||||
if (screen == -1 || screen > Screens.All.Count)
|
||||
screenBounds = Screens.Primary.Bounds;
|
||||
if (Screens.All.Count == 1)
|
||||
screenBounds = Screens.All[0].Bounds;
|
||||
else
|
||||
screenBounds = Screens.Primary.Bounds;
|
||||
else
|
||||
screenBounds = Screens.All[screen - 1].Bounds;
|
||||
|
||||
|
Reference in New Issue
Block a user