public void TrashAll(string drivePhotoDirId) { GoogleDriveClient drive = new GoogleDriveClient(); LogText("Search for files already in Google Photos directory on Google Drive. It can take a long time..."); var googleFilesLst = drive.GetFiles(null, null); if (googleFilesLst.Count == 0) { LogText("No files found"); return; } else LogText("Found " + googleFilesLst.Count + " files"); ResetProgress(googleFilesLst.Count); LogText("MOVE ALL FILES TO TRASH..."); foreach (var file in googleFilesLst) { drive.TrashFile(file.Id); IncreaseProgress(); } ResetProgress(10); LogText("READY"); }
public void FixVideoDates(List<TreeNode> rootNodes, string drivePhotoDirId) { LogText("Search for files on local drive"); localFiles = GetFilesFromNodes(rootNodes); if (localFiles.Count == 0) { LogText("No files found"); return; } GoogleDriveClient drive = new GoogleDriveClient(); var filesForFixing = new HashSet<string>(); LogText("Search for files already in Google Photos directory on Google Drive. It can take a long time..."); var googleFilesLst = drive.GetFiles(null, drivePhotoDirId); googleFiles = new Dictionary<string, List<File>>(); int hasVideoFiles = 0; foreach (var file in googleFilesLst) { if (!videoExt.Contains("."+file.FileExtension.ToLower())) continue; //Do not need trash files here //var x = file.ExplicitlyTrashed; if (!googleFiles.ContainsKey(file.OriginalFilename)) googleFiles.Add(file.OriginalFilename, new List<File>()); googleFiles[file.OriginalFilename].Add(file); hasVideoFiles++; } if (hasVideoFiles == 0) { LogText("No video files found"); return; } else LogText("Found " + hasVideoFiles + " video files"); filesForFixing.UnionWith(googleFiles.Keys); //filesForMoving.UnionWith(picasaFiles.Keys); //System.IO.File.WriteAllLines("localFiles", localFiles.Keys.ToList()); LogText("FIXING VIDEO TIME.."); ResetProgress(filesForFixing.Count); bool hasError = false; var opt = new ParallelOptions() { MaxDegreeOfParallelism = 1 }; //foreach (var googleFilePair in googleFiles) Parallel.ForEach(filesForFixing, opt, (googleFilePair) => { if (!localFiles.ContainsKey(googleFilePair)) { IncreaseProgress(); return; } if (hasError) return; for (int i = 0; i < 3; i++) { try { FixVideoFile(googleFilePair, drivePhotoDirId); if (i != 0) LogText("Try succeeded."); break; } catch (Exception ex) { if (i < 2) { LogText("Error fixing " + googleFilePair + ". Try again..."); if (i == 1) { lock (picasaFiles) { //Sometimes picassa and all already found files creditals coul be expired //Will delete them all and reinit as usual. picasaFiles.Clear(); picasaFilesId.Clear(); } } } else { hasError = true; throw ex; } } } IncreaseProgress(); }); LogText("\r\nREADY"); ResetProgress(100); }