/// <summary> /// Creates a deep copy of 'mod'. /// </summary> /// <param name="mod">The object it makes a copy of.</param> public ManagedMod(ManagedMod mod) { /* * Info */ this.title = mod.title; this.ID = mod.ID; this.URL = mod.URL; this.Version = mod.Version; this.guid = mod.guid; this.GamePath = mod.GamePath; this.ManagedFolderName = mod.ManagedFolderName; /* * General */ this.Enabled = mod.Enabled; this.Deployed = mod.Deployed; this.Method = mod.Method; this.PreviousMethod = mod.PreviousMethod; /* * SeparateBA2 */ this.archiveName = mod.archiveName; this.CurrentArchiveName = mod.CurrentArchiveName; this.Compression = mod.Compression; this.CurrentCompression = mod.CurrentCompression; this.Format = mod.Format; this.CurrentFormat = mod.CurrentFormat; /* * SeparateBA2 Frozen */ this.Freeze = mod.Freeze; this.Frozen = mod.Frozen; this.FrozenCompression = mod.FrozenCompression; this.FrozenFormat = mod.FrozenFormat; /* * Loose */ this.LooseFiles = new List <string>(mod.LooseFiles); this.RootFolder = mod.RootFolder; this.CurrentRootFolder = mod.CurrentRootFolder; }
/// <summary> /// Creates an new file out of the specified <see cref="EndianBinaryWriter"/>, optionally compressing the resulting file. /// </summary> /// <param name="outputPath">Filepath to which to write the file to.</param> /// <param name="stream"><see cref="MemoryStream"/> to create an archive out of.</param> /// <param name="compression">Optionally compress with Yaz0 or Yay0 compression.</param> public static void SaveFile(string outputPath, MemoryStream stream, ArchiveCompression compression = ArchiveCompression.Uncompressed) { if (string.IsNullOrEmpty(outputPath)) { throw new ArgumentNullException("filePath", "Cannot write archive to empty file path!"); } if (stream == null) { throw new ArgumentNullException("root", "Cannot write null EndianBinaryWriter to archive."); } MemoryStream compressedStream = new MemoryStream(); switch (compression) { case ArchiveCompression.Yay0: throw new NotImplementedException("Yay0 Compression not implemented."); //compressedStream = Yay0.Encode(uncompressedStream); //break; case ArchiveCompression.Yaz0: EndianBinaryWriter encoded = Yaz0.Encode(stream); encoded.Seek(0, SeekOrigin.Begin); encoded.BaseStream.CopyTo(compressedStream); break; case ArchiveCompression.Uncompressed: // Well, that was easy. compressedStream = stream; break; } compressedStream.Seek(0, SeekOrigin.Begin); using (var fileStream = File.Create(outputPath)) compressedStream.WriteTo(fileStream); }
/// <summary> /// Creates an archive out of the specified <see cref="VirtualFilesystemDirectory"/>, optionally compressing the resulting file. /// </summary> /// <param name="outputPath">Filepath to which to write the file to.</param> /// <param name="root"><see cref="VirtualFilesystemDirectory"/> to create an archive out of.</param> /// <param name="compression">Optionally compress with Yaz0 or Yay0 compression.</param> public static void WriteArchive(string outputPath, VirtualFilesystemDirectory root, ArchiveCompression compression = ArchiveCompression.Uncompressed) { if (string.IsNullOrEmpty(outputPath)) { throw new ArgumentNullException("filePath", "Cannot write archive to empty file path!"); } if (root == null) { throw new ArgumentNullException("root", "Cannot write null VirtualFilesystemDirectory to archive."); } Archive rarc = new Archive(); MemoryStream outputData = new MemoryStream(); // Create an archive structure from the given root and write it to file. Compression will be applied if specified. MemoryStream uncompressedStream = new MemoryStream(); using (EndianBinaryWriter fileWriter = new EndianBinaryWriter(uncompressedStream, Endian.Big)) { byte[] rawData = rarc.WriteFile(root); fileWriter.Write(rawData); fileWriter.Seek(0, SeekOrigin.Begin); fileWriter.BaseStream.CopyTo(outputData); } MemoryStream compressedStream = new MemoryStream(); switch (compression) { case ArchiveCompression.Yay0: throw new NotImplementedException("Yay0 Compression not implemented."); //compressedStream = Yay0.Encode(uncompressedStream); //break; case ArchiveCompression.Yaz0: EndianBinaryWriter encoded = Yaz0.Encode(uncompressedStream); encoded.Seek(0, SeekOrigin.Begin); encoded.BaseStream.CopyTo(compressedStream); break; case ArchiveCompression.Uncompressed: // Well, that was easy. compressedStream = uncompressedStream; break; } compressedStream.Seek(0, SeekOrigin.Begin); compressedStream.WriteTo(File.Create(outputPath)); }
/// <summary> /// Convert ArchiveCompression enum to string. /// </summary> private static string GetCompressionName(ArchiveCompression compression) { return(Enum.GetName(typeof(ArchiveCompression), (int)compression)); }
/// <summary> /// Creates an archive out of the specified <see cref="VirtualFilesystemDirectory"/>, optionally compressing the resulting file. /// </summary> /// <param name="outputPath">Filepath to which to write the file to.</param> /// <param name="root"><see cref="VirtualFilesystemDirectory"/> to create an archive out of.</param> /// <param name="compression">Optionally compress with Yaz0 or Yay0 compression.</param> public static void WriteArchive(string outputPath, VirtualFilesystemDirectory root, ArchiveCompression compression = ArchiveCompression.Uncompressed) { if (string.IsNullOrEmpty(outputPath)) throw new ArgumentNullException("filePath", "Cannot write archive to empty file path!"); if (root == null) throw new ArgumentNullException("root", "Cannot write null VirtualFilesystemDirectory to archive."); Archive rarc = new Archive(); MemoryStream outputData = new MemoryStream(); // Create an archive structure from the given root and write it to file. Compression will be applied if specified. MemoryStream uncompressedStream = new MemoryStream(); using (EndianBinaryWriter fileWriter = new EndianBinaryWriter(uncompressedStream, Endian.Big)) { byte[] rawData = rarc.WriteFile(root); fileWriter.Write(rawData); fileWriter.Seek(0, SeekOrigin.Begin); fileWriter.BaseStream.CopyTo(outputData); } MemoryStream compressedStream = new MemoryStream(); switch(compression) { case ArchiveCompression.Yay0: throw new NotImplementedException("Yay0 Compression not implemented."); //compressedStream = Yay0.Encode(uncompressedStream); //break; case ArchiveCompression.Yaz0: EndianBinaryWriter encoded = Yaz0.Encode(uncompressedStream); encoded.Seek(0, SeekOrigin.Begin); encoded.BaseStream.CopyTo(compressedStream); break; case ArchiveCompression.Uncompressed: // Well, that was easy. compressedStream = uncompressedStream; break; } compressedStream.Seek(0, SeekOrigin.Begin); compressedStream.WriteTo(File.Create(outputPath)); }