Skip to content

Commit

Permalink
Added auto updating, fixed dragging issue, improved performance with …
Browse files Browse the repository at this point in the history
…ready to run compilation, improved file size with trimming
  • Loading branch information
tommaier123 committed Feb 24, 2022
1 parent 3fbac3c commit a19da33
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 63 deletions.
14 changes: 12 additions & 2 deletions NoodleManagerX.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30330.147
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NoodleManagerX", "NoodleManagerX\NoodleManagerX.csproj", "{5B4DBD3E-3920-43F7-96B5-00CC7737E702}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UpdateHelper", "UpdateHelper\UpdateHelper.csproj", "{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,14 @@ Global
{5B4DBD3E-3920-43F7-96B5-00CC7737E702}.Release|Any CPU.Build.0 = Release|Any CPU
{5B4DBD3E-3920-43F7-96B5-00CC7737E702}.Release|x64.ActiveCfg = Release|x64
{5B4DBD3E-3920-43F7-96B5-00CC7737E702}.Release|x64.Build.0 = Release|x64
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Debug|x64.ActiveCfg = Debug|x64
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Debug|x64.Build.0 = Debug|x64
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Release|Any CPU.Build.0 = Release|Any CPU
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Release|x64.ActiveCfg = Release|x64
{1C53E0DB-F28A-4601-B6AE-CFBDE4A24901}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 12 additions & 4 deletions NoodleManagerX/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
</Grid>
<Grid IsVisible="{Binding Path=selectedTabIndex, Converter={StaticResource EqualsConverter}, ConverterParameter=6}">
<!--Path, Quest Enabled, Auto Update Content, Disable NM Update Notification-->
<Grid RowDefinitions="auto,auto,*,auto">
<Grid RowDefinitions="auto,auto,auto,auto,*,auto">
<Grid Grid.Row="0" ColumnDefinitions="auto,*,auto" Margin="10,10,10,10">
<TextBlock Grid.Column="0" Text="Synth Riders Directory" VerticalAlignment="Center"/>
<Border Grid.Column="1" Margin="20,0,0,0" BorderBrush="{Binding Path=directoryValid, Converter={StaticResource BoolColorConverter}, ConverterParameter=#aaaaaa|#ff0000}" BorderThickness="1">
Expand All @@ -444,10 +444,18 @@
</Button>
</Grid>
<Grid Grid.Row="1" ColumnDefinitions="auto,auto,*" Margin="10,10,10,10">
<TextBlock Grid.Column="0" Text="Allow Converts" VerticalAlignment="Center"/>
<CheckBox Grid.Column="1" Margin="16,0,0,0" IsChecked="{Binding settings.allowConverts}"/>
<CheckBox Grid.Column="0" IsChecked="{Binding settings.allowConverts}"/>
<TextBlock Grid.Column="1" Text="Allow Converts" Margin="16,0,0,0" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="4" Text="{Binding version}" VerticalAlignment="Center" Foreground="Gray"/>
<Grid Grid.Row="2" ColumnDefinitions="auto,auto,*" Margin="10,10,10,10">
<CheckBox Grid.Column="0" IsChecked="{Binding settings.ignoreUpdates}"/>
<TextBlock Grid.Column="1" Text="Ignore Updates" Margin="16,0,0,0" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Row="3" ColumnDefinitions="auto,auto,*" Margin="10,10,10,10">
<CheckBox Grid.Column="0" IsChecked="{Binding settings.getBetas}"/>
<TextBlock Grid.Column="1" Text="Update to Beta Versions" Margin="16,0,0,0" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="6" Text="{Binding version}" VerticalAlignment="Center" Foreground="Gray"/>
</Grid>
</Grid>
</Grid>
Expand Down
6 changes: 1 addition & 5 deletions NoodleManagerX/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class MainWindow : Window
public static Brush difficultyInactiveBrush;

private Grid blackBar;
public MouseDevice mouse;
private bool lastleftclick = false;
private bool lastHandled = false;
private Point lastclickposition;
Expand Down Expand Up @@ -57,12 +56,9 @@ public MainWindow()
#pragma warning disable 0618
Application.Current.InputManager.Process.Subscribe(x =>
{
if (mouse == null)
{
mouse = (MouseDevice)x.Device;
}
if (x is RawPointerEventArgs rawpointerevent)
{
MouseDevice mouse = (MouseDevice)x.Device;
bool leftclick = rawpointerevent.InputModifiers == RawInputModifiers.LeftMouseButton;

Point mouseonclient = this.PointToClient(mouse.Position);
Expand Down
147 changes: 101 additions & 46 deletions NoodleManagerX/Models/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
using Path = System.IO.Path;
using Stream = System.IO.Stream;
using MemoryStream = System.IO.MemoryStream;

using System.Net;
using System.Diagnostics;

namespace NoodleManagerX.Models
{
Expand All @@ -36,19 +37,16 @@ class MainViewModel : ReactiveObject


//Todo:
//check which dispatchers should be awaited
//better task structure in general
//possibly remove unnecessary flags from function parameters, use state machine/individual parameters
//get description when rightclicking an item and display in context menu
//multiple files
//update reminder
//don't leave thread safety up to luck
//get a updated at timestamp for updating, published at is fine for filesystem timestamp
//look at exception handling with tasks



[Reactive] private string version { get; set; } = "V0.6.0";
[Reactive] private string version { get; set; } = "V0.7.0";

public static MainViewModel s_instance;

Expand Down Expand Up @@ -121,33 +119,6 @@ public MainViewModel()
{
MainWindow.s_instance.Closing += ClosingEvent;

await LoadSettings();

settings.Changed.Subscribe(x => { SaveSettings(); });//save the settings when they change

this.WhenAnyValue(x => x.synthDirectory).Skip(1).Subscribe(x =>
{
directoryValid = CheckDirectory(synthDirectory);
if (settings.synthDirectory != synthDirectory && directoryValid)
{
settings.synthDirectory = synthDirectory;
ReloadLocalSources(true);
}
});

_ = Dispatcher.UIThread.InvokeAsync(() =>
{
if (!CheckDirectory(settings.synthDirectory))
{
settings.synthDirectory = "";
GetDirectoryFromRegistry();
}
else
{
synthDirectory = settings.synthDirectory;
}
});

minimizeCommand = ReactiveCommand.Create(() =>
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
Expand Down Expand Up @@ -274,6 +245,100 @@ public MainViewModel()
});
}));

await LoadSettings();

if (!settings.ignoreUpdates)
{
try
{
Octokit.GitHubClient github = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("NoodleManagerX"));
var all = github.Repository.Release.GetAll("tommaier123", "NoodleManagerX").Result;
if (!settings.getBetas) all = all.Where(x => x.Prerelease == false).ToList();
var latest = all.OrderByDescending(x => Int32.Parse(x.TagName.Substring(1).Replace(".", ""))).FirstOrDefault();

if (latest != null)
{
if (Int32.Parse(version.Substring(1).Replace(".", "")) < Int32.Parse(latest.TagName.Substring(1).Replace(".", "")))
{
Log("Update available to: " + latest.TagName);

string beta = "";
if (latest.Prerelease) beta = "Note: This is a beta version and may contain bugs" + Environment.NewLine;

var res = await Dispatcher.UIThread.InvokeAsync(async () =>
{
return await MessageBox.Show(MainWindow.s_instance, "New Update to " + latest.TagName + " available:" + Environment.NewLine + beta + Environment.NewLine + latest.Body + Environment.NewLine + Environment.NewLine + "Do you want to Download it?", "Update Available", MessageBox.MessageBoxButtons.OkCancel);
});

if (res == MessageBox.MessageBoxResult.Ok)
{
using (var client = new WebClient())
{
client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
{
_ = Dispatcher.UIThread.InvokeAsync(() =>
{
progress = e.ProgressPercentage;
});
};
string temp = Path.GetTempPath();
string location = Path.Combine(temp, "NoodleManagerX.exe");
string locationHelper = Path.Combine(temp, "UpdateHelper.exe");
Log("Writing update files to " + temp);
if (System.IO.File.Exists(location)) System.IO.File.Delete(location);
await client.DownloadFileTaskAsync("https://github.com/tommaier123/NoodleManagerX/releases/download/" + latest.TagName + "/NoodleManagerX.exe", location);

using (Stream resourceFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("NoodleManagerX.Resources.UpdateHelper.exe"))
using (System.IO.FileStream fs = System.IO.File.Open(locationHelper, System.IO.FileMode.Create))
{
resourceFile.CopyTo(fs);
}

Process proc = new Process();
proc.StartInfo.FileName = locationHelper;
proc.StartInfo.Arguments = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.Start();

await Dispatcher.UIThread.InvokeAsync(() =>
{
closing = true;
MainWindow.s_instance.Close();
});
}
}
}
}
}
catch (Exception e) { Log(MethodBase.GetCurrentMethod(), e); }
}

settings.Changed.Subscribe(x => { SaveSettings(); });//save the settings when they change

this.WhenAnyValue(x => x.synthDirectory).Skip(1).Subscribe(x =>
{
directoryValid = CheckDirectory(synthDirectory);
if (settings.synthDirectory != synthDirectory && directoryValid)
{
settings.synthDirectory = synthDirectory;
ReloadLocalSources(true);
}
});

_ = Dispatcher.UIThread.InvokeAsync(() =>
{
if (!CheckDirectory(settings.synthDirectory))
{
settings.synthDirectory = "";
GetDirectoryFromRegistry();
}
else
{
synthDirectory = settings.synthDirectory;
}
});

//the correct number of events needs to be skipped in ordere to avoid duplication
//1 for properties that get initialized
//2 for properties that get declared and are initialized via bindings
Expand All @@ -284,25 +349,15 @@ public MainViewModel()
this.WhenAnyValue(x => x.selectedSortMethod).Skip(2).Subscribe(x => GetPage());//reload maps when the sort method changes
this.WhenAnyValue(x => x.selectedSortOrder).Skip(2).Subscribe(x => GetPage());//reload maps when the sort order changes

items.CollectionChanged += ItemsCollectionChanged;
blacklist.CollectionChanged += BlacklistCollectionChanged;
items.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) => UpdateCollections();
blacklist.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) => SaveBlacklist();

