Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ckmExtractor
- {
- class Program
- {
- private static string FileName = "";
- private static void Main(string[] args)
- {
- if (args.Length > 0)
- FileName = args[0];
- while (string.IsNullOrWhiteSpace(FileName) || !FileName.EndsWith(".ckm"))
- {
- Console.WriteLine("Specify CKM file (you may obtain it at http://steamworkshopdownloader.com/):");
- FileName = Console.ReadLine();
- }
- Console.WriteLine("Starting extraction ...");
- Extract(FileName);
- Console.WriteLine("OK!");
- Console.ReadLine();
- }
- public static void Extract(string fileName)
- {
- var fs = new StreamReader(fileName);
- var br = new BinaryReader(fs.BaseStream);
- var len = br.ReadInt32();
- Console.WriteLine("BSA length is " + len);
- Console.WriteLine("Extracting bsa ...");
- cpyfile(br, Path.ChangeExtension(fileName, "bsa"), len);
- len = br.ReadInt32();
- if (len == 0)
- len = (int) (new FileInfo(FileName).Length - br.BaseStream.Position);
- else
- Console.WriteLine("! Unexpected non-zero value. Don`t trust this program`s results, report author about this error !");
- Console.WriteLine("ESP length is " + len);
- Console.WriteLine("Extracting esp ...");
- cpyfile(br, Path.ChangeExtension(fileName, "esp"), len);
- fs.Close();
- }
- public static void cpyfile(BinaryReader from, string fileName, int bytes)
- {
- var fs = new StreamWriter(fileName);
- var bw = new BinaryWriter(fs.BaseStream);
- int readBytes = 0;
- do
- {
- var bts = from.ReadBytes(Math.Min(4096, bytes - readBytes));
- readBytes += bts.Length;
- bw.Write(bts);
- } while (readBytes < bytes);
- fs.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement