Archive: WordFunc.nsh + TextFunc.nsh + FileFunc.nsh


WordFunc.nsh + TextFunc.nsh + FileFunc.nsh
I have thought :) more convenient to update one topic than three topics

Word Functions Header v2.52
Text Functions Header v1.4
File Functions Header v1.21


1. Function GetParameters moved from WordFunc.nsh to FileFunc.nsh
2. Text Functions LineFind and LineRead
    -now last line "-1" instead of "0"

These headers are included with NSIS. See: http://nsis.sourceforge.net/Docs/AppendixE.html#E


Word Functions Header v2.6
Text Functions Header v1.4
File Functions Header v1.3


1. "GetDrives" v1.1
   -Fixed: depended on drives order

2. "WordFind2X" v2.1
   -Loops sorted

3. New: "WordFind3X" v1.0
   -Find word, that contain string, between two delimiters.
   (Based on Afrow UK idea of Function "StrSortLR" 2003-06-18)

4. "WordFuncExample.nsi" updated.


Word Functions Header v2.6
Text Functions Header v1.5
File Functions Header v1.3


"LineFind" v1.3
  -Added "/NUL" option: No output text file (only read InputFile).


Word Functions Header v2.6
Text Functions Header v1.5
File Functions Header v1.4


1. New: "GetBaseName"
   -Get file name without extension.
   (Based on comperio idea of Function "GetBaseName" 2005-01-28)

2. New: "GetFileVersion"
   -Gets the version information from executable file.

3. New: "VersionCompare" v1.0
   -Compare version numbers.
   (Based on Afrow UK Function "VersionCheckNew2" 2005-01-24)
       His original function isn't included because of wrong results:
       ${VersionCheckNew2} "2.5.9" "2.5.01" $R0     -Ver2 newer
       ${VersionCheckNew2} "2.5.09" "2.5" $R0       -equal


Why is 2.5.09 equal to 2.5? Just a typo or does the function behave that way?


No. It isn't a typo.


@kichik:

His original function isn't included because of wrong results:
${VersionCheckNew2} "2.5.9" "2.5.01" $R0 -Ver2 newer
${VersionCheckNew2} "2.5.09" "2.5" $R0 -equal
read it another time :)

Thanks for letting me know :hang:
Fixed my function.

-Stu


Word Functions Header v2.6
Text Functions Header v1.6
File Functions Header v1.4


1. "LineFind" v1.4
   -Output file will not be updated if no changes made
   -Error flag if output file path isn't exists
   -Added: "{No}" callback this line and don't write others
   -Variables in callback function changed

2. Added script to simple install WordFunc.nsh, TextFunc.nsh, FileFunc.nsh


Word Functions Header v2.7
Text Functions Header v1.7
File Functions Header v1.5


1. "ClbSet", "ClbGet" removed from WordFunc.nsh

2. "LineRead" v1.2, "LineSum", "FileJoin" v1.4, "TextCompare" v1.2
   -Added IfErrors after FileOpen

3. "GetDrives" v1.2
   -Added "ALL" along with ""

4. New: "FileReadFromEnd" v1.0
   -Read text file from end line by line.

5. New: "DriveSpace" v1.0
   -Get total, occupied or free space of the drive.

6. Added: "GetRoot"
    (Based on KiCHiK Function "GetRoot")
   -Get the root directory.

7. Added: "GetParent"
    (Based on sunjammer Function "GetParent")
   -Get parent directory.

8. Added: "GetFileName"
    (Based on KiCHiK Function "GetFileName")
   -Get last part from directory path.

9. Many minor code and documentation improvements


Word Functions Header v2.7
Text Functions Header v1.7
File Functions Header v1.6


  "DriveSpace", "DirState", "GetFileVersion"
   -Missing ClearErrors at the beginning.


Word Functions Header v2.7
Text Functions Header v1.8
File Functions Header v1.7


