Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public void Run()
        {
            TwoDimArray source = TwoDimArrayFactory.Load2da(options.SourceFile);

            foreach (string patchPath in options.PatchFiles)
            {
                Console.WriteLine($"Processing patch: {patchPath}");
                TwoDimArray patch = TwoDimArrayFactory.Load2da(patchPath);
                ProcessPatch(source, patch);
                Console.WriteLine($"Patch processed: {patchPath}");
            }

            ExportResult(source);
        }
        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);
        }
Exemplo n.º 4
0
        private void DoAdd(TwoDimArray source, int index, TwoDimArrayEntry entryToAdd)
        {
            if (index < source.Entries.Count)
            {
                Console.WriteLine($"ADD patch entry at index {index} overwrites an existing value. Use REPLACE if replacement is intentional. Skipping...");
                return;
            }

            if (index > source.Entries.Count)
            {
                TwoDimArrayEntry padding = TwoDimArrayFactory.CreateEmptyEntry(source.Entries[0].Values.Keys);
                for (int i = source.Entries.Count - 1; i < index; i++)
                {
                    source.Entries.Add(padding);
                }
            }

            foreach (string column in PatchColumns)
            {
                entryToAdd.Values.Remove(column);
            }
            source.Entries.Add(entryToAdd);
        }
Exemplo n.º 5
0
        private void ProcessPatch(TwoDimArray source, TwoDimArray patch)
        {
            foreach (TwoDimArrayEntry entry in patch.Entries)
            {
                string command = (string)entry.Values[PatchCommand];
                int    index   = Convert.ToInt32(entry.Values[PatchRowIndex]);

                switch (command.ToUpperInvariant())
                {
                case "ADD":
                    DoAdd(source, index, entry);
                    break;

                case "REPLACE":
                    DoReplace(source.Entries[index], entry);
                    break;

                case "REMOVE":
                    DoRemove(source, index);
                    break;
                }
            }
        }
Exemplo n.º 6
0
 private void DoRemove(TwoDimArray source, int index)
 {
     source.Entries.RemoveAt(index);
 }