Exemple #1
0
 private void readyToStartBackup(object sender, EventArgs e)
 {
     if (sender == googleDriveTextBox)
     {
         AppConfiguration.SetAppConfig("NameOnGoogleDrive", googleDriveTextBox.Text);
     }
     if (String.IsNullOrEmpty(googleDriveTextBox.Text) ||
         String.IsNullOrEmpty(localFolderTextBox.Text) ||
         String.IsNullOrEmpty(credentialTextBox.Text) ||
         !FileInfoExtension.isDirectory(localFolderTextBox.Text))
     {
         startCancelBtn.Enabled = false;
     }
     else
     {
         startCancelBtn.Enabled = true;
     }
 }
Exemple #2
0
        // This event handler is where the actual,
        // potentially time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender,
                                              DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            e.Result = Error.SUCCESS;
            var isSourceDelete    = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete"));
            var nameOnGoogleDrive = AppConfiguration.GetAppConfig("NameOnGoogleDrive");
            var destPath          = AppConfiguration.GetAppConfig("LocalPath");
            var credentialPath    = AppConfiguration.GetAppConfig("CredentialPath");

            if (String.IsNullOrEmpty(destPath) ||
                String.IsNullOrEmpty(nameOnGoogleDrive) ||
                String.IsNullOrEmpty(credentialPath) ||
                !new FileInfo(credentialPath).Exists)
            {
                e.Result = Error.NOT_READY;
                return;
            }
            worker.ReportProgress(0, "Start security (0/3)");
            /// 파일 링크 주소
            foreach (string input in m_selectedFile)
            {
                var info = new FileInfo(input);
                Program.AddLog("Input file source : " + input);
                if (!FileInfoExtension.isDirectory(input))
                {
                    runFileMode(worker, input);
                }
                else
                {
                    runDirectoryMode(worker, input);
                }
            }
            worker.ReportProgress(100, "Start bong's security (3/3)");
        }
Exemple #3
0
        private Error runDirectoryMode(BackgroundWorker worker, string name)
        {
            var isSourceDelete    = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete"));
            var nameOnGoogleDrive = AppConfiguration.GetAppConfig("NameOnGoogleDrive");
            var destPath          = AppConfiguration.GetAppConfig("LocalPath");
            var credentialPath    = AppConfiguration.GetAppConfig("CredentialPath");

            var nameOnly = new DirectoryInfo(name).Name;
            var target   = destPath + "\\" + nameOnly;

            Program.AddLog("Start copy to " + target);

            //Create a tast to run copy file
            FileInfoExtension.CopyFolder(name, target);
            worker.ReportProgress(30, "Start security " + name);

            /// 인터넷 체크
            Program.AddLog("Internet connection check.. ");
            if (!GoogleDriveApi.CheckForInternetConnection())
            {
                Program.AddLog("Failed.");
                return(Error.FAILED_INTERNET_CONNECTION);
            }

            /// root id 가져오기
            var id = GoogleDriveApi.getBackupFolderId(nameOnGoogleDrive);

            if (String.IsNullOrEmpty(id))
            {
                id = GoogleDriveApi.CreateFolder(nameOnGoogleDrive);
            }

            Program.AddLog("Start google drive upload.. " + id);

            //Google upload
            target = target + ".zip";
            if (System.IO.File.Exists(target))
            {
                target = FileInfoExtension.getFilepathCheckExist(target);
            }

            if (FileInfoExtension.isDirectory(name))
            {
                // 압축
                if (!FileInfoExtension.Compression(name, target))
                {
                    return(Error.FAILED_COMPRESSION);
                }
            }

            worker.ReportProgress(80, "Start security " + target);
            Program.AddLog("Compression success.. ");
            if (GoogleDriveApi.FileUploadInFolder(id, target))
            {
                Program.AddLog("Upload success.");
                ///
                File.Delete(target);
                if (isSourceDelete)
                {
                    FileInfoExtension.DeleteFolder(name);
                }
            }
            else
            {
                return(Error.FAILED_UPLOAD);
            }

            return(Error.SUCCESS);
        }