Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
169 lines (159 loc) · 6.79 KB
/
Copy pathProgram.cs
File metadata and controls
169 lines (159 loc) · 6.79 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SystemPlus.Utils;
namespace TileUtil
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Execute(args);
}
public static void User()
{
while (true) {
Console.Write("Input: ");
string input = Console.ReadLine().Replace("\\", "/");
List<string> args = new List<string>();
bool inString = false;
string reading = string.Empty;
for (int i = 0; i < input.Length; i++) {
char c = input[i];
if (inString) {
if (c == '"') {
inString = false;
if (reading.Length > 0)
args.Add(reading);
reading = string.Empty;
}
else
reading += c;
} else {
if (c == '"')
inString = true;
else if (c == ' ') {
if (reading.Length > 0)
args.Add(reading);
reading = string.Empty;
}
else
reading += c;
}
}
if (reading.Length > 0)
args.Add(reading);
Execute(args.ToArray());
}
}
private static void Execute(string[] args)
{
if (args == null || args.Length < 1 || (args != null && args.Length > 0 && args[0].ToLower() == "help")) {
Console.WriteLine("help - shows help\n" +
"extract_dir {directory} - Extract all supertiles in directory\n" +
"extract {path(.tiles file)} - Extracts super tile file\n" +
"convert_tile_dir {directory} - Convert tiles in directory to pngs\n" +
"convert_tile - Convert tile to png");
return;
}
string command = args[0].ToLower();
if (command == "extract_dir" && args.Length > 1) {
string dir = args[1];
if (!Directory.Exists(dir)) {
Console.WriteLine($"Directory {dir} doesn't exist");
return;
}
string[] files = Directory.GetFiles(dir);
for (int i = 0; i < files.Length; i++)
if (Path.GetExtension(files[i]) == ".tiles")
try {
SuperTileExtractor.Extract(files[i]);
}
catch (Exception e) {
Console.WriteLine($"Failed to extract {Path.GetFileName(files[i])}, Exception: {e}");
}
Console.WriteLine("Done, press any key to exit...");
Console.ReadKey(true);
}
else if (command == "extract" && args.Length > 1) {
string path = args[1];
if (!File.Exists(path)) {
Console.WriteLine($"File {path} doesn't exist");
return;
}
else if (Path.GetExtension(path) != ".tiles") {
Console.WriteLine($"You must select .tiles file, not \"{Path.GetExtension(path)}\"");
return;
}
try {
SuperTileExtractor.Extract(path);
}
catch (Exception e) {
Console.WriteLine($"Failed to extract {Path.GetFileName(path)}, Exception: {e}");
}
Console.WriteLine("Done, press any key to exit...");
Console.ReadKey(true);
}
else if (command == "convert_tile_dir" && args.Length > 1) {
string dir = args[1];
if (!Directory.Exists(dir)) {
Console.WriteLine($"Directory {dir} doesn't exist");
return;
}
string saveTo = Directory.GetParent(dir).FullName + "/" + new DirectoryInfo(dir).Name + "Png/";
Directory.CreateDirectory(saveTo);
string[] files = Directory.GetFiles(dir);
int y = Console.CursorTop;
int c = 0;
for (int i = 0; i < files.Length; i++)
if (Path.GetExtension(files[i]) == ".tile") {
try {
TileImage img = TileImage.LoadTile(files[i]);
img.SavePng(saveTo + Path.GetFileNameWithoutExtension(files[i]) + ".png");
}
catch (Exception e) {
Console.WriteLine($"Failed to convert {Path.GetFileName(files[i])}, Exception: {e}");
}
c++;
int _y = Console.CursorTop;
Console.SetCursorPosition(0, y);
Console.WriteLine($"Converted {c}");
Console.SetCursorPosition(0, _y);
}
Console.WriteLine("Done, press any key to exit...");
Console.ReadKey(true);
}
else if (command == "convert_tile" && args.Length > 1) {
string path = args[1];
if (!File.Exists(path)) {
Console.WriteLine($"File {path} doesn't exist");
return;
}
else if (Path.GetExtension(path) != ".tile") {
Console.WriteLine($"You must select .tile file, not \"{Path.GetExtension(path)}\"");
return;
}
try {
TileImage img = TileImage.LoadTile(path);
img.SavePng(Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".png");
}
catch (Exception e) {
Console.WriteLine($"Failed to convert {Path.GetFileName(path)}, Exception: {e}");
}
Console.WriteLine("Done, press any key to exit...");
Console.ReadKey(true);
}
else if (command == "user" && args.Length == 1) {
User();
}
else
Console.WriteLine($"Command {command} with {args.Length} parameters doesn't exist, type \"help\" for command info");
}
}
}