Skip to content

Commit

Permalink
add modal to log progress, fix path with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyben committed Aug 1, 2016
1 parent 3cc029a commit b06996b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
42 changes: 40 additions & 2 deletions assets/custom.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.fs12{font-size:12px}.fs14{font-size:14px}.fs16{font-size:16px}.fs18{font-size:18px}.fs20{font-size:20px}.fs22{font-size:22px}.fs24{font-size:24px}.fs26{font-size:26px}.fs28{font-size:28px}.fs30{font-size:30px}.fs32{font-size:32px}.fs34{font-size:34px}.fs36{font-size:36px}.fs38{font-size:38px}.fs40{font-size:40px}
.mb0{margin-bottom:0px}.mt0{margin-top:0px}
.mb10{margin-bottom:10px}.mt10{margin-top:10px}.ml10{margin-left:10px}.mr10{margin-right:10px}
.mb15{margin-bottom:15px}.mt15{margin-top:15px}.ml15{margin-left:15px}.mr15{margin-right:15px}
Expand All @@ -8,4 +7,43 @@
.pb10{padding-bottom:10px}.pt10{padding-top:10px}.pl10{padding-left:10px}.pr10{padding-right:10px}
.pb20{padding-bottom:20px}.pt20{padding-top:20px}.pl20{padding-left:20px}.pr20{padding-right:20px}
.pb30{padding-bottom:30px}.pt30{padding-top:30px}.pl30{padding-left:30px}.pr30{padding-right:30px}
.navbar-brand>img{width:32px}

.navbar-brand > img {
width: 32px;
}

#modal {
display: none;
position: fixed;
z-index: 10;
padding-top: 55px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.3);
}

#modal-content {
background-color: #fefefe;
margin: auto;
padding: 15px;
border: 1px solid #888;
width: 90%;
}

#modal-content p {
font-weight: 600;
font-size: 16px;
}

#modal-content p span{
font-weight: 400;
font-size: 14px;
word-break: break-all;
}

#modal-btns{
display: none;
}
53 changes: 34 additions & 19 deletions assets/process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var fso = new ActiveXObject('Scripting.FileSystemObject')
var wsh = new ActiveXObject('WScript.Shell')
var sa = new ActiveXObject('Shell.Application')
var stream = new ActiveXObject("ADODB.Stream")

