From 8b635bd82eb81aeca74676c6713d43c1dd5b2b87 Mon Sep 17 00:00:00 2001 From: PeterForstmeier Date: Sat, 9 Jun 2012 11:48:52 +0200 Subject: [PATCH] Signing.xaml --- .../Project/ICSharpCode.SharpDevelop.csproj | 5 - .../ApplicationSettings.xaml.cs | 27 ++- .../ProjectOptions/BuildEvents.cs | 2 +- .../ProjectOptions/CreateKey.xaml | 92 ---------- .../ProjectOptions/CreateKey.xaml.cs | 170 ------------------ .../ProjectOptions/DebugOptions.xaml.cs | 2 +- .../ProjectOptions/ProjectOptionPanel.cs | 4 + .../OptionPanels/ProjectOptions/Signing.xaml | 44 +++-- .../ProjectOptions/Signing.xaml.cs | 96 +++++++--- 9 files changed, 108 insertions(+), 334 deletions(-) delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml delete mode 100644 src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml.cs diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index ce998841ac..2ddc222145 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -274,10 +274,6 @@ ApplicationSettings.xaml Code - - CreateKey.xaml - Code - DebugOptions.xaml Code @@ -899,7 +895,6 @@ - ProjectOptionPanel.cs diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs index b65f87ab3e..cd361f3aec 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.xaml.cs @@ -30,7 +30,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels private const string iconsfilter = "${res:SharpDevelop.FileFilter.Icons}|*.ico|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; private const string manifestFilter = "${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.ManifestFiles}|*.manifest|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; private const string win32filter = "Win32 Resource files|*.res|${res:SharpDevelop.FileFilter.AllFiles}|*.*"; - MSBuildBasedProject project; +// MSBuildBasedProject project; public ApplicationSettings() { @@ -41,7 +41,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels private void Initialize() { - foreach (IClass c in GetPossibleStartupObjects(project)) { + foreach (IClass c in GetPossibleStartupObjects(base.Project)) { startupObjectComboBox.Items.Add(c.FullyQualifiedName); } @@ -53,10 +53,10 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels project_MinimumSolutionVersionChanged(null, null); // re-evaluate if the project has the minimum version whenever this options page gets visible // because the "convert project" button on the compiling tab page might have updated the MSBuild version. - project.MinimumSolutionVersionChanged += project_MinimumSolutionVersionChanged; + base.Project.MinimumSolutionVersionChanged += project_MinimumSolutionVersionChanged; - projectFolderTextBox.Text = project.Directory; - projectFileTextBox.Text = Path.GetFileName(project.FileName); + projectFolderTextBox.Text = base.BaseDirectory; + projectFileTextBox.Text = Path.GetFileName(base.Project.FileName); //OptionBinding RefreshStartupObjectEnabled(this, EventArgs.Empty); @@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels { applicationManifestComboBox.Items.Add(StringParser.Parse("${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.EmbedDefault}")); applicationManifestComboBox.Items.Add(StringParser.Parse("${res:Dialog.ProjectOptions.ApplicationSettings.Manifest.DoNotEmbedManifest}")); - foreach (string fileName in Directory.GetFiles(project.Directory, "*.manifest")) { + foreach (string fileName in Directory.GetFiles(base.BaseDirectory, "*.manifest")) { applicationManifestComboBox.Items.Add(Path.GetFileName(fileName)); } applicationManifestComboBox.Items.Add(StringParser.Parse("<${res:Global.CreateButtonText}...>")); @@ -116,7 +116,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels protected override void Load(MSBuildBasedProject project, string configuration, string platform) { base.Load(project, configuration, platform); - this.project = project; Initialize(); } @@ -148,7 +147,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels void project_MinimumSolutionVersionChanged(object sender, EventArgs e) { // embedding manifests requires the project to target MSBuild 3.5 or higher - applicationManifestComboBox.IsEnabled = project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008; + applicationManifestComboBox.IsEnabled = base.Project.MinimumSolutionVersion >= Solution.SolutionVersionVS2008; } #region refresh Outputpath + StartupOptions @@ -196,10 +195,10 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels void ApplicationIconTextBox_TextChanged(object sender, TextChangedEventArgs e) { - if (project != null) { + if (base.Project != null) { if(FileUtility.IsValidPath(this.applicationIconTextBox.Text)) { - string appIconPath = Path.Combine(project.Directory, this.applicationIconTextBox.Text); + string appIconPath = Path.Combine(base.BaseDirectory, this.applicationIconTextBox.Text); Console.WriteLine(appIconPath); var b = File.Exists(appIconPath); if (File.Exists(appIconPath)) { @@ -257,7 +256,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels void CreateManifest() { - string manifestFile = Path.Combine(project.Directory, "app.manifest"); + string manifestFile = Path.Combine(base.BaseDirectory, "app.manifest"); if (!File.Exists(manifestFile)) { string defaultManifest; using (Stream stream = typeof(ApplicationSettings).Assembly.GetManifestResourceStream("Resources.DefaultManifest.manifest")) { @@ -272,10 +271,10 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels FileService.FireFileCreated(manifestFile, false); } - if (!project.IsFileInProject(manifestFile)) { - FileProjectItem newItem = new FileProjectItem(project, ItemType.None); + if (!base.Project.IsFileInProject(manifestFile)) { + FileProjectItem newItem = new FileProjectItem(base.Project, ItemType.None); newItem.Include = "app.manifest"; - ProjectService.AddProjectItem(project, newItem); + ProjectService.AddProjectItem(base.Project, newItem); ProjectBrowserPad.RefreshViewAsync(); } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs index 040a734128..5dc3043a45 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs @@ -24,7 +24,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels } public ProjectProperty RunPostBuildEvent { - get { return GetProperty("RunPostBuildEvent", Project.RunPostBuildEvent.OnBuildSuccess); } + get { return GetProperty("RunPostBuildEvent", SharpDevelop.Project.RunPostBuildEvent.OnBuildSuccess); } } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml deleted file mode 100644 index 9bbded2c53..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml +++ /dev/null @@ -1,92 +0,0 @@ - - - - 25 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml.cs deleted file mode 100644 index 0df6a93d27..0000000000 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKey.xaml.cs +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Created by SharpDevelop. - * User: Peter Forstmeier - * Date: 01.06.2012 - * Time: 20:20 - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; - -using ICSharpCode.Core; - -namespace ICSharpCode.SharpDevelop.Gui.OptionPanels -{ - /// - /// Interaction logic for CreateKeyXaml.xaml - /// - public partial class CreateKey : Window,INotifyPropertyChanged - { - - private bool checkBoxChecked; - private string keyFile; - private string baseDirectory; - - public CreateKey() - { - InitializeComponent(); - DataContext = this; - } - - public CreateKey (string baseDirectory):this() - { - this.baseDirectory = baseDirectory; - } - - - public bool CheckBoxChecked { - get { return checkBoxChecked; } - set { checkBoxChecked = value; - OnPropertyChange("CheckBoxChecked"); - } - } - - - public string KeyFile { - get { return keyFile; } - set { keyFile = value; - OnPropertyChange("KeyFile"); } - } - - /// - /// Gets the path of the "strong named" executable. This is used to create keys for strongly signing - /// .NET assemblies. - /// - public static string StrongNameTool { - get { - return FileUtility.GetSdkPath("sn.exe"); - } - } - - - public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; - - private void OnPropertyChange (string propertyName) - { - if (PropertyChanged != null) { - PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); - } - } - - void okButtonClick(object sender, RoutedEventArgs e) - { - KeyFile = KeyFile.Trim(); - if (KeyFile.Length == 0) { - MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.EnterKeyName}"); - return; - } - - if (CheckBoxChecked) { - if (!CheckPassword(this.passwordTextBox.Text.Trim(),this.confirmPasswordTextBox.Text.Trim())) - { - return; - } - MessageService.ShowMessage("Creating a key file with a password is currently not supported."); - return; - } - if (!KeyFile.EndsWith(".snk") && !KeyFile.EndsWith(".pfx")) - KeyFile += ".snk"; - if (CreateKeyInternal(Path.Combine(baseDirectory, KeyFile))) { - this.DialogResult = true; - Close(); - } - } - - /// - /// Creates a key with the sn.exe utility. - /// - /// The path of the key to create. - /// True if the key was created correctly. - private static bool CreateKeyInternal(string keyPath) - { - if (File.Exists(keyPath)) { - string question = "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}"; - question = StringParser.Parse(question, new StringTagPair("fileNames", keyPath)); - if (!MessageService.AskQuestion(question, "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}")) { - return false; - } - } - Process p = Process.Start(StrongNameTool, "-k \"" + keyPath + "\""); - p.WaitForExit(); - if (p.ExitCode != 0) { - MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.ErrorCreatingKey}"); - return false; - } - return true; - } - - - public static bool CheckPassword(string password, string confirm) - { - -// if (password.Text.Length < 6) { -// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordTooShort}"); -// password.Focus(); -// return false; -// } -// if (password.Text != confirm.Text) { -// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordsDontMatch}"); -// return false; -// } - return true; - } - - -// private static bool CheckPassword(Control password, Control confirm) -// { -// password.Text = password.Text.Trim(); -// confirm.Text = confirm.Text.Trim(); -// if (password.Text.Length < 6) { -// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordTooShort}"); -// password.Focus(); -// return false; -// } -// if (password.Text != confirm.Text) { -// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordsDontMatch}"); -// return false; -// } -// return true; -// } - - - void cancelButtonClick(object sender, RoutedEventArgs e) - { - this.DialogResult = false; - Close(); - } - - - } -} \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.xaml.cs index bd69f6e44c..c12e19ec4d 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.xaml.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels { get { - return GetProperty("StartAction", Project.StartAction.Project, PropertyStorageLocations.ConfigurationSpecific); + return GetProperty("StartAction", SharpDevelop.Project.StartAction.Project, PropertyStorageLocations.ConfigurationSpecific); } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ProjectOptionPanel.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ProjectOptionPanel.cs index 8bcd78ea59..0d5227aae8 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ProjectOptionPanel.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ProjectOptionPanel.cs @@ -180,6 +180,10 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels } } + public MSBuildBasedProject Project { + get { return project; } + } + public string BaseDirectory { get { return project.Directory; } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml index 03a7c80d90..f219560a1b 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml @@ -17,55 +17,51 @@ Header="{core:Localize Dialog.ProjectOptions.Signing.StrongName}"> - - - - - + + + + + - - - + + + - + + + + + + @@ -85,8 +82,7 @@ - + \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml.cs index 194605743e..acefa7dd11 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.xaml.cs @@ -7,17 +7,17 @@ */ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using System.IO; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; - using System.Windows.Input; using System.Windows.Media; - using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Widgets; @@ -30,9 +30,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels public partial class Signing : ProjectOptionPanel { private const string KeyFileExtensions = "*.snk;*.pfx;*.key"; - private List keyFile = new List(); - private MSBuildBasedProject project; - + private string selectedKey; + private ObservableCollection keyFile = new ObservableCollection(); public Signing() { @@ -43,15 +42,16 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels private void Initialize() { FindKeys(base.BaseDirectory); - SelectedKey = AssemblyOriginatorKeyFile.Value; - if (SelectedKey != null) { + SelectedKey = AssemblyOriginatorKeyFile.Value.Trim(); + if (SelectedKey.Length > 0) { if (!KeyFile.Contains(SelectedKey)) { keyFile.Add(SelectedKey); } } - keyFile.Add(StringParser.Parse("<${res:Global.CreateButtonText}...>")); keyFile.Add(StringParser.Parse("<${res:Global.BrowseText}...>")); + keyFileComboBox.SelectedIndex = 0; + keyFileComboBox.SelectionChanged += KeyFileComboBox_SelectionChanged; } public ProjectProperty SignAssembly { @@ -78,7 +78,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels protected override void Load(MSBuildBasedProject project, string configuration, string platform) { base.Load(project, configuration, platform); - this.project = project; Initialize(); } @@ -87,14 +86,15 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels if (signAssemblyCheckBox.IsChecked == true) { this.AssemblyOriginatorKeyFile.Value = "File"; } + keyFileComboBox.SelectionChanged -= KeyFileComboBox_SelectionChanged; return base.Save(project, configuration, platform); } #endregion - #region keyFile + #region KeyFile - public List KeyFile { + public ObservableCollection KeyFile { get { return keyFile; } set { keyFile = value; @@ -102,17 +102,20 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels } } - public string SelectedKey {get;set;} + + public string SelectedKey { + get { return selectedKey; } + set { selectedKey = value; + base.RaisePropertyChanged(() => SelectedKey); + } + } + void FindKeys(string directory) { directory = FileUtility.NormalizePath(directory); while (true) { try { -// var files = from file in new DirectoryInfo(@"C:\").GetFiles() -// where file..Name.StartsWith("_") -// select file; - foreach (string fileName in Directory.GetFiles(directory, "*.snk")) { keyFile.Add(MSBuildInternals.Escape(FileUtility.GetRelativePath(base.BaseDirectory, fileName))); } @@ -157,21 +160,60 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels private void CreateKeyFile() { - if (File.Exists(CreateKey.StrongNameTool)) { - CreateKey createKey = new CreateKey(base.BaseDirectory); - createKey.KeyFile = project.Name; - createKey.ShowDialog(); - if (createKey.DialogResult.HasValue && createKey.DialogResult.Value) - { - SelectedKey = MSBuildInternals.Escape(createKey.KeyFile); - } else{ - SelectedKey = String.Empty; + if (File.Exists(StrongNameTool)) { + string title = StringParser.Parse("${res:Dialog.ProjectOptions.Signing.CreateKey.Title}"); + string str = StringParser.Parse("${res:Dialog.ProjectOptions.Signing.CreateKey.KeyName}"); + var keyName = str.Remove(str.IndexOf("&"),1); + + string key = MessageService.ShowInputBox(title,keyName,base.Project.Name); + if(!String.IsNullOrEmpty(key)) { + if (CreateKey(key.Trim())) { + this.keyFileComboBox.SelectionChanged -= KeyFileComboBox_SelectionChanged; + var generated = MSBuildInternals.Escape(key); + KeyFile.Add(generated); + SelectedKey = generated; + this.keyFileComboBox.SelectionChanged += KeyFileComboBox_SelectionChanged; + } + } else { + MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.SNnotFound}"); } - } else { - MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.SNnotFound}"); } } #endregion + + /// + /// Gets the path of the "strong named" executable. This is used to create keys for strongly signing + /// .NET assemblies. + /// + private static string StrongNameTool { + get { + return FileUtility.GetSdkPath("sn.exe"); + } + } + + + /// + /// Creates a key with the sn.exe utility. + /// + /// The path of the key to create. + /// True if the key was created correctly. + private static bool CreateKey(string keyPath) + { + if (File.Exists(keyPath)) { + string question = "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}"; + question = StringParser.Parse(question, new StringTagPair("fileNames", keyPath)); + if (!MessageService.AskQuestion(question, "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}")) { + return false; + } + } + Process p = Process.Start(StrongNameTool, "-k \"" + keyPath + "\""); + p.WaitForExit(); + if (p.ExitCode != 0) { + MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.ErrorCreatingKey}"); + return false; + } + return true; + } } } \ No newline at end of file