Exemplo n.º 1
0
        /// <summary>
        /// Initializes standard components for this helper
        /// </summary>
        /// <param name="patchToRun"></param>
        /// <param name="filePath"></param>
        /// <param name="currentCulture"></param>
        /// <param name="log">Log to write events to (optional)</param>
        private static void _InitializeComponents(PCH patchToRun, string filePath, DB.Culture currentCulture, Log log)
        {
            // Testing TDU main folder
            _TestTduInstallPath();

            // Messages
            _Messages.Clear();

            // Current patch
            _CurrentPatch = patchToRun;

            // Current path
            // BUG_64: using specified folder as startup directory
            _CurrentPath = filePath;

            // Culture
            _CurrentCulture = currentCulture;

            // Logger
            if (log == null)
            {
                _PatchLog = new Log(null);
            }
            else
            {
                _PatchLog = log;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renvoie la langue actuelle pour la base de données
        /// </summary>
        public DB.Culture GetCurrentCulture()
        {
            string cultureCode = TduLanguage.Substring(0, 2);

            DB.Culture culture = (DB.Culture)Enum.Parse(typeof(DB.Culture), cultureCode);
            return(culture);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructeur principal
        /// </summary>
        /// <param name="dbFileName">Nom du fichier de bases de données à charger</param>
        internal DBResource(string dbFileName)
        {
            _FileName       = dbFileName;
            _CurrentCulture = (DB.Culture)Enum.Parse(typeof(DB.Culture), File2.GetExtensionFromFilename(_FileName).ToUpper());

            // Lecture
            _ReadData();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets contents on information label
        /// </summary>
        private void _UpdateInfoLabel()
        {
            DB.Culture currentCulture = Program.ApplicationSettings.GetCurrentCulture();

            _ResourceValue = _DbResource.GetEntryFromId(_ResourceId).value;

            resourceInfoLabel.Text = string.Format(_FORMAT_INFO_LABEL, _ResourceId, _DbResource.CurrentTopic, currentCulture,
                                                   _ResourceValue);
        }
Exemplo n.º 5
0
        /// <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;
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <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) !");
                }
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles patch execution
        /// </summary>
        /// <param name="patchToRun">Patch instance to execute</param>
        /// <param name="log">Log to store events - can be null</param>
        /// <param name="filePath">Path for patch files</param>
        /// <param name="currentCulture">Culture used in DB files</param>
        /// <param name="installGroups">List of instruction groups to install</param>
        /// <returns></returns>
        public static RunResult RunPatch(PCH patchToRun, Log log, string filePath, DB.Culture currentCulture, List <string> installGroups)
        {
            RunResult result           = RunResult.NotRun;
            int       warningCount     = 0;
            int       instructionCount = 1;

            if (patchToRun == null || string.IsNullOrEmpty(filePath))
            {
                return(result);
            }

            // Group handling
            if (installGroups == null)
            {
                installGroups = new List <string> {
                    PCH.REQUIRED_GROUP_NAME
                }
            }
            ;

            _InitializeComponents(patchToRun, filePath, currentCulture, log);

            _PatchLog.WriteEvent(string.Format(_MSG_RUNNING_PATCH, patchToRun.FileName, patchToRun.PatchInstructions.Count));
            _PatchLog.WriteEvent(string.Format(_MSG_CHOSEN_GROUPS, List2.ToString(installGroups)));

            // Instruction browsing
            bool isCritical = false;

            if (patchToRun.PatchInstructions.Count == 0)
            {
                _PatchLog.WriteEvent(_MSG_NO_INSTRUCTIONS);
            }
            else
            {
                foreach (PatchInstruction instr in patchToRun.PatchInstructions)
                {
                    if (instr.Enabled)
                    {
                        if (installGroups.Contains(instr.Group.name))
                        {
                            result = _ProcessInstruction(instr, instructionCount);

                            // Result analysis
                            switch (result)
                            {
                            case RunResult.RunWithErrors:
                                // Critical failure > patch stopped
                                _PatchLog.WriteEvent(string.Format(_MSG_INSTRUCTION_END_ERR, instr.Order));
                                isCritical = true;
                                break;

                            case RunResult.RunWithWarnings:
                                // Non-critical failure > next instruction
                                _PatchLog.WriteEvent(string.Format(_MSG_INSTRUCTION_END_WARN, instr.Order, 1));
                                warningCount++;
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            // Refused instruction
                            _PatchLog.WriteEvent(string.Format(_MSG_INSTRUCTION_REFUSED, instr.Order, instr.Group.name));
                        }

                        if (isCritical)
                        {
                            break;
                        }
                    }
                    else
                    {
                        // Disabled instruction
                        _PatchLog.WriteEvent(string.Format(_MSG_INSTRUCTION_DISABLED, instr.Order));
                    }

                    // EVO_100: Progress update
                    if (_ProgressBar != null)
                    {
                        _ProgressBar.PerformStep();
                    }

                    if (_TSProgressBar != null)
                    {
                        _TSProgressBar.PerformStep();
                    }

                    Application.DoEvents();

                    instructionCount++;
                }
            }

            switch (result)
            {
            case RunResult.NotRun:
                _PatchLog.WriteEvent(_MSG_NOT_RUN);
                break;

            case RunResult.RunWithErrors:
                _PatchLog.WriteEvent(_MSG_FINISHING_ERR);
                break;

            case RunResult.OK:
                if (warningCount > 0)
                {
                    _PatchLog.WriteEvent(string.Format(_MSG_FINISHING_WAR, warningCount));
                    result = RunResult.RunWithWarnings;
                }
                else
                {
                    _PatchLog.WriteEvent(_MSG_FINISHING_OK);
                }
                break;

            default:
                break;
            }

            // Displaying collected messages
            _DisplayCollectedMessages();

            // Saving Logger to file
            _PatchLog.SaveToFile(_PatchLog.Name);

            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Handles single execution
        /// </summary>
        /// <param name="patchToRun">Patch instance to execute</param>
        /// <param name="instructionNumber">Instruction number to execute</param>
        /// <param name="log">Log for message storing</param>
        /// <param name="tduPath">Path for tdu files; can be null = default</param>
        /// <param name="filePath">Path for patch files</param>
        /// <param name="currentCulture"></param>
        /// <returns></returns>
        public static RunResult RunSingleInstruction(PCH patchToRun, int instructionNumber, Log log, string tduPath, string filePath, DB.Culture currentCulture)
        {
            RunResult result = RunResult.NotRun;

            if (patchToRun == null || string.IsNullOrEmpty(filePath))
            {
                return(result);
            }

            _InitializeComponents(patchToRun, filePath, currentCulture, log);

            // Instruction finding
            PatchInstruction instr = patchToRun.GetInstruction(instructionNumber);

            if (instr != null)
            {
                result = _ProcessInstruction(instr, instructionNumber);

                switch (result)
                {
                case RunResult.RunWithWarnings:
                    // Non-critical failure > next instruction
                    _PatchLog.WriteEvent(string.Format(_MSG_INSTRUCTION_END_WARN, instr.Order, 1));
                    break;

                case RunResult.RunWithErrors:
                    _PatchLog.WriteEvent(_MSG_FINISHING_ERR);
                    break;

                default:
                    _PatchLog.WriteEvent(_MSG_FINISHING_OK);
                    break;
                }
            }

            // Displaying collected messages
            _DisplayCollectedMessages();

            // Saving Logger to file
            _PatchLog.SaveToFile(_PatchLog.Name);

            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Runs all install tasks. Takes chosen install groups into account
        /// </summary>
        /// <param name="patch"></param>
        /// <param name="log"></param>
        /// <param name="culture"></param>
        /// <param name="isInstall"></param>
        /// <param name="chosenInstallGroups"></param>
        public static void RunAll(PCH patch, Log log, DB.Culture culture, bool isInstall, List <string> chosenInstallGroups)
        {
            try
            {
                // 1. Preparatory : folders
                try
                {
                    // Setting transversal values
                    if (patch == null)
                    {
                        throw new Exception("No patch specified.");
                    }

                    _CurrentPatch = patch;

                    if (log != null)
                    {
                        _Log = log;
                    }

                    if (string.IsNullOrEmpty(Tools.TduPath))
                    {
                        throw new Exception("Invalid TDU install path specified.");
                    }

                    _Culture       = culture;
                    _InstallGroups = chosenInstallGroups;

                    // Go!
                    PreparatoryTask.Run();
                }
                catch (Exception ex)
                {
                    Log.Error("Install error when executing preparatory task.", ex);
                    throw;
                }

                // 2. Running patch
                try
                {
                    PatchTask.Run();
                }
                catch (Exception ex)
                {
                    Log.Error("Error when running core patch instructions.", ex);
                    throw;
                }

                // 3. Finalization
                try
                {
                    FinalizationTask.Run(isInstall);
                }
                catch (Exception ex)
                {
                    Log.Error("Error when executing finalization task.", ex);
                    throw;
                }
            }
            catch (Exception ex)
            {
                if (isInstall)
                {
                    throw new Exception("Current patch can't be installed:\r\n" + ex.Message, ex);
                }

                throw new Exception("Current patch can't be uninstalled:\r\n" + ex.Message, ex);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Runs all install tasks
 /// </summary>
 /// <param name="patch"></param>
 /// <param name="patchLog"></param>
 /// <param name="culture"></param>
 /// <param name="isInstall"></param>
 public static void RunAll(PCH patch, Log patchLog, DB.Culture culture, bool isInstall)
 {
     RunAll(patch, patchLog, culture, isInstall, null);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Loads vehicle data from database and reference
        /// </summary>
        /// <param name="slotRef">Reference of vehicle slot to load</param>
        private void _LoadVehicleData(string slotRef)
        {
            if (string.IsNullOrEmpty(slotRef))
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            try
            {
                StatusBarLogManager.ShowEvent(this, _STATUS_LOADING_VEHICLE);

                // Cleaning tasks
                _ClearCurrentTasks();

                _CurrentVehicle  = slotRef;
                _CurrentSlotName = VehicleSlotsHelper.SlotReferenceReverse[slotRef];

                // Loading database
                DB.Culture        currentCulture = Program.ApplicationSettings.GetCurrentCulture();
                EditHelper.Task[] currentTasks;
                string            dbBnkFile = Program.ApplicationSettings.TduMainFolder + LibraryConstants.FOLDER_DB + DB.GetBNKFileName(DB.Culture.Global);
                BNK    bnkFile         = TduFile.GetFile(dbBnkFile) as BNK;
                string resourceBnkFile = Program.ApplicationSettings.TduMainFolder + LibraryConstants.FOLDER_DB + DB.GetBNKFileName(currentCulture);
                BNK    rBnkFile        = TduFile.GetFile(resourceBnkFile) as BNK;

                // 1.CarRims
                TduFile[] currentFiles = DatabaseHelper.LoadTopicForEdit(DB.Topic.CarRims, DB.Culture.Global, bnkFile, rBnkFile, out currentTasks);

                _CurrentCarRimsTask = currentTasks[0];
                _CarRimsTable       = currentFiles[0] as DB;

                // 2.Rims
                currentFiles             = DatabaseHelper.LoadTopicForEdit(DB.Topic.Rims, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentRimsTask         = currentTasks[0];
                _CurrentRimsResourceTask = currentTasks[1];
                _RimsTable    = currentFiles[0] as DB;
                _RimsResource = currentFiles[1] as DBResource;

                // 3.CarPhysicsData
                currentFiles                = DatabaseHelper.LoadTopicForEdit(DB.Topic.CarPhysicsData, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentPhysicsTask         = currentTasks[0];
                _CurrentPhysicsResourceTask = currentTasks[1];
                _PhysicsTable               = currentFiles[0] as DB;
                _PhysicsResource            = currentFiles[1] as DBResource;

                // 4.Brands
                currentFiles               = DatabaseHelper.LoadTopicForEdit(DB.Topic.Brands, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentBrandsTask         = currentTasks[0];
                _CurrentBrandsResourceTask = currentTasks[1];
                _BrandsTable               = currentFiles[0] as DB;
                _BrandsResource            = currentFiles[1] as DBResource;

                // 5.CarShops
                currentFiles                 = DatabaseHelper.LoadTopicForEdit(DB.Topic.CarShops, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentCarShopsTask         = currentTasks[0];
                _CurrentCarShopsResourceTask = currentTasks[1];
                _CarShopsTable               = currentFiles[0] as DB;
                _CarShopsResource            = currentFiles[1] as DBResource;

                // 6.CarPacks
                currentFiles         = DatabaseHelper.LoadTopicForEdit(DB.Topic.CarPacks, DB.Culture.Global, bnkFile, rBnkFile, out currentTasks);
                _CurrentCarPacksTask = currentTasks[0];
                _CarPacksTable       = currentFiles[0] as DB;

                // 7.Colors
                currentFiles                  = DatabaseHelper.LoadTopicForEdit(DB.Topic.CarColors, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentCarColorsTask         = currentTasks[0];
                _CurrentCarColorsResourceTask = currentTasks[1];
                _CarColorsTable               = currentFiles[0] as DB;
                _CarColorsResource            = currentFiles[1] as DBResource;

                // 8.Interior
                currentFiles                 = DatabaseHelper.LoadTopicForEdit(DB.Topic.Interior, currentCulture, bnkFile, rBnkFile, out currentTasks);
                _CurrentInteriorTask         = currentTasks[0];
                _CurrentInteriorResourceTask = currentTasks[1];
                _InteriorTable               = currentFiles[0] as DB;
                _InteriorResource            = currentFiles[1] as DBResource;

                // 9.Colors id reference
                ColorsHelper.InitIdReference(_CarColorsResource, _InteriorResource);

                // 10.Cameras
                string camBinFile = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.CamerasBin);

                _CameraData = TduFile.GetFile(camBinFile) as Cameras;

                /* GUI */
                // Install Tab
                _InitializeInstallContents();

                // Camera-IK Tab
                _RefreshCameraIKContents();

                // Datasheet tab
                _InitializeDatasheetContents();

                // Dealers tab
                _InitializeDealersContents();

                // Tuner tab
                _InitializeTunerContents();

                // Physics tab
                _InitializePhysicsContents();

                // Colors tab
                _InitializeColorsContents();

                // Modification flags
                _IsDatabaseModified = false;
                _IsCameraModified   = false;

                // Clearing state vars
                _CurrentAvailabilitySpot = null;
                _CurrentTuningBrand      = null;

                // Vehicle name display
                _UpdateSlotAndModName();

                // Tabs are enabled
                vehicleEditTabControl.Enabled = true;

                StatusBarLogManager.ShowEvent(this, _STATUS_VEHICLE_READY);
            }
            catch (Exception ex)
            {
                // All tasks must be cleaned
                _ClearCurrentTasks();

                // Processing special error messages
                if (EditHelper.ERROR_CODE_TASK_EXISTS.Equals(ex.Message))
                {
                    MessageBoxes.ShowError(this, new Exception(_ERROR_LOADING_VEHICLE_CONFLICT, ex));
                }
                else
                {
                    MessageBoxes.ShowError(this, new Exception(_ERROR_LOADING_VEHICLE, ex));
                }

                StatusBarLogManager.ShowEvent(this, "");
            }

            Cursor = Cursors.Default;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Updates vehicle list according to slots reference
        /// </summary>
        private void _RefreshVehicleList()
        {
            Cursor = Cursors.WaitCursor;

            vehicleListView.Items.Clear();
            vehicleListView.Groups.Clear();

            // Taking list mode into account (original/modded names)
            Dictionary <string, string> originalNamesByModdedNames = null;
            SortedStringCollection      vehicleNames = new SortedStringCollection();

            if (_IsShowOriginalNames)
            {
                foreach (string vehicleName in VehicleSlotsHelper.SlotReference.Keys)
                {
                    vehicleNames.Add(vehicleName);
                }
            }
            else
            {
                // Loading database for read-only
                DB.Culture currentCulture = Program.ApplicationSettings.GetCurrentCulture();

                // Physics
                TduFile[]  loadedFiles = DatabaseHelper.LoadTopicForReadOnly(DB.Topic.CarPhysicsData, currentCulture);
                DB         physics     = loadedFiles[0] as DB;
                DBResource rPhysics    = loadedFiles[1] as DBResource;

                // Brands
                loadedFiles = DatabaseHelper.LoadTopicForReadOnly(DB.Topic.Brands, currentCulture);

                DB         brands  = loadedFiles[0] as DB;
                DBResource rBrands = loadedFiles[1] as DBResource;

                originalNamesByModdedNames = new Dictionary <string, string>();

                foreach (KeyValuePair <string, string> anotherPair in VehicleSlotsHelper.SlotReference)
                {
                    // Brand name
                    string brandName =
                        NamesHelper.GetVehicleBrandName(anotherPair.Value, physics, brands, rBrands);
                    // Vehicle name
                    string vehicleName =
                        NamesHelper.GetVehicleFullName(anotherPair.Value, false, physics, rPhysics,
                                                       brands, rBrands);
                    string moddedName = (brandName.ToUpper() + " " + vehicleName).Trim();

                    // To maintain 2 identical names
                    while (originalNamesByModdedNames.ContainsKey(moddedName))
                    {
                        moddedName += _SYMBOL_PRIME;
                    }

                    originalNamesByModdedNames.Add(moddedName, anotherPair.Key);
                    vehicleNames.Add(moddedName);
                }
            }

            // Reference browsing
            foreach (string vehicleName in vehicleNames)
            {
                ListViewItem li = new ListViewItem(vehicleName);

                // Group by brand (first word in fact)
                string        currentBrand = vehicleName.Split(' ')[0];
                ListViewGroup currentGroup = new ListViewGroup(currentBrand, currentBrand);

                if (!vehicleListView.Groups.Contains(currentGroup))
                {
                    vehicleListView.Groups.Add(currentGroup);
                }

                li.Group = vehicleListView.Groups[currentBrand];

                // Computing vehicle name
                string slotName = null;

                if (_IsShowOriginalNames)
                {
                    slotName = vehicleName;
                }
                else if (originalNamesByModdedNames != null && originalNamesByModdedNames.ContainsKey(vehicleName))
                {
                    slotName = originalNamesByModdedNames[vehicleName];
                }

                if (slotName != null && VehicleSlotsHelper.SlotReference.ContainsKey(slotName))
                {
                    string vehicleRef = VehicleSlotsHelper.SlotReference[slotName];

                    // Tag
                    li.Tag = vehicleRef;

                    VehicleSlotsHelper.VehicleInfo currentInfo = VehicleSlotsHelper.VehicleInformation[vehicleRef];

                    // Non-moddable vehicles are faded
                    // Image depending on car or bike type
                    if (currentInfo.isBike)
                    {
                        if (currentInfo.isModdable)
                        {
                            li.ImageIndex = (int)_ImageIndex.Bike;
                        }
                        else
                        {
                            li.ImageIndex = (int)_ImageIndex.NonModdableBike;
                        }
                    }
                    else
                    {
                        if (currentInfo.isModdable)
                        {
                            li.ImageIndex = (int)_ImageIndex.Car;
                        }
                        else
                        {
                            li.ImageIndex = (int)_ImageIndex.NonModdableCar;
                        }
                    }

                    vehicleListView.Items.Add(li);
                }
            }

            Cursor = Cursors.Default;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Manages component install/uninstall
        /// </summary>
        /// <param name="isInstall">true if install / false if uninstall</param>
        private void _Process(bool isInstall)
        {
            // Current culture
            //string selectedCulture = gameCultureComboBox.Text.Substring(0, 2);
            //DB.Culture currentCulture = (DB.Culture) Enum.Parse(typeof (DB.Culture), selectedCulture);
            // EVO_147
            const DB.Culture currentCulture = DB.Culture.US;

            // Selects right patch according to install/uninstall case
            PCH currentPatch = (isInstall ? _CurrentInstallPatch : _CurrentUninstallPatch);

            // TDU folder (override)
            Tools.TduPath = tduPathTextbox.Text;

            // Authorization checks
            // If specified ref matches a car pack vehicle, TDU version must be '1.66+megapack'
            if (Tools.InstalledTduVersion != Tools.TduVersion.V1_66_Megapack)
            {
                // Loading reference
                try
                {
                    VehicleSlotsHelper.InitReference(Application.StartupPath + LibraryConstants.FOLDER_XML);

                    // Getting vehicle information...
                    if (!Tools.KEY_MISC_SLOT.Equals(_CurrentInstallPatch.SlotRef) &&
                        VehicleSlotsHelper.VehicleInformation.ContainsKey(currentPatch.SlotRef))
                    {
                        VehicleSlotsHelper.VehicleInfo info =
                            VehicleSlotsHelper.VehicleInformation[currentPatch.SlotRef];

                        if (info.isAddon)
                        {
                            MessageBoxes.ShowWarning(this, _ERROR_MOD_NOT_ALLOWED);
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxes.ShowError(this, ex);
                    return;
                }
            }

            // If another mod is installed on current slot...
            // Exception for Patch 1.67d
            if (isInstall &&
                InstallHelper.IsAnotherModInstalled(currentPatch.SlotRef, currentPatch.Name) &&
                !AppConstants.SLOT_COMMUNITY_PATCH.Equals(currentPatch.SlotRef))
            {
                MessageBoxes.ShowWarning(this, string.Format(_ERROR_ANOTHER_MOD_INSTALLED, InstallHelper.GetInstalledModName(currentPatch.SlotRef)));
                return;
            }

            // EVO_134 Group handling, if necessary
            List <string> chosenInstallGroups = new List <string> {
                PCH.REQUIRED_GROUP_NAME
            };

            if (isInstall && currentPatch.Groups.Count > 1)
            {
                GroupsDialog dlg = new GroupsDialog(_CurrentInstallPatch);
                DialogResult dr  = dlg.ShowDialog(this);

                if (dr == DialogResult.OK)
                {
                    chosenInstallGroups = dlg.ChosenGroups;
                }
                else
                {
                    return;
                }
            }

            // Patch logger init
            string logFile  = Application.StartupPath + LibraryConstants.FILE_LOG_PATCH;
            Log    patchLog = new Log(logFile);

            patchLog.Appenders.Add(new ConsoleAppender());

            // EVO_100: progress bar init
            progressPanel.Visible = true;
            infoLabel.Visible     = false;

            mainProgressBar.Minimum = 0;
            mainProgressBar.Maximum = currentPatch.PatchInstructions.Count;
            mainProgressBar.Step    = 1;
            mainProgressBar.Value   = 0;
            PatchHelper.ProgressBar = mainProgressBar;

            // Using new helper
            try
            {
                InstallHelper.RunAll(currentPatch, patchLog, currentCulture, isInstall, chosenInstallGroups);
                Application.DoEvents();

                // Showing gui messages
                foreach (string message in PatchHelper.Messages)
                {
                    MessageBoxes.ShowWarning(this, message);
                }

                // OK
                MessageBoxes.ShowInfo(this, isInstall ? _MESSAGE_PATCH_SUCCESS : _MESSAGE_PATCH_UNINSTALL_SUCCESS);

                // Refreshing window contents
                //_LoadData(_CurrentInstallPatch.FileName, (_CurrentUninstallPatch == null) ? null : _CurrentUninstallPatch.FileName);

                // Contextual information has to be updated
                _UpdateContextualControls();
            }
            catch (Exception ex)
            {
                // Showing messages first
                foreach (string message in PatchHelper.Messages)
                {
                    MessageBoxes.ShowWarning(this, message);
                }

                if (PatchHelper.Messages.Count == 0)
                {
                    MessageBoxes.ShowError(this, ex);
                }
            }
            finally
            {
                // Hiding progress bar
                progressPanel.Visible = false;
            }
        }
Exemplo n.º 17
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);
        }