Esempio n. 1
0
 static public void CopyFolder(string sourceFolder, string destFolder)
 {
     if (isDirectory(sourceFolder))
     {
         if (!Directory.Exists(destFolder))
         {
             Directory.CreateDirectory(destFolder);
         }
         string[] files = Directory.GetFiles(sourceFolder);
         foreach (string file in files)
         {
             string name = Path.GetFileName(file);
             string dest = Path.Combine(destFolder, name);
             dest = FileInfoExtension.getFilepathCheckExist(name);
             File.Copy(file, dest);
         }
         string[] folders = Directory.GetDirectories(sourceFolder);
         foreach (string folder in folders)
         {
             string name = Path.GetFileName(folder);
             string dest = Path.Combine(destFolder, name);
             CopyFolder(folder, dest);
         }
     }
 }
Esempio n. 2
0
        private Error runFileMode(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 target = destPath + "\\" + Path.GetFileName(name);

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

            //Create a tast to run copy file
            target = FileInfoExtension.getFilepathCheckExist(target);

            File.Copy(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
            worker.ReportProgress(80, "Start security " + target);
            Program.AddLog("Compression success.. ");
            if (GoogleDriveApi.FileUploadInFolder(id, target))
            {
                Program.AddLog("Upload success.");
                if (isSourceDelete)
                {
                    FileInfoExtension.DeleteFolder(name);
                }
            }
            else
            {
                return(Error.FAILED_UPLOAD);
            }

            return(Error.SUCCESS);
        }
Esempio n. 3
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;
     }
 }
Esempio n. 4
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)");
        }