WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Help needed to compile helper!
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

Help needed to compile helper!

well, based on Instructor's functions and code posted on other topics I'm trying to compile a script that takes a given directory and builds a proper list ready to !include in install section. This could be a helper to parse the entire directory structure in the installation script. The code that I'm figuring is this:

code:
OutFile test.exe Name "NSIS Script Helper" !include "FileFunc.nsh" !insertmacro Locate !define DirName 'D:\New_Installation' !define FileList '$EXEDIR\Files.lst' var TargetDir Section FileOpen $R1 ${FileList} w ${Locate} "${DirName}" "/L=F /M=*.*" "LocateCallBack" FileClose $R1 IfErrors 0 +2 MessageBox MB_OK "Error" IDOK +2 Exec '"notepad.exe" "${FileList}"' SectionEnd Function LocateCallBack StrLen $R2 '${DirName}' StrCpy $TargetDir $R8 '' $R2 StrCmp $TargetDir '' +1 +3 FileWrite $R1 'SetOutPath "$$INSTDIR"$\r$\n' goto +2 FileWrite $R1 'CreateDirectory "$$INSTDIR$TargetDir"$\r$\nSetOutPath "$$INSTDIR$TargetDir"$\r$\n' FileWrite $R1 'File "$R8\$R7"$\r$\n' Push $0 FunctionEnd

The resulting list where I really stuck is this:
code:
SetOutPath "$INSTDIR" File "D:\New_Installation\root.dll" SetOutPath "$INSTDIR" File "D:\New_Installation\rootexec.exe" CreateDirectory "$INSTDIR\subdir" SetOutPath "$INSTDIR\subdir" File "D:\New_Installation\subdir\other_recourse.dll" CreateDirectory "$INSTDIR\subdir" SetOutPath "$INSTDIR\subdir" File "D:\New_Installation\subdir\recourse.dll" CreateDirectory "$INSTDIR\subdir\Folder" SetOutPath "$INSTDIR\subdir\Folder" File "D:\New_Installation\subdir\Folder\somedll.dll" CreateDirectory "$INSTDIR\subdir\Folder" SetOutPath "$INSTDIR\subdir\Folder" File "D:\New_Installation\subdir\Folder\some_other.dll" CreateDirectory "$INSTDIR\documents" SetOutPath "$INSTDIR\documents" File "D:\New_Installation\documents\help.pdf" CreateDirectory "$INSTDIR\documents" SetOutPath "$INSTDIR\documents" File "D:\New_Installation\documents\more_help.html"

I can't handle how I should write the code to eliminate the repeated lines 'SetOutPath...' and 'CreateDirectory...' so the resulting list will be like this:
code:
SetOutPath "$INSTDIR" File "D:\New_Installation\root.dll" File "D:\New_Installation\rootexec.exe" CreateDirectory "$INSTDIR\subdir" SetOutPath "$INSTDIR\subdir" File "D:\New_Installation\subdir\other_recourse.dll" File "D:\New_Installation\subdir\recourse.dll" CreateDirectory "$INSTDIR\subdir\Folder" SetOutPath "$INSTDIR\subdir\Folder" File "D:\New_Installation\subdir\Folder\somedll.dll" File "D:\New_Installation\subdir\Folder\some_other.dll" CreateDirectory "$INSTDIR\documents" SetOutPath "$INSTDIR\documents" File "D:\New_Installation\documents\help.pdf" File "D:\New_Installation\documents\more_help.html"

Help please!

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Last edited by Red Wine on 03-23-2006 at 10:36 PM

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-23-2006 09:40 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Afrow UK
Moderator

Registered: Nov 2002
From: Shropshire, England

I'm not sure why CreateDirectory is being used in the first place. With the above code you'll find that all the files will get dumped in $INSTDIR (because SetOutPath sets the output directory, and it's being set to $INSTDIR to begin with and it's never being changed thereafter).

You could try the RecFind script header at:
http://nsis.sourceforge.net/RecFind...xt%2C_FindClose

Your code would then look like this:

