Skip to content

Commit 1634293

Browse files
Adoption by Linuxgurugamer
Added InstallChecker and AssemblyVerison.tt Fix bug where a null entry in the renderers would throw an exception Added files needed for LGG to build
1 parent 557f917 commit 1634293

17 files changed

+2068
-33
lines changed

B9PartSwitch.sln

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "B9PartSwitch", "B9PartSwitch\B9PartSwitch.csproj", "{87F28FEA-BCCD-4A27-94E3-7B39790E99F1}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "B9PartSwitchTests", "B9PartSwitchTests\B9PartSwitchTests.csproj", "{C17BF82C-F906-4A92-8B9A-F8103CDB565C}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
11+
ProjectSection(SolutionItems) = preProject
12+
B9PartSwitch.version = B9PartSwitch.version
13+
buildRelease.bat = buildRelease.bat
14+
CHANGELOG.md = CHANGELOG.md
15+
deploy.bat = deploy.bat
16+
jenkins.txt = jenkins.txt
17+
KSP_VERSION = KSP_VERSION
18+
LICENSE = LICENSE
19+
README.md = README.md
20+
EndProjectSection
21+
EndProject
1022
Global
1123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1224
Debug|Any CPU = Debug|Any CPU
@@ -25,4 +37,7 @@ Global
2537
GlobalSection(SolutionProperties) = preSolution
2638
HideSolutionNode = FALSE
2739
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {2AF7D825-3F61-48CE-9C9D-09F03EFF40AA}
42+
EndGlobalSection
2843
EndGlobal

B9PartSwitch.version

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"NAME": "B9 Part Switch",
3+
"DOWNLOAD": "https://github.com/linuxgurugamer/B9PartSwitch/releases",
4+
"URL": "https://s3.amazonaws.com/blowfish-ksp-b9partswitch-avc/latest/B9PartSwitch.version",
5+
"GITHUB": {
6+
"USERNAME": "blowfishpro",
7+
"REPOSITORY": "B9PartSwitch"
8+
},
9+
"VERSION": {
10+
"MAJOR": 2,
11+
"MINOR": 21,
12+
"PATCH": 0,
13+
"BUILD": 0
14+
},
15+
"KSP_VERSION": {
16+
"MAJOR": 1,
17+
"MINOR": 12,
18+
"PATCH": 5
19+
},
20+
"KSP_VERSION_MIN": {
21+
"MAJOR": 1,
22+
"MINOR": 12,
23+
"PATCH": 0
24+
},
25+
"KSP_VERSION_MAX": {
26+
"MAJOR": 1,
27+
"MINOR": 12,
28+
"PATCH": 99
29+
}
30+
}

B9PartSwitch/AssemblyVersion.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// This code was generated by a tool. Any changes made manually will be lost
3+
// the next time this code is regenerated.
4+
//
5+
6+
using System.Reflection;
7+
8+
[assembly: AssemblyVersion("2.21.0.0")]
9+
[assembly: AssemblyFileVersion("2.21.0.0")]

