public override ArchiveBase GetArchive(Memory.Archive archive) { if (archive == Memory.Archives.ZZZ_MAIN || archive == Memory.Archives.ZZZ_OTHER) { var zzz = archive.ZZZ; if (FindFile(ref zzz) <= -1 || string.IsNullOrWhiteSpace(zzz)) { return(null); } if (File.Exists(zzz)) { archive.SetFilename(zzz); } return(!CacheTryGetValue(archive, out var ab) ? ArchiveZzz.Load(zzz) : ab); } if (CacheTryGetValue(archive, out var value)) { return(value); } GetArchive(archive, out var fI, out var fS, out StreamWithRangeValues fL); return(fI == null || fS == null || fL == null || fI.Length == 0 || fL.Length == 0 ? null : new ArchiveWorker(archive, fI, fS, fL)); }
protected void SetValues(Memory.Archive archive, params string[] filenames) { Memory.Log.WriteLine($"{nameof(StringsBase)}::{nameof(SetValues)} Archive= \"{archive}\", Files= {{{string.Join(", ", filenames)}}}"); Archive = archive; Filenames = filenames; }
//prevent two loads at the same time. #region Methods public static ArchiveBase Load(Memory.Archive path, bool skipList = false) { if (string.IsNullOrWhiteSpace(path)) { return(null); } lock (Locker) { if (CacheTryGetValue(path, out ArchiveBase value)) { return(value); } else { value = new ArchiveZzz(path, skipList); if (!value.IsOpen) { value = null; } if (value == null || string.IsNullOrWhiteSpace(path)) { return(null); } if (CacheTryAdd(value.GetPath() ?? path, value)) { } path.SetFilename(value.GetPath() ?? path); } return(value); } }
public static ArchiveBase Load(Memory.Archive archive) { if (archive.IsDir) { return(ArchiveWorker.Load(archive)); } if (archive.IsFile) { if (archive.IsFileArchive || archive.IsFileIndex || archive.IsFileList) { var a = new Memory.Archive(Path.GetFileNameWithoutExtension(archive), Path.GetDirectoryName(archive)); return(ArchiveWorker.Load(a)); } if (archive.IsZZZ) { return(ArchiveZzz.Load(archive)); } return(ArchiveWorker.Load(archive)); } return(null); }
public void GetArchive(Memory.Archive archive, out byte[] fi, out byte[] fs, out byte[] fl) { Memory.Log.WriteLine($"{nameof(ArchiveBase)}::{nameof(GetArchive)} - Reading: {archive.FI}, {archive.FS}, {archive.FL}"); fi = GetBinaryFile(archive.FI); fs = GetBinaryFile(archive.FS, cache: true); fl = GetBinaryFile(archive.FL); }
public void GetArchive(Memory.Archive archive, out StreamWithRangeValues fi, out ArchiveBase fs, out StreamWithRangeValues fl) { Memory.Log.WriteLine($"{nameof(ArchiveBase)}::{nameof(GetArchive)} - Reading: {archive.FI}, {archive.FS}, {archive.FL}"); fi = GetStreamWithRangeValues(archive.FI); fs = this; fl = GetStreamWithRangeValues(archive.FL); }
public FF8StringReference(Memory.Archive archive, string filename, long offset, ushort length = 0, Settings settings = Settings.None) { Archive = archive; Filename = filename; Offset = offset; ReadLength = length; StringSettings = settings; }
/// <summary> /// Saves the active archive and file list. /// </summary> /// <param name="path">Memory.Archive</param> /// <param name="skiplist">If list generation is unneeded you can skip it by setting true</param> public ArchiveWorker(Memory.Archive path, bool skiplist = false) { _path = path; if (!skiplist) { FileList = ProduceFileLists(); } }
protected void SetValues(Memory.Archive archive, params string[] filenames) { Debug.WriteLine("Task={0}, Thread={2}, [Files={1}]", Task.CurrentId, string.Join(", ", filenames), Thread.CurrentThread.ManagedThreadId); Archive = archive; Filenames = filenames; }
public override ArchiveBase GetArchive(Memory.Archive archive) { lock (GetArchiveLock) { if (!CacheTryGetValue(archive, out ArchiveBase value)) { return(ArchiveWorker.Load(archive, GetStreamWithRangeValues(archive.FI), this, GetStreamWithRangeValues(archive.FL))); } return(value); } }
/// <summary> /// Saves the active archive and file list. /// </summary> /// <param name="path">Memory.Archive</param> /// <param name="skiplist">If list generation is unneeded you can skip it by setting true</param> public ArchiveWorker(Memory.Archive path, bool skiplist = false) { if (Directory.Exists(path)) { isDir = true; } _path = path; if (!skiplist) { FileList = ProduceFileLists(); } }
private ArchiveWorker(Memory.Archive archive, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false) { ArchiveMap = new ArchiveMap(fI, fL, fS.GetMaxSize(archive)); Archive = archive; FsArchive = fS; //FS = null; if (!skipList) { GetListOfFiles(); } IsOpen = true; }
public override ArchiveBase GetArchive(Memory.Archive archive) { byte[] fI = GetBinaryFile(archive.FI); byte[] fS = GetBinaryFile(archive.FS); byte[] fL = GetBinaryFile(archive.FL); if (fI == null || fS == null || fL == null || fI.Length == 0 || fS.Length == 0 || fL.Length == 0) { return(null); } return(new ArchiveWorker(fI, fS, fL) { _path = archive }); }
/// <summary> /// Load Archive with out storing FS in byte[] works for archive that aren't compressed. /// </summary> /// <param name="path">Archive file archive.</param> /// <param name="fI">Stream containing the FI file</param> /// <param name="fS">Archive where the FS file is.</param> /// <param name="fL">Stream containing the FL file</param> /// <param name="skipList">Skip generating list of files</param> /// <returns>ArchiveWorker</returns> public static ArchiveBase Load(Memory.Archive path, StreamWithRangeValues fI, ArchiveBase fS, StreamWithRangeValues fL, bool skipList = false) { if (CacheTryGetValue(path, out var value)) { return(value); } value = new ArchiveWorker(path, fI, fS, fL, skipList); if (!value.IsOpen) { value = null; } if (CacheTryAdd(path, value)) { } return(value); }
private ArchiveZzz(Memory.Archive archive, bool skipList = false) { ArchiveBase tempArchive = null; ParentPath = FindParentPath(archive); if (ParentPath != null && ParentPath.Count > 0) { foreach (Memory.Archive p in ParentPath) { if (p.IsDir) { tempArchive = ArchiveBase.Load(p); } else if (tempArchive != null) { throw new Exception("zzz shouldn't be inside an archive."); } } } Archive = archive; if (tempArchive != null) { archive.SetFilename(tempArchive.GetListOfFiles() .FirstOrDefault(x => x.IndexOf(archive.ZZZ, StringComparison.OrdinalIgnoreCase) > 0)); } Memory.Log.WriteLine($"{nameof(ArchiveZzz)}:: opening archiveFile: {archive}"); if (string.IsNullOrWhiteSpace(archive)) { return; } using (BinaryReader br = Open()) { if (br == null) { return; } ArchiveMap = Header.Load(br); } if (!skipList) { GetListOfFiles(); } IsOpen = true; }
public static ArchiveBase Load(Memory.Archive path, bool skipList = false) { if (path.IsZZZ) { return(ArchiveZzz.Load(path, skipList)); } if (CacheTryGetValue(path, out var value)) { return(value); } value = new ArchiveWorker(path, skipList); if (!value.IsOpen) { value = null; } if (CacheTryAdd(path, value)) { } return(value); }
/// <summary> /// Saves the active archive and file list. /// </summary> /// <param name="archive">Memory.Archive</param> /// <param name="skipList">If list generation is unneeded you can skip it by setting true</param> private ArchiveWorker(Memory.Archive archive, bool skipList = false) { if (archive.IsDir) { Memory.Log.WriteLine($"{nameof(ArchiveWorker)}:: opening directory: {archive}"); IsDir = true; } else { Memory.Log.WriteLine($"{nameof(ArchiveWorker)}:: opening archiveFile: {archive}"); } Archive = archive; ParentPath = FindParentPath(archive); ArchiveBase tempArchive = null; if (ParentPath != null && ParentPath.Count > 0) { foreach (var p in ParentPath) { if (tempArchive != null) { tempArchive = tempArchive.GetArchive(p); } else if (p.IsDir || p.IsFile) { tempArchive = ArchiveBase.Load(p); } } } if (tempArchive != null) { tempArchive.GetArchive(archive, out var fi, out FsArchive, out var fl); ArchiveMap = new ArchiveMap(fi, fl, tempArchive.GetMaxSize(archive)); } if (!skipList) { GetListOfFiles(); } IsOpen = true; }
protected StringsBase(Memory.Archive archive, params string[] filenames) { Archive = archive; Filenames = filenames; Init(); }
public override ArchiveBase GetArchive(Memory.Archive archive) { return(new ArchiveWorker(GetBinaryFile(archive.FI), GetBinaryFile(archive.FS), GetBinaryFile(archive.FL))); }
public virtual int GetMaxSize(Memory.Archive archive) { using (var s = GetStreamWithRangeValues(archive.FS)) return(checked ((int)s.Size)); }
/// <summary> /// Generate archive worker and get file /// </summary> /// <param name="archive">which archive you want to read from</param> /// <param name="fileName">name of file you want to recieve</param> /// <returns>Uncompressed binary file data</returns> public static byte[] GetBinaryFile(Memory.Archive archive, string fileName) { ArchiveWorker tmp = new ArchiveWorker(archive, true); return(tmp.GetBinaryFile(fileName)); }
public abstract ArchiveBase GetArchive(Memory.Archive archive);