diff --git a/data/resources/StringResources.resx b/data/resources/StringResources.resx index 0118577bbd..d2bb892474 100644 --- a/data/resources/StringResources.resx +++ b/data/resources/StringResources.resx @@ -8404,7 +8404,7 @@ Press Esc to cancel this operation. Neutral language: - + Product: diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index ee51fe8c08..f44a40fcf2 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -303,9 +303,11 @@ OutputWindowOptionsPanel.xaml Code - + + AssemblyInfoPanel.xaml + TaskViewResources.xaml @@ -914,7 +916,7 @@ - + Designer MSBuild:Compile @@ -947,6 +949,10 @@ ICSharpCode.NRefactory.Cecil False + + {53dca265-3c3c-42f9-b647-f72ba678122b} + ICSharpCode.NRefactory.CSharp + {DC393B66-92ED-4CAD-AB25-CFEF23F3D7C6} ICSharpCode.NRefactory.Xml diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs new file mode 100644 index 0000000000..fb4759f036 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs @@ -0,0 +1,47 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.SharpDevelop.Gui.OptionPanels +{ + public class AssemblyInfo + { + public string Title { get; set; } + + public string Description { get; set; } + + public string Company { get; set; } + + public string Product { get; set; } + + public string Copyright { get; set; } + + public string Trademark { get; set; } + + public Version AssemblyVersion { get; set; } + + public Version FileVersion { get; set; } + + public Guid Guid { get; set; } + + public string NeutralLanguage { get; set; } + + public bool ComVisible { get; set; } + } +} \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml new file mode 100644 index 0000000000..66cafdf222 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs new file mode 100644 index 0000000000..ebbcab3392 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs @@ -0,0 +1,201 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.IO; +using System.Linq; +using ICSharpCode.NRefactory.CSharp; +using Mono.CSharp; +using Attribute = ICSharpCode.NRefactory.CSharp.Attribute; +using CSharpParser = ICSharpCode.NRefactory.CSharp.CSharpParser; + +namespace ICSharpCode.SharpDevelop.Gui.OptionPanels +{ + public class AssemblyInfoProvider + { + public AssemblyInfo Read(string fileName) + { + var syntaxTree = ReadSyntaxTree(fileName); + + if (syntaxTree == null) + throw new Exception("Can't read assembly info syntax tree."); + + var assemblyInfo = new AssemblyInfo(); + + foreach (var attributeSection in syntaxTree.Children.OfType()) + { + foreach (var attribute in attributeSection.Attributes) + { + var attributeType = attribute.Type as SimpleType; + if (attributeType == null) + continue; + + switch (attributeType.Identifier) + { + case "AssemblyTitle": + assemblyInfo.Title = GetAttributeValueAsString(attribute); + break; + case "AssemblyDescription": + assemblyInfo.Description = GetAttributeValueAsString(attribute); + break; + case "AssemblyConfigurtation": + break; + case "AssemblyCompany": + assemblyInfo.Company = GetAttributeValueAsString(attribute); + break; + case "AssemblyProduct": + assemblyInfo.Product = GetAttributeValueAsString(attribute); + break; + case "AssemblyCopyright": + assemblyInfo.Copyright = GetAttributeValueAsString(attribute); + break; + case "AssemblyTrademark": + assemblyInfo.Trademark = GetAttributeValueAsString(attribute); + break; + case "AssemblyCulture": + break; + case "ComVisible": + assemblyInfo.ComVisible = GetAttributeValueAsBool(attribute); + break; + case "Guid": + assemblyInfo.Guid = GetAttributeValueAsGuid(attribute); + break; + case "AssemblyVersion": + assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute); + break; + case "AssemblyFileVersion": + assemblyInfo.FileVersion = GetAttributeValueAsVersion(attribute); + break; + case "NeutralResourcesLanguageAttribute": + assemblyInfo.NeutralLanguage = GetAttributeValueAsString(attribute); + break; + } + } + } + + return assemblyInfo; + } + + public void Write(string fileName, AssemblyInfo assemblyInfo) + { + var syntaxTree = ReadSyntaxTree(fileName); + + if (syntaxTree == null) + throw new Exception("Can't read assembly info syntax tree."); + + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyTitle", assemblyInfo.Title); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyDescription", assemblyInfo.Description); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyCompany", assemblyInfo.Company); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyProduct", assemblyInfo.Product); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyCopyright", assemblyInfo.Copyright); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyTrademark", assemblyInfo.Trademark); + SetAttributeValueOrAddAttribute(syntaxTree, "ComVisible", assemblyInfo.ComVisible); + SetAttributeValueOrAddAttribute(syntaxTree, "Guid", assemblyInfo.Guid.ToString()); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyVersion", assemblyInfo.AssemblyVersion.ToString()); + SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyFileVersion", assemblyInfo.FileVersion.ToString()); + SetAttributeValueOrAddAttribute(syntaxTree, "NeutralResourcesLanguageAttribute", assemblyInfo.NeutralLanguage); + + WriteSyntaxTree(syntaxTree, fileName); + } + + private SyntaxTree ReadSyntaxTree(string fileName) + { + using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) + { + using (var streamReader = new StreamReader(fileStream)) + { + var codeParser = new CSharpParser(); + + return codeParser.Parse(streamReader); + } + } + } + + private void WriteSyntaxTree(SyntaxTree syntaxTree, string fileName) + { + File.WriteAllText(fileName, syntaxTree.ToString()); + } + + private string GetAttributeValueAsString(Attribute attribute) + { + var attributeArguments = attribute.Arguments.OfType().ToArray(); + if (attributeArguments.Length == 1) + return attributeArguments[0].Value as string; + + return string.Empty; + } + + private bool GetAttributeValueAsBool(Attribute attribute) + { + var attributeArguments = attribute.Arguments.OfType().ToArray(); + if (attributeArguments.Length == 1) + return (bool)attributeArguments[0].Value; + + return false; + } + + private Guid GetAttributeValueAsGuid(Attribute attribute) + { + var attributeArguments = attribute.Arguments.OfType().ToArray(); + if (attributeArguments.Length == 1) + return Guid.Parse(attributeArguments[0].Value as string); + + return Guid.Empty; + } + + private Version GetAttributeValueAsVersion(Attribute attribute) + { + var attributeArguments = attribute.Arguments.OfType().ToArray(); + if (attributeArguments.Length == 1) + { + var versionString = attributeArguments[0].Value as string; + var versionParts = versionString.Split('.'); + if (versionParts.Length == 4) + { + return new Version( + int.Parse(versionParts[0]), + int.Parse(versionParts[1]), + int.Parse(versionParts[2]), + int.Parse(versionParts[3])); + } + } + + return null; + } + + private void SetAttributeValueOrAddAttribute(SyntaxTree syntaxTree, string attributeName, object value) + { + var attribute = syntaxTree.Children.OfType().SelectMany(x => x.Attributes) + .FirstOrDefault(x => x.Type is SimpleType && ((SimpleType)x.Type).Identifier == attributeName); + + if (attribute != null) + { + attribute.Arguments.Clear(); + attribute.Arguments.Add(new PrimitiveExpression(value)); + } + else + { + attribute = new Attribute() { Type = new SimpleType(attributeName) }; + attribute.Arguments.Add(new PrimitiveExpression(value)); + + var attributeSection = new AttributeSection(attribute) { AttributeTarget = "assembly" }; + syntaxTree.AddChild(attributeSection, new NRefactory.Role("Member")); + } + } + } +} \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfoPanel.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfoPanel.xaml.cs deleted file mode 100644 index 9a14db257d..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfoPanel.xaml.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using ICSharpCode.SharpDevelop.Gui.OptionPanels; - -namespace ICSharpCode.SharpDevelop.Gui.OptionPanels -{ - /// - /// Interaction logic for AssemblyInfo.xaml - /// - public partial class AssemblyInfoPanel : ProjectOptionPanel - { - public AssemblyInfoPanel() - { - InitializeComponent(); - } - } -}