-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (42 loc) · 1.35 KB
/
Program.cs
File metadata and controls
52 lines (42 loc) · 1.35 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
using System.Diagnostics;
if (args.Length is not 1 || string.IsNullOrWhiteSpace(args[0]))
{
Console.WriteLine("Usage: mc-getobj <obj url>");
return;
}
var arg = args[0]; //ex.: https://resources.download.minecraft.net/66/6615ab7f668384cf98b0cb034ce8e4c52eaf86b2
if (!arg.StartsWith("https://resources.download.minecraft.net/"))
{
Console.WriteLine("That's not a valid Minecraft resource URL.");
return;
}
var uri = new Uri(arg);
var pathParts = uri.AbsolutePath.Split('/', StringSplitOptions.RemoveEmptyEntries);
if (pathParts.Length is not 2)
{
Console.WriteLine("That's not a valid Minecraft object URL.");
return;
}
var dirName = pathParts[0];
string mcObjDir = Path.Combine(Environment.GetEnvironmentVariable("appdata"), ".minecraft", "assets", "objects");
string dir = Path.Combine(mcObjDir, dirName);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
Console.WriteLine($"Created {dir}");
}
Console.WriteLine("Running curl...");
Console.WriteLine();
var curl = Process.Start(new ProcessStartInfo(@"C:\Windows\System32\curl.exe", $"-O {arg}")
{
WorkingDirectory = dir,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
})!;
var stdout = curl.StandardOutput.ReadToEnd();
var stderr = curl.StandardError.ReadToEnd();
curl.WaitForExit();
Console.Write(stdout);
Console.Write(stderr);