/// <summary> /// Loads an existing DownloadFile from a remote CDN /// </summary> /// <param name="client"></param> /// <param name="ekey"></param> public DownloadFile(CDNClient client, MD5Hash ekey) : this() { string url = Helpers.GetCDNUrl(ekey.ToString(), "data"); using (var stream = client.OpenStream(url).Result) using (var bt = new BlockTableStreamReader(stream)) Read(bt); }
/// <summary> /// Loads an existing EncodingFile from a remote CDN /// </summary> /// <param name="client"></param> /// <param name="ekey"></param> /// <param name="partial">Only reads the mandatory information. Prevents write support</param> public EncodingFile(CDNClient client, MD5Hash ekey, bool partial = false) : this() { Partial = partial; string url = Helpers.GetCDNUrl(ekey.ToString(), "data"); using (var stream = client.OpenStream(url).Result) using (var bt = new BlockTableStreamReader(stream)) Read(bt); }
/// <summary> /// Loads an existing DownloadSizeFile /// </summary> /// <param name="path">BLTE encoded file path</param> public DownloadSizeFile(string path) : this() { if (!File.Exists(path)) { throw new FileNotFoundException("Unable to open DownloadSizeFile", path); } using (var fs = File.OpenRead(path)) using (var bt = new BlockTableStreamReader(fs)) Read(bt); }
/// <summary> /// Loads an existing InstallFile /// </summary> /// <param name="path">BLTE encoded file path</param> public InstallFile(string path) : this() { if (!File.Exists(path)) { throw new FileNotFoundException("Unable to open InstallFile", path); } FilePath = path; using (var fs = File.OpenRead(path)) using (var bt = new BlockTableStreamReader(fs)) Read(bt); }
/// <summary> /// Loads an existing EncodingFile /// </summary> /// <param name="path">BLTE encoded file path</param> /// <param name="partial">Only reads the mandatory information. Prevents write support</param> public EncodingFile(string path, bool partial = false) : this() { if (!File.Exists(path)) { throw new FileNotFoundException("Unable to open EncodingFile", path); } Partial = partial; using (var fs = File.OpenRead(path)) using (var bt = new BlockTableStreamReader(fs)) Read(bt); }
public async Task AttemptReconstruction(UnshippedBuild model) { Directory.CreateDirectory(Consts.TempDir); if (!await DownloadFile(model.Encoding, Helpers.GetTempPath(model.Encoding))) { return; } if (!await DownloadFile(model.Install, Helpers.GetTempPath(model.Install))) { return; } Console.WriteLine($"Processing Encoding {model.Encoding}"); // these files are less important await DownloadFile(model.Download, Helpers.GetTempPath(model.Download)); await DownloadFile(model.Size, Helpers.GetTempPath(model.Size)); // load encoding file using var fs = File.OpenRead(Helpers.GetTempPath(model.Encoding)); using var blte = new BlockTableStreamReader(fs); var eSize = blte.Length; var ecSize = fs.Length; var encoding = new EncodingFile(blte); // extract all binaries await ExtractFiles(model, encoding); // attempt to find and download root if (await TryGetRoot(model, encoding)) { await DownloadFile(model.Root, Helpers.GetTempPath(model.Root)); } // generate buildconfig ConfigGenerator.BuildConfig(model, encoding, eSize, ecSize); Directory.Move(Consts.TempDir, model.GetDirectoryName()); Console.WriteLine($"{model.Encoding} moved to {model.GetDirectoryName()}"); }
private async Task <bool> TryGetRoot(UnshippedBuild model, EncodingFile encoding) { // find the zlib espec only used for a few files // namely root and world/liquid.tex var espec = encoding.ESpecStringTable.IndexOf("z"); // attemp to filter out just the root with min size var files = encoding.EKeyEntries .Where(x => x.ESpecIndex == espec && x.CompressedSize > Consts.MinRootSize) .ToArray(); if (files.Length == 0) { return(false); } // read the magic of each file var buffer = new byte[4]; for (var i = 0; i < files.Length; i++) { var endpoint = Helpers.GetCDNUrl(files[i].EKey.ToString(), "data"); var stream = await Client.OpenStream(endpoint, 0, 0x1000); // arbitary peek size var blte = new BlockTableStreamReader(stream); blte.Read(buffer); if (BitConverter.ToUInt32(buffer) == Consts.RootMagic) { model.Root = files[i].EKey.ToString(); return(true); } } return(false); }
/// <summary> /// Loads an existing DownloadFile /// </summary> /// <param name="stream"></param> public DownloadFile(BlockTableStreamReader stream) : this() { Read(stream); }
/// <summary> /// Loads an existing InstallFile /// </summary> /// <param name="stream"></param> public InstallFile(BlockTableStreamReader stream) : this() { Read(stream); }
/// <summary> /// Loads an existing EncodingFile /// </summary> /// <param name="stream"></param> /// <param name="partial">Only reads the mandatory information. Prevents write support</param> public EncodingFile(BlockTableStreamReader stream, bool partial = false) : this() { Partial = partial; Read(stream); }