mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
MO2Tests pass
This commit is contained in:
parent
9d3af1db5c
commit
54a7bc36d5
@ -125,5 +125,7 @@ namespace Wabbajack.Common
|
||||
public static RelativePath SettingsIni = (RelativePath)"settings.ini";
|
||||
public static byte SettingsVersion => 1;
|
||||
public static RelativePath ModListTxt = (RelativePath)"modlist.txt";
|
||||
public static RelativePath ModOrganizer2Exe = (RelativePath)"ModOrganizer.exe";
|
||||
public static RelativePath ModOrganizer2Ini = (RelativePath)"ModOrganizer.ini";
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ namespace Wabbajack.Common
|
||||
public AbsolutePath Parent => (AbsolutePath)Path.GetDirectoryName(_path);
|
||||
public RelativePath FileName => (RelativePath)Path.GetFileName(_path);
|
||||
public RelativePath FileNameWithoutExtension => (RelativePath)Path.GetFileNameWithoutExtension(_path);
|
||||
public bool IsEmptyDirectory => IsDirectory && !EnumerateFiles().Any();
|
||||
|
||||
/// <summary>
|
||||
/// Moves this file to the specified location
|
||||
|
@ -390,52 +390,40 @@ namespace Wabbajack.Lib
|
||||
await OutputFolder.Combine(directive.To).WriteAllTextAsync(data);
|
||||
}
|
||||
|
||||
public static IErrorResponse CheckValidInstallPath(string path, string downloadFolder)
|
||||
public static IErrorResponse CheckValidInstallPath(AbsolutePath path, AbsolutePath? downloadFolder)
|
||||
{
|
||||
var ret = Utils.IsDirectoryPathValid(path);
|
||||
if (!ret.Succeeded) return ret;
|
||||
|
||||
if (!Directory.Exists(path)) return ErrorResponse.Success;
|
||||
if (!path.Exists) return ErrorResponse.Success;
|
||||
|
||||
// Check folder does not have a Wabbajack ModList
|
||||
foreach (var file in Directory.EnumerateFiles(path))
|
||||
if (path.EnumerateFiles(false).Where(file => file.Exists).Any(file => file.Extension == Consts.ModListExtension))
|
||||
{
|
||||
if (!File.Exists(file)) continue;
|
||||
if (System.IO.Path.GetExtension(file).Equals(Consts.ModListExtension))
|
||||
{
|
||||
return ErrorResponse.Fail($"Cannot install into a folder with a Wabbajack ModList inside of it");
|
||||
}
|
||||
return ErrorResponse.Fail($"Cannot install into a folder with a Wabbajack ModList inside of it");
|
||||
}
|
||||
|
||||
// Check folder is either empty, or a likely valid previous install
|
||||
if (!Directory.IsEmpty(path))
|
||||
if (path.IsEmptyDirectory)
|
||||
{
|
||||
// If we have a MO2 install, assume good to go
|
||||
if (Directory.EnumerateFiles(path).Any(file =>
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
if (fileName.Equals("ModOrganizer.exe", StringComparison.OrdinalIgnoreCase)) return true;
|
||||
if (fileName.Equals("ModOrganizer.ini", StringComparison.OrdinalIgnoreCase)) return true;
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
return ErrorResponse.Success;
|
||||
}
|
||||
|
||||
// If we don't have a MO2 install, and there's any file that's not in the downloads folder, mark failure
|
||||
if (Directory.EnumerateFiles(path).Any(file =>
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
if (string.IsNullOrWhiteSpace(downloadFolder)) return true;
|
||||
return !Utils.IsUnderneathDirectory(file, downloadFolder);
|
||||
}))
|
||||
{
|
||||
return ErrorResponse.Fail($"Cannot install into a non-empty folder that does not look like a previous WJ installation.\n" +
|
||||
$"To override, delete all installed files from your target installation folder. Any files in your download folder are okay to keep.");
|
||||
}
|
||||
return ErrorResponse.Success;
|
||||
}
|
||||
|
||||
return ErrorResponse.Success;
|
||||
// If we have a MO2 install, assume good to go
|
||||
if (path.EnumerateFiles(false).Any(file =>
|
||||
{
|
||||
if (file.FileName == Consts.ModOrganizer2Exe) return true;
|
||||
if (file.FileName == Consts.ModOrganizer2Ini) return true;
|
||||
return false;
|
||||
}))
|
||||
{
|
||||
return ErrorResponse.Success;
|
||||
}
|
||||
|
||||
// If we don't have a MO2 install, and there's any file that's not in the downloads folder, mark failure
|
||||
if (downloadFolder.HasValue && path.EnumerateFiles(true).All(file => file.InFolder(downloadFolder.Value)))
|
||||
{
|
||||
return ErrorResponse.Success;
|
||||
}
|
||||
|
||||
return ErrorResponse.Fail($"Cannot install to this folder as it has unknown files that could be deleted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
using Xunit;
|
||||
|
||||
namespace Wabbajack.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class MO2Tests
|
||||
{
|
||||
#region CheckValidInstallPath
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_Empty()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
Assert.IsTrue(MO2Installer.CheckValidInstallPath(tempDir.Dir.FullName, downloadFolder: null).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_DoesNotExist()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
Assert.IsTrue(MO2Installer.CheckValidInstallPath(Path.Combine(tempDir.Dir.FullName, "Subfolder"), downloadFolder: null).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir.Combine("Subfolder"), downloadFolder: null).Succeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CheckValidInstallPath_Invalid()
|
||||
{
|
||||
// TODO: This doesn't fail, and I'm not sure why it should?
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
// Assert.IsFalse(MO2Installer.CheckValidInstallPath($"{tempDir.Dir.FullName}/*", downloadFolder: null).Succeeded);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_HasModlist()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
File.Create(Path.Combine(tempDir.Dir.FullName, $"ModOrganizer.exe"));
|
||||
File.Create(Path.Combine(tempDir.Dir.FullName, $"modlist{Consts.ModListExtension}"));
|
||||
Assert.IsFalse(MO2Installer.CheckValidInstallPath(tempDir.Dir.FullName, downloadFolder: null).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
using var mo2 = tempDir.Dir.Combine("ModOrganizer.exe").Create();
|
||||
using var molist = tempDir.Dir.Combine(((RelativePath)"modlist")).WithExtension(Consts.ModListExtension).Create();
|
||||
Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_ProperOverwrite()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
File.Create(Path.Combine(tempDir.Dir.FullName, $"ModOrganizer.exe"));
|
||||
Assert.IsTrue(MO2Installer.CheckValidInstallPath(tempDir.Dir.FullName, downloadFolder: null).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
using var tmp = tempDir.Dir.Combine(Consts.ModOrganizer2Exe).Create();
|
||||
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_ImproperOverwrite()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
File.Create(Path.Combine(tempDir.Dir.FullName, $"someFile.txt"));
|
||||
Assert.IsFalse(MO2Installer.CheckValidInstallPath(tempDir.Dir.FullName, downloadFolder: null).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
tempDir.Dir.DeleteDirectory();
|
||||
tempDir.Dir.CreateDirectory();
|
||||
using var tmp = tempDir.Dir.Combine($"someFile.txt").Create();
|
||||
Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Fact]
|
||||
public void CheckValidInstallPath_OverwriteFilesInDownloads()
|
||||
{
|
||||
using (var tempDir = new TempFolder())
|
||||
{
|
||||
var downloadsFolder = Path.Combine(tempDir.Dir.FullName, "downloads");
|
||||
Directory.CreateDirectory(downloadsFolder);
|
||||
File.Create(Path.Combine(tempDir.Dir.FullName, $"downloads/someFile.txt"));
|
||||
Assert.IsTrue(MO2Installer.CheckValidInstallPath(tempDir.Dir.FullName, downloadFolder: downloadsFolder).Succeeded);
|
||||
}
|
||||
using var tempDir = new TempFolder();
|
||||
var downloadsFolder = tempDir.Dir.Combine("downloads");
|
||||
downloadsFolder.CreateDirectory();
|
||||
using var tmp = tempDir.Dir.Combine($"downloads/someFile.txt").Create();
|
||||
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: downloadsFolder).Succeeded);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -18,8 +18,6 @@
|
||||
<None Include="EndToEndTests.cs" />
|
||||
<Compile Remove="Extensions.cs" />
|
||||
<None Include="Extensions.cs" />
|
||||
<Compile Remove="MO2Tests.cs" />
|
||||
<None Include="MO2Tests.cs" />
|
||||
<Compile Remove="RestartingDownloadsTests.cs" />
|
||||
<None Include="RestartingDownloadsTests.cs" />
|
||||
<Compile Remove="SanityTests.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user