12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns='http://www.w3.org/1999/xhtml'>
- <head>
- <title>Useful Headers</title>
- <meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r?) xhtml-backend" />
- <link rel="stylesheet" href="style.css" type='text/css' />
- </head>
- <body>
- <p><a href='AppendixD.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixF.html'>Next</a></p>
- <ul>
- <li><a class="btitle" href="AppendixE.html#headers"><b>Appendix E: </b>Useful Headers</a></li>
- <ul>
- <li><a href="AppendixE.html#filefunc">File Functions Header</a></li>
- <ul>
- <li><a href="AppendixE.html#E.1.1">Introduction</a></li>
- <li><a href="AppendixE.html#locate">Locate</a></li>
- <li><a href="AppendixE.html#getsize">GetSize</a></li>
- <li><a href="AppendixE.html#drivespace">DriveSpace</a></li>
- <li><a href="AppendixE.html#getdrives">GetDrives</a></li>
- <li><a href="AppendixE.html#gettime">GetTime</a></li>
- <li><a href="AppendixE.html#getfileattributes">GetFileAttributes</a></li>
- <li><a href="AppendixE.html#getfileversion">GetFileVersion</a></li>
- <li><a href="AppendixE.html#getexename">GetExeName</a></li>
- <li><a href="AppendixE.html#getexepath">GetExePath</a></li>
- <li><a href="AppendixE.html#getparameters">GetParameters</a></li>
- <li><a href="AppendixE.html#getoptions">GetOptions</a></li>
- <li><a href="AppendixE.html#getoptionss">GetOptionsS</a></li>
- <li><a href="AppendixE.html#getroot">GetRoot</a></li>
- <li><a href="AppendixE.html#getparent">GetParent</a></li>
- <li><a href="AppendixE.html#getfilename">GetFileName</a></li>
- <li><a href="AppendixE.html#getbasename">GetBaseName</a></li>
- <li><a href="AppendixE.html#getfileext">GetFileExt</a></li>
- <li><a href="AppendixE.html#bannertrimpath">BannerTrimPath</a></li>
- <li><a href="AppendixE.html#dirstate">DirState</a></li>
- <li><a href="AppendixE.html#refreshshellicons">RefreshShellIcons</a></li>
- </ul>
- <li><a href="AppendixE.html#textfunc">Text Functions Header</a></li>
- <ul>
- <li><a href="AppendixE.html#E.2.1">Introduction</a></li>
- <li><a href="AppendixE.html#linefind">LineFind</a></li>
- <li><a href="AppendixE.html#lineread">LineRead</a></li>
- <li><a href="AppendixE.html#filereadfromend">FileReadFromEnd</a></li>
- <li><a href="AppendixE.html#linesum">LineSum</a></li>
- <li><a href="AppendixE.html#filejoin">FileJoin</a></li>
- <li><a href="AppendixE.html#textcompare">TextCompare</a></li>
- <li><a href="AppendixE.html#textcompares">TextCompareS</a></li>
- <li><a href="AppendixE.html#configread">ConfigRead</a></li>
- <li><a href="AppendixE.html#configreads">ConfigReadS</a></li>
- <li><a href="AppendixE.html#configwrite">ConfigWrite</a></li>
- <li><a href="AppendixE.html#configwrites">ConfigWriteS</a></li>
- <li><a href="AppendixE.html#filerecode">FileRecode</a></li>
- <li><a href="AppendixE.html#trimnewlines">TrimNewLines</a></li>
- </ul>
- <li><a href="AppendixE.html#wordfunc">Word Functions Header</a></li>
- <ul>
- <li><a href="AppendixE.html#E.3.1">Introduction</a></li>
- <li><a href="AppendixE.html#wordfind">WordFind</a></li>
- <li><a href="AppendixE.html#wordfinds">WordFindS</a></li>
- <li><a href="AppendixE.html#wordfind2x">WordFind2X</a></li>
- <li><a href="AppendixE.html#wordfind2xs">WordFind2XS</a></li>
- <li><a href="AppendixE.html#wordfind3x">WordFind3X</a></li>
- <li><a href="AppendixE.html#wordfind3xs">WordFind3XS</a></li>
- <li><a href="AppendixE.html#wordreplace">WordReplace</a></li>
- <li><a href="AppendixE.html#wordreplaces">WordReplaceS</a></li>
- <li><a href="AppendixE.html#wordadd">WordAdd</a></li>
- <li><a href="AppendixE.html#wordadds">WordAddS</a></li>
- <li><a href="AppendixE.html#wordinsert">WordInsert</a></li>
- <li><a href="AppendixE.html#wordinserts">WordInsertS</a></li>
- <li><a href="AppendixE.html#strfilter">StrFilter</a></li>
- <li><a href="AppendixE.html#strfilters">StrFilterS</a></li>
- <li><a href="AppendixE.html#versioncompare">VersionCompare</a></li>
- <li><a href="AppendixE.html#versionconvert">VersionConvert</a></li>
- </ul>
- </ul>
- </ul>
- <a name="headers"></a><h1>Appendix E: Useful Headers</h1>
- <a name="filefunc"></a><h2>E.1 File Functions Header</h2>
- <a name="E.1.1"></a><h3>E.1.1 Introduction</h3>
- <p>Include header:</p>
- <pre>!include "FileFunc.nsh"
- </pre>
- <p>Call functions:</p>
- <pre>Section Install
- ${GetFileExt} "C:\My Downloads\Index.html" $R0
- ; $R0="html"
- SectionEnd
- </pre>
- <pre>Section un.Install
- ${GetParent} "C:\My Downloads\Index.html" $R0
- ; $R0="C:\My Downloads"
- SectionEnd
- </pre>
- <a name="locate"></a><h3>E.1.2 Locate</h3>
- <ul>
- <li>Find files, directories and empty directories with mask and size options.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${Locate} "[Path]" "[Options]" "Function"
- </pre>
- <pre>"[Path]" ; Disk or Directory
- ;
- "[Options]" ; /L=[FD|F|D|DE|FDE]
- ; /L=FD - Locate Files and Directories (default)
- ; /L=F - Locate Files only
- ; /L=D - Locate Directories only
- ; /L=DE - Locate Empty Directories only
- ; /L=FDE - Locate Files and Empty Directories
- ; /M=[mask]
- ; /M=*.* - Locate all (default)
- ; /M=*.doc - Locate Work.doc, 1.doc ...
- ; /M=Pho* - Locate PHOTOS, phone.txt ...
- ; /M=win???.exe - Locate winamp.exe, winver.exe ...
- ; /M=winamp.exe - Locate winamp.exe only
- ; /S=No:No[B|K|M|G]
- ; /S= - Don't locate file size (faster) (default)
- ; /S=0:0B - Locate only files of 0 Bytes exactly
- ; /S=5:9K - Locate only files of 5 to 9 Kilobytes
- ; /S=:10M - Locate only files of 10 Megabyte or less
- ; /S=1G - Locate only files of 1 Gigabyte or more
- ; /G=[1|0]
- ; /G=1 - Locate with subdirectories (default)
- ; /G=0 - Locate without subdirectories
- ; /B=[0|1]
- ; /B=0 - Banner isn't used (default)
- ; /B=1 - Banner is used. Callback when function
- ; start to search in new directory
- "Function" ; Callback function when found
- Function "Function"
- 	; $R9 "path\name"
- 	; $R8 "path"
- 	; $R7 "name"
- 	; $R6 "size" ($R6="" if directory, $R6="0" if file with /S=)
- 	; $R0-$R5 are not used (save data in them).
- 	; ...
- 	Push $var ; If $var="StopLocate" Then exit from function
- FunctionEnd
- </pre>
- <p><b>Note:</b> <br>- Error flag if disk or directory isn't exist <br>- Error flag if syntax error <br>- See also: <a href="http://nsis.sf.net/Locate_plugin">Locate plugin</a></p>
- <p><b>Example (Find one file):</b></p>
- <pre>Section
- 	${Locate} "C:\ftp" "/L=F /M=RPC DCOM.rar /S=1K" "Example1"
- 	; 'RPC DCOM.rar' file in 'C:\ftp' with size 1 Kb or more
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	MessageBox MB_OK "$$R0=$R0"
- SectionEnd
- Function Example1
- 	StrCpy $R0 $R9
- 	; $R0="C:\ftp\files\RPC DCOM.rar"
- 	MessageBox MB_YESNO '$R0$\n$\nFind next?' IDYES +2
- 	StrCpy $0 StopLocate
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Write results to a text file):</b></p>
- <pre>Section
- 	GetTempFileName $R0
- 	FileOpen $R1 $R0 w
- 	${Locate} "C:\ftp" "/S=:2M /G=0" "Example2"
- 	; folders and all files with size 2 Mb or less
- 	; don't scan subdirectories
- 	FileClose $R1
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec '"notepad.exe" "$R0"'
- SectionEnd
- Function Example2
- 	StrCmp $R6 '' 0 +3
- 	FileWrite $R1 "Directory=$R9$\r$\n"
- 	goto +2
- 	FileWrite $R1 "File=$R9 Size=$R6 Mb$\r$\n"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Write results to an INI file):</b></p>
- <pre>Section
- 	GetTempFileName $R0
- 	${Locate} "C:\ftp" "/L=F /S=0K" "Example3"
- 	; all files in 'C:\ftp' with size detect in Kb
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec '"notepad.exe" "$R0"'
- SectionEnd
- Function Example3
- 	WriteINIStr $R0 "$R8" "$R7" "$R6 Kb"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Delete empty directories):</b></p>
- <pre>Section
- 	StrCpy $R2 0
- 	StrCpy $R3 0
- 	loop:
- 	StrCpy $R1 0
- 	${Locate} "C:\ftp" "/L=DE" "Example4"
- 	IntOp $R3 $R3 + 1
- 	IntOp $R2 $R2 + $R1
- 	StrCmp $R0 StopLocate +2
- 	StrCmp $R1 0 0 loop
- 	IfErrors 0 +2
- 	MessageBox MB_OK 'error' IDOK +2
- 	MessageBox MB_OK '$R2 directories were removed$\n$R3 loops'
- SectionEnd
- Function Example4
- 	MessageBox MB_YESNOCANCEL 'Delete empty "$R9"?' IDNO end IDCANCEL cancel
- 	RMDir $R9
- 	IntOp $R1 $R1 + 1
- 	goto end
- 	cancel:
- 	StrCpy $R0 StopLocate
- 	end:
- 	Push $R0
- FunctionEnd
- </pre>
- <p><b>Example (Move all files into one folder):</b></p>
- <pre>Section
- 	StrCpy $R0 "C:\ftp" ;Directory move from
- 	StrCpy $R1 "C:\ftp2" ;Directory move into
- 	StrCpy $R2 0
- 	StrCpy $R3 0
- 	${Locate} "$R0" "/L=F" "Example5"
- 	IfErrors 0 +2
- 	MessageBox MB_OK 'error' IDOK +4
- 	StrCmp $R3 0 0 +2
- 	MessageBox MB_OK '$R2 files were moved' IDOK +2
- 	MessageBox MB_OK '$R2 files were moved$\n$R3 files were NOT moved'
- SectionEnd
- Function Example5
- 	StrCmp $R8 $R1 +6
- 	IfFileExists '$R1\$R7' +4
- 	Rename $R9 '$R1\$R7'
- 	IntOp $R2 $R2 + 1
- 	goto +2
- 	IntOp $R3 $R3 + 1
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Copy files with log):</b></p>
- <pre>Section
- 	StrCpy $R0 "C:\ftp" ;Directory copy from
- 	StrCpy $R1 "C:\ftp2" ;Directory copy into
- 	StrLen $R2 $R0
- 	GetTempFileName $0
- 	FileOpen $R3 $0 w
- 	${Locate} "$R0" "/L=FDE" "Example6"
- 	FileClose $R3
- 	IfErrors 0 +2
- 	MessageBox MB_OK 'error'
- 	Exec '"notepad.exe" "$0"' ;view log
- SectionEnd
- Function Example6
- 	StrCpy $1 $R8 '' $R2
- 	StrCmp $R6 '' 0 +3
- 	CreateDirectory '$R1$1\$R7'
- 	goto end
- 	CreateDirectory '$R1$1'
- 	CopyFiles /SILENT $R9 '$R1$1'
- 	IfFileExists '$R1$1\$R7' 0 +3
- 	FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -success$\r$\n"
- 	goto +2
- 	FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -failed$\r$\n"
- 	end:
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Recreate directory structure):</b></p>
- <pre>Section
- 	StrCpy $R0 "C:\ftp" ;Directory structure from
- 	StrCpy $R1 "C:\ftp2" ;Directory structure into
- 	StrLen $R2 $R0
- 	${Locate} "$R0" "/L=D" "Example7"
- 	IfErrors 0 +2
- 	MessageBox MB_OK 'error'
- SectionEnd
- Function Example7
- 	StrCpy $1 $R9 '' $R2
- 	CreateDirectory '$R1$1'
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Locate with banner - <a href="http://nsis.sourceforge.net/Nxs_plug-in">NxS plugin</a> required):</b></p>
- <pre>Section
- 	nxs::Show /NOUNLOAD `$(^Name) Setup` /top \
- 		`Setup searching something$\r$\nPlease wait... If you can..` \
- 		/h 1 /can 1 /end
- 	${Locate} "C:\WINDOWS" "/L=F /M=*.inf /B=1" "Example8"
- 	nxs::Destroy
- SectionEnd
- Function Example8
- 	StrCmp $R0 $R8 abortcheck
- 	StrCpy $R0 $R8
- 	nxs::Update /NOUNLOAD /sub "$R8" /pos 78 /end
- 	abortcheck:
- 	nxs::HasUserAborted /NOUNLOAD
- 	Pop $0
- 	StrCmp $0 1 0 +2
- 	StrCpy $0 StopLocate
- 	StrCmp $R9 '' end
- 	;...
- 	end:
- 	Push $0
- FunctionEnd
- </pre>
- <a name="getsize"></a><h3>E.1.3 GetSize</h3>
- <ul>
- <li>Find the size of a file, files mask or directory.</li><li>Find the sum of the files, directories and subdirectories.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetSize} "[Path]" "[Options]" $var1 $var2 $var3
- </pre>
- <pre>"[Path]" ; Disk or Directory
- ;
- "[Options]" ; /M=[mask]
- ; /M=*.* - Find all (default)
- ; /M=*.doc - Find Work.doc, 1.doc ...
- ; /M=Pho* - Find PHOTOS, phone.txt ...
- ; /M=win???.exe - Find winamp.exe, winver.exe ...
- ; /M=winamp.exe - Find winamp.exe only
- ; /S=No:No[B|K|M|G]
- ; /S= - Don't find file size (faster) (default)
- ; /S=0:0B - Find only files of 0 Bytes exactly
- ; /S=5:9K - Find only files of 5 to 9 Kilobytes
- ; /S=:10M - Find only files of 10 Megabyte or less
- ; /S=1G - Find only files of 1 Gigabyte or more
- ; /G=[1|0]
- ; /G=1 - Find with subdirectories (default)
- ; /G=0 - Find without subdirectories
- ;
- $var1 ; Result1: Size
- $var2 ; Result2: Sum of files
- $var3 ; Result3: Sum of directories
- </pre>
- <p><b>Note:</b> <br>- Error flag if disk or directory isn't exist <br>- Error flag if syntax error <br>- See also: <a href="http://nsis.sf.net/Locate_plugin">Locate plugin</a></p>
- <p><b>Examples:</b></p>
- <pre>Section 'Find file size of "$WINDIR\Explorer.exe" in KiB'
- 	${GetSize} "$WINDIR" "/M=Explorer.exe /S=0K /G=0" $0 $1 $2
- 	; $0="220" KiB
- 	; $1="1" files
- 	; $2="" directories
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- </pre>
- <pre>Section 'Find folder size of "C:\Installs\Drivers" in MiB'
- 	${GetSize} "C:\Installs\Drivers" "/S=0M" $0 $1 $2
- 	; $0="132" MiB
- 	; $1="555" files
- 	; $2="55" directories
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- </pre>
- <pre>Section 'Find sum of files and folders in "$WINDIR" (no subfolders)'
- 	${GetSize} "$WINDIR" "/G=0" $0 $1 $2
- 	; $0="" size
- 	; $1="253" files
- 	; $2="46" directories
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- </pre>
- <a name="drivespace"></a><h3>E.1.4 DriveSpace</h3>
- <ul>
- <li>Get total, occupied or free space of the drive.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${DriveSpace} "[Drive]" "[Options]" $var
- </pre>
- <pre>"[Drive]" ; Disk to check
- ;
- "[Options]" ; /D=[T|O|F]
- ; /D=T - Total space (default)
- ; /D=O - Occupied space
- ; /D=F - Free space
- ; /S=[B|K|M|G]
- ; /S=B - size in Bytes (default)
- ; /S=K - size in Kilobytes
- ; /S=M - size in Megabytes
- ; /S=G - size in Gigabytes
- ;
- $var ; Result: Size
- </pre>
- <p><b>Note:</b> <br>- Error flag if disk isn't exist or not ready <br>- Error flag if syntax error</p>
- <p><b>Example:</b></p>
- <pre>Section
- 	${DriveSpace} "C:\" "/D=F /S=M" $R0
- 	; $R0="2530" megabytes free on drive C:
- SectionEnd
- </pre>
- <a name="getdrives"></a><h3>E.1.5 GetDrives</h3>
- <ul>
- <li>Find all available drives in the system.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetDrives} "[Option]" "Function"
- </pre>
- <pre>"[Option]" ; [FDD+HDD+CDROM+NET+RAM]
- ; FDD Floppy Disk Drives
- ; HDD Hard Disk Drives
- ; CDROM CD-ROM Drives
- ; NET Network Drives
- ; RAM RAM Disk Drives
- ;
- ; [ALL]
- ; Find all drives by letter (default)
- ;
- "Function" ; Callback function when found
- Function "Function"
- 	; $9 "drive letter" (a:\ c:\ ...)
- 	; $8 "drive type" (FDD HDD ...)
- 	; $R0-$R9 are not used (save data in them).
- 	; ...
- 	Push $var ; If $var="StopGetDrives" Then exit from function
- FunctionEnd
- </pre>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${GetDrives} "FDD+CDROM" "Example1"
- SectionEnd
- Function Example1
- 	MessageBox MB_OK "$9 ($8 Drive)"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example2:</b></p>
- <pre>Section
- 	${GetDrives} "ALL" "Example2"
- SectionEnd
- Function Example2
- 	MessageBox MB_OK "$9 ($8 Drive)"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example3 (Get type of drive):</b></p>
- <pre>Section
- 	StrCpy $R0 "D:\" ;Drive letter
- 	StrCpy $R1 "invalid"
- 	${GetDrives} "ALL" "Example3"
- 	MessageBox MB_OK "Type of drive $R0 is $R1"
- SectionEnd
- Function Example3
- 	StrCmp $9 $R0 0 +3
- 	StrCpy $R1 $8
- 	StrCpy $0 StopGetDrives
- 	Push $0
- FunctionEnd
- </pre>
- <a name="gettime"></a><h3>E.1.6 GetTime</h3>
- <ul>
- <li>Get local or system time.</li><li>Get file time (access, creation and modification).</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetTime} "[File]" "[Option]" $var1 $var2 $var3 $var4 $var5 $var6 $var7
- </pre>
- <pre>"[File]" ; Ignored if "L" or "LS"
- ;
- "[Option]" ; [Options]
- ; L Local time
- ; A last Access file time
- ; C Creation file time
- ; M Modification file time
- ; LS System time (UTC)
- ; AS last Access file time (UTC)
- ; CS Creation file time (UTC)
- ; MS Modification file time (UTC)
- ;
- $var1 ; Result1: day
- $var2 ; Result2: month
- $var3 ; Result3: year
- $var4 ; Result4: day of week name
- $var5 ; Result5: hour
- $var6 ; Result6: minute
- $var7 ; Result7: seconds
- </pre>
- <p><b>Note:</b> <br>- Error flag if file isn't exist <br>- Error flag if syntax error <br>- See also: <a href="http://nsis.sf.net/Time_plugin">Time plugin</a></p>
- <p><b>Examples:</b></p>
- <pre>Section 'Get local time'
- 	${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
- 	; $0="01" day
- 	; $1="04" month
- 	; $2="2005" year
- 	; $3="Friday" day of week name
- 	; $4="16" hour
- 	; $5="05" minute
- 	; $6="50" seconds
- 	MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
- SectionEnd
- </pre>
- <pre>Section 'Get file time'
- 	${GetTime} "$WINDIR\Explorer.exe" "C" $0 $1 $2 $3 $4 $5 $6
- 	; $0="12" day
- 	; $1="10" month
- 	; $2="2004" year
- 	; $3="Tuesday" day of week name
- 	; $4="2" hour
- 	; $5="32" minute
- 	; $6="03" seconds
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
- SectionEnd
- </pre>
- <pre>Section 'Get system time'
- 	${GetTime} "" "LS" $0 $1 $2 $3 $4 $5 $6
- 	; $0="01" day
- 	; $1="04" month
- 	; $2="2005" year
- 	; $3="Friday" day of week name
- 	; $4="11" hour
- 	; $5="05" minute
- 	; $6="50" seconds
- 	MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6'
- SectionEnd
- </pre>
- <pre>Section 'Convert time to 12-hour format AM/PM'
- 	${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
- 	StrCmp $4 0 0 +3
- 	StrCpy $4 12
- 	goto +3
- 	StrCmp $4 12 +5
- 	IntCmp $4 12 0 0 +3
- 	StrCpy $7 AM
- 	goto +3
- 	IntOp $4 $4 - 12
- 	StrCpy $7 PM
- 	MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6 $7'
- SectionEnd
- </pre>
- <a name="getfileattributes"></a><h3>E.1.7 GetFileAttributes</h3>
- <ul>
- <li>Get attributes of file or directory.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetFileAttributes} "[File]" "[Attributes]" $var
- </pre>
- <pre>"[File]" ; File or directory
- ;
- "[Attributes]" ; "ALL" (default)
- ; -all attributes of file combined with "|" to output
- ;
- ; "READONLY|HIDDEN|SYSTEM|DIRECTORY|ARCHIVE|
- ; DEVICE|NORMAL|TEMPORARY|SPARSE_FILE|REPARSE_POINT|
- ; COMPRESSED|OFFLINE|NOT_CONTENT_INDEXED|ENCRYPTED"
- ; -file must have specified attributes
- ;
- $var ; Result:
- ; $var=attr1|attr2|... (if used "ALL")
- ; $var=1 file has specified attributes
- ; $var=0 file has no specified attributes
- </pre>
- <p><b>Note:</b> <br>- Error flag is set if file doesn't exist</p>
- <p><b>Example:</b></p>
- <pre>Section
- 	${GetFileAttributes} "C:\MSDOS.SYS" "ALL" $R0
- 	; $R0=READONLY|HIDDEN|SYSTEM|ARCHIVE
- 	${GetFileAttributes} "C:\MSDOS.SYS" "SYSTEM|HIDDEN" $R0
- 	; $R0=1
- 	${GetFileAttributes} "C:\MSDOS.SYS" "NORMAL" $R0
- 	; $R0=0
- SectionEnd
- </pre>
- <a name="getfileversion"></a><h3>E.1.8 GetFileVersion</h3>
- <ul>
- <li>Get version information from executable file.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetFileVersion} "[Executable]" $var
- </pre>
- <pre>"[Executable]" ; Executable file (*.exe *.dll ...)
- $var ; Result: Version number
- </pre>
- <p><b>Note:</b> <br>- Error flag if file doesn't exist <br>- Error flag if file doesn't contain version information</p>
- <p><b>Example:</b></p>
- <pre>${GetFileVersion} "C:\ftp\program.exe" $R0 ; $R0="1.1.0.12"
- </pre>
- <a name="getexename"></a><h3>E.1.9 GetExeName</h3>
- <ul>
- <li>Get installer filename (with valid case for Windows 98/Me).</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetExeName} $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetExeName} $R0 ; $R0="C:\ftp\program.exe"
- </pre>
- <a name="getexepath"></a><h3>E.1.10 GetExePath</h3>
- <ul>
- <li>Get installer pathname ($EXEDIR with valid case for Windows 98/Me).</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetExePath} $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetExePath} $R0 ; $R0="C:\ftp"
- </pre>
- <a name="getparameters"></a><h3>E.1.11 GetParameters</h3>
- <ul>
- <li>Get command line parameters.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetParameters} $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetParameters} $R0 ; $R0="[parameters]"
- </pre>
- <a name="getoptions"></a><h3>E.1.12 GetOptions</h3>
- <ul>
- <li>Get options from command line parameters.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetOptions} "[Parameters]" "[Option]" $var
- </pre>
- <pre>"[Parameters]" ; command line parameters
- ;
- "[Option]" ; option name
- ;
- $var ; Result: option string
- </pre>
- <p><b>Note:</b> <br>- The error flag is set if the option is not found <br>- The first character in the option string is treated as a parameter delimiter</p>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${GetOptions} "/S /T" "/T" $R0
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Not found" IDOK +2
- 	MessageBox MB_OK "Found"
- SectionEnd
- </pre>
- <p><b>Example2:</b></p>
- <pre>Section
- 	${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0
- 	;$R0=C:\Program Files\Common Files
- SectionEnd
- </pre>
- <p><b>Example3:</b></p>
- <pre>Section
- 	${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0
- 	;$R0=C:/Program Files/Common Files
- SectionEnd
- </pre>
- <p><b>Example4:</b></p>
- <pre>Section
- 	${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"' -ADMIN=password` "-INSTDIR=" $R0
- 	;$R0="C:/Program Files/Common Files"
- SectionEnd
- </pre>
- <a name="getoptionss"></a><h3>E.1.13 GetOptionsS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#getoptions">GetOptions</a>, but case sensitive.</li></ul>
- <a name="getroot"></a><h3>E.1.14 GetRoot</h3>
- <ul>
- <li>Get root directory.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetRoot} "[FullPath]" $var
- </pre>
- <p><b>Examples:</b></p>
- <pre>${GetRoot} "C:\Program Files\NSIS" $R0 ; $R0="C:"
- ${GetRoot} "\\SuperPimp\NSIS\Source\exehead\Ui.c" $R0 ; $R0="\\SuperPimp\NSIS"
- </pre>
- <a name="getparent"></a><h3>E.1.15 GetParent</h3>
- <ul>
- <li>Get parent directory.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetParent} "[PathString]" $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetParent} "C:\Program Files\Winamp\uninstwa.exe" $R0 ; $R0="C:\Program Files\Winamp"
- </pre>
- <a name="getfilename"></a><h3>E.1.16 GetFileName</h3>
- <ul>
- <li>Get last part from directory path.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetFileName} "[PathString]" $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetFileName} "C:\Program Files\Winamp\uninstwa.exe" $R0 ; $R0="uninstwa.exe"
- </pre>
- <a name="getbasename"></a><h3>E.1.17 GetBaseName</h3>
- <ul>
- <li>Get file name without extension.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetBaseName} "[FileString]" $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetBaseName} "C:\ftp\program.exe" $R0 ; $R0="program"
- </pre>
- <a name="getfileext"></a><h3>E.1.18 GetFileExt</h3>
- <ul>
- <li>Get extension of file.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${GetFileExt} "[FileString]" $var
- </pre>
- <p><b>Example:</b></p>
- <pre>${GetFileExt} "C:\ftp\program.exe" $R0 ; $R0="exe"
- </pre>
- <a name="bannertrimpath"></a><h3>E.1.19 BannerTrimPath</h3>
- <ul>
- <li>Trim string path for banner.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${BannerTrimPath} "[PathString]" "[Option]" $var
- </pre>
- <pre>"[PathString]" ;
- ;
- "[Option]" ; [Length][A|B|C|D]
- ;
- ; Length -Maximum string length
- ; A -Trim center path (default)
- ; (C:\root\...\third path)
- ; If A mode not possible Then will be used B mode
- ; B -Trim right path
- ; (C:\root\second path\...)
- ; If B mode not possible Then will be used C mode
- ; C -Trim right string
- ; (C:\root\second path\third p...)
- ; D -Trim right string + filename
- ; (C:\root\second p...\third path)
- ; If D mode not possible Then will be used C mode
- ;
- $var ; Result: Trimmed path
- </pre>
- <p><b>Example:</b></p>
- <pre>Section
- 	${BannerTrimPath} "C:\Server\Documents\Terminal\license.htm" "35A" $R0
- 	;$R0=C:\Server\...\Terminal\license.htm
- SectionEnd
- </pre>
- <p><b>Example (Banner plugin):</b></p>
- <pre>!include "WinMessages.nsh"
- !include "FileFunc.nsh"
- Section
- 	Banner::show "Starting..."
- 	Banner::getWindow
- 	Pop $R1
- 	${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback"
- 	Banner::destroy
- SectionEnd
- Function LocateCallback
- 	StrCmp $R0 $R8 code
- 	StrCpy $R0 $R8
- 	${BannerTrimPath} "$R8" "38B" $R8
- 	GetDlgItem $1 $R1 1030
- 	SendMessage $1 ${WM_SETTEXT} 0 "STR:$R8"
- 	code:
- 	StrCmp $R9 '' end
- 	;...
- 	end:
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (<a href="http://nsis.sourceforge.net/Nxs_plug-in">NxS plugin</a>):</b></p>
- <pre>!include "FileFunc.nsh"
- Section
- 	nxs::Show /NOUNLOAD `$(^Name) Setup`\
- 	 /top `Setup searching something$\nPlease wait$\nIf you can...`\
- 	 /h 1 /can 1 /end
- 	${Locate} "$WINDIR" "/L=F /M=*.* /B=1" "LocateCallback"
- 	nxs::Destroy
- SectionEnd
- Function LocateCallback
- 	StrCmp $R0 $R8 abortcheck
- 	StrCpy $R0 $R8
- 	${BannerTrimPath} "$R8" "55A" $R8
- 	nxs::Update /NOUNLOAD /sub "$R8" /pos 78 /end
- 	abortcheck:
- 	nxs::HasUserAborted /NOUNLOAD
- 	Pop $0
- 	StrCmp $0 1 0 +2
- 	StrCpy $0 StopLocate
- 	StrCmp $R9 '' end
- 	;...
- 	end:
- 	Push $0
- FunctionEnd
- </pre>
- <a name="dirstate"></a><h3>E.1.20 DirState</h3>
- <ul>
- <li>Check directory full, empty or not exist.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${DirState} "[path]" $var
- </pre>
- <pre>"[path]" ; Directory
- $var ; Result:
- ; $var=0 (empty)
- ; $var=1 (full)
- ; $var=-1 (directory not found)
- </pre>
- <p><b>Example:</b></p>
- <pre>${DirState} "$TEMP" $R0 ; $R0="1" (directory is full)
- </pre>
- <a name="refreshshellicons"></a><h3>E.1.21 RefreshShellIcons</h3>
- <ul>
- <li>After changing file associations, you can call this function to refresh the shell immediately.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${RefreshShellIcons}
- </pre>
- <p><b>Example:</b></p>
- <pre>Section
- 	WriteRegStr HKCR "Winamp.File\DefaultIcon" "" "$INSTDIR\WINAMP.EXE,2"
- 	${RefreshShellIcons}
- SectionEnd
- </pre>
- <a name="textfunc"></a><h2>E.2 Text Functions Header</h2>
- <a name="E.2.1"></a><h3>E.2.1 Introduction</h3>
- <p>Include header:</p>
- <pre>!include "TextFunc.nsh"
- </pre>
- <p>Call functions:</p>
- <pre>Section Install
- 	${LineRead} "C:\a.log" "-1" $R0
- 	; $R0="Last line$\r$\n"
- SectionEnd
- </pre>
- <pre>Section un.Install
- 	${TrimNewLines} "Last line$\r$\n" $R0
- 	; $R0="Last line"
- SectionEnd
- </pre>
- <a name="linefind"></a><h3>E.2.2 LineFind</h3>
- <ul>
- <li>Find specified lines in text file, and edit or view these lines in callback function.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${LineFind} "[File1]" "[File2|/NUL]" "[LineNumbers]" "Function"
- </pre>
- <pre>"[File1]" ; Input text file
- ;
- "[File2|/NUL]" ; [File2]
- ; Output text file
- ; If empty then File2=File1
- ; [/NUL]
- ; No output text file (only read File1)
- ;
- "[LineNumbers]" ; [No|-No|No:No|{No}|{-No}|{No:No}]
- ; 1:-1 all lines to change (default)
- ; 2 second line from start
- ; -3 third line from end
- ; 5:9 range of lines from 5 to 9
- ; {2} only second line from start to output
- ; {-3} only third line from end to output
- ; {5:9} only range of lines from 5 to 9 to output
- ;
- "Function" ; Callback function for specified lines
- Function "Function"
- 	; $R9 current line
- 	; $R8 current line number
- 	; $R7 current line negative number
- 	; $R6 current range of lines
- 	; $R5 handle of a file opened to read
- 	; $R4 handle of a file opened to write ($R4="" if "/NUL")
- 	; you can use any string functions
- 	; $R0-$R3 are not used (save data in them).
- 	; ...
- 	Push $var ; If $var="StopLineFind" Then exit from function
- 	 ; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
- FunctionEnd
- </pre>
- <p><b>Note:</b> <br>- Error flag if input file doesn't exist <br>- Error flag if output file path doesn't exist <br>- Ranges must be specified on growth (2 4:5 9:-8 -5:-4 -2:-1) <br>- Output file will not be updated if no changes made.</p>
- <p><b>Example1 (delete first two symbols):</b></p>
- <pre>Section
- 	${LineFind} "C:\a.log" "C:\a-edited.log" "3:-1" "Example1"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example1
- 	${TrimNewLines} '$R9' $R9
- 	StrCpy $R9 $R9 '' 2
- 	StrCpy $R9 '$R9$\r$\n'
- 	;start from 3 line and delete first two symbols
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example2 (show changed lines):</b></p>
- <pre>Section
- 	${LineFind} "C:\a.log" "a.log" "{5:12 15 -6:-5 -1}" "Example2"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example2
- 	${TrimNewLines} '$R9' $R9
- 	StrCpy $R9 "$R9 ~Changed line ($R8)~$\r$\n"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example3 (delete lines):</b></p>
- <pre>Section
- 	${LineFind} "C:\a.log" "\logs\a.log" "2:3 10:-5 -3:-2" "Example3"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example3
- 	StrCpy $0 SkipWrite
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example4 (insert lines):</b></p>
- <pre>Section
- 	${LineFind} "C:\a.log" "" "10" "Example4
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example4
- 	FileWrite $R4 "---First Line---$\r$\n"
- 	FileWrite $R4 "---Second Line ...---$\r$\n"
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example5 (replace in file with count of changes - "WordFunc.nsh" required):</b></p>
- <pre>!include "WordFunc.nsh"
- Section
- 	StrCpy $R0 0
- 	${LineFind} "C:\a.log" "C:\logs\a.log" "1:-1" "Example5"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	MessageBox MB_OK "Changed lines=$R0"
- SectionEnd
- Function Example5
- 	StrCpy $1 $R9
- 	${WordReplace} '$R9' ' ' '_' '+*' $R9
- 	StrCmp $1 $R9 +2
- 	IntOp $R0 $R0 + 1
- 	;$R0 count of changed lines
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example6 (line string to cut or delete):</b></p>
- <pre>Section
- 	${LineFind} "\a.log" "C:\logs\a.log" "" "Example6"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	MessageBox MB_OK "Processed lines=$R1:$R2"
- SectionEnd
- Function Example6
- 	;(Cut lines from a line to another line (also including that line))
- 	StrCmp $R0 finish stop
- 	StrCmp $R0 start finish
- 	StrCmp $R9 'Start Line$\r$\n' 0 skip
- 	StrCpy $R0 start
- 	StrCpy $R1 $R8
- 	goto code
- 	finish:
- 	StrCmp $R9 'Finish Line$\r$\n' 0 code
- 	StrCpy $R0 finish
- 	StrCpy $R2 $R8
- 	goto code
- 	skip:
- 	StrCpy $0 SkipWrite
- 	goto output
- 	stop:
- 	StrCpy $0 StopLineFind
- 	goto output
- 	;;(Delete lines from a line to another line (also including that line))
- 	; StrCmp $R0 finish code
- 	; StrCmp $R0 start finish
- 	; StrCmp $R9 'Start Line$\r$\n' 0 code
- 	; StrCpy $R0 start
- 	; StrCpy $R1 $R8
- 	; goto skip
- 	; finish:
- 	; StrCmp $R9 'Finish Line$\r$\n' 0 skip
- 	; StrCpy $R0 finish
- 	; StrCpy $R2 $R8
- 	; skip:
- 	; StrCpy $0 SkipWrite
- 	; goto output
- 	code:
- 	;...
- 	output:
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example7 (read lines):</b></p>
- <pre>Section
- 	${LineFind} "C:\a.log" "/NUL" "1:-1" "Example7"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example7
- 	MessageBox MB_OKCANCEL '$$R9 "Line"=[$R9]$\n$$R8 "#" =[$R8]' IDOK +2
- 	StrCpy $0 StopLineFind
- 	Push $0
- FunctionEnd
- </pre>
- <a name="lineread"></a><h3>E.2.3 LineRead</h3>
- <ul>
- <li>Get line in file specified with number.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${LineRead} "[File]" "[LineNumber]" $var
- </pre>
- <pre>"[File]" ; Input text file
- ;
- "[LineNumber]" ; [No|-No]
- ; 3 line number from start
- ; -5 line number from end
- ;
- $var ; Result: Line
- </pre>
- <p><b>Note:</b> <br>- Error flag if input file doesn't exist <br>- Error flag if line number not found</p>
- <p><b>Example:</b></p>
- <pre>Section
- 	${LineRead} "C:\a.log" "-1" $R0
- 	; $R0="Last line$\r$\n"
- SectionEnd
- </pre>
- <a name="filereadfromend"></a><h3>E.2.4 FileReadFromEnd</h3>
- <ul>
- <li>Read text file from end line by line.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${FileReadFromEnd} "[File]" "Function"
- </pre>
- <pre>"[File]" ; Input text file
- "Function" ; Callback function
- Function "Function"
- 	; $9 current line
- 	; $8 current line number
- 	; $7 current line negative number
- 	; $R0-$R9 are not used (save data in them).
- 	; ...
- 	Push $var ; If $var="StopFileReadFromEnd" Then exit from function
- FunctionEnd
- </pre>
- <p><b>Note:</b> <br>- Error flag if input file doesn't exist</p>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${FileReadFromEnd} "C:\a.log" "Example1"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example1
- 	MessageBox MB_OKCANCEL '"Line"=[$9]$\n "#"=[$8]$\n "-#"=[$7]' IDOK +2
- 	StrCpy $0 StopFileReadFromEnd
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example2 (Reverse text file):</b></p>
- <pre>Section
- 	GetTempFileName $R0
- 	FileOpen $R1 $R0 w
- 	${FileReadFromEnd} "C:\a.log" "Example2"
- 	FileClose $R1
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec '"notepad.exe" "$R0"'
- SectionEnd
- Function Example2
- 	StrCmp $7 -1 0 +5
- 	StrCpy $1 $9 1 -1
- 	StrCmp $1 '$\n' +3
- 	StrCmp $1 '$\r' +2
- 	StrCpy $9 '$9$\r$\n'
- 	FileWrite $R1 "$9"
- 	Push $0
- FunctionEnd
- </pre>
- <a name="linesum"></a><h3>E.2.5 LineSum</h3>
- <ul>
- <li>Get sum of lines in text file.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${LineSum} "[File]" $var
- </pre>
- <pre>"[File]" ; Input file
- $var ; Result: Sum of lines
- </pre>
- <p><b>Note:</b> <br>- Error flag if input file doesn't exist</p>
- <p><b>Example:</b></p>
- <pre>Section
- 	${LineSum} "C:\a.log" $R0
- 	; $R0="54"
- SectionEnd
- </pre>
- <a name="filejoin"></a><h3>E.2.6 FileJoin</h3>
- <ul>
- <li>Join two files in one (File1 + File2 = File3).</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${FileJoin} "[File1]" "[File2]" "[File3]"
- </pre>
- <pre>"[File1]" ; Input File1
- "[File2]" ; Input File2
- "[File3]" ; Output File3
- ; If [File3]="" Then add [File2] to [File1]
- </pre>
- <p><b>Note:</b> <br>- Error flag if input files don't exist <br>- Error flag if output file path doesn't exist</p>
- <p><b>Example1 (Join: a.log + b.log = Z.log):</b></p>
- <pre>Section
- 	${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\Z.log"
- SectionEnd
- </pre>
- <p><b>Example2 (Add: a.log + b.log = a.log):</b></p>
- <pre>Section
- 	${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\a.log"
- SectionEnd
- </pre>
- <a name="textcompare"></a><h3>E.2.7 TextCompare</h3>
- <ul>
- <li>Compare two text files.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${TextCompare} "[File1]" "[File2]" "[Option]" "Function"
- </pre>
- <pre>"[File1]" ; File1 Compare these lines
- "[File2]" ; File2 Compare with these lines
- "[Options]" ; (line-by-line):
- ; FastDiff Compare line N (File1) with line N (File2)
- ; Call function if Different lines found
- ; FastEqual Compare line N (File1) with line N (File2)
- ; Call function if Equal lines found
- ; (line number independent):
- ; SlowDiff Compare line N (File1) with all lines (File2)
- ; Call function if line N (File1) Different
- ; SlowEqual Compare line N (File1) with all lines (File2)
- ; Call function if line N (File1) Equal
- "Function" ; Callback function
- Function "Function"
- 	; $9 "Line File1"
- 	; $8 "Line number"
- 	; $7 "Line File2" (empty if SlowDiff)
- 	; $6 "Line number" (empty if SlowDiff)
- 	; $R0-$R9 are not used (save data in them).
- 	; ...
- 	Push $var ; If $var="StopTextCompare" Then exit from function
- FunctionEnd
- </pre>
- <p><b>Note:</b> <br>- Error flag if File1 or File2 doesn't exist <br>- Error flag if syntax error</p>
- <p><b>Example (Different or Equal):</b></p>
- <pre>Section
- 	StrCpy $R0 ''
- 	${TextCompare} "C:\1.txt" "C:\2.txt" "FastDiff" "Example1"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +4
- 	StrCmp $R0 NotEqual 0 +2
- 	MessageBox MB_OK "Files differ" IDOK +2
- 	MessageBox MB_OK "Files identical"
- SectionEnd
- Function Example1
- 	StrCpy $R0 NotEqual
- 	StrCpy $0 StopTextCompare
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Compare line-by-line - Different):</b></p>
- <pre>Section
- 	StrCpy $R0 'Text1.txt'
- 	StrCpy $R1 'Text2.txt'
- 	GetTempFileName $R2
- 	FileOpen $R3 $R2 w
- 	FileWrite $R3 "$R0 | $R1$\r$\n"
- 	${TextCompare} "$R0" "$R1" "FastDiff" "Example2"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec "notepad.exe $R2"
- FunctionEnd
- Function Example2
- 	FileWrite $R3 '$8=$9'
- 	FileWrite $R3 '$6=$7$\r$\n'
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Compare line-by-line - Equal):</b></p>
- <pre>Section
- 	StrCpy $R0 'Text1.txt'
- 	StrCpy $R1 'Text2.txt'
- 	GetTempFileName $R2
- 	FileOpen $R3 $R2 w
- 	FileWrite $R3 "$R0 | $R1$\r$\n"
- 	${TextCompare} "$R0" "$R1" "FastEqual" "Example3"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec "notepad.exe $R2"
- FunctionEnd
- Function Example3
- 	FileWrite $R3 '$8|$6=$9'
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Compare all lines - Different):</b></p>
- <pre>Section
- 	StrCpy $R0 'Text1.txt'
- 	StrCpy $R1 'Text2.txt'
- 	GetTempFileName $R2
- 	FileOpen $R3 $R2 w
- 	FileWrite $R3 "$R0 | $R1$\r$\n"
- 	${TextCompare} "$R0" "$R1" "SlowDiff" "Example4"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK end
- 	FileWrite $R3 "$\r$\n$R1 | $R0$\r$\n"
- 	${TextCompare} "$R1" "$R0" "SlowDiff" "Example4"
- 	FileClose $R3
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK end
- 	Exec "notepad.exe $R2"
- 	end:
- FunctionEnd
- Function Example4
- 	FileWrite $R3 '$8=$9'
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Compare all lines - Equal):</b></p>
- <pre>Section
- 	StrCpy $R0 'Text1.txt'
- 	StrCpy $R1 'Text2.txt'
- 	GetTempFileName $R2
- 	FileOpen $R3 $R2 w
- 	FileWrite $R3 "$R0 | $R1$\r$\n"
- 	${TextCompare} "$R0" "$R1" "SlowEqual" "Example5"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error" IDOK +2
- 	Exec "notepad.exe $R2"
- FunctionEnd
- Function Example5
- 	FileWrite $R3 '$8|$6=$9'
- 	Push $0
- FunctionEnd
- </pre>
- <p><b>Example (Show variables):</b></p>
- <pre>Section
- 	${TextCompare} "C:\1.txt" "C:\2.txt" "FastDiff" "Example6"
- 	IfErrors 0 +2
- 	MessageBox MB_OK "Error"
- SectionEnd
- Function Example6
- 	MessageBox MB_OKCANCEL '\
- 		$$9 "Line File1" =[$9]$\n\
- 		$$8 "Line #" =[$8]$\n\
- 		$$7 "Line File2" =[$7]$\n\
- 		$$6 "Line #" =[$6]'\
- 		IDOK +2
- 	StrCpy $0 StopTextCompare
- 	Push $0
- FunctionEnd
- </pre>
- <a name="textcompares"></a><h3>E.2.8 TextCompareS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#textcompare">TextCompare</a>, but case sensitive.</li></ul>
- <a name="configread"></a><h3>E.2.9 ConfigRead</h3>
- <ul>
- <li>Read value from entry name in config file.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${ConfigRead} "[File]" "[Entry]" $var
- </pre>
- <pre>"[File]" ; config file
- ;
- "[Entry]" ; entry name
- ;
- $var ; Result: Value
- </pre>
- <p><b>Note:</b> <br>- Error flag if entry not found <br>- Error flag if file doesn't exist</p>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${ConfigRead} "C:\AUTOEXEC.BAT" "SET winbootdir=" $R0
- 	;$R0=C:\WINDOWS
- SectionEnd
- </pre>
- <p><b>Example2:</b></p>
- <pre>Section
- 	${ConfigRead} "C:\apache\conf\httpd.conf" "Timeout " $R0
- 	;$R0=30
- SectionEnd
- </pre>
- <a name="configreads"></a><h3>E.2.10 ConfigReadS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#configread">ConfigRead</a>, but case sensitive.</li></ul>
- <a name="configwrite"></a><h3>E.2.11 ConfigWrite</h3>
- <ul>
- <li>Write value from entry name in config file.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${ConfigWrite} "[File]" "[Entry]" "[Value]" $var
- </pre>
- <pre>"[File]" ; config file
- ;
- "[Entry]" ; entry name
- ;
- "[Value]" ; value name
- ; if "" then delete Entry
- ;
- $var ; Result:
- ; $var=CHANGED Value is written
- ; $var=DELETED Entry is deleted
- ; $var=ADDED Entry and Value are added
- ; $var=SAME Entry and Value already exist
- </pre>
- <p><b>Note:</b> <br>- Error flag if file doesn't exist <br>- Error flag if file can't be opened</p>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${ConfigWrite} "C:\AUTOEXEC.BAT" "SET winbootdir=" "D:\WINDOWS" $R0
- 	;$R0=CHANGED
- SectionEnd
- </pre>
- <p><b>Example2:</b></p>
- <pre>Section
- 	${ConfigWrite} "C:\apache\conf\httpd.conf" "Timeout " "30" $R0
- 	;$R0=SAME
- SectionEnd
- </pre>
- <p><b>Example3:</b></p>
- <pre>Section
- 	${ConfigWrite} "C:\apache\conf\httpd.conf" "Timeout " "" $R0
- 	;$R0=DELETED
- SectionEnd
- </pre>
- <a name="configwrites"></a><h3>E.2.12 ConfigWriteS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#configwrite">ConfigWrite</a>, but case sensitive.</li></ul>
- <a name="filerecode"></a><h3>E.2.13 FileRecode</h3>
- <ul>
- <li>Recode text file from DOS to Windows format and vice-versa.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${FileRecode} "[File]" "[Format]"
- </pre>
- <pre>"[File]" ;
- ;
- "[Format]" ; OemToChar -from DOS to Windows
- ; CharToOem -from Windows to DOS
- </pre>
- <p><b>Note:</b> <br>- Error flag if file doesn't exist <br>- Error flag if syntax error</p>
- <p><b>Example:</b></p>
- <pre>Section
- 	${FileRecode} "C:\SCANDISK.LOG" "CharToOem"
- SectionEnd
- </pre>
- <a name="trimnewlines"></a><h3>E.2.14 TrimNewLines</h3>
- <ul>
- <li>Trim newlines in a string.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${TrimNewLines} "[string]" $var
- </pre>
- <pre>"[string]" ; Input string
- $var ; Result: String without '$\r' and '$\n' at the end
- </pre>
- <p><b>Example:</b></p>
- <pre>Section
- 	${TrimNewLines} "Text line$\r$\n" $R0
- 	; $R0="Text line"
- SectionEnd
- </pre>
- <a name="wordfunc"></a><h2>E.3 Word Functions Header</h2>
- <a name="E.3.1"></a><h3>E.3.1 Introduction</h3>
- <p>Include header:</p>
- <pre>!include "WordFunc.nsh"
- </pre>
- <p>Call functions:</p>
- <pre>Section Install
- 	${WordFind} "A--H---S" "-" "+2" $R0
- 	; $R0="H"
- SectionEnd
- </pre>
- <pre>Section un.Install
- 	${WordReplace} "A--H---S" "-" "x" "+3*" $R0
- 	; $R0="A--HxS"
- SectionEnd
- </pre>
- <a name="wordfind"></a><h3>E.3.2 WordFind</h3>
- <ul>
- <li>Multi-features string function.</li></ul>
- <pre>Strings:
- "[word+1][delimiter][word+2][delimiter][word+3]..."
- "[delimiter][word+1][delimiter][word+2][delimiter]..."
- "[delimiter][delimiter][word+1][delimiter][delimiter][delimiter]..."
- "...[word-3][delimiter][word-2][delimiter][word-1]"
- "...[delimiter][word-2][delimiter][word-1][delimiter]"
- "...[delimiter][delimiter][word-1][delimiter][delimiter][delimiter]"
- </pre>
- <p><b>Syntax: </b></p>
- <pre>${WordFind} "[string]" "[delimiter]" "[E][options]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- "[delimiter]" ;[delimiter]
- ; one or several symbols
- "[E][options]" ;[options]
- ; +number : word number from start
- ; -number : word number from end
- ; +number} : delimiter number from start
- ; all space after this
- ; delimiter to output
- ; +number{ : delimiter number from start
- ; all space before this
- ; delimiter to output
- ; +number}} : word number from start
- ; all space after this word
- ; to output
- ; +number{{ : word number from start
- ; all space before this word
- ; to output
- ; +number{} : word number from start
- ; all space before and after
- ; this word (word exclude)
- ; +number*} : word number from start
- ; all space after this
- ; word to output with word
- ; +number{* : word number from start
- ; all space before this
- ; word to output with word
- ; # : sum of words to output
- ; * : sum of delimiters to output
- ; /word : number of word to output
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 delimiter not found
- ; $var=2 no such word number
- ; $var=3 syntax error (Use: +1,-1},#,*,/word,...)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Note:</b> <br>- Accepted numbers 1,01,001,...</p>
- <p><b>Example (Find word by number):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " C:\" "-02" $R0
- 	; $R0="Program Files"
- SectionEnd
- </pre>
- <p><b>Example (Delimiter exclude):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "-2}" $R0
- 	; $R0=" C:\logo.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (Sum of words):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " C:\" "#" $R0
- 	; $R0="3"
- SectionEnd
- </pre>
- <p><b>Example (Sum of delimiters):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "*" $R0
- 	; $R0="2"
- SectionEnd
- </pre>
- <p><b>Example (Find word number):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " " "/Files" $R0
- 	; $R0="3"
- SectionEnd
- </pre>
- <p><b>Example ( }} ):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2}}" $R0
- 	; $R0=" C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example ( {} ):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2{}" $R0
- 	; $R0="C:\io.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example ( *} ):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2*}" $R0
- 	; $R0="C:\logo.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (Get parent directory):</b></p>
- <pre>Section
- 	StrCpy $R0 "C:\Program Files\NSIS\NSIS.chm"
- ;	 "C:\Program Files\NSIS\Include\"
- ;	 "C:\\Program Files\\NSIS\\NSIS.chm"
- 	${WordFind} "$R0" "\" "-2{*" $R0
- 	; $R0="C:\Program Files\NSIS"
- 	; "C:\\Program Files\\NSIS"
- SectionEnd
- </pre>
- <p><b>Example (Coordinates):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" ":\lo" "E+1{" $R0
- 	; $R0="C:\io.sys C"
- 	IfErrors end
- 	StrLen $0 $R0 ; $0 = Start position of word (11)
- 	StrLen $1 ':\lo' ; $1 = Word length (4)
- 	; StrCpy $R0 $R1 $1 $0 ; $R0 = :\lo
- 	end:
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordFind} "[string]" "[delimiter]" "E[options]" $R0
- 	IfErrors 0 end
- 	StrCmp $R0 1 0 +2 ; errorlevel 1?
- 	MessageBox MB_OK 'delimiter not found' IDOK end
- 	StrCmp $R0 2 0 +2 ; errorlevel 2?
- 	MessageBox MB_OK 'no such word number' IDOK end
- 	StrCmp $R0 3 0 +2 ; errorlevel 3?
- 	MessageBox MB_OK 'syntax error'
- 	end:
- SectionEnd
- </pre>
- <p><b>Example (Without errorlevel output):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys" "_" "+1" $R0
- 	; $R0="C:\io.sys C:\logo.sys" (error: delimiter "_" not found)
- SectionEnd
- </pre>
- <p><b>Example (If found):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "E+1{" $R0
- 	IfErrors notfound found
- 	found:
- 	MessageBox MB_OK 'Found' IDOK end
- 	notfound:
- 	MessageBox MB_OK 'Not found'
- 	end:
- SectionEnd
- </pre>
- <p><b>Example (If found 2):</b></p>
- <pre>Section
- 	${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "+1{" $R0
- 	StrCmp $R0 "C:\io.sys C:\logo.sys" notfound found ; error?
- 	found:
- 	MessageBox MB_OK 'Found' IDOK end
- 	notfound:
- 	MessageBox MB_OK 'Not found'
- 	end:
- SectionEnd
- </pre>
- <p><b>Example (To accept one word in string if delimiter not found):</b></p>
- <pre>Section
- 	StrCpy $0 'OneWord'
- 	StrCpy $1 1
- 	loop:
- 	${WordFind} "$0" " " "E+$1" $R0
- 	IfErrors 0 code
- 	StrCmp $1$R0 11 0 error
- 	StrCpy $R0 $0
- 	goto end
- 	code:
- 	; ...
- 	IntOp $1 $1 + 1
- 	goto loop
- 	error:
- 	StrCpy $1 ''
- 	StrCpy $R0 ''
- 	end:
- 	; $R0="OneWord"
- SectionEnd
- </pre>
- <a name="wordfinds"></a><h3>E.3.3 WordFindS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordfind">WordFind</a>, but case sensitive.</li></ul>
- <a name="wordfind2x"></a><h3>E.3.4 WordFind2X</h3>
- <ul>
- <li>Find word between two delimiters.</li></ul>
- <pre>Strings:
- "[delimiter1][word+1][delimiter2][delimiter1][word+2][delimiter2]..."
- "[text][delimiter1][text][delimiter1][word+1][delimiter2][text]..."
- "...[delimiter1][word-2][delimiter2][delimiter1][word-1][delimiter2]"
- "...[text][delimiter1][text][delimiter1][word-1][delimiter2][text]"
- </pre>
- <p><b>Syntax:</b></p>
- <pre>${WordFind2X} "[string]" "[delimiter1]" "[delimiter2]" "[E][options]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- "[delimiter1]" ;[delimiter1]
- ; first delimiter
- "[delimiter2]" ;[delimiter2]
- ; second delimiter
- "[E][options]" ;[options]
- ; +number : word number from start
- ; -number : word number from end
- ; +number}} : word number from start all space
- ; after this word to output
- ; +number{{ : word number from end all space
- ; before this word to output
- ; +number{} : word number from start
- ; all space before and after
- ; this word (word exclude)
- ; +number*} : word number from start
- ; all space after this
- ; word to output with word
- ; +number{* : word number from start
- ; all space before this
- ; word to output with word
- ; # : sum of words to output
- ; /word : number of word to output
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 no words found
- ; $var=2 no such word number
- ; $var=3 syntax error (Use: +1,-1,#)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Example (1):</b></p>
- <pre>Section
- 	${WordFind2X} "[C:\io.sys];[C:\logo.sys];[C:\WINDOWS]" "[C:\" "];" "+2" $R0
- 	; $R0="logo.sys"
- SectionEnd
- </pre>
- <p><b>Example (2):</b></p>
- <pre>Section
- 	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1" $R0
- 	; $R0="logo"
- SectionEnd
- </pre>
- <p><b>Example (3):</b></p>
- <pre>Section
- 	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{{" $R0
- 	; $R0="C:\WINDOWS C:\io.sys C:"
- SectionEnd
- </pre>
- <p><b>Example (4):</b></p>
- <pre>Section
- 	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{}" $R0
- 	; $R0="C:\WINDOWS C:\io.sys C:sys"
- SectionEnd
- </pre>
- <p><b>Example (5):</b></p>
- <pre>Section
- 	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{*" $R0
- 	; $R0="C:\WINDOWS C:\io.sys C:\logo."
- SectionEnd
- </pre>
- <p><b>Example (6):</b></p>
- <pre>Section
- 	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "/logo" $R0
- 	; $R0="2"
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordFind2X} "[io.sys];[C:\logo.sys]" "\" "];" "E+1" $R0
- 	; $R0="1" ("\...];" not found)
- 	IfErrors 0 noerrors
- 	MessageBox MB_OK 'Errorlevel=$R0' IDOK end
- 	noerrors:
- 	MessageBox MB_OK 'No errors'
- 	end:
- SectionEnd
- </pre>
- <a name="wordfind2xs"></a><h3>E.3.5 WordFind2XS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordfind2x">WordFind2X</a>, but case sensitive.</li></ul>
- <a name="wordfind3x"></a><h3>E.3.6 WordFind3X</h3>
- <ul>
- <li>Find a word that contains a string, between two delimiters.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${WordFind3X} "[string]" "[delimiter1]" "[center]" "[delimiter2]" "[E][options]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- "[delimiter1]" ;[delimiter1]
- ; first delimiter
- "[center]" ;[center]
- ; center string
- "[delimiter2]" ;[delimiter2]
- ; second delimiter
- "[E][options]" ;[options]
- ; +number : word number from start
- ; -number : word number from end
- ; +number}} : word number from start all space
- ; after this word to output
- ; +number{{ : word number from end all space
- ; before this word to output
- ; +number{} : word number from start
- ; all space before and after
- ; this word (word exclude)
- ; +number*} : word number from start
- ; all space after this
- ; word to output with word
- ; +number{* : word number from start
- ; all space before this
- ; word to output with word
- ; # : sum of words to output
- ; /word : number of word to output
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 no words found
- ; $var=2 no such word number
- ; $var=3 syntax error (Use: +1,-1,#)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Example (1):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "+1" $R0
- 	; $R0="1.AAB"
- SectionEnd
- </pre>
- <p><b>Example (2):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1" $R0
- 	; $R0="2.BAA"
- SectionEnd
- </pre>
- <p><b>Example (3):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{{" $R0
- 	; $R0="[1.AAB];"
- SectionEnd
- </pre>
- <p><b>Example (4):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{}" $R0
- 	; $R0="[1.AAB];[3.BBB];"
- SectionEnd
- </pre>
- <p><b>Example (5):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{*" $R0
- 	; $R0="[1.AAB];[2.BAA];"
- SectionEnd
- </pre>
- <p><b>Example (6):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "/2.BAA" $R0
- 	; $R0="2"
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "XX" "];" "E+1" $R0
- 	; $R0="1" ("[...XX...];" not found)
- 	IfErrors 0 noerrors
- 	MessageBox MB_OK 'Errorlevel=$R0' IDOK end
- 	noerrors:
- 	MessageBox MB_OK 'No errors'
- 	end:
- SectionEnd
- </pre>
- <a name="wordfind3xs"></a><h3>E.3.7 WordFind3XS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordfind3x">WordFind3X</a>, but case sensitive.</li></ul>
- <a name="wordreplace"></a><h3>E.3.8 WordReplace</h3>
- <ul>
- <li>Replace or delete word from string.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${WordReplace} "[string]" "[word1]" "[word2]" "[E][options]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- "[word1]" ;[word1]
- ; word to replace or delete
- "[word2]" ;[word2]
- ; replace with (if empty delete)
- "[E][options]" ;[options]
- ; +number : word number from start
- ; -number : word number from end
- ; +number* : word number from start multiple-replace
- ; -number* : word number from end multiple-replace
- ; + : replace all results
- ; +* : multiple-replace all results
- ; { : if exists replace all delimiters
- ; from left edge
- ; } : if exists replace all delimiters
- ; from right edge
- ; {} : if exists replace all delimiters
- ; from edges
- ; {* : if exists multiple-replace all
- ; delimiters from left edge
- ; }* : if exists multiple-replace all
- ; delimiters from right edge
- ; {}* : if exists multiple-replace all
- ; delimiters from edges
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 word to replace not found
- ; $var=2 no such word number
- ; $var=3 syntax error (Use: +1,-1,+1*,-1*,+,+*,{},{}*)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Example (replace):</b></p>
- <pre>Section
- 	${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "bmp" "+2" $R0
- 	; $R0="C:\io.sys C:\logo.bmp C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (delete):</b></p>
- <pre>Section
- 	${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "" "+" $R0
- 	; $R0="C:\io. C:\logo. C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (multiple-replace 1):</b></p>
- <pre>Section
- 	${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" " " " " "+1*" $R0
- 	; +1* or +2* or +3* or +4* or +5* or +6*
- 	; $R0="C:\io.sys C:\logo.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (multiple-replace 2):</b></p>
- <pre>Section
- 	${WordReplace} "C:\io.sys C:\logo.sysSYSsys C:\WINDOWS" "sys" "bmp" "+*" $R0
- 	; $R0="C:\io.bmp C:\logo.bmp C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (multiple-replace 3):</b></p>
- <pre>Section
- 	${WordReplace} "sysSYSsysC:\io.sys C:\logo.sys C:\WINDOWSsysSYSsys" "sys" "|" "{}*" $R0
- 	; $R0="|C:\io.sys C:\logo.sys C:\WINDOWS|"
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordReplace} "C:\io.sys C:\logo.sys" "sys" "bmp" "E+3" $R0
- 	; $R0="2" (no such word number "+3")
- 	IfErrors 0 noerrors
- 	MessageBox MB_OK 'Errorlevel=$R0' IDOK end
- 	noerrors:
- 	MessageBox MB_OK 'No errors'
- 	end:
- SectionEnd
- </pre>
- <a name="wordreplaces"></a><h3>E.3.9 WordReplaceS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordreplace">WordReplace</a>, but case sensitive.</li></ul>
- <a name="wordadd"></a><h3>E.3.10 WordAdd</h3>
- <ul>
- <li>Add words to string1 from string2 if not exist or delete words if exist.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${WordAdd} "[string1]" "[delimiter]" "[E][options]" $var
- </pre>
- <pre>"[string1]" ;[string1]
- ; string for addition or removing
- "[delimiter]" ;[delimiter]
- ; one or several symbols
- "[E][options]" ;[options]
- ; +string2 : words to add
- ; -string2 : words to delete
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 delimiter is empty
- ; $var=3 syntax error (use: +text,-text)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Example (add):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0
- 	; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
- SectionEnd
- </pre>
- <p><b>Example (delete):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
- 	; $R0="C:\logo.sys"
- SectionEnd
- </pre>
- <p><b>Example (add to one):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
- 	; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
- SectionEnd
- </pre>
- <p><b>Example (delete one):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0
- 	; $R0="C:\io.sys C:\logo.sys"
- SectionEnd
- </pre>
- <p><b>Example (No new words found):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0
- 	StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
- 	MessageBox MB_OK "No new words found to add"
- SectionEnd
- </pre>
- <p><b>Example (No words deleted):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0
- 	StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
- 	MessageBox MB_OK "No words found to delete"
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0
- 	; $R0="1" (delimiter is empty "")
- 	IfErrors 0 noerrors
- 	MessageBox MB_OK 'Errorlevel=$R0' IDOK end
- 	noerrors:
- 	MessageBox MB_OK 'No errors'
- 	end:
- SectionEnd
- </pre>
- <a name="wordadds"></a><h3>E.3.11 WordAddS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordadd">WordAdd</a>, but case sensitive.</li></ul>
- <a name="wordinsert"></a><h3>E.3.12 WordInsert</h3>
- <ul>
- <li>Insert word in string.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${WordInsert} "[string]" "[delimiter]" "[word]" "[E][options]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- "[delimiter]" ;[delimiter]
- ; one or several symbols
- "[word]" ;[word]
- ; word to insert
- "[E][options]" ;[options]
- ; +number : word number from start
- ; -number : word number from end
- ;
- ;[E]
- ; with errorlevel output
- ; IfErrors:
- ; $var=1 delimiter is empty
- ; $var=2 wrong word number
- ; $var=3 syntax error (Use: +1,-1)
- ;[]
- ; no errorlevel output (default)
- ; If some errors found then (result=input string)
- ;
- $var ;output (result)
- </pre>
- <p><b>Example (1):</b></p>
- <pre>Section
- 	${WordInsert} "C:\io.sys C:\WINDOWS" " " "C:\logo.sys" "-2" $R0
- 	; $R0="C:\io.sys C:\logo.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (2):</b></p>
- <pre>Section
- 	${WordInsert} "C:\io.sys" " " "C:\WINDOWS" "+2" $R0
- 	; $R0="C:\io.sys C:\WINDOWS"
- SectionEnd
- </pre>
- <p><b>Example (3):</b></p>
- <pre>Section
- 	${WordInsert} "" " " "C:\WINDOWS" "+1" $R0
- 	; $R0="C:\WINDOWS "
- SectionEnd
- </pre>
- <p><b>Example (With errorlevel output):</b></p>
- <pre>Section
- 	${WordInsert} "C:\io.sys C:\logo.sys" " " "C:\logo.sys" "E+4" $R0
- 	; $R0="2" (wrong word number "+4")
- 	IfErrors 0 noerrors
- 	MessageBox MB_OK 'Errorlevel=$R0' IDOK end
- 	noerrors:
- 	MessageBox MB_OK 'No errors'
- 	end:
- SectionEnd
- </pre>
- <a name="wordinserts"></a><h3>E.3.13 WordInsertS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#wordinsert">WordInsert</a>, but case sensitive.</li></ul>
- <a name="strfilter"></a><h3>E.3.14 StrFilter</h3>
- <ul>
- <li>Convert string to uppercase or lowercase.</li><li>Set symbol filter.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${StrFilter} "[string]" "[options]" "[symbols1]" "[symbols2]" $var
- </pre>
- <pre>"[string]" ;[string]
- ; input string
- ;
- "[options]" ;[+|-][1|2|3|12|23|31][eng|rus]
- ; + : convert string to uppercase
- ; - : convert string to lowercase
- ; 1 : only Digits
- ; 2 : only Letters
- ; 3 : only Special
- ; 12 : only Digits + Letters
- ; 23 : only Letters + Special
- ; 31 : only Special + Digits
- ; eng : English symbols (default)
- ; rus : Russian symbols
- ;
- "[symbols1]" ;[symbols1]
- ; symbols include (not changeable)
- ;
- "[symbols2]" ;[symbols2]
- ; symbols exclude
- ;
- $var ;output (result)
- </pre>
- <p><b>Note:</b> <br>- Error flag if syntax error <br>- Same symbol to include & to exclude = to exclude</p>
- <p><b>Example (UpperCase):</b></p>
- <pre>Section
- 	${StrFilter} "123abc 456DEF 7890|%#" "+" "" "" $R0
- 	; $R0="123ABC 456DEF 7890|%#"
- SectionEnd
- </pre>
- <p><b>Example (LowerCase):</b></p>
- <pre>Section
- 	${StrFilter} "123abc 456DEF 7890|%#" "-" "ef" "" $R0
- 	; $R0="123abc 456dEF 7890|%#"
- SectionEnd
- </pre>
- <p><b>Example (Filter1):</b></p>
- <pre>Section
- 	${StrFilter} "123abc 456DEF 7890|%#" "2" "|%" "" $R0
- 	; $R0="abcDEF|%" ;only Letters + |%
- SectionEnd
- </pre>
- <p><b>Example (Filter2):</b></p>
- <pre>Section
- 	${StrFilter} "123abc 456DEF 7890|%#" "13" "af" "4590" $R0
- 	; $R0="123a 6F 78|%#" ;only Digits + Special + af - 4590
- SectionEnd
- </pre>
- <p><b>Example (Filter3):</b></p>
- <pre>Section
- 	${StrFilter} "123abc 456DEF 7890|%#" "+12" "b" "def" $R0
- 	; $R0="123AbC4567890" ;only Digits + Letters + b - def
- SectionEnd
- </pre>
- <p><b>Example (Filter4):</b></p>
- <pre>Section
- 	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "+12rus" "ä" "ãå" $R0
- 	; $R0="123ÀÁÂ456ä7890" ;only Digits + Letters + ä - ãå
- SectionEnd
- </pre>
- <p><b>Example (English + Russian Letters):</b></p>
- <pre>Section
- 	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2rus" "" "" $R0
- 	; $R0="ÀÁÂãäå" ;only Russian Letters
- 	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2" "$R0" "" $R0
- 	; $R0="abcÀÁÂDEFãäå" ;only English + Russian Letters
- SectionEnd
- </pre>
- <p><b>Example (Word Capitalize):</b></p>
- <pre>Section
- 	Push "_01-PERPETUOUS_DREAMER__-__THE_SOUND_OF_GOODBYE_(ORIG._MIX).MP3_"
- 	Call Capitalize
- 	Pop $R0
- 	; $R0="_01-Perpetuous_Dreamer__-__The_Sound_Of_Goodbye_(Orig._Mix).mp3_"
- 	${WordReplace} "$R0" "_" " " "+*" $R0
- 	; $R0=" 01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3 "
- 	${WordReplace} "$R0" " " "" "{}" $R0
- 	; $R0="01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3"
- SectionEnd
- Function Capitalize
- 	Exch $R0
- 	Push $0
- 	Push $1
- 	Push $2
- 	${StrFilter} '$R0' '-eng' '' '' $R0
- 	${StrFilter} '$R0' '-rus' '' '' $R0
- 	StrCpy $0 0
- 	loop:
- 	IntOp $0 $0 + 1
- 	StrCpy $1 $R0 1 $0
- 	StrCmp $1 '' end
- 	StrCmp $1 ' ' +5
- 	StrCmp $1 '_' +4
- 	StrCmp $1 '-' +3
- 	StrCmp $1 '(' +2
- 	StrCmp $1 '[' 0 loop
- 	IntOp $0 $0 + 1
- 	StrCpy $1 $R0 1 $0
- 	StrCmp $1 '' end
- 	${StrFilter} '$1' '+eng' '' '' $1
- 	${StrFilter} '$1' '+rus' '' '' $1
- 	StrCpy $2 $R0 $0
- 	IntOp $0 $0 + 1
- 	StrCpy $R0 $R0 '' $0
- 	IntOp $0 $0 - 2
- 	StrCpy $R0 '$2$1$R0'
- 	goto loop
- 	end:
- 	Pop $2
- 	Pop $1
- 	Pop $0
- 	Exch $R0
- FunctionEnd
- </pre>
- <a name="strfilters"></a><h3>E.3.15 StrFilterS</h3>
- <ul>
- <li>Same as <a href="AppendixE.html#strfilter">StrFilter</a>, but case sensitive.</li></ul>
- <a name="versioncompare"></a><h3>E.3.16 VersionCompare</h3>
- <ul>
- <li>Compare version numbers.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${VersionCompare} "[Version1]" "[Version2]" $var
- </pre>
- <pre>"[Version1]" ; First version
- "[Version2]" ; Second version
- $var ; Result:
- ; $var=0 Versions are equal
- ; $var=1 Version1 is newer
- ; $var=2 Version2 is newer
- </pre>
- <p><b>Example:</b></p>
- <pre>Section
- 	${VersionCompare} "1.1.1.9" "1.1.1.01" $R0
- 	; $R0="1"
- SectionEnd
- </pre>
- <a name="versionconvert"></a><h3>E.3.17 VersionConvert</h3>
- <ul>
- <li>Convert version in the numerical format which can be compared.</li></ul>
- <p><b>Syntax:</b></p>
- <pre>${VersionConvert} "[Version]" "[CharList]" $var
- </pre>
- <pre>"[Version]" ; Version
- ;
- "[CharList]" ; List of characters, which will be replaced by numbers
- ; "abcdefghijklmnopqrstuvwxyz" (default)
- ;
- $var ; Result: converted version
- </pre>
- <p><b>Note:</b> <br>- Converted letters are separated with dot <br>- If character is non-digit and not in list then it will be converted to dot</p>
- <p><b>Example1:</b></p>
- <pre>Section
- 	${VersionConvert} "9.0a" "" $R0
- 	; $R0="9.0.01"
- 	${VersionConvert} "9.0c" "" $R1
- 	; $R1="9.0.03"
- 	${VersionCompare} "$R0" "$R1" $R2
- 	; $R2="2" version2 is newer
- SectionEnd
- </pre>
- <p><b>Example2:</b></p>
- <pre>Section
- 	${VersionConvert} "0.15c-9m" "" $R0
- 	; $R0="0.15.03.9.13"
- 	${VersionConvert} "0.15c-1n" "" $R1
- 	; $R1="0.15.03.1.14"
- 	${VersionCompare} "$R0" "$R1" $R2
- 	; $R2="1" version1 is newer
- SectionEnd
- </pre>
- <p><b>Example3:</b></p>
- <pre>Section
- 	${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
- 	; $R0="0.15.0327"
- 	${VersionConvert} "0.15c" "abcdefghijklmnopqrstuvwxyz+" $R1
- 	; $R1="0.15.03"
- 	${VersionCompare} "$R0" "$R1" $R2
- 	; $R2="1" version1 is newer
- SectionEnd
- </pre>
- <p><a href='AppendixD.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixF.html'>Next</a></p>
- <hr />
- <address>
- </address>
- </body>
- </html>
|