Ejemplo n.º 1
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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected override void _Process()
        {
            // Parameters
            string countValues = _GetParameter(PatchInstructionParameter.ParameterName.distributionValues);

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

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

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

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

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

            // Saving
            aiConfigFile.Save();
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// What the instruction should do
        /// </summary>
        protected void _CommonProcess()
        {
            // Common parameters
            string camId           = _GetParameter(PatchInstructionParameter.ParameterName.cameraIKIdentifier);
            string hoodView        = _GetParameter(PatchInstructionParameter.ParameterName.newHoodView);
            string hoodBackView    = _GetParameter(PatchInstructionParameter.ParameterName.newHoodBackView);
            string cockpitView     = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitView);
            string cockpitBackView = _GetParameter(PatchInstructionParameter.ParameterName.newCockpitBackView);

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

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

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

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

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

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

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

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

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

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

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

            // Saving
            currentCameras.Save();
        }
Ejemplo n.º 6
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;
        }