Esempio n. 1
0
        private void Distinguish_DoWork(object sender, DoWorkEventArgs e)
        {
            var games = new List <NesMiniApplication>();
            Dictionary <string, List <NesMiniApplication> > sortedGames = new Dictionary <string, 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 (!sortedGames.ContainsKey(game.Name + " | " + game.GoogleSuffix))
                        {
                            sortedGames.Add(game.Name + " | " + game.GoogleSuffix, new List <NesMiniApplication>());
                        }
                        sortedGames[game.Name + " | " + game.GoogleSuffix].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);
            foreach (string gameName in sortedGames.Keys)
            {
                if (sortedGames[gameName].Count() > 1)
                {
                    AddLog(gameName + " have " + sortedGames[gameName].Count());
                    string simmilar = findSimilar(sortedGames[gameName]);
                    if (simmilar != "")
                    {
                        foreach (NesMiniApplication app in sortedGames[gameName])
                        {
                            string f          = app.Command.Substring(app.Command.LastIndexOf("/") + 1);
                            string difference = f.Replace(simmilar, "");
                            if (difference.Contains("."))
                            {
                                difference = difference.Substring(0, difference.IndexOf("."));
                            }
                            AddLog("Renaming " + app.Name + " to " + app.Name + " - " + difference);
                            app.Name = app.Name + " - " + difference;
                            app.Save();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void LoadLibrary()
        {
            LoadingLibrary = true;
            if (GamesRemoved != null)
            {
                if (gameLibrary.Count() > 0)
                {
                    GamesRemoved(gameLibrary);
                }
            }

            gameLibrary.Clear();
            //  ReloadDefault();
            string[] selectedGames = ConfigIni.SelectedGames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (!System.IO.Directory.Exists(NesMiniApplication.GamesDirectory))
            {
                Directory.CreateDirectory(NesMiniApplication.GamesDirectory);
            }
            var gameDirs = Directory.GetDirectories(NesMiniApplication.GamesDirectory);
            List <NesMiniApplication> toAdd = new List <NesMiniApplication>();

            foreach (var gameDir in gameDirs)
            {
                try
                {
                    // Removing empty directories without errors
                    try
                    {
                        var game = NesMiniApplication.FromDirectory(gameDir);
                        if (game.GetType() == typeof(NesMiniApplication))
                        {
                            Console.Write("");
                        }
                        game.Selected = selectedGames.Contains(game.Code);
                        toAdd.Add(game);
                    }
                    catch (FileNotFoundException ex) // Remove bad directories if any
                    {
                        Debug.WriteLine(ex.Message + ex.StackTrace);
                        Directory.Delete(gameDir, true);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    MessageBox.Show(ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
            }
            if (toAdd.Count() > 0)
            {
                AddGames(toAdd);
            }
            LoadingLibrary = false;
            Manager.EventBus.getInstance().SizeRecalculationRequest();
        }
Esempio n. 3
0
        public void RefreshHakchiInfo()
        {
            hakchiGames.Clear();
            var gameDirs          = Directory.GetDirectories(Path.Combine(runningFolder, "games"));
            int nbGames           = 0;
            int nbCompressedGames = 0;
            int invalidGames      = 0;

            foreach (var gameDir in gameDirs)
            {
                try
                {
                    nbGames++;
                    // Removing empty directories without errors
                    try
                    {
                        var game = NesMiniApplication.FromDirectory(gameDir);
                        if ((System.IO.Directory.GetFiles(game.GamePath, "*.7z").Length > 0))
                        {
                            nbCompressedGames++;
                        }
                        else
                        {
                            AddLog(game.Name + " is not compressed");
                        }
                        hakchiGames.Add(game);
                    }
                    catch (FileNotFoundException ex) // Remove bad directories if any
                    {
                        invalidGames++;
                        // Directory.Delete(gameDir, true);
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            nudNbGames.Value         = nbGames;
            nudCompressedGames.Value = nbCompressedGames;
            nudInvalidGames.Value    = invalidGames;
        }
Esempio n. 4
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");
        }
Esempio n. 5
0
        private void Cleanup_DoWork(object sender, DoWorkEventArgs e)
        {
            var games = new List <NesMiniApplication>();


            var gameDirs = Directory.GetDirectories(Path.Combine(runningFolder, "games"));

            AddLog("Cleanup");
            foreach (var gameDir in gameDirs)
            {
                try
                {
                    // Removing empty directories without errors
                    try
                    {
                        var    game   = NesMiniApplication.FromDirectory(gameDir);
                        string ogName = game.Name;
                        bool   dirty  = false;
                        if (game.Name.Trim() != game.Name)
                        {
                            game.Name = game.Name.Trim();
                            dirty     = true;
                        }
                        if (game.Name.EndsWith("-"))
                        {
                            game.Name = game.Name.Substring(0, game.Name.Length - 1);

                            dirty = true;
                        }
                        if (game.Name.Contains("_"))
                        {
                            dirty     = true;
                            game.Name = game.Name.Replace("_", " ");
                        }
                        while (game.Name.Contains("  "))
                        {
                            dirty     = true;
                            game.Name = game.Name.Replace("  ", " ");
                        }
                        if (game.Name.Trim() != game.Name)
                        {
                            game.Name = game.Name.Trim();
                            dirty     = true;
                        }

                        if (dirty)
                        {
                            AddLog("Renamed " + ogName + " to " + game.Name);
                            game.Save();
                        }
                    }
                    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);
        }