static public bool CompressKom(string dir, string filename) { if (System.IO.Directory.Exists(dir) == false) { return(false); } Komfile kom = new Komfile(); string[] files = System.IO.Directory.GetFiles(dir, "*", System.IO.SearchOption.AllDirectories); foreach (string file in files) { if (file.Contains(".svn\\") == false) { string key = System.IO.Path.GetFileName(file); if (kom.subfiles.ContainsKey(key) == false) { kom.Add(key, Kom2SubFile.ReadSubFileFromFile(file), true); } } } if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(filename)) == false) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename)); } kom.Save(filename); kom.Close(); return(true); }
static public bool Equals(Kom2SubFile x, Kom2SubFile y) { if (x.Adler32 != y.Adler32 || x.Size != y.Size || x.FileTime != y.FileTime || x.CompressedSize != y.CompressedSize) { return(false); } return(true); }
public bool Add(string filename, Kom2SubFile subfile, bool overwrite) { if (subfiles.ContainsKey(filename)) { if (overwrite == false) { return(false); } subfiles.Remove(filename); } subfiles.Add(filename, subfile); return(true); }
static public bool Equals(Komfile x, Komfile y) { if (x.Adler32 != y.Adler32 || x.HeaderSize != y.HeaderSize || x.FileTime != y.FileTime || x.Subfiles.Count != y.Subfiles.Count) { return(false); } foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in x.Subfiles) { if (y.Subfiles.ContainsKey(KeyValue.Key) == false) { return(false); } if (Kom2SubFile.Equals(KeyValue.Value, y.Subfiles[KeyValue.Key]) == false) { return(false); } } return(true); }
public bool Open(string filename) { System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); bool re = true; try { byte[] magicbyte = reader.ReadBytes(52); string magicstring = System.Text.ASCIIEncoding.ASCII.GetString(magicbyte).Trim('\0'); uint size = reader.ReadUInt32(); bool compressed = true; if (reader.ReadUInt32() == 0) { compressed = false; } switch (magicstring) { case "KOG GC TEAM MASSFILE V.0.3.": komtype = EKomType.newkom; filetime = reader.ReadUInt32(); adler32 = reader.ReadUInt32(); header_size = reader.ReadUInt32(); System.Xml.XmlDocument headerxml = new System.Xml.XmlDocument(); byte[] header_raw = reader.ReadBytes((int)header_size); if (header_raw[0] != '<' || header_raw[1] != '?' || header_raw[2] != 'x' || header_raw[3] != 'm' || header_raw[4] != 'l') { if (ecb == null) { throw new EncryptedKomException(); } byte[] data = (byte[])header_raw.Clone(); ecb.Decrypt(data, 0, header_raw, 0, (int)header_size); komtype = EKomType.encrypt; } string xmlstring = System.Text.ASCIIEncoding.ASCII.GetString(header_raw); headerxml.LoadXml(xmlstring); System.Xml.XmlNodeList files = headerxml.SelectNodes("Files/File"); UInt32 offset = OffsetStart + header_size; foreach (System.Xml.XmlElement file in files) { string key = file.GetAttribute("Name"); Kom2SubFile subfile = Kom2SubFile.ReadSubFileFromKom(ecb, filename, file, offset); offset += subfile.CompressedSize; subfiles.Add(key, subfile); } break; case "KOG GC TEAM MASSFILE V.0.1.": case "KOG GC TEAM MASSFILE V.0.2.": komtype = EKomType.oldkom; for (int i = 0; i < size; i++) { string key = System.Text.ASCIIEncoding.ASCII.GetString(reader.ReadBytes(60)).Trim('\0'); Kom2SubFile subfile = Kom2SubFile.ReadSubFileFromOldKom(filename, reader, 60 + size * 72); if (key != "crc.xml") { subfiles.Add(key, subfile); } } break; default: re = false; break; } } catch (System.Exception ex) { komtype = EKomType.notkom; re = false; } stream.Close(); return(re); }