Beispiel #1
0
 private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     // Main window is closed > cleaning...
     try
     {
         File2.RemoveTemporaryFolder(null, LibraryConstants.FOLDER_TEMP);
     }
     catch (Exception)
     {
         Log.Info("Unable to remove temporary folder - does not matter.");
     }
 }
Beispiel #2
0
        private void mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            // Suppression des tâches d'édition
            EditHelper.Instance.ClearTasks();

            // Nettoyage des fichiers temporaires
            try
            {
                File2.RemoveTemporaryFolder(null, LibraryConstants.FOLDER_TEMP);
            }
            catch (Exception)
            {
                // Silent exception!
                //Exception2.PrintStackTrace(ex);
                Log.Info("Unable to remove temporary folder - may be gone, already.");
            }

            // Settings
            Program.ApplicationSettings.Save();
        }
Beispiel #3
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);
                }
            }
        }