Skip to content

Commit

Permalink
Refactor GetWorkshopFolder Logic & Document. Fixes issue with GoG whe…
Browse files Browse the repository at this point in the history
…n Directory.Exists returns true due to being too close to OS root
  • Loading branch information
Solxanich committed Aug 9, 2023
1 parent 8460afd commit cb42d82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion patches/tModLoader/Terraria/Social/SocialAPI.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

_mode = mode.Value;
@@ -48,9 +_,15 @@
@@ -48,9 +_,16 @@
break;
}

Expand All @@ -57,6 +57,7 @@
+
+ //TODO: Allow both APIs to be used at once. Currently, it would reinitiallize some of them.
+ SteamedWraps.Initialize();
+ ModLoader.Logging.tML.Info($"Current 1281930 Workshop Folder Directory: {WorkshopHelper.GetWorkshopFolder(ModLoader.Engine.Steam.TMLAppID_t)}");
}

public static void Shutdown()
Expand Down
28 changes: 19 additions & 9 deletions patches/tModLoader/Terraria/Social/Steam/WorkshopHelper.TML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ public class ModPublisherInstance : UGCBased.APublisherInstance
protected override void PrepareContentForUpdate() { }
}

/// <summary>
/// Priority is given to "-steamworkshopfolder" argument to ensure if someone has a custom steamapps/workshop folder away from tml, it can be found
/// If SteamClient is true (ie it is a steam user running a client or host&play),
/// InstallDir: SteamFiles/Steamapps/common/tModLoader is GetAppInstallDir
/// WorkshopFolder: SteamFiles/Steamapps/workshop is Path.Combine(GetAppInstallDir, .., .., Workshop)
/// If SteamClient is false, SteamAvailable = True -> Is FamilyShare or GoG Client. SteamedWraps.FamilyShare differentiates if needed
/// InstallDir: anywhere, manual.
/// WorkshopFolder: InstallDir/Steamapps/workshop
/// If Main.DedServ is true
/// Use SteamClient reference path if it exists && Not "-nosteam" supplied
/// Use NotSteamClient working folder path if "-nosteam" supplied or SteamClient ref path not exists
/// </summary>
public static string GetWorkshopFolder(AppId_t app)
{
if (Program.LaunchParameters.TryGetValue("-steamworkshopfolder", out string workshopLocCustom)) {
Expand All @@ -43,17 +55,15 @@ public static string GetWorkshopFolder(AppId_t app)
Logging.tML.Warn("-steamworkshopfolder path not found: " + workshopLocCustom);
}

string installLoc = null;
if (SteamedWraps.SteamClient) // get app install dir if possible
SteamApps.GetAppInstallDir(app, out installLoc, 1000);

installLoc ??= "."; // GetAppInstallDir may return null (#2491). Also the default location for dedicated servers and such
string steamClientPath = null; // GetAppInstallDir may return null (#2491). Also the default location for dedicated servers and such
if (SteamedWraps.SteamClient)
SteamApps.GetAppInstallDir(app, out steamClientPath, 1000);
steamClientPath ??= ".";
steamClientPath = Path.Combine(steamClientPath, "..", "..", "workshop");

var workshopLoc = Path.Combine(installLoc, "..", "..", "workshop");
if (Directory.Exists(workshopLoc) && !Program.LaunchParameters.ContainsKey("-nosteam") && !SteamedWraps.FamilyShared)
return workshopLoc;
if (SteamedWraps.SteamClient || !SteamedWraps.SteamAvailable && !Program.LaunchParameters.ContainsKey("-nosteam") && Directory.Exists(steamClientPath))
return steamClientPath;

// Load mods installed by GoG / Manually copied steamapps\workshop directories.
return Path.Combine("steamapps", "workshop");
}

Expand Down

0 comments on commit cb42d82

Please sign in to comment.