コード例 #1
0
        /// <summary>
        /// Returns all default challenges from specified reference folder
        /// </summary>
        /// <param name="referenceFolder"></param>
        public static Collection <DFE> LoadDefaultChallenges(string referenceFolder)
        {
            Collection <DFE> returnedChallenges = new Collection <DFE>();

            // Get all files in specified DFE folder
            DirectoryInfo dirInfo = new DirectoryInfo(referenceFolder);

            if (!dirInfo.Exists)
            {
                Directory.CreateDirectory(referenceFolder);
            }

            string[] returnedTracks = Directory.GetFiles(referenceFolder, LibraryConstants.FILTER_DFE);

            foreach (string anotherFile in returnedTracks)
            {
                DFE dfeFile = TduFile.GetFile(anotherFile) as DFE;

                if (dfeFile == null)
                {
                    Log.Warning("DFE file failed to load: " + anotherFile);
                }
                else
                {
                    returnedChallenges.Add(dfeFile);
                }
            }

            // Log message
            Log.Info("Original challenges found and loaded: " + returnedChallenges.Count);

            return(returnedChallenges);
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Parameters
            string countValues = _GetParameter(PatchInstructionParameter.ParameterName.distributionValues);

            // Using TduFile impl
            string   xmlFullPath  = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.AIConfig);
            AIConfig aiConfigFile = TduFile.GetFile(xmlFullPath) as AIConfig;

            if (aiConfigFile == null || !aiConfigFile.Exists)
            {
                throw new Exception("Invalid AI configuration file: " + xmlFullPath);
            }
            // Parsing distribution values
            string[] countCouples = countValues.Split(new[] { Tools.SYMBOL_VALUE_SEPARATOR2 }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string anotherCouple in countCouples)
            {
                string[] zoneValue = anotherCouple.Split(Tools.SYMBOL_VALUE_SEPARATOR);

                if (zoneValue.Length == 2)
                {
                    int zoneId = int.Parse(zoneValue[0]);

                    aiConfigFile.SetTrafficVehicleCountPerKilometer(zoneId, zoneValue[1]);
                }
                else
                {
                    throw new Exception("Invalid count parameter specified: " + anotherCouple);
                }
            }

            // Saving
            aiConfigFile.Save();
        }
コード例 #4
0
ファイル: MAPToolForm.cs プロジェクト: djey47/tdumt
        private void refreshButton_Click(object sender, EventArgs e)
        {
            // Contrôle de la saisie ...
            if (string.IsNullOrEmpty(inputFilePath.Text))
            {
                return;
            }

            // Récupération des infos

            try
            {
                Cursor = Cursors.WaitCursor;

                leMAP = TduFile.GetFile(inputFilePath.Text) as MAP;

                if (leMAP != null)
                {
                    // Mise à jour des entrées
                    _UpdateEntryList(true);
                }

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBoxes.ShowError(this, ex);
            }
        }
コード例 #5
0
ファイル: FileBrowserForm.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Crée une copie de sauvegarde du fichier spécifié
        /// </summary>
        /// <param name="fileName">nom de fichier à sauvegarder</param>
        private void _BackupFile(string fileName)
        {
            // According to file type...
            if (Regex.IsMatch(fileName, BNK.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                // Fichier BNK -> on crée une copie de sauvegarde par la méthode personnalisée
                // Chargement du fichier BNK
                BNK leBNK = TduFile.GetFile(fileName) as BNK;

                if (leBNK != null)
                {
                    // Backup
                    leBNK.MakeBackup();
                }
            }
            else if (Regex.IsMatch(fileName, TduFile.BACKUP_FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                // Backup -> sauvegarde inutile
                string message = string.Format(_ERROR_BACKUP_OF_BACKUP, fileName);

                MessageBoxes.ShowWarning(this, message);
            }
            else
            {
                // Pour les autres fichiers on effectue la sauvegarde par défaut
                Tools.BackupFile(fileName, fileName + "." + LibraryConstants.EXTENSION_BACKUP);
            }
        }
コード例 #6
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Parameters
            string camId      = _GetParameter(PatchInstructionParameter.ParameterName.cameraIKIdentifier);
            string viewSource = _GetParameter(PatchInstructionParameter.ParameterName.viewSource);

            Cameras.Position sourcePosition = _ValidatePosition(viewSource);
            string           viewTarget     = _GetParameter(PatchInstructionParameter.ParameterName.viewTarget);

            Cameras.Position targetPosition = _ValidatePosition(viewTarget);

            // Loading current camera
            string  currentCamFile = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.CamerasBin);
            Cameras currentCameras = TduFile.GetFile(currentCamFile) as Cameras;

            if (currentCameras == null || !currentCameras.Exists)
            {
                throw new Exception("Unable to load current camera data: " + currentCamFile);
            }

            // Retrieving entry
            Cameras.CamEntry entryToEdit = currentCameras.GetEntryByCameraId(camId);

            VehicleSlotsHelper.CustomizeCameraPosition(currentCameras, entryToEdit, Cameras.ViewType.Cockpit, sourcePosition, targetPosition);

            // Saving
            currentCameras.Save();
        }
コード例 #7
0
ファイル: GraphicsConverters.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Convertit un fichier DDS en fichier 2DB. Utilise l'en-tête du fichier 2DB d'origine.
        /// </summary>
        /// <param name="original2DBFile">ancien fichier 2DB</param>
        /// <param name="sourceDDSFile">fichier DDS à convertir</param>
        /// <param name="target2DBFile">nouveau fichier 2DB à créer</param>
        /// <param name="newTextureName">if not null, allows to override texture name</param>
        /// <param name="mipmapCount">if not -1, forces mipmap count</param>
        public static void DDSTo2DB(string original2DBFile, string sourceDDSFile, string target2DBFile, string newTextureName, int mipmapCount)
        {
            // EVO_37 : 1. Récupérer les dimensions de la texture
            DDS ddsFile = (DDS)TduFile.GetFile(sourceDDSFile);

            DDS.TextureHeader ddsHeader = (DDS.TextureHeader)ddsFile.Header;
            uint ddsWidth       = ddsHeader.ddsd.dwWidth;
            uint ddsHeight      = ddsHeader.ddsd.dwHeight;
            uint ddsMipmapCount = ddsHeader.ddsd.dwMipMapCount;

            // 2. Prendre l'en-tête du fichier 2DB original
            _2DB old2DBFile = (_2DB)TduFile.GetFile(original2DBFile);

            _2DB.TextureHeader old2DBHeader = (_2DB.TextureHeader)old2DBFile.Header;

            // 3.  Mettre à jour les dimensions et nombre de mipmap
            old2DBHeader.height = (short)ddsHeight;
            old2DBHeader.width  = (short)ddsWidth;
            // BUG_58 : mipmap count in 2DB takes main texture into account (so always >= 1)

            // Mipmap count enforcement
            if (mipmapCount == KEEP_ORIGINAL_MIPMAP_COUNT)
            {
                old2DBHeader.bMipMapCount = old2DBHeader.bMipMapCountBis = (byte)(ddsMipmapCount + 1);
            }
            else
            {
                old2DBHeader.bMipMapCount = old2DBHeader.bMipMapCountBis = (byte)mipmapCount;
            }

            // 4. Calcul de bourrage / découpage éventuels
            long fileSize = _2DB.HEADER_SIZE + (ddsFile.Size - DDS.HEADER_SIZE) + _2DB.FINALIZATION_STRING.LongLength;

            // 5. Création du nouveau fichier et assemblage
            using (BinaryWriter writer = new BinaryWriter(new FileStream(target2DBFile, FileMode.Create, FileAccess.Write)))
            {
                // Mettre à jour la taille du fichier dans l'entete
                old2DBHeader.dwSize  = (uint)fileSize;
                old2DBHeader.dwSize2 = old2DBHeader.dwSize2Bis = (uint)(fileSize - 32);

                // Override texture name ?
                if (newTextureName != null)
                {
                    old2DBHeader.strName = String2.ToByteArray(Tools.NormalizeName(newTextureName));
                }

                // Ecriture de l'en-tête
                old2DBFile.Header = old2DBHeader;
                writer.Write(old2DBFile.HeaderData);

                // Data writing
                byte[] imageData = ddsFile.ImageData;

                writer.Write(imageData);

                // Finalization: REAL  (??)
                writer.Write(_2DB.FINALIZATION_STRING);
            }
        }
コード例 #8
0
        /// <summary>
        /// Loads patch file data from specified file
        /// </summary>
        /// <param name="installPatchFile">Install patch file to load</param>
        /// <param name="uninstallPatchFile">Uninstall patch file to load (optional - can be null)</param>
        private void _LoadData(string installPatchFile, string uninstallPatchFile)
        {
            // Install file loading
            PCH currentPatch = TduFile.GetFile(installPatchFile) as PCH;

            if (currentPatch == null)
            {
                throw new Exception(_ERROR_INVALID_PATCH_FILE);
            }
            if (!currentPatch.Exists)
            {
                throw new FileNotFoundException("", installPatchFile);
            }

            _CurrentInstallPatch = currentPatch;

            // Uninstall file loading
            currentPatch = null;

            if (!string.IsNullOrEmpty(uninstallPatchFile))
            {
                currentPatch = TduFile.GetFile(uninstallPatchFile) as PCH;
            }

            if (currentPatch == null || !currentPatch.Exists)
            {
                Log.Info(_WARN_NO_UNINSTALL);
            }
            else
            {
                _CurrentUninstallPatch = currentPatch;
            }

            // Patch info
            // Name - version
            if (string.IsNullOrEmpty(_CurrentInstallPatch.Version))
            {
                titleLabel.Text = _CurrentInstallPatch.Name;
            }
            else
            {
                titleLabel.Text = string.Format(_FORMAT_LABEL_PROJECT, _CurrentInstallPatch.Name, _CurrentInstallPatch.Version);
            }

            // Author - date
            if (string.IsNullOrEmpty(_CurrentInstallPatch.Date))
            {
                contribLabel.Text = _CurrentInstallPatch.Author;
            }
            else
            {
                contribLabel.Text = string.Format(_FORMAT_LABEL_CONTRIBUTOR, _CurrentInstallPatch.Author, _CurrentInstallPatch.Date);
            }

            // EVO_142 : Free label
            freeLabel.Text = _CurrentInstallPatch.Free;
        }
コード例 #9
0
ファイル: TexturesTests.cs プロジェクト: djey47/tdumt
        public static void Read2DBFileTest(string fileName)
        {
            _2DB textureFile = (_2DB)TduFile.GetFile(fileName);

            if (textureFile == null)
            {
                throw new Exception();
            }
        }
コード例 #10
0
        private static NativeCameras _LoadCameras(string camFileName)
        {
            var camFile = TduFile.GetFile(camFileName) as TDUModdingLibrary.fileformats.binaries.Cameras;

            if (camFile == null)
            {
                throw new FileLoadException("Unable to load cameras file.", camFileName);
            }
            return(camFile);
        }
コード例 #11
0
        private static BNK _LoadBankFile(string bankFileName)
        {
            var bankFile = TduFile.GetFile(bankFileName) as BNK;

            if (bankFile == null)
            {
                throw new FileLoadException("Unable to load bank file.", bankFileName);
            }
            return(bankFile);
        }
