Hello
I'm new to NSIS, it looked fine at first sight but when I tried to make installer what I wanted I hit some problems:
1) Using variables is big pain, using strings manipulation is HUGE pain. I don't get how modern installer can lack any decent number of functions for such basic task. Handling Path/reg keys require complicated function in current script using StrCpy/StrCmp/IntOp. For example in my installer have to read key from file which stores installed path of application. But it isn't stored in right-to-use format I need to manipulate (cut path add some text). I've done it but when I want to display it using Static in confirmation window, it "eats" backshlashes. :-\ So is there easy way of manipulating paths in current NSIS ?
2) In general my installer will be template for game maps installers of other people so such user will customize name and similar things in script (stored as constants), but how to add files the easy way (not editing script and making line for every single file). Is there any file list generator or can I use external (of script) file-list file (🙂) ?
string functions
117 posts
1) The strings commands are easy to use if you follow the documentation. Probably there is already are suitable function written for you:
2) Using an extenal header file is even better. The users will only have to modify that file with defines. You can also use defines for filenames or add all files in a folder using *.* or /r.
2) Using an extenal header file is even better. The users will only have to modify that file with defines. You can also use defines for filenames or add all files in a folder using *.* or /r.
I know these function are the only help, but I would still opt for something easier as string manipulation is used very often and seeking and adding long function for every simple string task is a little too much work.
Also docs are not so informative, I had to dig quite a bit to find out how to concatenate strings. I found it finally in some example in the internet. The same goes for InstallOptions and custom pages in general.
Also docs are not so informative, I had to dig quite a bit to find out how to concatenate strings. I found it finally in some example in the internet. The same goes for InstallOptions and custom pages in general.
You can do everything with the current string commands. Sometimes you will have to use multiple commands, but that's the basic of all programming languages. There are hundreds of things you can do with strings, it's impossible to add a command for every possibility.
The whole point of having function is that becomes easy to do the same thing multiple times. If you think the functions they make your script less easy to read, put them in a header file.
If we would add a command for all things that can also be done using the scripting language, NSIS would become huge.
We are always working on improvements of the documentation, but it takes a lot of time. If you think it can be improved, why not help yourself?
The whole point of having function is that becomes easy to do the same thing multiple times. If you think the functions they make your script less easy to read, put them in a header file.
If we would add a command for all things that can also be done using the scripting language, NSIS would become huge.
We are always working on improvements of the documentation, but it takes a lot of time. If you think it can be improved, why not help yourself?
Well I don't want to create any argument but people can still write in assembler so what for do we need NSIS then? I was talking about usability and making things easier, which should be the goal of every computer app and epecially NSIS for installation tasks. I'm not saying that you should mirror STL or some other lib but few basic things.
As for me writitng docs - I was saying that one (in this case me) can't learn much from than - how could I write docs knowing little about subject, that's the problem.
As for me writitng docs - I was saying that one (in this case me) can't learn much from than - how could I write docs knowing little about subject, that's the problem.
So which things do you think that can be added to make string manipulation easier?
The problem is that it's easy to complain about documentation, but if nobody wants to help improving them (after they have learned NSIS) we don't get any further.
The problem is that it's easy to complain about documentation, but if nobody wants to help improving them (after they have learned NSIS) we don't get any further.
String functions like:
* finding index of char/substr in string
* finding first occurence char from subset in string starting from index.
* replacing char/substring in string
* conversion to/from C-style strings (for easier using strings in Windows functions).
* concatenating string (in current system name of veriable is joined with following text, which can make trouble in some cases) OR append-to-text function.
First three should have reverse-index versions. If this is too big to add maybe it could be made as plugin with "extra string functions".
* finding index of char/substr in string
* finding first occurence char from subset in string starting from index.
* replacing char/substring in string
* conversion to/from C-style strings (for easier using strings in Windows functions).
* concatenating string (in current system name of veriable is joined with following text, which can make trouble in some cases) OR append-to-text function.
First three should have reverse-index versions. If this is too big to add maybe it could be made as plugin with "extra string functions".
Concatenating strings can be done with StrCpy, like
StrCpy $MYSTRING "sometext $MYSTRING1 $MYSTRING2"
The are currently functions for all these search & replace actions. I see no reason to integrate them, it will only make the installer larger (functions only take a few bytes, adding it in native code to the exehead takes much more space).
You could write a plug-in with string functions, but it will still be larger than functions, and it will do exactly the same.
StrCpy $MYSTRING "sometext $MYSTRING1 $MYSTRING2"
The are currently functions for all these search & replace actions. I see no reason to integrate them, it will only make the installer larger (functions only take a few bytes, adding it in native code to the exehead takes much more space).
You could write a plug-in with string functions, but it will still be larger than functions, and it will do exactly the same.
i would add these typical c++ string-commands:
String.SubString
StringReplace
String.LastDelimiter
String.Length
String.Pos
i think, those are the most used, an important commands (after the included StrCpy and StrCmp).
String.SubString
StringReplace
String.LastDelimiter
String.Length
String.Pos
i think, those are the most used, an important commands (after the included StrCpy and StrCmp).
Most of these things can be done using the current commands (StrLen etc.). For the others you can use a function.
If someone wants to make a plug-in or header file with string manipulation functions, I will include it in the distribution.
If someone wants to make a plug-in or header file with string manipulation functions, I will include it in the distribution.
hmm, yes, i already thougt at a plugin for those commands, or even a collection of macros doing this in a header-file at the include-dir.
maybe an include-file would be easier ...
ah, i forgot that StrLen already exists 🙂
maybe an include-file would be easier ...
ah, i forgot that StrLen already exists 🙂
It would be nice if someone could put all useful string functions together in a nice header file with some documentation.
Do you want the typical <string.h> functions?
Not all, but a few, the most handy during setup functions, like those I mentioned. I don't think they would take more than 1-2KB of code.
PS. How to display path text from string char in Label control of dialog window? I have to convert it to C-style string; creating such function in current script would be quite painful.
Originally posted by Joost VerburgWhat if I want to insert variable into word, like "$APPNAMEreadme.txt", will it work correctly if I will have variables $APPNAME, $APPNAMER, $APPNAMEREAD ?
Concatenating strings can be done with StrCpy, like
StrCpy $MYSTRING "sometext $MYSTRING1 $MYSTRING2"
PS. How to display path text from string char in Label control of dialog window? I have to convert it to C-style string; creating such function in current script would be quite painful.
Originally posted by KHysiekThis may help you: http://nsis.sourceforge.net/archive/...ances=0,11,122
PS. How to display path text from string char in Label control of dialog window? I have to convert it to C-style string; creating such function in current script would be quite painful.
Putting all of the codes in one file, ready to include, like the <string.h> C++ file and thousands of others inside the C++, is the unique solution for that, I think, like Joost said.
If everyone wants, I can make an integrated file for that, but you have to aid sometimes because I don't know the C++ files and codes! (I think I have at least the C++ files, but I don't know how to use them)
If everyone wants, I can make an integrated file for that, but you have to aid sometimes because I don't know the C++ files and codes! (I think I have at least the C++ files, but I don't know how to use them)
It would be nice to have all of the string functions in one place. I often forget which header file I have strstr in or which one has strreplace. It would be great to include string.nsh and have all those functions right there (and probably something I should have been doing on my own anyway.).
yes, that would be really nice.
but i think, if someone collects all this functions, it will be better to convert them to macros. macros are much easier to include in the code, than functions, which require some 'pushing'.
but i think, if someone collects all this functions, it will be better to convert them to macros. macros are much easier to include in the code, than functions, which require some 'pushing'.
Must agree, better than plugin, a Nsis Header (NSH) will be a solution. I'm making a plugin, (3.40 KB) and 3 functions to include; I think will be better to make Nsis header files rather to embed the DLL.... 🙂
I'll do this way: (example)
${StrTok} $0 "My text" " "
It will combine:
Defines - easy the call of commands.
Macros - easy the call of command parameters.
Functions - don't occupy much space in compiled installer.
${StrTok} $0 "My text" " "
It will combine:
Defines - easy the call of commands.
Macros - easy the call of command parameters.
Functions - don't occupy much space in compiled installer.
Great, if you can finish it soon it can be included in NSIS 2.
Wow, that was unexpected...
In the case of StrTok, I don't know if I have to put the result in a variable, several ones, or use several times the same command to return results for each string before and after separators...
In the case of StrTok, I don't know if I have to put the result in a variable, several ones, or use several times the same command to return results for each string before and after separators...
Something to bear in mind if you plan on bundling all these functions in a single header: all of them will be included in the installer whether used or not, and the compiler will throw up warnings about them.
I thought they'd only be included if you specifically say:
!include "strings.nsh"
'Doh Sorry, didn't think about it very hard before I posted. 😁
!include "strings.nsh"
'Doh Sorry, didn't think about it very hard before I posted. 😁
He means that all functions in a header file will be included when including the file.
This problem can be solved by using macros which is already what deguix wants to do.
This problem can be solved by using macros which is already what deguix wants to do.
EDIT: I think that this should be not included in the NSIS 2, because putting this without much work in it (the first version) will be complainted for everyone, that something could be better.
You remember the old NSIS Update? It was just included after some NSIS versions, because needed to be changed?...
You remember the old NSIS Update? It was just included after some NSIS versions, because needed to be changed?...
Ok, I have the beta... It has these functions now:
Function - Command "Parameters":
Search in String Function - ${StrStr} "ResultVar" "StrToSearchIn" "StrToBeSearched"
StrTok Function - ${StrTok} "ResultVar" "ResultVar2" "StrToTokenizing" "Separators"
Copy to Clipboard Function - ${StrClbSet} "String"
Copy from Clipboard Function - ${StrClbGet} "ResultVar"
Use a first command out of Sections and Functions to insert its function in your installer script.
I made changes in two functions:
StrTok Function - now is based in StrStr, more simpler I think, but the results didn't change.
Copy from Clipboard Function - the function name was "CopyToClipboard", changed it to "CopyFromClipboard".
(I think someone should put the Modern UI startup message in the compilation as my style, because is more clear.)
(The documentation doesn't say about "/*" (start) and "*/" (end) for comments.)
Example Script:
Function - Command "Parameters":
Search in String Function - ${StrStr} "ResultVar" "StrToSearchIn" "StrToBeSearched"
StrTok Function - ${StrTok} "ResultVar" "ResultVar2" "StrToTokenizing" "Separators"
Copy to Clipboard Function - ${StrClbSet} "String"
Copy from Clipboard Function - ${StrClbGet} "ResultVar"
Use a first command out of Sections and Functions to insert its function in your installer script.
I made changes in two functions:
StrTok Function - now is based in StrStr, more simpler I think, but the results didn't change.
Copy from Clipboard Function - the function name was "CopyToClipboard", changed it to "CopyFromClipboard".
(I think someone should put the Modern UI startup message in the compilation as my style, because is more clear.)
(The documentation doesn't say about "/*" (start) and "*/" (end) for comments.)
Example Script:
Put this file in the NSIS Include Dir.
Name Test
OutFile Test.exe
!include "StringFunctions.nsh"
${StrStr}
Section
${StrStr} $0 "this is a long ass string" "ass"
SectionEnd
Yes, you can also use C-style comments. I'll add it to the manual.
Version 0.02, now just lacks the documentation and more tests...
This file includes basic how to use, commands, and comments about functions included and not included.
If you have any complaint about functions included or not included, please tell me now or I will finish the final version first... 😎
This file includes basic how to use, commands, and comments about functions included and not included.
If you have any complaint about functions included or not included, please tell me now or I will finish the final version first... 😎
So, what about functions I've mentioned earlier ? 🙂