Skip to content

Commit

Permalink
Add a warning window for incorrect installs.
Browse files Browse the repository at this point in the history
  • Loading branch information
godarklight committed Jun 30, 2014
1 parent 860c350 commit e3a341c
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions Client/Client.csproj
Expand Up @@ -75,6 +75,7 @@
<Compile Include="OptionsWindow.cs" />
<Compile Include="UniverseConverter.cs" />
<Compile Include="UniverseConverterWindow.cs" />
<Compile Include="IncorrectInstallWindow.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
Expand Down
76 changes: 76 additions & 0 deletions Client/IncorrectInstallWindow.cs
@@ -0,0 +1,76 @@
using System;
using UnityEngine;

namespace DarkMultiPlayer
{
public class IncorrectInstallWindow
{
public static IncorrectInstallWindow singleton;

private const int WINDOW_WIDTH = 600;
private const int WINDOW_HEIGHT = 200;
private Rect windowRect;
private Rect moveRect;
private bool initialized;
private bool display;
private GUILayoutOption[] layoutOptions;


public static IncorrectInstallWindow fetch
{
get
{
return singleton;
}
}

private void InitGUI()
{
//Setup GUI stuff
windowRect = new Rect((Screen.width / 2f) - (WINDOW_WIDTH / 2), (Screen.height / 2f) - (WINDOW_HEIGHT / 2f), WINDOW_WIDTH, WINDOW_HEIGHT);
moveRect = new Rect(0, 0, 10000, 20);

layoutOptions = new GUILayoutOption[2];
layoutOptions[0] = GUILayout.ExpandWidth(true);
layoutOptions[1] = GUILayout.ExpandHeight(true);
}

private void Draw()
{
if (!initialized)
{
initialized = true;
InitGUI();
}
if (display)
{
windowRect = GUILayout.Window(GUIUtility.GetControlID(6705, FocusType.Passive), windowRect, DrawContent, "DarkMultiPlayer", layoutOptions);
}
}

private void DrawContent(int windowID)
{
GUILayout.BeginVertical();
GUI.DragWindow(moveRect);
GUILayout.Label("DMP is not correctly installed");
GUILayout.Label("Current location: " + Client.fetch.assemblyPath);
GUILayout.Label("Correct location: " + Client.fetch.assemblyShouldBeInstalledAt);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Close"))
{
display = false;
}
GUILayout.EndVertical();
}

public static void Enable()
{
singleton = new IncorrectInstallWindow();
lock (Client.eventLock) {
Client.drawEvent.Add(singleton.Draw);
}
singleton.display = true;
}
}
}

26 changes: 26 additions & 0 deletions Client/Main.cs
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using UnityEngine;
using DarkMultiPlayerCommon;
using System.Reflection;

namespace DarkMultiPlayer
{
Expand All @@ -14,6 +15,10 @@ public class Client : MonoBehaviour
public string status;
public bool forceQuit;
public bool showGUI = true;
public bool incorrectlyInstalled = false;
public bool displayedIncorrectMessage = false;
public string assemblyPath;
public string assemblyShouldBeInstalledAt;
//Game running is directly set from NetworkWorker.fetch after a successful connection
public bool gameRunning;
public GameMode gameMode;
Expand Down Expand Up @@ -44,6 +49,18 @@ public static Client fetch
public void Awake()
{
GameObject.DontDestroyOnLoad(this);
assemblyPath = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).FullName;
string kspPath = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName;
//I find my abuse of Path.Combine distrubing.
assemblyShouldBeInstalledAt = Path.Combine(Path.Combine(Path.Combine(Path.Combine(kspPath, "GameData"), "DarkMultiPlayer"), "Plugins"), "DarkMultiPlayer.dll");
UnityEngine.Debug.Log("KSP installed at " + kspPath);
UnityEngine.Debug.Log("DMP installed at " + assemblyPath);
incorrectlyInstalled = (assemblyPath.ToLower() != assemblyShouldBeInstalledAt.ToLower());
if (incorrectlyInstalled)
{
UnityEngine.Debug.LogError("DMP is installed at '" + assemblyPath + "', It should be installed at '"+assemblyShouldBeInstalledAt+"'");
return;
}
SetupDirectoriesIfNeeded();
//Register events needed to bootstrap the workers.
lock (eventLock)
Expand Down Expand Up @@ -83,6 +100,15 @@ public void Start()

public void Update()
{
if (incorrectlyInstalled)
{
if (!displayedIncorrectMessage)
{
displayedIncorrectMessage = true;
IncorrectInstallWindow.Enable();
}
return;
}
try
{
if (HighLogic.LoadedScene == GameScenes.MAINMENU && !ModWorker.fetch.dllListBuilt)
Expand Down

3 comments on commit e3a341c

@oldmud0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure what the consequences would be for an incorrect installation. I mean, what if you just put it in a Mods subdirectory? Doesn't look like it would do any harm.

@godarklight
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DMP has some hard-coded paths, this could probably be avoided by using the assembly location, but someone will eventually put 2 copies of DMP into gamedata and things will go pear shaped :-/

@oldmud0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inevitably so. A simple check could be made to see if the assembly has already been loaded, but it would be a bit of a hacky solution. 😐

Please sign in to comment.