CSPspEmu.Gui.Winforms.GameList.ScanPath C# (CSharp) Méthode

ScanPath() public méthode

public ScanPath ( string Folder, string CacheFolder, int MaxCount = int.MaxValue ) : void
Folder string
CacheFolder string
MaxCount int
Résultat void
        public void ScanPath(string Folder, string CacheFolder, int MaxCount = int.MaxValue)
        {
            Entries.Clear();

            try
            {
                var CheckList = new List<string>();

                foreach (var File in Directory.EnumerateFiles(Folder, "*", SearchOption.AllDirectories))
                {
                    switch (Path.GetExtension(File).ToLowerInvariant())
                    {
                        case ".iso":
                        case ".cso":
                        case ".dax":
                        case ".pbp":
                            {
                                CheckList.Add(File);
                            }
                            break;
                    }
                    if (CheckList.Count > MaxCount) break;
                }

                int Current = 0;
                int Total = CheckList.Count;

                Parallel.ForEach(CheckList, (IsoFile) =>
                {
                    try
                    {
                        //Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                        if (Progress != null) Progress(IsoFile, Current, Total);

                        //Serializer.Serialize(Console.Out, Entry);

                        var Hash = GetHash(IsoFile);
                        try { Directory.CreateDirectory(CacheFolder + "/cspspemu_iso_cache"); } catch { }
                        var CacheFile = CacheFolder + "/cspspemu_iso_cache/cspspemu_iso_cache_" + Hash + ".xml";

                        GameEntry Entry;
                        bool Cached = false;

                        if (File.Exists(CacheFile))
                        {
                            Entry = (GameEntry)Serializer.Deserialize(File.OpenRead(CacheFile));
                            Cached = true;
                        }
                        else
                        {
                            Entry = HandleIso(IsoFile);
                            if (Entry == null) return;

                            using (var CacheFileStream = File.OpenWrite(CacheFile))
                            {
                                Serializer.Serialize(CacheFileStream, Entry);
                            }
                        }

                        lock (Entries)
                        {
                            Entries.Add(Entry);

                            if (EntryAdded != null && Entry != null)
                            {
                                EntryAdded(Entry, Cached);
                            }
                        }
                    }
                    catch (Exception Exception)
                    {
                        Console.Error.WriteLine(Exception);
                    }
                    Current++;
                });
            }
            catch (Exception Exception)
            {
                Console.Error.WriteLine(Exception);
            }
            Progress("Done!", 1, 1);
        }

Usage Example

Exemple #1
0
        public void Init(string IsosPath, string CachePath)
        {
            if (IsosPath == null)
            {
                return;
            }
            var ProgressForm = new ProgressForm();
            try
            {
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    var GameList = new GameList();
                    Console.WriteLine("Reading ISOs...");
                    GameList.Progress += (Title, Current, Total) =>
                    {
                        //Console.WriteLine("Progress: {0}, {1}/{2}", Title, Current, Total);
                        ProgressForm.SetProgress(Title, Current, Total);
                    };

                    var List = new List<GameList.GameEntry>();

                    GameList.EntryAdded += (Entry, Cached) =>
                    {
                        //Console.WriteLine("aaaaaaaa");
                        List.Add(Entry);
                        if (!Cached)
                        {
                            objectListView1.AddObject(Entry);
                        }
                    };

                    GameList.ScanPath(IsosPath, CachePath);

                    this.Invoke(new Action(() =>
                    {
                        objectListView1.SetObjects(List);
                        objectListView1.Sort(TitleColumn, SortOrder.Ascending);
                    }));

                    Console.WriteLine("Done");
                    /*
                    foreach (var Entry in GameList.Entries)
                    {
                        Console.WriteLine(Entry.TITLE);
                    }
                    */

                    ProgressForm.End();
                }, null);

                this.Invoke(new Action(() =>
                {
                    ProgressForm.ShowDialog();
                }));
            }
            finally
            {
                ProgressForm.End();
            }
        }