Ejemplo n.º 1
0
        private void trackTimer_Tick(object sender, EventArgs e)
        {
            // Timer interval reached
            // For each selected custom track, locate replaced name in DFE folder
            foreach (ListViewItem anotherItem in customTracksListView.Items)
            {
                try
                {
                    DFE currentTrack = anotherItem.Tag as DFE;

                    if (currentTrack != null)
                    {
                        FileInfo customTrackInfo   = new FileInfo(currentTrack.FileName);
                        DFE      replacedChallenge = _GetReplacedChallenge(customTrackInfo.Name);

                        if (replacedChallenge != null)
                        {
                            FileInfo replacedChallengeInfo = new FileInfo(replacedChallenge.FileName);
                            string   tduDfeFileName        = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Data_DFE), replacedChallengeInfo.Name);
                            FileInfo dfeTrackInfo          = new FileInfo(tduDfeFileName);

                            if (anotherItem.Checked)
                            {
                                // Checked > synchronization
                                if (dfeTrackInfo.Exists && dfeTrackInfo.LastWriteTime != customTrackInfo.LastWriteTime)
                                {
                                    File.Copy(currentTrack.FileName, tduDfeFileName, true);

                                    string message = string.Format(_FORMAT_TRACK_SYNC_OK, currentTrack.TrackName, replacedChallenge.TrackName);

                                    StatusBarLogManager.ShowEvent(this, message);
                                    SystemSounds.Exclamation.Play();
                                }
                            }

                            /*else
                             * {
                             *  // Unchecked > restoration
                             *  // Disabled beacause of conflicts
                             *  if (dfeTrackInfo.Exists && dfeTrackInfo.LastWriteTime != replacedChallengeInfo.LastWriteTime)
                             *  {
                             *      File.Copy(replacedChallenge.FileName, tduDfeFileName, true);
                             *
                             *      string message = string.Format(_FORMAT_TRACK_RESTORE_OK, replacedChallenge.TrackName);
                             *
                             *      StatusBarLogManager.ShowEvent(this, message);
                             *      SystemSounds.Exclamation.Play();
                             *  }
                             * }*/
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("A track synchronization issue has occured.", ex);
                }
            }
        }
Ejemplo n.º 2
0
        /// <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++;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Actualise l'arborescence
        /// </summary>
        private void _RefreshTreeView()
        {
            // On efface tout
            folderTreeView.Nodes.Clear();
            bnkStatusLabel.Text = bnkStatusLabelCountSize.Text = "";

            StatusBarLogManager.ShowEvent(this, _STATUS_NO_BNK_SELECTED);

            // Le dossier des bnk est-il valide ?
            DirectoryInfo di = new DirectoryInfo(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Bnk));

            if (!di.Exists)
            {
                // On efface tout
                bnkListView.Items.Clear();
                _ClearContentLists();

                MessageBoxes.ShowError(this, _ERROR_INVALID_TDU_PATH);
                return;
            }

            Cursor = Cursors.WaitCursor;

            // Noeud racine
            TreeNode rootNode = new TreeNode(_TREENODE_ROOT)
            {
                Tag                = LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Bnk),
                ImageIndex         = (int)ItemPictures.ClosedFolder,
                SelectedImageIndex = (int)ItemPictures.OpenedFolder
            };

            folderTreeView.Nodes.Add(rootNode);

            // Parcours des dossiers
            try
            {
                _AddFoldersToTreeView(rootNode);

                // On déploie le noeud racine
                rootNode.Expand();

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBoxes.ShowError(this, ex);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns all player profile names located into Documents\TDU folder
        /// </summary>
        /// <returns></returns>
        public static string[] GetPlayerProfiles()
        {
            string        savegamePath      = LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Savegame);
            DirectoryInfo savegameDirectory = new DirectoryInfo(savegamePath);

            if (savegameDirectory.Exists)
            {
                // Quick and easy way: take all subfolders as there should not be any custom folder here...
                DirectoryInfo[] subDirectories   = savegameDirectory.GetDirectories();
                string[]        returnedProfiles = new string[subDirectories.Length];
                int             i = 0;

                foreach (DirectoryInfo anotherSubDir in subDirectories)
                {
                    returnedProfiles[i++] = anotherSubDir.Name;
                }

                return(returnedProfiles);
            }

            throw new Exception("Unable to locate TDU savegames: " + savegamePath);
        }
