Skip to content

Commit

Permalink
Added information about obsolete nuget clients via \build features -
Browse files Browse the repository at this point in the history
…#38

    We'll support only information about new installer because:
    * The `\build` feature still does not guarantee of work for all cases. #36 (comment)
    * We don't have any guaranteed information about uninstall operation for our package because of removed	uninstall.ps1
      #38
  • Loading branch information
3F committed Jul 31, 2017
1 parent 99bc9be commit 5f4dd18
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 298 deletions.
7 changes: 5 additions & 2 deletions .vssbe
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
"Mode": {
"$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
"Type": "Script",
"Command": "#[IO copy.file(\n \"$(SolutionDir)tools/*.*\", \n \"$(odir)/tools/\", \n true, \n {\"*.nuspec\"})]\n\n#[IO copy.file(\"tools/DllExport.nuspec\", \"$(odir)/DllExport.nuspec\", true)]\n\n#[IO copy.file({\n \"$(pDllExport)/$(OutDir:$(pDllExport))/*.*\",\n \"$(pMSBuild)/$(OutDir:$(pMSBuild))/*.*\",\n \"$(pNSBin)/$(OutDir:$(pNSBin))/*.*\",\n \"$(pWizard)/$(OutDir:$(pWizard))/*.*\",\n \"$(pConf)/$(OutDir:$(pConf))/*.*\"\n }, \n \"$(odir)/tools/\", true)]\n\n \n#[IO copy.file(\"$(pMeta)/$(OutDir:$(pMeta))/*.dll\", \n \"$(odir)/lib/net20/\", true)]\n\n#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]\n#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]\n\n#[var buildInfo = $([System.String]::Concat(\" \"))\n S_NUM: #[$(pVer)]\n \n S_REV: #[$(revBuild)]\n \n S_NUM_REV: #[$(pVer)].#[$(revBuild)]\n \n bSha1: #[$(bSha1)]\n \n bName: #[$(bName)]\n \n bRevc: #[$(bRevc)]\n \n Metadata .NET: #[$(TargetFrameworkVersion:$(pMeta))]\n \n Wizard .NET: #[$(TargetFrameworkVersion:$(pWizard))]\n \n Configurator .NET: #[$(TargetFrameworkVersion:$(pConf))]\n \n Configuration: #[$(Configuration)]\n \n Platform: #[$(Platform)]\n \n cfgname: #[$(cfgname)]\n \n revDeltaBase: #[$(revDeltaBase)]\n \n revDeltaMin: #[$(revDeltaMin)]\n \n revDeltaMax: #[$(revDeltaMax)]\n \n \n :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]\n]\n\n#[IO writeLine(\"$(odir)/build_info.txt\"):#[var buildInfo]]",
"Command": "#[IO copy.file(\n \"$(SolutionDir)tools/*.*\", \n \"$(odir)/tools/\", \n true, \n {\"*.nuspec\"})]\n\n#[IO copy.file(\"tools/DllExport.nuspec\", \"$(odir)/DllExport.nuspec\", true)]\n\n#[IO copy.file({\n \"$(pDllExport)/$(OutDir:$(pDllExport))/*.*\",\n \"$(pMSBuild)/$(OutDir:$(pMSBuild))/*.*\",\n \"$(pNSBin)/$(OutDir:$(pNSBin))/*.*\",\n \"$(pWizard)/$(OutDir:$(pWizard))/*.*\",\n \"$(pConf)/$(OutDir:$(pConf))/*.*\"\n }, \n \"$(odir)/tools/\", true)]\n\n \n#[IO copy.file(\"$(pMeta)/$(OutDir:$(pMeta))/*.dll\", \n \"$(odir)/lib/net20/\", true)]\n \n#[IO copy.file(\"tools/build.targets\", \"$(odir)/build/net20/DllExport.targets\", true)]\n\n#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]\n#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]\n\n#[var buildInfo = $([System.String]::Concat(\" \"))\n S_NUM: #[$(pVer)]\n \n S_REV: #[$(revBuild)]\n \n S_NUM_REV: #[$(pVer)].#[$(revBuild)]\n \n bSha1: #[$(bSha1)]\n \n bName: #[$(bName)]\n \n bRevc: #[$(bRevc)]\n \n Metadata .NET: #[$(TargetFrameworkVersion:$(pMeta))]\n \n Wizard .NET: #[$(TargetFrameworkVersion:$(pWizard))]\n \n Configurator .NET: #[$(TargetFrameworkVersion:$(pConf))]\n \n Configuration: #[$(Configuration)]\n \n Platform: #[$(Platform)]\n \n cfgname: #[$(cfgname)]\n \n revDeltaBase: #[$(revDeltaBase)]\n \n revDeltaMin: #[$(revDeltaMin)]\n \n revDeltaMax: #[$(revDeltaMax)]\n \n \n :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]\n]\n\n#[IO writeLine(\"$(odir)/build_info.txt\"):#[var buildInfo]]",
"Command__": [
"#[IO copy.file(",
" \"$(SolutionDir)tools/*.*\", ",
Expand All @@ -396,6 +396,8 @@
" ",
"#[IO copy.file(\"$(pMeta)/$(OutDir:$(pMeta))/*.dll\", ",
" \"$(odir)/lib/net20/\", true)]",
" ",
"#[IO copy.file(\"tools/build.targets\", \"$(odir)/build/net20/DllExport.targets\", true)]",
"",
"#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]",
"#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]",
Expand Down Expand Up @@ -505,7 +507,7 @@
"Mode": {
"$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
"Type": "Script",
"Command": "#[IO writeLine(STDOUT): Build GetNuTool ...]\n#[IO writeLine(STDOUT): #[IO cmd(\"cd GetNuTool & call build\", 400)]]\n\n#[var frontend = $(pWizard)\\\\installer.bat]\n#[var gntECore = \"$(pGetNuTool)\\\\bin\\\\Release\\\\raw\\\\versions\\\\01. executable\\\\gnt.bat\"]\n#[var dxpWZ = $(dbin.Replace('/', '\\\\'))DllExport.bat]\n\n#[try\n{\n #[IO writeLine(STDOUT):\n #[IO cmd(\"copy /Y/B $(frontend)+$(gntECore) $(dxpWZ)\")]\n ]\n}\ncatch(err, msg)\n{\n #[IO write(STDOUT):\n Trying with another method... ]\n \n #[IO cmd(\"type $(frontend)>$(dxpWZ)\")]\n #[IO cmd(\"type $(gntECore)>>$(dxpWZ)\")]\n \n #[IO writeLine(STDOUT): ok]\n\n}]\n\n\n#[\" \n finalization\n\"]\n#[IO replace.Regex(\"$(dxpWZ)\", \"(@echo off) & echo.*?exit /B \\d+\", \"$1\")]\n\n\n#[\" \n update version\n\"]\n#[IO replace(\"$(dxpWZ)\", \"$-version-$\", \"$(dxpPrintVersion)\")]\n\n#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]",
"Command": "#[IO writeLine(STDOUT): Build GetNuTool ...]\n#[IO writeLine(STDOUT): #[IO cmd(\"cd GetNuTool & call build\", 400)]]\n\n#[var frontend = $(pWizard)\\\\installer.bat]\n#[var gntECore = \"$(pGetNuTool)\\\\bin\\\\Release\\\\raw\\\\versions\\\\01. executable\\\\gnt.bat\"]\n#[var dxpWZ = $(dbin.Replace('/', '\\\\'))DllExport.bat]\n\n#[try\n{\n #[IO writeLine(STDOUT):\n #[IO cmd(\"copy /Y/B $(frontend)+$(gntECore) $(dxpWZ)\")]\n ]\n}\ncatch(err, msg)\n{\n #[IO write(STDOUT):\n Trying with another method... ]\n \n #[IO cmd(\"type $(frontend)>$(dxpWZ)\")]\n #[IO cmd(\"type $(gntECore)>>$(dxpWZ)\")]\n \n #[IO writeLine(STDOUT): ok]\n\n}]\n\n\n#[\" \n finalization\n\"]\n#[IO replace.Regex(\"$(dxpWZ)\", \"(@echo off) & echo.*?exit /B \\d+\", \"$1\")]\n\n\n#[\" \n update version\n\"]\n#[IO replace(\"$(dxpWZ)\", \"$-version-$\", \"$(dxpPrintVersion)\")]\n#[IO replace(\"$(dxpWZ)\", \"$-pkg-version-$\", \"$(pVer)\")]\n\n#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]",
"Command__": [
"#[IO writeLine(STDOUT): Build GetNuTool ...]",
"#[IO writeLine(STDOUT): #[IO cmd(\"cd GetNuTool & call build\", 400)]]",
Expand Down Expand Up @@ -543,6 +545,7 @@
" update version",
"\"]",
"#[IO replace(\"$(dxpWZ)\", \"$-version-$\", \"$(dxpPrintVersion)\")]",
"#[IO replace(\"$(dxpWZ)\", \"$-pkg-version-$\", \"$(pVer)\")]",
"",
"#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]"
]
Expand Down
7 changes: 1 addition & 6 deletions DllExport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{E623294B-0
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{44F550ED-6D5E-45CB-8FD0-CBB35051B8E1}"
ProjectSection(SolutionItems) = preProject
tools\build.targets = tools\build.targets
tools\DllExport.nuspec = tools\DllExport.nuspec
tools\DllExportCmdLets.psm1 = tools\DllExportCmdLets.psm1
tools\gnt.bat = tools\gnt.bat
tools\hMSBuild.bat = tools\hMSBuild.bat
tools\init.ps1 = tools\init.ps1
tools\install.ps1 = tools\install.ps1
tools\net.r_eg.DllExport.targets = tools\net.r_eg.DllExport.targets
tools\nsbin.bat = tools\nsbin.bat
tools\nsbin.ps1 = tools\nsbin.ps1
tools\powershell.bat = tools\powershell.bat
tools\uninstall.ps1 = tools\uninstall.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{55898433-0EEF-4B38-B144-B2A40150E4F4}"
Expand Down
5 changes: 5 additions & 0 deletions Wizard/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ public enum ActionType: uint
/// To restore already configured environment.
/// </summary>
Restore,

/// <summary>
/// Information about obsolete nuget clients etc.
/// </summary>
Info,
}
}
85 changes: 85 additions & 0 deletions Wizard/CfgBatWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.IO;
using net.r_eg.DllExport.Wizard.Extensions;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.DllExport.Wizard
{
//TODO:
internal sealed class CfgBatWrapper
{
private const string DXP_INSTALLER = "DllExport.bat";

private IWizardConfig config;
private ISender log;

public CfgBatWrapper(IWizardConfig config, ISender log)
{
this.config = config ?? throw new ArgumentNullException(nameof(config));
this.log = log ?? throw new ArgumentNullException(nameof(log));
}

public bool TryPrepare()
{
try {
CopyFromPkg(DXP_INSTALLER);
return true;
}
catch(Exception ex) {
log.send(this, $"Installer: Copy failed `{ex.Message}`", Message.Level.Warn);
}
return false;
}

private string CopyFromPkg(string fname)
{
var dxp = Path.Combine(config.PkgPath, fname);
var dest = Path.Combine(config.SlnDir, fname);

try
{
if(!File.Exists(dest)) {
File.Copy(dxp, dest, false);
return dest;
}

if(dest.SHA1HashFromFile() != dxp.SHA1HashFromFile()) {
dest = $"{dest}_{Project.METALIB_PK_TOKEN}{Path.GetExtension(dest)}";
}
File.Copy(dxp, dest, true);
return dest;
}
finally
{
File.WriteAllText(
dest,
File.ReadAllText(dest).Replace("set \"wAction=\"", "set \"wAction=Configure\"")
);
}
}
}
}
27 changes: 17 additions & 10 deletions Wizard/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,26 @@ public void Configure()
{
var sln = String.IsNullOrWhiteSpace(Config.SlnFile) ?
SlnFiles?.FirstOrDefault() : Config.SlnFile;
if(sln == null)
if(sln != null)
{
throw new ArgumentException(
String.Format(
"We can't find any .sln file to continue processing. Use '{0}' property or check '{1}'",
nameof(IWizardConfig.SlnFile),
nameof(IWizardConfig.SlnDir)
)
);
Log.send(this, $"To restore '{sln}'", Message.Level.Info);
UniqueProjectsBy(sln)?.ForEach(p => p.Configure(ActionType.Restore));
}
Log.send(this, $"To restore '{sln}'", Message.Level.Info);

UniqueProjectsBy(sln)?.ForEach(p => p.Configure(ActionType.Restore));
throw new ArgumentException(
String.Format(
"We can't find any .sln file to continue processing. Use '{0}' property or check '{1}'",
nameof(IWizardConfig.SlnFile),
nameof(IWizardConfig.SlnDir)
)
);
}

if(Config.Type == ActionType.Info)
{
(new CfgBatWrapper(Config, Log)).TryPrepare();
UI.App.RunSTA(new UI.InfoForm(this));
return;
}
}

Expand Down
48 changes: 48 additions & 0 deletions Wizard/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace net.r_eg.DllExport.Wizard.Extensions
{
Expand Down Expand Up @@ -72,6 +74,32 @@ public static int ToInteger(this string value)
return Int32.Parse(value);
}

/// <summary>
/// Open url through default application.
/// </summary>
/// <param name="url"></param>
public static void OpenUrl(this string url)
{
if(!String.IsNullOrWhiteSpace(url)) {
System.Diagnostics.Process.Start(url);
}
}

/// <summary>
/// Calculate SHA-1 hash from file.
/// </summary>
/// <param name="file">Path to file.</param>
/// <returns>SHA-1 Hash code.</returns>
public static string SHA1HashFromFile(this string file)
{
using(var fs = File.OpenRead(file))
{
using(SHA1 sha1 = SHA1.Create()) {
return BytesToHexView(sha1.ComputeHash(fs));
}
}
}

/// <summary>
/// To open value from double quotes.
/// </summary>
Expand Down Expand Up @@ -110,6 +138,12 @@ public static string FilePathFormat(this string path, string root = null)
return CombineRootPath(OpenDoubleQuotes(path)?.Trim(), root);
}

