Skip to content

Instantly share code, notes, and snippets.

@TGRHavoc
Created May 27, 2015 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TGRHavoc/2a3771c0a3e211bac4d0 to your computer and use it in GitHub Desktop.
Save TGRHavoc/2a3771c0a3e211bac4d0 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using SimpleJSON;
using System.Diagnostics;
public class Updater : MonoBehaviour {
public string currentVersion = "1.0.0.0";
public string baseUrl = "http://localhost/GAME_NAME_here/"; //Base URL for your game
public string versionsFile = "versions.json"; //JSON file that contains the updates
// Use this for initialization
void Start () {
string[] data = System.Environment.GetCommandLineArgs();
WWW www = new WWW(baseUrl + versionsFile);
StartCoroutine(WaitForWWW(www));
}
IEnumerator WaitForWWW(WWW www){
yield return www;
if (www.error == null){
UnityEngine.Debug.Log("Recieved from (" + www.url+ "): " + www.text);
JSONNode data = JSON.Parse(www.text);
JSONArray updates = data["updates"].AsArray;
foreach (JSONNode update in updates){
if (string.Equals(update["version"], currentVersion)){
UnityEngine.Debug.Log("Update found.. Going to run updater.");
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "Updater.exe"; // Should be the name of the updater application
Process proc = new Process();
proc.StartInfo = start;
proc.Start();//sTART THE UPDATER
Application.Quit(); //Stop the game so updater can override file
}
}
}else{
UnityEngine.Debug.Log("Error: " + www.error + " @ " + www.url);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment