示例#1
0
        public static NesMiniApplication FromDirectory(string path, bool ignoreEmptyConfig = false)
        {
            var files = Directory.GetFiles(path, "*.desktop", SearchOption.TopDirectoryOnly);

            if (files.Length == 0)
            {
                throw new FileNotFoundException("Invalid app folder");
            }
            var    config = File.ReadAllLines(files[0]);
            string exec   = "";

            foreach (var line in config)
            {
                if (line.StartsWith("Exec="))
                {
                    exec = line;
                    break;
                }
            }

            string command = exec.Substring(5);

            var app = AppTypeCollection.GetAppByExec(command);

            if (app != null)
            {
                var constructor = app.Class.GetConstructor(new Type[] { typeof(string), typeof(bool) });
                return((NesMiniApplication)constructor.Invoke(new object[] { path, ignoreEmptyConfig }));
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        public string GetRomFile(NesMiniApplication app)
        {
            System.Collections.Generic.List <string> exts = new System.Collections.Generic.List <string>(AppTypeCollection.GetAppByType(app.GetType()).Extensions);
            List <string> expectedFiles = new List <string>();

            expectedFiles.Add(app.Code + ".desktop");
            expectedFiles.Add(app.Code + ".png");
            expectedFiles.Add(app.Code + "_small.png");

            List <string> possibleRomFiles = new List <string>();
            List <string> zFiles           = new List <string>();


            foreach (string f in System.IO.Directory.GetFiles(app.GamePath))
            {
                string fileName = System.IO.Path.GetFileName(f);
                if (!expectedFiles.Contains(fileName))
                {
                    string ext = System.IO.Path.GetExtension(fileName);
                    if (ext == ".7z")
                    {
                        zFiles.Add(fileName);
                    }
                    else
                    {
                        if (!exts.Contains(ext))
                        {
                        }
                        else
                        {
                            possibleRomFiles.Add(fileName);
                        }
                    }
                }
            }
            string tempCommand = app.Command;

            tempCommand = tempCommand.Replace(".nes .7z", ".nes.7z");


            /*Find if of the file is linked in the commande*/
            string foundRom = "";

            foreach (string z in zFiles)
            {
                if (tempCommand.Contains(z))
                {
                    foundRom = z;
                    break;
                }
            }
            if (foundRom == "")
            {
                /*Rom was not found in 7z*/
                foreach (string z in possibleRomFiles)
                {
                    if (tempCommand.Contains(z))
                    {
                        foundRom = z;
                        break;
                    }
                }
            }
            if (foundRom == "")
            {
                //Cant find rom from command line, now analyse files
                if (zFiles.Count >= 1)
                {
                    //Most likely this one
                    foundRom = zFiles[0];
                }
                else
                {
                    if (possibleRomFiles.Count >= 1)
                    {
                        foundRom = possibleRomFiles[0];
                    }
                }
            }
            if (foundRom == "")
            {
                string test = "abc";
            }
            return(foundRom);
        }
示例#3
0
        private void CompressWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            AddLog("Start compression sequence", null);

            var games    = new List <NesMiniApplication>();
            var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games"));

            AddLog("Loading game list");
            foreach (var gameDir in gameDirs)
            {
                try
                {
                    // Removing empty directories without errors
                    try
                    {
                        var game = NesMiniApplication.FromDirectory(gameDir);
                        if ((System.IO.Directory.GetFiles(game.GamePath, "*.7z").Length > 0))
                        {
                        }
                        else
                        {
                            AddLog(game.Name + " is not compressed");
                            games.Add(game);
                        }
                    }
                    catch (FileNotFoundException ex) // Remove bad directories if any
                    {
                        Directory.Delete(gameDir, true);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
            }
            AddLog("Done loading game list", null);

            AddLog(games.Count().ToString() + " games to compress");
            foreach (NesMiniApplication nm in games)
            {
                System.Collections.Generic.List <string> ext = new System.Collections.Generic.List <string>(AppTypeCollection.GetAppByType(nm.GetType()).Extensions);
                foreach (string f in System.IO.Directory.GetFiles(nm.GamePath))
                {
                    if (ext.Contains(System.IO.Path.GetExtension(f)))
                    {
                        File.WriteAllBytes(f + ".7z", Compress(f));
                        System.IO.File.Delete(f);
                        if (nm.Command.StartsWith("/bin/clover-kachikachi"))
                        {
                            //Replace with new command
                            nm.Command = (f + ".7z").Replace(Path.Combine(runningFolder, "games"), AppTypeCollection.GetAppByType(nm.GetType()).DefaultApps[0] + " /usr/share/games/nes/kachikachi").Replace("\\", "/");
                        }
                        else
                        {
                            nm.Command = nm.Command.Replace(System.IO.Path.GetFileName(f), System.IO.Path.GetFileName(f) + ".7z");
                        }
                        nm.Save();
                    }
                }
            }
            AddLog("Done compressing");
        }