Esempio n. 1
0
        internal static void Process(MainForm form)
        {
            if (!System.IO.File.Exists(FileName))
            {
                return;
            }

            mainForm = form;
            TabbedList newLines = new TabbedList();

            newLines.Add("<PanelAnimated>");
            newLines.Add("<Include>");
            newLines.Add("<FileName>panel.animated</FileName>");
            newLines.Add("</Include>");
            newLines.Add("</PanelAnimated>");
            newLines.Add("</openBVE>");
            string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "panel.xml");

            try
            {
                using (StreamWriter sw = new StreamWriter(fileOut))
                {
                    foreach (String s in newLines.Lines)
                    {
                        sw.WriteLine(s);
                    }
                }
            }
            catch
            {
                mainForm.updateLogBoxText += "Error writing file " + fileOut + Environment.NewLine;
                MessageBox.Show("An error occured whilst writing the new XML file. \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
        }
Esempio n. 2
0
        internal static void GenerateExtensionsCfgXML()
        {
            TabbedList newLines = new TabbedList();

            newLines.Add("<Train>");
            for (int i = 0; i < ConvertTrainDat.NumberOfCars; i++)
            {
                if (SingleFile == true)
                {
                    GenerateCarXML(ref newLines, i);
                }
                else
                {
                    TabbedList carLines = new TabbedList();
                    GenerateCarXML(ref carLines, i);
                    carLines.Add("</openBVE>");
                    string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "Car" + i + ".xml");
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(fileOut))
                        {
                            foreach (String s in carLines.Lines)
                            {
                                sw.WriteLine(s);
                            }
                        }
                        newLines.Add("<Car>" + "Car" + i + ".xml</Car>");
                    }
                    catch
                    {
                        mainForm.updateLogBoxText += "Error writing file " + fileOut + Environment.NewLine;
                        MessageBox.Show("An error occured whilst writing the new XML file for car " + i + ". \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        return;
                    }
                }
            }
            newLines.Add("</Train>");
            newLines.Add("</openBVE>");
            try
            {
                string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "Train.xml");
                using (StreamWriter sw = new StreamWriter(fileOut))
                {
                    foreach (String s in newLines.Lines)
                    {
                        sw.WriteLine(s);
                    }
                }
            }
            catch
            {
                MessageBox.Show("An error occured whilst writing the new XML file. \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            MessageBox.Show("Conversion succeeded.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 3
0
        /// <summary>Generates a train.xml file using the values / assumptions contained within the train.dat file</summary>
        internal static void GenerateDefaultXML()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            TabbedList newLines = new TabbedList();

            newLines.Add("<Train>");
            for (int i = 0; i < ConvertTrainDat.NumberOfCars; i++)
            {
                newLines.Add("<Car>");
                newLines.Add("<Length>" + ConvertTrainDat.CarLength + "</Length>");
                newLines.Add("<Width>" + ConvertTrainDat.CarWidth + "</Width>");
                newLines.Add("<Height>" + ConvertTrainDat.CarHeight + "</Height>");
                if (ConvertTrainDat.MotorCars[i] == true)
                {
                    newLines.Add("<MotorCar>True</MotorCar>");
                    newLines.Add("<Mass>" + ConvertTrainDat.MotorCarMass + "</Mass>");
                }
                else
                {
                    newLines.Add("<MotorCar>False</MotorCar>");
                    newLines.Add("<Mass>" + ConvertTrainDat.TrailerCarMass + "</Mass>");
                }
                newLines.Add("<FrontAxle>" + 0.4 * ConvertTrainDat.CarLength + "</FrontAxle>");
                newLines.Add("<RearAxle>" + -(0.4 * ConvertTrainDat.CarLength) + "</RearAxle>");
                newLines.Add("</Car>");
            }
            newLines.Add("</Train>");
            newLines.Add("</openBVE>");
            string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "Train.xml");

            try
            {
                using (StreamWriter sw = new StreamWriter(fileOut))
                {
                    foreach (String s in newLines.Lines)
                    {
                        sw.WriteLine(s);
                    }
                }
            }
            catch
            {
                mainForm.updateLogBoxText += "Error writing file " + fileOut + Environment.NewLine;
                MessageBox.Show("An error occured whilst writing the new XML file. \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
        }
Esempio n. 4
0
        internal static void GenerateCarXML(ref TabbedList newLines, int i)
        {
            newLines.Add("<Car>");
            if (CarInfos[i].Length != 0.0)
            {
                newLines.Add("<Length>" + CarInfos[i].Length + "</Length>");
            }
            else
            {
                newLines.Add("<Length>" + ConvertTrainDat.CarLength + "</Length>");
            }
            newLines.Add("<Width>" + ConvertTrainDat.CarWidth + "</Width>");
            newLines.Add("<Height>" + ConvertTrainDat.CarHeight + "</Height>");
            if (ConvertTrainDat.MotorCars[i] == true)
            {
                newLines.Add("<MotorCar>True</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.MotorCarMass + "</Mass>");
            }
            else
            {
                newLines.Add("<MotorCar>False</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.TrailerCarMass + "</Mass>");
            }
            if (CarInfos[i].AxlesDefined == true)
            {
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearAxle + "</RearAxle>");
            }
            else
            {
                newLines.Add("<FrontAxle>" + 0.4 * ConvertTrainDat.CarLength + "</FrontAxle>");
                newLines.Add("<RearAxle>" + -(0.4 * ConvertTrainDat.CarLength) + "</RearAxle>");
            }
            if (!String.IsNullOrEmpty(CarInfos[i].Object))
            {
                newLines.Add("<Object>" + CarInfos[i].Object + "</Object>");
            }
            newLines.Add("<Reversed>" + CarInfos[i].Reversed + "</Reversed>");
            if (CarInfos[i].FrontBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].FrontBogie.Object))
            {
                newLines.Add("<FrontBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].FrontBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].FrontBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].FrontBogie.Reversed + "</Reversed>");
                newLines.Add("</FrontBogie>");
            }

            if (CarInfos[i].RearBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].RearBogie.Object))
            {
                newLines.Add("<RearBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].RearBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].RearBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].RearBogie.Reversed + "</Reversed>");
                newLines.Add("</RearBogie>");
            }
            if (i == ConvertTrainDat.DriverCar)
            {
                if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel.animated")))
                {
                    newLines.Add("<InteriorView>panel.animated</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
                else if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel2.cfg")))
                {
                    newLines.Add("<InteriorView>panel2.cfg</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
            }
            newLines.Add("<Brake>");
            if (ConvertTrainDat.MotorCars[i] == true)
            {
                newLines.Add("<Compressor>");
                newLines.Add("<Rate>5000.0</Rate>");
                newLines.Add("</Compressor>");
            }

            newLines.Add("<MainReservoir>");
            newLines.Add("<MinimumPressure>" + ConvertTrainDat.MainReservoirMinimumPressure + "</MinimumPressure>");
            newLines.Add("<MaximumPressure>" + ConvertTrainDat.MainReservoirMaximumPressure + "</MaximumPressure>");
            newLines.Add("</MainReservoir>");
            newLines.Add("<AuxiliaryReservoir>");
            newLines.Add("<ChargeRate>200000.0</ChargeRate>");
            newLines.Add("</AuxiliaryReservoir>");
            newLines.Add("<EqualizingReservoir>");
            newLines.Add("<ServiceRate>50000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>250000.0</EmergencyRate>");
            newLines.Add("<ChargeRate>200000.0</ChargeRate>");
            newLines.Add("</EqualizingReservoir>");
            newLines.Add("<BrakePipe>");
            newLines.Add("<NormalPressure>" + ConvertTrainDat.BrakePipePressure + "</NormalPressure>");
            newLines.Add("<ServiceRate>1500000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>5000000.0</EmergencyRate>");
            newLines.Add("<ChargeRate>10000000.0</ChargeRate>");
            newLines.Add("</BrakePipe>");
            newLines.Add("<StraightAirPipe>");
            newLines.Add("<ServiceRate>300000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>400000.0</EmergencyRate>");
            newLines.Add("<ReleaseRate>200000.0</ReleaseRate>");
            newLines.Add("</StraightAirPipe>");
            newLines.Add("<BrakeCylinder>");
            newLines.Add("<ServiceMaximumPressure>" + ConvertTrainDat.BrakeCylinderServiceMaximumPressure + "</ServiceMaximumPressure>");
            newLines.Add("<EmergencyMaximumPressure>" + ConvertTrainDat.BrakeCylinderEmergencyMaximumPressure + "</EmergencyMaximumPressure>");
            newLines.Add("<EmergencyRate>" + ConvertTrainDat.BrakeCylinderEmergencyRate + "</EmergencyRate>");
            newLines.Add("<ReleaseRate>" + ConvertTrainDat.BrakeCylinderReleaseRate + "</ReleaseRate>");
            newLines.Add("</BrakeCylinder>");
            newLines.Add("</Brake>");
            newLines.Add("</Car>");
        }
Esempio n. 5
0
        internal static void GenerateCarXML(ref TabbedList newLines, int i)
        {
            newLines.Add("<Car>");
            if (CarInfos[i].Length != 0.0)
            {
                newLines.Add("<Length>" + CarInfos[i].Length + "</Length>");
            }
            else
            {
                newLines.Add("<Length>" + ConvertTrainDat.CarLength + "</Length>");
            }
            newLines.Add("<Width>" + ConvertTrainDat.CarWidth + "</Width>");
            newLines.Add("<Height>" + ConvertTrainDat.CarHeight + "</Height>");
            if (ConvertTrainDat.MotorCars[i] == true)
            {
                newLines.Add("<MotorCar>True</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.MotorCarMass + "</Mass>");
            }
            else
            {
                newLines.Add("<MotorCar>False</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.TrailerCarMass + "</Mass>");
            }
            if (CarInfos[i].AxlesDefined == true)
            {
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearAxle + "</RearAxle>");
            }
            else
            {
                newLines.Add("<FrontAxle>" + 0.4 * ConvertTrainDat.CarLength + "</FrontAxle>");
                newLines.Add("<RearAxle>" + -(0.4 * ConvertTrainDat.CarLength) + "</RearAxle>");
            }
            if (!String.IsNullOrEmpty(CarInfos[i].Object))
            {
                newLines.Add("<Object>" + CarInfos[i].Object + "</Object>");
            }
            newLines.Add("<Reversed>" + CarInfos[i].Reversed + "</Reversed>");
            if (CarInfos[i].FrontBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].FrontBogie.Object))
            {
                newLines.Add("<FrontBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].FrontBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].FrontBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].FrontBogie.Reversed + "</Reversed>");
                newLines.Add("</FrontBogie>");
            }

            if (CarInfos[i].RearBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].RearBogie.Object))
            {
                newLines.Add("<RearBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].RearBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].RearBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].RearBogie.Reversed + "</Reversed>");
                newLines.Add("</RearBogie>");
            }
            if (i == ConvertTrainDat.DriverCar)
            {
                if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel.animated")))
                {
                    newLines.Add("<InteriorView>panel.animated</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
                else if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel2.cfg")))
                {
                    newLines.Add("<InteriorView>panel2.cfg</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
            }
            newLines.Add("</Car>");
        }
Esempio n. 6
0
        internal static void Process(MainForm form)
        {
            if (!System.IO.File.Exists(FileName))
            {
                return;
            }
            mainForm = form;
            panel    = new Vector3(DriverPosition.X, DriverPosition.Y, DriverPosition.Z + 1.0);
            string[]   Lines    = System.IO.File.ReadAllLines(FileName);
            TabbedList newLines = new TabbedList();

            for (int i = 0; i < Lines.Length; i++)
            {
                int j = Lines[i].IndexOf(';');
                if (j >= 0)
                {
                    Lines[i] = Lines[i].Substring(0, j).Trim();
                }
                else
                {
                    Lines[i] = Lines[i].Trim();
                }
            }
            if (Lines.Length < 1 || string.Compare(Lines[0], "version 1.0", StringComparison.OrdinalIgnoreCase) != 0)
            {
                mainForm.updateLogBoxText += "Invalid sound.cfg format string " + Lines[0] + Environment.NewLine;
                MessageBox.Show("Invalid sound.cfg format declaration.");
                return;
            }
            newLines.Add("<CarSounds>");
            for (int i = 0; i < Lines.Length; i++)
            {
                switch (Lines[i].ToLowerInvariant())
                {
                case "[run]":
                    newLines.Add("<Run>");
                    i++;
                    while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            int    k;
                            if (!int.TryParse(a, System.Globalization.NumberStyles.Integer,
                                              CultureInfo.InvariantCulture, out k))
                            {
                                continue;
                            }
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            if (k >= 0)
                            {
                                newLines.Add("<Sound>");
                                newLines.Add("<Index>" + k + "</Index>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Sound>");
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Run>");
                    break;

                case "[motor]":
                    newLines.Add("<Motor>");
                    i++;
                    while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            int    k;
                            if (!int.TryParse(a, System.Globalization.NumberStyles.Integer,
                                              CultureInfo.InvariantCulture, out k))
                            {
                                continue;
                            }
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            if (k >= 0)
                            {
                                newLines.Add("<Sound>");
                                newLines.Add("<Index>" + k + "</Index>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Sound>");
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Motor>");
                    break;

                case "[ats]":
                    newLines.Add("<ATS>");
                    i++;
                    while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            int    k;
                            if (!int.TryParse(a, System.Globalization.NumberStyles.Integer,
                                              CultureInfo.InvariantCulture, out k))
                            {
                                continue;
                            }
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            if (k >= 0)
                            {
                                newLines.Add("<Sound>");
                                newLines.Add("<Index>" + k + "</Index>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Sound>");
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</ATS>");
                    break;

                case "[switch]":
                    newLines.Add("<Switch>");
                    i++;
                    while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            int    k;
                            if (!int.TryParse(a, System.Globalization.NumberStyles.Integer,
                                              CultureInfo.InvariantCulture, out k))
                            {
                                continue;
                            }
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            if (k >= 0)
                            {
                                newLines.Add("<Sound>");
                                newLines.Add("<Index>" + k + "</Index>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Sound>");
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Switch>");
                    break;

                case "[brake]":
                    newLines.Add("<Brake>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "bc release high":
                                newLines.Add("<ReleaseHigh>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</ReleaseHigh>");
                                break;

                            case "bc release":
                                newLines.Add("<Release>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</Release>");
                                break;

                            case "bc release full":
                                newLines.Add("<ReleaseFull>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</ReleaseFull>");
                                break;

                            case "emergency":
                                newLines.Add("<Emergency>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</Emergency>");
                                break;

                            case "bp decomp":
                                newLines.Add("<Application>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</Application>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Brake>");
                    break;

                case "[compressor]":
                    newLines.Add("<Compressor>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "attack":
                                newLines.Add("<Start>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Start>");
                                break;

                            case "loop":
                                newLines.Add("<Loop>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Loop>");
                                break;

                            case "release":
                                newLines.Add("<End>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</End>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Compressor>");
                    break;

                case "[suspension]":
                    newLines.Add("<Suspension>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "left":
                                newLines.Add("<Left>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</Left>");
                                break;

                            case "right":
                                newLines.Add("<Right>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>5.0</Radius>");
                                newLines.Add("</Right>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Suspension>");
                    break;

                case "[horn]":
                    newLines.Add("<Horn>");
                    i++;
                    List <string> primary   = new List <string>();
                    List <string> secondary = new List <string>();
                    List <string> music     = new List <string>();
                    while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }

                            switch (a.ToLowerInvariant())
                            {
                            //PRIMARY HORN (Enter)
                            case "primarystart":
                                primary.Add("<Start>");
                                primary.Add("<FileName>" + b + "</FileName>");
                                primary.Add("<Position>" + front + "</Position>");
                                primary.Add("<Radius>30.0</Radius>");
                                primary.Add("</Start>");
                                break;

                            case "primaryend":
                            case "primaryrelease":
                                primary.Add("<End>");
                                primary.Add("<FileName>" + b + "</FileName>");
                                primary.Add("<Position>" + front + "</Position>");
                                primary.Add("<Radius>30.0</Radius>");
                                primary.Add("</End>");
                                break;

                            case "primaryloop":
                            case "primary":
                                primary.Add("<Loop>");
                                primary.Add("<FileName>" + b + "</FileName>");
                                primary.Add("<Position>" + front + "</Position>");
                                primary.Add("<Radius>30.0</Radius>");
                                primary.Add("</Loop>");
                                break;

                            //SECONDARY HORN (Numpad Enter)
                            case "secondarystart":
                                secondary.Add("<Start>");
                                secondary.Add("<FileName>" + b + "</FileName>");
                                secondary.Add("<Position>" + front + "</Position>");
                                secondary.Add("<Radius>30.0</Radius>");
                                secondary.Add("</Start>");
                                break;

                            case "secondaryend":
                            case "secondaryrelease":
                                secondary.Add("<End>");
                                secondary.Add("<FileName>" + b + "</FileName>");
                                secondary.Add("<Position>" + front + "</Position>");
                                secondary.Add("<Radius>30.0</Radius>");
                                secondary.Add("</End>");
                                break;

                            case "secondaryloop":
                            case "secondary":
                                secondary.Add("<Loop>");
                                secondary.Add("<FileName>" + b + "</FileName>");
                                secondary.Add("<Position>" + front + "</Position>");
                                secondary.Add("<Radius>30.0</Radius>");
                                secondary.Add("</Loop>");
                                break;

                            //MUSIC HORN
                            case "musicstart":
                                music.Add("<Start>");
                                music.Add("<FileName>" + b + "</FileName>");
                                music.Add("<Position>" + front + "</Position>");
                                music.Add("<Radius>30.0</Radius>");
                                music.Add("</Start>");
                                break;

                            case "musicend":
                            case "musicrelease":
                                music.Add("<End>");
                                music.Add("<FileName>" + b + "</FileName>");
                                music.Add("<Position>" + front + "</Position>");
                                music.Add("<Radius>30.0</Radius>");
                                music.Add("</End>");
                                break;

                            case "musicloop":
                            case "music":
                                music.Add("<Loop>");
                                music.Add("<FileName>" + b + "</FileName>");
                                music.Add("<Position>" + front + "</Position>");
                                music.Add("<Radius>30.0</Radius>");
                                music.Add("</Loop>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    if (primary.Count != 0)
                    {
                        newLines.Add("<Primary>");
                        newLines.AddRange(primary);
                        newLines.Add("</Primary>");
                    }
                    if (secondary.Count != 0)
                    {
                        newLines.Add("<Secondary>");
                        newLines.AddRange(secondary);
                        newLines.Add("</Secondary>");
                    }
                    if (music.Count != 0)
                    {
                        newLines.Add("<Music>");
                        newLines.AddRange(music);
                        newLines.Add("<Toggle>true</Toggle>");
                        newLines.Add("</Music>");
                    }
                    newLines.Add("</Horn>");
                    break;

                case "[door]":
                    newLines.Add("<Door>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            else
                            {
                                switch (a.ToLowerInvariant())
                                {
                                case "open left":
                                    newLines.Add("<OpenLeft>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>-1.3,0,0</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</OpenLeft>");
                                    break;

                                case "open right":
                                    newLines.Add("<OpenRight>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>1.3,0,0</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</OpenRight>");
                                    break;

                                case "close left":
                                    newLines.Add("<CloseLeft>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>-1.3,0,0</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</CloseLeft>");
                                    break;

                                case "close right":
                                    newLines.Add("<CloseRight>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>1.3,0,0</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</CloseRight>");
                                    break;
                                }
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Door>");
                    break;

                case "[buzzer]":
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "correct":
                                newLines.Add("<Buzzer>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Buzzer>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--; break;

                case "[pilot lamp]":
                    newLines.Add("<PilotLamp>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "on":
                                newLines.Add("<On>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</On>");
                                break;

                            case "off":
                                newLines.Add("<Off>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Off>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</PilotLamp>");
                    break;

                case "[brake handle]":
                    newLines.Add("<BrakeHandle>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "apply":
                                newLines.Add("<Apply>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Apply>");
                                break;

                            case "applyfast":
                                newLines.Add("<ApplyFast>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</ApplyFast>");
                                break;

                            case "release":
                                newLines.Add("<Release>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Release>");
                                break;

                            case "releasefast":
                                newLines.Add("<ReleaseFast>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</ReleaseFast>");
                                break;

                            case "min":
                                newLines.Add("<Minimum>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Minimum>");
                                break;

                            case "max":
                                newLines.Add("<Maximum>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Maximum>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</BrakeHandle>");
                    break;

                case "[master controller]":
                    newLines.Add("<PowerHandle>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            else
                            {
                                switch (a.ToLowerInvariant())
                                {
                                case "up":
                                    newLines.Add("<Increase>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</Increase>");
                                    break;

                                case "upfast":
                                    newLines.Add("<IncreaseFast>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</IncreaseFast>");
                                    break;

                                case "down":
                                    newLines.Add("<Decrease>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</Decrease>");
                                    break;

                                case "downfast":
                                    newLines.Add("<DecreaseFast>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</DecreaseFast>");
                                    break;

                                case "min":
                                    newLines.Add("<Minimum>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</Minimum>");
                                    break;

                                case "max":
                                    newLines.Add("<Maximum>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>2.0</Radius>");
                                    newLines.Add("</Maximum>");
                                    break;
                                }
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</PowerHandle>");
                    break;

                case "[reverser]":
                    newLines.Add("<Reverser>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "on":
                                newLines.Add("<On>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</On>");
                                break;

                            case "off":
                                newLines.Add("<Off>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>" + panel + "</Position>");
                                newLines.Add("<Radius>2.0</Radius>");
                                newLines.Add("</Off>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Reverser>");
                    break;

                case "[breaker]":
                    newLines.Add("<Breaker>");
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            else
                            {
                                switch (a.ToLowerInvariant())
                                {
                                case "on":
                                    newLines.Add("<On>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</On>");
                                    break;

                                case "off":
                                    newLines.Add("<Off>");
                                    newLines.Add("<FileName>" + b + "</FileName>");
                                    newLines.Add("<Position>" + panel + "</Position>");
                                    newLines.Add("<Radius>5.0</Radius>");
                                    newLines.Add("</Off>");
                                    break;
                                }
                            }
                        }
                        i++;
                    }
                    i--;
                    newLines.Add("</Breaker>");
                    break;

                case "[others]":
                    i++; while (i < Lines.Length && !Lines[i].StartsWith("[", StringComparison.Ordinal))
                    {
                        int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                        if (j >= 0)
                        {
                            string a = Lines[i].Substring(0, j).TrimEnd();
                            string b = Lines[i].Substring(j + 1).TrimStart();
                            if (b.Length == 0 || Path.ContainsInvalidChars(b))
                            {
                                continue;
                            }
                            switch (a.ToLowerInvariant())
                            {
                            case "noise":
                                newLines.Add("<Loop>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Loop>");
                                break;

                            case "shoe":
                                newLines.Add("<Rub>");
                                newLines.Add("<FileName>" + b + "</FileName>");
                                newLines.Add("<Position>0,0,0</Position>");
                                newLines.Add("<Radius>10.0</Radius>");
                                newLines.Add("</Rub>");
                                break;
                            }
                        }
                        i++;
                    }
                    i--;
                    break;
                }
            }
            newLines.Add("</CarSounds>");
            newLines.Add("</openBVE>");
            string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "sound.xml");

            try
            {
                using (StreamWriter sw = new StreamWriter(fileOut))
                {
                    foreach (String s in newLines.Lines)
                    {
                        sw.WriteLine(s);
                    }
                }
            }
            catch
            {
                mainForm.updateLogBoxText += "Error writing file " + fileOut + Environment.NewLine;
                MessageBox.Show("An error occured whilst writing the new XML file. \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
        }
Esempio n. 7
0
        internal static void Process(MainForm form)
        {
            if (!System.IO.File.Exists(FileName))
            {
                return;
            }
            mainForm = form;
            string[]   Lines    = System.IO.File.ReadAllLines(FileName);
            TabbedList newLines = new TabbedList();

            for (int i = 0; i < Lines.Length; i++)
            {
                int j = Lines[i].IndexOf(';');
                if (j >= 0)
                {
                    Lines[i] = Lines[i].Substring(0, j).Trim(new char[] { });
                }
                else
                {
                    Lines[i] = Lines[i].Trim(new char[] { });
                }
            }
            if (Lines.Length < 1 || string.Compare(Lines[0], "version 1.0", StringComparison.OrdinalIgnoreCase) != 0)
            {
                mainForm.updateLogBoxText += "Invalid panel2 format string " + Lines[0] + Environment.NewLine;
                MessageBox.Show("Invalid panel2.cfg format declaration.");
                return;
            }
            newLines.Add("<Panel>");
            string currentSection = string.Empty;

            for (int i = 0; i < Lines.Length; i++)
            {
                int j = Lines[i].IndexOf("=", StringComparison.Ordinal);
                if (Lines[i].Length == 0)
                {
                    continue;
                }
                if (Lines[i][0] == '[' && Lines[i][Lines[i].Length - 1] == ']')
                {
                    if (currentSection != string.Empty)
                    {
                        newLines.Add("</" + currentSection + ">");
                    }
                    currentSection = Lines[i].Substring(1, Lines[i].Length - 2);
                    newLines.Add("<" + currentSection + ">");
                }
                else if (Lines[i].IndexOf('=') != -1)
                {
                    string a = Lines[i].Substring(0, j).TrimEnd(new char[] { });
                    string b = Lines[i].Substring(j + 1).TrimStart(new char[] { });
                    newLines.Add("<" + a + ">" + b + "</" + a + ">");
                }
            }
            newLines.Add("</" + currentSection + ">");
            newLines.Add("</Panel>");
            newLines.Add("</openBVE>");
            string fileOut = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(FileName), "panel.xml");

            try
            {
                using (StreamWriter sw = new StreamWriter(fileOut))
                {
                    foreach (String s in newLines.Lines)
                    {
                        sw.WriteLine(s);
                    }
                }
            }
            catch
            {
                mainForm.updateLogBoxText += "Error writing file " + fileOut + Environment.NewLine;
                MessageBox.Show("An error occured whilst writing the new XML file. \r\n Please check for write permissions.", "CarXML Convertor", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
        }
        internal static void GenerateCarXML(ref TabbedList newLines, int i)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            newLines.Add("<Car>");
            if (CarInfos[i].Length != 0.0)
            {
                newLines.Add("<Length>" + CarInfos[i].Length + "</Length>");
            }
            else
            {
                newLines.Add("<Length>" + ConvertTrainDat.CarLength + "</Length>");
            }
            newLines.Add("<Width>" + ConvertTrainDat.CarWidth + "</Width>");
            newLines.Add("<Height>" + ConvertTrainDat.CarHeight + "</Height>");
            if (ConvertTrainDat.MotorCars[i] == true)
            {
                newLines.Add("<MotorCar>True</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.MotorCarMass + "</Mass>");
                switch (ConvertTrainDat.ReadhesionDeviceType)
                {
                case 0:
                    newLines.Add("<ReadhesionDevice>TypeA</ReadhesionDevice>");
                    break;

                case 1:
                    newLines.Add("<ReadhesionDevice>TypeB</ReadhesionDevice>");
                    break;

                case 2:
                    newLines.Add("<ReadhesionDevice>TypeC</ReadhesionDevice>");
                    break;

                case 3:
                    newLines.Add("<ReadhesionDevice>TypeD</ReadhesionDevice>");
                    break;

                default:
                    newLines.Add("<ReadhesionDevice>NotFitted</ReadhesionDevice>");
                    break;
                }
                newLines.Add("<AccelerationCurves>");
                newLines.Add("<OpenBVE>");
                foreach (ConvertTrainDat.AccelerationCurve curve in ConvertTrainDat.AccelerationCurves)
                {
                    newLines.Add("<StageZeroAcceleration>" + curve.StageZeroAcceleration + "</StageZeroAcceleration>");
                    newLines.Add("<StageOneAcceleration>" + curve.StageOneAcceleration + "</StageOneAcceleration>");
                    newLines.Add("<StageOneSpeed>" + curve.StageOneSpeed + "</StageOneSpeed>");
                    newLines.Add("<StageTwoSpeed>" + curve.StageTwoSpeed + "</StageTwoSpeed>");
                    newLines.Add("<StageTwoExponent>" + curve.StageTwoExponent + "</StageTwoExponent>");
                }
                newLines.Add("</OpenBVE>");
                newLines.Add("</AccelerationCurves>");
            }
            else
            {
                newLines.Add("<MotorCar>False</MotorCar>");
                newLines.Add("<Mass>" + ConvertTrainDat.TrailerCarMass + "</Mass>");
            }
            if (CarInfos[i].AxlesDefined == true)
            {
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearAxle + "</RearAxle>");
            }
            else
            {
                newLines.Add("<FrontAxle>" + 0.4 * ConvertTrainDat.CarLength + "</FrontAxle>");
                newLines.Add("<RearAxle>" + -(0.4 * ConvertTrainDat.CarLength) + "</RearAxle>");
            }
            if (!String.IsNullOrEmpty(CarInfos[i].Object))
            {
                newLines.Add("<Object>" + CarInfos[i].Object + "</Object>");
            }
            newLines.Add("<Reversed>" + CarInfos[i].Reversed + "</Reversed>");
            newLines.Add("<LoadingSway>" + CarInfos[i].Reversed + "</LoadingSway>");
            if (CarInfos[i].FrontBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].FrontBogie.Object))
            {
                newLines.Add("<FrontBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].FrontBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].FrontBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].FrontBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].FrontBogie.Reversed + "</Reversed>");
                newLines.Add("</FrontBogie>");
            }

            if (CarInfos[i].RearBogie.AxlesDefined == true || !string.IsNullOrEmpty(CarInfos[i].RearBogie.Object))
            {
                newLines.Add("<RearBogie>");
                newLines.Add("<FrontAxle>" + CarInfos[i].RearBogie.FrontAxle + "</FrontAxle>");
                newLines.Add("<RearAxle>" + CarInfos[i].RearBogie.RearAxle + "</RearAxle>");
                newLines.Add("<Object>" + CarInfos[i].RearBogie.Object + "</Object>");
                newLines.Add("<Reversed>" + CarInfos[i].RearBogie.Reversed + "</Reversed>");
                newLines.Add("</RearBogie>");
            }
            if (i == ConvertTrainDat.DriverCar)
            {
                if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel.animated")))
                {
                    newLines.Add("<InteriorView>panel.animated</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
                else if (System.IO.File.Exists(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), "panel2.cfg")))
                {
                    newLines.Add("<InteriorView>panel.xml</InteriorView>");
                    newLines.Add("<DriverPosition>" + ConvertSoundCfg.DriverPosition.X + "," + ConvertSoundCfg.DriverPosition.Y + "," + ConvertSoundCfg.DriverPosition.Z + "</DriverPosition>");
                }
            }
            newLines.Add("<Brake>");
            if (ConvertTrainDat.MotorCars[i] == true)
            {
                newLines.Add("<Compressor>");
                newLines.Add("<Rate>5000.0</Rate>");
                newLines.Add("</Compressor>");
            }

            newLines.Add("<MainReservoir>");
            newLines.Add("<MinimumPressure>" + ConvertTrainDat.MainReservoirMinimumPressure + "</MinimumPressure>");
            newLines.Add("<MaximumPressure>" + ConvertTrainDat.MainReservoirMaximumPressure + "</MaximumPressure>");
            newLines.Add("</MainReservoir>");
            newLines.Add("<AuxiliaryReservoir>");
            newLines.Add("<ChargeRate>200000.0</ChargeRate>");
            newLines.Add("</AuxiliaryReservoir>");
            newLines.Add("<EqualizingReservoir>");
            newLines.Add("<ServiceRate>50000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>250000.0</EmergencyRate>");
            newLines.Add("<ChargeRate>200000.0</ChargeRate>");
            newLines.Add("</EqualizingReservoir>");
            newLines.Add("<BrakePipe>");
            newLines.Add("<NormalPressure>" + ConvertTrainDat.BrakePipePressure + "</NormalPressure>");
            newLines.Add("<ServiceRate>1500000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>5000000.0</EmergencyRate>");
            newLines.Add("<ChargeRate>10000000.0</ChargeRate>");
            newLines.Add("</BrakePipe>");
            newLines.Add("<StraightAirPipe>");
            newLines.Add("<ServiceRate>300000.0</ServiceRate>");
            newLines.Add("<EmergencyRate>400000.0</EmergencyRate>");
            newLines.Add("<ReleaseRate>200000.0</ReleaseRate>");
            newLines.Add("</StraightAirPipe>");
            newLines.Add("<BrakeCylinder>");
            newLines.Add("<ServiceMaximumPressure>" + ConvertTrainDat.BrakeCylinderServiceMaximumPressure + "</ServiceMaximumPressure>");
            newLines.Add("<EmergencyMaximumPressure>" + ConvertTrainDat.BrakeCylinderEmergencyMaximumPressure + "</EmergencyMaximumPressure>");
            newLines.Add("<EmergencyRate>" + ConvertTrainDat.BrakeCylinderEmergencyRate + "</EmergencyRate>");
            newLines.Add("<ReleaseRate>" + ConvertTrainDat.BrakeCylinderReleaseRate + "</ReleaseRate>");
            newLines.Add("</BrakeCylinder>");
            newLines.Add("</Brake>");
            newLines.Add("</Car>");
            if (i < Couplers.Length)
            {
                if (Couplers[i] != null)
                {
                    newLines.Add("<Coupler>");
                    newLines.Add("<Minimum>" + Couplers[i].Min + "</Minimum>");
                    newLines.Add("<Maximum>" + Couplers[i].Max + "</Maximum>");
                    newLines.Add("</Coupler>");
                }
            }
        }