Ejemplo n.º 1
0
        private void CopyAndPrepareResources(List<CarResource> resources)
        {
            Directory.CreateDirectory(Path.Combine(OutputDir, CarModelDir));
            Directory.CreateDirectory(Path.Combine(OutputDir, CarModelDir, AssembliesDir));
            // By default, put the default car assembly there
            DefaultCarAssembly defaultasy = new DefaultCarAssembly();
            using (StreamWriter writer = new StreamWriter(Path.Combine(OutputDir, CarModelDir, AssembliesDir, "DefaultCar.asy"), false))
            {
                writer.WriteLine(defaultasy.TransformText());
            }
            foreach (var res in resources)
            {
                try
                {
                    if (res.FileName.EndsWith(".tpl"))
                    {
                        File.Copy(Path.Combine(ProjectDir, CarModelDir, res.FileName), Path.Combine(OutputDir, CarModelDir, res.FileName), true);
                    }
                    else
                    {
                        string rescontent = PrepareResource(res);
                        string dirpath = Path.GetDirectoryName(Path.Combine(OutputDir, CarModelDir, res.FileName));

                        if (!Directory.Exists(dirpath))
                        {
                            Directory.CreateDirectory(dirpath);
                        }
                        AdamsCarFile test = new AdamsCarFile(rescontent);
                        foreach (var resconnect in res.References)
                        {
                            if (Replacements.ContainsKey(resconnect.Key))
                            {
                                test.Replace(Replacements[resconnect.Key], resconnect.Value.FileName);
                            }
                            else
                            {
                                GMEConsole.Warning.WriteLine("Replacement with key '" + resconnect.Key + "' was not found. Ignoring.");
                            }
                        }
                        foreach (var param in res.Parameters)
                        {
                            if (param.Replacement != null)
                            {
                                test.Replace(param.Replacement, param.Value);
                            }
                        }
                        using (StreamWriter writer = new StreamWriter(Path.Combine(OutputDir, CarModelDir, res.FileName), false))
                        {
                            writer.WriteLine(test.ToString());
                        }
                        //GMEConsole.Info.WriteLine(test.ToString());
                    }
                }
                catch (System.IO.DirectoryNotFoundException ex)
                {
                    GMEConsole.Error.WriteLine("Car resource '" + res.FileName + "' was not found. This file will not be included in the ADAMS model.");
                    throw ex;
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    GMEConsole.Error.WriteLine("Car resource '" + res.FileName + "' was not found. This file will not be included in the ADAMS model.");
                    throw ex;
                }
            }
        }
Ejemplo n.º 2
0
        private void CopyAndPrepareResources(List <CarResource> resources)
        {
            Directory.CreateDirectory(Path.Combine(OutputDir, CarModelDir));
            Directory.CreateDirectory(Path.Combine(OutputDir, CarModelDir, AssembliesDir));
            // By default, put the default car assembly there
            DefaultCarAssembly defaultasy = new DefaultCarAssembly();

            using (StreamWriter writer = new StreamWriter(Path.Combine(OutputDir, CarModelDir, AssembliesDir, "DefaultCar.asy"), false))
            {
                writer.WriteLine(defaultasy.TransformText());
            }
            foreach (var res in resources)
            {
                try
                {
                    if (res.FileName.EndsWith(".tpl"))
                    {
                        File.Copy(Path.Combine(ProjectDir, CarModelDir, res.FileName), Path.Combine(OutputDir, CarModelDir, res.FileName), true);
                    }
                    else
                    {
                        string rescontent = PrepareResource(res);
                        string dirpath    = Path.GetDirectoryName(Path.Combine(OutputDir, CarModelDir, res.FileName));

                        if (!Directory.Exists(dirpath))
                        {
                            Directory.CreateDirectory(dirpath);
                        }
                        AdamsCarFile test = new AdamsCarFile(rescontent);
                        foreach (var resconnect in res.References)
                        {
                            if (Replacements.ContainsKey(resconnect.Key))
                            {
                                test.Replace(Replacements[resconnect.Key], resconnect.Value.FileName);
                            }
                            else
                            {
                                GMEConsole.Warning.WriteLine("Replacement with key '" + resconnect.Key + "' was not found. Ignoring.");
                            }
                        }
                        foreach (var param in res.Parameters)
                        {
                            if (param.Replacement != null)
                            {
                                test.Replace(param.Replacement, param.Value);
                            }
                        }
                        using (StreamWriter writer = new StreamWriter(Path.Combine(OutputDir, CarModelDir, res.FileName), false))
                        {
                            writer.WriteLine(test.ToString());
                        }
                        //GMEConsole.Info.WriteLine(test.ToString());
                    }
                }
                catch (System.IO.DirectoryNotFoundException ex)
                {
                    GMEConsole.Error.WriteLine("Car resource '" + res.FileName + "' was not found. This file will not be included in the ADAMS model.");
                    throw ex;
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    GMEConsole.Error.WriteLine("Car resource '" + res.FileName + "' was not found. This file will not be included in the ADAMS model.");
                    throw ex;
                }
            }
        }