Beispiel #1
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();
        }
Beispiel #2
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();
        }
Beispiel #3
0
        /// <summary>
        /// Tries to retrieve TDU version by looking at Bnk1.map file size.
        /// </summary>
        /// <returns>TDU installed version or UNKNOWN value if not found.</returns>
        private static TduVersion _SearchForTduVersionFromMap()
        {
            TduVersion installedVersion = TduVersion.Unknown;

            // Locating Bnk1.map file
            string mapFileName = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.BnkMap);

            // DEBUG
            Log.Info("_SearchForTduVersionFromMap, Bnk1.map:" + mapFileName);

            // According to MAP size...
            FileInfo mapInfo = new FileInfo(mapFileName);

            if (mapInfo.Exists)
            {
                long mapSize = mapInfo.Length;

                Log.Info("Bnk1.map file found, size=" + mapSize);

                if (mapSize < MAP.SIZE_1_66_MAP)
                {
                    installedVersion = TduVersion.V1_45;
                }
                else if (mapSize < MAP.SIZE_1_66_MEGAPACK_MAP)
                {
                    installedVersion = TduVersion.V1_66;
                }
                else
                {
                    installedVersion = TduVersion.V1_66_Megapack;
                }
            }

            return(installedVersion);
        }
Beispiel #4
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);
                }
            }
        }
Beispiel #5
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++;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Se charge de nettoyer cette saleté de radial.cdb
        /// Retourne la taille du fichier s'il est présent.
        /// </summary>
        /// <returns>La taille de radial.cdb, ou -1 s'il est absent</returns>
        public static long DeleteRadial()
        {
            string radialFileName = LibraryConstants.GetSpecialFile(LibraryConstants.TduSpecialFile.RadialCrap);
            long   radialSize     = -1;

            if (File.Exists(radialFileName))
            {
                radialSize = new FileInfo(radialFileName).Length;
                File.Delete(radialFileName);
            }

            return(radialSize);
        }
        /// <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();
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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;
        }
Beispiel #12
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);
            }
        }
Beispiel #13
0
 /// <summary>
 /// Which value the variable should refer to
 /// </summary>
 internal override string GetValue()
 {
     return(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.FrontEndAllRes));
 }
Beispiel #14
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);
            }
        }
Beispiel #15
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);
            }
        }
Beispiel #16
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);
            }
        }
Beispiel #17
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);
                }
            }
        }
Beispiel #18
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;
                }
            }
        }
Beispiel #19
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);
            }
        }
Beispiel #20
0
 internal override string GetValue()
 {
     return(LibraryConstants.GetSpecialFolder(LibraryConstants.TduSpecialFolder.Bnk));
 }
Beispiel #21
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);
            }
        }