internal bool Enabled(ProjectColumn column) { if (Ignore?.Any(i => i == column.Name) == true) { return(false); } return(Select is null || (Select.Length == 1 && Select[0] == "*") || Select.Any(i => i == column.Name)); }
/// <summary> /// Actual method syncing all files /// </summary> /// <param name="sourcePath"></param> /// <param name="destPath"></param> private void SyncFilesystem(string sourcePath, string destPath) { if (cancel) { return; } foreach (var file in Directory.GetFiles(sourcePath).Where(x => !Ignore.Any(y => Regex.IsMatch(x, y)))) { if (cancel) { return; } try { if (GetBinary(LogLevel, 2)) { OnLog?.Invoke(this, LogLevel.File, file); } string newDestFilePath = Path.Combine(destPath, Path.GetFileName(file)); //string newDestFilePath = file.Replace(sourcePath, destPath); if (!File.Exists(newDestFilePath)) { File.Copy(file, newDestFilePath); } else if (new FileInfo(file).LastWriteTimeUtc != new FileInfo(newDestFilePath).LastWriteTimeUtc) { if (SyncMode == SyncMode.CopyWithVersioning) { string fileName = Path.GetFileName(newDestFilePath); string newPath = Path.GetFileNameWithoutExtension(fileName) + "_" + new FileInfo(newDestFilePath).LastWriteTimeUtc.ToString(Dateformat) + Path.GetExtension(fileName); File.Move(newDestFilePath, newPath); } File.Copy(file, newDestFilePath, true); } } catch (Exception e) { if (GetBinary(LogLevel, 0)) { OnLog?.Invoke(this, LogLevel.Error, file + " " + e.Message); } } } //Removes all files only present in the destination location if (SyncMode == SyncMode.CopyAndDelete) { foreach (var file in Directory.GetFiles(destPath) .Select(x => Path.GetFileName(x)) .Except(Directory.GetFiles(sourcePath) .Select(x => Path.GetFileName(x)))) { File.Delete(Path.Combine(destPath, file)); if (GetBinary(LogLevel, 4)) { OnLog?.Invoke(this, LogLevel.FileDeleted, Path.Combine(destPath, file)); } } } foreach (var dir in Directory.GetDirectories(sourcePath).Where(x => !Ignore.Any(y => Regex.IsMatch(x, y)))) { try { if (GetBinary(LogLevel, 1)) { OnLog?.Invoke(this, LogLevel.Directory, dir); } string newDestPath = Path.Combine(destPath, Path.GetFileName(dir)); //string newDestPath = dir.Replace(sourcePath, destPath); if (!Directory.Exists(newDestPath)) { Directory.CreateDirectory(newDestPath); } SyncFilesystem(dir, newDestPath); } catch (Exception e) { if (GetBinary(LogLevel, 0)) { OnLog?.Invoke(this, LogLevel.Error, dir + " " + e.Message); } } } //Removes all directories only present in the destination location if (SyncMode == SyncMode.CopyAndDelete) { foreach (var dir in Directory.GetDirectories(destPath) .Select(x => Path.GetFileName(x)) .Except(Directory.GetDirectories(sourcePath) .Select(x => Path.GetFileName(x)))) { Directory.Delete(Path.Combine(destPath, dir), true); if (GetBinary(LogLevel, 5)) { OnLog?.Invoke(this, LogLevel.DirectoryDeleted, Path.Combine(destPath, dir)); } } } }