Ejemplo n.º 1
0
        //private void downRun(string fileName, string fileID, string mimeType, string SelectedPath)
        //{
        //    try
        //    {
        //        GoogleDriveAPIV3.downloadFromDrive(fileName, fileID, SelectedPath, mimeType);
        //    }
        //    catch(Exception ex) { MessageBox.Show(ex.ToString()); }
        //}


        private void btnUpload_Click(object sender, EventArgs e)
        {
            string filePath, fileName;
            string parentID = (txtParentID.Text != string.Empty) ? txtParentID.Text : null;
            bool   result;

            if (chbUploadMultiple.Checked)
            {
                result = (MessageBox.Show("Do you want to upload only new/changed files on Google Drive ?",
                                          "Upload existing files?",
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                try
                {
                    lbFilesToUpload.BeginUpdate();

                    for (int i = lbFilesToUpload.Items.Count - 1; i >= 0; i--)
                    {
                        // lbFilesToUpload.Items[i].c
                        filePath = (chbCompress.Checked) ? Gtools.compressFile(lbFilesToUpload.Items[i].ToString()) : lbFilesToUpload.Items[i].ToString();
                        System.Diagnostics.Debug.WriteLine(filePath);
                        fileName = (chbCompress.Checked) ? Path.GetFileName(lbFilesToUpload.Items[i].ToString().Split('.').First()) + ".zip" : Path.GetFileName(lbFilesToUpload.Items[i].ToString());
                        GoogleDriveAPIV3.uploadToDrive(filePath, fileName, parentID, result, this);


                        string newName = "DONE!  " + lbFilesToUpload.Items[i].ToString();

                        lbFilesToUpload.Items.RemoveAt(i);
                        lbFilesToUpload.Items.Insert(i, newName);
                        updateDataGridView();
                    }
                    lbFilesToUpload.EndUpdate();
                }
                catch (Exception exc)
                {
                    System.Diagnostics.Debug.WriteLine(exc.Message);
                    lbFilesToUpload.EndUpdate();
                }
            }
            else
            {
                filePath = (chbCompress.Checked) ? Gtools.compressFile(txtFilePath.Text) : txtFilePath.Text;
                fileName = (chbCompress.Checked) ? txtFileName.Text.Split('.').First() + ".zip" : txtFileName.Text;
                if (GoogleDriveAPIV3.compareHash(Gtools.hashGenerator(filePath)))
                {
                    result = MessageBox.Show("The file : \"" + fileName +
                                             "\" \nAlready exists on Google Drive!! \nDo you want to uploaded anyway?",
                                             "File already exist on Google Drive",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;


                    Task.Run(() => { GoogleDriveAPIV3.uploadToDrive(filePath, fileName, parentID, !result, this); updateDataGridView(); });
                }
                else
                {
                    Task.Run(() => { GoogleDriveAPIV3.uploadToDrive(filePath, fileName, parentID, false, this); updateDataGridView(); });
                }
            }
        }
 public static bool compareHash(string hashToCompare)
 {
     foreach (GoogleDriveFile file in GoogleDriveAPIV3.listDriveFiles())
     {
         if (file.hash == hashToCompare)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        private void updateDataGridView(string name = null, string type = null)
        {
            if (InvokeRequired)
            {
                Invoke(new Action <string, string>(updateDataGridView), new object[] { name, type });
                return;
            }

            dtDriveFiles = null;
            dtDriveFiles = Gtools.ToDataTable <GoogleDriveFile>(GoogleDriveAPIV3.listDriveFiles(name, type));
            dgvFilesFromDrive.DataSource = dtDriveFiles;
        }
Ejemplo n.º 4
0
        private static void startWithArgs(string[] args)
        {
            string uploadFilePath, filename, backupName, parentID;
            int    user, compressing = 0, onlyNew = 0;

            try
            {
                if (loadUsers() && args.Length > 5)
                {
                    loadFileList(args[0]);
                    backupName = args[1];
                    parentID   = (args[2] != "0") ? args[2] : null;
                    int.TryParse(args[3], out user);
                    int.TryParse(args[4], out onlyNew);
                    int.TryParse(args[5], out compressing);


                    if (GoogleDriveAPIV3.GoogleDriveConnection(
                            UserList[user].clientSecretPath,
                            UserList[user].userName))
                    {
                        parentID = GoogleDriveAPIV3.createFolderToDrive(
                            Gtools.getTimeStamp() + "_" + backupName,
                            parentID);
                        foreach (IOFile file in IOFileList)
                        {
                            uploadFilePath = (compressing == 0) ? file.path : Gtools.compressFile(file.path);
                            filename       = (compressing == 0) ? file.name : file.name.Split('.').First() + ".zip";
                            GoogleDriveAPIV3.uploadToDrive(uploadFilePath, filename, parentID, (onlyNew != 0), new frmMain());
                        }
                    }
                    else
                    {
                        throw new Exception("Connection Error");
                    }
                }
                else
                {
                    throw new Exception("Arguments Error");
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.Message + " Start with Args Error.\n");
                Gtools.writeToFile(frmMain.errorLog, Environment.NewLine + DateTime.Now.ToString() +
                                   Environment.NewLine + exc.Message + " Start with Args Error.\n");
            }
        }
Ejemplo n.º 5
0
        private void downloadFile(string fileName, string fileID, string mimeType)
        {
            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog();

            switch (result)
            {
            case DialogResult.OK:
                txtJsonPath.Text = ofgJsonFile.FileName;
                string path = fbd.SelectedPath;
                Task.Run(() => { GoogleDriveAPIV3.downloadFromDrive(fileName, fileID, path, mimeType, this); });
                //Task.Run(() => downRun(fileName, fileID, path, mimeType));
                //downloadRunner = new Task(downRun);
                //downloadRunner.Start();
                // GoogleDriveAPIV3.downloadFromDrive(fileName, fileID, fbd.SelectedPath, mimeType);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (cbUser.SelectedIndex == -1)
     {
         MessageBox.Show("You have to Select A User in order to connect", "Attention!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         if (GoogleDriveAPIV3.GoogleDriveConnection(
                 UserList[cbUser.SelectedIndex].clientSecretPath,
                 UserList[cbUser.SelectedIndex].userName))
         {
             btnConnect.BackColor = Color.Green;
             Task.Run(() => { updateDataGridView(); });
         }
         else
         {
             btnConnect.BackColor = Color.Red;
             MessageBox.Show("Connection Error", "Attention!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Ejemplo n.º 7
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            string       fileId, fileName;
            DialogResult result = MessageBox.Show("Do you want to delete the " + dgvFilesFromDrive.SelectedRows.Count + " Selected Files?", "Confirm",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            switch (result)
            {
            case DialogResult.Yes:
                foreach (DataGridViewRow row in dgvFilesFromDrive.SelectedRows)
                {
                    fileName = dgvFilesFromDrive.Rows[row.Index].Cells[0].Value.ToString();
                    fileId   = dgvFilesFromDrive.Rows[row.Index].Cells[4].Value.ToString();
                    GoogleDriveAPIV3.removeFile(fileId);
                }
                break;

            default:
                break;
            }

            Task.Run(() => { updateDataGridView(); });
        }
Ejemplo n.º 8
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     Task.Run(() => { GoogleDriveAPIV3.createFolderToDrive(txtCreateFolder.Text, null); updateDataGridView(); });
 }