Skip to content

Commit

Permalink
option to enable/disable UPX compression + update 7za
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyben committed Jul 18, 2016
1 parent 20677a1 commit efa7d9e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
Binary file modified bin/7za.exe
Binary file not shown.
42 changes: 29 additions & 13 deletions hta/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,45 @@ function sendToBatch() {
var completion = form.elements['completion'].checked;
var distname = form.elements['distname'].value;
var icon = form.elements['icon'].value || false;
var upx = form.elements['upx'].checked;
if (icon && !hasExtension(icon, ['ico'], true)) return false;
if (isRequired(srcfile) && hasExtension(srcfile, ['bat', 'hta'], true) && isRequired(distname) && isWinFilename(distname)) {
var src = splitPath(srcfile);
var output = src.folder +'~'+ src.file +'~'+ include +'~'+ hidcon +'~'+ completion +'~'+ distname +'~'+ icon;
var output = src.folder +'~'+ src.file +'~'+ include +'~'+ hidcon +'~'+ completion +'~'+ distname +'~'+ icon +'~'+ upx;
if (!checkOverwrite(distname, src.folder)) return false;
fso.GetStandardStream(1).Write(output);
window.close();
}
}

function changeDistname() {
var form = document.forms[0];
var srcfile = form.elements['srcfile'].value;
var distname = form.elements['distname'];
distname.value = srcfile.split('\\').pop().replace(/\.[^/.]+$/, '');
changeHideConsole();
}

function changeHideConsole(){
var form = document.forms[0];
var hidcon = form.elements['hidcon'];
var srcfile = form.elements['srcfile'].value;
if (hasExtension(srcfile, ['bat'], false)) {
hidcon.disabled = false;
removeClass(hidcon.parentNode, 'text-muted');
} else {
hidcon.disabled = true;
hidcon.checked = false;
hidcon.parentNode.className += ' text-muted';
changeCompletion();
}
}

function changeCompletion() {
var form = document.forms[0];
var completion = form.elements['completion'];
var hidcon = form.elements['hidcon'];
var srcfile = form.elements['srcfile'].value;
if (hidcon.checked && hasExtension(srcfile, ['bat'], false)) {
if (hidcon.checked) {
completion.disabled = false;
removeClass(completion.parentNode, 'text-muted');
} else {
Expand All @@ -33,13 +56,6 @@ function changeCompletion() {
}
}

function changeDistname() {
var form = document.forms[0];
var srcfile = form.elements['srcfile'].value;
var distname = form.elements['distname'];
distname.value = srcfile.split('\\').pop().replace(/\.[^/.]+$/, '');
}

function splitPath(input) {
input = input.split('\\');
var file = input.pop();
Expand All @@ -56,10 +72,10 @@ function isRequired(input) {
}

function hasExtension(input, extensions, feedback) {
var hasOne = extensions.filter(function(value){
return input.indexOf(value, this.length - value.length) > -1
var hasOne = extensions.some(function(ext){
return input.indexOf(ext, input.length - ext.length) > -1
})
if (!hasOne[0]){
if (!hasOne){
if (feedback) errorFeedback('.is-ext', 'Not a ' + extensions + ' file');
return false;
}
Expand Down
19 changes: 15 additions & 4 deletions hta/thebatchman.hta
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<head>
<meta http-equiv="x-ua-compatible" content="ie=9">
<script language="javascript">
var appSize = { width: 350, height: 490 };
(function () {
var appSize = { width: 350, height: 520 };
window.resizeTo(appSize.width, appSize.height);
window.moveTo((screen.width - appSize.width) / 2, (screen.availHeight - appSize.height) / 2);
})()
</script>
<title>The Batchman</title>
<hta:application id="app" scroll="auto" sysmenu="yes" showInTaskbar="yes" caption="yes" border="thin" icon="../thebatchman_icon.ico" maximizebutton="no" minimizebutton="no" navigable="yes" singleInstance="yes">
Expand Down Expand Up @@ -53,11 +55,20 @@
<strong class="form-control-feedback hide">&#10006;</strong>
</div>

<div class="form-group mb15 mt25">
<div class="form-group mt20 mb15">
<div class="checkbox">
<label>
<input type="checkbox" name="hidcon" onchange="changeCompletion()">
Hide the console when running your exe ?
<input type="checkbox" name="upx">
Compress the exe with UPX ?
</label>
</div>
</div>

<div class="form-group mb15">
<div class="checkbox">
<label class="text-muted">
<input type="checkbox" name="hidcon" onchange="changeCompletion()" disabled>
Hide the console when running the exe ?
</label>
</div>
<div class="checkbox">
Expand Down
7 changes: 5 additions & 2 deletions thebatchman.bat
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
@echo off
setlocal

for /f "tokens=1-7 delims=~" %%i in ('mshta.exe "%~dp0\hta\thebatchman.hta"') do (
for /f "tokens=1-8 delims=~" %%i in ('mshta.exe "%~dp0\hta\thebatchman.hta"') do (
set "srcdir=%%i"
set "srcfile=%%j"
set "include=%%k"
set "hideconsole=%%l"
set "completion=%%m"
set "name=%%n"
set "icofile=%%o"
set "upx=%%p"
)
if "%srcfile%"=="" goto :eof
start "" mshta.exe "%~dp0\hta\wait.hta"
Expand Down Expand Up @@ -58,7 +59,9 @@ start /b /wait "Resourcer" "%~dp0\bin\resourcer.exe" -op:add -src:"%temp%\%name%
copy /b /y "%temp%\%name%.icx" + "%temp%\%name%.tmp" "%distexe%"

:: Compress executable with UPX
start /b /wait "Compressing" "bin\upx.exe" -1 -q "%distexe%"
if "%upx%" == "true" (
start /b /wait "Compressing" "bin\upx.exe" -1 -q "%distexe%"
)

:: Cleaning
if exist "%sfxconfig%" del /q /f "%sfxconfig%"
Expand Down

0 comments on commit efa7d9e

Please # to comment.