/// <summary>
/// To combine relative path with root.
/// </summary>
/// <param name="path"></param>
/// <param name="root"></param>
/// <returns></returns>
public static string CombineRootPath(string path, string root)
{
if(String.IsNullOrWhiteSpace(path) || Path.IsPathRooted(path)) {
Expand All @@ -122,5 +156,19 @@ public static string CombineRootPath(string path, string root)

return Path.Combine(root, path);
}

/// <summary>
/// To format bytes data to hex view.
/// </summary>
/// <param name="data">Bytes data.</param>
/// <returns>Hex view of bytes.</returns>
private static string BytesToHexView(byte[] data)
{
var ret = new StringBuilder();
foreach(byte b in data) {
ret.Append(b.ToString("X2"));
}
return ret.ToString();
}
}
}
1 change: 1 addition & 0 deletions Wizard/UI/ConfiguratorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Wizard/UI/ConfiguratorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Threading;
using System.Windows.Forms;
using net.r_eg.DllExport.NSBin;
using net.r_eg.DllExport.Wizard.Extensions;

namespace net.r_eg.DllExport.Wizard.UI
{
Expand Down Expand Up @@ -70,9 +71,7 @@ public ConfiguratorForm(IExecutor exec)

private void OpenUrl(string url)
{
if(!String.IsNullOrWhiteSpace(url)) {
System.Diagnostics.Process.Start(url);
}
url.OpenUrl();
}

private void RenderSlnFiles()
Expand Down
Loading

0 comments on commit 5f4dd18

Please sign in to comment.