Skip to content

Commit

Permalink
Added compressor for DllExport installer - #38
Browse files Browse the repository at this point in the history
also added `MsgGuiLevel` flag to show messages via GUI dlg for selected level
  • Loading branch information
3F committed Aug 2, 2017
1 parent 744a90b commit 7312630
Show file tree
Hide file tree
Showing 14 changed files with 740 additions and 32 deletions.
15 changes: 13 additions & 2 deletions .vssbe
Original file line number Diff line number Diff line change
Expand Up @@ -507,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#[IO replace(\"$(dxpWZ)\", \"$-pkg-version-$\", \"$(pVer)\")]\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#[\" \n .compressor\n\"]\n#[IO writeLine(STDOUT): Generate minified version of Wizard installer ...]\n#[IO writeLine(STDOUT): #[IO cmd(\"$(SolutionDir)tools\\hMSBuild $(SolutionDir)$(pWizard)/.compressor /p:core=\\\"$(SolutionDir)$(dxpWZ)\\\" /p:output=\\\"$(SolutionDir)$(dxpWZ)_minified.bat\\\" /nologo /v:m /m:4 \", 400)]]\n\n#[IO copy.file(\"$(dxpWZ)\", \"$(dxpWZ)_full.bat\", true)]\n#[IO copy.file(\"$(dxpWZ)_minified.bat\", \"$(dxpWZ)\", true)]\n#[IO delete.files({\"$(dxpWZ)_minified.bat\"})]\n\n#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]\n",
"Command__": [
"#[IO writeLine(STDOUT): Build GetNuTool ...]",
"#[IO writeLine(STDOUT): #[IO cmd(\"cd GetNuTool & call build\", 400)]]",
Expand Down Expand Up @@ -547,7 +547,18 @@
"#[IO replace(\"$(dxpWZ)\", \"$-version-$\", \"$(dxpPrintVersion)\")]",
"#[IO replace(\"$(dxpWZ)\", \"$-pkg-version-$\", \"$(pVer)\")]",
"",
"#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]"
"#[\" ",
" .compressor",
"\"]",
"#[IO writeLine(STDOUT): Generate minified version of Wizard installer ...]",
"#[IO writeLine(STDOUT): #[IO cmd(\"$(SolutionDir)tools\\hMSBuild $(SolutionDir)$(pWizard)/.compressor /p:core=\\\"$(SolutionDir)$(dxpWZ)\\\" /p:output=\\\"$(SolutionDir)$(dxpWZ)_minified.bat\\\" /nologo /v:m /m:4 \", 400)]]",
"",
"#[IO copy.file(\"$(dxpWZ)\", \"$(dxpWZ)_full.bat\", true)]",
"#[IO copy.file(\"$(dxpWZ)_minified.bat\", \"$(dxpWZ)\", true)]",
"#[IO delete.files({\"$(dxpWZ)_minified.bat\"})]",
"",
"#[IO copy.file(\"$(dxpWZ)\", \"$(odir)/\", true)]",
""
]
}
},
Expand Down
1 change: 1 addition & 0 deletions DllExport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{55898433
tools\gnt.bat = tools\gnt.bat
tools\hMSBuild.bat = tools\hMSBuild.bat
packages_restore.cmd = packages_restore.cmd
submodules.bat = submodules.bat
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSBin", "NSBin\NSBin.csproj", "{311706A5-5ED2-4006-B794-055009D8A256}"
Expand Down
258 changes: 258 additions & 0 deletions Wizard/.compressor
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2016-2017 Denis Kuzmin [ entry.reg@gmail.com ]
Distributed under the DllExport license
https://github.com/3F/DllExport
Based on compressor from hMSBuild project (Minified version):
https://github.com/3F/hMSBuild
-->

<!--
[Minified version]
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Main settings -->
<PropertyGroup>
<core Condition="'$(core)' == ''">DllExport.bat</core>
<output Condition="'$(output)' == ''">DllExport_minified.bat</output>
</PropertyGroup>

<!-- Entry point -->
<Target Name="handler" BeforeTargets="Build">
<Compress core="$(core)" output="$(output)" />
</Target>

<!-- Tasks settings -->
<PropertyGroup>
<TaskCoreDllPath Condition="Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll')">$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll</TaskCoreDllPath>
<TaskCoreDllPath Condition="'$(TaskCoreDllPath)' == '' and Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll')">$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll</TaskCoreDllPath>
</PropertyGroup>

<!-- Prepares list for downloader below -->
<UsingTask
TaskName="Compress"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(TaskCoreDllPath)">

<ParameterGroup>
<core ParameterType="System.String" Required="true" />
<output ParameterType="System.String" Required="true" />
</ParameterGroup>

<Task>
<Using Namespace="System" />
<Using Namespace="System.Collections.Generic" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
Func<char[], int, Func<int, bool>, string[]> gencomb = (char[] _dict, int _size, Func<int, bool> _rule0) =>
{
var combination = new char[_size];
var set = new List<string>((int)Math.Pow(_dict.Length, _size));
int pos = 0;
Action generator = null;
generator = () =>
{
for(int i = 0, lim = _size - 1; i < _dict.Length; ++i)
{
if(pos == 0 && !_rule0(i)) {
continue;
}
if(pos < lim) {
combination[pos] = _dict[i];
++pos;
generator();
--pos;
}
else {
combination[pos] = _dict[i];
set.Add(new String(combination.ToArray()));
}
}
};
generator();
return set.ToArray();
};
var cdict = new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '_' };
var vdict = gencomb(cdict, 2, (int i) => { return char.IsLetter(cdict[i]) || cdict[i] == '_'; });
// to skip processing for:
var exvar = new[] { "wSlnDir", "wPkgPath", "wMetaLib", "wDxpTarget", "wAction", "wSlnFile", "wRootPath", "ngserver" };
const string VNAME = "[a-z_][a-z_0-9]+";
const string VERS = "[Minified version]";
const string APP = "DllExport";
using(StreamReader reader = new StreamReader(core, System.Text.Encoding.UTF8, true))
{
var content = reader.ReadToEnd();
/* Shorten variables & labels */
var variables = new Dictionary<string, string>();
uint uniqVars = 0;
content = Regex.Replace
(
content,
@"(?'def'
set\s+?
(?:\/\S\s+?)?
(?:""\s*?)?
)
(?'name'"+ VNAME + @")
(?'lim'\s?\S?=)", // aq+=1,.. TODO: aq=aq+1 ; aq=1+aq ...
(Match m) =>
{
var def = m.Groups["def"].Value;
var vname = m.Groups["name"].Value;
var lim = m.Groups["lim"].Value;
if(exvar.Contains(vname)) {
return m.Groups[0].Value;
}
if(variables.ContainsKey(vname)) {
return def + variables[vname] + lim;
}
if(uniqVars + 1 > vdict.Length) {
throw new OverflowException("vdict does not contain data for new vars");
}
variables[vname] = vdict[uniqVars++];
return def + variables[vname] + lim;
},
RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase
);
// call :proc p1 p2 ...
content = Regex.Replace
(
content,
@"(?'def'call\s+:"+ VNAME + @"\s)(?'args'.+?)(?'eol'[\s&$])",
(Match m) =>
{
var def = m.Groups["def"].Value;
var cargs = m.Groups["args"].Value;
var eol = m.Groups["eol"].Value;
return def + Regex.Replace
(
cargs,
@"(?'split'^|\s)(?'name'" + VNAME + ")",
(Match _m) =>
{
var split = _m.Groups["split"].Value;
var vname = _m.Groups["name"].Value;
if(variables.ContainsKey(vname)) {
return split + variables[vname];
}
if(uniqVars + 1 > vdict.Length) {
throw new OverflowException("vdict does not contain data for new vars");
}
variables[vname] = vdict[uniqVars++];
return split + variables[vname];
},
RegexOptions.IgnoreCase | RegexOptions.Multiline
) + eol;
},
RegexOptions.IgnoreCase | RegexOptions.Multiline
);
// %name... & !name...
content = Regex.Replace
(
content,
@"(?'def'(?:[%!]|\sdefined\s+))(?'name'"+ VNAME + ")",
(Match m) =>
{
var def = m.Groups["def"].Value;
var vname = m.Groups["name"].Value;
if(!variables.ContainsKey(vname)) {
return def + vname;
}
return def + variables[vname];
},
RegexOptions.IgnoreCase
);
// labels
content = Regex.Replace
(
content,
@"(?'def'call\s*:|^\s*:|goto\s*:?)(?'label'" + VNAME + @")(?'eol'\s|$)",
(Match m) =>
{
var def = m.Groups["def"].Value;
var label = m.Groups["label"].Value;
var eol = m.Groups["eol"].Value;
if(variables.ContainsKey(label)) {
return def + variables[label] + eol;
}
if(uniqVars + 1 > vdict.Length) {
throw new OverflowException("vdict does not contain data for new labels");
}
variables[label] = vdict[uniqVars++];
return def + variables[label] + eol;
},
RegexOptions.IgnoreCase | RegexOptions.Multiline
);
/* A common rules */
content = Regex.Replace(content, @"(\r\n){2,}", "$1");
content = Regex.Replace(content, @"(\r\n)\s*", "$1");
//content = Regex.Replace(content, @"(?:rem|::)\s.*[\r\n]*", "");
content = Regex.Replace(content, @"(^\s*?(?:rem|::)\s)(?'data'.*)([\r\n]*)", (Match m) =>
{
var data = m.Groups["data"].Value.TrimStart();
if(!data.StartsWith("Copyright")
&& !data.StartsWith("GetNuTool")
&& !data.StartsWith("DllExport")
&& !data.StartsWith("http")
&& !data.StartsWith("Based ")
&& !data.StartsWith("---"))
{
return String.Empty;
}
if(data.Contains("/issues")) {
return String.Empty;
}
return m.Groups[0].Value;
}, RegexOptions.IgnoreCase | RegexOptions.Multiline);
//content = content.Replace(" " + APP + " - ", String.Format(" {0} {1} - ", APP, VERS));
using(TextWriter writer = new StreamWriter(output, false, new UTF8Encoding(false))) {
writer.Write(content);
}
Console.WriteLine("{0} version of `{1}` has been created -> `{2}`", VERS, core, output);
}
]]></Code>
</Task>
</UsingTask>

<!-- remap targets -->

<Target Name="Build" DependsOnTargets="handler" />

</Project>
6 changes: 3 additions & 3 deletions Wizard/CfgBatWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ private string CopyFromPkg(string fname)
}

if(dest.SHA1HashFromFile() != dxp.SHA1HashFromFile()) {
dest = $"{dest}_{Project.METALIB_PK_TOKEN}{Path.GetExtension(dest)}";
dest = dest.AddFileNamePostfix($"_{Project.METALIB_PK_TOKEN}");
}
File.Copy(dxp, dest, true);
return dest;
}
finally
{
File.WriteAllText(
dest,
File.ReadAllText(dest).Replace("set \"wAction=\"", "set \"wAction=Configure\"")
dest.AddFileNamePostfix("_Configure"),
"DllExport -action Configure"
);
}
}
Expand Down
Loading

0 comments on commit 7312630

Please sign in to comment.