/* * Util.ProjectInfo.cs * Authors: Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Security.Cryptography; using System.Text; namespace Util { /// /// Miscellaneous Information /// public static class ProjectInfo { #region Fields // The information string related to SVN private static readonly string SVNInfo; // The information string related to system private static readonly string SystemInfo; // The information string related to time private static readonly string TimeInfo; // The fully qualified path to the directory from which the game was run. private static readonly string homedirectory; #endregion #region Properties /// /// The information string related to SVN /// internal static string SVNInfoString { get { return SVNInfo; } } /// /// The information string related to system /// internal static string SystemInfoString { get { return SystemInfo; } } /// /// The information string related to time /// internal static string TimeInfoString { get { return TimeInfo; } } /// /// The fully qualified path to the directory from which the game was run. /// public static string HomeDirectory { get { return homedirectory; } } /// /// The Highest committed revision number at this time this project is compiled. /// public static string SVNRevisionNumber { get { return SVNRes.RevisionNumber; } } /// /// The Date of the highest commited revision. /// public static string SVNRevisionDate { get { return SVNRes.RevisionDate; } } /// /// The Date and Time this project was compiled. /// public static string BuildDate { get { return SVNRes.BuildDate; } } #endregion #region Creation /// /// Constructor /// static ProjectInfo() { string temploc = Assembly.GetEntryAssembly().Location; homedirectory = temploc.Substring(0, temploc.LastIndexOf('\\')); StringBuilder sb = new StringBuilder(); #if DEBUG sb.Append("This log was generated by DEBUG build from "); #else sb.Append("This log was generated by build from "); #endif sb.Append(BuildDate); sb.Append(" from SVN Revision "); sb.Append(SVNRevisionNumber); sb.Append(" ("); sb.Append(SVNRevisionDate); sb.Append(")."); SVNInfo = sb.ToString(); sb = new StringBuilder(); sb.Append("Running on "); sb.Append(Environment.OSVersion.ToString()); sb.Append("; Using .NET "); sb.Append(Environment.Version.ToString()); sb.Append(". ("); sb.Append(GetHash()); sb.Append(")"); SystemInfo = sb.ToString(); sb = new StringBuilder(); sb.Append("Started on "); sb.Append(DateTime.Now.ToString()); sb.Append(". Timer Resolution is "); sb.Append(Stopwatch.Frequency.ToString("d", CultureInfo.CurrentCulture)); sb.Append(" per second."); TimeInfo = sb.ToString(); } #endregion #region Getters /// /// Compute a hash string of the executing exe file. /// private static string GetHash() { MD5 md5 = MD5.Create(); StringBuilder sb = new StringBuilder(); using (FileStream fs = new FileStream(Assembly.GetEntryAssembly().Location, FileMode.Open, FileAccess.Read, FileShare.Read)) { foreach (byte b in md5.ComputeHash(fs)) { sb.Append(b.ToString("x2", CultureInfo.CurrentCulture).ToLower(CultureInfo.CurrentCulture)); } } return sb.ToString(); } #endregion } }