-
-
Save TGRHavoc/2a3771c0a3e211bac4d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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