-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntryPoint.cs
126 lines (112 loc) · 4.13 KB
/
EntryPoint.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
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
using MinecraftPackCompressor.Common;
using MinecraftPackCompressor.Compression;
using System.Diagnostics;
internal class EntryPoint
{
private static void Main(string[] args)
{
//path
string outPut = Path.Combine(Directory.GetCurrentDirectory(), "Output");
//create output folder
if (!Directory.Exists(outPut))
Directory.CreateDirectory(outPut);
//intro
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine
("==============================================\n" +
"Hello!\n" +
"This is Minecraft Pack Compressor.\n" +
"This is distributed under the MIT License.\n" +
"Copyright (c) 2024 Kyuri\n" +
"==============================================\n");
askPath:
//ask
Console.WriteLine("Enter the folder path to compress.");
string? folderPath;
while (true)
{
//read path
folderPath = Console.ReadLine();
// exist
if (Directory.Exists(folderPath))
break;
// not found
if (folderPath == "")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Enter any folder path.\n");
Console.ForegroundColor = ConsoleColor.White;
continue;
}
if (!Directory.Exists(folderPath))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{folderPath} is not found.\n");
Console.ForegroundColor = ConsoleColor.White;
continue;
}
}
//search pack
List<String> packFolders = [];
try
{
//search
packFolders = PackSearch.PackSearcher(folderPath);
}
catch (FileNotFoundException ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
goto askPath;
}
//result
Console.WriteLine("\nThe following folders were found.");
Console.ForegroundColor = ConsoleColor.Blue;
foreach (String pack in packFolders)
{
Console.WriteLine(pack);
}
Console.ForegroundColor = ConsoleColor.White;
//all compress?
Console.WriteLine("\nDo you want it all compressed? (y/n)");
ConsoleKeyInfo key = Console.ReadKey(true);
while (!key.Key.ToString().Equals("Y") && !key.Key.ToString().Equals("N"))
key = Console.ReadKey(true);
if (key.Key.ToString().Equals("Y"))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Compressing...");
foreach (String pack in packFolders)
{
Compressor.Compress(pack, outPut);
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Done!");
Console.ForegroundColor = ConsoleColor.White;
Process.Start("Explorer.exe", outPut);
}
if (key.Key.ToString().Equals("N"))
{
foreach (String pack in packFolders)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"\nDo you compress [{pack}]? (y/n)");
key = Console.ReadKey(true);
while (!key.Key.ToString().Equals("Y") && !key.Key.ToString().Equals("N"))
key = Console.ReadKey(true);
if (key.Key.ToString().Equals("N"))
continue;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Compressing...");
Compressor.Compress(pack, outPut);
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Done!");
Console.ForegroundColor = ConsoleColor.White;
Process.Start("Explorer.exe", outPut);
}
}
}