B9PartSwitch/AssemblyVersion.tt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<#@ template debug="false" hostspecific="true" language="C#" #>
2+
<#@ import namespace="System.IO" #>
3+
<#@ output extension=".cs" #>
4+
5+
<#@ assembly name="EnvDTE" #><# /* This assembly provides access to Visual Studio project properties. */ #>
6+
<#
7+
8+
// Instructions
9+
// 1. Add a new Text Template to the project
10+
// 2. Copy this file into the new template
11+
// 3. Update the string: versionfile with the complete path to the .version file
12+
// 4. Remove the following line from the file AssemblyInfo.cs (usually located in the "Property" folder inside your C# project):
13+
// [assembly: AssemblyVersion("1.0.0.0")]
14+
// 5. Add the following to the PreBuild steps:
15+
//
16+
// set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"
17+
// %textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt"
18+
19+
20+
int major = 0;
21+
int minor = 0;
22+
int build = 0;
23+
int patch = 0;
24+
bool versionSection = false;
25+
26+
int i = 0;
27+
int i2 = 0;
28+
string s;
29+
30+
// For Visual Studio / MSBuild Build-Time Template Resolution
31+
string RootDirectory = System.IO.Path.GetDirectoryName(Host.TemplateFile) + @"\..\";
32+
33+
//
34+
// Update the following with the name of the .version file which is in the root directory
35+
//
36+
string versionfile = RootDirectory + "B9PartSwitch.version";
37+
38+
39+
if (!File.Exists(versionfile))
40+
{
41+
Write("File: " + versionfile + " missing\n");
42+
}
43+
44+
try
45+
{
46+
foreach (var line in File.ReadAllLines(versionfile))
47+
{
48+
if (line != null)
49+
{
50+
if (!versionSection)
51+
{
52+
if (line.Contains("\"VERSION\""))
53+
versionSection = true;
54+
}
55+
else
56+
{
57+
if (line.Contains("}"))
58+
versionSection = false;
59+
i = line.IndexOf(":");
60+
i2 = line.IndexOf(",");
61+
if (i2 == -1)
62+
i2 = line.Length;
63+
if (i >= 0 && i2 >= 0)
64+
{
65+
s = line.Substring(i + 1, i2 - i - 1);
66+
67+
if (line.Contains("MAJOR"))
68+
Int32.TryParse(s, out major);
69+
70+
if (line.Contains("MINOR"))
71+
Int32.TryParse(s, out minor);
72+
73+
if (line.Contains("PATCH"))
74+
Int32.TryParse(s, out patch);
75+
76+
if (line.Contains("BUILD"))
77+
Int32.TryParse(s, out build);
78+
}
79+
}
80+
}
81+
}
82+
83+
}
84+
catch
85+
{
86+
major = 1;
87+
minor = 0;
88+
patch = 0;
89+
build = 0;
90+
}
91+
//Write("File done");
92+
93+
#>
94+
// This code was generated by a tool. Any changes made manually will be lost
95+
// the next time this code is regenerated.
96+
//
97+
98+
using System.Reflection;
99+
100+
[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")]
101+
[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")]

B9PartSwitch/B9PartSwitch.csproj

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props')" />
43
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
54
<PropertyGroup>
65
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +9,7 @@
109
<AppDesignerFolder>Properties</AppDesignerFolder>
1110
<RootNamespace>B9PartSwitch</RootNamespace>
1211
<AssemblyName>B9PartSwitch</AssemblyName>
13-
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1413
<FileAlignment>512</FileAlignment>
1514
<TargetFrameworkProfile />
1615
<NuGetPackageImportStamp>
@@ -34,23 +33,20 @@
3433
<WarningLevel>4</WarningLevel>
3534
</PropertyGroup>
3635
<ItemGroup>
37-
<Reference Include="Assembly-CSharp">
36+
<Reference Include="$(KSPDIR)\KSP_x64_Data\Managed\Assembly*.dll">
3837
<Private>False</Private>
3938
</Reference>
40-
<Reference Include="System">
41-
<Private>False</Private>
42-
</Reference>
43-
<Reference Include="UnityEngine">
44-
<Private>False</Private>
45-
</Reference>
46-
<Reference Include="UnityEngine.CoreModule">
47-
<Private>False</Private>
48-
</Reference>
49-
<Reference Include="UnityEngine.UI">
39+
<Reference Include="$(KSPDIR)\KSP_x64_Data\Managed\UnityEngine*.dll">
5040
<Private>False</Private>
5141
</Reference>
42+
<Reference Include="System" />
5243
</ItemGroup>
5344
<ItemGroup>
45+
<Compile Include="AssemblyVersion.cs">
46+
<AutoGen>True</AutoGen>
47+
<DesignTime>True</DesignTime>
48+
<DependentUpon>AssemblyVersion.tt</DependentUpon>
49+
</Compile>
5450
<Compile Include="CustomPartModule.cs" />
5551
<Compile Include="Extensions\AttachNodeExtensions.cs" />
5652
<Compile Include="Extensions\CustomPartModuleExtensions.cs" />
@@ -107,6 +103,7 @@
107103
<Compile Include="Fishbones\NodeDataMappers\ValueScalarMapperBuilder.cs" />
108104
<Compile Include="Fishbones\OperationManager.cs" />
109105
<Compile Include="Fishbones\UseParser.cs" />
106+
<Compile Include="InstallChecker.cs" />
110107
<Compile Include="Localization.cs" />
111108
<Compile Include="ModuleB9AssignUiGroups.cs" />
112109
<Compile Include="ModuleMatcher.cs" />
@@ -173,28 +170,44 @@
173170
<Compile Include="Utils\StringMatcher.cs" />
174171
</ItemGroup>
175172
<ItemGroup>
176-
<None Include="packages.config" />
173+
<Content Include="AssemblyVersion.tt">
174+
<Generator>TextTemplatingFileGenerator</Generator>
175+
<LastGenOutput>AssemblyVersion.cs</LastGenOutput>
176+
</Content>
177+
</ItemGroup>
178+
<ItemGroup>
179+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
177180
</ItemGroup>
178181
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
179182
<PropertyGroup>
180-
<PreBuildEvent>
181-
sh -e -c "cd '$(SolutionDir)' &amp;&amp; bundle exec fill-version '$(SolutionDir)/templates/AssemblyInfo.cs.erb' '$(ProjectDir)/Properties/AssemblyInfo.cs'"
182-
</PreBuildEvent>
183+
<PreBuildEvent>"$(DevEnvDir)\texttransform.exe" "$(ProjectDir)AssemblyVersion.tt"</PreBuildEvent>
183184
</PropertyGroup>
184185
<PropertyGroup>
185-
<PostBuildEvent>
186-
sh -e -c " mkdir -p '$(SolutionDir)/GameData/B9PartSwitch/Plugins/' &amp;&amp; cp '$(TargetPath)' '$(SolutionDir)/GameData/B9PartSwitch/Plugins/'"
187-
</PostBuildEvent>
186+
<PostBuildEvent>set KSPDIR=$(KSPDIR)
187+
188+
IF "%25KSPDIR%25"=="" (
189+
190+
ECHO Configuration error - KSPDIR not specified in project.
191+
192+
ECHO Either set KSPDIR environment variable or edit BetterLoadSaveGame.Common.props
193+
194+
PAUSE
195+
196+
GOTO DONE
197+
198+
)
199+
200+
start /D $(SolutionDir) /WAIT deploy.bat $(TargetDir) $(TargetFileName) $(TargetName)
201+
202+
if $(ConfigurationName) == Release (
203+
204+
start /D $(SolutionDir) /WAIT buildRelease.bat $(TargetDir) $(TargetFileName) $(TargetName)
205+
206+
)</PostBuildEvent>
188207
</PropertyGroup>
189208
<PropertyGroup>
190209
<LangVersion>9.0</LangVersion>
191210
</PropertyGroup>
192-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
193-
<PropertyGroup>
194-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
195-
</PropertyGroup>
196-
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.3.9.0\build\Microsoft.Net.Compilers.props'))" />
197-
</Target>
198211
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
199212
Other similar extension points exist, see Microsoft.Common.targets.
200213
<Target Name="BeforeBuild">

B9PartSwitch/InstallChecker.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Based on the InstallChecker from the Kethane mod for Kerbal Space Program.
3+
* https://github.com/Majiir/Kethane/blob/b93b1171ec42b4be6c44b257ad31c7efd7ea1702/Plugin/InstallChecker.cs
4+
*
5+
* Original is (C) Copyright Majiir.
6+
* CC0 Public Domain (http://creativecommons.org/publicdomain/zero/1.0/)
7+
* http://forum.kerbalspaceprogram.com/threads/65395-CompatibilityChecker-Discussion-Thread?p=899895&viewfull=1#post899895
8+
*
9+
* This file has been modified extensively and is released under the same license.
10+
*/
11+
using System;
12+
using System.IO;
13+
using System.Linq;
14+
using System.Reflection;
15+
using UnityEngine;
16+
17+
namespace B9PartSwitch
18+
{
19+
[KSPAddon(KSPAddon.Startup.Instantly, true)]
20+
internal class Startup : MonoBehaviour
21+
{
22+
private void Start()
23+
{
24+
string v = "n/a";
25+
AssemblyTitleAttribute attributes = (AssemblyTitleAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute), false);
26+
string title = attributes?.Title;
27+
if (title == null)
28+
{
29+
title = "TitleNotAvailable";
30+
}
31+
v = Assembly.GetExecutingAssembly().FullName;
32+
if (v == null)
33+
{
34+
v = "VersionNotAvailable";
35+
}
36+
Debug.Log("[" + title + "] Version " + v);
37+
}
38+
}
39+
40+
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
41+
internal class InstallChecker : MonoBehaviour
42+
{
43+
private const string MODNAME = "B9PartSwitch";
44+
private const string FOLDERNAME = "B9PartSwitch";
45+
private const string EXPECTEDPATH = FOLDERNAME + "/Plugins";
46+
47+
protected void Start()
48+
{
49+
// Search for this mod's DLL existing in the wrong location. This will also detect duplicate copies because only one can be in the right place.
50+
var assemblies = AssemblyLoader.loadedAssemblies.Where(a => a.assembly.GetName().Name == Assembly.GetExecutingAssembly().GetName().Name).Where(a => a.url != EXPECTEDPATH);
51+
if (assemblies.Any())
52+
{
53+
var badPaths = assemblies.Select(a => a.path).Select(p => Uri.UnescapeDataString(new Uri(Path.GetFullPath(KSPUtil.ApplicationRootPath)).MakeRelativeUri(new Uri(p)).ToString().Replace('/', Path.DirectorySeparatorChar)));
54+
PopupDialog.SpawnPopupDialog
55+
(
56+
new Vector2(0.5f, 0.5f),
57+
new Vector2(0.5f, 0.5f),
58+
"test",
59+
"Incorrect " + MODNAME + " Installation",
60+
MODNAME + " has been installed incorrectly and will not function properly. All files should be located in KSP/GameData/" + FOLDERNAME + ". Do not move any files from inside that folder.\n\nIncorrect path(s):\n" + String.Join("\n", badPaths.ToArray()),
61+
"OK",
62+
false,
63+
HighLogic.UISkin
64+
);
65+
Debug.Log("Incorrect " + MODNAME + " Installation: " + MODNAME + " has been installed incorrectly and will not function properly. All files should be located in KSP/GameData/" + EXPECTEDPATH + ". Do not move any files from inside that folder.\n\nIncorrect path(s):\n" + String.Join("\n", badPaths.ToArray())
66+
67+
);
68+
69+
}
70+
71+
//// Check for Module Manager
72+
//if (!AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name.StartsWith("ModuleManager") && a.url == ""))
73+
//{
74+
// PopupDialog.SpawnPopupDialog("Missing Module Manager",
75+
// modName + " requires the Module Manager mod in order to function properly.\n\nPlease download from http://forum.kerbalspaceprogram.com/threads/55219 and copy to the KSP/GameData/ directory.",
76+
// "OK", false, HighLogic.Skin);
77+
//}
78+
79+
CleanupOldVersions();
80+
}
81+
82+
/*
83+
* Tries to fix the install if it was installed over the top of a previous version
84+
*/
85+
void CleanupOldVersions()
86+
{
87+
try
88+
{
89+
}
90+
catch (Exception ex)
91+
{
92+
Debug.LogError("-ERROR- " + this.GetType().FullName + "[" + this.GetInstanceID().ToString("X") + "][" + Time.time.ToString("0.00") + "]: " +
93+
"Exception caught while cleaning up old files.\n" + ex.Message + "\n" + ex.StackTrace );
94+
95+
}
96+
}
97+
}
98+
}
99+

0 commit comments

Comments
 (0)