void XmlToNode(XmlDocument xml, XmlNodeList elements, NesMenuCollection rootMenuCollection, NesMenuCollection nesMenuCollection = null) { if (nesMenuCollection == null) { nesMenuCollection = rootMenuCollection; } foreach (XmlNode element in elements) { switch (element.Name) { case "Folder": var folder = new NesMenuFolder(element.Attributes["name"].Value, element.Attributes["icon"].Value); folder.Position = (NesMenuFolder.Priority) byte.Parse(element.Attributes["position"].Value); nesMenuCollection.Add(folder); XmlToNode(xml, element.ChildNodes, rootMenuCollection, folder.ChildMenuCollection); break; case "Game": case "OriginalGame": var code = element.Attributes["code"].Value; var games = from n in rootMenuCollection where ((n is NesMiniApplication || n is NesDefaultGame) && (n.Code == code)) select n; if (games.Count() > 0) { var game = games.First(); nesMenuCollection.Add(game); rootMenuCollection.Remove(game); } break; } } }
public void AddBack(List <NesMenuCollection> ignore = null) { bool root = false; if (ignore == null) { ignore = new List <NesMenuCollection>(); root = true; } ignore.Add(this); foreach (NesMenuFolder item in from i in this where i is NesMenuFolder select i) { if (ignore.Contains(item.ChildMenuCollection)) { continue; } var back = new NesMenuFolder(Resources.FolderNameBack, "folder_back"); back.Position = ConfigIni.Instance.BackFolderPosition; back.ChildMenuCollection = this; item.ChildMenuCollection.AddBack(ignore); item.ChildMenuCollection.Add(back); if (!root && ConfigIni.Instance.HomeFolder) { var rootFolder = new NesMenuFolder(Resources.FolderNameHome, "folder_home"); rootFolder.Position = ConfigIni.Instance.BackFolderPosition; rootFolder.ChildMenuCollection = ignore.First(); item.ChildMenuCollection.Add(rootFolder); } } }
void XmlToTree(string xmlString) { gamesCollection.Unsplit(); var oldCollection = new NesMenuCollection(); oldCollection.AddRange(gamesCollection); var xml = new XmlDocument(); xml.LoadXml(xmlString); gamesCollection.Clear(); XmlToNode(xml, xml.SelectSingleNode("/Tree").ChildNodes, oldCollection, gamesCollection); // oldCollection has only unsorted (new) games if (oldCollection.Count > 0) { NesMenuFolder unsorted; var unsorteds = from f in gamesCollection where f is NesMenuFolder && f.Name == Resources.FolderNameUnsorted select f; if (unsorteds.Count() > 0) { unsorted = unsorteds.First() as NesMenuFolder; } else { unsorted = new NesMenuFolder(Resources.FolderNameUnsorted); unsorted.Position = NesMenuFolder.Priority.Leftmost; gamesCollection.Add(unsorted); } foreach (var game in oldCollection) { unsorted.ChildMenuCollection.Add(game); } MessageBox.Show(this, Resources.NewGamesUnsorted, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } DrawTree(); }
void XmlToTree(string xmlString) { GamesCollection.Unsplit(); var oldCollection = new NesMenuCollection(); oldCollection.AddRange(GamesCollection); var xml = new XmlDocument(); xml.LoadXml(xmlString); GamesCollection.Clear(); XmlToNode(xml, xml.SelectSingleNode("/Tree").ChildNodes, oldCollection, GamesCollection); // oldCollection has only unsorted (new) games if (oldCollection.Count > 0) { var unsorted = new NesMenuFolder(Resources.FolderNameUnsorted); unsorted.Position = NesMenuFolder.Priority.Leftmost; foreach (var game in oldCollection) { unsorted.ChildMenuCollection.Add(game); } GamesCollection.Add(unsorted); MessageBox.Show(this, Resources.NewGamesUnsorted, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } DrawTree(); }
public void AddBack(List <NesMenuCollection> ignore = null) { if (ignore == null) { ignore = new List <NesMenuCollection>(); } ignore.Add(this); foreach (NesMenuFolder item in from i in this where i is NesMenuFolder select i) { if (ignore.Contains(item.ChildMenuCollection)) { continue; } var back = new NesMenuFolder(Resources.FolderNameBack, "folder_back"); back.Position = NesMenuFolder.Priority.Back; back.ChildMenuCollection = this; item.ChildMenuCollection.AddBack(ignore); item.ChildMenuCollection.Add(back); } }
TreeNode getUnsortedFolder() { var root = treeView.Nodes[0]; foreach (TreeNode el in root.Nodes) { if (el.Text == Resources.FolderNameUnsorted && el.Tag is NesMenuFolder) { return(el); } } var newNode = new TreeNode(Resources.FolderNameUnsorted, 0, 0); var newFolder = new NesMenuFolder(newNode.Text); newFolder.Position = NesMenuFolder.Priority.Leftmost; newNode.Tag = newFolder; (root.Tag as NesMenuCollection).Add(newFolder); root.Nodes.Add(newNode); return(newNode); }
TreeNode getFolder(string name) { var root = treeView.Nodes[0]; foreach (TreeNode el in root.Nodes) { if (el.Text == name && el.Tag is NesMenuFolder) { return(el); } } var newNode = new TreeNode(name, 0, 0); var newFolder = new NesMenuFolder(newNode.Text); newFolder.Position = NesMenuFolder.Priority.Leftmost; newNode.Tag = newFolder; (root.Tag as NesMenuCollection).Add(newFolder); root.Nodes.Add(newNode); return(newNode); }
void newFolder(TreeNode parent = null) { var newFolder = new NesMenuFolder(Resources.FolderNameNewFolder); var folderImageIndex = getImageIndex(newFolder); var newnode = new TreeNode(Resources.FolderNameNewFolder, folderImageIndex, folderImageIndex); newnode.Tag = newFolder; if (parent != null) { parent.Nodes.Add(newnode); treeView.SelectedNode = newnode; ShowSelected(); newnode.BeginEdit(); } else if (treeView.SelectedNode != null) { parent = treeView.SelectedNode; parent.Nodes.Add(newnode); ShowFolderStats(); var item = new ListViewItem(newnode.Text, folderImageIndex); item.Tag = newnode; listViewContent.SelectedItems.Clear(); listViewContent.Items.Add(item); item.BeginEdit(); } if (parent != null) { if (parent.Tag is NesMenuFolder) { (parent.Tag as NesMenuFolder).ChildMenuCollection.Add(newFolder); } else if (parent.Tag is NesMenuCollection) { (parent.Tag as NesMenuCollection).Add(newFolder); } } }
public void Split(SplitStyle style, int maxElements = 35) { bool originalToRoot = false; int originalCount = 0; switch (style) { case SplitStyle.Original_NoSplit: case SplitStyle.Original_Auto: case SplitStyle.Original_FoldersAlphabetic_FoldersEqual: case SplitStyle.Original_FoldersAlphabetic_PagesEqual: case SplitStyle.Original_FoldersEqual: case SplitStyle.Original_PagesEqual: style--; originalCount = this.Where(o => (o is NesApplication) && (o as NesApplication).IsOriginalGame).Count(); if (originalCount > 0) { originalToRoot = true; } break; } if (style == SplitStyle.NoSplit && !originalToRoot) { return; } if (((style == SplitStyle.Auto && !originalToRoot) || (style == SplitStyle.FoldersEqual && !originalToRoot) || (style == SplitStyle.PagesEqual) && !originalToRoot) && (Count <= maxElements)) { return; } var total = Count - originalCount; var partsCount = (int)Math.Ceiling((float)total / (float)maxElements); var perPart = (int)Math.Ceiling((float)total / (float)partsCount); var alphaNum = new Regex(@"[^\p{L}\p{Nd}0-9]", RegexOptions.Compiled); //var alphaNum = new Regex("[^a-zA-Z0-9]"); NesMenuCollection root; if (!originalToRoot) { root = this; } else { root = new NesMenuCollection(); root.AddRange(this.Where(o => (o is NesApplication) && !(o as NesApplication).IsOriginalGame)); if (root.Count == 0) { return; } this.RemoveAll(o => root.Contains(o)); this.Add(new NesMenuFolder() { Name = Resources.FolderNameMoreGames, Position = NesMenuFolder.Priority.Rightmost, ChildMenuCollection = root }); } var sorted = root.OrderBy(o => o.SortName); var collections = new List <NesMenuCollection>(); int i = 0; if (style == SplitStyle.Auto || style == SplitStyle.FoldersEqual || style == SplitStyle.PagesEqual) { var collection = new NesMenuCollection(); foreach (var game in sorted) { collection.Add(game); i++; if (((i % perPart) == 0) || (i == sorted.Count())) { collections.Add(collection); collection = new NesMenuCollection(); } } } if (style == SplitStyle.Auto) { if (collections.Count >= 12) { style = SplitStyle.FoldersEqual; } else { style = SplitStyle.PagesEqual; } } // Folders, equal if (style == SplitStyle.FoldersEqual) // minimum amount of games/folders on screen without glitches { root.Clear(); foreach (var coll in collections) { var fname = alphaNum.Replace(coll.Where(o => o is NesApplication).First().SortName.ToUpper(), ""); var lname = alphaNum.Replace(coll.Where(o => o is NesApplication).Last().SortName.ToUpper(), ""); System.Diagnostics.Debug.WriteLine($"fname:\"{fname}\", lname:\"{lname}\""); var folder = new NesMenuFolder() { ChildMenuCollection = coll, NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Right }; coll.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); root.Add(folder); } TrimFolderNames(root); } else if (style == SplitStyle.PagesEqual) // Pages, equal { root.Clear(); root.AddRange(collections[0]); collections[0] = root; for (i = 0; i < collections.Count; i++) { for (int j = i - 1; j >= 0; j--) { var fname = alphaNum.Replace(collections[j].Where(o => o is NesApplication).First().SortName.ToUpper(), ""); var lname = alphaNum.Replace(collections[j].Where(o => o is NesApplication).Last().SortName.ToUpper(), ""); var folder = new NesMenuFolder() { ChildMenuCollection = collections[j], NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Left }; collections[i].Insert(0, folder); } for (int j = i + 1; j < collections.Count; j++) { var fname = alphaNum.Replace(collections[j].Where(o => o is NesApplication).First().SortName.ToUpper(), ""); var lname = alphaNum.Replace(collections[j].Where(o => o is NesApplication).Last().SortName.ToUpper(), ""); var folder = new NesMenuFolder() { ChildMenuCollection = collections[j], NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Right }; collections[i].Insert(collections[i].Count, folder); } TrimFolderNames(collections[i]); } } else if (style == SplitStyle.FoldersAlphabetic_PagesEqual || style == SplitStyle.FoldersAlphabetic_FoldersEqual) { var letters = new Dictionary <char, NesMenuCollection>(); for (char ch = 'A'; ch <= 'Z'; ch++) { letters[ch] = new NesMenuCollection(); } letters['#'] = new NesMenuCollection(); foreach (var game in root) { if (!(game is NesApplication)) { continue; } var letter = game.SortName.Substring(0, 1).ToUpper()[0]; if (letter < 'A' || letter > 'Z') { letter = '#'; } letters[letter].Add(game); } root.Clear(); foreach (var letter in letters.Keys) { if (letters[letter].Count > 0) { string folderImageId = "folder_" + letter.ToString().ToLower(); if (letter < 'A' || letter > 'Z') { folderImageId = "folder_number"; } var folder = new NesMenuFolder() { ChildMenuCollection = letters[letter], Name = letter.ToString(), Position = NesMenuFolder.Priority.Right, ImageId = folderImageId }; if (style == SplitStyle.FoldersAlphabetic_PagesEqual) { folder.ChildMenuCollection.Split(SplitStyle.PagesEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); foreach (NesMenuFolder f in folder.ChildMenuCollection.Where(o => o is NesMenuFolder)) { if (f.ChildMenuCollection != root) { f.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); } } } else if (style == SplitStyle.FoldersAlphabetic_FoldersEqual) { folder.ChildMenuCollection.Split(SplitStyle.FoldersEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); } root.Add(folder); } } } else if (style == SplitStyle.FoldersGroupByApp) { var apps = new SortedDictionary <string, NesMenuCollection>(); var customApps = new Dictionary <string, NesMenuCollection>(); foreach (var system in CoreCollection.Systems) { apps[system] = new NesMenuCollection(); } foreach (var ai in AppTypeCollection.Apps) { if (!apps.ContainsKey(ai.Name)) { apps[ai.Name] = new NesMenuCollection(); } } apps[AppTypeCollection.UnknownApp.Name] = new NesMenuCollection(); foreach (var game in root) { if (!(game is NesApplication)) { continue; } NesApplication app = game as NesApplication; AppTypeCollection.AppInfo ai = app.Metadata.AppInfo; if (!ai.Unknown && apps.ContainsKey(ai.Name)) { apps[ai.Name].Add(game); } else if (!string.IsNullOrEmpty(app.Metadata.System) && apps.ContainsKey(app.Metadata.System)) { apps[app.Metadata.System].Add(game); } else { if (!string.IsNullOrEmpty(app.Desktop.Bin)) { if (!customApps.ContainsKey(app.Desktop.Bin)) { customApps.Add(app.Desktop.Bin, new NesMenuCollection()); } customApps[app.Desktop.Bin].Add(game); } else { apps[AppTypeCollection.UnknownApp.Name].Add(game); } } } root.Clear(); foreach (var app in apps) { if (app.Value.Count > 0) { string folderImageId = "folder"; var folder = new NesMenuFolder() { ChildMenuCollection = app.Value, Name = app.Key, Position = NesMenuFolder.Priority.Right, ImageId = folderImageId }; //folder.ChildMenuCollection.Split(SplitStyle.FoldersEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); root.Add(folder); } } foreach (var app in customApps) { if (app.Value.Count > 0) { string folderImageId = "folder"; var folder = new NesMenuFolder() { ChildMenuCollection = app.Value, Name = app.Key, Position = NesMenuFolder.Priority.Right, ImageId = folderImageId }; //folder.ChildMenuCollection.Split(SplitStyle.FoldersEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = root }); root.Add(folder); } } } if (originalToRoot) { if (style != SplitStyle.PagesEqual) { root.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = this }); } else { foreach (var collection in collections) { collection.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, ImageId = "folder_back", Position = ConfigIni.Instance.BackFolderPosition, ChildMenuCollection = this }); } } } }
public void Split(SplitStyle style, int maxElements = 35) { bool originalToRoot = false; switch (style) { case SplitStyle.Original_NoSplit: case SplitStyle.Original_Auto: case SplitStyle.Original_FoldersAlphabetic_FoldersEqual: case SplitStyle.Original_FoldersAlphabetic_PagesEqual: case SplitStyle.Original_FoldersEqual: case SplitStyle.Original_PagesEqual: style--; if (this.Where(o => o is NesDefaultGame).Count() > 0) { originalToRoot = true; } break; } if (style == SplitStyle.NoSplit && !originalToRoot) { return; } if (((style == SplitStyle.Auto && !originalToRoot) || style == SplitStyle.FoldersEqual || style == SplitStyle.PagesEqual) && (Count <= maxElements)) { return; } var total = Count; var partsCount = (int)Math.Ceiling((float)total / (float)maxElements); var perPart = (int)Math.Ceiling((float)total / (float)partsCount); var alphaNum = new Regex("[^a-zA-Z0-9]"); NesMenuCollection root; if (!originalToRoot) { root = this; } else { root = new NesMenuCollection(); root.AddRange(this.Where(o => !(o is NesDefaultGame))); if (root.Count == 0) { return; } this.RemoveAll(o => !(o is NesDefaultGame)); this.Add(new NesMenuFolder() { Name = Resources.FolderNameMoreGames, Position = NesMenuFolder.Priority.Rightmost, ChildMenuCollection = root }); } var sorted = root.OrderBy(o => o.Name); var collections = new List <NesMenuCollection>(); int i = 0; if (style == SplitStyle.Auto || style == SplitStyle.FoldersEqual || style == SplitStyle.PagesEqual) { var collection = new NesMenuCollection(); foreach (var game in sorted) { collection.Add(game); i++; if (((i % perPart) == 0) || (i == sorted.Count())) { collections.Add(collection); collection = new NesMenuCollection(); } } } if (style == SplitStyle.Auto) { if (collections.Count >= 12) { style = SplitStyle.FoldersEqual; } else { style = SplitStyle.PagesEqual; } } // Folders, equal if (style == SplitStyle.FoldersEqual) // minimum amount of games/folders on screen without glitches { root.Clear(); foreach (var coll in collections) { var fname = alphaNum.Replace(coll.Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).First().Name.ToUpper(), ""); var lname = alphaNum.Replace(coll.Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).Last().Name.ToUpper(), ""); var folder = new NesMenuFolder() { ChildMenuCollection = coll, NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Right }; coll.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = root }); root.Add(folder); } TrimFolderNames(root); } else if (style == SplitStyle.PagesEqual) // Pages, equal { root.Clear(); root.AddRange(collections[0]); collections[0] = root; for (i = 0; i < collections.Count; i++) { for (int j = i - 1; j >= 0; j--) { var fname = alphaNum.Replace(collections[j].Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).First().Name.ToUpper(), ""); var lname = alphaNum.Replace(collections[j].Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).Last().Name.ToUpper(), ""); var folder = new NesMenuFolder() { ChildMenuCollection = collections[j], NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Left }; collections[i].Insert(0, folder); } for (int j = i + 1; j < collections.Count; j++) { var fname = alphaNum.Replace(collections[j].Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).First().Name.ToUpper(), ""); var lname = alphaNum.Replace(collections[j].Where(o => (o is NesMiniApplication) || (o is NesDefaultGame)).Last().Name.ToUpper(), ""); var folder = new NesMenuFolder() { ChildMenuCollection = collections[j], NameParts = new string[] { fname, lname }, Position = NesMenuFolder.Priority.Right }; collections[i].Insert(collections[i].Count, folder); } TrimFolderNames(collections[i]); } } else if (style == SplitStyle.FoldersAlphabetic_PagesEqual || style == SplitStyle.FoldersAlphabetic_FoldersEqual) { var letters = new Dictionary <char, NesMenuCollection>(); for (char ch = 'A'; ch <= 'Z'; ch++) { letters[ch] = new NesMenuCollection(); } letters['#'] = new NesMenuCollection(); foreach (var game in root) { if (!(game is NesMiniApplication || game is NesDefaultGame)) { continue; } var letter = game.Name.Substring(0, 1).ToUpper()[0]; if (letter < 'A' || letter > 'Z') { letter = '#'; } letters[letter].Add(game); } root.Clear(); foreach (var letter in letters.Keys) { if (letters[letter].Count > 0) { string folderImageId = "folder_" + letter.ToString().ToLower(); if (letter < 'A' || letter > 'Z') { folderImageId = "folder_number"; } var folder = new NesMenuFolder() { ChildMenuCollection = letters[letter], Name = letter.ToString(), Position = NesMenuFolder.Priority.Right, ImageId = folderImageId }; if (style == SplitStyle.FoldersAlphabetic_PagesEqual) { folder.ChildMenuCollection.Split(SplitStyle.PagesEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = root }); foreach (NesMenuFolder f in folder.ChildMenuCollection.Where(o => o is NesMenuFolder)) { if (f.ChildMenuCollection != root) { f.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = root }); } } } else if (style == SplitStyle.FoldersAlphabetic_FoldersEqual) { folder.ChildMenuCollection.Split(SplitStyle.FoldersEqual, maxElements); folder.ChildMenuCollection.Add(new NesMenuFolder() { Name = Resources.FolderNameBack, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = root }); } root.Add(folder); } } } if (originalToRoot) { if (style != SplitStyle.PagesEqual) { root.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = this }); } else { foreach (var collection in collections) { collection.Add(new NesMenuFolder() { Name = Resources.FolderNameOriginalGames, ImageId = "folder_back", Position = NesMenuFolder.Priority.Back, ChildMenuCollection = this }); } } } }
public void Split(int maxElements) { if (Count <= maxElements) { return; } var total = Count; var partsCount = (int)Math.Ceiling((float)total / (float)maxElements); var perPart = (int)Math.Ceiling((float)total / (float)partsCount); var sorted = this.OrderBy(o => o.Name); var collections = new List <NesMenuCollection>(); var collection = new NesMenuCollection(); int i = 0; foreach (var game in sorted) { collection.Add(game); i++; if (((i % perPart) == 0) || (i == sorted.Count())) { collections.Add(collection); collection = new NesMenuCollection(); } } // Method A if (collections.Count >= 12) // minimum amount of games/folders on screen without glitches { var root = this; root.Clear(); foreach (var coll in collections) { var fname = coll.Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name; var lname = coll.Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name; var folder = new NesMenuFolder(); folder.Child = coll; folder.Name = fname.Substring(0, Math.Min(Letters, fname.Length)) + (fname.Length > Letters ? "..." : "") + " - " + lname.Substring(0, Math.Min(Letters, lname.Length)) + (lname.Length > Letters ? "..." : ""); root.Add(folder); coll.Add(new NesMenuFolder() { Name = "<- Back", Image = Resources.back, Child = root }); } } else // Method B { for (i = 0; i < collections.Count; i++) { for (int j = i - 1; j >= 0; j--) { var folder = new NesMenuFolder(); var fname = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name /*.ToUpper().Replace(" ", "")*/; var lname = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name /*.ToUpper().Replace(" ", "")*/; folder.Child = collections[j]; folder.Name = fname.Substring(0, Math.Min(Letters, fname.Length)) + (fname.Length > Letters ? "..." : "") + " - " + lname.Substring(0, Math.Min(Letters, lname.Length)) + (lname.Length > Letters ? "..." : ""); folder.Initial = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Code; folder.First = true; collections[i].Insert(0, folder); } for (int j = i + 1; j < collections.Count; j++) { var folder = new NesMenuFolder(); var fname = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Name /*.ToUpper().Replace(" ", "")*/; var lname = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).Last().Name /*.ToUpper().Replace(" ", "")*/; folder.Child = collections[j]; folder.Name = fname.Substring(0, Math.Min(Letters, fname.Length)) + (fname.Length > Letters ? "..." : "") + " - " + lname.Substring(0, Math.Min(Letters, lname.Length)) + (lname.Length > Letters ? "..." : ""); folder.Initial = collections[j].Where(o => (o is NesGame) || (o is NesDefaultGame)).First().Code; folder.First = false; collections[i].Insert(collections[i].Count, folder); } } Clear(); AddRange(collections[0]); } }