Skip to content

Commit

Permalink
TelemetryWrapper: Add version check on load
Browse files Browse the repository at this point in the history
  • Loading branch information
fat-lobyte committed Jun 27, 2017
1 parent 1097542 commit b8f530f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Telemetry.Test/TelemetryWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Reflection;
using UnityEngine;

Expand All @@ -7,6 +8,9 @@ namespace TelemetryTest
public class Telemetry
{
#if DEBUG_TELEMETRY
private const int APIVersionMajor = 0;
private const int APIVersionMinor = 1;

private static string thisAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;

private static object telemetryServiceInstance = null;
Expand Down Expand Up @@ -47,6 +51,7 @@ public static void Send(string id, object value)
static Telemetry()
{
#if DEBUG_TELEMETRY
int versionMajor = 0, versionMinor = 0;

// Search for telemetry assembly
Type telemetryServiceType = null;
Expand All @@ -55,22 +60,35 @@ static Telemetry()
if (loadedAssembly.name != "Telemetry")
continue;

telemetryServiceInstance = telemetryServiceType = loadedAssembly.assembly.GetType("Telemetry.TelemetryService");
telemetryServiceType = loadedAssembly.assembly.GetType("Telemetry.TelemetryService");

var fvi = FileVersionInfo.GetVersionInfo(loadedAssembly.path);

versionMajor = fvi.FileMajorPart;
versionMinor = fvi.FileMinorPart;
}

// if it's not loaded, bow and excuse ourselves
if (telemetryServiceType == null)
{
Debug.Log(thisAssemblyName + " could not find Telemetry module. Continuing without Telemetry.");
UnityEngine.Debug.Log(thisAssemblyName + " could not find Telemetry module. Continuing without Telemetry.");
return;
}

if (versionMajor != APIVersionMajor || versionMinor < APIVersionMinor)
{
UnityEngine.Debug.Log(thisAssemblyName +
" Telemetry module version " + versionMajor + "." + versionMinor + " is incompatible with the Wrapper version "
+ APIVersionMajor + "." + APIVersionMinor);
return;
}


// if it's loaded, get instance and Send/AddChannel Methods
telemetryServiceInstance = telemetryServiceType.GetProperty("Instance", telemetryServiceType).GetValue(null, null);
addChannelMethod = telemetryServiceType.GetMethod("AddChannel");
sendMethod = telemetryServiceType.GetMethod("Send");

Debug.Log(thisAssemblyName + " connected to Telemetry module.");
UnityEngine.Debug.Log(thisAssemblyName + " connected to Telemetry module.");
#endif
}
}
Expand Down

0 comments on commit b8f530f

Please sign in to comment.