Exemple #1
0
        static List <Title> openSDCard(string pathSd)
        {
            Process.log?.WriteLine("\nOpen SD Card");

            List <FsTitle> fsTitles = Process.processSd(pathSd);

            List <Title> titles = new List <Title>();

            if (fsTitles != null)
            {
                foreach (var fsTitle in fsTitles)
                {
                    Title title = Process.processTitle(fsTitle);
                    if (title != null)
                    {
                        titles.Add(title);
                    }
                }

                Process.log?.WriteLine("\n{0} titles processed", titles.Count);
            }
            else
            {
                string error = "SD card \"Contents\" directory could not be found";
                Process.log?.WriteLine(error);

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.Error.WriteLine(error);
                Console.ResetColor();
            }

            return(titles);
        }
Exemple #2
0
        private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            titles.Clear();
            Process.latestVersions.Clear();

            if (e.Argument is ValueTuple <Worker, string[]> argumentFile)
            {
                if (argumentFile.Item1 == Worker.File && argumentFile.Item2 is string[] files)
                {
                    List <string> filenames = files.ToList();
                    filenames.Sort();

                    Process.log?.WriteLine("{0} files selected", filenames.Count);

                    worker.ReportProgress(-1, String.Format("Opening {0} files", filenames.Count));

                    int count = filenames.Count, index = 0;

                    foreach (var filename in filenames)
                    {
                        if (worker.CancellationPending)
                        {
                            break;
                        }

                        worker.ReportProgress(100 * index++ / count, filename);

                        Title title = Process.processFile(filename);
                        if (title != null)
                        {
                            titles.Add(title);
                        }
                    }

                    if (!worker.CancellationPending)
                    {
                        worker.ReportProgress(100, "");
                    }

                    Process.log?.WriteLine("\n{0} titles processed", titles.Count);
                }
            }
            else if (e.Argument is ValueTuple <Worker, string> argumentPath)
            {
                if (argumentPath.Item1 == Worker.Directory && argumentPath.Item2 is string path)
                {
                    List <string> filenames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)
                                              .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro") ||
                                                     (Common.Settings.Default.NszExtension && (filename.ToLower().EndsWith(".xcz") || filename.ToLower().EndsWith(".nsz")))).ToList();
                    filenames.Sort();

                    Process.log?.WriteLine("{0} files selected", filenames.Count);

                    worker.ReportProgress(-1, String.Format("Opening {0} files from directory {1}", filenames.Count, path));

                    int count = filenames.Count, index = 0;

                    foreach (var filename in filenames)
                    {
                        if (worker.CancellationPending)
                        {
                            break;
                        }

                        worker.ReportProgress(100 * index++ / count, filename);

                        Title title = Process.processFile(filename);
                        if (title != null)
                        {
                            titles.Add(title);
                        }
                    }

                    if (!worker.CancellationPending)
                    {
                        worker.ReportProgress(100, "");
                    }

                    Process.log?.WriteLine("\n{0} titles processed", titles.Count);
                }
                else if (argumentPath.Item1 == Worker.SDCard && argumentPath.Item2 is string pathSd)
                {
                    List <FsTitle> fsTitles = Process.processSd(pathSd);

                    if (fsTitles != null)
                    {
                        int count = fsTitles.Count, index = 0;

                        foreach (var fsTitle in fsTitles)
                        {
                            if (worker.CancellationPending)
                            {
                                break;
                            }

                            worker.ReportProgress(100 * index++ / count, fsTitle.MainNca?.Filename);

                            Title title = Process.processTitle(fsTitle);
                            if (title != null)
                            {
                                titles.Add(title);
                            }
                        }

                        if (!worker.CancellationPending)
                        {
                            worker.ReportProgress(100, "");
                        }

                        Process.log?.WriteLine("\n{0} titles processed", titles.Count);
                    }
                    else
                    {
                        worker.ReportProgress(0, "");

                        string error = "SD card \"Contents\" directory could not be found";
                        Process.log?.WriteLine(error);

                        e.Result = error;
                        return;
                    }
                }
            }

            e.Result = titles;
        }
Exemple #3
0
        void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            titles.Clear();

            if (e.Argument is List <string> filenames)
            {
                int count = filenames.Count, index = 0;

                foreach (var filename in filenames)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }

                    worker.ReportProgress(100 * index++ / count, filename);

                    Title title = Process.processFile(filename);
                    if (title != null)
                    {
                        titles.Add(title);
                    }
                }

                if (!worker.CancellationPending)
                {
                    worker.ReportProgress(100, "");
                }

                Process.log?.WriteLine("\n{0} titles processed", titles.Count);
            }
            else if (e.Argument is string path)
            {
                List <FsTitle> fsTitles = Process.processSd(path);

                if (fsTitles != null)
                {
                    int count = fsTitles.Count, index = 0;

                    foreach (var fsTitle in fsTitles)
                    {
                        if (worker.CancellationPending)
                        {
                            break;
                        }

                        worker.ReportProgress(100 * index++ / count, fsTitle.MainNca?.Filename);

                        Title title = Process.processTitle(fsTitle);
                        if (title != null)
                        {
                            titles.Add(title);
                        }
                    }

                    if (!worker.CancellationPending)
                    {
                        worker.ReportProgress(100, "");
                    }

                    Process.log?.WriteLine("\n{0} titles processed", titles.Count);
                }
                else
                {
                    string error = "SD card \"Contents\" directory could not be found";
                    Process.log?.WriteLine(error);

                    e.Result = error;
                    return;
                }
            }

            e.Result = titles;
        }