<#
/*
   * Version.tt
   * 1.2.0.0 
 */
/* This file is licensed under the Do What the F* You Want to Public License ( http://www.wtfpl.net )
    * by LisiasT. http://ksp.lisias.net
    * modified by zer0kerbal
    *
    * You are allowed to copy, modify and use this file unrestrictedly. :)
    */
#>
<# // from https://docs.microsoft.com/en-us/visualstudio/modeling/walkthrough-generating-code-by-using-text-templates?view=vs-2017 #>
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.IO" #>
<#
	//
	// Update the following with mod name as listed on the .version file
	//
    string PROJECT_NAME = "Biomatic";

    int revisionNumber;
    int major = 0;
    int minor = 0;
    int patch = 0;
    int build = 0;

    try
    {
        string file = this.Host.ResolvePath("../../" + PROJECT_NAME + ".version");
        string text = File.ReadAllText(file);

        {
            int i = text.IndexOf("\"VERSION\"", System.StringComparison.Ordinal);
            int j = text.IndexOf("}", i + 1, System.StringComparison.Ordinal);
            text = text.Substring(i, j-i+1);
        }

        try
        {
            int i = text.IndexOf("\"MAJOR\"", System.StringComparison.Ordinal);
            while (!Char.IsNumber(text[i])) ++i;
            int j = i;
            while (Char.IsNumber(text[j])) ++j;
            Int32.TryParse(text.Substring(i,j-i), out major);
        }
        catch { }

        try
        {
            int i = text.IndexOf("\"MINOR\"", System.StringComparison.Ordinal);
            while (!Char.IsNumber(text[i])) ++i;
            int j = i;
            while (Char.IsNumber(text[j])) ++j;
            Int32.TryParse(text.Substring(i,j-i), out minor);
        }
        catch { }

        try
        {
            int i = text.IndexOf("\"PATCH\"", System.StringComparison.Ordinal);
            while (!Char.IsNumber(text[i])) ++i;
            int j = i;
            while (Char.IsNumber(text[j])) ++j;
            Int32.TryParse(text.Substring(i,j-i), out patch);
        }
        catch { }

        try
        {
            int i = text.IndexOf("\"BUILD\"", System.StringComparison.Ordinal);
            while (!Char.IsNumber(text[i])) ++i;
            int j = i;
            while (Char.IsNumber(text[j])) ++j;
            Int32.TryParse(text.Substring(i,j-i), out build);
        }
        catch { }
    }
    catch (Exception e)
    {
        Write("Error: " + e.Message);
    }
    try
    {
        //If we cannot find the file, the revision number is set to zero,
        //so even if the file doesn't exists the generation will run anyway.
        //NOTE: we suppose we're not messing with the generated file
        using(var f = File.OpenText(Host.ResolvePath("./Version.cs")))
        {
            //We're reading the previous revision number; in order to make the
            //code as simple as we can, we're just going to rewrite it on the first row, commented.
            //This is not elegant, but it's simple enough and quite effective.
            string s = f.ReadLine().Replace("//","");
            revisionNumber = int.Parse(s) + 1; 
        }
    }catch
    {     
        revisionNumber = 0; 
    }
#>
//<#=revisionNumber#>
// Automatically generated code. Any changes will be lost!
 // This code was generated by a tool. Any changes made manually will be lost
 // the next time this code is regenerated.
 // 
  
 using System.Reflection;

[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")]
[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= patch-1 #>.<#= revisionNumber #>")]
[assembly: AssemblyInformationalVersionAttribute("<#= PROJECT_NAME #> <#= major #>.<#= minor #>.<#= patch-1 #>.<#= revisionNumber #> -zed'K BETA")]
//"@FULL_VERSION@"

namespace <#= PROJECT_NAME #>
{
    public static class Version
    {
        public const int major = <#= major #>;
        public const int minor = <#= minor #>;
        public const int patch = <#= patch #>;
        public const int build = <#= build #>;
        public const string Number = "<#= major #>.<#= minor #>.<#= patch #>.<#= build #>";
#if DEBUG
        public const string Text = Number + " -zed'K BETA DEBUG";
#else
        public const string Text = Number + " -zed'K BETA";
#endif
    }
}