Use symlinks to create a modded copy
This commit is contained in:
parent
a7d26ebdb8
commit
8676e232da
2 changed files with 46 additions and 28 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
@ -29,29 +30,25 @@ namespace GCMM
|
|||
|
||||
private bool EnableDisableAutoPatching(bool enable)
|
||||
{
|
||||
string launcherConfig =
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"Techblox Launcher", "launcher_settings.ini");
|
||||
bool gamePathSet = false;
|
||||
if (File.Exists(launcherConfig))
|
||||
{
|
||||
string[] lines = File.ReadLines(launcherConfig).Select(line =>
|
||||
{
|
||||
if (line.StartsWith("133062..GAME_PATH=") && line.Contains('/'))
|
||||
{
|
||||
gamePathSet = true;
|
||||
return $"{line.Replace("/TBMM/", "/")}{(enable ? "TBMM/" : "")}";
|
||||
foreach (string file in Directory.EnumerateFiles(GamePath("")))
|
||||
File.Copy(file, Path.GetFileName(file), true);
|
||||
var toSymLink = new List<string> {GamePath("\\MonoBleedingEdge")};
|
||||
Directory.CreateDirectory("TechbloxPreview_Data");
|
||||
toSymLink.AddRange(Directory.EnumerateDirectories(GamePath("\\TechbloxPreview_Data"))
|
||||
.Except(new[] {"Managed"}));
|
||||
foreach (string file in Directory.EnumerateFiles(GamePath("\\TechbloxPreview_Data")))
|
||||
File.Copy(file, "TechbloxPreview_Data\\" + Path.GetFileName(file), true);
|
||||
Directory.CreateDirectory("TechbloxPreview_Data\\Managed");
|
||||
foreach (string file in Directory.EnumerateFiles(GamePath("\\TechbloxPreview_Data\\Managed")))
|
||||
File.Copy(file, "TechbloxPreview_Data\\Managed\\" + Path.GetFileName(file), true);
|
||||
return toSymLink.Select(targetName => (sourceName: targetName.Replace(GamePath("\\"), ""), targetName))
|
||||
.Where(tuple => !Directory.Exists(tuple.sourceName))
|
||||
.All(tuple => SymLinks.CreateFolderSymbolicLink(tuple.sourceName, tuple.targetName));
|
||||
}
|
||||
|
||||
return line;
|
||||
}).ToArray(); //Need to close the file
|
||||
File.WriteAllLines(launcherConfig, lines);
|
||||
}
|
||||
|
||||
return gamePathSet;
|
||||
} //TODO: Setting the game path might not be a good idea because of updates...
|
||||
|
||||
public void EnableDisableAutoPatchingWithDialog(bool enable)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (EnableDisableAutoPatching(enable))
|
||||
{
|
||||
|
@ -63,6 +60,12 @@ namespace GCMM
|
|||
DialogUtils.ShowError(resources.GetString("Change_launch_settings_error"),
|
||||
resources.GetString("Change_launch_settings_title"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DialogUtils.ShowError(resources.GetString("Change_launch_settings_error") + "\n\n" + e,
|
||||
resources.GetString("Change_launch_settings_title"));
|
||||
}
|
||||
}
|
||||
|
||||
public string GetGameFolder()
|
||||
{
|
||||
|
@ -72,7 +75,8 @@ namespace GCMM
|
|||
if (!File.Exists(launcherConfig)) return null;
|
||||
string path = File.ReadLines(launcherConfig)
|
||||
.FirstOrDefault(line => line.StartsWith("133062..GAME_PATH="))
|
||||
?.Substring("133062..GAME_PATH=".Length).Replace("/TBMM/", "/") + "StandaloneWindows64";
|
||||
?.Substring("133062..GAME_PATH=".Length).Replace("/TBMM/", "/");
|
||||
if (path != null) path = (path + "StandaloneWindows64").Replace('/', Path.DirectorySeparatorChar);
|
||||
if (path != null && GetExe(path) != null) return path;
|
||||
return null;
|
||||
}
|
||||
|
|
14
GCMM/SymLinks.cs
Normal file
14
GCMM/SymLinks.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace GCMM
|
||||
{
|
||||
public class SymLinks
|
||||
{
|
||||
public static bool CreateFolderSymbolicLink(string source, string target)
|
||||
{
|
||||
var proc = Process.Start(new ProcessStartInfo("cmd.exe", $"/c mklink /J \"{source}\" \"{target}\""));
|
||||
proc?.WaitForExit();
|
||||
return proc?.ExitCode == 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue