Esempio n. 1
0
        private void folderSettingEnable_Click(object sender, EventArgs e)
        {
            if (RecursiveNodeCheck(selectedFolder.node) == false)
            {
                DriveBackupData tmp = Program.driveDataList[selectedDrive];
                tmp.backupList.RemoveAll(str => str.StartsWith(BackupUtil.ConvertDrivePath(selectedFolder.FullName)));
                tmp.backupList.Add(BackupUtil.ConvertDrivePath(selectedFolder.FullName));
                Program.driveDataList[selectedDrive] = tmp;
                Program.SaveDriveData(tmp);

                /*selectedFolder.ImageIndex(1);
                *
                *  bool isExpanded = selectedFolder.node.IsExpanded;
                *  selectedFolder.node.Collapse();
                *  selectedFolder.node.Nodes.Clear();
                *  selectedFolder.node.Nodes.Add(new TreeNode("**Temp", 0, 0));
                *  if(isExpanded)
                *   selectedFolder.node.Expand();*/

                selectedFolder = null;
                LoadDriveList();
                PopulateBackupDriveTree();
                UpdateUIData();
            }
        }
Esempio n. 2
0
        private void LoadDriveList()
        {
            driveListView.Nodes.Clear();
            Dictionary <string, TreeNode> nodes = new Dictionary <string, TreeNode>();

            foreach (KeyValuePair <DriveInfo, DriveBackupData> dat in Program.driveDataList)
            {
                DriveBackupData driveDat = dat.Value;
                DriveInfo       drive    = driveDat.drive;
                TreeNode        tmp      = new TreeNode();
                tmp.Text = "(" + drive.Name + ") " + drive.VolumeLabel;
                tmp.Tag  = driveDat;

                if (driveDat.backupList != null && driveDat.backupList.Count > 0)
                {
                    foreach (var v in driveDat.backupList)
                    {
                        TreeNode tmp2 = new TreeNode();
                        tmp2.Text = BackupUtil.ConvertRealPath(v, drive);
                        tmp.Nodes.Add(tmp2);
                    }
                }
                else
                {
                    TreeNode tmp2 = new TreeNode();
                    tmp2.Text = "No synced folders found";
                    tmp.Nodes.Add(tmp2);
                }

                if (!nodes.ContainsKey(Program.VALID_DRIVE_TYPES[drive.DriveType]))
                {
                    TreeNode driveType = new TreeNode(Program.VALID_DRIVE_TYPES[drive.DriveType]);
                    nodes.Add(Program.VALID_DRIVE_TYPES[drive.DriveType], driveType);
                }

                TreeNode typeNode = nodes[Program.VALID_DRIVE_TYPES[drive.DriveType]];
                typeNode.Nodes.Add(tmp);
            }

            foreach (TreeNode node in nodes.Values)
            {
                driveListView.Nodes.Add(node);
            }
            driveListView.ExpandAll();
            UpdateUIData();
        }
Esempio n. 3
0
        private void PopulateBackupDriveTree()
        {
            backupTreeView.Nodes.Clear();
            if (!(selectedDrive == null || !selectedDrive.IsReady))
            {
                TreeNode root = new TreeNode();
                root.Text = selectedDrive.Name;

                DirectoryInfo directories = selectedDrive.RootDirectory;
                int           imageIndex  = 0;
                foreach (string inf in Program.driveDataList[selectedDrive].backupList)
                {
                    if (BackupUtil.ConvertDrivePath(directories.FullName) == inf)
                    {
                        imageIndex = 1;
                        break;
                    }

                    if (inf.Contains(BackupUtil.ConvertDrivePath(directories.FullName)))
                    {
                        imageIndex = 2;
                    }
                }

                root.ImageIndex         = imageIndex;
                root.SelectedImageIndex = imageIndex;

                root.Tag = directories;

                if (CountSubDirectories(directories) != 0)
                {
                    TreeNode node = new TreeNode();
                    node.Text = "**Temp";
                    node.Tag  = null;

                    root.Nodes.Add(node);
                }

                backupTreeView.Nodes.Add(root);

                root.Expand();
            }

            UpdateUIData();
        }
        public async Task Start(MethodInvoker method)
        {
            Debug.WriteLine("Start");
            await Task.Run(() => {
                try
                {
                    int c = 0;
                    foreach (string path in driveData.backupList)
                    {
                        if (Program.TERMINATE_BACKUP)
                        {
                            Program.BACKUP_STATE = "Terminated";
                            return;
                        }
                        c++;
                        DirectoryInfo inf = new DirectoryInfo(BackupUtil.ConvertRealPath(path, driveData.drive));
                        if (!inf.Exists)
                        {
                            continue;
                        }

                        List <BackupData> dat = GetBackupData(inf, null);
                        data     = data.Concat(dat).ToList();
                        progress = ((c * 100) / driveData.backupList.Count);
                        Program.BACKUP_PROGRESS = progress;
                    }
                    Debug.WriteLine("Complete" + data.Count);
                    method();
                    isComplete = true;
                } catch (FileNotFoundException e)
                {
                    Program.ThrowErrorMessage(e);
                    return;
                } catch (IOException e)
                {
                    Program.ThrowErrorMessage(e);
                    return;
                }
            });
        }
Esempio n. 5
0
        public static async Task <bool> StartBackup(DriveBackupData drive)
        {
            TERMINATE_BACKUP = false;
            try
            {
                ShowNotification("Backup Started", "A backup has started for " + drive.drive.Name + "...");
                if (Properties.Settings.Default.ShowProgress)
                {
                    new MethodInvoker(delegate { OpenProgressWindow(); }).Invoke();
                }
                BACKUP_DRIVE    = drive.drive.Name;
                BACKUP_PROGRESS = 0;
                BACKUP_STATE    = "Collecting File Data...";
                BackupListBuilder build = new BackupListBuilder(drive);
                await build.Start(delegate
                {
                    BACKUP_STATE = "Starting Backup...";
                    List <BackupData> backupList = build.data;
                    int fileCount  = 0;
                    int totalCount = 0;

                    long bytesWritten = 0;
                    foreach (BackupData dat in backupList)
                    {
                        if (TERMINATE_BACKUP)
                        {
                            BACKUP_STATE = "Terminated";
                            return;
                        }
                        BACKUP_STATE = "Syncing (" + totalCount + "/" + backupList.Count + ")...";
                        Debug.WriteLine(dat.fileHash);
                        Debug.WriteLine(dat.backupHash);
                        if (!(dat.fileHash == dat.backupHash))
                        {
                            BACKUP_FILE = "Syncing " + dat.filename;
                            bool ret    = BackupUtil.BackupFile(dat, drive);
                            if (ret == false)
                            {
                                BACKUP_STATE = "FAILED";
                                return;
                            }
                            Debug.WriteLine("Synced " + dat.filename);
                            //BACKUP_FILE = "Syncing " + dat.filename;
                            fileCount++;
                        }
                        else
                        {
                            Debug.WriteLine("Skipped " + dat.filename);
                            BACKUP_FILE = "Skipping " + dat.filename;
                        }
                        totalCount++;
                        bytesWritten   += dat.length;
                        BACKUP_PROGRESS = (int)((bytesWritten * 100) / build.totalCopySize);
                    }
                    BACKUP_PROGRESS = 100;
                    BACKUP_FILE     = "Complete";
                    BACKUP_STATE    = "Complete";
                    if (Properties.Settings.Default.AutoCloseProgress)
                    {
                        if (progressWindow != null && !progressWindow.IsDisposed)
                        {
                            progressWindow.Invoke((EventHandler) delegate
                            {
                                progressWindow.Close();
                            });
                        }
                    }
                    ShowNotification("Backup Finished", "The backup for " + drive.drive.Name + " has finished, " + fileCount + " files were synced.");
                });

                return(true);
            }
            catch (FileNotFoundException e)
            {
                ThrowErrorMessage(e);
                return(false);
            }
            catch (DirectoryNotFoundException e)
            {
                ThrowErrorMessage(e);
                return(false);
            }
            catch (IOException e)
            {
                ThrowErrorMessage(e);
                return(false);
            }
        }
Esempio n. 6
0
        private void backupTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            TreeNodeCollection nodes = e.Node.Nodes;
            bool alreadyLoaded       = true;

            foreach (TreeNode node in nodes)
            {
                if (node.Text == "**Temp" || node.Tag == null)
                {
                    node.Remove();
                    alreadyLoaded = false;
                    break;
                }
            }

            if (alreadyLoaded)
            {
                return;
            }

            foreach (DirectoryInfo dir in GetSubDirectories((DirectoryInfo)e.Node.Tag))
            {
                if (dir.Name == "__filesync")
                {
                    continue;
                }

                TreeNode tmp = new TreeNode(dir.Name, 0, 0);
                tmp.Tag = dir;

                if (CountSubDirectories(dir) != 0)
                {
                    TreeNode ph = new TreeNode();
                    ph.Text = "**Temp";
                    ph.Tag  = null;

                    tmp.Nodes.Add(ph);
                }

                e.Node.Nodes.Add(tmp);

                //Recursively check (Needs to be after added to list)
                int imageIndex = 0;
                foreach (string inf in Program.driveDataList[selectedDrive].backupList)
                {
                    if (BackupUtil.ConvertDrivePath(dir.FullName) == inf || RecursiveNodeCheck(tmp))
                    {
                        imageIndex = 1;
                        break;
                    }

                    if (inf.Contains(BackupUtil.ConvertDrivePath(dir.FullName)))
                    {
                        imageIndex = 2;
                    }
                }

                tmp.ImageIndex         = imageIndex;
                tmp.SelectedImageIndex = imageIndex;
            }
        }
