using UnityEngine;
using System.Collections;
using System.Reflection;
using System;
using System.IO;

// Update the asset bundle in Unity to your major/minor version numbers.
// Then call something like this to trace out version/date
// 
// Debug.Log(Build.version());

namespace com.deeperbeige.lib
{
    public class Build
    {
		private static bool   _initialised = false;
		private static string _version  = "0.0.0000";
		private static string _datetime = "unknown";
		private static string _bundleID = "unknown";
		
        
		// Build version
        public static string bundleID
        {
			get
			{
				if (! _initialised) Init();
				return _bundleID;
			}
        }
		
		
		// Build version
        public static string version
        {
			get
			{
				if (! _initialised) Init();
				return _version;
			}
        }
		
        // Build date/time
        public static string datetime
        {
			get
			{
				if (! _initialised) Init();
				return _datetime;
			}
        }
		
		private static void Init()
		{
			_initialised = true;
			
			TextAsset versionAsset = Resources.Load("Version") as TextAsset;
			if (versionAsset == null)
			{
				DevPanel.Log("Build: Could not find version information resource file");
				return;
			}
			
			string[] lines = versionAsset.text.Split('\n');
			if (lines.Length != 3) DevPanel.Log("Build: Corrupted version information resource file");
			if (lines.Length >= 1) _datetime = lines[0];
			if (lines.Length >= 2) _version  = lines[1];
			if (lines.Length >= 3) _bundleID = lines[2];
		}
    }
}