In order to avoid exiting from connected functions,
changed exit value in callback function to "Stop<FunctionName>":

-"LineFind"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop -> StopLineFind
-"FileReadFromEnd"&nbsp;&nbsp;Stop -> StopFileReadFromEnd
-"TextCompare"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StopCompare -> StopTextCompare
-"GetDrives"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop -> StopGetDrives


Word Functions Header v2.8
Text Functions Header v1.8
File Functions Header v1.8


1. "Locate" v1.5
&nbsp;&nbsp;&nbsp;-Added "/B=" parameter (when used banner with function)

2. "StrFilter" v1.2
&nbsp;&nbsp;&nbsp;-Missing ClearErrors at the beginning.


Word Functions Header v2.8
Text Functions Header v1.8
File Functions Header v1.9



Changes:

&nbsp;"Locate" v1.6
&nbsp;&nbsp;&nbsp;-Fixed: if error appeared in the callback, function don't restore stack after exit.


Word Functions Header v2.8
Text Functions Header v1.8
File Functions Header v2.0



Changes:

&nbsp;New: "GetOptions"
&nbsp;&nbsp;&nbsp;-Get options from command line parameters.


Word Functions Header v2.9
Text Functions Header v2.0
File Functions Header v2.3



Changes:

1. Verbosity added (faster compilation time)

2. "Locate" v1.7
&nbsp;&nbsp;&nbsp;&nbsp;-Fixed: Banner support

3. "GetOptions"
&nbsp;&nbsp;&nbsp;&nbsp;-Now required only 2 arguments:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${GetOptions} "[Parameters]" "[Option]" $var

4. "GetTime" v1.2
&nbsp;&nbsp;&nbsp;&nbsp;-Now convert day and month in DD and MM format

5. "TextCompare" v1.4
&nbsp;&nbsp;&nbsp;&nbsp;-Rewrited all code

6. "FileReadFromEnd" v1.2
&nbsp;&nbsp;&nbsp;&nbsp;-Now if the text file cannot be opened, the error flag is set


Word Functions Header v3.0
Text Functions Header v2.1
File Functions Header v2.4



Changes:

1. "VersionCompare" moved from FileFunc.nsh to WordFunc.nsh

2. New: "VersionConvert" v1.0
&nbsp;&nbsp;&nbsp;-Convert version in the numerical format which can be compared.

3. New: "ConfigRead" v1.0
&nbsp;&nbsp;&nbsp;-Read value from entry name in config file.

4. New: "ConfigWrite" v1.1
&nbsp;&nbsp;&nbsp;-Write value from entry name in config file.

5. New: "FileRecode"
&nbsp;&nbsp;&nbsp;-Recode text file from DOS to Windows format and vice-versa.

6. New: "GetFileAttributes" v1.1
&nbsp;&nbsp;&nbsp;-Get attributes of file or directory.

7. New: "BannerTrimPath"
&nbsp;&nbsp;&nbsp;-Trim string path for banner.


Word Functions Header v3.0
Text Functions Header v2.1
File Functions Header v2.5



Changes:

1. "GetDrives" v1.4
&nbsp;&nbsp;&nbsp;&nbsp;-Fixed: Alloc/Free (Thanks nechai)

2. "GetOptions"
&nbsp;&nbsp;&nbsp;&nbsp;-Better option search (complite ignoration in quotes)

3. Renamed example scripts (like in CVS):
&nbsp;&nbsp;&nbsp;&nbsp;...FuncTest.nsi -> ...Func.nsi
&nbsp;&nbsp;&nbsp;&nbsp;...FuncTest.ini -> ...Func.ini


Word Functions Header v3.0
Text Functions Header v2.1
File Functions Header v2.6



Changes:

1. "GetTime" v1.3
&nbsp;&nbsp;&nbsp;&nbsp;-Fixed: Free structures

2. "GetExeName" and "GetExePath"
&nbsp;&nbsp;&nbsp;&nbsp;-Simplification with "GetLongPathNameA"

