/// <summary>
 /// Try to add the specified the project with the target path. If there's an existing file in the project with the same name,
 /// it will ask the logger for the resolution, which has 4 choices: Overwrite|Ignore|Overwrite All|Ignore All
 /// </summary>
 internal static void TryAddFile(IProjectSystem project, string path, Func <Stream> content)
 {
     if (project.FileExists(path) && project.FileExistsInProject(path))
     {
         // file exists in project, ask user if he wants to overwrite or ignore
         string conflictMessage            = String.Format(CultureInfo.CurrentCulture, NuGetResources.FileConflictMessage, path, project.ProjectName);
         FileConflictResolution resolution = project.Logger.ResolveFileConflict(conflictMessage);
         if (resolution == FileConflictResolution.Overwrite || resolution == FileConflictResolution.OverwriteAll)
         {
             // overwrite
             project.Logger.Log(MessageLevel.Info, NuGetResources.Info_OverwriteExistingFile, path);
             using (Stream stream = content())
             {
                 project.AddFile(path, stream);
             }
         }
         else
         {
             // ignore
             project.Logger.Log(MessageLevel.Info, NuGetResources.Warning_FileAlreadyExists, path);
         }
     }
     else
     {
         using (Stream stream = content())
         {
             project.AddFile(path, stream);
         }
     }
 }
Beispiel #2
0
 internal static void TryAddFile(IProjectSystem project, string path, Func <Stream> content)
 {
     if (!project.FileExists(path) || !project.FileExistsInProject(path))
     {
         using (Stream stream2 = content())
         {
             project.AddFile(path, stream2);
         }
     }
     else
     {
         object[] args    = new object[] { path, project.ProjectName };
         string   message = string.Format(CultureInfo.CurrentCulture, NuGetResources.FileConflictMessage, args);
         FileConflictResolution resolution = project.Logger.ResolveFileConflict(message);
         if ((resolution != FileConflictResolution.Overwrite) && (resolution != FileConflictResolution.OverwriteAll))
         {
             object[] objArray3 = new object[] { path };
             project.Logger.Log(MessageLevel.Info, NuGetResources.Warning_FileAlreadyExists, objArray3);
         }
         else
         {
             object[] objArray2 = new object[] { path };
             project.Logger.Log(MessageLevel.Info, NuGetResources.Info_OverwriteExistingFile, objArray2);
             using (Stream stream = content())
             {
                 project.AddFile(path, stream);
             }
         }
     }
 }