private void GetEntryType(EntryViewModel entry) { if (entry.ResourceMapEntry is ResourceMapScope) { entry.Icon = "/Assets/folder-horizontal.png"; } else { entry.Icon = "/Assets/blue-document.png"; ResourceMapItem resourceMapItem = (ResourceMapItem)entry.ResourceMapEntry; CandidateViewModel[] candidates = EnumerateCandidates(resourceMapItem) .Select(candidate => new CandidateViewModel(PriFile, PriStream, ResourceRootPath, resourceMapItem, candidate)).ToArray(); if (candidates.Length == 0) { entry.Icon = "/Assets/document.png"; } else if (candidates.All(c => c.SourceNotFound || c.LocationNotFound)) { entry.Icon = "/Assets/blue-document-attribute-x.png"; } else if (candidates.All( c => c.Candidate.Type == ResourceValueType.String || c.Candidate.Type == ResourceValueType.AsciiString || c.Candidate.Type == ResourceValueType.Utf8String)) { entry.Icon = "/Assets/blue-document-attribute-s.png"; entry.IsString = true; } else if (resourceMapItem.Name.EndsWith(".xbf", StringComparison.OrdinalIgnoreCase) || resourceMapItem.Name.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase)) { entry.Icon = "/Assets/blue-document-xaml.png"; } } }
private void CollapseStringResources(EntryViewModel entry) { if (ContainsOnlyStringResources(entry)) { Dictionary <EntryViewModel, string> strings = new Dictionary <EntryViewModel, string>(); CollectStringResources(entry, string.Empty, strings); entry.Children.Clear(); foreach (KeyValuePair <EntryViewModel, string> s in strings) { entry.Children.Add(new StringEntryViewModel(s.Key.ResourceMapEntry, s.Value)); } } else { foreach (EntryViewModel child in entry.Children) { if (child.Type == EntryType.Scope) { CollapseStringResources(child); } } } }
private void GetEntries() { Entries.Clear(); Candidates.Clear(); ResourceMapSection primaryResourceMapSection = PriFile.GetSectionByRef(PriFile.PriDescriptorSection.PrimaryResourceMapSection.Value); HierarchicalSchemaSection schemaSection = PriFile.GetSectionByRef(primaryResourceMapSection.SchemaSection); Dictionary <ResourceMapEntry, EntryViewModel> entriesToViewModels = new Dictionary <ResourceMapEntry, EntryViewModel>(); bool parentMissing = false; do { foreach (ResourceMapScope scope in schemaSection.Scopes) { if (scope.FullName == string.Empty) { continue; } IList <EntryViewModel> targetEntryCollection; if (scope.Parent == null) { targetEntryCollection = Entries; } else { EntryViewModel parentViewModel; if (scope.Parent.FullName == string.Empty) { targetEntryCollection = Entries; } else if (!entriesToViewModels.TryGetValue(scope.Parent, out parentViewModel)) { parentMissing = true; continue; } else { targetEntryCollection = parentViewModel.Children; } } EntryViewModel entry = new EntryViewModel(scope); GetEntryType(entry); entriesToViewModels.Add(scope, entry); targetEntryCollection.Add(entry); } } while (parentMissing); foreach (ResourceMapItem item in schemaSection.Items) { EntryViewModel parentViewModel; if (!entriesToViewModels.TryGetValue(item.Parent, out parentViewModel)) { continue; } parentViewModel.Children.Add(new EntryViewModel(item)); GetEntryType(parentViewModel.Children.Last()); } CollapseStringResources(); }