diff --git a/Wizard/DxpIsolatedEnv.cs b/Wizard/DxpIsolatedEnv.cs new file mode 100644 index 0000000..c593637 --- /dev/null +++ b/Wizard/DxpIsolatedEnv.cs @@ -0,0 +1,62 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2017 Denis Kuzmin < entry.reg@gmail.com > :: github.com/3F + * + * 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.Collections.Generic; +using net.r_eg.MvsSln.Core; +using net.r_eg.MvsSln.Log; + +namespace net.r_eg.DllExport.Wizard +{ + /// + /// https://github.com/3F/DllExport/issues/56 + /// TODO: MvsSln core + /// + public class DxpIsolatedEnv: IsolatedEnv, IEnvironment + { + public const string ERR_MSG = "DXPInternalErrorMsg"; + + public DxpIsolatedEnv(ISlnResult data) + : base(data) + { + + } + + protected override Microsoft.Build.Evaluation.Project Load(string path, IDictionary properties) + { + try + { + return base.Load(path, properties); + } + catch(Exception ex) + { + LSender._.send(this, $"MBE. Found problem when new Project('{path}'): '{ex.Message}'", Message.Level.Debug); + + var prj = new Microsoft.Build.Evaluation.Project(); + prj.SetProperty(ERR_MSG, ex.Message); + return prj; + } + } + } +} diff --git a/Wizard/Executor.cs b/Wizard/Executor.cs index 6fa1712..8fc1cd6 100644 --- a/Wizard/Executor.cs +++ b/Wizard/Executor.cs @@ -37,7 +37,7 @@ namespace net.r_eg.DllExport.Wizard { public class Executor: IExecutor, IConfigInitializer, IDisposable { - protected Dictionary solutions = new Dictionary(); + protected Dictionary solutions = new Dictionary(); /// /// Cache for loaded projects. @@ -163,7 +163,7 @@ public bool UpdateCfgStorageType(string sln) return false; } - if(UniqueProjectsBy(sln).Any(p => p.HasExternalStorage)) { + if(UniqueProjectsBy(sln)?.Any(p => p.HasExternalStorage) == true) { Config.CfgStorage = CfgStorageType.TargetsFile; return true; } @@ -206,15 +206,22 @@ protected IEnvironment GetEnv(string file) return null; } - if(!solutions.ContainsKey(file)) { - solutions[file] = new Sln(file, SlnItems.EnvWithMinimalProjects); + if(!solutions.ContainsKey(file)) + { + var sln = new Sln(file, SlnItems.Projects + | SlnItems.SolutionConfPlatforms + | SlnItems.ProjectConfPlatforms); + + solutions[file] = new DxpIsolatedEnv(sln.Result); + solutions[file].LoadMinimalProjects(); } - return solutions[file].Result.Env; + + return solutions[file]; } private void Free() { - solutions?.ForEach(sln => sln.Value.Result?.Env?.Dispose()); + solutions?.ForEach(sln => sln.Value?.Dispose()); if(_targetsFile != null) { _targetsFile.Dispose(); diff --git a/Wizard/IProject.cs b/Wizard/IProject.cs index 2c58c96..ce1c0b3 100644 --- a/Wizard/IProject.cs +++ b/Wizard/IProject.cs @@ -39,6 +39,12 @@ public interface IProject /// bool Installed { get; } + /// + /// Message if an internal error occurred, otherwise null value. + /// TODO: because of DxpIsolatedEnv. See details there. + /// + string InternalError { get; } + /// /// Special identifier. Like `ProjectGuid` that is not available in SDK-based projects. /// https://github.com/3F/DllExport/issues/36#issuecomment-320794498 diff --git a/Wizard/Project.cs b/Wizard/Project.cs index 13c5b47..038da09 100644 --- a/Wizard/Project.cs +++ b/Wizard/Project.cs @@ -65,7 +65,16 @@ public IXProject XProject /// public bool Installed { - get => !String.IsNullOrWhiteSpace(GetProperty(MSBuildProperties.DXP_ID)); + get => InternalError == null && !String.IsNullOrWhiteSpace(GetProperty(MSBuildProperties.DXP_ID)); + } + + /// + /// Message if an internal error occurred, otherwise null value. + /// TODO: because of DxpIsolatedEnv. See details there. + /// + public string InternalError + { + get => XProject?.GetProperty(DxpIsolatedEnv.ERR_MSG, true).evaluatedValue; } /// @@ -306,7 +315,9 @@ protected IUserConfig GetUserConfig(IXProject project, IConfigInitializer cfg) /// protected void Save() { - XProject?.Save(); + if(XProject?.ProjectFullPath != null && InternalError == null) { + XProject.Save(); + } } protected void CfgDDNS() diff --git a/Wizard/UI/ConfiguratorForm.cs b/Wizard/UI/ConfiguratorForm.cs index d0d2628..7bd0242 100644 --- a/Wizard/UI/ConfiguratorForm.cs +++ b/Wizard/UI/ConfiguratorForm.cs @@ -158,13 +158,8 @@ private void RenderProjects(string sln) toolTipMain.SetToolTip(comboBoxSln, sln); - var projects = exec.UniqueProjectsBy(sln); - if(projects != null) - { - foreach(var project in projects) { - projectItems.Add(project); - } - } + exec.UniqueProjectsBy(sln)? + .ForEach(prj => projectItems.Add(prj)); } private void DoSilentAction(Action act, ComboBox box, EventHandler handler) diff --git a/Wizard/UI/Controls/ProjectItemControl.cs b/Wizard/UI/Controls/ProjectItemControl.cs index 633aa07..8423882 100644 --- a/Wizard/UI/Controls/ProjectItemControl.cs +++ b/Wizard/UI/Controls/ProjectItemControl.cs @@ -24,6 +24,7 @@ using System; using System.ComponentModel; +using System.IO; using System.Windows.Forms; using RGiesecke.DllExport; @@ -32,7 +33,12 @@ namespace net.r_eg.DllExport.Wizard.UI.Controls internal sealed partial class ProjectItemControl: UserControl { private readonly int EX_HEIGHT; - private IProject project; + + public IProject Project + { + get; + private set; + } public bool Installed { @@ -159,9 +165,21 @@ public void SetNamespace(string name, bool addIfNotExists = true) Namespaces.Text = name; } + public bool LockIfError(string msg) + { + if(msg == null) { + return false; + } + + chkInstalled.Enabled = false; + textBoxIdent.Text = "Project cannot be loaded:"; + textBoxProjectPath.Text = msg; + return true; + } + public ProjectItemControl(IProject project) { - this.project = project; + Project = project ?? throw new ArgumentNullException(nameof(project)); InitializeComponent(); EX_HEIGHT = Height; @@ -244,9 +262,9 @@ private void InstalledStatus(bool status) private void btnBrowse_Click(object sender, EventArgs e) { - var path = project?.XProject?.ProjectPath; + var path = Project.XProject?.ProjectItem.project.fullPath; if(!String.IsNullOrWhiteSpace(path)) { - Browse?.Invoke(path); + Browse?.Invoke(Path.GetDirectoryName(path)); } } diff --git a/Wizard/UI/Controls/ProjectItemsControl.cs b/Wizard/UI/Controls/ProjectItemsControl.cs index b9c7202..a3191e4 100644 --- a/Wizard/UI/Controls/ProjectItemsControl.cs +++ b/Wizard/UI/Controls/ProjectItemsControl.cs @@ -153,17 +153,21 @@ private void ConfigureControl(ProjectItemControl control, IProject project) control.Platform = project.Config.Platform; control.Compiler = project.Config.Compiler; - control.Browse = Browse; - control.NamespaceValidate = NamespaceValidate; - control.OpenUrl = OpenUrl; + control.Browse = Browse; + control.OpenUrl = OpenUrl; + + if(control.LockIfError(project.InternalError)) { + return; + } + + control.NamespaceValidate = NamespaceValidate; control.Namespaces.Items.Clear(); control.Namespaces.Items.AddRange(project.Config.Namespaces.ToArray()); control.Namespaces.SelectedIndex = 0; - control.Namespaces.MaxLength = project.Config.NSBuffer; - if(project.Installed) { + if(control.Installed) { control.SetNamespace(project.Config.Namespace, true); } } diff --git a/Wizard/Wizard.csproj b/Wizard/Wizard.csproj index e7bce48..92aa41e 100644 --- a/Wizard/Wizard.csproj +++ b/Wizard/Wizard.csproj @@ -67,6 +67,7 @@ +