; ---------------------------------------------------- ; PortableMaxima ; ---------------------------------------------------- ; Par sarkos modifié par Mageti & Joshua ; Utilisant comme base de travail le script de John T. Haller ; License : GPL ; Ce script permet de créer PortableMaxima. ; Ce script est à compiler avec NSIS de Nullsoft (http://www.nullsoft.com). ; Il nécessite le plugin "ipicsplash" (affichage splashscreen) et "Registry" (pour les manipulation de la base de registre) pour être compilé. ; $id=PortablePhotoFiltre.nsi $date=2006-04-55 ; ---------------------------------------------------- ; Général !define NAME "PortableWxMaxima" !define APP "WxMaxima" !define VER "0.1.0.0" !define DEFAULTEXE "Wxmaxima.exe" !define DEFAULTAPPDIR "Maxima\wxMaxima" !define OUTDIR "Maxima\wxMaxima" !define REGCONFHOTE "HKCUWxMaxima_hote.reg" !define REGNOTRECONF "HKCUWxMaxima.reg" !define REGKEYCONF "HKEY_CURRENT_USER\Software\wxMaxima" !include "Registry.nsh" ; Nom de l'exécutable Name "${NAME}" ; Etiquette Caption "${NAME} - Portable" ; Icone Icon "${NAME}.ico" WindowIcon Off ; Nom du fichier à créer OutFile "${NAME}.exe" ; Runtime Switches SetDateSave on SetDatablockOptimize on CRCCheck On SilentInstall Silent AutoCloseWindow True ; ---------------------------------------------------- ; Variables Var IniPath Var DataDir Var AppDirectory Var AppExecutable Var AdditionalParameters Var DisableSplashScreen Var ExecString ; ---------------------------------------------------- ; Version Informations VIProductVersion "${VER}" VIAddVersionKey FileDescription "${NAME} pour Windows" VIAddVersionKey LegalCopyright "GPL" VIAddVersionKey Comments "Permet de lancer ${APP} depuis un disque amovible." VIAddVersionKey CompanyName "par Mageti pour Framasoft" VIAddVersionKey OriginalFilename "${NAME}.exe" VIAddVersionKey FileVersion "${VER}" ; ---------------------------------------------------- ; Sections Section "Main" ; Trouver le fichier INI, s'il y en a un IfFileExists "$EXEDIR\${NAME}.ini" "" CheckDataINI StrCpy "$IniPath" "$EXEDIR" Goto ReadINI CheckDataINI: Push "$EXEDIR" Call GetRoot Pop $0 strcpy "$DataDir" "$0\Data\AppsData" IfFileExists "$DataDir\${APP}\${NAME}.ini" "" NoINI StrCpy "$IniPath" "$DataDir\${APP}" Goto ReadINI ReadINI: ; Lit les paramètres du fichier INI ReadINIStr $0 "$IniPath\${NAME}.ini" "${NAME}" "${APP}Directory" StrCpy "$AppDirectory" "$EXEDIR\$0" ; Vérifie que les paramètres requis ci-dessus sont présents IfErrors NoINI ReadINIStr $0 "$IniPath\${NAME}.ini" "${NAME}" "AdditionalParameters" StrCpy "$AdditionalParameters" $0 ReadINIStr $0 "$IniPath\${NAME}.ini" "${NAME}" "${APP}Executable" StrCpy "$AppExecutable" $0 ReadINIStr $0 "$IniPath\${NAME}.ini" "SplashScreen" "DisableSplashScreen" StrCpy "$DisableSplashScreen" $0 ; Pour n'importe quelle paramètre du fichier INI non requis contenant une chaine vide, ignorer les erreurs associées ClearErrors ; Correct PROGRAMEXECUTABLE si paramètre vide StrCmp $AppExecutable "" "" EndINI StrCpy "$AppExecutable" "${DEFAULTEXE}" Goto EndINI NoINI: ; Pas de fichier INI, nous utiliserons les paramètres par défaut StrCpy "$AdditionalParameters" "" StrCpy "$AppExecutable" "${DEFAULTEXE}" StrCpy "$DisableSplashScreen" "false" IfFileExists "$EXEDIR\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE StrCpy "$AppDirectory" "$EXEDIR\${DEFAULTAPPDIR}" GoTo EndINI EndINI: IfFileExists "$AppDirectory\$AppExecutable" FoundProgramEXE NoProgramEXE: ; Si le chemin pointant vers l'exécutable est invalide MessageBox MB_OK|MB_ICONEXCLAMATION `$AppDirectory\$AppExecutable was not found. Please check your configuration` Abort FoundProgramEXE: StrCmp $DisableSplashScreen "true" GetAppParameters ; Affiche le splash screen InitPluginsDir File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg" ipicsplash::show 1000 600 400 -1 "$PLUGINSDIR\splash.jpg" ; Check des paramètres GetAppParameters: Call GetParameters Pop $0 ; Routine si pas de paramètres StrCmp "'$0'" "''" "" ExecWithParameters StrCpy $ExecString `"$AppDirectory\$AppExecutable"` Goto AdditionalParameters ; Routine si paramètres ExecWithParameters: StrCpy $ExecString `"$AppDirectory\$AppExecutable" $0` Goto TestAdminRight AdditionalParameters: StrCmp $AdditionalParameters "" TestAdminRight ; Envoi des Paramètres additionnels StrCpy $ExecString `$ExecString $AdditionalParameters` ; test s'il existe une autre configuration dans la base de registre TestAdminRight: ; on va tester les droits administrateurs de l'utilisateur UserInfo::GetName IfErrors TestProfile ;pas de souci car pas de distinction entre admin et utilisateur autre Pop $7 UserInfo::GetAccountType Pop $8 StrCmp $8 "Admin" TestProfile 0 MessageBox MB_OK 'L utilisateur "$7" n est pas un administrateur, il se peut que l utilisation ne puisse pas se faire' Goto TestProfile TestProfile: ${registry::KeyExists} "HKEY_CURRENT_USER\Software\wxMaxima" $R8 IfErrors ErreurRegistre StrCmp $R8 "0" ExecWithOtherProfile ExecApp ExecWithOtherProfile: StrCpy $OUTDIR '${OUTDIR}' ; on sauvegarde la configuration de l'hôte ${registry::SaveKey} ${REGKEYCONF} "$EXEDIR\Profile\${REGCONFHOTE}" "/G=1 /D=2" $R9 ; on installe la notre ${registry::RestoreKey} "$EXEDIR\Profile\${REGNOTRECONF}" $R9 ; on lance l'appli ExecWait "$ExecString" ; on resauvegarde notre configuration ${registry::SaveKey} ${REGKEYCONF} "$EXEDIR\Profile\${REGNOTRECONF}" "/G=1 /D=2" $R9 ; et on réinjecte celle de l'hôte ${registry::RestoreKey} "$EXEDIR\Profile\${REGCONFHOTE}" $R9 Goto EndSection ; Lancement Application ExecApp: StrCpy $OUTDIR '${OUTDIR}' ;Intallation du Profile ${registry::RestoreKey} "$EXEDIR\Profile\${REGNOTRECONF}" $R9 ExecWait "$ExecString" ; Sauvegarde du profile : on copie les clefs de la base de registre ${registry::SaveKey} ${REGKEYCONF} "$EXEDIR\Profile\${REGNOTRECONF}" "/G=1 /D=2" $R9 ; On supprime les clefs de la base de registre ${registry::DeleteKey} ${REGKEYCONF} $R9 Goto EndSection ErreurRegistre: MessageBox MB_OK 'Une erreur est survenue et peut avoir été caussée $\n\ par le fait que vous n êtes pas administrateur $\n\ Le programme va se fermer' Goto EndSection EndSection: ${registry::Unload} SectionEnd Section .onInit Call Mutex SectionEnd ; ------------------------------------------- ; Obtenir les paramètres ; ------------------------------------------- Function "GetParameters" Push $R0 Push $R1 Push $R2 StrCpy $R0 $CMDLINE 1 StrCpy $R1 '"' StrCpy $R2 1 StrCmp $R0 '"' loop StrCpy $R1 ' ' ; we're scanning for a space instead of a quote loop: StrCpy $R0 $CMDLINE 1 $R2 StrCmp $R0 $R1 loop2 StrCmp $R0 "\" "" "nofile" IntOp $2 $R2 + 1 nofile: ;MessageBox MB_OK "r0: $R0" StrCmp $R0 "" loop2 IntOp $R2 $R2 + 1 Goto loop loop2: IntOp $R0 $R2 - $2 IntOp $R0 $R0 - 4 ;MessageBox MB_OK "$R2 - $2 = $R0" StrCpy $R7 $CMDLINE $R0 $2 ; we save the filename ;MessageBox MB_OK "$2" loop2b: IntOp $R2 $R2 + 1 StrCpy $R0 $CMDLINE 1 $R2 ;MessageBox MB_OK "rr0: $R0" StrCmp $R0 " " loop2b StrCpy $R0 $CMDLINE "" $R2 Pop $R2 Pop $R1 Exch $R0 FunctionEnd ; ------------------------------------------- ; Obtenir le chemin root ; Auteur : KiCHiK ; Source : http://nsis.sourceforge.net/Get_the_Root_Directory ; ------------------------------------------- Function GetRoot Exch $0 Push $1 Push $2 Push $3 Push $4 StrCpy $1 $0 2 StrCmp $1 "\\" UNC StrCpy $0 $1 Goto done UNC: StrCpy $2 3 StrLen $3 $0 loop: IntCmp $2 $3 "" "" loopend StrCpy $1 $0 1 $2 IntOp $2 $2 + 1 StrCmp $1 "\" loopend loop loopend: StrCmp $4 "1" +3 StrCpy $4 1 Goto loop IntOp $2 $2 - 1 StrCpy $0 $0 $2 done: Pop $4 Pop $3 Pop $2 Pop $1 Exch $0 FunctionEnd ; ------------------------------------------- ; Prévenir plusieurs Instances ; Sources : http://www.veekee.net/wikinsis/docs/AppendiceC.html#C.11 ; ------------------------------------------- Function Mutex System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex") i .r1 ?e' Pop $R0 StrCmp $R0 0 +3 MessageBox MB_OK|MB_ICONEXCLAMATION "${NAME} est déjà lancé." Abort FunctionEnd ; ------------------------------------------- ; Fin du script