|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using libEDSsharp; |
| 8 | + |
| 9 | +namespace EDSSharp |
| 10 | +{ |
| 11 | + class Program |
| 12 | + { |
| 13 | + |
| 14 | + static libEDSsharp.EDSsharp eds = new EDSsharp(); |
| 15 | + static string gitversion = ""; |
| 16 | + |
| 17 | + static void Main(string[] args) |
| 18 | + { |
| 19 | + try |
| 20 | + { |
| 21 | + |
| 22 | + Dictionary<string, string> argskvp = new Dictionary<string, string>(); |
| 23 | + |
| 24 | + int argv = 0; |
| 25 | + |
| 26 | + for (argv = 0; argv < (args.Length - 1); argv++) |
| 27 | + { |
| 28 | + if (args[argv] == "--infile") |
| 29 | + { |
| 30 | + argskvp.Add("--infile", args[argv + 1]); |
| 31 | + } |
| 32 | + |
| 33 | + if (args[argv] == "--outfile") |
| 34 | + { |
| 35 | + argskvp.Add("--outfile", args[argv + 1]); |
| 36 | + } |
| 37 | + |
| 38 | + if (args[argv] == "--type") |
| 39 | + { |
| 40 | + argskvp.Add("--type", args[argv + 1]); |
| 41 | + } |
| 42 | + |
| 43 | + argv++; |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + if (argskvp.ContainsKey("--type") && argskvp.ContainsKey("--infile") && argskvp.ContainsKey("--outfile")) |
| 48 | + { |
| 49 | + string infile = argskvp["--infile"]; |
| 50 | + string outfile = argskvp["--outfile"]; |
| 51 | + |
| 52 | + switch (Path.GetExtension(infile).ToLower()) |
| 53 | + { |
| 54 | + case ".xdd": |
| 55 | + openXDDfile(infile, outfile); |
| 56 | + break; |
| 57 | + |
| 58 | + case ".xml": |
| 59 | + openXMLfile(infile,outfile); |
| 60 | + break; |
| 61 | + |
| 62 | + case ".eds": |
| 63 | + openEDSfile(infile, outfile,InfoSection.Filetype.File_EDS); |
| 64 | + break; |
| 65 | + |
| 66 | + |
| 67 | + default: |
| 68 | + return; |
| 69 | + |
| 70 | + } |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + Console.WriteLine("Usage EDSEditor --type CanOpenNode --infile file.[xdd|eds|xml] --outfile CO_OD.c"); |
| 75 | + } |
| 76 | + } |
| 77 | + catch(Exception e) |
| 78 | + { |
| 79 | + Console.WriteLine(e.ToString()); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private static void openEDSfile(string infile, string outfile, InfoSection.Filetype ft) |
| 84 | + { |
| 85 | + |
| 86 | + eds.Loadfile(infile); |
| 87 | + |
| 88 | + exportCOOD(outfile); |
| 89 | + |
| 90 | + } |
| 91 | + |
| 92 | + private static void exportCOOD(string outpath) |
| 93 | + { |
| 94 | + |
| 95 | + outpath = Path.GetFullPath(outpath); |
| 96 | + |
| 97 | + string savePath = Path.GetDirectoryName(outpath); |
| 98 | + |
| 99 | + eds.fi.exportFolder = savePath; |
| 100 | + |
| 101 | + Warnings.warning_list.Clear(); |
| 102 | + |
| 103 | + CanOpenNodeExporter cone = new CanOpenNodeExporter(); |
| 104 | + cone.export(savePath, Path.GetFileNameWithoutExtension(outpath), gitversion, eds); |
| 105 | + |
| 106 | + foreach(string warning in Warnings.warning_list) |
| 107 | + { |
| 108 | + Console.WriteLine("WARNING :" + warning); |
| 109 | + } |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | + private static void openXMLfile(string path,string outpath) |
| 114 | + { |
| 115 | + |
| 116 | + CanOpenXML coxml = new CanOpenXML(); |
| 117 | + coxml.readXML(path); |
| 118 | + |
| 119 | + Bridge b = new Bridge(); |
| 120 | + |
| 121 | + eds = b.convert(coxml.dev); |
| 122 | + eds.xmlfilename = path; |
| 123 | + |
| 124 | + exportCOOD(outpath); |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + private static void openXDDfile(string path, string outpath) |
| 129 | + { |
| 130 | + CanOpenXDD coxml = new CanOpenXDD(); |
| 131 | + eds = coxml.readXML(path); |
| 132 | + |
| 133 | + if (eds == null) |
| 134 | + return; |
| 135 | + |
| 136 | + eds.xddfilename = path; |
| 137 | + exportCOOD(outpath); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments