private void XCount(DirectoryInfo sourceDirectory) { if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName)) { foreach (FileInfo fi in sourceDirectory.GetFiles()) { if (MonitoredTypesHelper.AllowFile(fi.FullName, monitoredTypesOnly)) { if (Interrupt.Reason != "Cancel") { totalBytes += fi.Length; SignalUpdateCount(fi.Length); } } } foreach (DirectoryInfo di in sourceDirectory.GetDirectories()) { if (Interrupt.Reason != "Cancel") { XCount(di); } } } //Check if user has chosen to cancel run. if (Interrupt.Reason == "Cancel") { Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Count cancelled")); } }
/// <summary> /// Append directory level information into the specified DataTable. /// </summary> /// <param name="qualifier">Top level directory.</param> /// <param name="dirs">Work in progress collection of directories.</param> /// <param name="estimate">Number of directory entries found. Used for future estimating.</param> public override void DirLevel(DirectoryEntry parentEntry, string qualifier, string directory, ref List <string> dirs, ref long estimate) { string spec; string path; string name; path = directory; if (directory.Length > qualifier.Length) { directory = directory.Substring(qualifier.Length); } else { directory = string.Empty; } try { DirectoryInfo directoryInfo = new DirectoryInfo(path); directoryInfo.Refresh(); if (DirectoryExclusionsHelper.AllowDirectory(path)) { DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories(); for (int row = 0; row < directoryInfoArray.Length; row++) { try { name = directoryInfoArray[row].Name; spec = path + Path.DirectorySeparatorChar.ToString() + name; if (DirectoryExclusionsHelper.AllowDirectory(spec)) { if (directoryInfoArray[row].Exists) { dirs.Add(spec); DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); entry.StdSize = 0; entry.StdDate = System.DateTime.Parse("01/01/2000"); entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = "dir"; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } } catch (OleDbException oExceptionA) { System.Diagnostics.Debug.WriteLine(oExceptionA.Errors[0].Message); } if (Interrupt.Reason == "Cancel") { break; } } FileInfo[] fileInfoArray = directoryInfo.GetFiles(); for (int row = 0; row < fileInfoArray.Length; row++) { try { name = fileInfoArray[row].Name; spec = path + Path.DirectorySeparatorChar.ToString() + name; if (fileInfoArray[row].Exists) { string ext = Path.GetExtension(spec); if (ext.StartsWith(".")) { if (ext.Length > 1) { ext = ext.Substring(1); } else { ext = string.Empty; } } if (MonitoredTypesHelper.AllowFile(spec, monitoredTypesOnly)) { DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); entry.StdSize = fileInfoArray[row].Length; entry.StdDate = fileInfoArray[row].LastWriteTime; entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = ext; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } } catch (OleDbException exceptionB) { System.Diagnostics.Debug.WriteLine(exceptionB.Errors[0].Message); } if (Interrupt.Reason == "Cancel") { break; } } } } catch (DirectoryNotFoundException oExceptionNF) { System.Diagnostics.Debug.WriteLine(oExceptionNF.Message); } finally { } }
/// <summary> /// Append directory level information into the specified DataTable. /// </summary> /// <param name="qualifier">Top level directory.</param> /// <param name="dirs">Work in progress collection of directories.</param> /// <param name="estimate">Number of directory entries found. Used for future estimating.</param> public override void DirLevel(DirectoryEntry parentEntry, string qualifier, string directory, ref List <string> dirs, ref long estimate) { string spec; string path; string name; path = directory; if (directory.Length > qualifier.Length) { directory = directory.Substring(qualifier.Length); } else { directory = string.Empty; } try { //TODO: Google Drive Instead of File System. if (DirectoryExclusionsHelper.AllowDirectory(path)) { List <DirectoryEntry> driveEntries = GetDriveEntriesInFolder(parentEntry.EntryId); for (int row = 0; row < driveEntries.Count; row++) { DirectoryEntry driveEntry = driveEntries[row]; if (driveEntry.MimeType == Connector.FOLDER_MIME_TYPE) { name = driveEntry.EntryName; spec = path + Path.DirectorySeparatorChar.ToString() + name; if (DirectoryExclusionsHelper.AllowDirectory(spec)) { if (Filer.DirectoryExists(spec)) { dirs.Add(spec); Dirs.Add(driveEntry); DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); entry.StdSize = 0; entry.StdDate = System.DateTime.Parse("01/01/2000"); entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = "dir"; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } } else { name = driveEntry.EntryName; spec = path + Path.DirectorySeparatorChar.ToString() + name; if (Filer.FileExists(spec)) { string ext = Path.GetExtension(spec); if (ext.StartsWith(Connector.FULL_STOP)) { if (ext.Length > 1) { ext = ext.Substring(1); } else { ext = string.Empty; } } if (MonitoredTypesHelperG.AllowFile(spec, monitoredTypesOnly)) { DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); entry.StdSize = driveEntry.StdSize; entry.StdDate = driveEntry.StdDate; entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = ext; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } } if (Interrupt.Reason == "Cancel") { break; } } } } catch (DirectoryNotFoundException oExceptionNF) { System.Diagnostics.Debug.WriteLine(oExceptionNF.Message); } finally { } }
/// <summary> /// Append directory level information into the specified DataTable. /// </summary> /// <param name="qualifier">Top level directory.</param> /// <param name="dirs">Work in progress collection of directories.</param> /// <param name="estimate">Number of directory entries found. Used for future estimating.</param> public override void DirLevel(DirectoryEntry parentEntry, string qualifier, string directory, ref List <string> dirs, ref long estimate) { string spec; string path; string name; path = directory; if (directory.Length > qualifier.Length) { directory = directory.Substring(qualifier.Length); } else { directory = string.Empty; } try { if (DirectoryExclusionsHelper.AllowDirectory(path)) { string commandLine = Administrator.ProfileManager.SystemProfile.ADB + string.Format(DIRECTORY_LIST_COMMAND_TEMPLATE, path); CommandLauncher launcher = new CommandLauncher(); launcher.Run(commandLine); List <string> lines = launcher.OutputLines; for (int row = 0; row < lines.Count; row++) { string line = lines[row]; if (line.Trim().Length == 0) { continue; } if (line.StartsWith("total")) { continue; } string fileName = string.Empty; string timeText = string.Empty; string dateText = string.Empty; string sizeText = string.Empty; string dateTimeText = string.Empty; string[] parts; int index = -1; if (line.Contains(":")) { int pos = line.IndexOf(":"); pos = line.IndexOf(" ", pos); fileName = line.Substring(pos); fileName = fileName.Trim(); line = line.Substring(0, pos); parts = line.Split(' '); index = parts.Length - 1; timeText = parts[index--]; dateText = parts[index--]; sizeText = parts[index--]; dateTimeText = dateText + " " + timeText; } else { parts = line.Split(' '); index = parts.Length - 1; fileName = parts[index--]; timeText = parts[index--]; dateText = parts[index--]; sizeText = parts[index--]; dateTimeText = dateText + " " + timeText; } if (line.StartsWith("/")) { //No such file or directory. } else if (line.StartsWith("d")) { //Directory. try { name = fileName; spec = path + "/" + name; if (DirectoryExclusionsHelper.AllowDirectory(spec)) { dirs.Add(spec); DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); entry.StdSize = 0; entry.StdDate = System.DateTime.Parse("01/01/2000"); entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = "dir"; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } catch (Exception oExceptionA) { System.Diagnostics.Debug.WriteLine(oExceptionA.Message); } if (Interrupt.Reason == "Cancel") { break; } } else { //File. try { name = fileName; spec = path + "/" + name; string ext = string.Empty; int pos = fileName.LastIndexOf("."); if (pos > -1) { ext = fileName.Substring(pos); } if (ext.StartsWith(".")) { if (ext.Length > 1) { ext = ext.Substring(1); } else { ext = string.Empty; } } //if (MonitoredTypesHelper.AllowFile(spec, monitoredTypesOnly)) if (true) { DirectoryEntry entry = new DirectoryEntry(); entry.StdHlq = qualifier.Trim(); entry.StdDir = directory.Trim(); entry.StdFile = name.Trim(); long size = 0; long.TryParse(sizeText, out size); entry.StdSize = size; DateTime dateTime = DateTime.MinValue; DateTime.TryParse(dateTimeText, out dateTime); entry.StdDate = dateTime; entry.SourceDate = entry.StdDate; entry.TargetDate = entry.StdDate; entry.SourceFile = entry.StdFile; entry.TargetFile = entry.StdFile; entry.StdType = ext; entry.CtlComparison = string.Empty; directoryListing.Add(entry); estimate += entry.StdSize; SignalUpdateProgress("DirList", entry.StdSize); } } catch (Exception exceptionB) { System.Diagnostics.Debug.WriteLine(exceptionB.Message); } if (Interrupt.Reason == "Cancel") { break; } } } } } catch (DirectoryNotFoundException oExceptionNF) { System.Diagnostics.Debug.WriteLine(oExceptionNF.Message); } finally { } }
private void XDelete(DirectoryInfo sourceDirectory, UserSetting.CopyRuleEnum copyRule) { if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName)) { Administrator.Tracer.WriteLine(); Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Delete From : ""{0}""", sourceDirectory.ToString())); foreach (DirectoryInfo di in sourceDirectory.GetDirectories()) { if (Interrupt.Reason != "Cancel") { XDelete(di, copyRule); } } foreach (FileInfo fi in sourceDirectory.GetFiles()) { if (MonitoredTypesHelper.AllowFile(fi.FullName, monitoredTypesOnly)) { if (fi.Exists) { long fileLength = fi.Length; if (Interrupt.Reason != "Cancel") { try { fi.IsReadOnly = false; fi.Delete(); Administrator.Tracer.WriteTimedMsg("I", String.Format(@"{0} - Deleted", fi.Name)); } catch (Exception ex) { Administrator.Tracer.WriteTimedMsg("E", String.Format(@"Error while deleting : ""{0}""", fi.Name)); Administrator.Tracer.WriteTimedMsg("E", ex.Message); } } SignalUpdateDelete(fileLength); } } } if (Directory.Exists(sourceDirectory.FullName)) { if (Interrupt.Reason != "Cancel") { try { Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Removing : ""{0}""", sourceDirectory.FullName)); sourceDirectory.Delete(); } catch (Exception ex) { Administrator.Tracer.WriteTimedMsg("E", String.Format(@"Error while removing : ""{0}""", sourceDirectory.FullName)); Administrator.Tracer.WriteTimedMsg("E", ex.Message); } } } } //Check if user has chosen to cancel run. if (Interrupt.Reason == "Cancel") { Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Delete cancelled")); return; } }
private void XCopy(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory, UserSetting.CopyRuleEnum copyRule) { if (DirectoryExclusionsHelper.AllowDirectory(sourceDirectory.FullName)) { if (!Directory.Exists(targetDirectory.FullName)) { Directory.CreateDirectory(targetDirectory.FullName); } Administrator.Tracer.WriteLine(); Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Copy From : ""{0}""", sourceDirectory.ToString())); Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Copy To : ""{0}""", targetDirectory.ToString())); foreach (FileInfo fi in sourceDirectory.GetFiles()) { if (MonitoredTypesHelper.AllowFile(fi.FullName, monitoredTypesOnly)) { if (Interrupt.Reason != "Cancel") { try { string targetFile = Path.Combine(targetDirectory.ToString(), fi.Name); FileInfo targetFileInfo = new FileInfo(targetFile); bool doCopy = false; if (targetFileInfo.Exists) { if (copyRule == UserSetting.CopyRuleEnum.SkipMatches) { doCopy = false; Administrator.Tracer.WriteTimedMsg("I", String.Format(@"{0} - Skipped", fi.Name)); } else if (copyRule == UserSetting.CopyRuleEnum.ReplaceMatches) { doCopy = true; } else if (copyRule == UserSetting.CopyRuleEnum.ReplaceOnlyWithNewer) { if (CompareDateTimeStamps(fi.LastWriteTime, targetFileInfo.LastWriteTime) > 0) { doCopy = true; } else { doCopy = false; Administrator.Tracer.WriteTimedMsg("I", String.Format(@"{0} - Skipped - Source file is not newer", fi.Name)); } } else if (copyRule == UserSetting.CopyRuleEnum.ReplacePreservingNewest) { if (CompareDateTimeStamps(fi.LastWriteTime, targetFileInfo.LastWriteTime) >= 0) { doCopy = true; } else { doCopy = false; Administrator.Tracer.WriteTimedMsg("I", String.Format(@"{0} - Skipped - Source file is older", fi.Name)); } } } else { doCopy = true; } if (doCopy) { try { if (targetFileInfo.Exists) { targetFileInfo.IsReadOnly = false; } fi.CopyTo(Path.Combine(targetDirectory.ToString(), fi.Name), true); targetFileInfo = new FileInfo(targetFile); if (targetFileInfo.Exists) { targetFileInfo.IsReadOnly = false; } Administrator.Tracer.WriteTimedMsg("I", String.Format(@"{0} - Copied", fi.Name)); } catch (Exception ex) { Administrator.Tracer.WriteLine(); Administrator.Tracer.WriteTimedMsg("E", String.Format(@"{0} - Error : {1}{2}", fi.Name, Environment.NewLine, ex.Message)); Administrator.Tracer.WriteLine(); } } SignalUpdateCopy(fi.Length); } catch (Exception ex2) { Administrator.Tracer.WriteLine(); Administrator.Tracer.WriteTimedMsg("E", String.Format(@"{0} - Target File (Name too long) Error : {1}{2}", fi.Name, Environment.NewLine, ex2.Message)); Administrator.Tracer.WriteLine(); } } } } foreach (DirectoryInfo di in sourceDirectory.GetDirectories()) { if (Interrupt.Reason != "Cancel") { try { if (DirectoryExclusionsHelper.AllowDirectory(di.FullName)) { DirectoryInfo targetDirectoryInfo = targetDirectory.CreateSubdirectory(di.Name); XCopy(di, targetDirectoryInfo, copyRule); } } catch (Exception ex) { Administrator.Tracer.WriteLine(); Administrator.Tracer.WriteTimedMsg("E", String.Format(@"{0} - Target Directory (Name too long) Error : {1}{2}", di.Name, Environment.NewLine, ex.Message)); Administrator.Tracer.WriteLine(); } } } } //Check if user has chosen to cancel run. if (Interrupt.Reason == "Cancel") { Administrator.Tracer.WriteTimedMsg("I", String.Format(@"Copy cancelled")); return; } }