Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region License |
| 2 | // |
||
| 3 | // The Open Toolkit Library License |
||
| 4 | // |
||
| 5 | // Copyright (c) 2006 - 2010 the Open Toolkit library. |
||
| 6 | // |
||
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
||
| 8 | // of this software and associated documentation files (the "Software"), to deal |
||
| 9 | // in the Software without restriction, including without limitation the rights to |
||
| 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||
| 11 | // the Software, and to permit persons to whom the Software is furnished to do |
||
| 12 | // so, subject to the following conditions: |
||
| 13 | // |
||
| 14 | // The above copyright notice and this permission notice shall be included in all |
||
| 15 | // copies or substantial portions of the Software. |
||
| 16 | // |
||
| 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
| 18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
| 19 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
| 20 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
| 21 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
| 22 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
| 23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
| 24 | // OTHER DEALINGS IN THE SOFTWARE. |
||
| 25 | // |
||
| 26 | #endregion |
||
| 27 | |||
| 28 | using System; |
||
| 29 | using System.IO; |
||
| 30 | |||
| 31 | namespace Build.UpdateVersion |
||
| 32 | { |
||
| 33 | class Program |
||
| 34 | { |
||
| 35 | const string Major = "1"; |
||
| 36 | const string Minor = "0"; |
||
| 37 | |||
| 38 | public static void Main() |
||
| 39 | { |
||
| 40 | DateTime now = DateTime.UtcNow; |
||
| 41 | GenerateVersionInfo(now, "../../Version.txt"); |
||
| 42 | GenerateAssemblyInfo(now, "../GlobalAssemblyInfo.cs"); |
||
| 43 | } |
||
| 44 | |||
| 45 | static void GenerateVersionInfo(DateTime now, string file) |
||
| 46 | { |
||
| 47 | string version = null; |
||
| 48 | |||
| 49 | if (System.IO.File.Exists(file)) |
||
| 50 | { |
||
| 51 | string[] lines = System.IO.File.ReadAllLines(file); |
||
| 52 | if (lines.Length > 0 && !String.IsNullOrEmpty(lines[0])) |
||
| 53 | { |
||
| 54 | version = lines[0]; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | // If the file does not exist, create it. |
||
| 59 | if (version == null) |
||
| 60 | { |
||
| 61 | version = now.ToString("u").Split(' ')[0]; |
||
| 62 | System.IO.File.WriteAllLines(file, new string[] { version }); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | static void GenerateAssemblyInfo(DateTime now, string file) |
||
| 67 | { |
||
| 68 | // Build number is defined as the number of days since 1/1/2010. |
||
| 69 | // Revision number is defined as the fraction of the current day, expressed in seconds. |
||
| 70 | double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays; |
||
| 71 | string build = ((int)timespan).ToString(); |
||
| 72 | string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString(); |
||
| 73 | |||
| 74 | File.WriteAllLines(file, new string[] |
||
| 75 | { |
||
| 76 | "// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.", |
||
| 77 | "// Do not edit by hand!", |
||
| 78 | "", |
||
| 79 | "using System;", |
||
| 80 | "using System.Reflection;", |
||
| 81 | "using System.Resources;", |
||
| 82 | "using System.Runtime.CompilerServices;", |
||
| 83 | "using System.Runtime.InteropServices;", |
||
| 84 | "", |
||
| 85 | "[assembly: AssemblyCompany(\"The Open Toolkit Library\")]", |
||
| 86 | "[assembly: AssemblyProduct(\"The Open Toolkit Library\")]", |
||
| 87 | "[assembly: AssemblyCopyright(\"Copyright © 2006 - 2010 the Open Toolkit Library\")]", |
||
| 88 | "[assembly: AssemblyTrademark(\"OpenTK\")]", |
||
| 89 | String.Format("[assembly: AssemblyVersion(\"{0}.{1}.0.0\")]", Major, Minor), |
||
| 90 | String.Format("[assembly: AssemblyFileVersion(\"{0}.{1}.{2}.{3}\")]", Major, Minor, build, revision), |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |