public void RenameAndMoveFile(CacheFile cacheFile, FilenameDatabaseEntry entry) { if (entry != null) { string filename = entry.Filename; if (filename[0] == '.') { filename = filename.Substring(1); } Filename = filename; } string outputFolder = cacheFile.OutputFolder; string oldFileEntryPath = outputFolder + "\\" + RelativePath; string fileEntryPath = ""; if (String.IsNullOrEmpty(Filename)) { string unknownDir = cacheFile.OutputUnknownFolder; if (!Directory.Exists(unknownDir)) { Directory.CreateDirectory(unknownDir); } string Extension = Helper.ExtensionFinder(oldFileEntryPath); string fileEntryName = String.Format("{0}{1}{2}", TACFile.UnknownFilesPath, Index.ToString(), Extension); fileEntryPath = outputFolder + fileEntryName; } else { fileEntryPath = Filename.Replace('/', '\\'); fileEntryPath = outputFolder + "\\" + fileEntryPath; fileEntryPath = Helper.SwitchExtension(fileEntryPath); string dir = Path.GetDirectoryName(fileEntryPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } fileEntryPath = fileEntryPath.Replace("\\\\", "\\"); oldFileEntryPath = oldFileEntryPath.Replace("\\\\", "\\"); RelativePath = "\\" + Helper.GetRelativePath(fileEntryPath, outputFolder); if (fileEntryPath == oldFileEntryPath) { return; } if (File.Exists(fileEntryPath)) { File.Delete(fileEntryPath); } File.Move(oldFileEntryPath, fileEntryPath); }
private void Merge(List <FilenameDatabaseEntry> entries) { DescriptionChanged(this, new DescriptionChangedArgs("Merging file with database...")); for (int i = 0; i < entries.Count; i++) { ProgressChanged(this, new ProgressChangedArgs(i, entries.Count)); FilenameDatabaseEntry entry = entries[i]; FilenameDatabase.Add(entry); } Finished(this, new FinishedArgs(true)); }
public byte[] GetFileFromEntry(FilenameDatabaseEntry dbEntry, out bool found) { uint offset = 0; uint size = 0; foreach (TADFileEntry entry in TADFile.FileEntries) { if (entry.FirstHash == dbEntry.FirstHash && entry.SecondHash == dbEntry.SecondHash) { offset = entry.FileOffset; size = entry.FileSize; break; } } found = false; if (offset == 0) { return(new byte[0]); } if (m_buffer == null || m_buffer.Length == 0) { if (!Helper.IsFileValid(Filename)) { return(new byte[0]); } using (FileStream stream = File.Open(Filename, FileMode.Open)) { stream.Seek(offset, SeekOrigin.Begin); byte[] buffer = new byte[size]; stream.Read(buffer, 0, (int)size); found = true; return(buffer); } } byte[] fileBuffer = new byte[size]; Array.Copy(m_buffer, offset, fileBuffer, 0, size); found = true; return(fileBuffer); }