Rewrite launcher resource fetching to avoid Dictionary

This commit is contained in:
UnknownShadow200 2017-09-11 17:48:41 +10:00
parent 09e584b61c
commit f5bd452765
5 changed files with 55 additions and 42 deletions

View File

@ -40,7 +40,7 @@ namespace Launcher.Gui.Screens {
failed = true;
if (!fetcher.Done) return;
if (ResourceList.Files.Count > 0) {
if (ResourceList.GetFetchFlags() != 0) {
ResourcePatcher patcher = new ResourcePatcher(fetcher, drawer);
patcher.Run();
}

View File

@ -27,21 +27,19 @@ namespace Launcher.Patcher {
}
void CheckTexturePack() {
ushort flags = 0;
foreach (var entry in ResourceList.Files)
flags |= entry.Value;
byte flags = ResourceList.GetFetchFlags();
if (flags != 0) AllResourcesExist = false;
if ((flags & ResourceList.cMask) != 0) {
if ((flags & ResourceList.mask_classic) != 0) {
DownloadSize += 291/1024f; ResourcesCount++;
}
if ((flags & ResourceList.mMask) != 0) {
if ((flags & ResourceList.mask_modern) != 0) {
DownloadSize += 4621/1024f; ResourcesCount++;
}
if ((flags & ResourceList.tMask) != 0) {
if ((flags & ResourceList.mask_terrain) != 0) {
DownloadSize += 7/1024f; ResourcesCount++;
}
if ((flags & ResourceList.gMask) != 0) {
if ((flags & ResourceList.mask_gui) != 0) {
DownloadSize += 21/1024f; ResourcesCount++;
}
}
@ -84,9 +82,15 @@ namespace Launcher.Patcher {
reader.Extract(src);
}
bool ShouldProcessZipEntry(string filename) {
string name = ResourceList.GetFile(filename);
ResourceList.Files.Remove(name);
bool ShouldProcessZipEntry(string filename) {
string name = ResourceList.GetFile(filename);
for (int i = 0; i < ResourceList.Filenames.Length; i++) {
if (ResourceList.FilesExist[i]) continue;
if (name != ResourceList.Filenames[i]) continue;
ResourceList.FilesExist[i] = true;
break;
}
return false;
}

View File

@ -29,21 +29,17 @@ namespace Launcher.Patcher {
const string musicUri = "http://s3.amazonaws.com/MinecraftResources/music/";
const string newMusicUri = "http://s3.amazonaws.com/MinecraftResources/newmusic/";
ushort flags;
public void DownloadItems(AsyncDownloader downloader, Action<string> setStatus) {
this.downloader = downloader;
this.downloader = downloader;
byte fetchFlags = ResourceList.GetFetchFlags();
flags = 0;
foreach (var entry in ResourceList.Files)
flags |= entry.Value;
if ((flags & ResourceList.cMask) != 0)
if ((fetchFlags & ResourceList.mask_classic) != 0)
QueueItem(jarClassicUri, "classic jar");
if ((flags & ResourceList.mMask) != 0)
if ((fetchFlags & ResourceList.mask_modern) != 0)
QueueItem(jar162Uri, "1.6.2 jar");
if ((flags & ResourceList.gMask) != 0)
if ((fetchFlags & ResourceList.mask_gui) != 0)
QueueItem(pngGuiPatchUri, "gui.png patch");
if ((flags & ResourceList.tMask) != 0)
if ((fetchFlags & ResourceList.mask_terrain) != 0)
QueueItem(pngTerrainPatchUri, "terrain.png patch");
DownloadMusicFiles();

View File

@ -4,29 +4,43 @@ using System.Collections.Generic;
namespace Launcher.Patcher {
public sealed class ResourceList {
public static class ResourceList {
public const byte mask_classic = 0x01;
public const byte mask_modern = 0x02;
public const byte mask_gui = 0x04;
public const byte mask_terrain = 0x08;
public const ushort cMask = 0xF000;
public const ushort mMask = 0x0F00;
public const ushort gMask = 0x00F0;
public const ushort tMask = 0x000F;
public static Dictionary<string, ushort> Files = new Dictionary<string, ushort>() {
public static string[] Filenames = new string[] {
// classic jar files
{ "char.png", cMask }, { "clouds.png", cMask },
{ "default.png", cMask }, { "particles.png", cMask },
{ "rain.png", cMask }, { "terrain.png", cMask | tMask },
{ "gui_classic.png", cMask }, { "icons.png", cMask },
//{ "arrows.png", cMask }, { "sign.png", cMask },
{ "creeper.png", cMask }, { "pig.png", cMask },
{ "sheep.png", cMask }, { "sheep_fur.png", cMask },
{ "skeleton.png", cMask }, { "spider.png", cMask },
{ "zombie.png", cMask },
// Other files
{ "snow.png", mMask }, { "chicken.png", mMask },
{ "animations.png", mMask }, { "gui.png", gMask },
"char.png", "clouds.png", "default.png", "particles.png",
"rain.png", "gui_classic.png", "icons.png", "terrain.png",
"creeper.png", "pig.png", "sheep.png", "sheep_fur.png",
"skeleton.png", "spider.png", "zombie.png", // "arrows.png", "sign.png"
// other files
"snow.png", "chicken.png", "animations.png", "gui.png",
};
public static byte[] FileMasks = new byte[] {
// classic jar files
mask_classic, mask_classic, mask_classic, mask_classic,
mask_classic, mask_classic, mask_classic, mask_classic | mask_terrain,
mask_classic, mask_classic, mask_classic, mask_classic,
mask_classic, mask_classic, mask_classic, // cMask, cMask
// other files
mask_modern, mask_modern, mask_modern, mask_gui,
};
public static bool[] FilesExist = new bool[Filenames.Length];
public static byte GetFetchFlags() {
byte flags = 0;
for (int i = 0; i < Filenames.Length; i++) {
if (FilesExist[i]) continue;
flags |= FileMasks[i];
}
return flags;
}
public static string[] DigSounds = new string[] { "Acloth1", "Acloth2", "Acloth3", "Acloth4", "Bglass1",
"Bglass2", "Bglass3", "Agrass1", "Agrass2", "Agrass3", "Agrass4", "Agravel1", "Agravel2",
"Agravel3", "Agravel4", "Asand1", "Asand2", "Asand3", "Asand4", "Asnow1", "Asnow2", "Asnow3",

View File

@ -132,8 +132,7 @@ namespace Launcher {
static bool ParseEscaped(string json, ref int index, StringBuilder s) {
char c = json[index++];
if (c == '\\') { s.Append('\\'); return true; }
if (c == '"') { s.Append('"'); return true; }
if (c == '/' || c == '\\' || c == '"') { s.Append(c); return true; }
if (c != 'u') { s.Append('?'); return true; }
int remaining = json.Length - index;