private void InitiateSync_Complete(object sender, RunWorkerCompletedEventArgs e) { runningList.Clear(); pendingList.Clear(); completedList.Clear(); failedList.Clear(); totalList.Clear(); if (syncForceStopped) { totalSyncCount = -2; pendingSyncCount = -2; parent.UpdateSyncDetails(totalSyncCount, pendingSyncCount); return; } if (e.Error != null) { Debug.Assert(false, "Failed to get sync list. \n" + e.Error.Message); totalSyncCount = 0; pendingSyncCount = 0; parent.UpdateSyncDetails(totalSyncCount, pendingSyncCount); parent.IsSyncing = false; return; } InitiateSyncResult result = e.Result as InitiateSyncResult; if (string.IsNullOrEmpty(result.Output)) { if (string.IsNullOrEmpty(result.Error)) { MessageBox.Show(parent, "Nothing to sync."); } else { MessageBox.Show(parent, "Failed to get sync list:\n" + result.Error); } totalSyncCount = 0; pendingSyncCount = 0; parent.UpdateSyncDetails(totalSyncCount, pendingSyncCount); parent.IsSyncing = false; return; } string[] delim = new string[1]; delim[0] = "\r\n"; string[] syncFiles = (result.Output as string).Split(delim, StringSplitOptions.RemoveEmptyEntries); totalSyncCount = syncFiles.Length; pendingSyncCount = syncFiles.Length; parent.UpdateSyncDetails(totalSyncCount, pendingSyncCount); if (result.ForceSplit || (syncFiles.Length > parent.Options.FileThreshold)) { List <string> syncList = new List <string>(); foreach (string file in syncFiles) { #if USE_DEPOT_FILE int index = file.IndexOf('#'); string depotFile = (index > 0) ? file.Remove(index) : file; syncList.Add(depotFile.ToLower()); #else int index = file.IndexOf('#'); index = file.IndexOf(':', index); index = (index > 0) ? (index - 1) : 0; string localFile = file.Substring(index); syncList.Add(localFile.ToLower()); #endif } #if USE_DEPOT_FILE ProcessFileList(syncList, "//depot/"); #else ProcessFileList(syncList, parent.Options.ClientRoot + "\\"); #endif } else if (syncFiles.Length > 0) { SyncFolder(parent.Options.SyncFolder, syncFiles.Length); } processingFoldersDone = true; }
private void InitiateSync_DoWork(object sender, DoWorkEventArgs workArgs) { BackgroundWorker worker = sender as BackgroundWorker; List <string> foldersToProcess = new List <string>(); foldersToProcess.Add(parent.Options.SyncFolder); InitiateSyncResult result = new InitiateSyncResult(); result.Output = string.Empty; result.Error = string.Empty; while (foldersToProcess.Count != 0) { string folder = foldersToProcess[0]; foldersToProcess.RemoveAt(0); worker.ReportProgress(10, folder); string cmd = "sync -n "; cmd += (parent.Options.ForceSync) ? "-f " : ""; cmd += folder; cmd += string.IsNullOrEmpty(parent.Options.Revision) ? "" : ("@" + parent.Options.Revision); MyExecute exec = new MyExecute("sd.exe", cmd, false, true, true); lock (processMutex) { processes.Add(exec.ProcessHandle); } bool retval = exec.Run(); lock (processMutex) { processes.Remove(exec.ProcessHandle); } if (retval == true) { string output = exec.Output.Trim(); string error = exec.Error.Trim(); if (string.IsNullOrEmpty(output)) { if (string.IsNullOrEmpty(error)) { //nothing to sync } else { if (error.Contains("up-to-date") || error.Contains("no such file")) { //nothing to sync } else if (error.Contains("Request too large")) { //need to breakup the request List <string> subfolders = GetSubFolders(folder); foldersToProcess.AddRange(subfolders); result.ForceSplit = true; } else { //got an unhandled error result.Error += folder + ": " + error + "\n"; } } } else { result.Output += "\r\n" + output; } } else { result.Output = string.Empty; result.Error = "Failed to execute sd.exe."; break; } } result.Output = result.Output.Trim(); result.Error = result.Error.Trim(); workArgs.Result = result; }