code:
OutFile GenerateFileList.exe Name "GenerateFileList" !include RecFind.nsh !define DirName 'D:\New_Installation' !define FileList '$EXEDIR\Files.lst' Section FileOpen $R2 ${FileList} w ${RecFindOpen} "${DirName}" $R0 $R1 FileWrite $R2 'SetOutPath "$\r$\n${DirName}$R0$\r$\n"' ${RecFindFirst} FileWrite $R2 'File "${DirName}$R0\$R1$\r$\n"' ${RecFindNext} ${RecFindClose} FileClose $R2 Quit SectionEnd


Although the code is much simpler you have less options here. I actually implemented a file extension filter into ${RecFindFirst} but for some reason I never uploaded the changes and now I've lost them altogether. I'll probably sort this out sometime.

-Stu

__________________
afrowuk.co.uk

Quick Link | Report this post to a moderator | IP: Logged

Afrow UK is offline Old Post 03-23-2006 10:23 PM
Click Here to See the Profile for Afrow UK Click here to Send Afrow UK a Private Message Click Here to Email Afrow UK Visit Afrow UK's homepage! Find more posts by Afrow UK Add Afrow UK to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

oops sorry!
I missed a line in my code! now it's fixed and writes the proper SetOutPath for every created directory. Yet, the problem is still there! how can I eliminate the repeated lines?

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-23-2006 10:42 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

@ -Stu
This is the list I got with your function.

code:
SetOutPath " D:\New_Installation "File "D:\New_Installation\root.dll "File "D:\New_Installation\rootexec.exe "SetOutPath " D:\New_Installation\subdir "File "D:\New_Installation\subdir\other_recourse.dll "File "D:\New_Installation\subdir\recourse.dll "SetOutPath " D:\New_Installation\subdir\Folder "File "D:\New_Installation\subdir\Folder\somedll.dll "File "D:\New_Installation\subdir\Folder\some_other.dll "SetOutPath " D:\New_Installation\documents "File "D:\New_Installation\documents\help.pdf "File "D:\New_Installation\documents\more_help.html "

Quite close to what I'm looking for!!!
I should change the variables when writing to the file to point the InstallDir and subdirs and create them also. That's OK I guess, I'm going to make it later. Yet, there are some strange things with the quotes. How should I fix them?
Thanks anyway!

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-23-2006 11:08 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

The quotes was the easiest thing!
Based on Stu's code above here is the script:

code:
OutFile GenerateFileList.exe Name "GenerateFileList" !include RecFind.nsh !define DirName 'D:\New_Installation' !define FileList '$EXEDIR\Files.lst' Section FileOpen $R2 ${FileList} w ${RecFindOpen} "${DirName}" $R0 $R1 StrCmp '$R0' '' +1 +3 FileWrite $R2 'SetOutPath "$$INSTDIR$R0"$\r$\n' Goto +2 FileWrite $R2 'CreateDirectory "$$INSTDIR$R0"$\r$\nSetOutPath "$$INSTDIR$R0"$\r$\n' ${RecFindFirst} FileWrite $R2 'File "${DirName}$R0\$R1"$\r$\n' ${RecFindNext} ${RecFindClose} FileClose $R2 Quit SectionEnd

And here is the resulting list:
code:
SetOutPath "$INSTDIR" File "D:\New_Installation\root.dll" File "D:\New_Installation\rootexec.exe" CreateDirectory "$INSTDIR\subdir" SetOutPath "$INSTDIR\subdir" File "D:\New_Installation\subdir\other_recourse.dll" File "D:\New_Installation\subdir\recourse.dll" CreateDirectory "$INSTDIR\subdir\Folder" SetOutPath "$INSTDIR\subdir\Folder" File "D:\New_Installation\subdir\Folder\somedll.dll" File "D:\New_Installation\subdir\Folder\some_other.dll" CreateDirectory "$INSTDIR\documents" SetOutPath "$INSTDIR\documents" File "D:\New_Installation\documents\help.pdf" File "D:\New_Installation\documents\more_help.html"

Thanks Stu

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-23-2006 11:42 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

You don't need CreateDirectory because SetOutPath create it.

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 03-24-2006 06:09 AM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

Hi Instructor,
need it or not, do you have any suggestions how to eliminate the repeated lines for the example (top of the page} based in your code?
Thanks in advance

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-24-2006 08:10 AM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Afrow UK
Moderator

Registered: Nov 2002
From: Shropshire, England

No need for this at all in the RecFind script:

