VortexCompilerVM staging and downloads picker wiring

This commit is contained in:
Justin Swanson 2019-11-16 21:09:46 -06:00
parent dec8707ff2
commit 4978e55e04
7 changed files with 66 additions and 57 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@ -7,6 +8,7 @@ using Microsoft.Win32;
namespace Wabbajack.Common
{
[DebuggerDisplay("{Name}")]
public class SteamGame
{
public int AppId;

View File

@ -27,6 +27,9 @@ namespace Wabbajack.Lib
public bool IgnoreMissingFiles { get; set; }
public const string StagingMarkerName = "__vortex_staging_folder";
public const string DownloadMarkerName = "__vortex_downloads_folder";
public VortexCompiler(Game game, string gamePath, string vortexFolder, string downloadsFolder, string stagingFolder)
{
ModManager = ModManager.Vortex;
@ -99,7 +102,7 @@ namespace Wabbajack.Lib
Directory.CreateDirectory(ModListOutputFolder);
IEnumerable<RawSourceFile> vortexStagingFiles = Directory.EnumerateFiles(StagingFolder, "*", SearchOption.AllDirectories)
.Where(p => p.FileExists() && p != "__vortex_staging_folder")
.Where(p => p.FileExists() && p != StagingMarkerName)
.Select(p => new RawSourceFile(VFS.Index.ByRootPath[p])
{Path = p.RelativeTo(StagingFolder)});
@ -412,8 +415,8 @@ namespace Wabbajack.Lib
Game == Game.DarkestDungeon ? new IncludeRegex(this, "project\\.xml$") : null,
new IgnoreStartsWith(this, " __vortex_staging_folder"),
new IgnoreEndsWith(this, "__vortex_staging_folder"),
new IgnoreStartsWith(this, StagingFolder),
new IgnoreEndsWith(this, StagingFolder),
new IgnoreGameFiles(this),
@ -432,47 +435,41 @@ namespace Wabbajack.Lib
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vortex");
}
public static bool TryRetrieveDownloadLocation(Game game, out string downloads, string vortexFolderPath = null)
{
vortexFolderPath = vortexFolderPath ?? TypicalVortexFolder();
if (!File.Exists(Path.Combine(vortexFolderPath, "downloads", "__vortex_downloads_folder")))
{
downloads = default;
return false;
}
downloads = Path.Combine(vortexFolderPath, "downloads", GameRegistry.Games[game].NexusName);
return true;
}
public static string RetrieveDownloadLocation(Game game, string vortexFolderPath = null)
{
if (!TryRetrieveDownloadLocation(game, out var loc, vortexFolderPath))
{
throw new ArgumentException("Could not locate downloads folder");
}
return loc;
}
public static bool TryRetrieveStagingLocation(Game game, out string staging, string vortexFolderPath = null)
{
vortexFolderPath = vortexFolderPath ?? TypicalVortexFolder();
var gameName = GameRegistry.Games[game].NexusName;
if (!File.Exists(Path.Combine(vortexFolderPath, gameName, "mods", "__vortex_staging_folder")))
{
staging = default;
return false;
}
staging = Path.Combine(vortexFolderPath, gameName, "mods");
return true;
return Path.Combine(vortexFolderPath, "downloads", GameRegistry.Games[game].NexusName);
}
public static string RetrieveStagingLocation(Game game, string vortexFolderPath = null)
{
if (!TryRetrieveStagingLocation(game, out var loc, vortexFolderPath))
{
throw new ArgumentException("Could not locate staging folder");
}
return loc;
vortexFolderPath = vortexFolderPath ?? TypicalVortexFolder();
var gameName = GameRegistry.Games[game].NexusName;
return Path.Combine(vortexFolderPath, gameName, "mods");
}
public static IErrorResponse IsValidBaseDownloadsFolder(string path)
{
if (!Directory.Exists(path)) return ErrorResponse.Fail($"Path does not exist: {path}");
if (Directory.EnumerateFiles(path, DownloadMarkerName, SearchOption.TopDirectoryOnly).Any()) return ErrorResponse.Success;
return ErrorResponse.Fail($"Folder must contain {DownloadMarkerName} file");
}
public static IErrorResponse IsValidDownloadsFolder(string path)
{
return IsValidBaseDownloadsFolder(Path.GetDirectoryName(path));
}
public static IErrorResponse IsValidBaseStagingFolder(string path)
{
if (!Directory.Exists(path)) return ErrorResponse.Fail($"Path does not exist: {path}");
if (Directory.EnumerateFiles(path, StagingMarkerName, SearchOption.TopDirectoryOnly).Any()) return ErrorResponse.Success;
return ErrorResponse.Fail($"Folder must contain {StagingMarkerName} file");
}
public static IErrorResponse IsValidStagingFolder(string path)
{
return IsValidBaseStagingFolder(Path.GetDirectoryName(path));
}
}
}

