public void Load(ISettingsStore settings) { var model = FileSettings.Load(settings); IncludeFolders.Load(model); IncludeExtensions.Load(model); ExcludeFolders.Load(model); ExcludePatterns.Load(model); }
public void Save(ISettingsStore settings) { var model = new FileSettings(); IncludeFolders.Populate(ref model); IncludeExtensions.Populate(ref model); ExcludeFolders.Populate(ref model); ExcludePatterns.Populate(ref model); model.Save(settings); if (!_hasChanges) { _hasChanges = IncludeFolders.IsDirty || IncludeExtensions.IsDirty || ExcludeFolders.IsDirty || ExcludePatterns.IsDirty; } }
private void AddFilesToTargetAndRecurse(string absPath, string relPath, List <string> ExcludeFiles = null, List <string> ExcludeFolders = null, bool Optional = false) { if (ExcludeFiles == null) { ExcludeFiles = new List <string>(); } ExcludeFiles.Add(@".*\.lastcodeanalysissucceeded"); if (!Program.YamlData.Deploy.Debug) { ExcludeFiles.Add(@".*\.pdb"); } ExcludeFiles.Add(@".*\.d\.ts"); if (ExcludeFolders == null) { ExcludeFolders = new List <string>(); } ExcludeFolders.Add(@"\.git"); if (File.Exists(Path.Combine(absPath, DONTDEPLOY))) { return; } if (!Directory.Exists(absPath)) { if (Optional) { return; } throw new Error($"Folder {absPath} does not exist"); } string[] files = Directory.GetFiles(absPath); foreach (string file in files) { bool exclude = false; string filename = Path.GetFileName(file); foreach (string excludeFile in ExcludeFiles) { if (LikeString(filename, excludeFile)) { exclude = true; break; } } if (!exclude) { Console.WriteLine("Copying {0}", file); // Check for minimal length (most files should be > 0 (or > 3 Unicode) long length = new System.IO.FileInfo(file).Length; if (length <= 3 && !file.Contains("node_modules\\") && !file.Contains("node_modules/")) { if ((file.EndsWith(".ts") && !file.EndsWith(".d.ts")) || file.EndsWith(".css") || file.EndsWith(".js")) { throw new Error($"File {file} is empty"); } } // Check for stray .js and .css files without filelistJS/CSS.txt in Addons folder if (file.EndsWith(".css") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\\node_modules\\") && file.Contains(@"\\Addons\\")))) { string dir = file; int maxLevels = 3; for (; ;) { dir = Path.GetDirectoryName(dir); if (File.Exists(Path.Combine(dir, "filelistCSS.txt"))) { break; } --maxLevels; if (maxLevels == 0) { throw new Error($"File {file} found without filelistCSS.txt"); } } } if (file.EndsWith(".js") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\node_modules\") && file.Contains(@"\Addons\")))) { string dir = file; int maxLevels = 3; for (; ;) { dir = Path.GetDirectoryName(dir); if (File.Exists(Path.Combine(dir, "filelistJS.txt"))) { break; } --maxLevels; if (maxLevels == 0) { throw new Error($"File {file} found without FilelistJS.txt"); } } } string relFile = Path.Combine(relPath, filename); string searchFile = BackupZipFile.CleanFileName(relFile);//$$$$verify if (BackupTargetZip != null) { bool found = (from e in BackupTargetZip.Entries where e.RelativeName == searchFile select e).Any(); if (!found) { BackupTargetZip.AddFile(file, relFile); } } if (BackupTargetFolder != null) { Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BackupTargetFolder, relFile))); File.Copy(file, Path.Combine(BackupTargetFolder, relFile)); } } } string[] dirs = Directory.GetDirectories(absPath); foreach (string dir in dirs) { bool exclude = false; string folder = Path.GetFileName(dir); if (ExcludeFolders != null) { foreach (string excludeFolder in ExcludeFolders) { if (LikeString(folder, excludeFolder)) { exclude = true; break; } } } if (!exclude) { Console.WriteLine("Copying folder {0}", folder); AddFilesToTargetAndRecurse(dir, Path.Combine(relPath, folder), ExcludeFiles, ExcludeFolders); } } if (files.Length == 0 && dirs.Length == 0) { // no files or folders, just add the folder in the ZIP file // some modules/data providers check folder existence to determine whether the module is installed if (BackupTargetZip != null) { //$$$$BackupTargetZip.AddDirectoryByName(relPath); } if (BackupTargetFolder != null) { string absFolder = Path.Combine(BackupTargetFolder, relPath); Directory.CreateDirectory(absFolder); } } }
public ConversionOptions GetConfiguration() { var options = new ConversionOptions(); if (Path.HasValue()) { options.Paths = Path.Values; } if (File.HasValue()) { options.Files = File.Values; } if (List.HasValue()) { options.ListFile = List.Value(); } if (options.Paths.Count == 0 && options.Files.Count == 0 && String.IsNullOrEmpty(options.ListFile)) { throw new ConfigurationException("Nothing to process, must specify one of --path, --file or --list"); } if (IndentStyle.HasValue()) { var style = IndentStyle.Value().ToLower(); if (style == "tabs") { options.Indentation = IndentationStyle.Tabs; } else if (style == "spaces") { options.Indentation = IndentationStyle.Spaces; } else if (style == "leave") { options.Indentation = IndentationStyle.Leave; } else { throw new ConfigurationException($"'{style}' is an invalid indentation style"); } } if (LineEndings.HasValue()) { var lineEndingStyle = LineEndings.Value().ToLower(); if (lineEndingStyle == "crlf") { options.LineEndingStyle = LineEnding.CRLF; } else if (lineEndingStyle == "lf") { options.LineEndingStyle = LineEnding.LF; } else { throw new ConfigurationException("Line Endings must be crlf or lf"); } } options.StripTrailingSpaces = StripTrailingSpaces.HasValue(); // no point going any further if one of the change options isn't actually specified if (options.StripTrailingSpaces == false && options.Indentation == IndentationStyle.Leave && options.LineEndingStyle == LineEnding.Leave) { throw new ConfigurationException("Nothing to do, you must specify one of --strip-trailing-spaces, --line-endings or --indent"); } if (TabWidth.HasValue()) { if (!Int32.TryParse(TabWidth.Value(), out int tabWidth)) { throw new ConfigurationException("tabwidth must be a valid number"); } options.TabWidth = tabWidth; } if (IncludeExtensions.HasValue()) { options.IncludeExtensions = ParseFileExtensionsOption(IncludeExtensions.Values); } if (ExcludeExtensions.HasValue()) { options.ExcludeExtensions = ParseFileExtensionsOption(ExcludeExtensions.Values); } if (ExcludeFolders.HasValue()) { options.ExcludeFolders = ExcludeFolders.Values; } // the presence of recurse|dryrun means it's on, there is no value options.Recurse = Recurse.HasValue(); options.DryRun = DryRun.HasValue(); options.Verbose = Verbose.HasValue(); return(options); }