/// <summary> /// Prepares a packed file for viewing/editing. can be used as stand-alone to get files without creating any task. /// </summary> /// <param name="bnk">BNK file</param> /// <param name="packedFilePath">Path of packed file to prepare</param> /// <returns>Full path of extracted file</returns> public string PrepareFile(BNK bnk, string packedFilePath) { string returnPath = null; if (bnk == null || string.IsNullOrEmpty(packedFilePath)) { return(returnPath); } // Working folder string workFolder = File2.SetTemporaryFolder(null, LibraryConstants.FOLDER_TEMP, true); if (workFolder == null) { throw new Exception(ERROR_CODE_TEMP_FOLDER); } // Extracting packed file into working folder string packedFileName = bnk.GetPackedFileName(packedFilePath); returnPath = string.Format(@"{0}\{1}", workFolder, packedFileName); bnk.ExtractPackedFile(packedFilePath, returnPath, false); // Removing attributes on file File.SetAttributes(returnPath, FileAttributes.Normal); return(returnPath); }
/// <summary> /// Creates backup copy of replaced packed file /// </summary> /// <param name="bnkFilePath"></param> /// <param name="packedFileName"></param> /// <param name="backupFolder"></param> private static void _BackupFile(string bnkFilePath, string packedFileName, string backupFolder) { FileInfo fi = new FileInfo(bnkFilePath); // BUG_84: suffix added to folder string backupSubFolder = string.Concat(fi.Name, _SUFFIX_PACKED); string destinationFileName = string.Concat(backupFolder, @"\", backupSubFolder, @"\", packedFileName); // If backup file already exists, it is kept if (!File.Exists(destinationFileName)) { // Loading Bnk to extract file BNK bnk = TduFile.GetFile(bnkFilePath) as BNK; if (bnk == null || !bnk.Exists) { throw new Exception("Invalid BNK file: " + bnkFilePath); } fi = new FileInfo(destinationFileName); if (fi.Directory == null) { throw new Exception("Invalid file name: " + destinationFileName); } if (!Directory.Exists(fi.Directory.FullName)) { Directory.CreateDirectory(fi.Directory.FullName); } string packedFilePath = bnk.GetPackedFilesPaths(packedFileName)[0]; bnk.ExtractPackedFile(packedFilePath, destinationFileName, false); } }
/// <summary> /// Réalise la conversion multiple /// </summary> private void _MultipleConvert() { // Vérifications if (string.IsNullOrEmpty(sourceBNKTextBox.Text) || string.IsNullOrEmpty(targetFolderTextBox.Text)) { return; } Cursor = Cursors.WaitCursor; // Parcours des fichiers et extraction des 2DB BNK bnkFile = TduFile.GetFile(sourceBNKTextBox.Text) as BNK; if (bnkFile == null) { throw new Exception(_ERROR_INVALID_BNK_FILE); } Collection <string> textureFiles = bnkFile.GetPackedFilesPathsByExtension(LibraryConstants.EXTENSION_2DB_FILE); string tempFolder = File2.SetTemporaryFolder(null, LibraryConstants.FOLDER_TEMP, true); foreach (string anotherFilePath in textureFiles) { // 1.Extraction depuis le BNK vers le dossier temporaire bnkFile.ExtractPackedFile(anotherFilePath, tempFolder, true); // 2.Conversion des fichiers 2DB>DDS string fileName = tempFolder + @"\" + bnkFile.GetPackedFileName(anotherFilePath); FileInfo fi = new FileInfo(fileName); string newFileName = targetFolderTextBox.Text + @"\" + File2.ChangeExtensionOfFilename(fi.Name, LibraryConstants.EXTENSION_DDS_FILE); // If file already exists, it is renamed Tools.RenameIfNecessary(newFileName, LibraryConstants.SUFFIX_OLD_FILE); GraphicsConverters._2DBToDDS(fileName, newFileName); } // EVO 32 string message = string.Format(_STATUS_SUCCESS_MULTIPLE, textureFiles.Count); StatusBarLogManager.ShowEvent(this, message); // On efface le champ source sourceBNKTextBox.Text = ""; // Mise à jour de l'emplacement des 2DB _2DBLocationLink.Text = tempFolder; Cursor = Cursors.Default; }
public void ExtractPackedFile_WhenFileTarget_ShouldCreateFileAtRightLocation() { // GIVEN string bankFile = FileTesting.CreateFileFromResource("TDUModdingLibraryTests.Resources.banks.pc." + ResourceFile, Path.Combine(_tempPath, ResourceFile)); BNK bnk = TduFile.GetFile(bankFile) as BNK; Assert.NotNull(bnk); string packedFilePath = @"D:\Eden-Prog\Games\TestDrive\Resources\4Build\PC\EURO\Vehicules\Cars\Mercedes\CLK_55\.2DM\CLK_55"; // WHEN string expectedFilePath = Path.Combine(_tempPath, "extracted.CLK_55.2DM"); bnk.ExtractPackedFile(packedFilePath, expectedFilePath, false); // THEN Assert.IsTrue(File.Exists(expectedFilePath)); }
/// <summary> /// Handles database loading /// </summary> private void _LoadDatabase() { DB.Culture currentCulture = Program.ApplicationSettings.GetCurrentCulture(); string resourceBNKFileName = DB.GetBNKFileName(currentCulture); BNK resourceBNK = TduFile.GetFile(Tools.TduPath + LibraryConstants.FOLDER_DB + resourceBNKFileName) as BNK; if (resourceBNK != null) { // Extracting Houses resource string packedFileName = DB.GetFileName(currentCulture, DB.Topic.Houses); string packedFilePath = resourceBNK.GetPackedFilesPaths(packedFileName)[0]; string tempLocation = File2.SetTemporaryFolder(null, LibraryConstants.FOLDER_TEMP, true); resourceBNK.ExtractPackedFile(packedFilePath, tempLocation, true); // Loading resource _HousesResource = TduFile.GetFile(tempLocation + @"\" + packedFileName) as DBResource; if (_HousesResource == null) { throw new Exception("Error while loading database resources (Houses) !"); } } }