private object readObject(KSP.IO.TextReader reader, String name)
        {
            Type   t   = Type.GetType(NamespacePrefix + name);
            object obj = Activator.CreateInstance(t);

            String n;

            // now parse the lines and put them into the dictionary.
            // if there is another object inside, parse it and invoke "add"
            while ((n = nextLine(reader)) != null && !n.Equals("}"))
            {
                if (n.IndexOf('=') != -1)
                {
                    string[] parts = n.Split('=');
                    string   vname = parts[0].Trim();
                    string   value = n.Substring(n.IndexOf('=') + 1).Trim().Replace("\\n", "\n");

                    ReflectionTools.setValue(vname, value, obj);
                }
                else
                {
                    object inner = readObject(reader, n);
                    t.GetMethod("add", new Type[] { inner.GetType() }).Invoke(obj, new object[] { inner });
                }
            }
            return(obj);
        }
        /// <summary>
        /// Parses the object.
        /// </summary>
        /// <returns>The object.</returns>
        /// <param name="reader">Reader.</param>
        private object readObject(KSP.IO.TextReader reader)
        {
            object obj = null;

            // Get the name of the class an create an instance
            String n = nextLine(reader);

            obj = readObject(reader, n);

            return(obj);
        }
 /// <summary>
 /// Parses the passed file (uses KSP.IO) and returns the parsed object
 /// </summary>
 /// <returns>The file.</returns>
 /// <param name="path">Path.</param>
 public object readFile(String path)
 {
     KSP.IO.TextReader reader = KSP.IO.TextReader.CreateForType <MissionController> (path);
     try {
         return(readObject(reader));
     } catch (Exception e) {
         Debug.LogError(e.Message);
         return(null);
     } finally {
         reader.Close();
     }
 }
Beispiel #4
0
        public static void LoadConfiguration()
        {
            if (FileExcist("Config.cfg"))
            {
                KSP.IO.TextReader tr    = KSP.IO.TextReader.CreateForType <EvaSettings>("Config.cfg");
                string[]          lines = tr.ReadToEnd().Split('\n');

                foreach (var line in lines)
                {
                    string[] parts = line.Split('=');

                    try
                    {
                        if (parts.Length > 1)
                        {
                            string name  = parts[0].Trim();
                            string value = parts[1].Trim();

                            switch (name)
                            {
                            case "ShowDebugLines": { displayDebugLinesSetting = bool.Parse(value); } break;

                            case "ShowLoadingKerbals": { displayLoadingKerbals = bool.Parse(value); } break;

                            case "EnableHelmetToggle": { displayToggleHelmet = bool.Parse(value); } break;

                            case "SelectMouseButton": { selectMouseButton = int.Parse(value); } break;

                            case "DispatchMouseButton": { dispatchMouseButton = int.Parse(value); } break;

                            case "SelectKey": { selectKeyButton = value; } break;

                            case "DispatchKey": { dispatchKeyButton = value; } break;

                            case "TargetVesselBySelection": { targetVesselBySelection = bool.Parse(value); } break;
                            }
                        }
                    }
                    catch
                    {
                        EvaDebug.DebugWarning("[EFX] Config loading error ");
                    }
                }
                displayDebugLines = displayDebugLinesSetting;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Parses the passed file (uses KSP.IO) and returns the parsed object
 /// </summary>
 /// <returns>The file.</returns>
 /// <param name="path">Path.</param>
 public object readFile(String path)
 {
     KSP.IO.TextReader reader = KSP.IO.TextReader.CreateForType <KerbalStuffVersion_BOM>(path);
     try
     {
         return(readObject(reader));
     }
     catch (Exception e)
     {
         log.error(e.Message);
         return(null);
     }
     finally
     {
         reader.Close();
     }
 }
        /// <summary>
        /// Reads the next single line, that is not a comment and that is relevant ("not {")
        /// </summary>
        /// <returns>The line.</returns>
        /// <param name="reader">Reader.</param>
        private String nextLine(KSP.IO.TextReader reader)
        {
            String str = reader.ReadLine();

            if (str != null)
            {
                str = str.Trim();
            }
            while (str != null && (str.Length == 0 || str.Equals("{") || str[0] == '#'))
            {
                str = reader.ReadLine();
                if (str != null)
                {
                    str = str.Trim();
                }
            }
            return(str);
        }
Beispiel #7
0
        private object readObject(KSP.IO.TextReader reader, String name)
        {
            Type   t   = Type.GetType(NamespacePrefix + name);
            object obj = Activator.CreateInstance(t);
            Dictionary <string, string> dataIn = new Dictionary <string, string>();

            String n;

            // now parse the lines and put them into the dictionary.
            // if there is another object inside, parse it and invoke "add"
            while ((n = nextLine(reader)) != null)
            {
                string vname = "" + n;
                string value = "" + n;
                dataIn.Add(vname, value);
            }
            return(obj);
        }
Beispiel #8
0
        private void LoadAlarms()
        {
            string AlarmsFileVersion = "2";

            Alarms = new KACAlarmList();
            KSP.IO.TextReader tr      = KSP.IO.TextReader.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title));
            String            strFile = tr.ReadToEnd();

            tr.Close();

            while (strFile.Contains("|<ENDLINE>"))
            {
                String strAlarm = strFile.Substring(0, strFile.IndexOf("|<ENDLINE>"));
                strFile = strFile.Substring(strAlarm.Length + "|<ENDLINE>".Length).TrimStart("\r\n".ToCharArray());

                if (strAlarm.StartsWith("AlarmsFileVersion|"))
                {
                    AlarmsFileVersion = strAlarm.Split("|".ToCharArray())[1];
                    KACWorker.DebugLogFormatted("AlarmsFileVersion:{0}", AlarmsFileVersion);
                }
                else if (!strAlarm.StartsWith("VesselID|"))
                {
                    KACAlarm tmpAlarm = new KACAlarm();

                    switch (AlarmsFileVersion)
                    {
                    case "3":
                        tmpAlarm.LoadFromString3(strAlarm, KACWorkerGameState.CurrentTime.UT);
                        break;

                    default:
                        tmpAlarm.LoadFromString2(strAlarm);
                        break;
                    }

                    Alarms.Add(tmpAlarm);
                }
            }
        }
Beispiel #9
0
        private static void LoadFile()
        {
            string fileName = String.Format("Evas-{0}.txt", HighLogic.CurrentGame.Title);

            if (FileExcist(fileName))
            {
                KSP.IO.TextReader tr = KSP.IO.TextReader.CreateForType <EvaSettings>(fileName);

                string file = tr.ReadToEnd();
                tr.Close();

                EvaTokenReader reader = new EvaTokenReader(file);

                EvaDebug.DebugLog("Size KeySize: " + collection.Count);

                //read every eva.
                while (!reader.EOF)
                {
                    //Load all the eva's in the list.
                    LoadEva(reader.NextToken('[', ']'));
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Reads the next single line
        /// </summary>
        /// <returns>The line.</returns>
        /// <param name="reader">Reader.</param>
        private String nextLine(KSP.IO.TextReader reader)
        {
            String str = reader.ReadLine();

            return(str);
        }