コード例 #12
0
        /// <summary>
        /// Loads the whole database in specified location and returns edit tasks
        /// </summary>
        /// <param name="databasePath"></param>
        /// <param name="culture"></param>
        /// <param name="isReadOnly"></param>
        /// <param name="returnedTasks"></param>
        /// <returns></returns>
        public static Dictionary <DB.Topic, TduFile[]> LoadDatabase(string databasePath, DB.Culture culture, bool isReadOnly, out Dictionary <DB.Topic, EditHelper.Task[]> returnedTasks)
        {
            Dictionary <DB.Topic, TduFile[]> returnedData = new Dictionary <DB.Topic, TduFile[]>();

            returnedTasks = new Dictionary <DB.Topic, EditHelper.Task[]>();

            if (!string.IsNullOrEmpty(databasePath))
            {
                if (Directory.Exists(databasePath))
                {
                    // Opening main BNK
                    string dbBnkFile = databasePath + @"\" + DB.GetBNKFileName(DB.Culture.Global);
                    BNK    dbBnk     = TduFile.GetFile(dbBnkFile) as BNK;

                    if (dbBnk == null)
                    {
                        throw new Exception("Unable to load BNK: " + dbBnkFile);
                    }

                    // Opening resource BNK
                    string resBnkFile = databasePath + @"\" + DB.GetBNKFileName(culture);
                    BNK    resBnk     = TduFile.GetFile(resBnkFile) as BNK;

                    if (resBnk == null)
                    {
                        throw new Exception("Unable to load BNK: " + resBnk);
                    }

                    // Loading topics and resources
                    foreach (DB.Topic anotherTopic in Enum.GetValues(typeof(DB.Topic)))
                    {
                        if (anotherTopic != DB.Topic.None)
                        {
                            EditHelper.Task[] loadedTasks;
                            TduFile[]         loadedFiles = LoadTopicForEdit(anotherTopic, culture, dbBnk, resBnk,
                                                                             out loadedTasks);

                            returnedData.Add(anotherTopic, loadedFiles);

                            if (!isReadOnly)
                            {
                                returnedTasks.Add(anotherTopic, loadedTasks);
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Specified database path doesn't exist: " + databasePath);
                }
            }

            return(returnedData);
        }
コード例 #13
0
ファイル: EditorTracksDialog.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Updates DFE files list view
        /// </summary>
        private void _RefreshIGEList()
        {
            //Checkboxes visibility
            igeListView.CheckBoxes = _IsSelectMode;

            igeListView.Items.Clear();

            Collection <IGE> _EditorChallenges = new Collection <IGE>();

            // Loading IGE tracks
            string profileFolder = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Savegame), @"\", Program.ApplicationSettings.PlayerProfile);
            string igeFolder     = string.Concat(profileFolder, LibraryConstants.FOLDER_IGE);

            if (Directory.Exists(igeFolder))
            {
                FileInfo[] igeFiles = new DirectoryInfo(igeFolder).GetFiles();

                foreach (FileInfo anotherTrack in igeFiles)
                {
                    IGE newIge = TduFile.GetFile(anotherTrack.FullName) as IGE;

                    if (newIge == null)
                    {
                        Log.Warning("Error when loading IGE track file: " + anotherTrack.FullName + ", skipping...");
                    }
                    else
                    {
                        _EditorChallenges.Add(newIge);
                    }
                }
            }

            // Filling editor tracks...
            int trackIndex = 1;

            foreach (IGE igeFile in _EditorChallenges)
            {
                // New list item
                ListViewItem lvi = new ListViewItem(trackIndex.ToString())
                {
                    Tag = igeFile
                };

                // Track names
                lvi.SubItems.Add(igeFile.TrackName);
                lvi.SubItems.Add(igeFile.Description);
                lvi.SubItems.Add(igeFile.TrackId);

                igeListView.Items.Add(lvi);

                trackIndex++;
            }
        }
コード例 #14
0
ファイル: EditHelper.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Creates a new task and returns a copy instance
        /// </summary>
        /// <param name="parentBNK">Parent BNK file</param>
        /// <param name="packedFilePath">Path of packed file under edit</param>
        /// <param name="isFurtive">true to prevent this task to be displayed in GUI, else false</param>
        /// <returns>Added task instance</returns>
        public Task AddTask(BNK parentBNK, string packedFilePath, bool isFurtive)
        {
            Task editTask = new Task();

            if (parentBNK == null)
            {
                return(editTask);
            }

            // New task
            editTask.parentBNK            = parentBNK;
            editTask.editedPackedFilePath = packedFilePath;
            editTask.startDate            = DateTime.Now;

            if (_SameTaskExists(editTask))
            {
                throw new Exception(ERROR_CODE_TASK_EXISTS);
            }

            // Preparing edit...
            editTask.isFurtive     = isFurtive;
            editTask.extractedFile = _PrepareFile(editTask);

            if (editTask.extractedFile == null)
            {
                throw new Exception(ERROR_CODE_EXTRACT_FAILED);
            }

            // BUG_48: Preparing tracking...
            editTask.trackedFile = TduFile.GetTrackedFileName(editTask.extractedFile);

            // Original write time
            if (editTask.extractedFile.Equals(editTask.trackedFile))
            {
                FileInfo fi = new FileInfo(editTask.extractedFile);

                editTask.trackedLastFileWriteTime = fi.LastWriteTime;
            }
            else
            {
                // If tracked file name is different from extracted one, this data is set after first tracking
                // Because at the moment tracked file may not be ready
                editTask.trackedLastFileWriteTime = DateTime.MinValue;
            }

            editTask.isValid = true;

            // Change in task list
            _Tasks.Add(editTask);
            NotifyAll();

            return(editTask);
        }
コード例 #15
0
        public void LoadBnkFileForXenonPlatform_ShouldNotCrash()
        {
            // GIVEN
            string bankFile = FileTesting.CreateFileFromResource("TDUModdingLibraryTests.Resources.banks.xenon." + ResourceFile,
                                                                 Path.Combine(_tempPath, ResourceFile));

            // WHEN
            BNK bnk = TduFile.GetFile(bankFile) as BNK;

            // THEN
            Assert.NotNull(bnk);
        }
コード例 #16
0
        /// <summary>
        /// Returns the right FileHandler according to specified file.
        /// </summary>
        /// <param name="fileName">file name</param>
        /// <returns>RegulardHandler instance if it's from an unsupported type</returns>
        public static FileHandler GetHandler(string fileName)
        {
            // TDU File
            TduFile     tduFile = TduFile.GetFile(fileName);
            FileHandler handler = new RegularHandler();

            // New mapping management

            // DB
            if (Regex.IsMatch(fileName, DB.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new DBHandler();
            }
            // BNK
            else if (Regex.IsMatch(fileName, BNK.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new BNKHandler();
            }
            // DDS
            else if (Regex.IsMatch(fileName, DDS.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new DDSHandler();
            }
            // 2DB
            else if (Regex.IsMatch(fileName, _2DB.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new _2DBHandler();
            }
            // MAP
            else if (Regex.IsMatch(fileName, MAP.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new MAPHandler();
            }
            // PCH
            else if (Regex.IsMatch(fileName, PCH.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new PCHHandler();
            }
            // DB Resources
            else if (Regex.IsMatch(fileName, DBResource.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            {
                handler = new DBResourceHandler();
            }
            // DFE/IGE

            /*else if (Regex.IsMatch(fileName, DFE.FILENAME_PATTERN, RegexOptions.IgnoreCase)
            || Regex.IsMatch(fileName, IGE.FILENAME_PATTERN, RegexOptions.IgnoreCase))
            ||  handler = new TrackHandler();*/

            handler._TheTDUFile = tduFile;

            return(handler);
        }
コード例 #17
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected void _CommonProcess()
        {
            // Common parameters
            string camId           = _GetParameter(PatchInstructionParameter.ParameterName.cameraIKIdentifier);
            string hoodView        = _GetParameter(PatchInstructionParameter.ParameterName.newHoodView);
            string hoodBackView    = _GetParameter(PatchInstructionParameter.ParameterName.newHoodBackView);
            string cockpitView     = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitView);
            string cockpitBackView = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitBackView);

            // Parameter validation
            string hoodCamId = hoodView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType hoodViewType  = _ValidateViewType(hoodView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           hoodBackCamId = hoodBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType hoodBackViewType = _ValidateViewType(hoodBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           cockpitCamId     = cockpitView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType cockpitViewType  = _ValidateViewType(cockpitView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);
            string           cockpitBackCamId = cockpitBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[0];

            Cameras.ViewType cockpitBackViewType = _ValidateViewType(cockpitBackView.Split(Tools.SYMBOL_VALUE_SEPARATOR)[1]);

            // Loading current camera
            string  currentCamFile = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.CamerasBin);
            Cameras currentCameras = TduFile.GetFile(currentCamFile) as Cameras;

            if (currentCameras == null || !currentCameras.Exists)
            {
                throw new Exception("Unable to load current camera data: " + currentCamFile);
            }

            // Loading default camera
            Cameras defaultCameras = TduFile.GetFile(camReferenceFilename) as Cameras;

            if (defaultCameras == null || !defaultCameras.Exists)
            {
                throw new Exception("Unable to load new camera data: " + camReferenceFilename);
            }

            // Views
            VehicleSlotsHelper.InitReference(Tools.WorkingPath + LibraryConstants.FOLDER_XML);

            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Hood, hoodCamId, hoodViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Hood_Back, hoodBackCamId, hoodBackViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Cockpit, cockpitCamId, cockpitViewType);
            _Customize(currentCameras, defaultCameras, camId, Cameras.ViewType.Cockpit_Back, cockpitBackCamId, cockpitBackViewType);

            // Saving
            currentCameras.Save();
        }
コード例 #18
0
        public void ReadResourceFile_ShouldGetAllEntries()
        {
            //Given
            string fileName = FileTesting.CreateFileFromResource("TDUModdingLibraryTests.Resources.TDU_Achievements.fr", Path.Combine(_tempPath, ResourceFile));

            //When
            DBResource dbResource = TduFile.GetFile(fileName) as DBResource;

            //Then
            Assert.NotNull(dbResource);
            Assert.AreEqual(DB.Culture.FR, dbResource.CurrentCulture);
            Assert.AreEqual(DB.Topic.Achievements, dbResource.CurrentTopic);
            Assert.AreEqual(253, dbResource.EntryList.Count);
        }
コード例 #19
0
ファイル: _2DBToDDSForm.cs プロジェクト: djey47/tdumt
        /// <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;
        }
コード例 #20
0
ファイル: TexturesTests.cs プロジェクト: djey47/tdumt
        public static void GetDDSHeaderAsBytesTest(string fileName)
        {
            DDS textureFile = (DDS)TduFile.GetFile(fileName);

            DDS.TextureHeader header;
            byte[]            headerBytes = null;

            if (textureFile == null)
            {
                throw new Exception();
            }

            header      = (DDS.TextureHeader)textureFile.Header;
            headerBytes = textureFile.HeaderData;
        }
コード例 #21
0
ファイル: PropertiesDialog.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Defines window contents
        /// </summary>
        private void _InitializeContents()
        {
            // Window title
            FileInfo fi = new FileInfo(_FileName);

            Text = string.Format(_FORMAT_WINDOW_TITLE, fi.Name);

            // Loading file
            TduFile file = TduFile.GetFile(_FileName);

            // Properties
            if (file.Exists)
            {
                ListView2.FillWithProperties(propertiesListView, file.Properties);
            }
        }
コード例 #22
0
        public void Save_ShouldMakeFileWithSizeMultipleOf8()
        {
            //Given
            string fileName = FileTesting.CreateFileFromResource(
                "TDUModdingLibraryTests.Resources.TDU_Achievements.db", Path.Combine(_tempPath, ContentsFile));
            DB db = TduFile.GetFile(fileName) as DB;

            //When
            Assert.NotNull(db);
            db.Save();

            //Then
            FileInfo fileInfo = new FileInfo(fileName);

            Assert.IsTrue(fileInfo.Length % 8 == 0);
        }
コード例 #23
0
ファイル: _2DBToDDSForm.cs プロジェクト: djey47/tdumt
        private void fileInfo4Button_Click(object sender, EventArgs e)
        {
            // EVO_65: properties
            try
            {
                TduFile bnkFile = TduFile.GetFile(sourceBNKTextBox.Text);

                if (bnkFile.Exists)
                {
                    ListView2.FillWithProperties(propertiesListView, bnkFile.Properties);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
            }
        }
コード例 #24
0
ファイル: DbResourcesEditorForm.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Prépare le chargement d'une catégorie depuis la base de données courante
        /// </summary>
        /// <param name="category">Type de données recherché</param>
        /// <param name="culture">Code pays</param>
        private void _LoadFromCurrentDatabase(DB.Topic category, DB.Culture culture)
        {
            // Localisation du fichier BNK
            string bnkPath = Program.ApplicationSettings.TduMainFolder + LibraryConstants.FOLDER_DB + DB.GetBNKFileName(culture);
            BNK    bnk     = TduFile.GetFile(bnkPath) as BNK;

            if (bnk != null && bnk.Exists)
            {
                string fileName = DB.GetFileName(culture, category);
                string filePath = bnk.GetPackedFilesPaths(fileName)[0];

                // EVO_91: using edit support from ModdingLibrary
                EditHelper.Task currentTask = EditHelper.Instance.AddTask(bnk, filePath, true);

                _EditedFile = currentTask.extractedFile;
            }
        }
コード例 #25
0
ファイル: _2DBToDDSForm.cs プロジェクト: djey47/tdumt
        private void file2InfoButton_Click(object sender, EventArgs e)
        {
            // EVO_65: properties
            try
            {
                TduFile textureFile = TduFile.GetFile(newDDSFilePath.Text);

                if (textureFile.Exists)
                {
                    ListView2.FillWithProperties(propertiesListView, textureFile.Properties);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
            }
        }
コード例 #26
0
        /// <summary>
        /// Loads the whole specified topic for edit mode and returns corresponding TduFiles and EditTasks
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="culture"></param>
        /// <param name="bnkFile"></param>
        /// <param name="rBnkFile"></param>
        /// <param name="returnedTasks"></param>
        /// <returns></returns>
        public static TduFile[] LoadTopicForEdit(DB.Topic topic, DB.Culture culture, BNK bnkFile, BNK rBnkFile, out EditHelper.Task[] returnedTasks)
        {
            TduFile[] returnedFiles = new TduFile[2];

            returnedTasks = new EditHelper.Task[2];

            if (bnkFile != null && bnkFile.Exists)
            {
                // Getting files
                string dbFilePath = bnkFile.GetPackedFilesPaths(DB.GetFileName(DB.Culture.Global, topic))[0];

                returnedTasks[0] = EditHelper.Instance.AddTask(bnkFile, dbFilePath, true);

                if (culture != DB.Culture.Global &&
                    rBnkFile != null && rBnkFile.Exists)
                {
                    string dbrFilePath = rBnkFile.GetPackedFilesPaths(DB.GetFileName(culture, topic))[0];

                    returnedTasks[1] = EditHelper.Instance.AddTask(rBnkFile, dbrFilePath, true);
                }

                // Loading these files
                DB main = TduFile.GetFile(returnedTasks[0].extractedFile) as DB;

                if (main == null || !main.Exists)
                {
                    throw new Exception(topic + " main database loading failure.");
                }
                returnedFiles[0] = main;

                // Resource (optional)
                if (returnedTasks[1].isValid)
                {
                    DBResource resource = TduFile.GetFile(returnedTasks[1].extractedFile) as DBResource;

                    if (resource == null || !resource.Exists)
                    {
                        throw new Exception(string.Concat(topic, "-", culture, " resource database loading failure."));
                    }
                    returnedFiles[1] = resource;
                }
            }

            return(returnedFiles);
        }
コード例 #27
0
ファイル: BNKTest.cs プロジェクト: djey47/tdumt
        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));
        }
コード例 #28
0
ファイル: UninstallPackedFileI.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Replaces packed file in TDU installed files by previous backup
        /// </summary>
        /// <param name="bnkFilePath"></param>
        /// <param name="packedFileName"></param>
        /// <param name="backupFolder"></param>
        private static void _UninstallPackedFile(string bnkFilePath, string packedFileName, string backupFolder)
        {
            FileInfo fi = new FileInfo(bnkFilePath);
            // BUG_84: suffix added to folder
            string backupSubFolder = string.Concat(fi.Name, InstallPackedFileI._SUFFIX_PACKED);
            string backupFileName  = string.Concat(backupFolder, @"\", backupSubFolder, @"\", packedFileName);

            // Replaces file in BNK
            BNK bnk = TduFile.GetFile(bnkFilePath) as BNK;

            if (bnk == null || !bnk.Exists)
            {
                throw new Exception("Invalid BNK file: " + bnkFilePath);
            }

            string packedFilePath = bnk.GetPackedFilesPaths(packedFileName)[0];

            bnk.ReplacePackedFile(packedFilePath, backupFileName);
        }
コード例 #29
0
ファイル: FileBrowserForm.cs プロジェクト: djey47/tdumt
        /// <summary>
        /// Loads specified BNK file into BNK Manager
        /// </summary>
        /// <param name="selectedFile"></param>
        private void _LoadBnkFile(string selectedFile)
        {
            // Vérification : si le fichier n'est pas déjà chargé
            if (_CurrentBnkFile == null || !selectedFile.Equals(_CurrentBnkFile.FileName))
            {
                // Chargement du fichier BNK
                StatusBarLogManager.ShowEvent(this, _STATUS_BNK_LOADING);

                _CurrentBnkFile = TduFile.GetFile(selectedFile) as BNK;

                if (_CurrentBnkFile != null)
                {
                    // Mise à jour des listes
                    SetBnkContentsChanged();
                    // No selection in packed list
                    contentListView.SelectedItems.Clear();
                    contentTreeView.SelectedNode = null;
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Loads the whole specified topic in current database for read-only mode
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="culture"></param>
        /// <returns>Array of database loaded TduFile. Index 0 is the main (encrypted) file, index 1 is the resource one</returns>
        public static TduFile[] LoadTopicForReadOnly(DB.Topic topic, DB.Culture culture)
        {
            TduFile[] returnedFiles = new TduFile[2];

            // Loading BNKs
            string databaseFolder  = LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database);
            string mainBnkFile     = string.Concat(databaseFolder, DB.GetBNKFileName(DB.Culture.Global));
            string resourceBnkFile = string.Concat(databaseFolder, DB.GetBNKFileName(culture));
            BNK    mainBnk         = TduFile.GetFile(mainBnkFile) as BNK;
            BNK    resourceBnk     = TduFile.GetFile(resourceBnkFile) as BNK;

            // Getting read-only files
            if (mainBnk != null && resourceBnk != null)
            {
                string dbPackedFileName = DB.GetFileName(DB.Culture.Global, topic);
                string fileName         =
                    EditHelper.Instance.PrepareFile(mainBnk, mainBnk.GetPackedFilesPaths(dbPackedFileName)[0]);
                string dbrPackedFileName = DB.GetFileName(culture, topic);
                string resourceFileName  =
                    EditHelper.Instance.PrepareFile(resourceBnk, resourceBnk.GetPackedFilesPaths(dbrPackedFileName)[0]);

                // Loading these files
                DB         main     = TduFile.GetFile(fileName) as DB;
                DBResource resource = TduFile.GetFile(resourceFileName) as DBResource;

                if (main == null || !main.Exists)
                {
                    throw new Exception(topic + " main database failure.");
                }
                if (resource == null || !resource.Exists)
                {
                    throw new Exception(string.Concat(topic, "-", culture, " resource database failure."));
                }

                // Filling array
                returnedFiles[0] = main;
                returnedFiles[1] = resource;
            }

            return(returnedFiles);
        }