Skip to content

Commit

Permalink
Even smarter checks for valid KSPRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcassidy committed Sep 21, 2024
1 parent b6c0e12 commit 75a60e1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
81 changes: 57 additions & 24 deletions KSPCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,85 @@
<KSPCommonPropsImported>true</KSPCommonPropsImported>
</PropertyGroup>

<!-- import the csproj.user file. This might not be a good idea -->
<!--Parse KSP platform-specific paths -->
<!-- These can be overwritten by user and props files -->
<PropertyGroup Condition=" '$(ManagedRelativePath)' == '' ">
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64_Data\Managed</ManagedRelativePath>
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('OSX'))">KSP.app\Contents\Resources\Data\Managed</ManagedRelativePath>
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('Linux'))">KSP_Data\Managed</ManagedRelativePath>
</PropertyGroup>
<PropertyGroup>
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64.exe</KSPExecutable>
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('OSX'))">KSP.app/Contents/MacOS/KSP</KSPExecutable>
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('Linux'))">KSP.x86_64</KSPExecutable>
<SteamKSPRoot Condition="($([MSBuild]::IsOsPlatform('Windows')))">C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program</SteamKSPRoot>
<SteamKSPRoot Condition="($([MSBuild]::IsOsPlatform('OSX')))">$(HOME)/Library/Application Support/Steam/steamapps/common/Kerbal Space Program</SteamKSPRoot>
</PropertyGroup>

