Archive: Need help with my custom page (droplist)


Need help with my custom page (droplist)
Hi,
I've created a custom page.

http://cs-erweiterungen.de/Picture.jpg

On the custom page the user can insert his steam ID/IP or a name. When he has insert his steam ID/IP or name he must choose which type it is.

It's for define an Admin. One can define 3 Admins.

The first "admin code" works fine but I've a problem with the 2 others.. when one choose the type of Admin in the droplist it isn't work. In the "users.ini" file are further the words Flag1 or Flag2.

Could you help me?

; Password Page
Function Steam_IDPage
!insertmacro SectionFlagIsSet ${Section2} ${SF_SELECTED} ShowPage SkipPage
ShowPage:

GetDlgItem $R0 $HWNDPARENT 2
EnableWindow $R0 0|1 # 0=hide, 1=show
GetDlgItem $R0 $HWNDPARENT 3
EnableWindow $R0 0|1 # 0=hide, 1=show
!insertmacro MUI_HEADER_TEXT "Konfiguration des Erweiterungs System" "Tragen Sie die Administratoren ein."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "steam_id.ini"

SkipPage:

FunctionEnd

Function .OnGUIEnd
Call CopyFlag
FunctionEnd

; Copy Flag
!macro REPLACE_FLAG1 SOURCE

Push "Flag1" #-- text to be replaced within the " "
Push "${SOURCE}" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

goto done3
!macroend

; Copy Flag
!macro REPLACE_FLAG2 SOURCE

Push "Flag2" #-- text to be replaced within the " "
Push "${SOURCE}" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

goto done3
!macroend

; Copy Flag
!macro REPLACE_FLAG3 SOURCE

Push "Flag3" #-- text to be replaced within the " "
Push "${SOURCE}" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

goto done3
!macroend

; Copy Flag
Function CopyFlag

;1
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 12" "State"

StrCmp $R0 "Steam ID" 0 notSteamID1
!insertmacro REPLACE_FLAG1 ce
notSteamID1:

StrCmp $R0 "IP" 0 notIP1
!insertmacro REPLACE_FLAG1 de
notIP1:

StrCmp $R0 "Name" 0 done1
!insertmacro REPLACE_FLAG1 be
done1:

;2
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 13" "State"

StrCmp $R0 "Steam ID" 0 notSteamID2
!insertmacro REPLACE_FLAG2 ce
notSteamID2:

StrCmp $R0 "IP" 0 notIP2
!insertmacro REPLACE_FLAG2 de
notIP2:

StrCmp $R0 "Name" 0 done2
!insertmacro REPLACE_FLAG2 be
done2:

;3
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 14" "State"

StrCmp $R0 "Steam ID" 0 notSteamID3
!insertmacro REPLACE_FLAG3 ce
notSteamID3:

StrCmp $R0 "IP" 0 notIP3
!insertmacro REPLACE_FLAG3 de
notIP3:

StrCmp $R0 "Name" 0 done3
!insertmacro REPLACE_FLAG3 be
done3:

Pop $R0
FunctionEnd

LangString NoSteam_ID ${LANG_GERMAN} "Bitte geben Sie eine Steam_ID ein!"

; Page Leave Feautures
Function PageLeaveSteam_ID

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "steam_id.ini" "Field 7" "State"
${If} $R0 != ""
Push "steamid1" #-- text to be replaced within the " "
Push "$R0" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function
${EndIf}

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "steam_id.ini" "Field 8" "State"
${If} $R0 != ""
Push "steamid2" #-- text to be replaced within the " "
Push "$R0" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function
${EndIf}

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "steam_id.ini" "Field 9" "State"
${If} $R0 != ""
Push "steamid3" #-- text to be replaced within the " "
Push "$R0" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\cstrike\addons\amxmodx\configs\users.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function
${EndIf}

ReadIniStr $0 '$PLUGINSDIR\steam_id.ini' 'Field 12' 'State'
strcmp $0 '' error ok
error:
MessageBox MB_OK "Bitte wählen Sie einen 'Admintyp' aus!"
abort
ok:

FunctionEnd

Hi!

What exactly is not working? You can't use the droplist box?

Cheers

Bruno


Yes, right my problem ist that the code from the droplist number 2 and 3 are not working.

I've extract the code now.

Thanks for your help. I hope you understand my problem :)


Hi Speedy!

The script reads "state" of the wrong sections.
I suggest using


!define CMB_ADMINTYP1 "Field 5"
:
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "${CMB_ADMINTYP1}" "State"


If you change your dialog, you only have to change the definitions in one place.

These are the correct ReagINIStr:

ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 10" "State"
:
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 11" "State"
:
ReadINIStr $R0 "$PLUGINSDIR\steam_id.ini" "Field 12" "State"

I suggest not using goto in your REPLACE_FLAGx macros. They are wrong, because they jump to done3 which is after the third instruction set.

Just a question:

What is the purpose of Pop in there?

done3:

Pop $R0 ; <<--
FunctionEnd


Ok, with these hints the script should work.

To improve the readability of your script, you might create the macros in this manner:

!macro REPLACE FLAG SOURCE
Push "${FLAG}" #-- text to be replaced within
Push "${SOURCE}" #-- replace with anything
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $INSTDIR\Test.txt #-- file to replace in
Call AdvReplaceInFile #-- Call the Function
!macroend

With this change you could remove two macros.

Ok, hope this helps.

Have a nice day!

Tschuess!

Bruno

Thanks a lot Bruno :)

It works fine. Only one further question.

Is it possible when user writes something in Field 8, in Field 11 must be also choosed the "Admintyp"...

and when he writes something in Field 9, in Field 10 must be choosed the "Admintyp"?

Thank you


Hi Speedy!

Yes of course!

Just add code to your validate script (PageLeaveSteam_ID): Read every value and decide whether everything is alright. If not, tell the user why and call Abort. This will leave the dialog as it is. The user edits the entries and tries again.

Have a nice day!

Cheers

Bruno


Hi,
I've tried now to create this code but I don't understand how I can make this code that he checks values between two Fields:

I tried this but it's completely wrong^^:

!insertmacro MUI_INSTALLOPTIONS_READ $R1 "steam_id.ini" "Field 8" "State"
strcmp $R0 '' $R1 error ok
error:
MessageBox MB_OK|MB_ICONINFORMATION "$(NoAdmin)"
Abort
ok:


Could you write me an example please :)?
Thank you

Hi Speedy!

Here's a draft how it could look like.


ReadIniStr $0 '$PLUGINSDIR\steam_id.ini' 'Field 12' 'State'
ReadIniStr $1 '$PLUGINSDIR\steam_id.ini' 'Field 7' 'State'

${Unless} $1 == '' ; if not
${If} $0 == ''
MessageBox MB_OK "Bitte wählen Sie einen 'Admintyp' aus!"
Abort
${EndIf}
${EndIf}


LogicLib is very useful. Here you'll find some information:
http://nsis.sourceforge.net/LogicLib
and in the Examples\LogicLib.nsi too.

Have a nice day!

Cheers

Bruno

Hey thanks :) !

Works perfect