Ejemplo n.º 6
0
 internal override string GetValue()
 {
     return(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Bnk));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameters
            string databaseIdentifier = _GetParameter(PatchInstructionParameter.ParameterName.databaseId);
            string rimName            = _GetParameter(PatchInstructionParameter.ParameterName.rimName);
            string tempFolder         = "";

            try
            {
                // 1. Extracting brands
                BNK    databaseBNK;
                string rimsDBFileName;
                string rimsDBFilePath;

                try
                {
                    string bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(PatchHelper.CurrentCulture));

                    rimsDBFileName = DB.GetFileName(PatchHelper.CurrentCulture, DB.Topic.Rims);
                    databaseBNK    = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK == null)
                    {
                        throw new Exception("Database BNK file is invalid.");
                    }

                    // Files are extracted to a temporary location
                    rimsDBFilePath = databaseBNK.GetPackedFilesPaths(rimsDBFileName)[0];

                    tempFolder = File2.SetTemporaryFolder(null, LibraryConstants.FOLDER_TEMP, true);
                    databaseBNK.ExtractPackedFile(rimsDBFilePath, tempFolder, true);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to extract DB file.", ex);
                }

                // 2. Getting TduFile
                DBResource rimsDBResource;

                try
                {
                    rimsDBResource = TduFile.GetFile(tempFolder + @"\" + rimsDBFileName) as DBResource;

                    if (rimsDBResource == null || !rimsDBResource.Exists)
                    {
                        throw new Exception("Extracted rim db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents.", ex);
                }

                // 3. Setting value in DB file
                DBResource.Entry rimsEntry = rimsDBResource.GetEntryFromId(databaseIdentifier);

                try
                {
                    if (rimsEntry.isValid)
                    {
                        rimsEntry.value = rimName;
                        rimsDBResource.UpdateEntry(rimsEntry);
                    }
                    else
                    {
                        throw new Exception("Unable to retrieve a DB entry for identifier: " + databaseIdentifier);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to locate DB entry to update.", ex);
                }

                // 4. Saving
                try
                {
                    rimsDBResource.Save();
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save DB files.", ex);
                }

                // 5. File replacing
                try
                {
                    // Rims
                    databaseBNK.ReplacePackedFile(rimsDBFilePath, tempFolder + @"\" + rimsDBFileName);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to replace database files in BNK.", ex);
                }
            }
            finally
            {
                // Cleaning up
                try
                {
                    File2.RemoveTemporaryFolder(null, tempFolder);
                }
                catch (Exception ex)
                {
                    // Silent
                    Exception2.PrintStackTrace(ex);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameter
            string vehicleRef = _GetParameter(PatchInstructionParameter.ParameterName.vehicleDatabaseId);

            // Modifying corresponding topic
            EditHelper.Task dbTask      = new EditHelper.Task();
            string          bnkFilePath = "";

            try
            {
                string dbFileName = null;

                // 1. Creating edit task
                try
                {
                    bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(DB.Culture.Global));

                    BNK databaseBNK = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK != null)
                    {
                        dbFileName = DB.GetFileName(DB.Culture.Global, DB.Topic.CarShops);
                        dbTask     = EditHelper.Instance.AddTask(databaseBNK, databaseBNK.GetPackedFilesPaths(dbFileName)[0], true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create edit task on BNK file: " + bnkFilePath, ex);
                }

                // 2. Getting TduFile
                DB db;

                try
                {
                    db = TduFile.GetFile(dbTask.extractedFile) as DB;

                    if (db == null || !db.Exists)
                    {
                        throw new Exception("Extracted db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents: " + dbFileName, ex);
                }

                // 3. Setting values in DB file
                DatabaseHelper.RemoveValueFromAnyColumn(db, vehicleRef, DatabaseConstants.COMPACT1_PHYSICS_DB_RESID);

                Log.Info("Entry updating completed: " + vehicleRef);

                // 4. Saving
                try
                {
                    db.Save();
                    EditHelper.Instance.ApplyChanges(dbTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save BNK file: " + bnkFilePath, ex);
                }
            }
            finally
            {
                // Cleaning up
                EditHelper.Instance.RemoveTask(dbTask);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Parameters
            string vehicleName = _GetParameter(PatchInstructionParameter.ParameterName.slotFullName);
            string cameraId    = _GetParameter(PatchInstructionParameter.ParameterName.cameraIKIdentifier);

            // Loading reference
            VehicleSlotsHelper.InitReference(PatchHelper.CurrentPath);

            // Checking validity
            if (!VehicleSlotsHelper.SlotReference.ContainsKey(vehicleName))
            {
                throw new Exception("Specified vehicle name is not supported: " + vehicleName);
            }

            if (!VehicleSlotsHelper.CamReference.ContainsKey(cameraId))
            {
                throw new Exception("Specified camera identifier is not supported: " + cameraId);
            }

            // Edit task
            EditHelper.Task task = new EditHelper.Task();

            try
            {
                try
                {
                    string bnkFileName = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(DB.Culture.Global));
                    BNK    dbBnkFile   = TduFile.GetFile(bnkFileName) as BNK;

                    if (dbBnkFile != null)
                    {
                        string dbFilePath =
                            dbBnkFile.GetPackedFilesPaths(DB.GetFileName(DB.Culture.Global, DB.Topic.CarPhysicsData))[0];

                        task =
                            EditHelper.Instance.AddTask(dbBnkFile, dbFilePath, true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to get TDU database contents in DB.BNK.", ex);
                }

                // Opens packed file
                DB physicsDB = TduFile.GetFile(task.extractedFile) as DB;

                if (physicsDB == null)
                {
                    throw new Exception("Unable to get CarPhysicsData information.");
                }

                // Changes camera
                try
                {
                    string vehicleRef = VehicleSlotsHelper.SlotReference[vehicleName];

                    VehicleSlotsHelper.ChangeCameraById(vehicleRef, cameraId, physicsDB);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to use new camera set: " + cameraId + " for " + vehicleName, ex);
                }

                // Saving
                try
                {
                    physicsDB.Save();
                    EditHelper.Instance.ApplyChanges(task);
                    EditHelper.Instance.RemoveTask(task);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save and replace file in BNK.", ex);
                }
            }
            finally
            {
                EditHelper.Instance.RemoveTask(task);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameter
            string vehicleRef   = _GetParameter(PatchInstructionParameter.ParameterName.vehicleDatabaseId);
            string spotAndSlots = _GetParameter(PatchInstructionParameter.ParameterName.resourceValues);

            // Modifying corresponding topic
            EditHelper.Task dbTask      = new EditHelper.Task();
            string          bnkFilePath = "";

            try
            {
                string dbFileName = null;

                // 1. Creating edit task
                try
                {
                    bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(DB.Culture.Global));

                    BNK databaseBNK = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK != null)
                    {
                        dbFileName = DB.GetFileName(DB.Culture.Global, DB.Topic.CarShops);
                        dbTask     = EditHelper.Instance.AddTask(databaseBNK, databaseBNK.GetPackedFilesPaths(dbFileName)[0], true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create edit task on BNK file: " + bnkFilePath, ex);
                }

                // 2. Getting TduFile
                DB db;

                try
                {
                    db = TduFile.GetFile(dbTask.extractedFile) as DB;

                    if (db == null || !db.Exists)
                    {
                        throw new Exception("Extracted db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents: " + dbFileName, ex);
                }

                // 3. Setting values in DB file
                // One identifier (primary key: REF)
                List <Couple <string> > couples = Tools.ParseCouples(spotAndSlots);

                // Parsing couples
                foreach (Couple <string> couple in couples)
                {
                    string   spotRef = couple.FirstValue;
                    string[] slots   = couple.SecondValue.Split(new string[] { Tools.SYMBOL_VALUE_SEPARATOR3 }, StringSplitOptions.RemoveEmptyEntries);

                    // Does id exist ?
                    if (db.EntriesByPrimaryKey.ContainsKey(spotRef))
                    {
                        // Already exists > modify it
                        foreach (string anotherSlot in slots)
                        {
                            string slotColumnName =
                                string.Format(DatabaseConstants.SLOT_CARSHOPS_PATTERN_DB_COLUMN, anotherSlot);

                            DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(db, slotColumnName, spotRef, vehicleRef);
                        }

                        Log.Info("Entry updating completed for spot: " + spotRef + " - " + couple.SecondValue);
                    }
                    else
                    {
                        Log.Error("Specified location does not exist! " + spotRef, null);
                    }
                }

                Log.Info("Entry updating completed for vehicle: " + vehicleRef);

                // 4. Saving
                try
                {
                    db.Save();
                    EditHelper.Instance.ApplyChanges(dbTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save BNK file: " + bnkFilePath, ex);
                }
            }
            finally
            {
                // Cleaning up
                EditHelper.Instance.RemoveTask(dbTask);
            }
        }
Ejemplo n.º 11
0
        private void checkpointsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Click on Import Checkpoints...
            if (customTracksListView.SelectedItems.Count == 1)
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    // Select original (DFE challenge only)
                    DFE originalChallenge = customTracksListView.SelectedItems[0].Tag as DFE;

                    if (originalChallenge != null)
                    {
                        // Select IGE/DFE file(s) to append
                        bool   isNotFinished = true;
                        string profileFolder = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Savegame), @"\", Program.ApplicationSettings.PlayerProfile);
                        string igeFolder     = string.Concat(profileFolder, LibraryConstants.FOLDER_IGE);

                        openFileDialog.Title            = _TITLE_PICK_TRACK_TO_MERGE;
                        openFileDialog.Filter           = GuiConstants.FILTER_DFE_IGE_FILES;
                        openFileDialog.InitialDirectory = igeFolder;

                        while (isNotFinished)
                        {
                            // File selection
                            DialogResult dr = openFileDialog.ShowDialog(this);

                            if (dr == DialogResult.OK)
                            {
                                // Appends waypoints to end of original challenge
                                DFE additionalTrack = TduFile.GetFile(openFileDialog.FileName) as DFE;

                                if (additionalTrack == null)
                                {
                                    throw new Exception("Unable to load custom track: " + openFileDialog.FileName);
                                }

                                // Creating new Waypoint data
                                originalChallenge.MergeCheckpoints(additionalTrack);
                            }

                            // Continue ?
                            dr = MessageBoxes.ShowQuestion(this, _QUESTION_CONTINUE_MERGE, MessageBoxButtons.YesNo);

                            if (dr == DialogResult.No)
                            {
                                isNotFinished = false;
                            }
                        }

                        // End, saving DFE track
                        originalChallenge.Save();

                        // Refresh
                        _RefreshCustomList();

                        StatusBarLogManager.ShowEvent(this, _STATUS_MERGE_OK);
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameters
            string fileName = _GetParameter(PatchInstructionParameter.ParameterName.resourceFileName);
            string values   = _GetParameter(PatchInstructionParameter.ParameterName.resourceValues);

            // Modifying corresponding topic
            DB.Topic        currentTopic = (DB.Topic)Enum.Parse(typeof(DB.Topic), fileName);
            EditHelper.Task dbTask       = new EditHelper.Task();
            string          bnkFilePath  = "";

            try
            {
                string dbFileName = null;

                // 1. Creating edit task
                try
                {
                    bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(DB.Culture.Global));

                    BNK databaseBNK = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK != null)
                    {
                        dbFileName = DB.GetFileName(DB.Culture.Global, currentTopic);
                        dbTask     = EditHelper.Instance.AddTask(databaseBNK, databaseBNK.GetPackedFilesPaths(dbFileName)[0], true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create edit task on BNK file: " + bnkFilePath, ex);
                }

                // 2. Getting TduFile
                DB db;

                try
                {
                    db = TduFile.GetFile(dbTask.extractedFile) as DB;

                    if (db == null || !db.Exists)
                    {
                        throw new Exception("Extracted db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents: " + dbFileName, ex);
                }

                // 3. Setting values in DB file
                // One identifier (primary key: REF) or 2 identifiers (2 first columns)
                List <Couple <string> > couples = Tools.ParseCouples(values);
                string[] idArray = new string[couples.Count];
                int      counter = 0;

                // Parsing couples
                foreach (Couple <string> couple in couples)
                {
                    string id    = couple.FirstValue;
                    string value = couple.SecondValue;

                    // Does id exist ?
                    if (db.EntriesByPrimaryKey.ContainsKey(id))
                    {
                        // Already exists > modify it
                        DatabaseHelper.UpdateAllCellsFromTopicWherePrimaryKey(db, id, value);

                        Log.Info("Entry updating completed: " + id + " - " + value);
                    }
                    else
                    {
                        // Does not exist > create it
                        DatabaseHelper.InsertAllCellsIntoTopic(db, value);

                        Log.Info("Entry adding completed: " + value);
                    }

                    idArray[counter++] = id;
                }

                // 4. Saving
                try
                {
                    db.Save();
                    EditHelper.Instance.ApplyChanges(dbTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save BNK file: " + bnkFilePath, ex);
                }
            }
            finally
            {
                // Cleaning up
                EditHelper.Instance.RemoveTask(dbTask);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Which value the variable should refer to
 /// </summary>
 internal override string GetValue()
 {
     return(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.FrontEndAllRes));
 }
Ejemplo n.º 14
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameters
            string fileName = _GetParameter(PatchInstructionParameter.ParameterName.resourceFileName);
            string id       = _GetParameter(PatchInstructionParameter.ParameterName.databaseId);

            // Modifying corresponding topic
            DB.Topic        currentTopic = (DB.Topic)Enum.Parse(typeof(DB.Topic), fileName);
            EditHelper.Task dbTask       = new EditHelper.Task();
            string          bnkFilePath  = "";

            try
            {
                string dbFileName = null;

                // 1. Creating edit task
                try
                {
                    bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(DB.Culture.Global));

                    BNK databaseBNK = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK != null)
                    {
                        dbFileName = DB.GetFileName(DB.Culture.Global, currentTopic);
                        dbTask     = EditHelper.Instance.AddTask(databaseBNK, databaseBNK.GetPackedFilesPaths(dbFileName)[0], true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create edit task on BNK file: " + bnkFilePath, ex);
                }

                // 2. Getting TduFile
                DB db;

                try
                {
                    db = TduFile.GetFile(dbTask.extractedFile) as DB;

                    if (db == null || !db.Exists)
                    {
                        throw new Exception("Extracted db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents: " + dbFileName, ex);
                }

                // 3. Removing values in DB file
                DatabaseHelper.DeleteFromTopicWhereIdentifier(db, id);

                // 4. Saving
                try
                {
                    db.Save();
                    EditHelper.Instance.ApplyChanges(dbTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save BNK file: " + bnkFilePath, ex);
                }
            }
            finally
            {
                // Cleaning up
                EditHelper.Instance.RemoveTask(dbTask);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Checking parameters
            string fileName = _GetParameter(PatchInstructionParameter.ParameterName.resourceFileName);
            string values   = _GetParameter(PatchInstructionParameter.ParameterName.resourceValues);

            // For each language file
            DB.Topic currentTopic = (DB.Topic)Enum.Parse(typeof(DB.Topic), fileName);

            for (int i = 0; i < 8; i++)
            {
                DB.Culture      currentCulture   = (DB.Culture)Enum.Parse(typeof(DB.Culture), i.ToString());
                EditHelper.Task resourceTask     = new EditHelper.Task();
                string          bnkFilePath      = "";
                string          resourceFileName = null;

                // 1. Creating edit task
                try
                {
                    bnkFilePath = string.Concat(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Database), DB.GetBNKFileName(currentCulture));

                    BNK databaseBNK = TduFile.GetFile(bnkFilePath) as BNK;

                    if (databaseBNK != null)
                    {
                        resourceFileName = DB.GetFileName(currentCulture, currentTopic);
                        resourceTask     =
                            EditHelper.Instance.AddTask(databaseBNK,
                                                        databaseBNK.GetPackedFilesPaths(resourceFileName)[0], true);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to create edit task on BNK file: " + bnkFilePath, ex);
                }

                // 2. Getting TduFile
                DBResource resource;

                try
                {
                    resource = TduFile.GetFile(resourceTask.extractedFile) as DBResource;

                    if (resource == null || !resource.Exists)
                    {
                        throw new Exception("Extracted resource db file not found!");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to gain access to DB contents: " + resourceFileName, ex);
                }

                // 3. Setting values in DB file
                List <Couple <string> > couples = Tools.ParseCouples(values);

                // Parsing couples
                foreach (Couple <string> couple in couples)
                {
                    string id    = couple.FirstValue;
                    string value = couple.SecondValue;

                    // Does id exist ?
                    DBResource.Entry currentEntry = resource.GetEntryFromId(id);

                    if (currentEntry.isValid)
                    {
                        // Already exists > modify it
                        currentEntry.value = value;
                        resource.UpdateEntry(currentEntry);

                        Log.Info("Entry succesfully updated : " + id + " - " + value);
                    }
                    else
                    {
                        // Does not exist > create it
                        currentEntry.isValid = true;
                        currentEntry.id      = new ResourceIdentifier(id, currentTopic);
                        currentEntry.value   = value;
                        currentEntry.index   = resource.EntryList.Count + 1;
                        resource.InsertEntry(currentEntry);

                        Log.Info("Entry succesfully added : " + id + " - " + value);
                    }
                }

                // 4. Saving
                try
                {
                    resource.Save();
                    EditHelper.Instance.ApplyChanges(resourceTask);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to save BNK file: " + bnkFilePath, ex);
                }

                // 5. Cleaning up
                EditHelper.Instance.RemoveTask(resourceTask);
            }
        }