<!-- Calculate mod paths -->
<!-- These can be overwritten by user, csproj, and props files -->
<PropertyGroup>
<!-- The root directory of the mod repository -->
<RepoRootPath Condition=" '$(RepoRootPath)' == '' ">$(SolutionDir.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</RepoRootPath>
<BinariesOutputRelativePath Condition=" '$(BinariesOutputRelativePath)' == '' ">GameData/$(SolutionName)</BinariesOutputRelativePath>
</PropertyGroup>

<!-- Import the csproj.user file. -->
<!-- This can overwrite ManagedRelativePath and KSPExecutable,
set KSPRoot and ReferencePath, and any other user-specific settings -->
<Import Project="$(MSBuildProjectFullPath).user" Condition="Exists('$(MSBuildProjectFullPath).user')"/>

<!--import solution-wide props if it exists -->
<!-- Import a props.user file -->
<!-- serves the same role as the csproj.user file -->
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props.user') " Project="$(SolutionDir)$(SolutionName).props.user"/>

<!-- Import solution-wide props if it exists -->
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props') " Project="$(SolutionDir)$(SolutionName).props"/>

<!-- The following properties can be customized per-mod in SolutionName.props-->
<PropertyGroup>
<!-- The root directory of the mod repository -->
<RepoRootPath Condition = " '$(RepoRootPath)' == '' ">$(SolutionDir.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</RepoRootPath>
<BinariesOutputRelativePath Condition = " '$(BinariesOutputRelativePath)' == '' ">GameData\$(SolutionName)</BinariesOutputRelativePath>
<!-- Default KSPRoot to the "KSP_ROOT" environment variable if it exists -->
<!-- Doing this overrides any checks for a valid KSP install so be careful! -->
<KSPRoot Condition=" '$(KSPRoot)' == '' And '$(KSP_ROOT)' != ''">$(KSP_ROOT)</KSPRoot>
</PropertyGroup>

<!-- Search for KSPRoot -->
<PropertyGroup>
<!-- Default KSPRoot to the "KSP_ROOT" environment variable if it exists -->
<!-- Doing this overrides any checks for a valid KSP install so be careful! -->
<KSPRoot Condition=" '$(KSPRoot)' == '' And '$(KSP_ROOT)' != ''">$(KSP_ROOT)</KSPRoot>

<!-- look for a KSP installation in SolutionDir -->
<KSPRoot Condition = " '$(KSPRoot)' == '' And Exists('$(SolutionDir)KSP/GameData')">$(SolutionDir)KSP</KSPRoot>
<KSPRoot Condition=" '$(KSPRoot)' == '' And Exists('$(SolutionDir)KSP/GameData')">$(SolutionDir)KSP</KSPRoot>

<!-- use ReferencePath if it exists and is a valid KSP install -->
<KSPRoot Condition = " '$(KSPRoot)' == '' And Exists('$(ReferencePath)GameData')">$(ReferencePath.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</KSPRoot>
<KSPRoot Condition=" '$(KSPRoot)' == '' And Exists('$(ReferencePath)GameData')">$(ReferencePath.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</KSPRoot>

<!--If the reference path isn't set, use the default steam location, but this will be incorrect in lots of cases-->
<SteamKSPRoot Condition = "($([MSBuild]::IsOsPlatform('Windows')))">C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program</SteamKSPRoot>
<SteamKSPRoot Condition = "($([MSBuild]::IsOsPlatform('OSX')))">$(HOME)/Library/Application Support/Steam/steamapps/common/Kerbal Space Program</SteamKSPRoot>
<KSPRoot Condition = "'$(KSPRoot)' == '' And Exists('$(SteamKSPRoot)/GameData')">$(SteamKSPRoot)</KSPRoot>
<KSPRoot Condition="'$(KSPRoot)' == '' And Exists('$(SteamKSPRoot)/GameData')">$(SteamKSPRoot)</KSPRoot>

<!-- default CKAN compatibility versions -->
<CKANCompatibleVersions Condition="('$(CKANCompatibleVersions)' == '')">1.12 1.11 1.10 1.9 1.8</CKANCompatibleVersions>
</PropertyGroup>

<!--Import a props.user file if it exists, so that KSPRoot can be set globally for the whole mod if desired-->
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props.user') " Project="$(SolutionDir)$(SolutionName).props.user"/>

<!--Parse KSP platform-specific paths -->
<PropertyGroup Condition = " '$(ManagedRelativePath)' == '' ">
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64_Data\Managed</ManagedRelativePath>
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('OSX'))">KSP.app\Contents\Resources\Data\Managed</ManagedRelativePath>
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('Linux'))">KSP_Data\Managed</ManagedRelativePath>
<!-- Assemble a list of KSPRoot candidates. Additional items can be defined in .csproj.user if desired -->
<ItemGroup>
<KSPRootCandidate Include="$(SolutionDir)KSP"/>
<KSPRootCandidate Include="$(ReferencePath)"/>
<KSPRootCandidate Include="$(SteamKSPRoot)"/>
</ItemGroup>
<!-- Search through candidates and select the first one that looks like a valid install-->
<ItemGroup>
<_ValidKSPRootCandidate Include="@(KSPRootCandidate.Identity)" Condition="Exists('@(KSPRootCandidate.Identity)/$(ManagedRelativePath/Assembly-CSharp.dll')"/>
</ItemGroup>
<PropertyGroup>
<KSPRoot Condition="'$(KSPRoot)' == '' "> %(_ValidKSPRootCandidate.Identity) </KSPRoot>
</PropertyGroup>

<!-- Calculate ManagedPath -->
<PropertyGroup>
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64.exe</KSPExecutable>
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('OSX'))">KSP.app/Contents/MacOS/KSP</KSPExecutable>
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('Linux'))">KSP.x86_64</KSPExecutable>
<ManagedPath>$(KSPRoot)\$(ManagedRelativePath)</ManagedPath>
<ManagedPath>$(KSPRoot)/$(ManagedRelativePath)</ManagedPath>
</PropertyGroup>

<!-- set the start action so that you can launch directly from VS -->
<PropertyGroup>
<StartAction>Program</StartAction>
Expand Down
1 change: 1 addition & 0 deletions KSPCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<Target Name="CheckForKSPRoot" BeforeTargets="ResolveReferences" Condition="'$(KSPRoot)' == ''">
<Error Text="KSPBuildTools was unable to find a KSP installation. Please set the ReferencePath or KSPRoot property in your csproj.user file to a valid KSP installation directory (the one with GameData in it)"/>
<Message Text="Found KSPRoot at $(KSPRoot)" Importance="low"/>
</Target>

<!-- Copy output files to mod folder -->
Expand Down

0 comments on commit 75a60e1

Please sign in to comment.