function doIt() {
Expand All @@ -11,6 +10,9 @@ function doIt() {
var completion = form.elements['completion'].checked
var distname = form.elements['distname'].value
var icon = form.elements['icon'].value || 'assets\\default_icon.ico'
var modal = document.getElementById('modal')
var modalContent = document.getElementById('modal-content')
var modalBtns = document.getElementById('modal-btns')

if (isRequired(srcfile) && hasExtension(srcfile, ['bat', 'hta'], true) && isRequired(distname) && isWinFilename(distname)) {
var src = splitPath(srcfile)
Expand All @@ -25,27 +27,35 @@ function doIt() {
if (!hasExtension(icon, ['ico'], true)) return false
if (!overwrite(distname + '.exe', src.folder)) return false

modal.style.display = 'block'
log('Processing...', modalContent, modalBtns)

// HTA completion feedback and copy to temp directory
stream.CharSet = 'utf-8'
stream.Open()
stream.LoadFromFile(srcfile)
if (completion) {
var content = stream.ReadText()
content += '\nstart "" mshta.exe javascript:alert("'+ distname +' complete");close()'
stream.Flush()
stream.WriteText(content)
log('Adding completion line...', modalContent, modalBtns)
var srcContent = stream.ReadText()
stream.Close()
stream.Open()
srcContent += '\nstart "" mshta.exe javascript:alert("'+ distname +' complete");close()'
stream.WriteText(srcContent)
}
stream.saveToFile(tempfile, 2)
stream.Close()

// Compress
if (include) {
wsh.Run('bin\\7za.exe a -t7z -mx1 -y ' + archive + ' ' + tempfile + ' ' + src.folder + '\\* -x!' + srcfile, 0, true)
log('Compressing all files...', modalContent, modalBtns)
wsh.Run('bin\\7za.exe a -t7z -mx1 -y "' + archive + '" "' + tempfile + '" "' + src.folder + '\\*" -x!"' + srcfile +'"', 0, true)
} else {
wsh.Run('bin\\7za.exe a -t7z -mx1 -y ' + archive + ' ' + tempfile, 0, true)
log('Compressing...', modalContent, modalBtns)
wsh.Run('bin\\7za.exe a -t7z -mx1 -y "' + archive + '" "' + tempfile +'"', 0, true)
}

// Create Config File for SFX
log('Converting to executable...', modalContent, modalBtns)
var sfxfile = tempdir + '\\' + 'thebatchman_' + distname + '_sfx.txt'
var sfxconfig = ';!@Install@!UTF-8!'
if (hidcon) sfxconfig += '\nRunProgram="hidcon:'+ src.file +'"'
Expand All @@ -64,29 +74,24 @@ function doIt() {
binaryCopy(['bin\\7zsd_LZMA2.sfx', sfxfile, archive], disttemp)

// Add Icon and Finalize
log('Adding icon...', modalContent, modalBtns)
binaryCopy([disttemp], disticx)
wsh.Run('bin\\resourcer.exe -op:add -src:"'+ disticx +'" -type:icon -name:name -lang:1033 -file:"'+ icon +'"', 0, true)
binaryCopy([disticx, disttemp], distexe)

// Clean
log('Cleaning...', modalContent, modalBtns)
fso.DeleteFile(tempfile)
fso.DeleteFile(disticx)
fso.DeleteFile(disttemp)
fso.DeleteFile(archive)
fso.DeleteFile(sfxfile)
alert('Done !')
// window.close()
log('Done !', modalContent, modalBtns)
log('<span>'+ distexe +'</span>', modalContent, modalBtns)
modalBtns.style.display = 'block'
} else {
location.reload()
}

// var exe = wsh.exec(cmd)
// var out = ''
// while (!exe.stdOut.atEndOfStream) {
// var s = exe.stdOut.readLine()
// s = s.replace( /\r/gm, '' )
// out += s + '\n'
// }
// document.getElementById("output").value = out

}

Expand Down Expand Up @@ -214,3 +219,13 @@ function forEachEl(selector, fn) {
function removeClass(el, classToRemove) {
el.className = el.className.replace(new RegExp('(^|\\b)' + classToRemove.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
}

function log(message, parent, before) {
var p = document.createElement('p')
p.innerHTML = message
if (before) {
parent.insertBefore(p, before)
} else {
parent.appendChild(p)
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ So think of adding `goto completion` in your script instead of `goto:eof` if you
Tested on Windows 10 x64, but should work on every Windows up to XP SP2 (x86 or x64), as long as you have Internet Explorer 8 or more recent.

## Included dependencies and licensing
+ [7-zip command-line](http://www.7-zip.org/) 15.12 (under GNU LGPL)
+ [7-zip command-line](http://www.7-zip.org/) 16.02 (under GNU LGPL)
+ [7-zip modified SFX modules](http://7zsfx.info/en/) 1.6 (under GNU LGPL)
+ [Anolis Resourcer](http://anolis.codeplex.com/) 0.9 (under GNU GPLv2)
+ [Bootstrap](http://getbootstrap.com/) 3.3.5 (under MIT)
Expand Down
11 changes: 10 additions & 1 deletion thebatchman.hta
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="x-ua-compatible" content="ie=9">
<script language="javascript">
(function () {
var appSize = { width: 350, height: 520 }
var appSize = { width: 350, height: 510 }
window.resizeTo(appSize.width, appSize.height)
window.moveTo((screen.width - appSize.width) / 2, (screen.availHeight - appSize.height) / 2)
})()
Expand Down Expand Up @@ -82,5 +82,14 @@
</div>
</div>
</div>

<div id="modal">
<div id="modal-content">
<div id="modal-btns" class="text-center mt20">
<a class="btn btn-info" onclick="location.reload()">New file</a>
<a class="btn btn-default" onclick="window.close()">Exit</a>
</div>
</div>
</div>
</body>
</html>

0 comments on commit b06996b

Please sign in to comment.