コード例 #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (!UpdateSettings())
            {
                return;
            }
            var scanLog = new Log("scan");

            if (DM.Config.PathToScan.Count < 1)
            {
                scanLog.Warn("No directory to scan.");
                return;
            }

            var w = Reactor.Run(
                DM.Config.PathToScan,
                dirs => {
                scanLog.Info("Scan started!");

                //Search for new movies
                foreach (String path in dirs.SelectMany(Scanner.GetFiles))
                {
                    if (DM.Instance.HasFile(path))
                    {
                        continue;
                    }
                    scanLog.Info(path);

                    try
                    {
                        var m = Scanner.FetchMovie(path);
                        if (m == null)
                        {
                            scanLog.Info(">> ignored");
                            DM.AddSkipped(path);
                            continue;
                        }
                        scanLog.Info(">> found: " + m.Title + " " + m.Year);
                        DM.AddMovie(m);

                        Dispatcher.BeginInvoke(DispatcherPriority.Send, new DispatcherOperationCallback(delegate
                        {
                            UpdateTitle();
                            return(null);
                        }), null);
                    }
                    catch (Exception ex)
                    {
                        if (ex is Scanner.NoMatchFoundException)
                        {
                            DM.AddUnmatched(path);
                            scanLog.Warn(">> no match found");
                            continue;
                        }

                        scanLog.Error(ex.Message);
                    }
                }

                //Dlete missing movies
                int cmpt = 0;
                foreach (var path in DM.Instance.GetAllFiles().Where(p => !File.Exists(p)))
                {
                    DM.RemoveFile(path);
                    cmpt++;
                }
                scanLog.Info(cmpt + " missing files deleted");

                return("");
            },
                null, null, (s, ex) => scanLog.Info("Scan finished"));
        }