-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (62 loc) · 1.89 KB
/
Program.cs
File metadata and controls
75 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.IO;
using VisualPinball.Engine.VPT.Table;
namespace VisualPinball.TableScript
{
class Program
{
static void Main(string[] args)
{
// validate inputs
try {
if (args.Length < 1) {
throw new ArgumentException("USAGE: VisualPinball.TableScript <input file or folder> [<output folder>]");
}
// input file(s)
if (!FileOrDirectoryExists(args[0])) {
throw new ArgumentException($"Non-existent input path: \"{args[0]}\".");
}
var inputAttr = File.GetAttributes(args[0]);
var inputFiles = (inputAttr & FileAttributes.Directory) == FileAttributes.Directory
? Directory.GetFiles(args[0], "*.vpx")
: new[] {args[0]};
if (inputFiles.Length == 0) {
throw new ArgumentException($"No .vpx files found at \"{args[0]}\"");
}
// output folder
string outputDir = null;
if (args.Length > 1) {
outputDir = args[1];
if (!Directory.Exists(outputDir)) {
throw new ArgumentException($"Invalid output folder \"{outputDir}\".");
}
}
foreach (var inputFile in inputFiles) {
Console.WriteLine($"Processing \"{inputFile}\"...");
var inputTable = TableLoader.Load(inputFile, false);
var code = inputTable.Data.Code;
if (Environment.NewLine == "\n") {
code = code.Replace("\r\r\n", "\n");
code = code.Replace("\r\n", "\n");
code = code.Replace("\r", "\n");
}
if (outputDir != null) {
var outputFilePath = Path.Join(outputDir, Path.GetFileNameWithoutExtension(inputFile) + ".vbs");
File.WriteAllText(outputFilePath, code);
}
else {
Console.WriteLine(code);
}
}
} catch (ArgumentException e) {
Console.WriteLine(e.Message);
} catch (Exception e) {
Console.WriteLine(e);
}
}
private static bool FileOrDirectoryExists(string name)
{
return Directory.Exists(name) || File.Exists(name);
}
}
}