/// <summary> /// Adds a file, located in <paramref name="fileName"/>, to <see cref="Mythic.Package.MythicPackageBlock.Files"/> table. /// </summary> /// <param name="fileName">Path to a file on HD.</param> /// <param name="innerFolder">Relative folder within KR (destination).</param> /// <param name="flag">Compression type.</param> public void AddFile(string fileName, string innerFolder, CompressionFlag flag) { if (String.IsNullOrEmpty(fileName)) { throw new ArgumentException("fileName"); } if (IsFull) { throw new BlockFullException(); } MythicPackageFile index = new MythicPackageFile(fileName, innerFolder, flag); index.Parent = this; index.Index = m_Files.Count; index.Added = true; m_FileCount += 1; m_Files.Add(index); m_Parent.Header.FileCount += 1; }
/// <summary> /// Initializes a new instance from <paramref name="reader"/>. /// </summary> /// <param name="reader">Binary file (.uop source).</param> /// <param name="parent">Parent package.</param> public MythicPackageBlock(BinaryReader reader, MythicPackage parent) { m_Parent = parent; m_FileCount = reader.ReadInt32(); m_NextBlock = reader.ReadInt64(); MythicPackageFile file; int index = 0; do { file = new MythicPackageFile(reader, this); file.Index = index++; if (file.DataBlockAddress != 0) { m_Files.Add(file); } UpdateProgress(parent.Blocks.Count * parent.Header.BlockSize + index, parent.Header.FileCount); }while (index < m_Parent.Header.BlockSize); }
/// <summary> /// Replace the existing files inside the current package with the one with the same names provided on the files list. /// </summary> /// <param name="filesList">List of the files to replace</param> /// <param name="rootDir">Root directory of the file structure. Used to create the relative path for the files to add. Only necessary if <paramref name="addMissing"/> is true.</param> /// <param name="addMissing">Do we need to add the files that are not present in the current package?</param> /// <param name="flag">Compression type.</param> /// <param name="backupFolder">if a backup folder is specified, all files that needs replacing will be extracted there first.</param> public void ReplaceFiles(List <string> filesList, string rootDir = "", bool addMissing = false, CompressionFlag flag = CompressionFlag.Zlib, string backupFolder = null) { // create a queue for the files Queue <string> q = new Queue <string>(filesList); // keep looping until the queue is empty while (q.Count > 0) { // get the file from the list and make sure is lower case string currFile = q.Dequeue().ToLower(); // search for a file with the current file name MythicPackageFile found = (from b in Blocks from f in b.Files where !string.IsNullOrEmpty(f.FileName) && Path.GetFileName(f.FileName) == Path.GetFileName(currFile) select f).FirstOrDefault(); // if we found a file, we execute the replace if (found != null) { // if a backup is required, we unpack the current file first if (!string.IsNullOrEmpty(backupFolder)) { found.Unpack(backupFolder, true); } // replace the file found.Replace(currFile, found.FilePath, flag); } // if the file doesn't exit, we add it to the archive (if addMissing is true) else if (addMissing) { AddFile(currFile, GetRelativePath(rootDir, currFile)); } } }
/// <summary> /// Constucts new file descriptor. /// </summary> /// <param name="fileName">Path to the mythic package.</param> /// <param name="file">Information about file in mythic package.</param> public FileDescriptor(string fileName, MythicPackageFile file) { m_FileName = fileName; m_File = file; }