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>
|
||||
<TextBox Text="Some cool text here" Margin="5" />
|
||||
<TextBox Watermark="This is a watermark" Margin="5" />
|
||||
<CheckBox Content="sldkflskdf" />
|
||||
</StackPanel>
|
||||
</Design.PreviewWith>
|
||||
|
||||
@ -267,4 +268,30 @@
|
||||
<Style Selector="Button.icon:pressed">
|
||||
<Setter Property="Foreground" Value="{StaticResource SPT_DarkGrayBlue}"></Setter>
|
||||
</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>
|
@ -98,33 +98,29 @@ public static class FileHelper
|
||||
{
|
||||
Log.Debug($"Starting StreamAssemblyResourceOut, resourcename: {resourceName}, outputFilePath: {outputFilePath}");
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
Log.Debug($"1");
|
||||
|
||||
FileInfo outputFile = new FileInfo(outputFilePath);
|
||||
Log.Debug($"2");
|
||||
|
||||
if (outputFile.Exists)
|
||||
{
|
||||
Log.Debug($"3");
|
||||
outputFile.Delete();
|
||||
}
|
||||
Log.Debug($"4");
|
||||
|
||||
if (!outputFile.Directory.Exists)
|
||||
{
|
||||
Log.Debug($"5");
|
||||
Directory.CreateDirectory(outputFile.Directory.FullName);
|
||||
}
|
||||
Log.Debug($"6");
|
||||
|
||||
var resName = assembly.GetManifestResourceNames().First(x => x.EndsWith(resourceName));
|
||||
Log.Debug($"7");
|
||||
|
||||
using (FileStream fs = File.Create(outputFilePath))
|
||||
using (Stream s = assembly.GetManifestResourceStream(resName))
|
||||
{
|
||||
Log.Debug($"8");
|
||||
s.CopyTo(fs);
|
||||
}
|
||||
Log.Debug($"9");
|
||||
|
||||
outputFile.Refresh();
|
||||
Log.Debug(outputFile.Exists.ToString());
|
||||
|
||||
return outputFile.Exists;
|
||||
}
|
||||
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
|
||||
Copy-Item $source $destination
|
||||
Copy-Item $source $destination -ErrorAction SilentlyContinue
|
||||
|
||||
if (Test-Path $destination) {
|
||||
$sLength = (Get-Item $source).Length
|
||||
|
@ -10,8 +10,8 @@
|
||||
<PackageIcon>icon.ico</PackageIcon>
|
||||
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
|
||||
<Configurations>Debug;Release;TEST</Configurations>
|
||||
<AssemblyVersion>2.82</AssemblyVersion>
|
||||
<FileVersion>2.82</FileVersion>
|
||||
<AssemblyVersion>2.83</AssemblyVersion>
|
||||
<FileVersion>2.83</FileVersion>
|
||||
<Company>SPT</Company>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -26,6 +26,8 @@
|
||||
<EmbeddedResource Include="Resources\update.ps1"/>
|
||||
<None Remove="Resources\7z.dll"/>
|
||||
<EmbeddedResource Include="Resources\7z.dll"/>
|
||||
<None Remove="Resources\add_shortcuts.ps1" />
|
||||
<EmbeddedResource Include="Resources\add_shortcuts.ps1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Avalonia;
|
||||
using System.Diagnostics;
|
||||
using Avalonia;
|
||||
using ReactiveUI;
|
||||
using Serilog;
|
||||
using SPTInstaller.CustomControls;
|
||||
@ -9,6 +10,7 @@ using System.Windows.Input;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Platform.Storage;
|
||||
using SPTInstaller.Models;
|
||||
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
@ -38,6 +40,14 @@ public class MessageViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _showCloseButton, value);
|
||||
}
|
||||
|
||||
private bool _showOptions;
|
||||
|
||||
public bool ShowOptions
|
||||
{
|
||||
get => _showOptions;
|
||||
set => this.RaiseAndSetIfChanged(ref _showOptions, value);
|
||||
}
|
||||
|
||||
private string _cacheInfoText;
|
||||
|
||||
public string CacheInfoText
|
||||
@ -54,6 +64,20 @@ public class MessageViewModel : ViewModelBase
|
||||
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 () =>
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
@ -97,8 +121,7 @@ public class MessageViewModel : ViewModelBase
|
||||
|
||||
public ICommand CloseCommand { get; set; } = ReactiveCommand.Create(() =>
|
||||
{
|
||||
if (Application.Current.ApplicationLifetime is
|
||||
Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
|
||||
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopApp)
|
||||
{
|
||||
desktopApp.MainWindow.Close();
|
||||
}
|
||||
@ -110,6 +133,64 @@ public class MessageViewModel : ViewModelBase
|
||||
Message = result.Message;
|
||||
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(() =>
|
||||
{
|
||||
CacheInfoText = "Getting cache size ...";
|
||||
@ -122,6 +203,7 @@ public class MessageViewModel : ViewModelBase
|
||||
if (result.Succeeded)
|
||||
{
|
||||
Log.Information(Message);
|
||||
ShowOptions = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
</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}">
|
||||
|
||||
<Label Grid.Column="1" Grid.Row="1"
|
||||
@ -35,12 +35,18 @@
|
||||
VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
|
||||
Padding="20 10" />
|
||||
|
||||
<Button Grid.Row="5" Grid.Column="1" Classes="link" Content="{Binding ClipCommandText}"
|
||||
Command="{Binding CopyLogFileToClipboard}" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
/>
|
||||
<StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal" Spacing="10">
|
||||
<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="6" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0"
|
||||
<cc:CacheInfo Grid.Row="7" Grid.ColumnSpan="3" Padding="10" Margin="10 0 0 0"
|
||||
VerticalAlignment="Bottom"
|
||||
InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}" />
|
||||
InfoText="{Binding CacheInfoText}" State="{Binding CacheCheckState}"
|
||||
/>
|
||||
|
||||
<Button Grid.Row="7" Grid.Column="2" Classes="link" Content="{Binding ClipCommandText}"
|
||||
Command="{Binding CopyLogFileToClipboard}" HorizontalAlignment="Right" VerticalAlignment="Bottom"
|
||||
/>
|
||||
</Grid>
|
||||
</UserControl>
|
Loading…
x
Reference in New Issue
Block a user