forked from KillzXGaming/TextureConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
54 lines (45 loc) · 1.72 KB
/
Program.cs
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
using System;
using Toolbox.Core;
using Toolbox.Core.IO;
namespace TextureConverter
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: TextureConverter file [ext] [output]" );
return;
}
OpenTK.GameWindow window = new OpenTK.GameWindow();
Runtime.OpenTKInitialized = true;
var file = STFileLoader.OpenFileFormat(args[0]);
if (file == null)
{
Console.WriteLine("No files specified");
return;
}
string ext = ".png";
string directory = System.IO.Path.GetDirectoryName(args[0]).Replace("\\", "/") + "/";
Console.WriteLine("Directory: " + directory);
if (args.Length > 1) {
ext = args[1];
}
Console.WriteLine($"file {file.FileInfo.FileName} {file.GetType()}");
if (file is STGenericTexture) {
ExportTexture((STGenericTexture)file, $"{directory}{System.IO.Path.GetFileNameWithoutExtension(((STGenericTexture)file).Name)}{ext}");
}
if (file is ITextureContainer)
{
foreach (var tex in ((ITextureContainer)file).TextureList) {
ExportTexture(tex, $"{directory}{System.IO.Path.GetFileNameWithoutExtension(tex.Name)}{ext}");
}
}
Console.WriteLine("\nConverted the file at " + args[0] + " to " + ext + " format");
}
static void ExportTexture(STGenericTexture texture, string fileName) {
texture.Export(fileName, new TextureExportSettings());
}
}
}