-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
132 lines (114 loc) · 5.03 KB
/
Copy pathProgram.cs
File metadata and controls
132 lines (114 loc) · 5.03 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
using System;
using System.IO;
using System.Linq;
using System.Net;
namespace AssetIndexGenerator
{
internal class Program
{
static string customUrl = string.Empty; //Change this to the url you will upload your assets to
static string manifestName = string.Empty; //Change this to the json name
static void Main(string[] args)
{
Console.WriteLine("AssetIndexGenerator v1.0; by DEJVOSS Productions");
if (!Directory.Exists("resources") || !Directory.EnumerateFileSystemEntries("resources").Any())
{
Directory.CreateDirectory("resources");
Logger("Please put your resources to the .\\resources directory. Press any key to exit.");
Console.ReadLine();
Environment.Exit(0);
}
foreach(string arg in args)
{
if (arg == "-help")
{
Console.WriteLine("Arguments:");
Console.WriteLine(" -help Shows this menu");
Console.WriteLine(" -name= Name the manifest will be saved as [REQUIRED]");
Console.WriteLine(" -url= URL to where you upload your assets [REQUIRED]");
Console.WriteLine("Example usage:");
Console.WriteLine(" AssetIndexGenerator.exe -name=my_cool_manifest -url=http://example.com/assets/resources");
Console.WriteLine(" Then upload the contents of .\\out\\ to the folder on your webserver you specified above");
Console.ReadLine();
break;
}
else if (arg.StartsWith("-url="))
customUrl = arg.Replace("-url=", "");
else if(arg.StartsWith("-name="))
manifestName = arg.Replace("-name=", "");
}
if(manifestName == string.Empty)
{
Console.Write("Enter the name of your manifest: ");
manifestName = Console.ReadLine();
}
if(customUrl == string.Empty)
{
Console.Write("Enter the URL where you'll upload your assets to: ");
customUrl = Console.ReadLine();
}
Console.WriteLine($"URL: {customUrl}");
Console.WriteLine($"Name: {manifestName}");
Work();
}
static void Logger(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[ERROR] " + message);
Console.ForegroundColor = ConsoleColor.Gray;
}
static void Work()
{
string manifest = "";
manifest += "{";
manifest += "\"objects\": {";
Directory.CreateDirectory("resources");
string[] files = Directory.GetFiles("resources", "*.*", SearchOption.AllDirectories);
int i = 0;
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
FileStream fop = File.OpenRead(file);
string chksum = BitConverter.ToString(System.Security.Cryptography.SHA1.Create().ComputeHash(fop)).Replace("-", "").ToLower();
string firstTwo = chksum.Substring(0, 2);
bool isOnServers = DoesExist($"https://resources.download.minecraft.net/{firstTwo}/{chksum}");
if (!isOnServers)
{
Directory.CreateDirectory($"out/resources/{firstTwo}");
if (!File.Exists($"out/resources/{firstTwo}/{chksum}"))
File.Copy(file, $"out/resources/{firstTwo}/{chksum}");
}
string fileNew = file.Replace("\\", "/").Replace("resources/", "");
Console.WriteLine("Processing " + fileNew.ToString() + "... " + (i + 1) + " / " + files.Count());
manifest += $"\"{fileNew}\": {{";
manifest += $"\"hash\": \"{chksum}\",";
manifest += $"\"size\": {fi.Length}";
if (!isOnServers)
manifest += $",\"custom_url\": \"{customUrl}/{firstTwo}/{chksum}\"";
manifest += $"}},";
i++;
}
manifest = manifest.Remove(manifest.Length - 1);
manifest += "}";
manifest += "}";
Directory.CreateDirectory($"out/indexes");
File.WriteAllText($"out/indexes/{manifestName}.json", manifest);
Console.WriteLine("Finished!");
Console.WriteLine("Upload the contents of .\\out\\ to the folder on your webserver you specified.\nPress any key to exit.");
Console.ReadLine();
}
static bool DoesExist(string url)
{
try
{
WebClient wc = new WebClient();
string resp = wc.DownloadString(url);
return true;
}
catch (WebException)
{
return false;
}
}
}
}