private static bool TryEnsureFileExists( RelativePath relativeFilePath, IProjectFolder projectFolder, IProjectFile sourceFile, IProjectModelTransactionCookie transaction, out IProjectFile file) { file = projectFolder.GetSubFiles(relativeFilePath.Name).FirstOrDefault(); if (file != null) { var message = $"The file '{relativeFilePath.FullPath}' already exists.{Environment.NewLine}" + "Do you want to overwrite it?"; return(MessageBox.ShowYesNo(message)); } file = ExecutionHelpers.CreateFile(relativeFilePath.Name, projectFolder, sourceFile, transaction); return(true); }
private static bool TryCreateFiles( List <FileGeneratorOutput> fileGeneratorOutputs, IProjectModelTransactionCookie transaction) { var alreadyExistedFilePaths = new List <string>(); foreach (FileGeneratorOutput output in fileGeneratorOutputs) { IProjectFile file = output.ProjectFolder.GetSubFiles(output.FileName).FirstOrDefault(); if (file == null) { file = ExecutionHelpers.CreateFile( output.FileName, output.ProjectFolder, output.SourceProjectFile, transaction ); } else { alreadyExistedFilePaths.Add(output.FilePath); } output.GeneratedProjectFile = file; } if (alreadyExistedFilePaths.Count > 0) { string message = $"The following files already exist:{Environment.NewLine}" + string.Join(Environment.NewLine, alreadyExistedFilePaths) + Environment.NewLine + Environment.NewLine + "Do you want to overwrite them?"; return(MessageBox.ShowYesNo(message)); } return(true); }