You are here

UPX script

3 posts / 0 new
Last post
Shawn Faucher
Shawn Faucher's picture
Offline
Last seen: 15 years 3 months ago
Developer
Joined: 2007-10-23 22:14
UPX script

Here's a script I've been working on to automatically UPX all exe & dll files in the App\[app] folder and its subfolders. It compresses with the recommended settings, and does a upx -t on each resultant file to make sure it decompresses correctly. If it doesn't, it automatically reverts to the backed up original copy. If it does the backup is deleted. It's written to be run from the Source directory of the app. Two variables need to be set, UPXBIN points to the upx.exe binary and APP is the name of the root app binary folder. So far it seems to have worked like a charm on GnuCash Portable. I've been running it through its paces with no crashes yet.

:: This script will compress all exe and dll files in the %APP% directory to save space.
:: Files that don't compress correctly are automatically reverted
@ECHO OFF
:: UPX is available at http://upx.sourceforge.net
SET UPXBIN=F:\PortableApps\UPX\upx.exe
SET APP=GnuCash

ECHO Compressing exe and dll files
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=*" %%G IN ('DIR /B /S ..\..\App\%APP%\*.exe ..\..\App\%APP%\*.dll') DO (
    %UPXBIN% "%%G" --best --compress-icons=0 --nrv2e --crp-ms=999999 -k
	SET VAR=%%G
	%UPXBIN% "%%G" -t
	IF !ERRORLEVEL! NEQ 0 (MOVE /Y !VAR:~0,-1!^~ %%G) ELSE (DEL /Q !VAR:~0,-1!^~)
)
pause
Ryan McCue
Ryan McCue's picture
Offline
Last seen: 15 years 2 months ago
Joined: 2006-01-06 21:27
Mmm.

Tasty.

"If you're not part of the solution, you're part of the precipitate."

wraithdu
Offline
Last seen: 11 years 5 months ago
Developer
Joined: 2007-06-27 20:22
I like. One suggestion, you

I like. One suggestion, you could change

SET APP=%1

then pass the name of your app on the commandline. This way you could put it in your PATH and run in from a cmd prompt, working directory = your source dir.

Log in or register to post comments