コード例 #1
0
ファイル: NesMiniApplication.cs プロジェクト: ethan3874/SNES
        public static NesMiniApplication Import(string fileName, string sourceFile = null, byte[] rawRomData = null)
        {
            var extension = Path.GetExtension(fileName).ToLower();

            if (extension == ".desktop")
            {
                return(ImportApp(fileName));
            }
            if (rawRomData == null)
            {
                rawRomData = File.ReadAllBytes(fileName);
            }
            List <Manager.EmulatorManager.Emulator> availableEmus = Manager.EmulatorManager.getInstance().ListByFileType(System.IO.Path.GetFileName(fileName));

            Manager.EmulatorManager.Emulator toUse = null;
            if (availableEmus.Count > 0)
            {
                toUse = availableEmus[0];
                NesMiniApplication app = (NesMiniApplication)UnknowSystem.Import(fileName, sourceFile, rawRomData, toUse.Prefix[0], toUse.Executable, Manager.BitmapManager.getInstance().GetBitmap(".\\images\\" + toUse.DefaultImage), toUse.SupportZip);
                // app.theRom = Manager.RomManager.getInstance().AddRom(fileName);
                return(app);
            }
            else
            {
                return(null);
            }



            //string application = extension.Length > 2 ? ("/bin/" + extension.Substring(1)) : DefaultApp;
            //return Import(fileName, sourceFile, rawRomData, DefaultPrefix, application, DefaultCover);
        }
コード例 #2
0
        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.BySystem)
            {
                var Systems = new Dictionary <string, NesMenuCollection>();
                foreach (var game in root)
                {
                    Manager.EmulatorManager.Emulator emu = ((NesMiniApplication)game).GetEmulator();
                    if (!Systems.ContainsKey(emu.SystemName))
                    {
                        Systems[emu.SystemName] = new NesMenuCollection();
                    }
                    Systems[emu.SystemName].Add(game);
                }
                root.Clear();
                foreach (string system in Systems.Keys)
                {
                    var folder = new NesMenuFolder()
                    {
                        ChildMenuCollection = Systems[system], Name = system, Position = NesMenuFolder.Priority.Left, ImageId = "folder"
                    };
                    root.Add(folder);
                }
            }
            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
                        });
                    }
                }
            }
        }