/// <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> /// 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); } } }
/// <summary> /// Met à jour la liste des entrées /// </summary> /// <param name="keepSelection">true pour replacer le sélecteur à l'emplacement d'origine, false sinon</param> private void _UpdateEntryList(bool keepSelection) { // Sauvegarde de l'indice sélectionné if (keepSelection) { ListView2.StoreSelectedIndex(entryList); } // Vidage de liste entryList.Items.Clear(); entryCountLabel.Text = _ENTRY_COUNT_START_TEXT; // Utilisation de la clé XML if (!string.IsNullOrEmpty(inputKEYFilePath.Text)) { leMAP.SetFileNamesFromKey(inputKEYFilePath.Text); } // Lecture de la structure foreach (UInt32 anotherKey in leMAP.EntryList.Keys) { MAP.Entry anotherEntry = leMAP.EntryList[anotherKey]; ListViewItem anotherItem = new ListViewItem(string.Format("{0}", anotherEntry.entryNumber + 1)); // EVO 13 : recherche de la taille du fichier sur disque FileInfo fi = null; try { if (anotherEntry.fileName != null) { string actualFileName = Program.ApplicationSettings.TduMainFolder + @"\" + anotherEntry.fileName; fi = new FileInfo(actualFileName); } } catch (Exception ex) { // Erreur silencieuse ici Exception2.PrintStackTrace(ex); } anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.fileId)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.firstSize)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.secondSize)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.address)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.fileName)); if (fi != null && fi.Exists) { // EVO 13 : un fichier dont la taille ne correspond pas est affiché en rouge if (fi.Length != anotherEntry.firstSize || fi.Length != anotherEntry.secondSize) { anotherItem.ForeColor = GuiConstants.COLOR_INVALID_ITEM; } anotherItem.SubItems.Add(string.Format("{0}", fi.Length)); } else { anotherItem.SubItems.Add(""); } entryList.Items.Add(anotherItem); } // Nombre d'entrées entryCountLabel.Text = string.Format(_ENTRY_COUNT_TEXT, leMAP.EntryList.Keys.Count); // Restauration de la sélection if (keepSelection) { ListView2.RestoreSelectedIndex(entryList); } }
/// <summary> /// Lit le contenu du fichier /// </summary> protected override void _ReadData() { FileStream input = null; BinaryReader reader = null; try { input = new FileStream(_FileName, FileMode.Open, FileAccess.Read); reader = new BinaryReader(input); // En-tête _Header.dwTwo = reader.ReadUInt32(); _Header.dwZero1 = reader.ReadUInt32(); _Header.dwSize = reader.ReadUInt32(); _Header.bID1 = reader.ReadBytes(4); _Header.bID2 = reader.ReadBytes(4); _Header.dwZero2 = reader.ReadUInt32(); _Header.dwSize2 = reader.ReadUInt32(); _Header.dwSize2Bis = reader.ReadUInt32(); _Header.strName = reader.ReadBytes(8); _Header.width = reader.ReadInt16(); _Header.height = reader.ReadInt16(); _Header.one = reader.ReadInt16(); _Header.bMipMapCount = reader.ReadByte(); _Header.bMipMapCountBis = reader.ReadByte(); _Header.bFormat = reader.ReadByte(); _Header.bUnk2 = reader.ReadByte(); _Header.unk3 = reader.ReadInt16(); _Header.dwUnk4 = reader.ReadUInt32(); _Header.dwUnk5 = reader.ReadUInt32(); _Header.dwType = reader.ReadUInt32(); _Header.dwFlags = reader.ReadUInt32(); _Header.dwUnk6 = reader.ReadUInt32(); _Header.dwUnk7 = reader.ReadUInt32(); _Header.dwZero3 = reader.ReadUInt32(); // Données d'image FileInfo fi = new FileInfo(_FileName); _ImageData = reader.ReadBytes((int)(fi.Length - HEADER_SIZE)); // EVO_65: property support Property.ComputeValueDelegate nameDelegate = delegate { string textureName = Array2.BytesToString(_Header.strName); return(Tools.OutlineExtendedCharacters(textureName)); }; Property.ComputeValueDelegate dimensionsDelegate = delegate { return(_Header.width + "x" + _Header.height); }; Property.ComputeValueDelegate mipmapDelegate = delegate { return(_Header.bMipMapCount.ToString()); }; Property.ComputeValueDelegate formatDelegate = delegate { return(GetFormatName(_Header.bFormat)); }; Property.ComputeValueDelegate typeDelegate = delegate { return(_Header.dwType.ToString()); }; Property.ComputeValueDelegate flagsDelegate = delegate { return(_Header.dwFlags.ToString()); }; Property.ComputeValueDelegate magicDelegate = delegate { return(_Header.dwUnk6 + " - " + _Header.dwUnk7); }; _Properties.Add(new Property("Texture name", "2DB", nameDelegate)); _Properties.Add(new Property("Dimensions", "Texture", dimensionsDelegate)); _Properties.Add(new Property("Mipmap count", "Texture", mipmapDelegate)); _Properties.Add(new Property("Format", "2DB", formatDelegate)); _Properties.Add(new Property("Type", "2DB", typeDelegate)); _Properties.Add(new Property("Flags", "2DB", flagsDelegate)); _Properties.Add(new Property("Magic", "2DB", magicDelegate)); } catch (Exception ex) { Exception2.PrintStackTrace(ex); throw; } finally { // Fermeture if (reader != null) { reader.Close(); } if (input != null) { input.Close(); } } }
/// <summary> /// Reads contents of specified section /// </summary> /// <param name="section">Section to read</param> private void _ReadSectionData(Section section) { if (section == null || section.data == null) { return; } using (BinaryReader dataReader = new BinaryReader(new MemoryStream(section.data))) { // Lecture différente selon le type de section switch (section.sectionType) { case SectionType.Header: #region HEADER // Données inutiles... dataReader.BaseStream.Seek(0xC, SeekOrigin.Current); // Special flags (required on some files) _SpecialFlag1 = dataReader.ReadUInt16(); _SpecialFlag2 = dataReader.ReadUInt16(); // Taille du fichier bnk, en octets _FileSize = dataReader.ReadUInt32(); // Taille du contenu compacté (modulo 0x10) dataReader.BaseStream.Seek(0x4, SeekOrigin.Current); // Block sizes (???) _MainBlockSize = dataReader.ReadUInt32(); _SecondaryBlockSize = dataReader.ReadUInt32(); // File count //_PackedFileCount = dataReader.ReadUInt32(); dataReader.ReadUInt32(); // Année de réalisation _Year = dataReader.ReadUInt32(); // Section addresses _GetSection(SectionType.FileSize).address = dataReader.ReadUInt32(); _GetSection(SectionType.TypeMapping).address = dataReader.ReadUInt32(); _GetSection(SectionType.FileName).address = dataReader.ReadUInt32(); _GetSection(SectionType.FileOrder).address = dataReader.ReadUInt32(); // TODO 1x4 bytes to decrypt _Unknown = dataReader.ReadUInt32(); _GetSection(SectionType.FileData).address = dataReader.ReadUInt32(); break; #endregion case SectionType.FileSize: #region INFOS SUR LE CONTENU int fileCounter = 0; while (dataReader.BaseStream.Position < section.data.Length) { fileCounter++; PackedFile aFile = new PackedFile { startAddress = dataReader.ReadUInt32(), fileSize = dataReader.ReadUInt32() }; // Nom de fichier (temporaire). Info non lue. // BUG_39 : handling of 0 byte files if (aFile.fileSize != 0 || (aFile.fileSize == 0 && (section.data.Length - dataReader.BaseStream.Position) > _FILE_INFO_ENTRY_LENGTH)) { aFile.fileName = _UNKNOWN_FILE_NAME + fileCounter; } else { // It's pure padding info aFile.fileName = _PADDING_FILE_NAME + fileCounter; aFile.fileSize = _FileSize - aFile.startAddress; } // TODO 2x4 octets à décrypter.... aFile.unknown1 = dataReader.ReadUInt32(); aFile.unknown2 = dataReader.ReadUInt32(); // aFile.exists = true; aFile.parentBnk = this; // Warning: use private member here to prevent recursive Loading ! __FileList.Add(aFile); } break; #endregion case SectionType.FileName: #region LISTE DE FICHIERS // New loader, recursive if (section.data.Length > 1) { _FileInfoHierarchyRoot = _ReadFileInfoNode(dataReader, 0, null, section.data.Length); } break; #endregion case SectionType.FileOrder: #region ORDONNANCEMENT DES FICHIERS // On récupère l'ordre et on met à jour le nom de fichier try { // Last file is just padding and must no be taken into account for order for (int i = 0; i < __FileList.Count - 1; i++) { // Lecture du numéro de fichier concerné // Si il y a plus de 255 fichiers, on doit lire des valeurs de 2 octets int anOrder = __FileList.Count > 255 ? dataReader.ReadInt16() : dataReader.ReadByte(); // Récupération du nom de fichier PackedFile aFile = __FileList[anOrder]; // Renaming aFile.fileName = _NameList[i]; aFile.filePath = _PathList[i]; // On ajoute le fichier à la liste, au bon emplacement __FileList[anOrder] = aFile; // On met à jour l'index par nom de fichier try { __FileByPathList.Add(aFile.filePath, aFile); } catch (Exception ex) { throw new Exception("Error when adding a file path to index: " + aFile.filePath, ex); } } } catch (Exception ex) { Exception2.PrintStackTrace(ex); throw; } break; #endregion } } }
/// <summary> /// Tries to retrieve TDU version by seeking into Windows registry first, or by alternative ways if it fails. /// </summary> /// <returns>TDU installed version or Unknown value if not found.</returns> internal static TduVersion _SearchForTduVersion() { TduVersion installedVersion = TduVersion.Unknown; // Registry search 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); } string version = key.GetValue(_REGVALUE_TDU_GAME_VERSION) as string; if (version == null) { throw new Exception("TDU version value not found: " + _REGVALUE_TDU_GAME_VERSION); } switch (version) { case _REGDATA_1_45_VERSION: installedVersion = TduVersion.V1_45; break; case _REGDATA_1_66_VERSION: installedVersion = TduVersion.V1_66; break; case _REGDATA_1_66_MEGAPACK_VERSION: installedVersion = TduVersion.V1_66_Megapack; break; default: throw new Exception("Invalid version data in registry: " + installedVersion); } } catch (Exception ex) { // Silent Exception2.PrintStackTrace(new Exception(_ERROR_SEARCH_TDU_VERSION, ex)); } // Alternative ways... if (installedVersion == TduVersion.Unknown) { Log.Info("Searching TDU version from Bnk1.map file size..."); try { // Searching for version according to Bnk1.map file size installedVersion = _SearchForTduVersionFromMap(); } catch (Exception ex) { // Silent Exception2.PrintStackTrace(new Exception(_ERROR_SEARCH_TDU_VERSION, ex)); } } // If nothing works... if (installedVersion == TduVersion.Unknown) { Log.Warning(_ERROR_SEARCH_TDU_VERSION); } return(installedVersion); }
/// <summary> /// Lecture du contenu du fichier /// </summary> protected override void _ReadData() { FileStream input = null; BinaryReader reader = null; try { input = new FileStream(_FileName, FileMode.Open, FileAccess.Read); reader = new BinaryReader(input); // En-tête DDSURFACEDESC2 resultSurface; DDPIXELFORMAT resultPixelFormat; DDCAPS2 resultCaps; _Header.dwMagic = reader.ReadUInt32(); resultSurface.dwSize = reader.ReadUInt32(); resultSurface.dwFlags = reader.ReadUInt32(); resultSurface.dwHeight = reader.ReadUInt32(); resultSurface.dwWidth = reader.ReadUInt32(); resultSurface.dwPitchOrLinearSize = reader.ReadUInt32(); resultSurface.dwDepth = reader.ReadUInt32(); resultSurface.dwMipMapCount = reader.ReadUInt32(); resultSurface.dwReserved1 = reader.ReadBytes(44); resultPixelFormat.dwSize = reader.ReadUInt32(); resultPixelFormat.dwFlags = reader.ReadUInt32(); resultPixelFormat.dwFourCC = reader.ReadUInt32(); resultPixelFormat.dwRGBBitCount = reader.ReadUInt32(); resultPixelFormat.dwRBitMask = reader.ReadUInt32(); resultPixelFormat.dwGBitMask = reader.ReadUInt32(); resultPixelFormat.dwBBitMask = reader.ReadUInt32(); resultPixelFormat.dwRGBAlphaBitMask = reader.ReadUInt32(); resultCaps.dwCaps1 = reader.ReadUInt32(); resultCaps.dwCaps2 = reader.ReadUInt32(); resultCaps.Reserved = reader.ReadBytes(8); resultSurface.dwReserved2 = reader.ReadUInt32(); resultSurface.ddsCaps = resultCaps; resultSurface.ddpfPixelFormat = resultPixelFormat; _Header.ddsd = resultSurface; // Données d'image FileInfo fi = new FileInfo(_FileName); _ImageData = reader.ReadBytes((int)(fi.Length - HEADER_SIZE)); // EVO_65: property support Property.ComputeValueDelegate dimensionsDelegate = delegate { return(resultSurface.dwWidth + "x" + resultSurface.dwHeight); }; Property.ComputeValueDelegate mipmapDelegate = delegate { return(resultSurface.dwMipMapCount.ToString()); }; Property.ComputeValueDelegate formatDelegate = delegate { return(GetFormatName(resultPixelFormat.dwFourCC)); }; Property.ComputeValueDelegate bitCountDelegate = delegate { return(resultPixelFormat.dwRGBBitCount.ToString()); }; _Properties.Add(new Property("Dimensions", "Texture", dimensionsDelegate)); _Properties.Add(new Property("Mipmap count", "Texture", mipmapDelegate)); _Properties.Add(new Property("Format", "DDS", formatDelegate)); _Properties.Add(new Property("RGB bit count", "DDS", bitCountDelegate)); } catch (Exception ex) { Exception2.PrintStackTrace(ex); throw; } finally { // Fermeture if (reader != null) { reader.Close(); } if (input != null) { input.Close(); } } }
/// <summary> /// Convertit un fichier DDS en fichier 2DB (EVO_37). Génère un nouvel en-tête. /// </summary> /// <param name="sourceDDSFile">fichier DDS à convertir</param> /// <param name="target2DBFile">nouveau fichier 2DB à créer</param> /// <param name="newTextureName">if not null, allows to override texture name</param> /// <param name="mipmapCount">if not -1, forces mipmap count</param> public static void DDSTo2DB(string sourceDDSFile, string target2DBFile, string newTextureName, int mipmapCount) { if (sourceDDSFile != null && target2DBFile != null) { DDS ddsFile = (DDS)TduFile.GetFile(sourceDDSFile); DDS.TextureHeader ddsHeader = (DDS.TextureHeader)ddsFile.Header; // Construction d'un fichier 2DB flambant neuf FileInfo fi = new FileInfo(target2DBFile); _2DB new2DBFile = (_2DB)TduFile.GetFile(target2DBFile); _2DB.TextureHeader newHeader = new _2DB.TextureHeader(); string picName; // Override texture name ? if (newTextureName != null) { picName = Tools.NormalizeName(newTextureName); } else { picName = Tools.NormalizeName(fi.Name.ToUpper()); } // Valeurs connues newHeader.bID1 = String2.ToByteArray(_2DB.ID1_STRING); newHeader.bID2 = String2.ToByteArray(_2DB.ID2_STRING); newHeader.dwTwo = 2; newHeader.dwZero1 = newHeader.dwZero2 = newHeader.dwZero3 = 0; newHeader.one = 1; newHeader.height = (short)ddsHeader.ddsd.dwHeight; newHeader.width = (short)ddsHeader.ddsd.dwWidth; newHeader.strName = String2.ToByteArray(picName); // BUG_58 : mipmap count in 2DB takes main texture into account (so always >= 1) uint ddsMipmapCount = ddsHeader.ddsd.dwMipMapCount; // Mipmap count enforcement if (mipmapCount == KEEP_ORIGINAL_MIPMAP_COUNT) { newHeader.bMipMapCount = newHeader.bMipMapCountBis = (byte)(ddsMipmapCount + 1); } else { newHeader.bMipMapCount = newHeader.bMipMapCountBis = (byte)mipmapCount; } // Format & type (linked ??) byte format; uint type; switch (ddsHeader.ddsd.ddpfPixelFormat.dwFourCC) { case DDS.FORMAT_FOURCC_DXT1: format = _2DB.FORMAT_ID_B1; type = _2DB.TYPE_DXT1; break; case DDS.FORMAT_FOURCC_DXT5: format = _2DB.FORMAT_ID_B5; type = _2DB.TYPE_DXT5; break; case DDS.FORMAT_FOURCC_UNKNOWN: format = _2DB.FORMAT_ID_BARGB8; type = _2DB.TYPE_ARGB8; break; default: // Log warning Log.Warning("Unsupported texture format: '" + ddsHeader.ddsd.ddpfPixelFormat.dwFourCC + "'. Treated as DXT5."); // DXT5 format = _2DB.FORMAT_ID_B5; type = _2DB.TYPE_DXT5; break; } newHeader.bFormat = format; newHeader.dwType = type; // TODO A découvrir... et initialiser plus tard newHeader.dwFlags = 512; newHeader.dwUnk6 = 0; newHeader.dwUnk7 = 0; newHeader.bUnk2 = 0; newHeader.unk3 = 0; newHeader.dwUnk4 = 0; // Derniers calculs : taille du fichier uint _2dbSize = (uint)(_2DB.HEADER_SIZE + ddsFile.ImageData.Length + _2DB.FINALIZATION_STRING.Length); newHeader.dwSize = _2dbSize; newHeader.dwSize2 = newHeader.dwSize2Bis = _2dbSize - 32; // Ecriture des sections try { using (BinaryWriter writer = new BinaryWriter(new FileStream(target2DBFile, FileMode.Create, FileAccess.Write))) { // 1. En-tête new2DBFile.Header = newHeader; writer.Write(new2DBFile.HeaderData); // 2. Données d'image writer.Write(ddsFile.ImageData); // Finalisation writer.Write(_2DB.FINALIZATION_STRING); } } catch (IOException ioe) { Exception2.PrintStackTrace(ioe); throw; } } }
/// <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)); }
/// <summary> /// Génére le menu contextuel relatif à la vue concernée /// </summary> /// <param name="baseForm">Form de base</param> /// <param name="args">Parameters : expected [0] viewType, [1] fileName</param> /// <returns></returns> public ContextMenuStrip CreateContextMenu(Form baseForm, params object[] args) { // Parameters ViewType viewType = (ViewType)args[0]; string fileName = args[1] as string; ContextMenuStrip contextMenu = new ContextMenuStrip(); string fileExtension = File2.GetExtensionFromFilename(fileName); FileBrowserForm browserForm = baseForm as FileBrowserForm; if (browserForm == null) { return(contextMenu); } // Récupère l'éditeur par défaut pour le fichier string defaultEditor = FileHandler.DefaultEditor; if (!string.IsNullOrEmpty(fileExtension)) { try { FileHandler f = FileHandler.GetHandler(fileName); // On récupère l'éditeur par réflexion if (f != null) { PropertyInfo pi = f.GetType().GetProperty(_PROPERTY_NAME_DEFAULT_EDITOR); defaultEditor = (string)pi.GetValue(f.GetType(), null); } } catch (Exception ex) { // Erreur silencieuse string message = string.Format(_ERROR_DEFAULT_EDITOR, fileExtension); Exception2.PrintStackTrace(new Exception(message, ex)); } } if (viewType == ViewType.FileList) { // Liste de fichiers // Selon l'extension if (fileExtension != null) { switch (fileExtension.ToUpper()) { case "": // Commandes communes // EVO_149: Backup contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget); contextMenu.Items.Add(new ToolStripSeparator()); break; case LibraryConstants.EXTENSION_BNK_FILE: // Extract contextMenu.Items.Add(_MENU_ITEM_EXTRACT_ALL, null, browserForm.ExtractAllBnkTarget); contextMenu.Items.Add(new ToolStripSeparator()); // Backup contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget); contextMenu.Items.Add(new ToolStripSeparator()); break; case LibraryConstants.EXTENSION_BACKUP: // Restore contextMenu.Items.Add(_MENU_ITEM_RESTORE, null, browserForm.RestoreTarget); contextMenu.Items.Add(new ToolStripSeparator()); break; default: // Open contextMenu.Items.Add(string.Format(_MENU_ITEM_OPEN, defaultEditor), null, browserForm.OpenFileTarget); contextMenu.Items.Add(new ToolStripSeparator()); // Backup contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget); contextMenu.Items.Add(new ToolStripSeparator()); break; } // Commandes communes : Delete, Properties contextMenu.Items.Add(_MENU_ITEM_DELETE, null, browserForm.DeleteFileTarget); // EVO_65 : properties contextMenu.Items.Add(new ToolStripSeparator()); contextMenu.Items.Add(_MENU_ITEM_PROPERTIES, null, browserForm.PropertiesTarget); } } else if (viewType == ViewType.ContentListFlat || viewType == ViewType.ContentListHierarchical) { // BNK contents contextMenu.Items.Add(_MENU_ITEM_REPLACE_KEEP, null, browserForm.ReplaceKeepNameTarget); contextMenu.Items.Add(_MENU_ITEM_REPLACE_RENAME, null, browserForm.ReplaceRenameTarget); contextMenu.Items.Add(new ToolStripSeparator()); contextMenu.Items.Add(_MENU_ITEM_EXTRACT, null, browserForm.ExtractBnkTarget); if (browserForm._SelectedPackedFilesCount == 1) { contextMenu.Items.Add(_MENU_ITEM_RENAME, null, browserForm.RenameTarget); } //contextMenu.Items.Add(string.Format(_MENU_ITEM_OPEN_PACKED, defaultEditor), null, browserForm.ViewContentTarget); contextMenu.Items.Add(string.Format(_MENU_ITEM_EDIT_PACKED, defaultEditor), null, browserForm.EditContentTarget); /*contextMenu.Items.Add(new ToolStripSeparator()); * contextMenu.Items.Add(_MENU_ITEM_DELETE, null, browserForm.DeletePackedTarget);*/ // EVO_65: properties contextMenu.Items.Add(new ToolStripSeparator()); contextMenu.Items.Add(_MENU_ITEM_PROPERTIES, null, browserForm.PackedPropertiesTarget); } else if (viewType == ViewType.FolderTree) { // Arborescence de dossiers // Pas de clic droit géré } return(contextMenu); }
/// <summary> /// Convertit de liste de config de lancement en chaîne /// </summary> /// <param name="configList"></param> /// <returns></returns> public static string ConvertToString(Collection <LaunchConfiguration> configList) { string returnedValue = null; if (configList != null) { StringBuilder sbResult = new StringBuilder(); int itemCount = 0; foreach (LaunchConfiguration config in configList) { itemCount++; try { // 0. Nom sbResult.Append(config.Name); sbResult.Append(_VALUE_SEPARATOR); // 1. Default sbResult.Append(config.Default.ToString()); sbResult.Append(_VALUE_SEPARATOR); // 2. Mode fenetré sbResult.Append(config.WindowedMode.ToString()); sbResult.Append(_VALUE_SEPARATOR); // 3. FPS sbResult.Append(config.FpsDisplayed.ToString()); sbResult.Append(_VALUE_SEPARATOR); // 4. Nettoyage radial sbResult.Append(config.CleanRadial.ToString()); sbResult.Append(_VALUE_SEPARATOR); // 5. Commande avant lancement if (config.PreviousCommand == null) { sbResult.Append(""); } else { sbResult.Append(config.PreviousCommand); } sbResult.Append(_VALUE_SEPARATOR); // 6. Commande après lancement if (config.NextCommand == null) { sbResult.Append(""); } else { sbResult.Append(config.NextCommand); } sbResult.Append(_VALUE_SEPARATOR); // 7. Coordinates sbResult.Append(config.PosDisplayed.ToString()); // Item suivant if (itemCount != configList.Count) { sbResult.Append(_ITEM_SEPARATOR); } } catch (Exception ex) { Exception2.PrintStackTrace(ex); } } returnedValue = sbResult.ToString(); } return(returnedValue); }