Example #1
0
        static void HandleDeviceArrived(string driveLetter)
        {
            MultiProgress progress = new MultiProgress(new IProgress[] {});

            List <IUsbDriveInfo> foundDrives = GetFoundDrives();
            var drive = foundDrives.FirstOrDefault(d => d.RootDirectory.ToString() == driveLetter);

            if (drive == null || !drive.IsReady)
            {
                return;
            }
            try
            {
                if (!IsAKnownBackupDrive(drive))
                {
                    if (DialogResult.Yes == new NewDrivePopup().ShowDialog())
                    {
                        Directory.CreateDirectory(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString()));
                    }
                }
                //based on that popup, it might now pass this test:
                if (IsAKnownBackupDrive(drive))
                {
                    LaunchBackup(progress, GetFileLogProgress(progress), drive);
                }
            }
            catch (Exception error)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem(error, "Sorry, something went wrong.");
            }
        }
Example #2
0
        public BackupControl(string destinationDeviceRoot, long availableFreeSpaceInKilobytes, long totalSpaceOfDeviceInKilobytes, MultiProgress progress)
        {
            Progress = progress;
            //Font = SystemFonts.MessageBoxFont;
            _destinationDeviceRoot         = destinationDeviceRoot;
            _availableFreeSpaceInKilobytes = availableFreeSpaceInKilobytes;
            _totalSpaceOfDeviceInKilobytes = totalSpaceOfDeviceInKilobytes;
            InitializeComponent();
            SetWindowText();
            listView1.Visible       = false;
            backupNowButton.Visible = false;

            string destinationFolderPath = GetDestinationFolderPath(destinationDeviceRoot);

            if (!Directory.Exists(destinationFolderPath))
            {
                Directory.CreateDirectory(destinationFolderPath);
            }

            ReadInGroups(destinationFolderPath);

            DoPreview = false;
            AutoStart = true;

            syncProgressBar.Style = ProgressBarStyle.Marquee;             //until we have an estimate

            _driveDetector = new DriveDetector();

            //TODO: use this instead of polling in the main program
            //driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);

            //TODO: see if DeviceRemoved could be used instaead of DeviceSomethingHappened
            //driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
            _driveDetector.DeviceSomethingHappened += new DriveDetectorEventHandler(OnDriveSomething);
            //driveDetector.QueryRemove += new DriveDetectorEventHandler(OnQueryRemove);


            _synchronizer = new Synchronizer(destinationFolderPath, _groups, availableFreeSpaceInKilobytes, Progress);
            _synchronizer.GroupProgress += new Action(OnSynchronizer_GroupProgress);

            _mediaStatusIndicator.DriveLabel = destinationDeviceRoot;

            _mediaStatusIndicator.ExistingFillPercentage = 100 - (int)(100.0 * availableFreeSpaceInKilobytes / totalSpaceOfDeviceInKilobytes);

            //until we know how much we're going to fill up
            _mediaStatusIndicator.PendingFillPercentage = _mediaStatusIndicator.UnknownFillPercentage;
            _mediaStatusIndicator.DeviceSizeInKiloBytes = totalSpaceOfDeviceInKilobytes;

            closeButton.Visible  = false;
            cancelButton.Visible = true;
            _status.Text         = "";
            listView1.Visible    = true;
            Cursor = Cursors.WaitCursor;

            _preparationWorker         = new BackgroundWorker();
            _preparationWorker.DoWork += OnPreparationWorker_DoWork;
            _preparationWorker.WorkerSupportsCancellation = true;
            _preparationWorker.RunWorkerCompleted        += OnPreparationCompleted;
        }
Example #3
0
 public MainWindow(BackupControl backupControl, MultiProgress progress)
 {
     //Font = SystemFonts.MessageBoxFont;
     InitializeComponent();
     SetWindowText();
     backupControl.Dock      = DockStyle.Fill;
     backupControl.CloseNow += () => Close();
     _backupPage.Controls.Add(backupControl);
     progress.Add(_logBox);
 }
Example #4
0
        private static void OnStartViaMenu(object sender, EventArgs e)
        {
            var drives = UsbDriveInfo.GetDrives();

            if (drives.Count == 0)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem("No USB drives found");
                return;
            }
            var progress = new MultiProgress(new IProgress[] {});

            LaunchBackup(progress, GetFileLogProgress(progress), drives[0]);
            return;
        }
Example #5
0
        private static FileLogProgress GetFileLogProgress(MultiProgress progress)
        {
            FileLogProgress fileLogProgress = null;

            try
            {
                var path = Path.Combine(Path.GetTempPath(), "myWorkSafeLog.txt");
                fileLogProgress = new FileLogProgress(path);
                progress.Add(fileLogProgress);
            }
            catch (Exception)
            {
                //don't want to not backup if something goes wrong creating the log
            }
            return(fileLogProgress);
        }
Example #6
0
        private static void DoTestRun()
        {
            MultiProgress progress = new MultiProgress(new IProgress[] { });
            var           destinationDeviceRoot = @"c:\dev\temp\SafetyStick";

//			if (Directory.Exists(path))
//				Directory.Delete(path, true);

            //		var info = new DriveInfo(Path.GetPathRoot(destinationPath));

            var totalSpaceInKilobytes = 900 * 1024;            // (int)(100.0 * info.AvailableFreeSpace / info.TotalSize);
            var freeSpaceInKilobytes  = 800 * 1024;
            var backupControl         = new BackupControl(destinationDeviceRoot, freeSpaceInKilobytes, totalSpaceInKilobytes, progress);

            backupControl.DoPreview = false;
            backupControl.AutoStart = true;

            new MainWindow(backupControl, progress).ShowDialog();
        }
Example #7
0
        static void HandleDeviceArrived(string driveLetter)
        {
            MultiProgress       progress    = new MultiProgress(new IProgress[] {});
            List <UsbDriveInfo> foundDrives = GetFoundDrives();
            var drive = foundDrives.FirstOrDefault(d => d.RootDirectory.ToString() == driveLetter);

            if (drive == null || !drive.IsReady)
            {
                return;
            }
            try
            {
                if (!IsAKnownBackupDrive(drive))
                {
                    if (DialogResult.Yes == new NewDrivePopup().ShowDialog())
                    {
                        Directory.CreateDirectory(BackupControl.GetDestinationFolderPath(drive.RootDirectory.ToString()));
                    }
                }
                //based on that popup, it might now pass this test:
                if (IsAKnownBackupDrive(drive))
                {
                    long   totalSpaceInKilobytes = (long)(drive.TotalSize / 1024);
                    long   freeSpaceInKilobytes  = (long)(drive.AvailableFreeSpace / 1024);
                    string destinationDeviceRoot = drive.RootDirectory.ToString();
                    var    backupControl         = new BackupControl(destinationDeviceRoot, freeSpaceInKilobytes, totalSpaceInKilobytes, progress);
                    using (var form = new MainWindow(backupControl, progress))
                    {
                        form.ShowDialog();
                    }
                }
            }
            catch (Exception error)
            {
                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Sorry, something went wrong.");
            }
        }