View File

@ -43,10 +43,6 @@ namespace Wabbajack.Test
protected VortexCompiler MakeCompiler()
{
if (VortexCompiler.TryRetrieveDownloadLocation(utils.Game, out var downloads))
{
throw new ArgumentException("Could not locate downloads folder");
}
return new VortexCompiler(
game: utils.Game,
gamePath: utils.GameFolder,

View File

@ -87,8 +87,6 @@ namespace Wabbajack
public class VortexCompilationSettings
{
public string DownloadLocation { get; set; }
public string StagingLocation { get; set; }
public Game LastCompiledGame { get; set; }
public Dictionary<Game, VortexGameSettings> ModlistSettings { get; } = new Dictionary<Game, VortexGameSettings>();
}
@ -96,6 +94,8 @@ namespace Wabbajack
public class VortexGameSettings
{
public string GameLocation { get; set; }
public string DownloadLocation { get; set; }
public string StagingLocation { get; set; }
public CompilationModlistSettings ModlistSettings { get; } = new CompilationModlistSettings();
}
}

View File

@ -46,7 +46,7 @@ namespace Wabbajack
this.ReadMeText = new FilePickerVM()
{
PathType = FilePickerVM.PathTypeOptions.File,
DoExistsCheck = true,
DoExistsCheck = false,
};
}

View File

@ -59,13 +59,13 @@ namespace Wabbajack
};
this.DownloadsLocation = new FilePickerVM()
{
DoExistsCheck = false,
DoExistsCheck = true,
PathType = FilePickerVM.PathTypeOptions.Folder,
PromptTitle = "Select Downloads Folder"
};
this.StagingLocation = new FilePickerVM()
{
DoExistsCheck = false,
DoExistsCheck = true,
PathType = FilePickerVM.PathTypeOptions.Folder,
PromptTitle = "Select Staging Folder"
};
@ -115,14 +115,6 @@ namespace Wabbajack
// Load settings
this.settings = parent.MWVM.Settings.Compiler.VortexCompilation;
this.SelectedGame = gameOptions.First(x => x.Game == settings.LastCompiledGame);
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
{
this.DownloadsLocation.TargetPath = settings.DownloadLocation;
}
if (!string.IsNullOrWhiteSpace(settings.StagingLocation))
{
this.StagingLocation.TargetPath = settings.StagingLocation;
}
parent.MWVM.Settings.SaveSignal
.Subscribe(_ => Unload())
.DisposeWith(this.CompositeDisposable);
@ -149,6 +141,16 @@ namespace Wabbajack
{
this.SetGameToGogLocation();
}
this.DownloadsLocation.TargetPath = pair.Current?.DownloadLocation ?? null;
if (string.IsNullOrWhiteSpace(this.DownloadsLocation.TargetPath))
{
this.DownloadsLocation.TargetPath = VortexCompiler.RetrieveDownloadLocation(this.SelectedGame.Game);
}
this.StagingLocation.TargetPath = pair.Current?.StagingLocation ?? null;
if (string.IsNullOrWhiteSpace(this.StagingLocation.TargetPath))
{
this.StagingLocation.TargetPath = VortexCompiler.RetrieveStagingLocation(this.SelectedGame.Game);
}
})
.DisposeWith(this.CompositeDisposable);
@ -174,12 +176,24 @@ namespace Wabbajack
// Find game commands
this.FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation);
this.FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation);
// Add additional criteria to download/staging folders
this.DownloadsLocation.AdditionalError = this.WhenAny(x => x.DownloadsLocation.TargetPath)
.Select(path =>
{
if (path == null) return ErrorResponse.Success;
return VortexCompiler.IsValidDownloadsFolder(path);
});
this.StagingLocation.AdditionalError = this.WhenAny(x => x.StagingLocation.TargetPath)
.Select(path =>
{
if (path == null) return ErrorResponse.Success;
return VortexCompiler.IsValidBaseStagingFolder(path);
});
}
public void Unload()
{
settings.DownloadLocation = this.DownloadsLocation.TargetPath;
settings.StagingLocation = this.StagingLocation.TargetPath;
settings.LastCompiledGame = this.SelectedGame.Game;
this.ModlistSettings?.Save();
}

View File

@ -110,7 +110,7 @@
Grid.Column="6"
Height="30"
VerticalAlignment="Center"
DataContext="{Binding DownloadLocation}"
DataContext="{Binding DownloadsLocation}"
FontSize="14"
ToolTip="The folder to downloads your mods" />
<TextBlock