/// <summary> /// Scans all of the files in the list and removes any files that are protected. /// </summary> public void ValidateRequiredFiles(RequiredFilesModel requiredFiles) { var directoriesToRemove = new List <string>(); var filesToRemove = new List <string>(); foreach (var directory in requiredFiles.Directories) { if (IsProtected(directory)) { directoriesToRemove.Add(directory); } } foreach (var file in requiredFiles.Files) { if (IsProtected(file)) { filesToRemove.Add(file); } } foreach (var directory in directoriesToRemove) { requiredFiles.Directories.Remove(directory); } foreach (var file in filesToRemove) { requiredFiles.Files.Remove(file); } }
public RequiredFilesModel GetRequiredFiles(EntryModel entry) { var requiredFiles = new RequiredFilesModel(); var platformDirectory = _pathBuilder.GetPlatformDirectory(entry); if (Directory.Exists(platformDirectory)) { var directories = Directory.GetDirectories(platformDirectory); var processedDirectories = new List <string>(); foreach (var directory in directories) { var directoryName = Path.GetFileName(directory); processedDirectories.Add(directoryName); } var files = Directory.GetFiles(platformDirectory); var processedFiles = new List <string>(); foreach (var file in files) { var fileName = Path.GetFileName(file); processedFiles.Add(fileName); } requiredFiles.Directories = processedDirectories; requiredFiles.Files = processedFiles; ValidateRequiredFiles(requiredFiles); } return(requiredFiles); }
private void DeleteRequiredFiles(string rootDirectory, RequiredFilesModel requiredFiles) { // Out with the old foreach (var file in requiredFiles.Files) { string targetFile = Path.Combine(rootDirectory, file); if (File.Exists(targetFile)) { _logger.LogInfo($"Deleting: {targetFile}"); File.Delete(targetFile); } } foreach (var directory in requiredFiles.Directories) { string targetDirectory = Path.Combine(rootDirectory, directory); if (Directory.Exists(targetDirectory)) { _logger.LogError($"Deleting: {targetDirectory}"); Directory.Delete(targetDirectory, true); } } }
public void SaveLastRequiredFiles(RequiredFilesModel requiredFiles) { string serializedFiles = JsonConvert.SerializeObject(requiredFiles, Formatting.Indented); SaveToJsonFile(serializedFiles, LastRequiredJsonPath); }
private void InstallRequiredFiles(string platformDirectory, string rootDirectory, RequiredFilesModel requiredFiles) { // In with the new foreach (var file in requiredFiles.Files) { var sourceFile = Path.Combine(platformDirectory, file); var targetFile = Path.Combine(rootDirectory, file); if (File.Exists(sourceFile)) { _logger.LogInfo($"Copying: {sourceFile} -> {targetFile}"); File.Copy(sourceFile, targetFile, true); } } foreach (var file in requiredFiles.Directories) { var sourceDirectory = Path.Combine(platformDirectory, file); var targetDirectory = Path.Combine(rootDirectory, file); if (Directory.Exists(sourceDirectory)) { _logger.LogInfo($"Copying: {sourceDirectory} -> {targetDirectory}"); FileSystem.CopyDirectory(sourceDirectory, targetDirectory, true); } } }