/// <summary> /// Upload a file to Google Drive /// </summary> /// <param name="filePath"></param> public void Upload(string filePath) { try { string parentID = GDriveUploadFolderID; string fileName = Path.GetFileName(filePath); var ret = GoogleDriveAPIV3.uploadNewFileToDrive(filePath, fileName, parentID, this); if (ret != null) { if (ret == "") { log.Info("Not a (new) file: " + fileName); } else { log.Info(string.Format("File \"{0}\" upload successfully, GDrive fileId : {1}", fileName, ret)); if (DeleteFileAfterUploaded) { File.Delete(filePath); } } } else { log.Error("File upload failed: " + fileName); } } catch (Exception ex) { log.Error("Upload, ex = " + ex); } }
public static bool compareHash(string hashToCompare) { foreach (GoogleDriveFile file in GoogleDriveAPIV3.listDriveFiles()) { if (file.hash == hashToCompare) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormMain_Load(object sender, EventArgs e) { try { //Hide the Form BeginInvoke(new MethodInvoker(delegate { Hide(); })); //Make sure the directory structure is ready Directory.CreateDirectory(Path.Combine(DefaultFTPFolder, SubfolderNameForUploadToGoogleDrive)); //Start folder file created watcher startWatcher(); //Connect to Google Drive if (GoogleDriveAPIV3.GoogleDriveConnection( DefaultJSONSecretPath, UserName)) { log.Info("Google Drive has been connected, ready to upload files..."); connected = true; this.trayIcon.Icon = Properties.Resources.GreenLight; this.trayIcon.ShowBalloonTip(100, "Status", "Google Drive connected, ready to upload files...", ToolTipIcon.Info); if (UploadExistingFiles) { moveAndUploadExistingFiles(); } } else { log.Error("Make conncection to Google Drive failed!"); } } catch (Exception ex) { log.Error("FormMain_Load, ex = " + ex); } }