3. "BannerTrimPath"
&nbsp;&nbsp;&nbsp;&nbsp;-Added D mode


Word Functions Header v3.1
Text Functions Header v2.1
File Functions Header v2.7


Changes:

1. "WordReplace" v2.1
&nbsp;&nbsp;&nbsp;&nbsp;-Fixed: Incorrect rule for return errorlevel 1 in situation when string beginning with word to replace and its only one word in string and when uses option - deletes all founded words (thanks hemancuso)

2. "GetExeName" and "GetExePath"
&nbsp;&nbsp;&nbsp;&nbsp;-Fixed: Return empty string in Windows 95 (thanks kichik)


Word Functions Header v3.1
Text Functions Header v2.1
File Functions Header v2.8


Changes:

1. Now "GetRoot" returns not only root drive or UNC:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${GetRoot} "Program Files\NSIS" $R0 &nbsp;&nbsp;&nbsp;# $R0="Program Files" instead of ""
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${GetRoot} "\Program Files\NSIS" $R0 &nbsp;&nbsp;# $R0="\Program Files" instead of ""

2. Some typos corrected (thanks Jamyn)


What about UTC (Coordinated Universal Time?)
I need to use UTC (Coordinated Universal Time) instead of Local Time which can be gotten from kernel32::GetSystemTime. Any chance of updating the "official" version of Text Functions Header to incorporate that functionality?

My other option is to hack GetTime() and include it directly in my code. Yuck.


Word Functions Header v3.1
Text Functions Header v2.1
File Functions Header v2.9


Changes:

"GetTime" v1.4
-Added support for system time (UTC)
-Added example how to convert time to 12-hour format AM/PM


Has the getdrives function been tested on windows 98,

If so does it work?


Has the getdrives function been tested on windows 98
Yes
If so does it work?
:) Yes

Thanks


Word Functions Header v3.2
Text Functions Header v2.2
File Functions Header v3.0


Changes:

1. "WordReplace" v2.2
&nbsp;&nbsp;&nbsp;-Added options "{", "}", "{*", "}*"

2. "GetOptions"
&nbsp;&nbsp;&nbsp;-Now sets error flag if option does not found

3. "ConfigRead"
&nbsp;&nbsp;&nbsp;-Now sets error flag if entry does not found

4. New case sensitive functions (NSIS 2.14 required):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"WordFindS", "WordFind2XS", "WordFind3XS", "WordReplaceS",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"WordAddS", "WordInsertS", "StrFilterS", "TextCompareS",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ConfigReadS", "ConfigWriteS", "GetOptionsS"

5. Added program for simple headers install


Word Functions Header v3.2
Text Functions Header v2.3
File Functions Header v3.1


Changes:

-Added /NOUNLOAD flag for the system plugin. Functions that uses system plugin calls several times, now 25-75% faster ("GetSize", "DriveSpace", "GetDrives", "GetTime", "ConfigWrite", "FileRecode").


kichik, plz update the CVS :)


Hey Instructor,
I have to say that your functions are very cool. I find that I use them almost every chance I get!

Here's an enhancement suggestion for the Locate function:
Currently, there is an option /M=[mask] to add options of what to search for. A cool option might be something like /!M=[mask] to specify what to EXCLUDE.

For example /!M=*.EXE would mean to exclude all dat files from the search.

Using both together, one might use
/M=*.DAT /!M=doofus.dat

which would translate to:
"Include all *.DAT files except the file named 'doofus.dat'"

That's all I have for now. Keep up the great work!:up:


Many filters implemented in Locate plugin


Thanks for the link, Instructor. Looks exactly what I was looking for!

So tell me, why is this not included with NSIS itself like you've your other functions? (Just curious)


So tell me, why is this not included with NSIS itself like you've your other functions? (Just curious)
I think this is not my question :)

