private static void CopyNewVersion(string sourceDirectory, string destinationDirectory) { if (Directory.Exists(destinationDirectory)) { // Custom code if (UpdaterHelper.IsFolderIgnored(destinationDirectory)) { return; } List <string> updatedDestinationFiles = new List <string>(); Application.DoEvents(); Tracing.Tracer.LogText("CopyNewVersion from '{0}' to '{1}'", sourceDirectory, destinationDirectory); string[] sourceFiles = Directory.GetFiles(sourceDirectory, "*.*"); ICollection <string> selfFiles = GetSelfFiles(sourceDirectory); foreach (string sourceFileName in sourceFiles) { if (!selfFiles.Contains(sourceFileName) && !UpdaterHelper.IsFileIgnored(sourceFileName)) // Custom code { string destinationFileName = Path.Combine(destinationDirectory, Path.GetFileName(sourceFileName)); if (File.Exists(destinationFileName)) { File.SetAttributes(destinationFileName, FileAttributes.Normal); } // Custom code (do not copy unchanged files) Application.DoEvents(); DateTime sourceFileModified = File.GetLastWriteTime(sourceFileName); DateTime destFileModified = DateTime.MinValue; if (File.Exists(destinationFileName)) { destFileModified = File.GetLastWriteTime(destinationFileName); } if (sourceFileModified == destFileModified) { form.SetProgressPosition(); updatedDestinationFiles.Add(destinationFileName); continue; } File.Copy(sourceFileName, destinationFileName, true); Tracing.Tracer.LogText("The \"{0}\" file was copied to \"{1}\".", sourceFileName, destinationFileName); form.SetProgressPosition(); // Custom code updatedDestinationFiles.Add(destinationFileName); } } // Custom code if (UpdaterHelper.DeleteExistingFiles) { UpdaterHelper.RemoveNotUpdatedDestinationFiles(destinationDirectory, updatedDestinationFiles); } UpdateSubDirectories(sourceDirectory, destinationDirectory); } }
/// <summary> /// Remove the files that were not updated, but ignore the folders and files specified in app.config settings (IgnoredFolders & IgnoredFilePatterns). /// </summary> public static void RemoveNotUpdatedDestinationFiles(string destinationDirectory, List <string> updatedDestinationFiles) { //string[] destinationFiles = Directory.GetFiles(sourceDirectory, "DevExpress.*.dll|DevExpress.*.xml"); string[] destinationFiles = Directory.GetFiles(destinationDirectory, "*.*"); string[] additionalDestinationFiles = destinationFiles.Except(updatedDestinationFiles).ToArray(); foreach (string additionalDestinationFilePath in additionalDestinationFiles) { if (!UpdaterHelper.IsFileIgnored(additionalDestinationFilePath)) { try { if (File.Exists(additionalDestinationFilePath)) { File.Delete(additionalDestinationFilePath); Tracing.Tracer.LogText("The \"{0}\" file was deleted.", additionalDestinationFilePath); } } catch (Exception ex) { Tracing.Tracer.LogWarning("Error while deleting the \"{0}\" file: \"{1}\".", additionalDestinationFilePath, ex.Message); } } } }