Merge pull request #262 from wabbajack-tools/fix-deleting-downloads

Fix case sensitive bug with download deletion during install
This commit is contained in:
Timothy Baldridge 2019-12-12 16:00:31 -07:00 committed by GitHub
commit bc057704d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View File

@ -928,5 +928,12 @@ namespace Wabbajack.Common
var decoded = ProtectedData.Unprotect(bytes, Encoding.UTF8.GetBytes(key), DataProtectionScope.LocalMachine); var decoded = ProtectedData.Unprotect(bytes, Encoding.UTF8.GetBytes(key), DataProtectionScope.LocalMachine);
return Encoding.UTF8.GetString(decoded).FromJSONString<T>(); return Encoding.UTF8.GetString(decoded).FromJSONString<T>();
} }
public static bool IsInPath(this string path, string parent)
{
return path.ToLower().TrimEnd('\\').StartsWith(parent.ToLower().TrimEnd('\\') + "\\");
}
} }
} }

View File

@ -348,10 +348,8 @@ namespace Wabbajack.Lib
{ {
var relative_to = f.RelativeTo(OutputFolder); var relative_to = f.RelativeTo(OutputFolder);
Utils.Status($"Checking if modlist file {relative_to}"); Utils.Status($"Checking if modlist file {relative_to}");
if (indexed.ContainsKey(relative_to) || f.StartsWith(DownloadFolder + Path.DirectorySeparator)) if (indexed.ContainsKey(relative_to) || f.IsInPath(DownloadFolder))
{
return; return;
}
Utils.Log($"Deleting {relative_to} it's not part of this modlist"); Utils.Log($"Deleting {relative_to} it's not part of this modlist");
File.Delete(f); File.Delete(f);

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wabbajack.Common;
namespace Wabbajack.Test
{
[TestClass]
public class UtilsTests
{
[TestMethod]
public void IsInPathTests()
{
Assert.IsTrue("c:\\foo\\bar.exe".IsInPath("c:\\foo"));
Assert.IsFalse("c:\\foo\\bar.exe".IsInPath("c:\\fo"));
Assert.IsTrue("c:\\Foo\\bar.exe".IsInPath("c:\\foo"));
Assert.IsTrue("c:\\foo\\bar.exe".IsInPath("c:\\Foo"));
Assert.IsTrue("c:\\foo\\bar.exe".IsInPath("c:\\fOo"));
Assert.IsTrue("c:\\foo\\bar.exe".IsInPath("c:\\foo\\"));
Assert.IsTrue("c:\\foo\\bar\\".IsInPath("c:\\foo\\"));
}
}
}

View File

@ -112,6 +112,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ContentRightsManagementTests.cs" /> <Compile Include="ContentRightsManagementTests.cs" />
<Compile Include="CompilationStackTests.cs" /> <Compile Include="CompilationStackTests.cs" />
<Compile Include="UtilsTests.cs" />
<Compile Include="VortexTests.cs" /> <Compile Include="VortexTests.cs" />
<Compile Include="WebAutomationTests.cs" /> <Compile Include="WebAutomationTests.cs" />
<Compile Include="zEditIntegrationTests.cs" /> <Compile Include="zEditIntegrationTests.cs" />