Esempio n. 7
0
        private void UpdateUIData()
        {
            if (selectedDrive != null)
            {
                driveEditorGroup.Enabled = true;
            }
            else
            {
                driveEditorGroup.Enabled = false;
                return;
            }

            try
            {
                //DriveSettings Group
                driveSettingSetup.Enabled         = !Program.driveDataList[selectedDrive].backupDataExists;
                driveSettingForceBackup.Visible   = Program.driveDataList[selectedDrive].backupDataExists;
                driveSettingDelete.Visible        = Program.driveDataList[selectedDrive].backupDataExists;
                driveSettingBackupPath.Visible    = Program.driveDataList[selectedDrive].backupDataExists;
                driveSettingEnableBackup.Visible  = Program.driveDataList[selectedDrive].backupDataExists;
                driveSettingDisableBackup.Visible = Program.driveDataList[selectedDrive].backupDataExists;

                driveSettingEnableBackup.Enabled  = !Program.driveDataList[selectedDrive].backupEnabled;
                driveSettingDisableBackup.Enabled = Program.driveDataList[selectedDrive].backupEnabled;

                //BackupDetails Group
                backupDetailsGroup.Visible = Program.driveDataList[selectedDrive].backupDataExists;
                if (Program.driveDataList[selectedDrive].backupDataExists)
                {
                    backupPath.Text            = Program.driveDataList[selectedDrive].defaultBackupLocation + (selectedFolder != null && selectedFolder.FullName != null ? selectedFolder.FullName.Substring(2) : "");
                    backupEnabledCheck.Checked = Program.driveDataList[selectedDrive].backupEnabled;
                }

                //Folder Settings Group
                if (selectedFolder != null)
                {
                    folderSettingsGroup.Visible = Program.driveDataList[selectedDrive].backupDataExists;
                    if (RecursiveNodeCheck(selectedFolder.node) == false)
                    {
                        folderSettingDisable.Enabled = Program.driveDataList[selectedDrive].backupList.Contains(BackupUtil.ConvertDrivePath(selectedFolder.FullName));
                        folderSettingEnable.Enabled  = !Program.driveDataList[selectedDrive].backupList.Contains(BackupUtil.ConvertDrivePath(selectedFolder.FullName));
                    }
                    else
                    {
                        folderSettingEnable.Enabled  = false;
                        folderSettingDisable.Enabled = false;
                    }
                    selectedFolderPath.Text = selectedFolder.FullName;
                }
                else
                {
                    selectedFolderPath.Text     = "";
                    folderSettingsGroup.Visible = false;
                }

                //Selected Folder
                selectedFolderLabel.Visible = Program.driveDataList[selectedDrive].backupDataExists;
                selectedFolderPath.Visible  = Program.driveDataList[selectedDrive].backupDataExists;
            } catch (System.Collections.Generic.KeyNotFoundException)
            {
                driveEditorGroup.Enabled = false;
            }
        }
        private List <BackupData> GetBackupData(DirectoryInfo dir, List <BackupData> dat)
        {
            if (dat == null)
            {
                dat = new List <BackupData>();
            }

            if (Program.TERMINATE_BACKUP)
            {
                Program.BACKUP_STATE = "Terminated";
                return(new List <BackupData>());
            }

            try
            {
                FileInfo[] files = dir.GetFiles();
                totalItems += files.Length;
                foreach (FileInfo file in files)
                {
                    Program.BACKUP_FILE = file.FullName;
                    if (Program.TERMINATE_BACKUP)
                    {
                        Program.BACKUP_STATE = "Terminated";
                        return(new List <BackupData>());
                    }
                    BackupData backup   = new BackupData();
                    bool       sizeDiff = false;
                    totalCopySize  += file.Length;
                    backup.filename = file.Name;
                    backup.path     = file.DirectoryName;
                    backup.length   = file.Length;
                    FileInfo corr = BackupUtil.FindCorrespondingFile(backup, driveData);
                    backup.fileHash = BackupUtil.ComputeHash(file);
                    if (!sizeDiff && corr != null && corr.Exists)
                    {
                        backup.backupHash = BackupUtil.FindUncompressedHash(corr);
                    }
                    scannedItems++;
                    Program.BACKUP_PROGRESS = (scannedItems * 100) / totalItems;
                    dat.Add(backup);
                    Program.BACKUP_STATE = "Collecting file data... (" + dat.Count + ")";
                }
            } catch (System.UnauthorizedAccessException)
            {
            }

            try
            {
                DirectoryInfo[] dirs = dir.GetDirectories();
                totalItems += dirs.Length;
                foreach (DirectoryInfo val in dirs)
                {
                    if (Program.TERMINATE_BACKUP)
                    {
                        Program.BACKUP_STATE = "Terminated";
                        return(new List <BackupData>());
                    }

                    if (val.Name == "__filesync")
                    {
                        continue;
                    }

                    scannedItems++;
                    Program.BACKUP_PROGRESS = (scannedItems * 100) / totalItems;
                    dat = GetBackupData(val, dat);
                }
            } catch (System.UnauthorizedAccessException)
            {
            }


            return(dat);
        }