Old 20th January 2004, 11:50   #1
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
string functions

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 () ?
KHysiek is offline   Reply With Quote
Old 20th January 2004, 12:06   #2
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
1) The strings commands are easy to use if you follow the documentation. Probably there is already are suitable function written for you:

http://nsis.sourceforge.net/archive/...11&instances=0

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.
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 12:40   #3
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
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.
KHysiek is offline   Reply With Quote
Old 20th January 2004, 13:00   #4
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
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?
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 13:28   #5
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
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.
KHysiek is offline   Reply With Quote
Old 20th January 2004, 14:14   #6
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
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.
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 16:31   #7
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
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".
KHysiek is offline   Reply With Quote
Old 20th January 2004, 17:03   #8
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
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.
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 19:13   #9
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
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).
Comm@nder21 is offline   Reply With Quote
Old 20th January 2004, 19:38   #10
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
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.
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 19:41   #11
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
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
Comm@nder21 is offline   Reply With Quote
Old 20th January 2004, 20:07   #12
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
It would be nice if someone could put all useful string functions together in a nice header file with some documentation.
Joost Verburg is offline   Reply With Quote
Old 20th January 2004, 21:33   #13
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
Do you want the typical <string.h> functions?


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 21st January 2004, 05:56   #14
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
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.

Quote:
Originally posted by Joost Verburg
Concatenating strings can be done with StrCpy, like

StrCpy $MYSTRING "sometext $MYSTRING1 $MYSTRING2"
What if I want to insert variable into word, like "$APPNAMEreadme.txt", will it work correctly if I will have variables $APPNAME, $APPNAMER, $APPNAMEREAD ?

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.
KHysiek is offline   Reply With Quote
Old 21st January 2004, 09:52   #15
MoNKi
Senior Member
 
Join Date: Aug 2002
Location: Spain
Posts: 112
Quote:
Originally posted by KHysiek
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.
This may help you: http://nsis.sourceforge.net/archive/...ances=0,11,122
MoNKi is offline   Reply With Quote
Old 21st January 2004, 10:43   #16
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 21st January 2004, 17:34   #17
Spatacoli
Junior Member
 
Join Date: Jan 2004
Posts: 24
Send a message via ICQ to Spatacoli
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.).
Spatacoli is offline   Reply With Quote
Old 21st January 2004, 18:49   #18
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
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'.
Comm@nder21 is offline   Reply With Quote
Old 21st January 2004, 20:14   #19
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
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....


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 22nd January 2004, 20:46   #20
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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.

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 22nd January 2004, 21:02   #21
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
Great, if you can finish it soon it can be included in NSIS 2.
Joost Verburg is offline   Reply With Quote
Old 22nd January 2004, 21:23   #22
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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...

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 22nd January 2004, 21:52   #23
eccles
NSIS Dev
 
eccles's Avatar
 
Join Date: Sep 2001
Location: Leicester, UK
Posts: 193
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.

You can lead a man to knowledge, but you can't make him think!
eccles is offline   Reply With Quote
Old 22nd January 2004, 22:03   #24
Spatacoli
Junior Member
 
Join Date: Jan 2004
Posts: 24
Send a message via ICQ to Spatacoli
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.
Spatacoli is offline   Reply With Quote
Old 22nd January 2004, 22:23   #25
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
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.
Joost Verburg is offline   Reply With Quote
Old 22nd January 2004, 22:31   #26
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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?...

My Wiki Pages

Working now on:
New projects. (language: any)

Last edited by deguix; 22nd January 2004 at 23:02.
deguix is offline   Reply With Quote
Old 23rd January 2004, 02:27   #27
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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:
code:

Name Test
OutFile Test.exe

!include "StringFunctions.nsh"

${StrStr}

Section

${StrStr} $0 "this is a long ass string" "ass"

SectionEnd



Put this file in the NSIS Include Dir.
Attached Files
File Type: nsh stringfunctions.nsh (6.0 KB, 366 views)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 23rd January 2004, 09:11   #28
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
Yes, you can also use C-style comments. I'll add it to the manual.
Joost Verburg is offline   Reply With Quote
Old 25th January 2004, 13:03   #29
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
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...
Attached Files
File Type: nsh strfunc.nsh (27.4 KB, 322 views)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 27th January 2004, 16:25   #30
KHysiek
Junior Member
 
Join Date: Jan 2004
Posts: 6
Thumbs up

So, what about functions I've mentioned earlier ?
KHysiek is offline   Reply With Quote
Old 28th January 2004, 02:19   #31
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Quote:
* finding index of char/substr in string
Maybe a change to StrStr to do that, so I have to work a little bit...

Quote:
* finding first occurence char from subset in string starting from index.
You can do this using StrCpy to customize where it will start and use StrStr Function.

Quote:
* replacing char/substring in string
Use StrReplace Function.

Quote:
* conversion to/from C-style strings (for easier using strings in Windows functions).
Hmmmm... maybe using System plugin or Math plugin. I will try to search.

Quote:
* 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.
One command resume it all: StrCpy.

Quote:
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.
Use NSISToIO inside header file. (I don't know if this is right if you want to do that in a normal dialog from Windows or something)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 28th January 2004, 14:32   #32
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Quote:
conversion to/from C-style strings (for easier using strings in Windows functions).
NSIS uses C-style strings. What do you mean by this?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 31st January 2004, 19:52   #33
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Any estimate to when 1.00 will be ready?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 31st January 2004, 21:05   #34
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Hehehe, I bought a new game and I and my brother couldn't stop to play it until now... but it is nearly done. 6:00 AM of tomorrow is done, or more soon if it is possible... (sharing pc problems, you know)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 1st February 2004, 13:11   #35
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Version 1.00 done. Included the header file and manual.

Changes:

- Added documentation.
- Renamed header file to "StrFunc.nsh".
- Added 1 function, StrLoc.
- Modified StrStrAdv, removed some lines.
- Fixed StrTok, 2 simple numbers made it loop everytime.
- Fixed some small issues in the header file.
Attached Files
File Type: zip strfunc.zip (8.2 KB, 245 views)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 5th February 2004, 10:37   #36
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Thanks.

I tried to write an example file for the header file but stumbled upon a few problems. The example file, including the described problems is attached.

StrLoc doesn't seem to function when the string it searches for is larger than the string it searches in. I found this because I got confused of the readme which states the usage line is:

${StrLoc} ResultVar String StrToSearchIn Direction

On first look it looks like I'm supposed to put the string that I want searched in StringToSearchIn, but it's the other way around. How about SearchIn SearchFor?

According to my understanding, the next line should return "abc", but it doesn't:

${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1"

It returns an empty string. If I search for the second occurrence of "abc" in "abcabcabc", starting from the right position, it should find the second set of "abc", but it doesn't.

StrSort doesn't seem to want to search for more than one char (line 136). It also has a problem if you want to search for "error" (line 139).

And last but not least, StrTok gets stuck in an endless loop if the token number is 0.
Attached Files
File Type: nsi strfunc.nsi (5.2 KB, 237 views)

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 6th February 2004, 02:23   #37
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Version 1.01, all bugs you said are fixed:

- Fixed Documentation about StrSort and StrTok.
- Fixed StrTok default value for the string part. Now it's "L".
- Fixed StrStrAdv fixed wrong search when had a combination of same substrings one after another in a string.
- Fixed StrLoc, when a string isn't found, don't return any value at all.

Read the manual for see more details.
Attached Files
File Type: zip strfunc.zip (8.5 KB, 221 views)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 6th February 2004, 12:50   #38
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
StrLoc and StrSort are still not working right. The documentation of StrSort got mixed up. It's talking about StringToSearch but there is no such parameter on the usage line. Example attached.
Attached Files
File Type: nsi strfunc.nsi (5.9 KB, 226 views)

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 6th February 2004, 23:42   #39
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Fixed StrLoc, removed StrSort and added to CVS.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 7th February 2004, 02:17   #40
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Oh right, as you wish...

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump