/// <summary> /// Replaces this file with another. /// </summary> /// <param name="fileName">Path to the file on HD.</param> /// <param name="packageFolder">Relative folder within KR.</param> /// <param name="flag">Compression type.</param> public void Replace(string fileName, string packageFolder, CompressionFlag flag) { m_FileName = Path.Combine(packageFolder, Path.GetFileName(fileName)).ToLower(); m_FileHash = HashDictionary.HashFileName(m_FileName); m_SourceFileName = fileName; m_Compression = flag; m_DataBlockLength = 0; m_DataBlockHash = 0; Modified = true; }
/// <summary> /// Checks if hash of <paramref name="keyword"/> is equal to <see cref="Mythic.Package.MythicPackageFile.FileHash"/>. /// </summary> /// <param name="hash">Hash of the <paramref name="keyword"/></param> /// <param name="keyword">Word or a phrase.</param> /// <returns>If <paramref name="keyword"/> equals to <see cref="Mythic.Package.MythicPackageFile.FileHash"/>.</returns> public bool SearchHash(ulong hash, string keyword) { if (m_FileName == null && m_FileHash == hash) { HashDictionary.Set(hash, keyword); m_FileName = keyword; return(true); } return(false); }
/// <summary> /// Checks if hash of <paramref name="keyword"/> is equal to <see cref="Mythic.Package.MythicPackageFile.FileHash"/>. /// </summary> /// <param name="hash">Hash of the <paramref name="keyword"/></param> /// <param name="keyword">Word or a phrase.</param> /// <returns>If <paramref name="keyword"/> equals to <see cref="Mythic.Package.MythicPackageFile.FileHash"/>.</returns> public bool SearchHash(ulong hash, char[] keyword) { if (m_FileName == null && m_FileHash == hash) { String name = new String(keyword); HashDictionary.Set(hash, name); m_FileName = name; return(true); } return(false); }
/// <summary> /// Search the exact file name inside the UOP file /// </summary> /// <param name="fileName">EXACT file name to search</param> /// <returns>Index of the <see cref="Mythic.Package.MythicPackageFile"/> in <see cref="Mythic.Package.MythicPackageBlock.Files"/> table.</returns> public SearchResult SearchExactFileName(string fileName) { foreach (MythicPackageBlock block in m_Blocks) { foreach (MythicPackageFile file in block.Files) { if (file.FileHash == HashDictionary.HashFileName(fileName)) { return(new SearchResult(block.Index, file.Index)); } } } return(SearchResult.NotFound); }
/// <summary> /// Search the exact file name inside the UOP file /// </summary> /// <param name="fileName">EXACT file name to search</param> /// <returns>Index of the <see cref="MythicPackageFile"/> in <see cref="MythicPackageBlock.Files"/> table.</returns> public SearchResult SearchExactFileName(string fileName) { // search for the exact file name MythicPackageFile found = (from b in Blocks from f in b.Files where f.FileHash == HashDictionary.HashFileName(fileName) select f).FirstOrDefault(); // did we find the file? if (found != null) { return(new SearchResult(found.Parent.Index, found.Index, HashDictionary.AddedFilenames.Contains(found.FileHash), found)); } // if we got here, we found nothing return(SearchResult.NotFound); }
/// <summary> /// Saves file data to <paramref name="writer"/>. /// </summary> /// <param name="reader">Binary file (.uop source).</param> /// <param name="writer">Binary file (.uop destination).</param> public void SaveData(BinaryReader reader, BinaryWriter writer) { if (m_SourceBuffer != null) { writer.Write(m_SourceBuffer, 0, m_CompressedSize); HashDictionary.Set(m_FileHash, m_FileName); } else { reader.BaseStream.Seek(m_OldDataBlockAddress + m_DataBlockLength, SeekOrigin.Begin); m_SourceBuffer = reader.ReadBytes(m_CompressedSize); writer.Write(m_SourceBuffer, 0, m_CompressedSize); } m_OldDataBlockAddress = m_DataBlockAddress; m_SourceBuffer = null; m_Modified = false; m_Added = false; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="fileName">Absolute path to the file on HD.</param> /// <param name="innerFolder">Relative folder within KR (destination).</param> /// <param name="flag">Compression type.</param> public MythicPackageFile(string fileName, string innerFolder, CompressionFlag flag) { if (String.IsNullOrEmpty(fileName)) { throw new ArgumentException("fileName"); } m_FileName = Path.Combine(innerFolder, Path.GetFileName(fileName)).ToLower(); if (m_FileName.StartsWith("\\") || m_FileName.StartsWith("/")) { m_FileName = m_FileName.Substring(1); } m_FileName = m_FileName.Replace('\\', '/'); m_FileHash = HashDictionary.HashFileName(m_FileName); m_SourceFileName = fileName; m_Compression = flag; m_DataBlockLength = 0; m_DataBlockHash = 0; }
/// <summary> /// Reloads file names from the dictionary. /// </summary> public void RefreshFileName() { m_FileName = HashDictionary.Get(m_FileHash, false); }