Merge branch 'master' into 1-7-small-engines

pull/587/head
Chris Adderley 5 years ago committed by GitHub
commit a7ce0f901b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,9 @@
- New base model for Twitch
- New variants for Twitch with 1.6-era Restock podped model
- Tuned colliders, pivots of parts to line up with 1.7-era parts
- Plugin improvements:
- Warn user if Restock is installed in the wrong location
- Warn user if old 1.25m tank directories are detected
v0.1.3
------

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Restock
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
public class InstallChecker : MonoBehaviour
{
public readonly IEnumerable<string> UNEXPECTED_URLS = Array.AsReadOnly(new[] {
"Squad/Parts/FuelTank/fuelTankT100",
"Squad/Parts/FuelTank/fuelTankT200",
"Squad/Parts/FuelTank/fuelTankT400",
"Squad/Parts/FuelTank/fuelTankT800",
});
private void Start()
{
string[] errorMessages = CheckInstallLocation().Concat(CheckUnexpectedUrls()).ToArray();
if (errorMessages.Length > 0) CreateWarningDialog(errorMessages);
}
private IEnumerable<string> CheckInstallLocation()
{
UrlDir gameData = GameDatabase.Instance.root.children.First(dir => dir.type == UrlDir.DirectoryType.GameData);
AssemblyLoader.LoadedAssembly loadedAssembly = AssemblyLoader.loadedAssemblies.GetByAssembly(Assembly.GetExecutingAssembly());
if (loadedAssembly == null)
{
Debug.LogError("[Restock] Error checking install location - could not find loaded assembly");
yield break;
}
UrlDir assemblyDir = GetDirectory(gameData, loadedAssembly.url);
if (assemblyDir == null)
{
Debug.LogError("[Restock] Error checking install location - could not find assembly url directory: " + loadedAssembly.url);
yield break;
}
string observedInstallPath = Path.GetFullPath(assemblyDir.parent.path);
string expectedInstallPath = Path.GetFullPath(Path.Combine(KSPUtil.ApplicationRootPath, Path.Combine("GameData", "ReStock")));
if (observedInstallPath != expectedInstallPath)
{
Debug.LogError($"[Restock] Install found at '{observedInstallPath}'");
yield return $"Expected Restock to be installed at\n{expectedInstallPath}\nbut actually installed at\n{observedInstallPath}";
}
}
private IEnumerable<string> CheckUnexpectedUrls()
{
UrlDir gameData = GameDatabase.Instance.root.children.First(dir => dir.type == UrlDir.DirectoryType.GameData);
foreach (string unexpectedUrl in UNEXPECTED_URLS)
{
if (!(gameData.GetDirectory(unexpectedUrl) is UrlDir unexpectedDir)) continue;
Debug.LogError("[ReStock] Found unexpected directory " + unexpectedDir.path);
yield return $"Found unexpected directory, likely left over from an older version of KSP:\n" + unexpectedDir.path;
}
}
private void CreateWarningDialog(params string[] allMessages)
{
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new MultiOptionDialog(
"RestockInstallWarning",
$"Restock has detected installation issues:\n\n{string.Join("\n\n", allMessages)}",
"Restock - installation issues detected",
HighLogic.UISkin,
new Rect(0.5f, 0.5f, 500f, 60f),
new DialogGUIFlexibleSpace(),
new DialogGUIHorizontalLayout(
new DialogGUIFlexibleSpace(),
new DialogGUIButton("OK", delegate () { }, 140.0f, 30.0f, true),
new DialogGUIFlexibleSpace()
)
),
true,
HighLogic.UISkin);
}
private UrlDir GetDirectory(UrlDir baseUrl, string url)
{
string[] splitUrl = url.Trim().Split('/');
UrlDir currentDir = baseUrl;
foreach (string dirName in splitUrl)
{
currentDir = currentDir.children.FirstOrDefault(dir => dir.name == dirName);
if (currentDir == null) return null;
}
return currentDir;
}
}
}

@ -41,6 +41,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="InstallChecker.cs" />
<Compile Include="MaterialModifiers\ColorPropertyMaterialModifier.cs" />
<Compile Include="MaterialModifiers\FloatPropertyMaterialModifier.cs" />
<Compile Include="MaterialModifiers\IMaterialModifier.cs" />

Loading…
Cancel
Save