D-Bug & Automation Forum | |
D-Bug & Automation Forum >> Coding >> Quick Extract 0.4 source code.
http://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1269690191 Message started by Christos on 27.03.10 at 11:43:10 |
Title: Quick Extract 0.4 source code. Post by Christos on 27.03.10 at 11:43:10
Quick extract is a small program that simplifies the unarchiving proces.
[code] ' This program is released under the WTFPL 2.0. See COPYING for more details ' ' ' Shel_read is used to get the parameters that executed the program ' the next series of instructions are used to get the directory variables ' ................................................... ' ~SHEL_READ(cmd$,tail_str$) tail$=RIGHT$(tail_str$,(LEN(tail_str$)-1)) filelength%=RINSTR(tail$,"\") length%=LEN(tail$)-filelength% filename$=RIGHT$(tail$,length%) progsize%=RINSTR(cmd$,"\") progdir$=LEFT$(cmd$,progsize%) ' get the file extension ext$=RIGHT$(tail$,3) ' folder$ is the name and location of the folder to be created size%=LEN(tail$)-4 folderfull$=LEFT$(tail$,size%) lsize%=RINSTR(folderfull$,"\") mysize%=LEN(folderfull$)-lsize% folder$=RIGHT$(folderfull$,mysize%)+CHR$(0) ' this set gives us the current directory dsize%=RINSTR(tail$,"\") directory$=LEFT$(tail$,dsize%)+CHR$(0) CHDIR directory$ ' this will create an alert box so the user can choose what to do text$="QUICK EXTRACT 0.4 COPYRIGHT|2010 Christos Tziotzis|Extract in current dir|or create a new one?" button$="New|Cur|Quit" ALERT 2,text$,1,button$,choice IF choice=3 END ENDIF ' here we check the extension to define what type of packing method was used ' and proceed to the relative unpacking procedure IF ext$="zip" OR ext$="ZIP" @unzip ENDIF IF ext$="rar" OR ext$="RAR" @unrar ENDIF IF ext$="lzh" OR ext$="LZH" OR ext$="lha" OR ext$="LHA" @unlzh ENDIF IF ext$="zoo" OR ext$="ZOO" @unzoo ENDIF IF ext$="tar" OR ext$="TAR" @untar ENDIF IF ext$=".gz" OR ext$=".GZ" extmore$=RIGHT$(tail$,6) IF extmore$="tar.gz" OR extmore$="TAR.GZ" @untargz ELSE @gunzip ENDIF ENDIF IF ext$="tgz" OR ext$="TGZ" @untargz ENDIF END > PROCEDURE project_settings ' WARNING: The contents of this procedure should not be edited! ' INFO "GFA-Basic Editor v1.51 " ' DATE "12/31/1999" ' TIME "03:47:34" ' LIB$ "GBE Lib " ' LIB# $3 ' $CMD %00000000000000100000000000000001 ' $RAM $0001F400 ' FLGS %00010111 ' _SYM $0 ' .EXT "prg" ' OBJ0 " " ' OBJ1 " " ' OBJ2 " " ' OBJ3 " " ' OBJ4 " " ' OBJ5 " " ' CRSR $0000001B ' BLKS $000000B7 ' BLKE $000000C3 ' MRK0 $FFFFFFFF ' MRK1 $FFFFFFFF ' MRK2 $FFFFFFFF ' MRK3 $FFFFFFFF ' MRK4 $FFFFFFFF ' MRK5 $FFFFFFFF ' MRK6 $00000003 ' MRK7 $00000012 ' MRK8 $FFFFFFFF ' MRK9 $0000001B ' FIND '00 ' ' RPLC '00 ' ' FRH0 '00 ' ' FRH1 '00 ' ' FRH2 '00 ' ' FRH3 '00 ' ' FRH4 '00 ' ' FRH5 '00 ' ' FRH6 '00 ' ' FRH7 '00 ' ' FRH8 '00 ' ' FRH9 '00 ' ' PST0 '00 ' ' PST1 '00 ' ' UND0 '00 ' ' UND1 '00 ' ' CMD$ '00 ' ' ENV$ '00 ' RETURN PROCEDURE unzip ' this procedure calls the extracting programs with the appropriate parameters ' as choosen at the alert box ' RESERVE 124000 cmdl$=filename$+" -d "+folder$+CHR$(0) cmdl2$=filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ENDIF IF choice=2 EXEC 0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ' I should probably find a way to check whether the program completed succesfuly ' and not just write it ALERT 1,"Operation completed",1,"OK",ending END ' RESERVE RETURN PROCEDURE unrar ' RESERVE 400000 cmdl$="x "+filename$+" "+folder$+CHR$(0) cmdl2$="x "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\unrar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\unrar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE unlzh ' RESERVE 200000 cmdl$=filename$+" "+folder$+CHR$(0) cmdl2$="x "+"/x- "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\lharceng.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\lharceng.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE unzoo ' RESERVE 120000 cmdl$="x// "+filename$+CHR$(0) cmdl2$="x/ "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\zoo.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\zoo.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation Completed",1,"OK",ending ' RESERVE RETURN PROCEDURE untar ' RESERVE 512000 cmdl$=" -xvf "+filename$+" -C"+folder$+CHR$(0) cmdl2$=" -xvf "+filename$+CHR$(0) IF choice=1 MKDIR folder$ EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE untargz @gunzip filetar$=LEFT$(filename$,LEN(filename$)-3) foldertar$=LEFT$(folder$,LEN(folder$)-3) ' RESERVE 512000 cmdl$=" -xvf "+filetar$+" -C"+foldertar$+CHR$(0) cmdl2$=" -xvf "+filetar$+CHR$(0) IF choice=1 MKDIR folder$ EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE gunzip ' RESERVE 512000 cmdl$=" -d "+filename$+CHR$(0) EXEC 0,progdir$+"arc\gunzip.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN [/code] |
Title: Re: Quick Extract 0.5 source code. Post by Christos on 14.03.12 at 18:34:37
I added support for tar.bz2 and fixed a bug with tar.gz (and mostly tgz).
[code]' This program is released under the WTFPL 2.0. See COPYING for more details ' ' ' Shel_read is used to get the parameters that executed the program ' the next series of instructions are used to get the directory variables ' ................................................... ' ~SHEL_READ(cmd$,tail_str$) tail$=RIGHT$(tail_str$,(LEN(tail_str$)-1)) filelength%=RINSTR(tail$,"\") length%=LEN(tail$)-filelength% filename$=RIGHT$(tail$,length%) progsize%=RINSTR(cmd$,"\") progdir$=LEFT$(cmd$,progsize%) ' get the file extension ext$=RIGHT$(tail$,3) ' folder$ is the name and location of the folder to be created size%=LEN(tail$)-4 folderfull$=LEFT$(tail$,size%) lsize%=RINSTR(folderfull$,"\") mysize%=LEN(folderfull$)-lsize% folder$=RIGHT$(folderfull$,mysize%)+CHR$(0) ' this set gives us the current directory dsize%=RINSTR(tail$,"\") directory$=LEFT$(tail$,dsize%)+CHR$(0) CHDIR directory$ ' this will create an alert box so the user can choose what to do text$="QUICK EXTRACT 0.5 by ChrisTOS|Released under WTFPL version 2|Extract in current dir|or create a new one?" button$="New|Cur|Quit" ALERT 2,text$,1,button$,choice IF choice=3 END ENDIF ' here we check the extension to define what type of packing method was used ' and proceed to the relative unpacking procedure IF ext$="zip" OR ext$="ZIP" @unzip ENDIF IF ext$="rar" OR ext$="RAR" @unrar ENDIF IF ext$="lzh" OR ext$="LZH" OR ext$="lha" OR ext$="LHA" @unlzh ENDIF IF ext$="zoo" OR ext$="ZOO" @unzoo ENDIF IF ext$="tar" OR ext$="TAR" @untar ENDIF IF ext$=".gz" OR ext$=".GZ" extmore$=RIGHT$(tail$,6) IF extmore$="tar.gz" OR extmore$="TAR.GZ" @untargz ELSE @gunzip ENDIF ENDIF IF ext$="tgz" OR ext$="TGZ" @untargz ENDIF IF ext$="bz2" OR ext$="BZ2" extmore$=RIGHT$(tail$,7) IF extmore$="tar.bz2" OR extmore$="TAR.BZ2" @untarbz2 ELSE @bunzip2 ENDIF ENDIF IF ext$="tbz" OR ext$="TBZ" @untarbz2 ENDIF END > PROCEDURE project_settings ' WARNING: The contents of this procedure should not be edited! ' INFO "GFA-Basic Editor v1.51 " ' DATE "03/13/2012" ' TIME "13:29:16" ' LIB$ "GBE Lib " ' LIB# $3 ' $CMD %00000000000000100000000000000001 ' $RAM $0001F400 ' FLGS %00010111 ' _SYM $0 ' .EXT "prg" ' OBJ0 " " ' OBJ1 " " ' OBJ2 " " ' OBJ3 " " ' OBJ4 " " ' OBJ5 " " ' CRSR $0000001B ' BLKS $FFFFFFFF ' BLKE $FFFFFFFF ' MRK0 $FFFFFFFF ' MRK1 $FFFFFFFF ' MRK2 $FFFFFFFF ' MRK3 $FFFFFFFF ' MRK4 $FFFFFFFF ' MRK5 $FFFFFFFF ' MRK6 $00000000 ' MRK7 $00000012 ' MRK8 $FFFFFFFF ' MRK9 $0000001B ' FIND '00 ' ' RPLC '00 ' ' FRH0 '00 ' ' FRH1 '00 ' ' FRH2 '00 ' ' FRH3 '00 ' ' FRH4 '00 ' ' FRH5 '00 ' ' FRH6 '00 ' ' FRH7 '00 ' ' FRH8 '00 ' ' FRH9 '00 ' ' PST0 '00 ' ' PST1 '00 ' ' UND0 '00 ' ' UND1 '00 ' ' CMD$ '00 ' ' ENV$ '00 ' RETURN PROCEDURE unzip ' this procedure calls the extracting programs with the appropriate parameters ' as choosen at the alert box ' RESERVE 124000 cmdl$=filename$+" -d "+folder$+CHR$(0) cmdl2$=filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ENDIF IF choice=2 EXEC 0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ' I should probably find a way to check whether the program completed succesfuly ' and not just write it ALERT 1,"Operation completed",1,"OK",ending END ' RESERVE RETURN PROCEDURE unrar ' RESERVE 400000 cmdl$="x "+filename$+" "+folder$+CHR$(0) cmdl2$="x "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\unrar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\unrar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE unlzh ' RESERVE 200000 cmdl$=filename$+" "+folder$+CHR$(0) cmdl2$="x "+"/x- "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\lharceng.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\lharceng.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE unzoo ' RESERVE 120000 cmdl$="x// "+filename$+CHR$(0) cmdl2$="x/ "+filename$+CHR$(0) IF choice=1 EXEC 0,progdir$+"arc\zoo.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\zoo.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation Completed",1,"OK",ending ' RESERVE RETURN PROCEDURE untar ' RESERVE 512000 cmdl$=" -xvf "+filename$+" -C"+folder$+CHR$(0) cmdl2$=" -xvf "+filename$+CHR$(0) IF choice=1 MKDIR folder$ EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE untargz @gunzip filetar$=LEFT$(filename$,LEN(filename$)-3) foldertar$=LEFT$(folder$,LEN(folder$)-4) cmdl$=" -xvf "+filetar$+" -C"+foldertar$+CHR$(0) cmdl2$=" -xvf "+filetar$+CHR$(0) IF choice=1 IF ext$="tgz" OR ext$="TGZ" ' **************special provisions for tgz************** MKDIR folder$ filetar$=filetar$+"tar" cmdl$=" -xvf "+filetar$+" -C"+folder$+CHR$(0) cmdl2$=" -xvf "+filetar$+CHR$(0) ' ********end of ugly hack*********** ELSE MKDIR foldertar$ ENDIF EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE gunzip ' RESERVE 512000 cmdl$=" -d "+filename$+CHR$(0) EXEC 0,progdir$+"arc\gunzip.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE untarbz2 @bunzip2 filetar$=LEFT$(filename$,LEN(filename$)-4) foldertar$=LEFT$(folder$,LEN(folder$)-5) PRINT filetar$ PRINT foldertar$ ' RESERVE 512000 cmdl$=" -xvf "+filetar$+" -C "+foldertar$+CHR$(0) cmdl2$=" -xvf "+filetar$+CHR$(0) IF choice=1 MKDIR foldertar$ EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ELSE EXEC 0,progdir$+"arc\tar.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"" ENDIF ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN PROCEDURE bunzip2 ' RESERVE 512000 cmdl$=" -d "+filename$+CHR$(0) EXEC 0,progdir$+"arc\bunzip2.ttp",CHR$(LEN(cmdl$))+cmdl$,"" ALERT 1,"Operation completed",1,"OK",ending ' RESERVE RETURN[/code] |
Title: Re: Quick Extract 0.5 source code. Post by ggn on 14.03.12 at 20:03:56
WTFPL \o/
In a more serious note, I had a quick glance over the source code and would like to make a few suggestions. They are more or less of aesthetic purposes, but maybe they will help Christos (or anyone else) in bigger projects. (hope they won't come out as too pretentious ;)) Code (]~SHEL_READ(cmd$,tail_str$) tail$=RIGHT$(tail_str$,(LEN(tail_str$)-1))[/code):
There, this must have saved at most 128 bytes of RAM :). Next up: Code (]IF ext$="zip" OR ext$="ZIP" @unzip ENDIF IF ext$="rar" OR ext$="RAR" @unrar ENDIF IF ext$="lzh" OR ext$="LZH" OR ext$="lha" OR ext$="LHA" @unlzh ENDIF IF ext$="zoo" OR ext$="ZOO" @unzoo ENDIF IF ext$="tar" OR ext$="TAR" @untar ENDIF ... etc [/code):
Finally you could also replace all ifs with select/case: Code (]select upper$(ext$) case "ZIP" @unzip case "RAR" @unrar case "LZH" @unlzh case"LHA" @unlzh case "ZOO" @unzoo case "TAR" @untar .... endselect[/code):
All those years I used the ~exec(...) syntax, i.e. discarding the program's exit code. You could use this to your advantage here: Code (]return&=EXEC(0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"") if return&=0 'program exited successfully else 'oops, something bad happened endif[/code):
Anyway, that's my xunty suggestions regarding the code. About program functionality now... How about if the program scanned (for example) for control pressed at startup and if that's true then extract the contents of the archive in a new folder and if (again for example) alt was pressed then it'd extract the contents in a new folder? That would (imho) reward frequent users with a more usable program, since they won't have to move the mouse to select an option they know by heart. |
Title: Re: Quick Extract 0.4 source code. Post by Christos on 15.03.12 at 02:35:21
He he, experience! ;)
Don't worry nothing seems pretentious and indeed it will look a lot better instead of the mess it is now. I am a bit worried in introducing new commands in case ( ;) )it breaks compatibility with the firebee but I will give it a shot for the next version. The exec trick i didn't know at all and that's a pretty good suggestion. Now that I see the code again i feel like I don't have to have the ending alert in all commands and I should just have one before the end.. That would save a few bytes in program size :D P.S. The power of really free software! |
D-Bug & Automation Forum » Powered by YaBB 2.6.0! YaBB Forum Software © 2000-2024. All Rights Reserved. |