tools/builder/Config.cs
author Scott Ehlert <ds@alliedmods.net>
Wed Jun 20 11:30:29 2007 +0000 (2007-06-20)
changeset 994 a0d587e40030
parent 467 8192f64d8f57
child 1548 e759eedf6c9b
permissions -rw-r--r--
Changed "Player" to "Client" in error messages about clients (attempt at some sort of error message consistency)

P.S. Happy 1000 Revisions, SourceMod!
     1 using System;
     2 using System.IO;
     3 using System.Text;
     4 
     5 namespace builder
     6 {
     7 	public enum BasePlatform
     8 	{
     9 		Platform_Windows,
    10 		Platform_Linux
    11 	};
    12 
    13 	public class Config
    14 	{
    15 		public string SourceBase;
    16 		public string OutputBase;
    17 		public string BuilderPath;
    18 		public string CompressOptions;
    19 		public string SVNVersion;
    20 		public string ProductVersion;
    21 		public string Compressor;
    22 		public string BuildOptions;
    23 		public builder.BasePlatform Platform;
    24 
    25 		public Config()
    26 		{
    27 			if ((int)System.Environment.OSVersion.Platform == 128)
    28 			{
    29 				Platform = BasePlatform.Platform_Linux;
    30 			} 
    31 			else 
    32 			{
    33 				Platform = BasePlatform.Platform_Windows;
    34 			}
    35 		}
    36 
    37 		public static string PathFormat(string format, params string [] args)
    38 		{
    39 			string temp = string.Format(format, args);
    40 			return temp.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
    41 		}
    42 
    43 		public bool ReadFromFile(string file)
    44 		{
    45 			bool read = true;
    46 			StreamReader sr = null;
    47 			try
    48 			{
    49 				sr = new StreamReader(file);
    50 
    51 				string line;
    52 				string delim = "\t \n\r\v";
    53 				string split = "=";
    54 				
    55 				while ( (line = sr.ReadLine()) != null )
    56 				{
    57 					line = line.Trim(delim.ToCharArray());
    58 					if (line.Length < 1 || line[0] == ';')
    59 					{
    60 						continue;
    61 					}
    62 					string [] s = line.Split(split.ToCharArray());
    63 					string key, val = "";
    64 					if (s.GetLength(0) >= 1)
    65 					{
    66 						key = s[0];
    67 						if (s.GetLength(0) >= 2)
    68 						{
    69 							for (int i=1; i<s.GetLength(0); i++)
    70 							{
    71 								val += s[i];
    72 							}
    73 						}
    74 						key = key.Trim(delim.ToCharArray());
    75 						val = val.Trim(delim.ToCharArray());
    76 						if (key.CompareTo("SourceBase") == 0)
    77 						{
    78 							SourceBase = val;
    79 						} 
    80 						else if (key.CompareTo("OutputBase") == 0) 
    81 						{
    82 							OutputBase = val;
    83 						} 
    84 						else if (key.CompareTo("BuilderPath") == 0) 
    85 						{
    86 							BuilderPath = val;
    87 						} 
    88 						else if (key.CompareTo("CompressOptions") == 0) 
    89 						{
    90 							CompressOptions = val;
    91 						} 
    92 						else if (key.CompareTo("SVNVersion") == 0) 
    93 						{
    94 							SVNVersion = val;
    95 						} 
    96 						else if (key.CompareTo("ProductVersion") == 0)
    97 						{
    98 							ProductVersion = val;
    99 						} 
   100 						else if (key.CompareTo("Compressor") == 0) 
   101 						{
   102 							Compressor = val;
   103 						} 
   104 						else if (key.CompareTo("BuildOptions") == 0) 
   105 						{
   106 							BuildOptions = val;
   107 						}
   108 					}
   109 				}
   110 			} 
   111 			catch (System.Exception e)
   112 			{
   113 				Console.WriteLine("Unable to read {0:s}: {1:s}", file, e.Message);
   114 				read = false;
   115 			}
   116 
   117 			if (sr != null)
   118 			{
   119 				sr.Close();
   120 			}
   121 
   122 			return read;
   123 		}
   124 	}
   125 }