Example #1
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);
        }
Example #2
0
        private void sourceDeleteChanged(object sender, EventArgs e)
        {
            var t = Convert.ToString(sourceFolderDeleteAfterCopy.Checked);

            AppConfiguration.SetAppConfig("SourceDelete", t);
        }