From b06996b50cb6a831fc888404b9be235b5e1bb2f0 Mon Sep 17 00:00:00 2001 From: jbensimon Date: Mon, 1 Aug 2016 22:20:02 +0200 Subject: [PATCH] add modal to log progress, fix path with spaces --- assets/custom.css | 42 +++++++++++++++++++++++++++++++++++-- assets/process.js | 53 ++++++++++++++++++++++++++++++----------------- readme.md | 2 +- thebatchman.hta | 11 +++++++++- 4 files changed, 85 insertions(+), 23 deletions(-) diff --git a/assets/custom.css b/assets/custom.css index 74cd20b..ae9580b 100644 --- a/assets/custom.css +++ b/assets/custom.css @@ -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} @@ -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} \ No newline at end of file + +.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; +} \ No newline at end of file diff --git a/assets/process.js b/assets/process.js index 1f43504..51414c0 100644 --- a/assets/process.js +++ b/assets/process.js @@ -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() { @@ -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) @@ -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 +'"' @@ -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(''+ distexe +'', 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 } @@ -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) + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index 62fc1f6..09e5eb8 100644 --- a/readme.md +++ b/readme.md @@ -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) diff --git a/thebatchman.hta b/thebatchman.hta index d9b6cba..ae27df8 100644 --- a/thebatchman.hta +++ b/thebatchman.hta @@ -4,7 +4,7 @@