Beispiel #1
0
        /// <summary>
        /// Utilise le fichier clé spécifié pour mettre à jour les noms de fichiers
        /// </summary>
        /// <param name="keyFilePath">Chemin vers le fichier clé</param>
        public void SetFileNamesFromKey(string keyFilePath)
        {
            // Récupération du contenu de la clé
            Dictionary <uint, string> keyContents = GetKeyContents(keyFilePath);

            // Parcours de la clé
            foreach (uint anotherId in keyContents.Keys)
            {
                // Mise à jour de la structure
                try
                {
                    Entry currentEntry = entryList[anotherId];

                    if (currentEntry.entryNumber > 0)
                    {
                        currentEntry.fileName          = keyContents[anotherId];
                        entryList[currentEntry.fileId] = currentEntry;
                    }
                }
                catch (Exception ex)
                {
                    // Exception silencieuse ici, mais tracée
                    Exception2.PrintStackTrace(ex);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Restaure un fichier depuis la copie de sauvegarde
        /// </summary>
        /// <param name="backupFileName">Nom de la copie</param>
        /// <param name="originalFileName">Nom du fichier d'origine</param>
        public static void RestoreFile(string backupFileName, string originalFileName)
        {
            try
            {
                // Vérifications
                if (backupFileName == null || originalFileName == null || backupFileName.Equals(originalFileName))
                {
                    throw new Exception(_ERROR_RESTORE_PARAMS);
                }

                // Suppression du fichier actuel
                try
                {
                    File.SetAttributes(originalFileName, FileAttributes.Normal);
                    File.Delete(originalFileName);
                }
                catch (FileNotFoundException fnfEx)
                {
                    // ANO_26 : Si le fichier n'existe pas, on continue
                    Exception2.PrintStackTrace(fnfEx);
                }

                // Renommage de la sauvegarde
                File.Move(backupFileName, originalFileName);
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format(_ERROR_RESTORE, originalFileName, backupFileName);
                throw new Exception(errorMessage, ex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Manages instruction execution
        /// </summary>
        /// <param name="currentLogger">Logger to write execution events (optional)</param>
        /// <returns>A run result</returns>
        public PatchHelper.RunResult Run(Log currentLogger)
        {
            PatchHelper.RunResult runResult = PatchHelper.RunResult.OK;

            try
            {
                // Instruction
                _Process();
            }
            catch (Exception ex)
            {
                // Error logged
                Exception2.PrintStackTrace(ex);

                if (currentLogger != null)
                {
                    currentLogger.WriteEvent(string.Format(_MSG_SPOTTED_EXCEPTION, ex.Message));
                }

                if (FailOnError)
                {
                    runResult = PatchHelper.RunResult.RunWithErrors;
                }
                else
                {
                    runResult = PatchHelper.RunResult.RunWithWarnings;
                }
            }

            return(runResult);
        }
Beispiel #4
0
        /// <summary>
        /// Tries to retrieve TDU install folder by seeking into Windows registry.
        /// </summary>
        /// <returns>TDU install location or an empty string if not found.</returns>
        internal static string _SearchForTduInstallPath()
        {
            string installPath = "";

            try
            {
                RegistryKey key = Registry.LocalMachine;

                // 64bit OS support
                string keyName = (System64.Is64BitOs() ?
                                  _REGKEY_TDU_64
                               : _REGKEY_TDU_32);

                key = key.OpenSubKey(keyName);

                if (key == null)
                {
                    throw new Exception("TDU registry key not found under LOCAL_MACHINE: " + keyName);
                }

                installPath = key.GetValue(_REGVALUE_TDU_INSTALL_PATH) as string;
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(new Exception(_ERROR_SEARCH_TDU_LOCATION, ex));
            }

            return(installPath ?? "");
        }
Beispiel #5
0
        /// <summary>
        /// Met à jour une seule entrée dans la liste
        /// </summary>
        /// <param name="lvItem">élément de la liste</param>
        /// <param name="entryId">identifiant de l'entrée mise à jour</param>
        private void _UpdateSingleEntry(ListViewItem lvItem, uint entryId)
        {
            if (lvItem == null)
            {
                return;
            }

            MAP.Entry entry = leMAP.EntryList[entryId];

            lvItem.ForeColor        = SystemColors.WindowText;
            lvItem.SubItems[1].Text = string.Format("{0}", entry.fileId);
            lvItem.SubItems[2].Text = string.Format("{0}", entry.firstSize);
            lvItem.SubItems[3].Text = string.Format("{0}", entry.secondSize);
            lvItem.SubItems[4].Text = string.Format("{0}", entry.address);
            lvItem.SubItems[5].Text = string.Format("{0}", entry.fileName);

            // EVO 13 : un fichier dont la taille ne correspond pas est affiché en rouge
            try
            {
                uint actualSize = uint.Parse(lvItem.SubItems[6].Text);
                if (actualSize != entry.firstSize || actualSize != entry.secondSize)
                {
                    lvItem.ForeColor = GuiConstants.COLOR_INVALID_ITEM;
                }
            }
            catch (Exception ex)
            {
                // Silent exception
                Exception2.PrintStackTrace(ex);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Reads group exclusion list from specified XML node to update list
        /// </summary>
        /// <param name="groupNode"></param>
        private static Collection <string> _RetrieveExcludedGroups(XmlNode groupNode)
        {
            Collection <string> returnedNames  = new Collection <string>();
            XmlNode             exclusionsNode = groupNode.SelectSingleNode(_EXCLUSIONS_NODE);

            if (exclusionsNode != null)
            {
                try
                {
                    XmlNodeList allExclusions = exclusionsNode.SelectNodes(_EXCLUSION_NODE);

                    if (allExclusions != null)
                    {
                        foreach (XmlNode anotherExc in allExclusions)
                        {
                            string groupName = anotherExc.Attributes[_GROUP_ATTRIBUTE].Value;

                            if (!returnedNames.Contains(groupName))
                            {
                                returnedNames.Add(groupName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Exception2.PrintStackTrace(new Exception("Dependencies not defined in patch file! Using defaults.", ex));
                }
            }

            return(returnedNames);
        }
Beispiel #7
0
        /// <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();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Retourne la liste d'items invalides dans le tableau
        /// </summary>
        /// <returns></returns>
        private Collection <ListViewItem> _GetInvalidEntries()
        {
            Collection <ListViewItem> listeRetour = new Collection <ListViewItem>();

            // Parcours du tableau
            foreach (ListViewItem anotherItem in entryList.Items)
            {
                try
                {
                    uint size1 = uint.Parse(anotherItem.SubItems[2].Text);
                    uint size2 = uint.Parse(anotherItem.SubItems[3].Text);

                    if (!string.IsNullOrEmpty(anotherItem.SubItems[6].Text))
                    {
                        uint actualSize = uint.Parse(anotherItem.SubItems[6].Text);

                        if (size1 != actualSize || size2 != actualSize)
                        {
                            listeRetour.Add(anotherItem);
                        }
                    }
                }
                catch (FormatException fex)
                {
                    // on passe à l'entrée suivante
                    Exception2.PrintStackTrace(fex);
                }
            }

            return(listeRetour);
        }
Beispiel #9
0
        /// <summary>
        /// Exports instruction bribe to specified file
        /// </summary>
        /// <param name="instructionsToExport">List of instructions to export</param>
        /// <param name="writer">XML writer to export to - must be initialized</param>
        public void ExportInstruction(List <PatchInstruction> instructionsToExport, XmlWriter writer)
        {
            if (instructionsToExport != null && writer != null)
            {
                XmlDocument doc = new XmlDocument();

                try
                {
                    XmlElement instructionsElement = doc.CreateElement(_INSTRUCTIONS_NODE);

                    foreach (PatchInstruction anotherInstruction in instructionsToExport)
                    {
                        _SaveInstruction(anotherInstruction, doc, instructionsElement);
                    }

                    doc.AppendChild(instructionsElement);
                }
                catch (Exception ex)
                {
                    // Current instruction won't be exported
                    Exception2.PrintStackTrace(ex);
                }

                doc.Save(writer);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Effectue le remplacement direct d'un fichier empaqueté par le fichier spécifié
        /// </summary>
        /// <param name="selectedFile">Chemin du fichier de remplacement</param>
        /// <returns>true si le remplacement a réussi, false sinon</returns>
        private bool _DirectReplace(string selectedFile)
        {
            bool      returnedResult = false;
            Exception ex             = null;

            // EVO_17
            // Recherche d'un fichier de même nom
            if (_CurrentBnkFile != null && !string.IsNullOrEmpty(selectedFile))
            {
                FileInfo            fi            = new FileInfo(selectedFile);
                Collection <string> possiblePaths = _CurrentBnkFile.GetPackedFilesPaths(fi.Name);

                if (possiblePaths.Count == 1)
                {
                    // Remplacement
                    _CurrentBnkFile.ReplacePackedFile(possiblePaths[0], selectedFile);
                    returnedResult = true;
                }
                else if (possiblePaths.Count == 0)
                {
                    ex = new Exception("Unable to replace file: " + fi.Name + " - a packed file with same name does not exist.");
                }
                else
                {
                    ex = new Exception("Unable to replace file: " + fi.Name + " - more than one packed file exist with same name.");
                }
            }

            if (ex != null)
            {
                Exception2.PrintStackTrace(ex);
            }

            return(returnedResult);
        }
        /// <summary>
        /// Reads a <see cref="SerializationInfo"/> data which contains
        /// the data needed to deserialize to a new instance.
        /// </summary>
        /// <param name="ex">The new instance.</param>
        /// <param name="info">The <see cref="SerializationInfo"/> to read data.</param>
        /// <param name="context">The destination for this serialization.</param>
        public static void SetObjectData(Exception ex, SerializationInfo info, StreamingContext context)
        {
            if (ex == null)
            {
                throw new ArgumentNullException(nameof(ex));
            }
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            string    message    = info.GetString("Message");
            Exception inner      = (Exception)info.GetValue("InnerException", typeof(Exception));
            string    stackTrace = info.GetString("StackTraceString");
            int       hResult    = info.GetInt32("HResult");

            IntPtr[] methodDescs = (IntPtr[])info.GetValue("MethodDescs", typeof(IntPtr[]));
            string   source      = info.GetString("Source");

            ex.SetMessage(message);
            ex.SetInnerException(inner);
            HResultFieldInfo.SetValue(ex, hResult);
            MethodDescsFieldInfo.SetValue(ex, methodDescs);

            Exception2 ex2 = ex as Exception2;

            if (ex2 != null)
            {
                ex2.SetStackTraceString(stackTrace);
                ex2.Source = source;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Convertit de chaîne en Config de lancement
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Collection <LaunchConfiguration> ConvertFromString(string value)
        {
            Collection <LaunchConfiguration> returnedConfigList = null;

            // Paramètres sous forme de chaîne
            if (value != null)
            {
                string[]            itemList = value.Split(_ITEM_SEPARATOR);
                LaunchConfiguration result;

                returnedConfigList = new Collection <LaunchConfiguration>();

                foreach (string item in itemList)
                {
                    string[] paramList = item.Split(_VALUE_SEPARATOR);

                    result = new LaunchConfiguration();

                    try
                    {
                        // 0. Nom
                        result.Name = paramList[0];

                        // 1. Default
                        result.Default = bool.Parse(paramList[1]);

                        // 2. Mode fenetré
                        result.WindowedMode = bool.Parse(paramList[2]);

                        // 3. FPS
                        result.FpsDisplayed = bool.Parse(paramList[3]);

                        // 4. Nettoyage radial
                        result.CleanRadial = bool.Parse(paramList[4]);

                        // 5. Commande avant lancement
                        result.PreviousCommand = paramList[5];

                        // 6. Commande après lancement
                        result.NextCommand = paramList[6];

                        // 7. Coordinates
                        if (paramList.Length > 7)
                        {
                            result.PosDisplayed = bool.Parse(paramList[7]);
                        }

                        returnedConfigList.Add(result);
                    }
                    catch (Exception ex)
                    {
                        Exception2.PrintStackTrace(ex);
                    }
                }
            }

            return(returnedConfigList);
        }
Beispiel #13
0
        /// <summary>
        /// Constructeur par défaut
        /// </summary>
        public MainForm()
        {
            InitializeComponent();
            _Instance = this;

            // Titre
            Text = _TITLE_MAIN_FORM;

            // EVO_73: Debug mode notify
            if (bool.Parse(Program.ApplicationSettings.DebugModeEnabled))
            {
                Text += _TITLE_BRIBE_DEBUG;
            }

            // EVO_40 : lancement automatique d'un module
            try
            {
                string moduleName = Program.ApplicationSettings.StartupModule;

                if (StartupModuleList.Contains(moduleName))
                {
                    ModuleType moduleType = (ModuleType)Enum.Parse(typeof(ModuleType), moduleName);

                    LoadTool(moduleType, null);
                }
            }
            catch (Exception ex)
            {
                // Exception silencieuse
                Exception2.PrintStackTrace(new Exception("Unable to launch startup module.", ex));
            }

            // EVO_36 : initialisation des configurations de lancement
            string launchConfigurationsValue = Program.ApplicationSettings.TduLaunchConfigurations;

            if (string.IsNullOrEmpty(launchConfigurationsValue))
            {
                Collection <LaunchConfiguration> launchConfigs = new Collection <LaunchConfiguration>();
                LaunchConfiguration launchConfig = new LaunchConfiguration
                {
                    Default = true,
                    Name    = _LAUNCH_CONFIG_DEFAULT_NAME
                };

                launchConfigs.Add(launchConfig);

                Program.ApplicationSettings.TduLaunchConfigurations = LaunchConfigurationConverter.ConvertToString(launchConfigs);
                Program.ApplicationSettings.Save();
            }

            // View mode
            _isBasicView = !bool.Parse(Program.ApplicationSettings.AdvancedMode);
            _SetView();
        }
 protected override unsafe int OnException2(
     CorDebugAppDomain pAppDomain,
     CorDebugThread pThread,
     CorDebugFrame pFrame,
     uint nOffset,
     CorDebugExceptionCallbackType dwEventType,
     uint dwFlags)
 {
     Exception2?.Invoke(this, pAppDomain, pThread, pFrame, nOffset, dwEventType, dwFlags);
     return(Continue());
 }
Beispiel #15
0
        /// <summary>
        /// Saves patch to a PCH (XML format) file
        /// </summary>
        public override void Save()
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                // Header
                doc.LoadXml(Xml2.XML_1_0_HEADER + _ROOT_NODE_START + _ROOT_NODE_END);

                // Properties
                XmlElement propElement = doc.CreateElement(_PROPERTIES_NODE);

                propElement.SetAttribute(_NAME_ATTRIBUTE, _Name);
                propElement.SetAttribute(_VERSION_ATTRIBUTE, _Version);
                propElement.SetAttribute(_AUTHOR_ATTRIBUTE, _Author);
                propElement.SetAttribute(_DATE_ATTRIBUTE, _Date);
                propElement.SetAttribute(_SLOT_REF_ATTRIBUTE, _SlotRef);
                propElement.SetAttribute(_FREE_ATTRIBUTE, _Free);
                propElement.SetAttribute(_INSTALLER_FILE_NAME_ATTRIBUTE, _InstallerFileName);
                propElement.SetAttribute(_INFO_URL_ATTRIBUTE, InfoURL);

                // EVO_131: roles
                _WriteRoles(doc, propElement);

                // EVO_134: groups
                _WriteGroups(doc, propElement);

                XmlElement docElement = doc.DocumentElement;

                if (docElement != null)
                {
                    docElement.AppendChild(propElement);

                    // Instructions
                    XmlElement instructionsElement = doc.CreateElement(_INSTRUCTIONS_NODE);

                    foreach (PatchInstruction instr in _PatchInstructions)
                    {
                        _SaveInstruction(instr, doc, instructionsElement);
                    }

                    docElement.AppendChild(instructionsElement);
                }

                // End
                doc.Save(_FileName);
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
                throw new Exception(_ERROR_SAVING_PATCH, ex);
            }
        }
Beispiel #16
0
 static void Main(String[] args)
 {
     try
     {
         initFromArgs(args);
         Console.WriteLine("Started from path '" + Exception2.getPath(m_workPath) + "'");
     }
     catch (Exception ex)
     {
         ConsolePrintException(ex, args);
     }
 } //Main
        /// <summary>
        /// Wraps a <see cref="Exception"/> instance into a new serializable type.
        /// </summary>
        /// <param name="ex">The target instance.</param>
        /// <returns>A new <see cref="Exception2"/> instance.</returns>
        public static Exception AsSerializable(Exception ex)
        {
            if (ex is ISerializable)
            {
                return(ex);
            }

            Exception2 ex2 = new Exception2(ex.Message, ex.InnerException);

            HResultFieldInfo.SetValue(ex2, GetHResult(ex));
            MethodDescsFieldInfo.SetValue(ex2, GetMethodDescs(ex));
            return(ex2);
        }
Beispiel #18
0
        /// <summary>
        /// Patche le MAP pour désactiver la protection (yes !!!)
        /// Une copie de sauvegarde du MAP peut être créée
        /// </summary>
        /// <param name="makeBackup">true to make a backup</param>
        public void PatchIt(bool makeBackup)
        {
            // If it's already a magic map, no need to patch it...
            if (!_IsMagicMap)
            {
                string backupFileName = null;

                try
                {
                    // Copie de sauvegarde
                    // ANO_27 : gestion des sauvegardes existantes
                    if (makeBackup)
                    {
                        backupFileName = FileName + "." + LibraryConstants.EXTENSION_BACKUP;

                        while (File.Exists(backupFileName))
                        {
                            backupFileName += "." + LibraryConstants.EXTENSION_BACKUP;
                        }

                        Tools.BackupFile(FileName, backupFileName);
                    }

                    // Collecte des ids
                    ArrayList ids = new ArrayList();

                    foreach (uint entry in EntryList.Keys)
                    {
                        ids.Add(entry);
                    }

                    // Fix
                    foreach (uint entry in ids)
                    {
                        UpdateEntrySizes(entry, 0, 0);
                    }
                }
                catch (Exception ex)
                {
                    // Si erreur, on restaure la sauvegarde si elle a été créée
                    Exception2.PrintStackTrace(ex);

                    if (makeBackup && File.Exists(backupFileName))
                    {
                        Tools.RestoreFile(backupFileName, _FileName);
                    }

                    throw;
                }
            }
        }
Beispiel #19
0
 static void Main(String[] args)
 {
     try
     {
         // First instantiate SolutionProjectBuilder, then initialize -x command line arguments to not to print full path's.
         String testx = m_workPath;
         initFromArgs(args);
         Console.WriteLine("Started from path '" + Exception2.getPath(m_workPath) + "'");
     }
     catch (Exception ex)
     {
         ConsolePrintException(ex, args);
     }
 } //Main
Beispiel #20
0
        /// <summary>
        /// Convertit l'en-tête 2DB en tableau d'octets
        /// </summary>
        /// <returns></returns>
        protected byte[] _ConvertHeaderToBytes()
        {
            byte[]       result    = new byte[HEADER_SIZE];
            Stream       memStream = new MemoryStream(result);
            BinaryWriter writer    = new BinaryWriter(memStream);

            try
            {
                // Reconstitution de la structure dans le tableau d'octets
                writer.Write(_Header.dwTwo);
                writer.Write(_Header.dwZero1);
                writer.Write(_Header.dwSize);
                writer.Write(_Header.bID1);
                writer.Write(_Header.bID2);
                writer.Write(_Header.dwZero2);
                writer.Write(_Header.dwSize2);
                writer.Write(_Header.dwSize2Bis);
                writer.Write(_Header.strName);
                writer.Write(_Header.width);
                writer.Write(_Header.height);
                writer.Write(_Header.one);
                writer.Write(_Header.bMipMapCount);
                writer.Write(_Header.bMipMapCountBis);
                writer.Write(_Header.bFormat);
                writer.Write(_Header.bUnk2);
                writer.Write(_Header.unk3);
                writer.Write(_Header.dwUnk4);
                writer.Write(_Header.dwUnk5);
                writer.Write(_Header.dwType);
                writer.Write(_Header.dwFlags);
                writer.Write(_Header.dwUnk6);
                writer.Write(_Header.dwUnk7);
                writer.Write(_Header.dwZero3);
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
                throw;
            }
            finally
            {
                memStream.Close();
                writer.Close();
            }
            return(result);
        }
Beispiel #21
0
        private void file2InfoButton_Click(object sender, EventArgs e)
        {
            // EVO_65: properties
            try
            {
                TduFile textureFile = TduFile.GetFile(newDDSFilePath.Text);

                if (textureFile.Exists)
                {
                    ListView2.FillWithProperties(propertiesListView, textureFile.Properties);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
            }
        }
Beispiel #22
0
        private void fileInfo4Button_Click(object sender, EventArgs e)
        {
            // EVO_65: properties
            try
            {
                TduFile bnkFile = TduFile.GetFile(sourceBNKTextBox.Text);

                if (bnkFile.Exists)
                {
                    ListView2.FillWithProperties(propertiesListView, bnkFile.Properties);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
            }
        }
Beispiel #23
0
        /// <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();
            }
        }
Beispiel #24
0
        /// <summary>
        /// Convertit l'en-tête DDS en tableau d'octets
        /// </summary>
        /// <returns></returns>
        protected byte[] _ConvertHeaderToBytes()
        {
            byte[] result = new byte[HEADER_SIZE];

            MemoryStream memStream = new MemoryStream(result);
            BinaryWriter writer    = new BinaryWriter(memStream);

            try
            {
                writer.Write(_Header.dwMagic);
                writer.Write(_Header.ddsd.dwSize);
                writer.Write(_Header.ddsd.dwFlags);
                writer.Write(_Header.ddsd.dwHeight);
                writer.Write(_Header.ddsd.dwWidth);
                writer.Write(_Header.ddsd.dwPitchOrLinearSize);
                writer.Write(_Header.ddsd.dwDepth);
                writer.Write(_Header.ddsd.dwMipMapCount);
                writer.Write(_Header.ddsd.dwReserved1);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwSize);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwFlags);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwFourCC);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwRGBBitCount);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwRBitMask);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwGBitMask);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwBBitMask);
                writer.Write(_Header.ddsd.ddpfPixelFormat.dwRGBAlphaBitMask);
                writer.Write(_Header.ddsd.ddsCaps.dwCaps1);
                writer.Write(_Header.ddsd.ddsCaps.dwCaps2);
                writer.Write(_Header.ddsd.ddsCaps.Reserved);
                writer.Write(_Header.ddsd.dwReserved2);
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);
                throw;
            }
            finally
            {
                memStream.Close();
                writer.Close();
            }

            return(result);
        }
Beispiel #25
0
        /// <summary>
        /// Imports instruction(s) according to provided bribe
        /// </summary>
        /// <param name="bribe">Instructions XML bribe</param>
        public void ImportInstruction(string bribe)
        {
            if (!string.IsNullOrEmpty(bribe))
            {
                XmlDocument doc = new XmlDocument();

                doc.LoadXml(bribe);

                try
                {
                    XmlNode instructionsNode = doc.DocumentElement;

                    if (instructionsNode != null)
                    {
                        XmlNodeList allInstructionNodes = instructionsNode.SelectNodes(_SINGLE_INSTRUCTION_NODE);
                        int         order = _PatchInstructions.Count + 1;

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

                                if (pi == null)
                                {
                                    Log.Warning("Invalid instruction - can't be imported.");
                                }
                                else
                                {
                                    _PatchInstructions.Add(pi);
                                    order++;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Current instruction won't be added
                    Exception2.PrintStackTrace(ex);
                }
            }
        }
Beispiel #26
0
        /// <summary>
        ///
        /// {</summary>
        /// <param name="parameterName"></param>
        /// <param name="evaluateVariable"></param>
        /// <returns></returns>
        protected string _GetParameter(PatchInstructionParameter.ParameterName parameterName, bool evaluateVariable)
        {
            bool   requiredParameter = false;
            string returnedValue     = null;

            try
            {
                // Parameter information
                ParameterInfo info = SupportedParameterInformation[parameterName];

                requiredParameter = info.Required;

                // Retrieving parameter value...
                PatchInstructionParameter resultPip = _Parameters[parameterName.ToString()];

                if (resultPip != null)
                {
                    if (evaluateVariable)
                    {
                        returnedValue = PatchInstructionParameter.EvaluateParameter(resultPip.Value);
                    }
                    else
                    {
                        returnedValue = resultPip.Value;
                    }
                }
                else if (requiredParameter)
                {
                    throw new MissingParameterException(parameterName);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);

                if (requiredParameter)
                {
                    throw new MissingParameterException(parameterName, ex);
                }
            }

            return(returnedValue);
        }
Beispiel #27
0
        /// <summary>
        /// Renvoie le contenu de la clé dans une table indexée par l'identifiant MAP
        /// </summary>
        /// <param name="pKeyFileName">Nom du fichier clé</param>
        /// <returns>Une collection de couples (id,nom de fichier)</returns>
        public static Dictionary <uint, string> GetKeyContents(string pKeyFileName)
        {
            Dictionary <uint, string> res = new Dictionary <uint, string>();

            if (string.IsNullOrEmpty(pKeyFileName))
            {
                return(res);
            }

            try
            {
                XmlDocument xmlDoc = new XmlDocument();

                xmlDoc.Load(pKeyFileName);

                XmlElement rootElement = xmlDoc.DocumentElement;

                if (rootElement != null)
                {
                    // On parcourt les noeuds enfants
                    foreach (XmlElement noeudEnfant in rootElement.ChildNodes)
                    {
                        // Lecture des infos...
                        String mapId    = noeudEnfant.GetAttribute(_KEY_TAG_ID);
                        String fileName = noeudEnfant.GetAttribute(_KEY_TAG_FILENAME);

                        res.Add(uint.Parse(mapId), fileName);
                    }
                }
            }
            catch (Exception ex)
            {
                // Exception silencieuse ici, mais tracée
                Exception2.PrintStackTrace(ex);
            }

            return(res);
        }
        /// <summary>
        /// Populates a <see cref="SerializationInfo"/> with the data
        /// needed to serialize the target object.
        /// </summary>
        /// <param name="ex">The target object.</param>
        /// <param name="info">The <see cref="SerializationInfo"/> to populate with data.</param>
        /// <param name="context">The destination for this serialization.</param>
        public static void GetObjectData(Exception ex, SerializationInfo info, StreamingContext context)
        {
            if (ex == null)
            {
                throw new ArgumentNullException(nameof(ex));
            }
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            info.AddValue("Message", ex.Message, typeof(string));
            info.AddValue("InnerException", AsSerializable(ex.InnerException), typeof(Exception));
            info.AddValue("StackTraceString", ex.StackTrace, typeof(string));
            info.AddValue("HResult", GetHResult(ex));
            info.AddValue("MethodDescs", GetMethodDescs(ex), typeof(IntPtr[]));

            string     source = null;
            Exception2 ex2    = ex as Exception2;

            if (ex2 != null)
            {
                source = ex2.Source;
            }
            info.AddValue("Source", source, typeof(string));

            if (context.State == StreamingContextStates.Remoting)
            {
                // Compatibility with full framework
                info.AddValue("ClassName", DefaultClassName, typeof(string));
                info.AddValue("Data", null, typeof(IDictionary));
                info.AddValue("HelpURL", null, typeof(string));
                info.AddValue("RemoteStackTraceString", null, typeof(string));
                info.AddValue("RemoteStackIndex", 0, typeof(int));
                info.AddValue("ExceptionMethod", null, typeof(string));
            }
        }
Beispiel #29
0
    static void Main(String[] args)
    {
        String csName = getExecutingScript(false, true);

        solution("out_" + csName);

        project("out_" + csName);
        vsver(2015);
        platforms("Win32");
        kind("ConsoleApp");
        files("?some.cpp");

        solution("out_" + csName + "2");

        // Reselect solution, reselect project, add one more file.
        solution("out_" + csName);
        project("out_" + csName);
        files("?some2.cpp");

        Console.WriteLine(Path.GetFileName(getExecutingScript()));
        Console.WriteLine(getExecutingScript(false, true));
        Console.WriteLine(getExecutingScript(false, true, true));
        Console.WriteLine(Exception2.getPath(getExecutingScript(true, true)));
    } //Main
Beispiel #30
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);
                }
            }
        }