MtpDevice.Connect();
ReloadLocalSources();
_ = GetPage();
});
}

private void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateCollections();
}

private void BlacklistCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
SaveBlacklist();
}

public void ReloadLocalSources(bool directoryChanged = false)
{
if (!(directoryChanged && MtpDevice.connected))//don't reload when directory changes and quest is connected
Expand Down Expand Up @@ -481,7 +536,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
progress = 1;
updatingLocalItems = true;
});

localItems.Clear();
bool dbExists = false;

Expand All @@ -508,7 +563,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
{
await Dispatcher.UIThread.InvokeAsync(async () =>
{
var res = await MessageBox.Show(null, "Click OK to delete maps without metadata e.g. if they were not downloaded from synthriderz.com" + Environment.NewLine + "This will only happen once when loading a new game directory" + Environment.NewLine + "Choosing to cancel might lead to duplicate maps" + Environment.NewLine + "Building the database for the first time can take some minutes", "Warning", MessageBox.MessageBoxButtons.OkCancel);
var res = await MessageBox.Show(MainWindow.s_instance, "Click OK to delete maps without metadata e.g. if they were not downloaded from synthriderz.com" + Environment.NewLine + "This will only happen once when loading a new game directory" + Environment.NewLine + "Choosing to cancel might lead to duplicate maps" + Environment.NewLine + "Building the database for the first time can take some minutes", "Warning", MessageBox.MessageBoxButtons.OkCancel);
if (res == MessageBox.MessageBoxResult.Ok)
{
pruning = true;
Expand Down
2 changes: 2 additions & 0 deletions NoodleManagerX/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class Settings : ReactiveObject
{
[Reactive] [DataMember] public string synthDirectory { get; set; } = "";
[Reactive] [DataMember] public bool allowConverts { get; set; } = false;
[Reactive] [DataMember] public bool ignoreUpdates { get; set; } = false;
[Reactive] [DataMember] public bool getBetas { get; set; } = true;
}
}
15 changes: 10 additions & 5 deletions NoodleManagerX/NoodleManagerX.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net5.0-windows</TargetFrameworks>
<ApplicationIcon>icon-nm.ico</ApplicationIcon>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
<DebugType>embedded</DebugType>
<Platforms>AnyCPU;x64</Platforms>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
Expand All @@ -19,22 +19,27 @@
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.12" />
<PackageReference Include="Avalonia.Svg.Skia" Version="0.10.12" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="9.0.0" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="10.0.0" />
<PackageReference Include="ManagedBass" Version="3.1.0" />
<PackageReference Include="MediaDevices" Version="1.9.1" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="NAudio" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ReactiveUI.Fody" Version="17.1.17" />
<PackageReference Include="Octokit" Version="0.50.0" />
<PackageReference Include="ReactiveUI.Fody" Version="17.1.50" />
<PackageReference Include="SharpAdbClient" Version="2.3.23" />
<PackageReference Include="YoutubeExplode" Version="6.0.7" />
<PackageReference Include="YoutubeExplode" Version="6.1.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\*.png" />
<EmbeddedResource Include="Assets\icons\*.svg" />
<EmbeddedResource Include="Assets\icon-nm.ico" />
<EmbeddedResource Include="Assets\Fonts\*.ttf" />
</ItemGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)'=='win-x64'or'$(Configuration)'=='DEBUG'">
<EmbeddedResource Include="Resources\UpdateHelper.exe" />
</ItemGroup>

<!--
<ItemGroup Condition="'$(RuntimeIdentifier)'=='win-x64'or'$(Configuration)'=='DEBUG'">
<EmbeddedResource Include="Resources\windows.zip" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishReadyToRun>True</PublishReadyToRun>
</PropertyGroup>
</Project>
Binary file added NoodleManagerX/Resources/UpdateHelper.exe
Binary file not shown.
Binary file removed NoodleManagerX/Resources/linux.zip
Binary file not shown.
Binary file removed NoodleManagerX/Resources/osx.zip
Binary file not shown.
Binary file removed NoodleManagerX/Resources/windows.zip
Binary file not shown.
24 changes: 24 additions & 0 deletions UpdateHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Diagnostics;
using System.IO;

namespace UpdateHelper
{
internal class Program
{
static void Main(string[] args)
{
if (args.Length >= 1)
{
string oldPath = Path.Combine(args[0], "NoodleManagerX.exe");
string tmpPath = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "NoodleManagerX.exe");
File.Move(tmpPath, oldPath, true);

Process proc = new Process();
proc.StartInfo.FileName = oldPath;
proc.StartInfo.UseShellExecute = true;
proc.Start();
}
}
}
}
Loading

0 comments on commit a19da33

Please sign in to comment.