| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace System.Fire.Container {
- public partial class ContainerList {
- /// <summary>
- /// Exports an file from the container to the given path
- /// </summary>
- /// <param name="FileIndex">The container file index</param>
- /// <param name="ExportPath">Path to export the file to</param>
- /// <returns>Returns true if the export was successfull</returns>
- public bool ExportFile(int FileIndex, string ExportPath) {
- return this.ExportFile(this._files[FileIndex], ExportPath);
- }
- /// <summary>
- /// Exports an file from the container to the given path
- /// </summary>
- /// <param name="File">The container file index</param>
- /// <param name="ExportPath">Path to export the file to</param>
- /// <returns>Returns true if the export was successfull</returns>
- public bool ExportFile(ContainerFile File, string ExportPath) {
- FileInfo fi = new FileInfo(ExportPath);
- FileAttributes fa = new DirectoryInfo(fi.DirectoryName).Attributes;
- if ((fa | FileAttributes.ReadOnly) == fa) {
- System.Diagnostics.Debug.WriteLine(fi.DirectoryName + " is ReadOnly");
- return false;
- }
- if ((fa | FileAttributes.Hidden) == fa) {
- System.Diagnostics.Debug.WriteLine(fi.DirectoryName + " is Hidden");
- }
- if (!Directory.Exists(fi.DirectoryName))
- Directory.CreateDirectory(fi.DirectoryName);
- if (System.IO.File.Exists(ExportPath))
- System.IO.File.Delete(ExportPath);
- FileStream fs = new FileStream(ExportPath, FileMode.CreateNew);
- BinaryWriter bw = new BinaryWriter(fs);
- //byte Group = 0, Container = 0;
- //ushort Pos = 0;
- long size = 0;
- for (int i = 0, c = File.NumChunks; i < c; i++) {
- //File.GetChunk(i, ref Group, ref Container, ref Pos);
- byte[] b = this.ReadChunk(File.ChunkPos, i);
- if (size + b.Length > File.Size) {
- bw.Write(b.Take((int)(File.Size - size)).ToArray());
- size += File.Size - size;
- } else {
- bw.Write(b);
- size += b.Length;
- }
- }
- bw.Close();
- return true;
- }
- }
- }
|