OK, I found an odd problem:
I'm using the Locate function from NSIS ver 2.15.

I'm using it to search for all files/directies. I found that if I push two items to the stack, then locate will stop. But, if I just push one item to the stack, it works as expected.

I also noticed that when i push the text "blah" to the stack the 2nd time (instead of "continue"), I get a Windows error.

Here's a short sample showing the error:


name "test"
outfile "test.exe"
!define ROOT "C:\TEMP"
!include FileFunc.nsh
!insertmacro Locate

Page instfiles

Section
${Locate} "${ROOT}" "/L=FD /M=*.* /G=1 /B=0" "AddToList"
SectionEnd

Function AddToList
MessageBox MB_OK "$$R7=$R7"
Push "$R7"
Push "continue" ### if I remove this line, it works fine
FunctionEnd


Is this an NSIS error or a problem with ${locate}?

You can not use NSIS stack in the callback function, because it is used by function. Only one push requered in the callback.

P.S.
You can call another function from the callback, on condition that this function don't change the stack after completion.


hmmm... I see. I'll have to keep that in mind.

I didn't see this this info in the NSIS manuals. Are you the one that manages those, or do I need to post a separate request on the NSIS sourceforge site?


*sigh* :(
I may have opened a big can of worms with this. In my example script above, I changed the sample script above to write the file names to a text file instead of pushing to the stack using the command FileWrite $myHandle "$R7$\r$\n". (my hope was to bypass the stack completely and then retrieve the values one at a time later.) Unfortunately, I find that it didn't work, either. :cry:

However, using a WriteIniStr command WriteIniStr "$myFileName" "General" "$R7" "" did work, so I guess I have a workaround.

But, I'd still like to understand why the FileWrite did not work. My only guess is that some NSIS functions (like FileWrite) must also use the NSIS stack. Is this correct? (If so, would perhaps using regular variables work better?)


See example in manual "Write results to a text file"

My only guess is that some NSIS functions (like FileWrite) must also use the NSIS stack. Is this correct?
FileOpen-FileWrite-FileClose don't use NSIS stack.

Thanks, Instructor. As always, your suggestion worked perfectly!
(I guess I can just chalk this up as a bad day.) :weird:


Hi. I test this:

${VersionCompare} "2.3" "2.29" $0

And it tells me that $0 is 2. That means that 2.29 is a higher version than 2.3, which is wrong. Same goes with:

${VersionCompare} "2.29" "2.3" $0

it tells me that $0 is 1.

I'll try to fix it, but I'm a newbie in NSIS...


Archive: WordFunc.nsh + TextFunc.nsh + FileFunc.nsh


Sorry, I had a lapsus there. Just ignore my last post. :-P


GetOptions doesn't work correctly when it finds a URL because of the "/" in the URL value (example: /url=http://nsis.sf.net)

Maybe a check can be added for "//" ?


Use quotes /url="http://nsis.sf.net"


I have a situation where I don't have control over what is passed in, so I can't have quotes put around the value itself. I got everything working by using a different routine to get the value. It's no problem, probably a very uncommon situation.


Word Functions Header v3.3
Text Functions Header v2.4
File Functions Header v3.2


Changes:

1. "GetFileAttributes" v1.2
&nbsp;&nbsp;&nbsp;-Some corrections

2. Prevent error in case of including headers several times.


Word Functions Header v3.3
Text Functions Header v2.4
File Functions Header v3.3


Changes:

1. "Locate" v1.8
&nbsp;&nbsp;&nbsp;-Handles were not getting closed properly.

2. "GetSize" v2.0
&nbsp;&nbsp;&nbsp;-Handles were not getting closed properly.


*zap* I was on an old page when I commented - d'oh!


Any chance to get the day and number of seconds returned from GetTime as a 0-padded string if it's less than 10? In other words "08" instead of "8" for seconds and day-of-month?

Thanks much.

-DB


Edit. nevermind. I found the readme and i overlooked something.