示例#1
0
        private void ExportResult(TwoDimArray result)
        {
            Console.WriteLine($"Exporting patched 2da to \"{options.DestFile}\"");
            TwoDimArrayTool tool = TwoDimArrayTool.Start($"-l csv -o \"{options.DestFile}\"");

            using (CsvWriter csvWriter = new CsvWriter(tool.StandardInput, CultureInfo.InvariantCulture))
            {
                csvWriter.WriteRecords(result.Entries.Select(entry => entry.Values).Cast <object>());
            }

            tool.WaitAndCheckExitCode();
        }
示例#2
0
        public static TwoDimArrayTool Start(string arguments)
        {
            Process process = new Process();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = false;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.FileName  = ToolCommand;
            process.StartInfo.Arguments = arguments;

            TwoDimArrayTool twoDimArrayTool = new TwoDimArrayTool
            {
                process = process
            };

            process.Start();
            return(twoDimArrayTool);
        }
        public static TwoDimArray Load2da(string path)
        {
            TextReader      textReader;
            TwoDimArrayTool tool = null;

            if (path.EndsWith(".2da"))
            {
                tool       = TwoDimArrayTool.Start($"-k csv -i \"{path}\"");
                textReader = tool.StandardOutput;
            }
            else
            {
                textReader = File.OpenText(path);
            }

            using CsvReader csvReader = new CsvReader(textReader, CultureInfo.InvariantCulture);
            TwoDimArray twoDimArray = new TwoDimArray(csvReader.GetRecords <dynamic>());

            tool?.WaitAndCheckExitCode();
            return(twoDimArray);
        }