Merge pull request 'add shortcuts, open folder, etc' (#96) from waffle.lord/Installer:impl/shortcuts into master
Reviewed-on: SPT/Installer#96
This commit is contained in:
commit
a70590d92a
@ -9,6 +9,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<TextBox Text="Some cool text here" Margin="5" />
|
<TextBox Text="Some cool text here" Margin="5" />
|
||||||
<TextBox Watermark="This is a watermark" Margin="5" />
|
<TextBox Watermark="This is a watermark" Margin="5" />
|
||||||
|
<CheckBox Content="sldkflskdf" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Design.PreviewWith>
|
</Design.PreviewWith>
|
||||||
|
|
||||||
@ -267,4 +268,30 @@
|
|||||||
<Style Selector="Button.icon:pressed">
|
<Style Selector="Button.icon:pressed">
|
||||||
<Setter Property="Foreground" Value="{StaticResource SPT_DarkGrayBlue}"></Setter>
|
<Setter Property="Foreground" Value="{StaticResource SPT_DarkGrayBlue}"></Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<!-- Checkbox Styles -->
|
||||||
|
<Style Selector="CheckBox">
|
||||||
|
<Setter Property="Foreground" Value="White"/>
|
||||||
|
<Style.Resources>
|
||||||
|
<SolidColorBrush x:Key="CheckBoxCheckBackgroundStrokeUnchecked" Color="DimGray"/>
|
||||||
|
</Style.Resources>
|
||||||
|
</Style>
|
||||||
|
<Style Selector="CheckBox:pointerover /template/ ContentPresenter#ContentPresenter">
|
||||||
|
<Setter Property="Foreground" Value="White"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="CheckBox:checked /template/ ContentPresenter#ContentPresenter">
|
||||||
|
<Setter Property="Foreground" Value="White"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="CheckBox:pointerover /template/ Border#NormalRectangle">
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource SPT_Yellow}"/>
|
||||||
|
</Style>
|
||||||
|
<Style Selector="CheckBox:checked /template/ Border#NormalRectangle">
|
||||||
|
<Setter Property="BorderBrush" Value="{StaticResource SPT_Yellow}"/>
|
||||||
|
<Setter Property="Background" Value="{StaticResource SPT_DarkGrayBlue}"/>
|
||||||
|
</Style>
|
||||||
|
<Style Selector="CheckBox:checked /template/ Path#CheckGlyph">
|
||||||
|
<Setter Property="Fill" Value="{StaticResource SPT_Yellow}"/>
|
||||||
|
</Style>
|
||||||
</Styles>
|
</Styles>
|
@ -98,33 +98,29 @@ public static class FileHelper
|
|||||||
{
|
{
|
||||||
Log.Debug($"Starting StreamAssemblyResourceOut, resourcename: {resourceName}, outputFilePath: {outputFilePath}");
|
Log.Debug($"Starting StreamAssemblyResourceOut, resourcename: {resourceName}, outputFilePath: {outputFilePath}");
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
Log.Debug($"1");
|
|
||||||
|
|
||||||
FileInfo outputFile = new FileInfo(outputFilePath);
|
FileInfo outputFile = new FileInfo(outputFilePath);
|
||||||
Log.Debug($"2");
|
|
||||||
if (outputFile.Exists)
|
if (outputFile.Exists)
|
||||||
{
|
{
|
||||||
Log.Debug($"3");
|
|
||||||
outputFile.Delete();
|
outputFile.Delete();
|
||||||
}
|
}
|
||||||
Log.Debug($"4");
|
|
||||||
if (!outputFile.Directory.Exists)
|
if (!outputFile.Directory.Exists)
|
||||||
{
|
{
|
||||||
Log.Debug($"5");
|
|
||||||
Directory.CreateDirectory(outputFile.Directory.FullName);
|
Directory.CreateDirectory(outputFile.Directory.FullName);
|
||||||
}
|
}
|
||||||
Log.Debug($"6");
|
|
||||||
var resName = assembly.GetManifestResourceNames().First(x => x.EndsWith(resourceName));
|
var resName = assembly.GetManifestResourceNames().First(x => x.EndsWith(resourceName));
|
||||||
Log.Debug($"7");
|
|
||||||
using (FileStream fs = File.Create(outputFilePath))
|
using (FileStream fs = File.Create(outputFilePath))
|
||||||
using (Stream s = assembly.GetManifestResourceStream(resName))
|
using (Stream s = assembly.GetManifestResourceStream(resName))
|
||||||
{
|
{
|
||||||
Log.Debug($"8");
|
|
||||||
s.CopyTo(fs);
|
s.CopyTo(fs);
|
||||||
}
|
}
|
||||||
Log.Debug($"9");
|
|
||||||
outputFile.Refresh();
|
outputFile.Refresh();
|
||||||
Log.Debug(outputFile.Exists.ToString());
|
|
||||||
return outputFile.Exists;
|
return outputFile.Exists;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
23
SPTInstaller/Resources/add_shortcuts.ps1
Normal file
23
SPTInstaller/Resources/add_shortcuts.ps1
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
param (
|
||||||
|
[string]$installPath
|
||||||
|
)
|
||||||
|
|
||||||
|
$desktop = Join-Path $env:USERPROFILE "Desktop"
|
||||||
|
|
||||||
|
$launcherExe = gci $installPath | where {$_.Name -like "*.Launcher.exe"} | select -ExpandProperty FullName
|
||||||
|
$serverExe = gci $installPath | where {$_.Name -like "*.Server.exe"} | select -ExpandProperty FullName
|
||||||
|
|
||||||
|
$launcherShortcut = Join-Path $desktop "SPT.Launcher.lnk"
|
||||||
|
$serverShortcut = Join-Path $desktop "SPT.Server.lnk"
|
||||||
|
|
||||||
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
|
|
||||||
|
$launcher = $WshShell.CreateShortcut($launcherShortcut)
|
||||||
|
$launcher.TargetPath = $launcherExe
|
||||||
|
$launcher.WorkingDirectory = $installPath
|
||||||
|
$launcher.Save()
|
||||||
|
|
||||||
|
$server = $WshShell.CreateShortcut($serverShortcut)
|
||||||
|
$server.TargetPath = $serverExe
|
||||||
|
$server.WorkingDirectory = $installPath
|
||||||
|
$server.Save()
|
@ -43,7 +43,7 @@ while (-not $copied) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Remove-Item $destination -ErrorAction SilentlyContinue
|
Remove-Item $destination -ErrorAction SilentlyContinue
|
||||||
Copy-Item $source $destination
|
Copy-Item $source $destination -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if (Test-Path $destination) {
|
if (Test-Path $destination) {
|
||||||
$sLength = (Get-Item $source).Length
|
$sLength = (Get-Item $source).Length
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
<PackageIcon>icon.ico</PackageIcon>
|
<PackageIcon>icon.ico</PackageIcon>
|
||||||
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
|
||||||
<Configurations>Debug;Release;TEST</Configurations>
|
<Configurations>Debug;Release;TEST</Configurations>
|
||||||
<AssemblyVersion>2.82</AssemblyVersion>
|
<AssemblyVersion>2.83</AssemblyVersion>
|
||||||
<FileVersion>2.82</FileVersion>
|
<FileVersion>2.83</FileVersion>
|
||||||
<Company>SPT</Company>
|
<Company>SPT</Company>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -26,6 +26,8 @@
|
|||||||
<EmbeddedResource Include="Resources\update.ps1"/>
|
<EmbeddedResource Include="Resources\update.ps1"/>
|
||||||
<None Remove="Resources\7z.dll"/>
|
<None Remove="Resources\7z.dll"/>
|
||||||
<EmbeddedResource Include="Resources\7z.dll"/>
|
<EmbeddedResource Include="Resources\7z.dll"/>
|
||||||
|
<None Remove="Resources\add_shortcuts.ps1" />
|
||||||
|
<EmbeddedResource Include="Resources\add_shortcuts.ps1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Avalonia;
|
using System.Diagnostics;
|
||||||
|
using Avalonia;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using SPTInstaller.CustomControls;
|
using SPTInstaller.CustomControls;
|
||||||
@ -9,6 +10,7 @@ using System.Windows.Input;
|
|||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
using SPTInstaller.Models;
|
||||||
|
|
||||||
namespace SPTInstaller.ViewModels;
|
namespace SPTInstaller.ViewModels;
|
||||||
|
|
||||||
@ -38,6 +40,14 @@ public class MessageViewModel : ViewModelBase
|
|||||||
set => this.RaiseAndSetIfChanged(ref _showCloseButton, value);
|
set => this.RaiseAndSetIfChanged(ref _showCloseButton, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _showOptions;
|
||||||
|
|
||||||
|
public bool ShowOptions
|
||||||
|
{
|
||||||
|
get => _showOptions;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _showOptions, value);
|
||||||
|
}
|
||||||
|
|
||||||
private string _cacheInfoText;
|
private string _cacheInfoText;
|
||||||
|
|
||||||
public string CacheInfoText
|
public string CacheInfoText
|
||||||
@ -54,6 +64,20 @@ public class MessageViewModel : ViewModelBase
|
|||||||
set => this.RaiseAndSetIfChanged(ref _clipCommandText, value);
|
set => this.RaiseAndSetIfChanged(ref _clipCommandText, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _addShortcuts;
|
||||||
|
public bool AddShortcuts
|
||||||
|
{
|
||||||
|
get => _addShortcuts;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _addShortcuts, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _openInstallFolder = true;
|
||||||
|
public bool OpenInstallFolder
|
||||||
|
{
|
||||||
|
get => _openInstallFolder;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _openInstallFolder, value);
|
||||||
|
}
|
||||||
|
|
||||||
public ICommand CopyLogFileToClipboard => ReactiveCommand.CreateFromTask(async () =>
|
public ICommand CopyLogFileToClipboard => ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
@ -97,8 +121,7 @@ public class MessageViewModel : ViewModelBase
|
|||||||
|
|
||||||
public ICommand CloseCommand { get; set; } = ReactiveCommand.Create(() =>
|
public ICommand CloseCommand { get; set; } = ReactiveCommand.Create(() =>
|
||||||
{
|
{
|
||||||
if (Application.Current.ApplicationLifetime is
|
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopApp)
|
||||||
Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
|
|
||||||
{
|
{
|
||||||
desktopApp.MainWindow.Close();
|
desktopApp.MainWindow.Close();
|
||||||
}
|
}
|
||||||
@ -110,6 +133,64 @@ public class MessageViewModel : ViewModelBase
|
|||||||
Message = result.Message;
|
Message = result.Message;
|
||||||
ClipCommandText = "Copy installer log to clipboard";
|
ClipCommandText = "Copy installer log to clipboard";
|
||||||
|
|
||||||
|
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopApp)
|
||||||
|
{
|
||||||
|
var data = ServiceHelper.Get<InternalData?>();
|
||||||
|
|
||||||
|
desktopApp.MainWindow.Closing += (_, _) =>
|
||||||
|
{
|
||||||
|
if (ShowOptions)
|
||||||
|
{
|
||||||
|
if (OpenInstallFolder)
|
||||||
|
{
|
||||||
|
Process.Start(new ProcessStartInfo()
|
||||||
|
{
|
||||||
|
FileName = "explorer.exe",
|
||||||
|
Arguments = data.TargetInstallPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AddShortcuts)
|
||||||
|
{
|
||||||
|
var shortcuts = new FileInfo(Path.Join(DownloadCacheHelper.CachePath, "add_shortcuts.ps1"));
|
||||||
|
|
||||||
|
if (!FileHelper.StreamAssemblyResourceOut("add_shortcuts.ps1", shortcuts.FullName))
|
||||||
|
{
|
||||||
|
Log.Fatal("Failed to prepare shortcuts file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(shortcuts.FullName))
|
||||||
|
{
|
||||||
|
Log.Fatal("Shortcuts file not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Information("Running add shortcuts script ...");
|
||||||
|
|
||||||
|
Process.Start(new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "powershell.exe",
|
||||||
|
CreateNoWindow = true,
|
||||||
|
ArgumentList =
|
||||||
|
{
|
||||||
|
"-ExecutionPolicy", "Bypass", "-File", $"{shortcuts.FullName}", $"{data.TargetInstallPath}"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Copy(App.LogPath, Path.Join(data.TargetInstallPath, "spt-installer.log"), true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Failed to copy installer log to install path");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
CacheInfoText = "Getting cache size ...";
|
CacheInfoText = "Getting cache size ...";
|
||||||
@ -122,6 +203,7 @@ public class MessageViewModel : ViewModelBase
|
|||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
Log.Information(Message);
|
Log.Information(Message);
|
||||||
|
ShowOptions = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
</UserControl.Styles>
|
</UserControl.Styles>
|
||||||
|
|
||||||
<Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,20,AUTO,20,Auto,*"
|
<Grid ColumnDefinitions="*,AUTO,*" RowDefinitions="*,AUTO,20,AUTO,20,Auto,Auto,*"
|
||||||
Classes.error="{Binding HasErrors}">
|
Classes.error="{Binding HasErrors}">
|
||||||
|
|
||||||
<Label Grid.Column="1" Grid.Row="1"
|
<Label Grid.Column="1" Grid.Row="1"
|
||||||
@ -35,12 +35,18 @@
|
|||||||
VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
|
VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
|
||||||
Padding="20 10" />
|
Padding="20 10" />
|
||||||
|
|
||||||
<Button Grid.Row="5" Grid.Column="1" Classes="link" Content="{Binding ClipCommandText}"
|
<StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal" Spacing="10">
|
||||||
Command="{Binding CopyLogFileToClipboard}" HorizontalAlignment="Center" VerticalAlignment="Center"
|
<CheckBox IsChecked="{Binding OpenInstallFolder}" Content="Open Install Folder" IsVisible="{Binding ShowOptions}"/>
|
||||||
|
<CheckBox IsChecked="{Binding AddShortcuts}" Content="Add Desktop Shortcuts" IsVisible="{Binding ShowOptions}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<cc:CacheInfo Grid.Row="7" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<cc:CacheInfo Grid.Row="6" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0"
|
<Button Grid.Row="7" Grid.Column="2" Classes="link" Content="{Binding ClipCommandText}"
|
||||||
VerticalAlignment="Bottom"
|
Command="{Binding CopyLogFileToClipboard}" HorizontalAlignment="Right" VerticalAlignment="Bottom"
|
||||||
InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}" />
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
Loading…
x
Reference in New Issue
Block a user