public static string GetGooglePhotoFolderId(Action<string> logText = null) { if (_googlePhotoFolderId != null) return _googlePhotoFolderId; List<string> sugestionNames = new List<string>() { "Google Photos", "Google Фото", "Google Photo" }; var local = GetSavedName(); if (!String.IsNullOrWhiteSpace(local)) sugestionNames.Insert(0, local); var photoFolders = new List<Google.Apis.Drive.v2.Data.File>(); while (true) { try { if (logText != null) { logText("Login on google."); if (!Directory.Exists(GoogleDriveClient.CredPath)) logText("New browser window will appear. You should click accept for work with app."); } var google = new GoogleDriveClient(); if (logText != null) logText("Login Ok."); foreach (var sg in sugestionNames) { photoFolders = google.GetDirectories(sg, "root"); if (photoFolders.Count > 0) break; } } catch (System.Threading.ThreadAbortException ex) { return null; } catch (Exception ex) { if (MessageBox.Show("Can't connect to google drive. Probably something wrong with your internet connection?\r\nTry again please.\r\n"+ "\r\nException Code:\r\n"+ex.ToString(), "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) continue; else return null; } break; } if (photoFolders.Count == 1) return photoFolders[0].Id; if (photoFolders.Count > 1) { MessageBox.Show("Unexpected error. Too many photo folders.\r\n Remove 'Google photos' folders, which is not needed."); return null; } //Can't found photo folder if (_thisForm == null || _thisForm.IsDisposed) _thisForm = new GetGooglePhotosFolder(); _thisForm.FillGoogleDirs(); _thisForm.ShowDialog(); var result = _thisForm.result; var resultName = _thisForm.resultName; _thisForm.Dispose(); if (!String.IsNullOrWhiteSpace(result)) { if (!String.IsNullOrWhiteSpace(resultName)) SetSavedName(resultName); _googlePhotoFolderId = result; } return result; }
public void FillGoogleDirs() { var google = new GoogleDriveClient(); var folders = google.GetDirectories(null, "root"); _dirs = new Dictionary<string, string>(); radioListBox.Items.Clear(); foreach (var folder in folders) { if (!_dirs.ContainsKey(folder.Title)) { _dirs.Add(folder.Title, folder.Id); radioListBox.Items.Add(folder.Title); } } }