コード例 #1
0
 private static bool ExtractResource(string cachePath, uint index, IReadOnlyList<string> args)
 {
     if (args.Count != 5)
         return false;
     uint compressedSize;
     if (!uint.TryParse(args[3], NumberStyles.HexNumber, null, out compressedSize))
         return false;
     var outPath = args[4];
     try
     {
         using (var stream = File.OpenRead(cachePath))
         {
             var cache = new ResourceCache(stream);
             using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
             {
                 cache.Decompress(stream, (int)index, compressedSize, outStream);
                 Console.WriteLine("Wrote 0x{0:X} bytes to {1}.", outStream.Position, outPath);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed to extract resource: {0}", ex.Message);
     }
     return true;
 }
コード例 #2
0
 private static bool ImportResource(string cachePath, uint index, IReadOnlyList<string> args)
 {
     if (args.Count != 4)
         return false;
     var inPath = args[3];
     try
     {
         using (var stream = File.Open(cachePath, FileMode.Open, FileAccess.ReadWrite))
         {
             var cache = new ResourceCache(stream);
             var data = File.ReadAllBytes(inPath);
             var compressedSize = cache.Compress(stream, (int)index, data);
             Console.WriteLine("Imported 0x{0:X} bytes.", data.Length);
             Console.WriteLine("Compressed size = 0x{0:X}", compressedSize);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed to import resource: {0}", ex.Message);
     }
     return true;
 }