Advertisement
Guest User

Kyle

a guest
Jan 30th, 2010
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Copyright (C) 2004-2009 John T. Haller
  2.  
  3. ;Website: http://PortableApps.com/7-ZipPortable
  4.  
  5. ;This software is OSI Certified Open Source Software.
  6. ;OSI Certified is a certification mark of the Open Source Initiative.
  7.  
  8. ;This program is free software; you can redistribute it and/or
  9. ;modify it under the terms of the GNU General Public License
  10. ;as published by the Free Software Foundation; either version 2
  11. ;of the License, or (at your option) any later version.
  12.  
  13. ;This program is distributed in the hope that it will be useful,
  14. ;but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;GNU General Public License for more details.
  17.  
  18. ;You should have received a copy of the GNU General Public License
  19. ;along with this program; if not, write to the Free Software
  20. ;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  21.  
  22. !define PORTABLEAPPNAME "Age of Empires Portable"
  23. !define NAME "AgeOfEmpiresPortable"
  24. !define APPNAME "AOE"
  25. !define VER "1.0.0.0"
  26. !define WEBSITE "PortableApps.com/AgeOfEmpiresPortable"
  27. !define DEFAULTEXE "EMPIRES.EXE"
  28. !define DEFAULTAPPDIR "AgeOfEmpires"
  29. !define DEFAULTSETTINGSPATH "settings"
  30. !define LAUNCHERLANGUAGE "English"
  31.  
  32. ;=== Program Details
  33. Name "${PORTABLEAPPNAME}"
  34. OutFile "..\..\${NAME}.exe"
  35. Caption "${PORTABLEAPPNAME} | PortableApps.com"
  36. VIProductVersion "${VER}"
  37. VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
  38. VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
  39. VIAddVersionKey CompanyName "PortableApps.com"
  40. VIAddVersionKey LegalCopyright "John T. Haller"
  41. VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
  42. VIAddVersionKey FileVersion "${VER}"
  43. VIAddVersionKey ProductVersion "${VER}"
  44. VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
  45. VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
  46. VIAddVersionKey OriginalFilename "${NAME}.exe"
  47. ;VIAddVersionKey PrivateBuild ""
  48. ;VIAddVersionKey SpecialBuild ""
  49.  
  50. ;=== Runtime Switches
  51. CRCCheck On
  52. WindowIcon Off
  53. SilentInstall Silent
  54. AutoCloseWindow True
  55. RequestExecutionLevel user
  56.  
  57. ; Best Compression
  58. SetCompress Auto
  59. SetCompressor /SOLID lzma
  60. SetCompressorDictSize 32
  61. SetDatablockOptimize On
  62.  
  63. ;=== Include
  64. ;(Standard NSIS)
  65. !include Registry.nsh
  66. !include TextFunc.nsh
  67. !insertmacro GetParameters
  68.  
  69. ;(Custom)
  70. !include ReadINIStrWithDefault.nsh
  71.  
  72. ;=== Program Icon
  73. Icon "..\..\App\AppInfo\appicon.ico"
  74.  
  75. ;=== Languages
  76. LoadLanguageFile "${NSISDIR}\Contrib\Language files\${LAUNCHERLANGUAGE}.nlf"
  77. !include PortableApps.comLauncherLANG_${LAUNCHERLANGUAGE}.nsh
  78.  
  79. Var PROGRAMDIRECTORY
  80. Var SETTINGSDIRECTORY
  81. Var ADDITIONALPARAMETERS
  82. Var EXECSTRING
  83. Var PROGRAMEXECUTABLE
  84. Var INIPATH
  85. Var DISABLESPLASHSCREEN
  86. Var ISDEFAULTDIRECTORY
  87. Var SECONDARYLAUNCH
  88. Var FAILEDTORESTOREKEY
  89. Var MISSINGFILEORPATH
  90. Var APPLANGUAGE
  91.  
  92.  
  93. Section "Main"
  94.     ;=== Check if already running
  95.     System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}2") i .r1 ?e'
  96.     Pop $0
  97.     StrCmp $0 0 CheckForINI
  98.         StrCpy $SECONDARYLAUNCH "true"
  99.  
  100.     CheckForINI:
  101.     ;=== Find the INI file, if there is one
  102.         IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
  103.             StrCpy "$INIPATH" "$EXEDIR"
  104.             Goto ReadINI
  105.  
  106.     ReadINI:
  107.         ;=== Read the parameters from the INI file
  108.         ${ReadINIStrWithDefault} $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory" "App\${DEFAULTAPPDIR}"
  109.         StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
  110.         ${ReadINIStrWithDefault} $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory" "Data\${DEFAULTSETTINGSPATH}"
  111.         StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"
  112.  
  113.         ;=== Check that the above required parameters are present
  114.         IfErrors NoINI
  115.  
  116.         ${ReadINIStrWithDefault} $ADDITIONALPARAMETERS "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters" ""
  117.         ${ReadINIStrWithDefault} $PROGRAMEXECUTABLE "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable" "${DEFAULTEXE}"
  118.         ${ReadINIStrWithDefault} $DISABLESPLASHSCREEN "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen" "false"
  119.  
  120.         ;=== Correct PROGRAMEXECUTABLE if blank
  121.         StrCmp $PROGRAMEXECUTABLE "" "" CheckForProgramINI
  122.             StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
  123.             Goto CheckForProgramINI
  124.            
  125.     CheckForProgramINI:
  126.         IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE
  127.  
  128.     NoINI:
  129.         ;=== No INI file, so we'll use the defaults
  130.         StrCpy "$ADDITIONALPARAMETERS" ""
  131.         StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
  132.         StrCpy "$DISABLESPLASHSCREEN" "false"
  133.  
  134.         IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
  135.             StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
  136.             StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}"
  137.             StrCpy "$ISDEFAULTDIRECTORY" "true"
  138.             GoTo FoundProgramEXE
  139.  
  140.     NoProgramEXE:
  141.         ;=== Program executable not where expected
  142.         StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
  143.         MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
  144.         Abort
  145.        
  146.     FoundProgramEXE:
  147.         ;=== Check if already running
  148.         StrCmp $SECONDARYLAUNCH "true" CheckForSettings
  149.         FindProcDLL::FindProc "$PROGRAMEXECUTABLE"                
  150.         StrCmp $R0 "1" WarnAnotherInstance CheckForSettings
  151.  
  152.     WarnAnotherInstance:
  153.         MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
  154.         Abort
  155.    
  156.     CheckForSettings:
  157.         IfFileExists "$SETTINGSDIRECTORY\*.*" GetPassedParameters
  158.         ;=== No settings found
  159.         StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
  160.         CreateDirectory $SETTINGSDIRECTORY
  161.         Goto SettingsFound
  162.    
  163.     CopyDefaultSettings:
  164.         CreateDirectory "$EXEDIR\Data"
  165.         CreateDirectory "$EXEDIR\Data\settings"
  166.         CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
  167.         GoTo SettingsFound
  168.  
  169.     SettingsFound:
  170.         StrCpy $DISABLESPLASHSCREEN "true"
  171.         StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
  172.             ;=== Show the splash screen before processing the files
  173.             InitPluginsDir
  174.             File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"   
  175.             newadvsplash::show /NOUNLOAD 1500 0 0 -1 /L $PLUGINSDIR\splash.jpg
  176.  
  177.     GetPassedParameters:
  178.         ;=== Get any passed parameters
  179.         ${GetParameters} $0
  180.         StrCmp "'$0'" "''" "" LaunchProgramParameters
  181.  
  182.         ;=== No parameters
  183.         StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
  184.         Goto AdditionalParameters
  185.  
  186.     LaunchProgramParameters:
  187.         StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`
  188.  
  189.     AdditionalParameters:
  190.         StrCmp $ADDITIONALPARAMETERS "" LaunchNow
  191.  
  192.         ;=== Additional Parameters
  193.         StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`
  194.  
  195.     /*RegistryBackup:
  196.         StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
  197.         ;=== Backup the registry
  198.         ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00BACKUP" $R0
  199.         StrCmp $R0 "0" RestoreTheKey
  200.         ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00" $R0
  201.         StrCmp $R0 "-1" RestoreTheKey
  202.         ${registry::MoveKey} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00" "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00BACKUP" $R0
  203.         Sleep 100
  204.  
  205.     RestoreTheKey:
  206.         IfFileExists "$SETTINGSDIRECTORY\aoe.reg" "" LaunchNow
  207.    
  208.         IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
  209.             nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\aoe.reg"`
  210.             Pop $R0
  211.             StrCmp $R0 '0' LaunchNow ;successfully restored key
  212.  
  213.     RestoreTheKey9x:
  214.         ${registry::RestoreKey} "$SETTINGSDIRECTORY\aoe.reg" $R0
  215.         StrCmp $R0 '0' LaunchNow ;successfully restored key
  216.         StrCpy $FAILEDTORESTOREKEY "true"*/
  217.    
  218.     LaunchNow:
  219.         Sleep 100
  220.         ExecWait $EXECSTRING
  221.        
  222.     CheckRunning:
  223.         Sleep 1000
  224.         FindProcDLL::FindProc "${DEFAULTEXE}"                  
  225.         StrCmp $R0 "1" CheckRunning
  226.        
  227.         StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
  228.         ${registry::SaveKey} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00" "$SETTINGSDIRECTORY\aoe.reg" "" $0
  229.         Sleep 100
  230.    
  231.     SetOriginalKeyBack:
  232.         ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00" $R0
  233.         Sleep 100
  234.         ${registry::KeyExists} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00BACKUP" $R0
  235.         StrCmp $R0 "-1" TheEnd
  236.         ${registry::MoveKey} "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00BACKUP" "HKEY_CURRENT_USER\Software\Microsoft\Games\Age of Empires\1.00" $R0
  237.         Sleep 100
  238.         Goto TheEnd
  239.        
  240.     LaunchAndExit:
  241.         Exec $EXECSTRING
  242.    
  243.     TheEnd:
  244.         ${registry::Unload}
  245.         newadvsplash::stop /WAIT
  246. SectionEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement