Example #1
0
File: PCH.cs Project: djey47/tdumt
        /// <summary>
        /// Reads role list from specified XML node to update role list
        /// </summary>
        /// <param name="propNode"></param>
        private void _RetrieveRoles(XmlNode propNode)
        {
            _Roles.Clear();

            try
            {
                XmlNode     rolesNode = propNode.SelectSingleNode(_ROLES_NODE);
                XmlNodeList allRoles  = rolesNode.SelectNodes(_ROLE_NODE);

                if (allRoles != null)
                {
                    foreach (XmlNode anotherRole in allRoles)
                    {
                        string role = anotherRole.Attributes[_WHAT_ATTRIBUTE].Value;
                        string name = Xml2.GetAttributeWithDefaultValue(anotherRole, _NAME_ATTRIBUTE, _NAME_UNKNOWN);

                        _Roles.Add(role, name);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(new Exception("Roles not defined in patch file! Using defaults.", ex));
            }

            // If no role is set, standard roles are set
            if (_Roles.Count == 0)
            {
                _SetStandardRoles();
            }
        }
Example #2
0
File: PCH.cs Project: djey47/tdumt
        /// <summary>
        /// Method to create an instruction from a XML node
        /// </summary>
        /// <param name="node">node to process</param>
        /// <param name="order">instruction order</param>
        /// <returns>Correponding instruction</returns>
        private PatchInstruction _ProcessInstruction(XmlNode node, int order)
        {
            PatchInstruction processedPI = null;

            if (node != null && order > 0)
            {
                // Main attributes
                string instructionType = node.Attributes[_TYPE_ATTRIBUTE].Value;
                string isFailOnError   = Xml2.GetAttributeWithDefaultValue(node, _FAIL_ON_ERROR_ATTRIBUTE, true.ToString());
                string isEnabled       = Xml2.GetAttributeWithDefaultValue(node, _ENABLED_ATTRIBUTE, true.ToString());
                string comment         = Xml2.GetAttributeWithDefaultValue(node, _COMMENT_ATTRIBUTE, "");
                string groupName       = Xml2.GetAttributeWithDefaultValue(node, _GROUP_ATTRIBUTE, REQUIRED_GROUP_NAME);

                processedPI = PatchInstruction.MakeInstruction(instructionType);

                if (processedPI != null)
                {
                    processedPI.FailOnError = bool.Parse(isFailOnError);
                    processedPI.Enabled     = bool.Parse(isEnabled);
                    processedPI.Order       = order;
                    processedPI.Comment     = comment;

                    if (string.IsNullOrEmpty(groupName))
                    {
                        groupName = REQUIRED_GROUP_NAME;
                    }

                    processedPI.Group = GetGroupFromName(groupName);

                    // Instruction parameters
                    XmlNodeList allParameterNodes = node.SelectNodes(_PARAMETER_NODE);

                    if (allParameterNodes != null)
                    {
                        foreach (XmlNode anotherParameterNode in allParameterNodes)
                        {
                            PatchInstructionParameter pip = _ProcessParameter(anotherParameterNode);

                            if (pip == null)
                            {
                                throw new Exception("Invalid parameter: " + anotherParameterNode.Value);
                            }

                            processedPI.Parameters.Add(pip.Name, pip);
                        }
                    }
                }
            }

            return(processedPI);
        }
Example #3
0
File: PCH.cs Project: djey47/tdumt
        /// <summary>
        /// Reads group dependency and exclusion from specified XML node to update list
        /// </summary>
        /// <param name="propNode"></param>
        private void _RetrieveGroups(XmlNode propNode)
        {
            _Groups.Clear();

            try
            {
                XmlNode groupsNode = propNode.SelectSingleNode(_GROUPS_NODE);

                if (groupsNode != null)
                {
                    // Custom required group name
                    _CustomRequiredName = Xml2.GetAttributeWithDefaultValue(groupsNode, _CUSTOM_REQUIRED_ATTRIBUTE,
                                                                            REQUIRED_GROUP_NAME);

                    // Dependencies and exclusions
                    XmlNodeList allDependancies = groupsNode.SelectNodes(_DEPENDENCY_NODE);

                    if (allDependancies != null)
                    {
                        foreach (XmlNode anotherDep in allDependancies)
                        {
                            string groupName                   = anotherDep.Attributes[_GROUP_ATTRIBUTE].Value;
                            string requiredName                = Xml2.GetAttributeWithDefaultValue(anotherDep, _REQUIRED_ATTRIBUTE, null);
                            bool   isDefaultChecked            = bool.Parse(Xml2.GetAttributeWithDefaultValue(anotherDep, _CHECKED_ATTRIBUTE, "false"));
                            Collection <string> excludedGroups = _RetrieveExcludedGroups(anotherDep);

                            _Groups.Add(new InstallGroup {
                                name = groupName, parentName = requiredName, isDefaultChecked = isDefaultChecked, excludedGroupNames = excludedGroups, exists = true
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(new Exception("Roles not defined in patch file! Using defaults.", ex));
            }

            // If no role is set, standard roles are set
            if (_Roles.Count == 0)
            {
                _SetStandardRoles();
            }
        }
Example #4
0
        /// <summary>
        /// Initializes vehicle reference according to specified XML file.
        /// </summary>
        /// <param name="referenceFilePath">Path of XML reference file (just path, not filename)</param>
        public static void InitReference(string referenceFilePath)
        {
            // Is init needed ?
            if (!_IsReady && !string.IsNullOrEmpty(referenceFilePath) && Directory.Exists(referenceFilePath))
            {
                // Parsing ref XML file and writing to reference
                XmlDocument doc = new XmlDocument();

                doc.Load(referenceFilePath + FILE_SLOTS_REF_XML);

                XmlNode slotsNode = doc.DocumentElement;

                if (slotsNode != null)
                {
                    XmlNodeList allVehicles = slotsNode.SelectNodes(_VEHICLE_NODE);

                    if (allVehicles != null)
                    {
                        foreach (XmlNode anotherNode in allVehicles)
                        {
                            string name       = anotherNode.Attributes[_NAME_ATTRIBUTE].Value;
                            string vehicleRef = anotherNode.Attributes[_REF_ATTRIBUTE].Value;
                            string defaultCam = anotherNode.Attributes[_CAMERA_ATTRIBUTE].Value;
                            string defaultIK  = anotherNode.Attributes[_IK_ATTRIBUTE].Value;

                            // New camera ?
                            string newCam = Xml2.GetAttributeWithDefaultValue(anotherNode, _NEW_CAMERA_ATTRIBUTE, null);

                            // Top speed (km/h)
                            string topSpeed = Xml2.GetAttributeWithDefaultValue(anotherNode, _TOP_SPEED_ATTRIBUTE, "0");

                            // Addon car ?
                            bool isAddon =
                                bool.Parse(Xml2.GetAttributeWithDefaultValue(anotherNode, _ADDON_ATTRIBUTE, "false"));

                            // Is it a bike ?
                            bool isBike =
                                bool.Parse(Xml2.GetAttributeWithDefaultValue(anotherNode, _BIKE_ATTRIBUTE, "false"));

                            // Moddable vehicle ?
                            bool isModdable =
                                bool.Parse(Xml2.GetAttributeWithDefaultValue(anotherNode, _MODDABLE_ATTRIBUTE, "true"));

                            _SlotReference.Add(name, vehicleRef);
                            _SlotReferenceReverse.Add(vehicleRef, name);
                            _CamReferenceReverse.Add(name, defaultCam);
                            _IKReferenceReverse.Add(name, defaultIK);

                            if (!_CamReference.ContainsKey(defaultCam))
                            {
                                _CamReference.Add(defaultCam, name);
                            }
                            if (newCam != null && !_NewCamReference.ContainsKey(newCam))
                            {
                                _NewCamReference.Add(newCam, name);
                            }
                            if (!_IKReference.ContainsKey(defaultIK))
                            {
                                _IKReference.Add(defaultIK, name);
                            }

                            // Vehicle information
                            VehicleInfo info = new VehicleInfo
                            {
                                isAddon       = isAddon,
                                isBike        = isBike,
                                defaultCamera = defaultCam,
                                newCamera     = newCam,
                                defaultIK     = defaultIK,
                                isModdable    = isModdable,
                                topSpeed      = ushort.Parse(topSpeed)
                            };

                            // Updating reference
                            _VehicleInformation.Add(vehicleRef, info);
                        }
                    }
                }

                // Loads default camera
                string defaultCamerasFileName = referenceFilePath + LibraryConstants.FOLDER_DEFAULT +
                                                Cameras.FILE_CAMERAS_BIN;
                _DefaultCameras = (Cameras)TduFile.GetFile(defaultCamerasFileName);

                if (_DefaultCameras == null || !_DefaultCameras.Exists)
                {
                    throw new Exception("Default camera file invalid or not found: " + defaultCamerasFileName);
                }

                // OK !
                _IsReady = true;
            }
        }
Example #5
0
File: PCH.cs Project: djey47/tdumt
        /// <summary>
        /// Reads patch from a PCH (XML format) file
        /// </summary>
        protected override sealed void _ReadData()
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(FileName);

                // Properties
                XmlElement docElement = doc.DocumentElement;

                if (docElement != null)
                {
                    XmlNode propNode = docElement.SelectSingleNode(_PROPERTIES_NODE);

                    _Name              = propNode.Attributes[_NAME_ATTRIBUTE].Value;
                    _Version           = propNode.Attributes[_VERSION_ATTRIBUTE].Value;
                    _Author            = propNode.Attributes[_AUTHOR_ATTRIBUTE].Value;
                    _Date              = propNode.Attributes[_DATE_ATTRIBUTE].Value;
                    _Free              = Xml2.GetAttributeWithDefaultValue(propNode, _FREE_ATTRIBUTE, "");
                    _InstallerFileName = Xml2.GetAttributeWithDefaultValue(propNode, _INSTALLER_FILE_NAME_ATTRIBUTE,
                                                                           INSTALLER_FILE_NAME);

                    // EVO_131: roles
                    _RetrieveRoles(propNode);

                    // EVO_134: groups
                    _RetrieveGroups(propNode);

                    // New attributes
                    _SlotRef = Xml2.GetAttributeWithDefaultValue(propNode, _SLOT_REF_ATTRIBUTE, "");
                    InfoURL  = Xml2.GetAttributeWithDefaultValue(propNode, _INFO_URL_ATTRIBUTE, "");

                    // Instructions
                    XmlNode     instrNode           = docElement.SelectSingleNode(_INSTRUCTIONS_NODE);
                    XmlNodeList allInstructionNodes = instrNode.SelectNodes(_SINGLE_INSTRUCTION_NODE);
                    int         order = 1;

                    if (allInstructionNodes != null)
                    {
                        foreach (XmlNode anotherInstructionNode in allInstructionNodes)
                        {
                            try
                            {
                                PatchInstruction pi = _ProcessInstruction(anotherInstructionNode, order);

                                if (pi == null)
                                {
                                    throw new Exception();
                                }
                                _PatchInstructions.Add(pi);

                                // Groups update
                                if (!_Groups.Contains(pi.Group))
                                {
                                    _Groups.Add(pi.Group);
                                }

                                order++;
                            }
                            catch (Exception ex)
                            {
                                // Current instruction won't be added
                                Exception2.PrintStackTrace(new Exception("Invalid instruction.", ex));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Silent exception
                Exception2.PrintStackTrace(new Exception(_ERROR_LOADING_PATCH, ex));
            }

            // EVO_65: Properties
            Property.ComputeValueDelegate instructionCountDelegate = () => PatchInstructions.Count.ToString();
            Property.ComputeValueDelegate nameDelegate             = () => Name;
            Property.ComputeValueDelegate authorDelegate           = () => Author;
            Property.ComputeValueDelegate dateDelegate             = () => Date;
            Property.ComputeValueDelegate versionDelegate          = () => Version;
            Property.ComputeValueDelegate slotDelegate             = () => SlotRef;
            Property.ComputeValueDelegate groupCountDelegate       = () => Groups.Count.ToString();
            Property.ComputeValueDelegate installerDelegate        = () => InstallerFileName;
            Property.ComputeValueDelegate urlDelegate = () => InfoURL;

            Properties.Add(new Property("Patch name", "Patch", nameDelegate));
            Properties.Add(new Property("Author", "Patch", authorDelegate));
            Properties.Add(new Property("Date", "Patch", dateDelegate));
            Properties.Add(new Property("Version", "Patch", versionDelegate));
            Properties.Add(new Property("Group count", "Patch", groupCountDelegate));
            Properties.Add(new Property("Instruction count", "Patch", instructionCountDelegate));
            Properties.Add(new Property("Slot reference", "Patch", slotDelegate));
            Properties.Add(new Property("Installer file name", "Patch", installerDelegate));
            Properties.Add(new Property("Information URL", "Patch", urlDelegate));
        }