private void contextMenuTreeView_Opening(object sender, CancelEventArgs e) { TreeNode selNode = (TreeNode)treeView.GetNodeAt(treeView.PointToClient(Cursor.Position)); if (selNode == null || selNode.Parent == null) { e.Cancel = true; return; } extractToolStripMenuItem.Enabled = true; removeModToolStripMenuItem.Enabled = false; unlocalizeToolStripMenuItem.Enabled = false; removeUnlocalizeToolStripMenuItem.Enabled = false; packThisFolderToolStripMenuItem.Enabled = false; removeResourceToolStripMenuItem.Enabled = false; reintroduceResourceToolStripMenuItem.Enabled = false; doNotPackThisFolderToolStripMenuItem.Enabled = false; if (selNode != null) { //Mod File string filePath = GetWorkspaceFileFromNode(selNode); if (File.Exists(filePath)) { removeModToolStripMenuItem.Enabled = true; return; } //Mod Folder if (Directory.Exists(filePath)) { removeModToolStripMenuItem.Enabled = true; //Can pack if (_ProjectManager.CanBePacked(selNode.Name)) { ResourceCollection resCol = _ProjectManager.GetResourceCollection(selNode.Name); string relativePath = _ProjectManager.GetRelativePath(selNode.Name); if (_ProjectManager.CurrentProject.IsResourceToBePacked(resCol.PartitionName, relativePath)) { doNotPackThisFolderToolStripMenuItem.Enabled = true; } else { packThisFolderToolStripMenuItem.Enabled = true; } } return; } ResourceItem rItem = _ProjectManager.GetResource(selNode.Name); if (rItem != null) { if (rItem.ResourceCollection.IsRegion && rItem.OffInPack == 0) { if (!_ProjectManager.CurrentProject.IsUnlocalized(rItem.ResourceCollection.PartitionName, rItem.RelativePath)) { unlocalizeToolStripMenuItem.Enabled = true; } else { removeUnlocalizeToolStripMenuItem.Enabled = true; } } if (!_ProjectManager.CurrentProject.IsResourceRemoved(rItem.ResourceCollection.PartitionName, rItem.RelativePath)) { removeResourceToolStripMenuItem.Enabled = true; } else { reintroduceResourceToolStripMenuItem.Enabled = true; } return; } } e.Cancel = true; }
private void RefreshTreeNodeStyle(TreeNode node, bool recursive) { if (node == null) { return; } ResourceItem rItem = _ProjectManager.GetResource(node.Name); //See for subnodes if (rItem != null && node.Nodes.Count == 0 && rItem.Nodes.Count != 0) { PopulateTreeViewResources(node, rItem.Nodes, rItem.ResourceCollection.IsRegion); } PopulateTreeViewWorkspace(node); //Checking if file is in workspace (mod) string modPath = GetWorkspaceFileFromNode(node); if (File.Exists(modPath)) { node.ForeColor = UIConstants.NODE_MOD; node.SelectedImageKey = UIConstants.ICON_FILE; node.ImageKey = UIConstants.ICON_FILE; } else if (Directory.Exists(modPath)) { node.ForeColor = UIConstants.NODE_MOD; node.SelectedImageKey = UIConstants.ICON_FOLDER; node.ImageKey = UIConstants.ICON_FOLDER; } else if (rItem != null) { if (_ProjectManager.CurrentProject.IsResourceRemoved(rItem.ResourceCollection.PartitionName, rItem.RelativePath)) { node.ForeColor = UIConstants.NODE_MOD_DELETED; } else if (_ProjectManager.CurrentProject.IsUnlocalized(rItem.ResourceCollection.PartitionName, rItem.RelativePath)) { node.ForeColor = UIConstants.NODE_MOD_UNLOCALIZED; } else if (rItem.Source == FileSource.Patch) { node.ForeColor = UIConstants.NODE_PATCH; } else if (rItem.Source == FileSource.LS || rItem.Source == FileSource.NotFound) { node.ForeColor = UIConstants.NODE_LS; } } else { LogHelper.Warning(string.Format("The node '{0}' could not be found and has been removed.", node.Name)); node.Remove(); } if (rItem != null) { if (rItem.IsFolder) { if (rItem.IsAPackage) { node.SelectedImageKey = UIConstants.ICON_PACKED; node.ImageKey = UIConstants.ICON_PACKED; } else { node.SelectedImageKey = UIConstants.ICON_FOLDER; node.ImageKey = UIConstants.ICON_FOLDER; } } else { node.SelectedImageKey = UIConstants.ICON_FILE; node.ImageKey = UIConstants.ICON_FILE; } } //Plugins ResourceCollection resCol = _ProjectManager.GetResourceCollection(node.Name); foreach (Sm4shBasePlugin plugin in _ProjectManager.Plugins) { if (plugin.Icons == null) { continue; } int result = plugin.InternalCanResourceBeLoaded(resCol, _ProjectManager.GetRelativePath(node.Name)); if (result > -1 && result < plugin.Icons.Length) { node.SelectedImageKey = plugin.Name + result.ToString(); node.ImageKey = plugin.Name + result.ToString(); break; } } if (recursive && node.IsExpanded) { foreach (TreeNode childNode in node.Nodes) { RefreshTreeNodeStyle(childNode, recursive); } } }
public SoundMSBTFile(Sm4shProject projectManager, SoundEntryCollection sEntryCollection, string path) { _ResCol = projectManager.GetResourceCollection(path); string soundMSBTFile = projectManager.ExtractResource(path, PathHelper.FolderTemp); SoundEntryCollection = sEntryCollection; _VarsMSBT = new SortedDictionary <string, MSBTVariable>(); _Path = path; using (FileStream fileStream = File.Open(soundMSBTFile, FileMode.Open)) { using (BinaryReader b = new BinaryReader(fileStream)) { ParseFileHeader(b); if (_Header.Label != "MsgStdBn") { throw new Exception(string.Format("Can't load '{0}', the file doesn't appear to be a MSBT file.", soundMSBTFile)); } //Keep header b.BaseStream.Position = 0; uint offSetLBL1 = HEADER_LEN; //Getting offset to ATR1 b.BaseStream.Position = offSetLBL1; _SectionLBL1 = ParseSectionHeader(b); if (_SectionLBL1.Label != "LBL1") { throw new Exception(string.Format("Error while reading '{0}', can't find LBL1 section.", soundMSBTFile)); } uint offSetATR1 = offSetLBL1 + HEADER_LBL1 + _SectionLBL1.SectionSize; while (offSetATR1 % 0x10 != 0)// || offSetATR1 == offSetLBL1 + HEADER_LBL1 + _SectionLBL1.SectionSize) { offSetATR1++; } //Getting offset to TXT2 b.BaseStream.Position = offSetATR1; _SectionATR1 = ParseSectionHeader(b); if (_SectionATR1.Label != "ATR1") { throw new Exception(string.Format("Error while reading '{0}', can't find ATR1 section.", soundMSBTFile)); } b.BaseStream.Position = offSetATR1 + HEADER_ATR1; _ATR1Bloc = b.ReadBytes((int)_SectionATR1.SectionSize); uint offSetTXT2 = offSetATR1 + HEADER_ATR1 + _SectionATR1.SectionSize; while (offSetTXT2 % 0x10 != 0)// || offSetTXT2 == offSetATR1 + HEADER_ATR1 + _SectionATR1.SectionSize) { offSetTXT2++; } //Parsing TXT2 b.BaseStream.Position = offSetTXT2; _SectionTXT2 = ParseSectionHeader(b); if (_SectionTXT2.Label != "TXT2") { throw new Exception(string.Format("Error while reading '{0}', can't find TXT2 section.", soundMSBTFile)); } b.BaseStream.Position += 8; uint txt2NbrEntries = ReadUInt32BigEndian(b); uint[] offSetIntList = new uint[txt2NbrEntries]; for (int i = 0; i < txt2NbrEntries; i++) { offSetIntList[i] = ReadUInt32BigEndian(b); } b.BaseStream.Position = offSetTXT2 + HEADER_TXT2; byte[] txt2Bloc = b.ReadBytes((int)_SectionTXT2.SectionSize); string[] msbtvariables = GetMSBTStringVariables(txt2Bloc, txt2NbrEntries, offSetIntList); //Associate strings to variable names b.BaseStream.Position = offSetLBL1 + HEADER_LBL1; _SizeHashTable = ReadUInt32BigEndian(b); uint lbl1ChecksumSize = _SizeHashTable * 0x8; uint nbrEntries = 0; for (int i = 0; i < _SizeHashTable; i++) { nbrEntries += ReadUInt32BigEndian(b); b.BaseStream.Position += 4; } if (msbtvariables.Length != nbrEntries) { throw new Exception(string.Format("Error while reading '{0}', the number of LBL1 entries doesn't match the number of TXT2 entries.", soundMSBTFile)); } b.BaseStream.Position = offSetLBL1 + HEADER_LBL1 + 0x4 + lbl1ChecksumSize; for (int i = 0; i < nbrEntries; i++) { string variableName = b.ReadString(); uint variableIndex = ReadUInt32BigEndian(b); MSBTVariable newVariable = new MSBTVariable(variableName, msbtvariables[variableIndex]); _VarsMSBT.Add(variableName, newVariable); } } } //Assign SoundEntries variables if (!_ResCol.IsRegion) { foreach (SoundEntry sEntry in sEntryCollection.SoundEntries) { sEntry.Title = GetVariableValue(VAR_TITLE + sEntry.OriginalSoundLabel, Strings.DEFAULT_SENTRY_TITLE); sEntry.SoundTestTitle = GetVariableValue(VAR_TITLE2 + sEntry.OriginalSoundLabel, Strings.DEFAULT_SENTRY_TITLE2); sEntry.Description = GetVariableValue(VAR_DESCRIPTION + sEntry.OriginalSoundLabel, string.Empty); sEntry.Description2 = GetVariableValue(VAR_DESCRIPTION2 + sEntry.OriginalSoundLabel, string.Empty); sEntry.Source = GetVariableValue(VAR_SOURCE + sEntry.OriginalSoundLabel, string.Empty); } } }