Archive: How can I make this custom page


How can I make this custom page
Hy I would make me an custom page for my Counter-Strike 1.6 Extension Pack. In this custom page the user should can choose with an File Dir an (how can I make it that he can only chose mp3-files ?) MP3-File who he can hear at the startmenu of counter-Strike 1.6.

The File must be put in in $Installdir\cstrike\media
and it must be rename in gamestartup.mp3

Could anybody help me ? I don't know what I must do.


Firstly, in the INI file for the FileRequest, you want:
Filter=MP3 Files|*.mp3

To get the path selected, in the Page's Leave Function (set with Page pageFunc pageLeaveFunc), read the value from the INI file with MUI_INSTALLOPTIONS_READ.
Then, to move the file, do:
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "ini_file.ini" "Field X" "State"
Rename "$INSTDIR\cstrike\media\gamestartup.mp3" "$INSTDIR\cstrike\media\gamestartup-old.mp3"
Rename "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"

-Stu


Hy Afrow UK
you're very friendly and help me a lot.

Thank you

I've tried to make the Custom Page like you've write. But I think that I've make something wrong, because there comes always the Error:

Error: resolving create-page function "PageMP3-File" in install pages
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process


Could you help me to find what I've make wrong?

Thank you


Quite obviously, you're missing the PageMP3-File Function in your script.

You need:
Function PageMP3-File
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "MP3-File.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "MP3-File.ini"
FunctionEnd

-Stu


Hy, thank you for the reply. I've added the function but there is still the same error.

I write all the thing who I write in the .nsi in the following code.

Is there something wrong?



; ReserveFiles
ReserveFile "MP3-File.ini"



; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page custom PageMP3-File PageLeaveMP3-File
!insertmacro MUI_PAGE_FINISH


; Funtions
Function .onInit

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "MP3-File.ini"

FunctionEnd


; Page MP3-File
Function PageMP3-File


!insertmacro MUI_HEADER_TEXT "MP3-File Einfügen" "Spielmenü Sound ändern"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "MP3-File.ini"
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
Rename "$INSTDIR\cstrike\media\gamestartup.mp3" "$INSTDIR\cstrike\media\gamestartup-old.mp3"
Rename "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"

FunctionEnd


You still need the Leave function present too!
Please read about the Page instruction syntax in the NSIS manual.


; ReserveFiles
ReserveFile "MP3-File.ini"

; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page custom PageMP3-File PageLeaveMP3-File
!insertmacro MUI_PAGE_FINISH

; Funtions
Function .onInit

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "MP3-File.ini"

FunctionEnd


; Page MP3-File
Function PageMP3-File

!insertmacro MUI_HEADER_TEXT "MP3-File Einfügen" "Spielmenü Sound ändern"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "MP3-File.ini"

FunctionEnd

Function PageLeaveMP3-File

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
Rename "$INSTDIR\cstrike\media\gamestartup.mp3" "$INSTDIR\cstrike\media\gamestartup-old.mp3"
Rename "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"

FunctionEnd

-Stu

Hy thank you the error isn' come more. And the rename of gamestartup.mp3 in gamestartup.mp3 works too. But the transfer from the $R0 in $Installdir\cstrike\media
doesn't work I've test if it works when I writc


; Page Leave MP3-File
Function PageLeaveMP3-File

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
Delete "$INSTDIR\cstrike\media\gamestartup.mp3"
CreateDirectory $INSTDIR\cstrike\media
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media"
Rename "$R0" "gamestartup.mp3"

FunctionEnd


But it isdn't work. What could I do?

Thank you

Just do:

Delete "$INSTDIR\cstrike\media\gamestartup.mp3"
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"

-Stu


Hy thank you for always answer me very friendly. I've make it now like you have write, but it doesn't works. The old gamestartup.mp3 is deleted but there isn't the new. Could it be that I must write something in the MP3-Page.ini ?

This is it:

[Settings]
NumFields=3
CancelEnabled=0
CancelShow=0
BackEnabled=0

[Field 1]
Type=FileRequest
State=FileRequest
Left=30
Right=153
Top=27
Bottom=40
Filter=MP3 Files|*.mp3

[Field 2]
Type=Label
Text=Wählen sie eine MP3-Audio Datei, die Sie im Spielmenü von Counter-Strike 1.6 hören wollen.
Left=4
Right=197
Top=2
Bottom=19

[Field 3]
Type=Label
Text=Bei keiner wird die jetzige behalten
Left=37
Right=150
Top=44
Bottom=52


Perhaps you should add validation for this:

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
StrCmp $R0 "" +2
IfFileExists $R0 +2
Abort
Delete "$INSTDIR\cstrike\media\gamestartup.mp3"
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"

-Stu


Mmh no it doesn't works. But thank you that you have help me.


Ok, try:
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\*"

-Stu


Hy Afrow UK,
the code

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
StrCmp $R0 "" +2
IfFileExists $R0 +2
Abort
Delete "$INSTDIR\cstrike\media\gamestartup.mp3"
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\gamestartup.mp3"


hasn't works so I've tested the Code

CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\*"

with this code

Function PageLeaveMP3-File

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "MP3-File.ini" "Field 1" "FileRequest"
Delete "$INSTDIR\cstrike\media\gamestartup.mp3"
CopyFiles /silent "$R0" "$INSTDIR\cstrike\media\*"

FunctionEnd

But it isn't works

Thank you Sp33dy


I don't see why it can't work, unless the $INSTDIR\cstrike\media folder does not exist. Plus you need the code I posted in case the user does not enter an MP3 file on the custom page (if that happens it will delete their gamestartup.mp3 and not replace it).
Just keep messing with CopyFiles. I can't help you any further because I can't see anything wrong with the code.

-Stu