private static void ReplaceDebugger(GameLocationInfo gameLocation) { String sourceDirectory = Path.GetFullPath("Debugger"); if (!Directory.Exists(sourceDirectory)) { throw new DirectoryNotFoundException("Debugger's directory was not found: " + sourceDirectory); } Console.WriteLine("Copy a debugger..."); String targetDirectory = Path.Combine(gameLocation.RootDirectory, "Debugger"); Directory.CreateDirectory(targetDirectory); foreach (String sourcePath in Directory.EnumerateFileSystemEntries(sourceDirectory, "*", SearchOption.AllDirectories)) { if (!sourcePath.StartsWith(sourceDirectory)) { throw new InvalidDataException(sourcePath); } String relativePath = sourcePath.Substring(sourceDirectory.Length); String targetPath = targetDirectory + relativePath; if ((File.GetAttributes(sourcePath) & FileAttributes.Directory) == FileAttributes.Directory) { Directory.CreateDirectory(targetPath); } else { File.Copy(sourcePath, targetPath, true); Console.WriteLine("Copied: " + targetPath); } } Console.WriteLine("The debugger was copied!"); }
private static void ExtractFiles(GameLocationInfo gameLocation, GZipStream input, BinaryReader br, ref Int64 leftSize, ConsoleProgressHandler progressHandler) { Dictionary <Int16, String> pathMap = new Dictionary <Int16, String>(400); UInt16 idMask = 1 << 15; Byte[] buff = new Byte[64 * 1024]; while (leftSize > 0) { Int64 uncompressedSize = br.ReadUInt32(); DateTime writeTimeUtc = new DateTime(br.ReadInt64(), DateTimeKind.Utc); Boolean hasPlatform = false; String[] pathParts = new String[br.ReadByte() + 1]; pathParts[0] = gameLocation.RootDirectory; for (Int32 i = 1; i < pathParts.Length; i++) { String part = null; Int16 id = br.ReadInt16(); if ((id & idMask) == idMask) { id = (Int16)(id & ~idMask); Int32 bytesNumber = br.ReadByte(); Int32 readed = 0; while (bytesNumber > 0) { readed = br.Read(buff, readed, bytesNumber); bytesNumber -= readed; } part = Encoding.UTF8.GetString(buff, 0, readed); pathParts[i] = part; pathMap.Add(id, part); } else { part = pathMap[id]; pathParts[i] = part; } if (part == "{PLATFORM}") { hasPlatform = true; } } String outputPath = Path.Combine(pathParts); if (hasPlatform) { if (Directory.Exists(gameLocation.ManagedPathX64)) { if (Directory.Exists(gameLocation.ManagedPathX86)) { String x64 = outputPath.Replace("{PLATFORM}", "x64"); String x86 = outputPath.Replace("{PLATFORM}", "x86"); ExtractFile(input, uncompressedSize, buff, writeTimeUtc, progressHandler, x64, x86); } else { outputPath = outputPath.Replace("{PLATFORM}", "x86"); ExtractFile(input, uncompressedSize, buff, writeTimeUtc, progressHandler, outputPath); } } else if (Directory.Exists(gameLocation.ManagedPathX86)) { outputPath = outputPath.Replace("{PLATFORM}", "x86"); ExtractFile(input, uncompressedSize, buff, writeTimeUtc, progressHandler, outputPath); } else { progressHandler.IncrementProcessedSize(uncompressedSize); } } else { ExtractFile(input, uncompressedSize, buff, writeTimeUtc, progressHandler, outputPath); } leftSize -= uncompressedSize; } }