mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix the launcher so it no longer dies when run from strange folders
This commit is contained in:
parent
bbe75e5061
commit
1408926de9
@ -17,9 +17,4 @@
|
||||
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xunit.DependencyInjection" Version="8.5.0" />
|
||||
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="8.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -9,6 +9,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MessageBox.Avalonia.DTO;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Compression.Zip;
|
||||
using Wabbajack.Downloaders.Http;
|
||||
@ -172,14 +173,38 @@ public class MainWindowViewModel : ViewModelBase
|
||||
|
||||
private async Task VerifyCurrentLocation()
|
||||
{
|
||||
var entryPoint = KnownFolders.EntryPoint;
|
||||
if (entryPoint.FileName == "Desktop".ToRelativePath()
|
||||
|| entryPoint.Depth <= 1
|
||||
|| entryPoint.FileName == "Downloads".ToRelativePath())
|
||||
try
|
||||
{
|
||||
var entryPoint = KnownFolders.EntryPoint;
|
||||
if (entryPoint.FileName == "Desktop".ToRelativePath()
|
||||
|| entryPoint.Depth <= 1
|
||||
|| entryPoint.FileName == "Downloads".ToRelativePath())
|
||||
{
|
||||
|
||||
var msg = MessageBox.Avalonia.MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(new MessageBoxStandardParams()
|
||||
{
|
||||
Topmost = true,
|
||||
ShowInCenter = true,
|
||||
ContentTitle = "Wabbajack Launcher: Bad startup path",
|
||||
ContentMessage =
|
||||
"Cannot start in the root, Downloads or Desktop folders.\nPlease move Wabbajack to another folder."
|
||||
});
|
||||
var result = await msg.Show();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = ex.Message;
|
||||
var msg = MessageBox.Avalonia.MessageBoxManager
|
||||
.GetMessageBoxStandardWindow("Bad Download Path",
|
||||
"Cannot start in the root, Downloads or Desktop folders.");
|
||||
.GetMessageBoxStandardWindow(new MessageBoxStandardParams()
|
||||
{
|
||||
Topmost = true,
|
||||
ShowInCenter = true,
|
||||
ContentTitle = "Wabbajack Launcher: Error",
|
||||
ContentMessage = ex.ToString()
|
||||
});
|
||||
var result = await msg.Show();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.2-mauipre.1.22054.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
|
||||
<PackageReference Include="Xunit.DependencyInjection" Version="8.5.0" />
|
||||
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
@ -11,13 +11,15 @@ public static class KnownFolders
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = Process.GetCurrentProcess().MainModule!.FileName!.ToAbsolutePath().Parent;
|
||||
if (result.FileName == "dotnet".ToRelativePath() || Assembly.GetEntryAssembly() != null)
|
||||
var result = Process.GetCurrentProcess().MainModule?.FileName?.ToAbsolutePath() ?? default;
|
||||
|
||||
|
||||
if ((result != default && result.Depth > 1 && result.FileName == "dotnet".ToRelativePath()) || Assembly.GetEntryAssembly() != null)
|
||||
{
|
||||
return Assembly.GetExecutingAssembly().Location.ToAbsolutePath().Parent;
|
||||
result = Assembly.GetEntryAssembly()!.Location.ToAbsolutePath();
|
||||
}
|
||||
|
||||
return result;
|
||||
return result == default ? Environment.CurrentDirectory.ToAbsolutePath() : result.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public struct AbsolutePath : IPath, IComparable<AbsolutePath>, IEquatable<Absolu
|
||||
internal readonly string[] Parts;
|
||||
|
||||
public Extension Extension => Extension.FromPath(Parts[^1]);
|
||||
public RelativePath FileName => (RelativePath) Parts[^1];
|
||||
public RelativePath FileName => new(Parts[^1..]);
|
||||
|
||||
internal AbsolutePath(string[] parts, PathFormat format)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user