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:
@ -174,12 +174,6 @@ namespace Observatory.PluginManagement
|
||||
Properties.Core.Default.Save();
|
||||
}
|
||||
|
||||
//private static string GetSettingsFile(IObservatoryPlugin plugin)
|
||||
//{
|
||||
// var configDirectory = new FileInfo(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath).Directory;
|
||||
// return configDirectory.FullName + "\\" + plugin.Name + ".json";
|
||||
//}
|
||||
|
||||
private static List<string> LoadPlugins(out List<(IObservatoryWorker plugin, PluginStatus signed)> observatoryWorkers, out List<(IObservatoryNotifier plugin, PluginStatus signed)> observatoryNotifiers)
|
||||
{
|
||||
observatoryWorkers = new();
|
||||
@ -190,6 +184,8 @@ namespace Observatory.PluginManagement
|
||||
|
||||
if (Directory.Exists(pluginPath))
|
||||
{
|
||||
ExtractPlugins(pluginPath);
|
||||
|
||||
//Temporarily skipping signature checks. Need to do this the right way later.
|
||||
var pluginLibraries = Directory.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}{Path.DirectorySeparatorChar}plugins", "*.dll");
|
||||
//var coreToken = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
|
||||
@ -241,16 +237,39 @@ namespace Observatory.PluginManagement
|
||||
return errorList;
|
||||
}
|
||||
|
||||
private static void ExtractPlugins(string pluginFolder)
|
||||
{
|
||||
var files = Directory.GetFiles(pluginFolder, "*.zip")
|
||||
.Concat(Directory.GetFiles(pluginFolder, "*.eop")); // Elite Observatory Plugin
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.Compression.ZipFile.ExtractToDirectory(file, pluginFolder, true);
|
||||
File.Delete(file);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Just ignore files that don't extract successfully.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string LoadPluginAssembly(string dllPath, List<(IObservatoryWorker plugin, PluginStatus signed)> workers, List<(IObservatoryNotifier plugin, PluginStatus signed)> notifiers)
|
||||
{
|
||||
|
||||
string recursionGuard = string.Empty;
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += (context, name) => {
|
||||
|
||||
if (name.Name.EndsWith("resources"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//Importing Observatory.Framework in the Explorer Lua scripts causes an attempt to reload
|
||||
//the assembly, just hand it back the one we already have.
|
||||
// Importing Observatory.Framework in the Explorer Lua scripts causes an attempt to reload
|
||||
// the assembly, just hand it back the one we already have.
|
||||
if (name.Name.StartsWith("Observatory.Framework") || name.Name == "ObservatoryFramework")
|
||||
{
|
||||
return context.Assemblies.Where(a => a.FullName.Contains("ObservatoryFramework")).First();
|
||||
@ -262,7 +281,17 @@ namespace Observatory.PluginManagement
|
||||
return context.LoadFromAssemblyPath(foundDlls[0]);
|
||||
}
|
||||
|
||||
return context.LoadFromAssemblyName(name);
|
||||
if (name.Name != recursionGuard)
|
||||
{
|
||||
recursionGuard = name.Name;
|
||||
|
||||
return context.LoadFromAssemblyName(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unable to load assembly " + name.Name);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var pluginAssembly = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(new FileInfo(dllPath).FullName);
|
||||
|
16
ObservatoryCore/Properties/Core.Designer.cs
generated
16
ObservatoryCore/Properties/Core.Designer.cs
generated
@ -12,7 +12,7 @@ namespace Observatory.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")]
|
||||
internal sealed partial class Core : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Core defaultInstance = ((Core)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Core())));
|
||||
@ -238,7 +238,7 @@ namespace Observatory.Properties {
|
||||
this["NativeNotifyTimeout"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
@ -250,5 +250,17 @@ namespace Observatory.Properties {
|
||||
this["StartMonitor"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string ExportFolder {
|
||||
get {
|
||||
return ((string)(this["ExportFolder"]));
|
||||
}
|
||||
set {
|
||||
this["ExportFolder"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,5 +59,8 @@
|
||||
<Setting Name="StartMonitor" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="ExportFolder" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
@ -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