using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace GlobalScope
{
    public static class Globals
    {
        private static String _PathToServerVersion = @"\\silicium\software\MASER software\Released\GoldenEye";
        private static String _PathToPreferredInstall = @"C:\GoldenEye";

        private const String _FileNameOfSoftware = "GoldenEye.exe";
        private const String _UpdaterExeFile = "Updater.exe";
        private const String _LegalUpdateKeyWord = "DoUpdateGoldenEye"; // LegalUpdateKeyWord cannot be changed in new build without breaking auto-update loops
        private const String _UpdaterModuleDescription = "GoldenEye Updater";
        private const String _SoftwareDescription = "GoldenEye";
        private const String _UserRegistrationFile = "UserRegistration.txt";
        private const String _CalledByUpdaterKeyWord = "CalledByGoldenEyeUpdater";
        
        


        public static String CurrentDir
        {
            get
            {
                System.Reflection.Assembly a = System.Reflection.Assembly.GetEntryAssembly();
                string currentExe = System.IO.Path.GetFullPath(a.Location);
                return System.IO.Path.GetDirectoryName(a.Location).ToLower();
            }
        }

        public static String BuildVersion
        {
            get
            {
                System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
                string exe = System.IO.Path.GetFullPath(ass.Location);
                DateTime dt = new System.IO.FileInfo(exe).LastWriteTimeUtc;
                return String.Format("{0:0000}{1:00}{2:00}.{3:00}", dt.Year, dt.Month, dt.Day,dt.Hour);
            }
        }

        public static FileInfo CurrentExe
        {
            get
            {
                System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
                return new FileInfo(System.IO.Path.GetFullPath(ass.Location));
            }
        }


        public static void RegisterUser(String Description)
        {
            try
            {
                DateTime dt = DateTime.Now;
                String timestamp = String.Format("{0:0000}/{1:00}/{2:00} @ {3:00}:{4:00}", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute);
                string user = String.Format("   [User] {0}",  System.Environment.UserName);
                string machine = String.Format("   [Machine] {0}", System.Environment.MachineName);
                string description = String.Format("   {0}",Description);
                using (System.IO.StreamWriter sw = System.IO.File.AppendText(Globals.UserRegistrationFilePath))
                {
                    sw.WriteLine(timestamp);
                    sw.WriteLine(user);
                    sw.WriteLine(machine);
                    sw.WriteLine(description);
                }
            }
            catch { }
        }




        // Gets
        public static String PathToServerVersion { get { return _PathToServerVersion; } set {_PathToServerVersion =value; } }
        public static String PathToPreferredInstall { get { return _PathToPreferredInstall; } set { _PathToPreferredInstall = value; } }
        public static String UpdaterModuleDescription { get { return _UpdaterModuleDescription; } }
        public static String SoftwareDescription { get { return _SoftwareDescription; } }
        public static String LegalUpdateKeyWord { get { return _LegalUpdateKeyWord; } }
        public static String UpdaterExeFile { get { return _UpdaterExeFile; } }
        public static String FileNameOfSoftware { get { return _FileNameOfSoftware; } }
        public static String UserRegistrationFilePath { get { return _PathToServerVersion + "\\"+ _UserRegistrationFile; } }
        public static String CalledByUpdaterKeyWord { get { return _CalledByUpdaterKeyWord; } }


        public static String UserInfo
        {
            get
            {
                DateTime dt = DateTime.Now;
                String timestamp = String.Format("{0:0000}/{1:00}/{2:00} @ {3:00}:{4:00}", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute);

                string result = "unknown user @ unknown machine on " + timestamp;
                try
                {
                    string user = String.Format("{0}", System.Environment.UserName);
                    string machine = String.Format("{0}", System.Environment.MachineName);
                    result = String.Format("{0} @ machine {1} on {2}", user, machine,timestamp);
                }
                catch { }
                return result;
            }
        }

        

        // Functions
        private const string _SpaceReplace = "!@#$%^&*()";
        public static String SpaceOut(String s) { return s.Replace(" ", _SpaceReplace); }
        public static String SpaceIn(String s) { return s.Replace(_SpaceReplace, " "); }




        // Cosntants
        public const String AdministratorEmail = "wim.booij@maser.nl";
      



    }
}