code:
StrCmp '$R0' '' +1 +3 FileWrite $R2 'SetOutPath "$$INSTDIR$R0"$\r$\n' Goto +2 FileWrite $R2 'CreateDirectory "$$INSTDIR$R0"$\r$\nSetOutPath "$$INSTDIR$R0"$\r$\n'

Anything between ${RecFindOpen} and ${RecFindFirst} is executed only when moving into a new directory and not for each new file found. Also $R0 (the directory path) will never be empty "" so it will always jump to the second FileWrite instruction anyway.

Therefore you just need:
code:
FileWrite $R2 'SetOutPath "$$INSTDIR$R0"$\r$\n'

SetOutPath creates the directories recursively as well! So no need for CreateDirectory.

-Stu

__________________
afrowuk.co.uk

Quick Link | Report this post to a moderator | IP: Logged

Afrow UK is offline Old Post 03-24-2006 09:36 AM
Click Here to See the Profile for Afrow UK Click here to Send Afrow UK a Private Message Click Here to Email Afrow UK Visit Afrow UK's homepage! Find more posts by Afrow UK Add Afrow UK to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

quote:
do you have any suggestions how to eliminate the repeated lines for the example (top of the page} based in your code?

code:
Name "Output" OutFile "Output.exe" !include "FileFunc.nsh" !insertmacro Locate !define DirName 'C:\TC' !define FileList '$EXEDIR\Files.lst' Section StrCpy $R0 '' StrLen $R1 '${DirName}' FileOpen $R3 '${FileList}' w FileWrite $R3 'SetOutPath "$$INSTDIR"$\r$\n' ${Locate} "${DirName}" "/L=F /M=*.*" "LocateCallBack" FileClose $R3 IfErrors 0 +2 MessageBox MB_OK "Error" IDOK +2 Exec '"notepad.exe" "${FileList}"' SectionEnd Function LocateCallBack StrCpy $1 $R8 '' $R1 StrCmp $R0 $1 +4 StrCpy $R0 $1 FileWrite $R3 'SetOutPath "$$INSTDIR$R0"$\r$\n' goto +2 FileWrite $R3 'File "$R9"$\r$\n' Push $0 FunctionEnd

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 03-24-2006 10:03 AM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

@ Stu:
Yes, you're always turning on the light! I used SetOutPath $INSTDIR in my install section also, that's why appeared two times up there!
@ Instructor:
I'll check that later, yet, I'm sure it works.

Thanks, I'm learning from you people, and I like it!

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-24-2006 10:42 AM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

OK, no need for CreateDirectory while SetOutPath creates the directories recursively as mentionend above. I use it just to have the list in tact.
@ Instructor: The code in your last post getting closer. There are not repeated lines, though, it takes only the first file found into every subdir.

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-24-2006 12:29 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

quote:
@ Instructor: The code in your last post getting closer. There are not repeated lines, though, it takes only the first file found into every subdir.
Oops
code:
Name "Output" OutFile "Output.exe" !include "FileFunc.nsh" !insertmacro Locate !define DirName 'C:\TC' !define FileList '$EXEDIR\Files.lst' Section StrCpy $R0 '' StrLen $R1 '${DirName}' FileOpen $R3 '${FileList}' w FileWrite $R3 'SetOutPath "$$INSTDIR"$\r$\n' ${Locate} "${DirName}" "/L=F /M=*.*" "LocateCallBack" FileClose $R3 IfErrors 0 +2 MessageBox MB_OK "Error" IDOK +2 Exec '"notepad.exe" "${FileList}"' SectionEnd Function LocateCallBack StrCpy $1 $R8 '' $R1 StrCmp $R0 $1 +3 StrCpy $R0 $1 FileWrite $R3 'SetOutPath "$$INSTDIR$R0"$\r$\n' FileWrite $R3 'File "$R9"$\r$\n' Push $0 FunctionEnd

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 03-24-2006 12:59 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

COOL! Both working perfect!
Such things I could not manage by my self yet.
Keep going. Scratching NSIS's shell. With these two tools, let's see If I can figure a simple helper gui which offers options to select a given dir and all subdirs, select only files into the root of the given dir, or select individual files from different locations and build a list ready to !include. Besides the scratching, I guess would be usefull if one could save some typing while building an installation.
I'll come back later.

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 03-24-2006 02:19 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 08:48 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Help needed to compile helper!
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON