Exemplo n.º 1
0
 public static Task Scan(string src, string dest, Action <FixAction> recv, Action <double> progress = null)
 {
     return(Task.Run(() => {
         try {
             var scanner = new ShortcutScanner();
             scanner.progressReporter = progress;
             scanner.ops = recv;
             scanner.src = src;
             scanner.dest = dest;
             scanner.ScanSync();
         }catch (Exception e) {
             MessageBox.Show(e.ToString());
         }
     }));
 }
Exemplo n.º 2
0
        private void Preview_Click(object sender, RoutedEventArgs ev)
        {
            var srcAddr  = Src.Text;
            var destAddr = Dest.Text;

            action.Clear();
            List.ItemsSource = action;

            if (!Directory.Exists(srcAddr))
            {
                System.Windows.MessageBox.Show("Source address does not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!System.IO.Path.IsPathRooted(destAddr))
            {
                System.Windows.MessageBox.Show("Destination address is not valid", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (destAddr.Contains(srcAddr, StringComparison.OrdinalIgnoreCase))
            {
                System.Windows.MessageBox.Show("Destination address cannot contain source address", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Src.IsEnabled      = false;
            Dest.IsEnabled     = false;
            Preview.IsEnabled  = false;
            SrcPick.IsEnabled  = false;
            DestPick.IsEnabled = false;

            // Be a little conservative. If we move across volume then we keep the backup
            if (Path.GetPathRoot(srcAddr) == Path.GetPathRoot(destAddr))
            {
                action.Add(new ActionModel(new MoveAction(srcAddr, destAddr)));
            }
            else
            {
                action.Add(new ActionModel(new CopyAction(srcAddr, destAddr)));
            }

            var recv = new Action <FixAction>((a) => {
                Dispatch(() => {
                    action.Add(new ActionModel(a));
                });
            });
            var t = new Thread(() => {
                try {
                    var prevV = 0d;
                    var task  = ShortcutScanner.Scan(srcAddr, destAddr, recv, (v) => {
                        if (v > prevV + 0.01)
                        {
                            prevV = v;
                            Dispatch(() => {
                                Progress.Value = v * 0.2;
                            });
                        }
                    });

                    task.Wait();

                    prevV = 0d;
                    task  = RegistryScanner.Scan(srcAddr, destAddr, recv, (v) => {
                        if (v > prevV + 0.01)
                        {
                            prevV = v;
                            Dispatch(() => {
                                Progress.Value = v * 0.8 + 0.2;
                            });
                        }
                    });
                    task.Wait();

                    Dispatch(() => {
                        Apply.IsEnabled  = true;
                        Cancel.IsEnabled = true;
                    });
                } catch (Exception e) {
                    MessageBox.Show(e.ToString());
                }
            });

            t.IsBackground = true;
            t.Start();
        }