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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -29,39 +30,41 @@ namespace GCMM
|
||||||
|
|
||||||
private bool EnableDisableAutoPatching(bool enable)
|
private bool EnableDisableAutoPatching(bool enable)
|
||||||
{
|
{
|
||||||
string launcherConfig =
|
foreach (string file in Directory.EnumerateFiles(GamePath("")))
|
||||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
File.Copy(file, Path.GetFileName(file), true);
|
||||||
"Techblox Launcher", "launcher_settings.ini");
|
var toSymLink = new List<string> {GamePath("\\MonoBleedingEdge")};
|
||||||
bool gamePathSet = false;
|
Directory.CreateDirectory("TechbloxPreview_Data");
|
||||||
if (File.Exists(launcherConfig))
|
toSymLink.AddRange(Directory.EnumerateDirectories(GamePath("\\TechbloxPreview_Data"))
|
||||||
{
|
.Except(new[] {"Managed"}));
|
||||||
string[] lines = File.ReadLines(launcherConfig).Select(line =>
|
foreach (string file in Directory.EnumerateFiles(GamePath("\\TechbloxPreview_Data")))
|
||||||
{
|
File.Copy(file, "TechbloxPreview_Data\\" + Path.GetFileName(file), true);
|
||||||
if (line.StartsWith("133062..GAME_PATH=") && line.Contains('/'))
|
Directory.CreateDirectory("TechbloxPreview_Data\\Managed");
|
||||||
{
|
foreach (string file in Directory.EnumerateFiles(GamePath("\\TechbloxPreview_Data\\Managed")))
|
||||||
gamePathSet = true;
|
File.Copy(file, "TechbloxPreview_Data\\Managed\\" + Path.GetFileName(file), true);
|
||||||
return $"{line.Replace("/TBMM/", "/")}{(enable ? "TBMM/" : "")}";
|
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)
|
public void EnableDisableAutoPatchingWithDialog(bool enable)
|
||||||
{
|
{
|
||||||
if (EnableDisableAutoPatching(enable))
|
try
|
||||||
{
|
{
|
||||||
DialogUtils.ShowInfo(resources.GetString("Change_launch_settings_done"),
|
if (EnableDisableAutoPatching(enable))
|
||||||
resources.GetString("Change_launch_settings_title"));
|
{
|
||||||
Configuration.AutoPatch = enable ? AutoPatchingState.Enabled : AutoPatchingState.Disabled;
|
DialogUtils.ShowInfo(resources.GetString("Change_launch_settings_done"),
|
||||||
|
resources.GetString("Change_launch_settings_title"));
|
||||||
|
Configuration.AutoPatch = enable ? AutoPatchingState.Enabled : AutoPatchingState.Disabled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogUtils.ShowError(resources.GetString("Change_launch_settings_error"),
|
||||||
|
resources.GetString("Change_launch_settings_title"));
|
||||||
}
|
}
|
||||||
else
|
catch (Exception e)
|
||||||
DialogUtils.ShowError(resources.GetString("Change_launch_settings_error"),
|
{
|
||||||
|
DialogUtils.ShowError(resources.GetString("Change_launch_settings_error") + "\n\n" + e,
|
||||||
resources.GetString("Change_launch_settings_title"));
|
resources.GetString("Change_launch_settings_title"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetGameFolder()
|
public string GetGameFolder()
|
||||||
|
@ -72,7 +75,8 @@ namespace GCMM
|
||||||
if (!File.Exists(launcherConfig)) return null;
|
if (!File.Exists(launcherConfig)) return null;
|
||||||
string path = File.ReadLines(launcherConfig)
|
string path = File.ReadLines(launcherConfig)
|
||||||
.FirstOrDefault(line => line.StartsWith("133062..GAME_PATH="))
|
.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;
|
if (path != null && GetExe(path) != null) return path;
|
||||||
return null;
|
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