Game.Modding.Toolchain.Dependencies.RiderPathLocator
Assembly: Game (Assembly-CSharp)
Namespace: Game.Modding.Toolchain.Dependencies
Type: internal static class
Base: System.Object
Summary:
This static helper locates JetBrains Rider installations on Windows, macOS and Linux. It supports discovering Rider installed via JetBrains Toolbox, classic installations, Snap packages and desktop entries. It parses several JSON files produced by the Toolbox, reads product-info.json and build.txt to determine Rider versions/build numbers, and exposes results as RiderInfo structures. The implementation is defensive — many parsing operations are wrapped to log warnings on failure instead of throwing.
Fields
-
private class SettingsJson
This private serializable helper type maps the Toolbox ".settings.json" layout for the install location. It provides GetInstallLocationFromJson to safely parse the install_location string from JSON using UnityEngine.JsonUtility. Used by GetToolboxRiderRootPath to resolve an alternate Toolbox root. -
private class ToolboxHistory
Serializable helper representing a Toolbox channel ".history.json". GetLatestBuildFromJson extracts the latest build identifier (the "build" string) from the JSON history, returning null on parse failure. -
private class ItemNode
Serializable node used by ToolboxHistory representing one history item. -
private class BuildNode
Serializable node representing the build entry with a 'build' string. -
internal class ProductInfo
Serializable type used to parse Rider's product-info.json. Contains fields version and versionSuffix and a static helper GetProductInfo that returns a ProductInfo instance parsed from a JSON string or null on failure. -
private class ToolboxInstallData
Serializable helper for older/newer toolbox channel settings format that contains an active_application with builds list. GetLatestBuildFromJson extracts the first build from active_application.builds. -
private class ActiveApplication
Represents the active_application object inside Toolbox channel settings with a builds list. -
internal struct RiderInfo
Struct returned by the locator: contains bool IsToolbox, string Presentation, System.Version BuildNumber, ProductInfo ProductInfo, and string Path. The RiderInfo constructor takes a path and an isToolbox flag, populates BuildNumber and ProductInfo by reading files relative to the supplied path, normalizes Path, and constructs a human-readable Presentation string. -
private static class Logger
Internal logger wrapper used to log warnings and exceptions using UnityEngine.Debug.LogError/LogException. Used by parsing helpers to avoid throwing.
Properties
- none
This static class exposes no properties. The RiderInfo struct contains public fields (IsToolbox, Presentation, BuildNumber, ProductInfo, Path) but no encapsulated properties.
Constructors
- none (static class)
As a static class there is no public constructor. Initialization is handled by static methods on demand.
Methods
-
public static RiderInfo[] GetAllRiderPaths()
Returns an array of RiderInfo for Rider installations discovered on the current platform. Internally switches on PlatformInfo.operatingSystemFamily to call platform-specific collectors. Exceptions during collection are caught and logged; on error an empty array is returned. -
private static RiderInfo[] CollectAllRiderPathsLinux()
Linux-specific collector. Looks at $HOME and JetBrains Toolbox directory, parses ~/.local/share/applications/jetbrains-rider.desktop for Exec entries, and checks the snap path /snap/rider/current/bin/rider.sh. Returns discovered RiderInfo entries. Marks Toolbox installs using GetIsToolbox. -
private static RiderInfo[] CollectRiderInfosMac()
macOS collector. Scans /Applications for "Rider.app" bundles, and also searches the Toolbox base directory for Rider app bundles. Toolbox results are marked as toolbox installs. -
private static RiderInfo[] CollectRiderInfosWindows()
Windows collector. Uses CollectPathsFromToolbox to gather toolbox installs, then scans the registry uninstall keys (both HKCU and HKLM uninstall branches including WOW6432Node) to find installed Rider entries (checks DisplayName contains "Rider" and InstallLocation). Converts found install locations to rider64.exe paths and returns RiderInfo entries. -
private static string GetToolboxBaseDir()
Returns the base Toolbox "apps/Rider" root depending on platform: - Windows: %LocalAppData%\JetBrains\Toolbox (may be overridden by .settings.json install_location).
- macOS: $HOME/Library/Application Support/JetBrains/Toolbox (then apps/Rider)
-
Linux: $HOME/.local/share/JetBrains/Toolbox (then apps/Rider) If environment variables are missing the method returns empty string.
-
private static string GetToolboxRiderRootPath(string localAppData)
Combines the provided localAppData path with JetBrains/Toolbox and apps/Rider. If a .settings.json file exists at the Toolbox root it tries to read install_location to override the root. -
internal static ProductInfo GetBuildVersion(string path)
Given the path to the Rider executable or app bundle, attempts to locate product-info.json (relative to path via GetRelativePathToBuildTxt), reads it and parses into ProductInfo. Returns null if the directory/file doesn't exist or parsing fails. -
internal static System.Version GetBuildNumber(string path)
Attempts to read build.txt (relative path determined by GetRelativePathToBuildTxt) and parse the numeric version portion found after the first "-" in the file content. Returns a System.Version or null if not found/parsable. -
internal static bool GetIsToolbox(string path)
Determines whether the provided path is inside the Toolbox base directory by comparing full paths. Uses GetToolboxBaseDir to compute the Toolbox root. -
private static string GetRelativePathToBuildTxt()
Returns the platform-specific relative path to Rider's build.txt: - Windows/Linux: "../../build.txt"
-
macOS: "Contents/Resources/build.txt" Throws an exception for unknown OS families (defensive).
-
private static void CollectPathsFromRegistry(string registryKey, List<string> installPaths)
Top-level helper that opens both HKCU and HKLM registry keys for the provided registryKey (typically the Uninstall branches) and forwards them to the overload that inspects subkeys. -
private static void CollectPathsFromRegistry(List<string> installPaths, RegistryKey key)
Inspects a registry key, enumerates subkeys, checks for an InstallLocation value and a DisplayName containing "Rider", and if found attempts to add bin\rider64.exe (on Windows) to installPaths if that file exists. Swallows ArgumentException and continues. -
private static string[] CollectPathsFromToolbox(string toolboxRiderRootPath, string dirName, string searchPattern, bool isMac)
Given a toolbox apps/Rider root, iterates channel directories, inspects .history.json and .channel.settings.json for latest build identifiers, looks for executables in the build directories using GetExecutablePaths, and returns found executable paths. Any IO/parse exceptions per channel are logged and ignored. -
private static string[] GetExecutablePaths(string dirName, string searchPattern, bool isMac, string buildDir)
Given a buildDir and expected subdir (dirName) and search pattern: - On non-mac: returns the single path Path.Combine(buildDir, dirName, searchPattern) if that file exists.
-
On macOS: returns subdirectories under Path.Combine(buildDir, dirName) matching searchPattern (e.g., Rider*.app) if they exist. Returns an empty array when nothing is found.
-
internal static ProductInfo ProductInfo.GetProductInfo(string json)
(nested)
Parses product-info.json into ProductInfo and returns it, logging on error and returning null. -
private static string SettingsJson.GetInstallLocationFromJson(string json)
(nested)
Parses .settings.json for install_location using UnityEngine.JsonUtility and returns it or null, logging on error. -
private static string ToolboxHistory.GetLatestBuildFromJson(string json)
(nested)
Parses .history.json for the latest build id and returns it or null, logging on error. -
private static string ToolboxInstallData.GetLatestBuildFromJson(string json)
(nested)
Parses channel settings JSON for an active_application.builds list and returns the first build or null, logging on error. -
private static void Logger.Warn(string message, Exception e = null)
(nested)
Logs an error message via UnityEngine.Debug.LogError and, if an exception is provided, logs it with UnityEngine.Debug.LogException. Used across the class to report parse/IO problems instead of throwing.
Notes and behavior details: - Many JSON parsing helpers use UnityEngine.JsonUtility, which expects types matching the JSON. If the JSON structure changes the functions will log warnings and return null rather than throw. - The code depends on PlatformInfo.operatingSystemFamily to branch logic. Ensure that value is available in the modding runtime. - On Windows the registry is queried under the CurrentUser and LocalMachine Uninstall keys. Access to the registry may require appropriate privileges. - Build detection relies on presence and content of build.txt and product-info.json. Some packaging or distribution methods might omit these files; in such cases version/build parsing will return null. - Paths returned in RiderInfo.Path are FileInfo.FullName normalized and should be safe to pass to other APIs expecting absolute paths.
Usage Example
// Example: enumerate Rider installations and print info
var riders = RiderPathLocator.GetAllRiderPaths();
foreach (var r in riders)
{
Debug.Log($"Found Rider: {r.Presentation}");
Debug.Log($" Path: {r.Path}");
Debug.Log($" IsToolbox: {r.IsToolbox}");
Debug.Log($" BuildNumber: {(r.BuildNumber != null ? r.BuildNumber.ToString() : "unknown")}");
if (r.ProductInfo != null)
{
Debug.Log($" Product version: {r.ProductInfo.version} {r.ProductInfo.versionSuffix}");
}
}
Additional tips for modders: - To integrate with tooling, call GetAllRiderPaths and prefer displaying RiderInfo.Presentation to users so they see friendly names (Toolbox installs are marked). - If you only need a preferred Rider, filter by BuildNumber or ProductInfo to choose a minimum version. - When running on Linux, the method also checks for snap and .desktop Exec entries; desktop .desktop parsing looks for lines starting with Exec="..." and extracts the first quoted token. - The code is intentionally fault-tolerant; check for nulls on BuildNumber/ProductInfo before using them.