tools/builder/Config.cs
author David Anderson <dvander@alliedmods.net>
Wed Dec 19 01:47:26 2007 +0000 (2007-12-19)
changeset 1806 b1ba61360272
parent 1548 e759eedf6c9b
child 1816 269bbfbfbcac
permissions -rw-r--r--
fixed build
     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 source_path;
    16 		public string pkg_path;
    17 		public string builder_path;
    18 		public string build_options;
    19 		public builder.BasePlatform Platform;
    20 
    21 		public Config()
    22 		{
    23 			if ((int)System.Environment.OSVersion.Platform == 128)
    24 			{
    25 				Platform = BasePlatform.Platform_Linux;
    26 			} 
    27 			else 
    28 			{
    29 				Platform = BasePlatform.Platform_Windows;
    30 			}
    31 		}
    32 
    33 		public static string PathFormat(string format, params string [] args)
    34 		{
    35 			string temp = string.Format(format, args);
    36 			return temp.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
    37 		}
    38 
    39 		public bool ReadFromFile(string file)
    40 		{
    41 			bool read = true;
    42 			StreamReader sr = null;
    43 			try
    44 			{
    45 				sr = new StreamReader(file);
    46 
    47 				string line;
    48 				string delim = "\t \n\r\v";
    49 				string split = "=";
    50 				
    51 				while ( (line = sr.ReadLine()) != null )
    52 				{
    53 					line = line.Trim(delim.ToCharArray());
    54 					if (line.Length < 1 || line[0] == ';')
    55 					{
    56 						continue;
    57 					}
    58 					string [] s = line.Split(split.ToCharArray());
    59 					string key, val = "";
    60 					if (s.GetLength(0) >= 1)
    61 					{
    62 						key = s[0];
    63 						if (s.GetLength(0) >= 2)
    64 						{
    65 							for (int i=1; i<s.GetLength(0); i++)
    66 							{
    67 								val += s[i];
    68 							}
    69 						}
    70 						key = key.Trim(delim.ToCharArray());
    71 						val = val.Trim(delim.ToCharArray());
    72 						if (key.CompareTo("SourceBase") == 0)
    73 						{
    74 							source_path = val;
    75 						} 
    76 						else if (key.CompareTo("OutputBase") == 0) 
    77 						{
    78 							pkg_path = val;
    79 						} 
    80 						else if (key.CompareTo("BuilderPath") == 0) 
    81 						{
    82 							builder_path = val;
    83 						} 
    84 						else if (key.CompareTo("BuildOptions") == 0) 
    85 						{
    86 							build_options = val;
    87 						}
    88 					}
    89 				}
    90 			} 
    91 			catch (System.Exception e)
    92 			{
    93 				Console.WriteLine("Unable to read {0:s}: {1:s}", file, e.Message);
    94 				read = false;
    95 			}
    96 
    97 			if (sr != null)
    98 			{
    99 				sr.Close();
   100 			}
   101 
   102 			return read;
   103 		}
   104 	}
   105 }