mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
We now remap ModOrganizer.ini files
This commit is contained in:
parent
7be81d9a98
commit
5c7acc5e18
@ -31,6 +31,15 @@ namespace Wabbajack.Common
|
||||
|
||||
public static string WABBAJACK_INCLUDE = "WABBAJACK_INCLUDE";
|
||||
|
||||
public static string GAME_PATH_MAGIC_BACK = "{--||GAME_PATH_MAGIC_BACK||--}";
|
||||
public static string GAME_PATH_MAGIC_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}";
|
||||
public static string GAME_PATH_MAGIC_FORWARD = "{--||GAME_PATH_MAGIC_FORWARD||--}";
|
||||
|
||||
public static string MO2_PATH_MAGIC_BACK = "{--||MO2_PATH_MAGIC_BACK||--}";
|
||||
public static string MO2_PATH_MAGIC_DOUBLE_BACK = "{--||MO2_PATH_MAGIC_DOUBLE_BACK||--}";
|
||||
public static string MO2_PATH_MAGIC_FORWARD = "{--||MO2_PATH_MAGIC_FORWARD||--}";
|
||||
|
||||
|
||||
public static String AppName = "Wabbajack";
|
||||
public static string HashCacheName = "Wabbajack.hash_cache";
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ namespace Wabbajack
|
||||
IgnoreDisabledMods(),
|
||||
IncludeThisProfile(),
|
||||
// Ignore the ModOrganizer.ini file it contains info created by MO2 on startup
|
||||
IgnoreStartsWith("ModOrganizer.ini"),
|
||||
IncludeStubbedMO2Ini(),
|
||||
IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Data")),
|
||||
IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Papyrus Compiler")),
|
||||
IgnoreStartsWith(Path.Combine(Consts.GameFolderFilesDir, "Skyrim")),
|
||||
@ -524,6 +524,35 @@ namespace Wabbajack
|
||||
};
|
||||
}
|
||||
|
||||
private Func<RawSourceFile, Directive> IncludeStubbedMO2Ini()
|
||||
{
|
||||
return source =>
|
||||
{
|
||||
if (source.Path == "ModOrganizer.ini")
|
||||
{
|
||||
return RemapIni(source, GamePath);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
private Directive RemapIni(RawSourceFile source, string gamePath)
|
||||
{
|
||||
var data = File.ReadAllText(source.AbsolutePath);
|
||||
|
||||
data = data.Replace(GamePath, Consts.GAME_PATH_MAGIC_BACK);
|
||||
data = data.Replace(GamePath.Replace("\\", "\\\\"), Consts.GAME_PATH_MAGIC_DOUBLE_BACK);
|
||||
data = data.Replace(GamePath.Replace("\\", "/"), Consts.GAME_PATH_MAGIC_FORWARD);
|
||||
|
||||
data = data.Replace(MO2Folder, Consts.MO2_PATH_MAGIC_BACK);
|
||||
data = data.Replace(MO2Folder.Replace("\\", "\\\\"), Consts.MO2_PATH_MAGIC_DOUBLE_BACK);
|
||||
data = data.Replace(MO2Folder.Replace("\\", "/"), Consts.MO2_PATH_MAGIC_FORWARD);
|
||||
var result = source.EvolveTo<RemappedInlineFile>();
|
||||
result.SourceData = Encoding.UTF8.GetBytes(data).ToBase64();
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private Func<RawSourceFile, Directive> IgnorePathContains(string v)
|
||||
{
|
||||
v = $"\\{v.Trim('\\')}\\";
|
||||
|
@ -96,6 +96,13 @@ namespace Wabbajack
|
||||
public string SourceData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A file that has the game and MO2 folders remapped on installation
|
||||
/// </summary>
|
||||
public class RemappedInlineFile : InlineFile
|
||||
{
|
||||
}
|
||||
|
||||
public class FromArchive : Directive
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using CG.Web.MegaApiClient;
|
||||
using Compression.BSA;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -45,6 +46,7 @@ namespace Wabbajack
|
||||
|
||||
public string NexusAPIKey { get; private set; }
|
||||
public bool IgnoreMissingFiles { get; internal set; }
|
||||
public string GameFolder { get; private set; }
|
||||
|
||||
public void Info(string msg, params object[] args)
|
||||
{
|
||||
@ -79,6 +81,12 @@ namespace Wabbajack
|
||||
Directory.CreateDirectory(Outputfolder);
|
||||
Directory.CreateDirectory(DownloadFolder);
|
||||
|
||||
if (ModList.Directives.OfType<RemappedInlineFile>().FirstOrDefault() != null && !LocateGameFolder())
|
||||
{
|
||||
Info("Stopping installation because game folder was not selected");
|
||||
return;
|
||||
}
|
||||
|
||||
HashArchives();
|
||||
DownloadArchives();
|
||||
HashArchives();
|
||||
@ -108,7 +116,20 @@ namespace Wabbajack
|
||||
Info("Installation complete! You may exit the program.");
|
||||
}
|
||||
|
||||
|
||||
private bool LocateGameFolder()
|
||||
{
|
||||
var vf = new VistaFolderBrowserDialog();
|
||||
vf.Description = "Please Locate Your Game Installation Path";
|
||||
vf.UseDescriptionForTitle = true;
|
||||
if (vf.ShowDialog() == true)
|
||||
{
|
||||
GameFolder = vf.SelectedPath;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// We don't want to make the installer index all the archives, that's just a waste of time, so instead
|
||||
/// we'll pass just enough information to VFS to let it know about the files we have.
|
||||
@ -192,11 +213,33 @@ namespace Wabbajack
|
||||
Status("Writing included file {0}", directive.To);
|
||||
var out_path = Path.Combine(Outputfolder, directive.To);
|
||||
if (File.Exists(out_path)) File.Delete(out_path);
|
||||
|
||||
File.WriteAllBytes(out_path, directive.SourceData.FromBase64());
|
||||
if (directive is RemappedInlineFile)
|
||||
{
|
||||
WriteRemappedFile((RemappedInlineFile)directive);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllBytes(out_path, directive.SourceData.FromBase64());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void WriteRemappedFile(RemappedInlineFile directive)
|
||||
{
|
||||
var data = Encoding.UTF8.GetString(directive.SourceData.FromBase64());
|
||||
|
||||
data = data.Replace(Consts.GAME_PATH_MAGIC_BACK, GameFolder);
|
||||
data = data.Replace(Consts.GAME_PATH_MAGIC_DOUBLE_BACK, GameFolder.Replace("\\", "\\\\"));
|
||||
data = data.Replace(Consts.GAME_PATH_MAGIC_FORWARD, GameFolder.Replace("\\", "/"));
|
||||
|
||||
data = data.Replace(Consts.MO2_PATH_MAGIC_BACK, Outputfolder);
|
||||
data = data.Replace(Consts.MO2_PATH_MAGIC_DOUBLE_BACK, Outputfolder.Replace("\\", "\\\\"));
|
||||
data = data.Replace(Consts.MO2_PATH_MAGIC_FORWARD, Outputfolder.Replace("\\", "/"));
|
||||
|
||||
File.WriteAllText(Path.Combine(Outputfolder, directive.To), data);
|
||||
return;
|
||||
}
|
||||
|
||||
private void BuildFolderStructure()
|
||||
{
|
||||
Info("Building Folder Structure");
|
||||
|
Loading…
Reference in New Issue
Block a user