Move logs/downloaded modlists into the launcher folder

This commit is contained in:
Timothy Baldridge 2021-03-18 23:04:27 -06:00
parent c1d5f9771f
commit 22b7782578
10 changed files with 73 additions and 13 deletions

View File

@ -127,7 +127,7 @@ namespace Wabbajack.Common
public static AbsolutePath PatchCacheFolder => LocalAppDataPath.Combine("patch_cache");
public static int MaxConnectionsPerServer = 4;
public static AbsolutePath LogsFolder => ((RelativePath)"logs").RelativeToEntryPoint();
public static AbsolutePath LogsFolder { get; set; } = ((RelativePath)"logs").RelativeToEntryPoint();
public static AbsolutePath EntryPoint => (AbsolutePath)(Assembly.GetEntryAssembly()?.Location ?? (string)((RelativePath)"Unknown").RelativeToWorkingDirectory());
public static AbsolutePath LogFile => LogsFolder.Combine(EntryPoint.FileNameWithoutExtension + ".current.log");
public static int MaxOldLogs = 50;

View File

@ -30,7 +30,7 @@ namespace Wabbajack.Common
private static readonly Subject<IStatusMessage> LoggerSubj = new Subject<IStatusMessage>();
public static IObservable<IStatusMessage> LogMessages => LoggerSubj;
private static async Task InitalizeLogging()
public static async Task InitalizeLogging()
{
_startTime = DateTime.Now;

View File

@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common.IO;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using DriveInfo = Alphaleonis.Win32.Filesystem.DriveInfo;
using File = Alphaleonis.Win32.Filesystem.File;
@ -164,6 +165,11 @@ namespace Wabbajack.Common
}
}
/// <summary>
/// Returns the path to the Windows folder, most often c:\Windows
/// </summary>
public static AbsolutePath WindowsFolder => (AbsolutePath)KnownFolders.Windows.Path;
public AbsolutePath Root => (AbsolutePath)Path.GetPathRoot(_path);
/// <summary>

View File

@ -863,6 +863,14 @@ namespace Wabbajack.Common
CreateNoWindow = true,
});
}
public static void OpenFolder(AbsolutePath path)
{
Process.Start(new ProcessStartInfo(AbsolutePath.WindowsFolder.Combine("explorer.exe").ToString(), path.ToString())
{
CreateNoWindow = true,
});
}
public static bool IsInPath(this string path, string parent)
{

View File

@ -10,25 +10,37 @@ namespace Wabbajack.Lib
{
public class LauncherUpdater
{
public static async Task Run()
public static Lazy<AbsolutePath> CommonFolder = new (() =>
{
var entryPoint = AbsolutePath.EntryPoint;
// If we're not in a folder that looks like a version, abort
if (!Version.TryParse(entryPoint.FileName.ToString(), out var version))
{
Utils.Log($"Not in a version folder, not attempting update. Got {entryPoint.Parent}");
return;
return entryPoint;
}
// If we're not in a folder that has Wabbajack.exe in the parent folder, abort
if (!entryPoint.Parent.Parent.Combine(Consts.AppName).WithExtension(new Extension(".exe")).IsFile)
if (!entryPoint.Parent.Combine(Consts.AppName).WithExtension(new Extension(".exe")).IsFile)
{
Utils.Log("Parent folder does not contain launcher, not updating");
return entryPoint;
}
return entryPoint.Parent;
});
public static async Task Run()
{
if (CommonFolder.Value == AbsolutePath.EntryPoint)
{
Utils.Log("Outside of standard install folder, not updating");
return;
}
var oldVersions = entryPoint.Parent
var version = Version.Parse(AbsolutePath.EntryPoint.FileName.ToString());
var oldVersions = CommonFolder.Value
.EnumerateDirectories()
.Select(f => Version.TryParse(f.FileName.ToString(), out var ver) ? (ver, f) : default)
.Where(f => f != default)

View File

@ -12,7 +12,10 @@ namespace Wabbajack
{
public App()
{
Consts.LogsFolder = LauncherUpdater.CommonFolder.Value.Combine("logs");
LoggingSettings.LogToFile = true;
Utils.InitalizeLogging().Wait();
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
if (CLIArguments.Help)

View File

@ -75,7 +75,7 @@ namespace Wabbajack
{
_parent = parent;
Metadata = metadata;
Location = Consts.ModListDownloadFolder.Combine(Metadata.Links.MachineURL + (string)Consts.ModListExtension);
Location = LauncherUpdater.CommonFolder.Value.Combine("downloaded_mod_lists", Metadata.Links.MachineURL + (string)Consts.ModListExtension);
ModListTagList = new List<ModListTag>();
Metadata.tags.ForEach(tag =>
{

View File

@ -91,6 +91,7 @@ namespace Wabbajack
public ReactiveCommand<Unit, Unit> VisitModListWebsiteCommand { get; }
public ReactiveCommand<Unit, Unit> CloseWhenCompleteCommand { get; }
public ReactiveCommand<Unit, Unit> OpenLogsCommand { get; }
public ReactiveCommand<Unit, Unit> GoToInstallCommand { get; }
public ReactiveCommand<Unit, Unit> BeginCommand { get; }
@ -319,6 +320,9 @@ namespace Wabbajack
canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread());
OpenLogsCommand = ReactiveCommand.Create(
execute: () => Utils.OpenFolder(Consts.LogsFolder));
VisitModListWebsiteCommand = ReactiveCommand.Create(
execute: () =>
{

View File

@ -22,6 +22,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
x:Name="TitleText"
@ -80,6 +81,29 @@
Text="Install Folder" />
</Grid>
<Grid Grid.Row="1" Grid.Column="2"
VerticalAlignment="Center"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button
x:Name="OpenLogsButton"
Width="50"
Height="50"
Style="{StaticResource CircleButtonStyle}">
<icon:PackIconFontAwesome
Width="25"
Height="25"
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
Kind="ListAltRegular" />
</Button>
<TextBlock Grid.Row="1"
Margin="0,10,0,0"
HorizontalAlignment="Center"
Text="Log Files" />
</Grid>
<Grid Grid.Row="1" Grid.Column="3"
VerticalAlignment="Center"
Background="Transparent">
<Grid.RowDefinitions>
@ -102,9 +126,9 @@
HorizontalAlignment="Center"
Text="Readme" />
</Grid>
<Grid Grid.Row="1" Grid.Column="3"
VerticalAlignment="Center"
Background="Transparent">
<Grid Grid.Row="1" Grid.Column="4"
VerticalAlignment="Center"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

View File

@ -52,6 +52,9 @@ namespace Wabbajack
this.WhenAny(x => x.ViewModel.CloseWhenCompleteCommand)
.BindToStrict(this, x => x.CloseButton.Command)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.OpenLogsCommand)
.BindToStrict(this, x => x.OpenLogsButton.Command)
.DisposeWith(dispose);
});
}
}