Click or drag to resize

KspPathsMakeRelativePathToGameData Method

Returns path relative to the game's GameData folder.

Namespace:  KSPDev.FSUtils
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public static string MakeRelativePathToGameData(
	params string[] pathParts
)
Request Example View Source

Parameters

pathParts
Type: SystemString
Path parts tp consutruct an absolute or relative path.

Return Value

Type: String
Relative path. All relative casts (e.g. '..') will be resolved, and all directory separators will be translated to / regardless to the platform settings.
Remarks
Note that method doesn't care if the path exists. The returned path will always use / as directory separator regardless to the platform.
Examples
Let's say mod's exact location is not known (e.g. as it is for MiniAVC) and the mod needs to load a texture. In order to do it the mod needs to know a GameData relative path which can be used as a prefix to the texture. Below is a sample code that figures it out.
var assembly = Assembly.GetExecutingAssembly();
var relPath = KspPaths.MakeRelativePathToGameData(assembly.Location);
Debug.LogWarningFormat("Assembly {0} is loaded from {1}", assembly.FullName, relPath);
// Pretend the mod's DLL lives in 'Plugins' subfolder.
var textureFolder = KspPaths.NormalizePath(Path.GetDirectoryName(relPath) + "/../Textures");
// Get a texture from 'Textures' folder that lives in the mods's root.
var texture = GameDatabase.Instance.GetTexture(textureFolder + "/MyTexture.png", false);
See Also