6 changed files with 326 additions and 32 deletions
@ -0,0 +1,47 @@
@@ -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; } |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
<optionPanels:ProjectOptionPanel |
||||
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.AssemblyInfoPanel" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:optionPanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels" |
||||
mc:Ignorable="d"> |
||||
<ScrollViewer VerticalScrollBarVisibility="Auto"> |
||||
<Grid> |
||||
<Grid.Resources> |
||||
<Style TargetType="{x:Type Label}"> |
||||
<Setter Property="VerticalAlignment" Value="Center"/> |
||||
</Style> |
||||
<Style TargetType="{x:Type TextBox}"> |
||||
<Setter Property="Height" Value="20"/> |
||||
<Setter Property="Margin" Value="4"/> |
||||
<Setter Property="VerticalAlignment" Value="Center"/> |
||||
<EventSetter Event="TextChanged" Handler="OnPanelOptionsChanged"/> |
||||
</Style> |
||||
<Style TargetType="{x:Type CheckBox}"> |
||||
<Setter Property="Margin" Value="4"/> |
||||
<Setter Property="VerticalAlignment" Value="Center"/> |
||||
<EventSetter Event="Checked" Handler="OnPanelOptionsChanged"/> |
||||
<EventSetter Event="Unchecked" Handler="OnPanelOptionsChanged"/> |
||||
</Style> |
||||
</Grid.Resources> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition/> |
||||
</Grid.ColumnDefinitions> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
<RowDefinition Height="Auto"/> |
||||
</Grid.RowDefinitions> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Title}" Grid.Column="0" Grid.Row="0"/> |
||||
<TextBox Text="{Binding Title}" Grid.Column="1" Grid.Row="0"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Description}" Grid.Column="0" Grid.Row="1"/> |
||||
<TextBox Text="{Binding Description}" Grid.Column="1" Grid.Row="1"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Company}" Grid.Column="0" Grid.Row="2"/> |
||||
<TextBox Text="{Binding Company}" Grid.Column="1" Grid.Row="2"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Product}" Grid.Column="0" Grid.Row="3"/> |
||||
<TextBox Text="{Binding Product}" Grid.Column="1" Grid.Row="3"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Copyright}" Grid.Column="0" Grid.Row="4"/> |
||||
<TextBox Text="{Binding Copyright}" Grid.Column="1" Grid.Row="4"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Trademark}" Grid.Column="0" Grid.Row="5"/> |
||||
<TextBox Text="{Binding Trademark}" Grid.Column="1" Grid.Row="5"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.AssemblyVersion}" Grid.Column="0" Grid.Row="6"/> |
||||
<TextBox Text="{Binding AssemblyVersion}" Grid.Column="1" Grid.Row="6"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.FileVersion}" Grid.Column="0" Grid.Row="7"/> |
||||
<TextBox Text="{Binding FileVersion}" Grid.Column="1" Grid.Row="7"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.GUID}" Grid.Column="0" Grid.Row="8"/> |
||||
<TextBox Text="{Binding Guid}" Grid.Column="1" Grid.Row="8"/> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.NeutralLanguage}" Grid.Column="0" Grid.Row="9"/> |
||||
<TextBox Text="{Binding NeutralLanguage}" Grid.Column="1" Grid.Row="9"/> |
||||
<CheckBox Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.MakeAssemblyCOMVisible}" IsChecked="{Binding ComVisible}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="10"/> |
||||
</Grid> |
||||
</ScrollViewer> |
||||
</optionPanels:ProjectOptionPanel> |
@ -0,0 +1,201 @@
@@ -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<AttributeSection>()) |
||||
{ |
||||
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<PrimitiveExpression>().ToArray(); |
||||
if (attributeArguments.Length == 1) |
||||
return attributeArguments[0].Value as string; |
||||
|
||||
return string.Empty; |
||||
} |
||||
|
||||
private bool GetAttributeValueAsBool(Attribute attribute) |
||||
{ |
||||
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray(); |
||||
if (attributeArguments.Length == 1) |
||||
return (bool)attributeArguments[0].Value; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private Guid GetAttributeValueAsGuid(Attribute attribute) |
||||
{ |
||||
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().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<PrimitiveExpression>().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<AttributeSection>().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<AttributeSection>("Member")); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,29 +0,0 @@
@@ -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 |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for AssemblyInfo.xaml
|
||||
/// </summary>
|
||||
public partial class AssemblyInfoPanel : ProjectOptionPanel |
||||
{ |
||||
public AssemblyInfoPanel() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue