Итак, после продолжительного молчания, представляю новый скрипт:
читать дальше »
Код:
;Text/Registry definitions
!define PRODUCT_NAME "AIMP2"
!define PRODUCT_VERSION " 2.6.0.499 rc1"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define BRANDING "By Happy Bulldozer860"
!define pkgdir "d:\package"
;includes
!include "MUI.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "WordFunc.nsh"
SetCompressor /SOLID lzma
;SetCompress Off
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!define MUI_COMPONENTSPAGE_NODESC
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "Russian"
;service macroses
!insertmacro GetOptions
!insertmacro RefreshShellIcons
;variables section
;ui variables
Var SkinFile
Var IconFile
Var IconFileName
Var WindowCaption
;unnatend mode variables
Var IniFile
Var gMode
;open command for files related with $installdir
Var OpenCommand
;profiles related varialbes
Var ProfilePath
Var MultiUser
;extensions related variables
Var ClassName
Var IconIndex
;script initialization
Function .onInit
;
; when /g switch specified and not present /s switch, then generate default config
;
;inifile definition
StrCpy $WindowCaption "${PRODUCT_NAME} ${PRODUCT_VERSION}"
${WordReplace} "$EXEFILE" ".exe" ".ini" "+" $IniFile
StrCpy $IniFile "$EXEDIR\$IniFile"
;gMode detection
StrCpy $gMode 0
${GetOptions} $CMDLINE "/G" $0
;if not found /G then exit
IfErrors EndFunc 0
;When Silent setup then ignoring /G
IfSilent +3 0
StrCpy $gMode 1
StrCpy $WindowCaption "Генератор файла ответов ${PRODUCT_NAME}"
EndFunc:
FunctionEnd
;Common directives
BrandingText "${BRANDING}"
Name "${PRODUCT_NAME}"
Caption "$WindowCaption"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES\AIMP2"
ShowInstDetails show
ShowUninstDetails show
;installation types
InstType "Полная"
InstType "Сокращенная"
InstType "Минимальная"
!macro ProcessSection secID
;
;if gMode=1 - generate default config. if 0 and not silent - reads the config
StrCpy $R0 1
StrCmp $gMode 1 WriteMode
IfSilent 0 EndMarco
IfFileExists $IniFile 0 EndMarco
ReadINIStr $R0 $IniFile Sections ${secID}
IfErrors 0 +2
StrCpy $R0 0
Goto EndMarco
WriteMode:
StrCpy $R0 0
WriteINIStr $IniFile Sections ${secID} 1
EndMarco:
!macroend
;custom filetype registration function
!macro RegisterExtension extenstion
;create a class for extesion
;read/write section state
!insertmacro ProcessSection ${extenstion}
;if $r0 is 0 then exit section
StrCmp $R0 0 EndMacro 0
;--------------section code----------------
StrCpy $ClassName "AIMP.${extenstion}"
StrCmp ${extenstion} "AUDIOCD" +2 0
WriteRegStr HKCR ".${extenstion}" "" "$ClassName"
WriteRegStr HKCR "${extenstion}" "" "$ClassName"
WriteRegStr HKCR "$ClassName" "" "AIMP: ${extenstion}"
WriteRegStr HKCR "$ClassName\CLSID" "" "{0041494D-5032-4472-6F70-546172676574}"
WriteRegStr HKCR "$ClassName\shell\open" "" "Открыть в AIMP2"
WriteRegStr HKCR "$ClassName\shell\open\command" "" "$OpenCommand"
WriteRegStr HKCR "$ClassName\shell\open\DropTarget" "CLSID" "{0041494D-5032-4472-6F70-546172676574}"
;define icon for class
${Switch} ${extenstion}
${Case} "WAV"
StrCpy $IconIndex 0
${Break}
;mp3 group
${Case} "MP3"
StrCpy $IconIndex 1
${Break}
${Case} "MP1"
StrCpy $IconIndex 1
${Break}
${Case} "MP2"
StrCpy $IconIndex 1
${Break}
${Case} "OGG"
StrCpy $IconIndex 2
${Break}
${Case} "WMA"
StrCpy $IconIndex 3
${Break}
;mod group
${Case} "MOD"
StrCpy $IconIndex 5
${Break}
${Case} "IT"
StrCpy $IconIndex 5
${Break}
${Case} "MO3"
StrCpy $IconIndex 5
${Break}
${Case} "MTM"
StrCpy $IconIndex 5
${Break}
${Case} "S3M"
StrCpy $IconIndex 5
${Break}
${Case} "XM"
StrCpy $IconIndex 5
${Break}
${Case} "FLAC"
StrCpy $IconIndex 6
${Break}
${Case} "MPC"
StrCpy $IconIndex 7
${Break}
${Case} "ACS2"
StrCpy $IconIndex 8
${Break}
;playlists group
${Case} "CUE"
StrCpy $IconIndex 9
${Break}
${Case} "PLS"
StrCpy $IconIndex 9
${Break}
${Case} "M3U"
StrCpy $IconIndex 9
${Break}
${Case} "M3U8"
StrCpy $IconIndex 9
${Break}
${Case} "PLC"
StrCpy $IconIndex 9
${Break}
${Case} "UMX"
StrCpy $IconIndex 9
${Break}
${Default}
StrCpy $IconIndex 4
${Break}
${EndSwitch}
WriteRegStr HKCR "$ClassName\DefaultIcon" "" "$IconFile,$IconIndex"
EndMacro:
!macroend
; !macro UnRegisterExtension extenstion
; StrCpy $ClassName "AIMP.${extenstion}"
; ReadRegStr $0 HKCR ".${extenstion}" ""
; StrCmp $0 $ClassName 0 +3
; DeleteRegKey HKCR ".${extenstion}"
; DeleteRegKey HKCR "$ClassName"
; !macroend
;sections
Section "!${PRODUCT_NAME}" CORE
SectionIn 1 2 3 RO
StrCmp $gMode 1 0 NotgMode
WriteINIStr $IniFile Advanced Directory $INSTDIR
Goto EndSection
NotgMode:
;this is required section so don't perfom reading from inifile
StrCpy $ProfilePath "$INSTDIR\Data\Profile"
IfSilent 0 NotSilent
IfFileExists $IniFile 0 NotSilent
ReadINIStr $R0 $IniFile Advanced Directory
StrCmp $R0 "" NotSilent 0
StrCpy $INSTDIR $R0
NotSilent:
SetOutPath "$INSTDIR\"
File /r "${pkgdir}\AIMP\Player\*.*"
WriteUninstaller "$OUTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$OUTDIR\aimp2.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$OUTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
EndSection:
SectionEnd
Section "Отдельные настройки на каждого пользователя" MultiUser
SectionIn 1 2 3
;read/write section state
!insertmacro ProcessSection "MultiUser"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
StrCpy $MultiUser 1
;-------------------------------------------
EndSection:
SectionEnd
;=========================================================================================================================
SectionGroup /e "Дополнения"
Section "Скины" Skins
SectionIn 1
;read/write section state
!insertmacro ProcessSection "Skins"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
SetOutPath "$INSTDIR\Skins"
File "${pkgdir}\AIMP\Skins\*.*"
;-------------------------------------------
EndSection:
SectionEnd
Section "Иконки типов файлов" Icons
SectionIn 1
!insertmacro ProcessSection "Icons"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
SetOutPath "$INSTDIR\Icons"
File "${pkgdir}\AIMP\Icons\*.*"
;-------------------------------------------
EndSection:
SectionEnd
SectionGroupEnd
;=========================================================================================================================
SectionGroup /e "Ярлыки"
Section "В меню Пуск" StartMenu
SectionIn 1 2
!insertmacro ProcessSection "StartMenu"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
SetShellVarContext all
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\aimp2.exe"
IfFileExists "$INSTDIR\AIMP2t.exe" 0 +2
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME} Advanced Tag Editor.lnk" "$INSTDIR\AIMP2t.exe"
IfFileExists "$INSTDIR\AIMP2c.exe" 0 +2
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME} Audio Converter.lnk" "$INSTDIR\AIMP2c.exe"
IfFileExists "$INSTDIR\AIMP2r.exe" 0 +2
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME} Audio Recorder.lnk" "$INSTDIR\AIMP2r.exe"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Удалить ${PRODUCT_NAME}.lnk" "$INSTDIR\uninst.exe"
;-------------------------------------------
EndSection:
SectionEnd
Section "На рабочем столе" Desktop
SectionIn 1
!insertmacro ProcessSection "Desktop"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
SetShellVarContext all
CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\aimp2.exe"
;-------------------------------------------
EndSection:
SectionEnd
Section "В панели быстрого запуска" QuickLaunch
SectionIn 1
!insertmacro ProcessSection "QuickLaunch"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
SetShellVarContext all
CreateShortCut "$QUICKLAUNCH\${PRODUCT_NAME}.lnk" "$INSTDIR\aimp2.exe"
;-------------------------------------------
EndSection:
SectionEnd
SectionGroupEnd
;=========================================================================================================================
SectionGroup /e "Ассоциации файлов"
Section "-SetupIconsVariables"
StrCmp $gMode 1 NotgMode
;default icon file
StrCpy $IconFileName "aimp2.dll"
IfSilent 0 EndSection
IfFileExists $IniFile 0 EndSection
ReadINIStr $R0 $IniFile Advanced IconFileName
IfFileExists "$INSTDIR\Icons\$R0" 0 EndSection
StrCpy $IconFileName $R0
EndSection:
StrCpy $IconFile "$INSTDIR\Icons\$IconFileName"
StrCpy $OpenCommand "$INSTDIR\AIMP2.exe $\"%1$\""
NotgMode:
SectionEnd
Section "Контекстое меню проводника" ContextMenu
SectionIn 1 2
;read/write section state
!insertmacro ProcessSection "ContextMenu"
;if $r0 is 0 then exit section
StrCmp $R0 0 EndSection 0
;--------------section code----------------
RegDLL "$INSTDIR\System\aimp_shell.dll"
EndSection:
SectionEnd
Section "AAC" aac
SectionIn 1 2
!insertmacro RegisterExtension "AAC"
SectionEnd
Section "ACS2"
SectionIn 1 2
!insertmacro RegisterExtension "ACS2"
SectionEnd
Section "AIF"
SectionIn 1 2
!insertmacro RegisterExtension "AIF"
SectionEnd
Section "AIFF"
SectionIn 1 2
!insertmacro RegisterExtension "AIFF"
SectionEnd
Section "APE"
SectionIn 1 2
!insertmacro RegisterExtension "APE"
SectionEnd
Section "AUDIOCD"
SectionIn 1 2
!insertmacro RegisterExtension "AUDIOCD"
SectionEnd
Section "CDA"
SectionIn 1 2
!insertmacro RegisterExtension "CDA"
SectionEnd
Section "CUE"
SectionIn 1 2
!insertmacro RegisterExtension "CUE"
SectionEnd
Section "FLAC"
SectionIn 1 2
!insertmacro RegisterExtension "FLAC"
SectionEnd
Section "IT"
SectionIn 1 2
!insertmacro RegisterExtension "IT"
SectionEnd
Section "M3U"
SectionIn 1 2
!insertmacro RegisterExtension "M3U"
SectionEnd
Section "M3U8"
SectionIn 1 2
!insertmacro RegisterExtension "M3U8"
SectionEnd
Section "MID"
SectionIn 1 2
!insertmacro RegisterExtension "MID"
SectionEnd
Section "MO3"
SectionIn 1 2
!insertmacro RegisterExtension "MO3"
SectionEnd
Section "MOD"
SectionIn 1 2
!insertmacro RegisterExtension "MOD"
SectionEnd
Section "MP1"
SectionIn 1 2
!insertmacro RegisterExtension "MP1"
SectionEnd
Section "MP2"
SectionIn 1 2
!insertmacro RegisterExtension "MP2"
SectionEnd
Section "MP3"
SectionIn 1 2
!insertmacro RegisterExtension "MP3"
SectionEnd
Section "MPC"
SectionIn 1 2
!insertmacro RegisterExtension "MPC"
SectionEnd
Section "MTM"
SectionIn 1 2
!insertmacro RegisterExtension "MTM"
SectionEnd
Section "OGG"
SectionIn 1 2
!insertmacro RegisterExtension "OGG"
SectionEnd
Section "PLC"
SectionIn 1 2
!insertmacro RegisterExtension "PLC"
SectionEnd
Section "PLS"
SectionIn 1 2
!insertmacro RegisterExtension "PLS"
SectionEnd
Section "S3M"
SectionIn 1 2
!insertmacro RegisterExtension "S3M"
SectionEnd
Section "UMX"
SectionIn 1 2
!insertmacro RegisterExtension "UMX"
SectionEnd
Section "WAV"
SectionIn 1 2
!insertmacro RegisterExtension "WAV"
SectionEnd
Section "WMA"
SectionIn 1 2
!insertmacro RegisterExtension "WMA"
SectionEnd
Section "WV"
SectionIn 1 2
!insertmacro RegisterExtension "WV"
SectionEnd
Section "XM"
SectionIn 1 2
!insertmacro RegisterExtension "XM"
SectionEnd
Section "-RefreshIcons"
SectionIn 1 2 3
StrCmp $gMode 1 +2 0
${RefreshShellIcons}
SectionEnd
SectionGroupEnd
;=========================================================================================================================
Section "-PostinstallProfileProcessing"
;here we must set current user constats context
StrCmp $gMode 1 NotgMode
SetShellVarContext current
;common INI settings
CreateDirectory "$INSTDIR\DATA"
WriteINIStr "$INSTDIR\DATA\AIMP.INI" System DefaultLang russian.lng
WriteINIStr "$INSTDIR\DATA\AIMP.INI" System Version 2603
StrCmp $MultiUser 1 PerUserCFG OneUserCFG
PerUserCFG:
WriteINIStr "$INSTDIR\DATA\AIMP.INI" System UserMode 1
StrCpy $ProfilePath "$APPDATA\AIMP"
CreateDirectory "$ProfilePath"
Goto WriteCFG
OneUserCFG:
WriteINIStr "$INSTDIR\DATA\AIMP.INI" System UserMode 0
CreateDirectory "$INSTDIR\DATA\Profile"
Goto WriteCFG
WriteCFG:
SetOutPath "$ProfilePath"
File /nonfatal /r "${pkgdir}\Aimp\Profile\"
IfFileExists "$ProfilePath\AIMP2.INI" EndSection
WriteINIStr "$ProfilePath\AIMP2.INI" System LangFile russian.lng ;язык по умолчанию для плеера
WriteINIStr "$ProfilePath\AIMP2r.INI" System LangFile russian.lng ;язык по умолчанию для рекордера
WriteINIStr "$ProfilePath\AIMP2c.INI" System LangFile russian.lng ;язык по умолчанию для конвертера
WriteINIStr "$ProfilePath\AIMP2t.INI" System LangFile russian.lng ;язык по умолчанию для таггера
EndSection:
IfSilent 0 NotSilent
IfFileExists $IniFile 0 NoIniFile
ReadINIStr $R0 $IniFile Advanced SkinFile
IfFileExists "$INSTDIR\Skins\$R0" 0 NoIniFile
StrCpy $SkinFile $R0
NoIniFile:
WriteINIStr "$ProfilePath\AIMP2.INI" Skins DefaultSkin $SkinFile ;скин
NotSilent:
WriteINIStr "$ProfilePath\AIMP2.INI" Skins ICL $IconFileName ;значки
NotgMode:
SectionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "Удаление программы $(^Name) было успешно завершено."
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Вы уверены в том, что желаете удалить $(^Name) и все компоненты программы?" IDYES +2
Abort
FunctionEnd
Section Uninstall
UnRegDLL "$INSTDIR\System\aimp_shell.dll"
ExecWait '$INSTDIR\aimp2.exe /REG=U'
RMDir /r "$INSTDIR\"
SetShellVarContext all
RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
Delete "$DESKTOP\${PRODUCT_NAME}.LNK"
Delete "$QUICKLAUNCH\${PRODUCT_NAME}.lnk"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd
Теперь инсталятор поддерживает всего два ключа командной строки - /G и /S
/G - запускает инсталятор в режиме генератора файла ответов, примерно также работает инсталятор к-лайт кодеков с ключом -MakeUnatended.
Расставляете галки на нужных компонентах, в системе никаких изменений не происходит, а факт выбора компонентов записываются в файл с именем <ИМЯ_СБОРКИ_БЕЗ_РАСШИРЕНИЯ>.ini.
/S - ну этот ключ в представлении не нуждается, правда, теперь при его указании инсталятор смотрит наличие файла ответов, и если текущий компонент помечен как выбранный, компонент устанавливается, в противном случае компонент игнорируется. Если файла ответов нет, происходит обычная тихая установка.
Возможность указания пользовательской шкуры и библиотеки значков вынесена также в файл ответов. В файл ответов необходимо добавить(увы, пока вручную) три строки:
Код:
[advanced]
SkinFile=Lagoon.acs2
IconFileName=aimp classic2.dll
Скрипт поддерживает упаковку аимпа с TOOLS и без, без необходимости его правки. Проверяется наличие соотвествующих файлов, и если их нет, ярлыки на инструменты просто не создаются.
Скрипт нуждается в доработке. Я хочу иметь возможность указывать шкуру и файл значков через генератор файла ответов. Также:
-в файле ответов пока нельзя указать папку, куда ставить программу, в режиме генератора она не сохраняется.
-при упаковке версии 2.60 галки, что плеер ассоциирован с файлами, не проставляются. Тем не менее, ассоциации проставляются корректно, файлы остаются за плеером.
-при наличии уже готового файла ответов, в режиме генератора, если вы НЕ выбираете компонент, а в файле ответов он присутсвует как выбранный, ВЫБОР НЕ БУДЕТ СБРОШЕН. Рекомендуется удалять старые файлы ответов перед запуском генератора.
ВНИМАНИЕ! Если вы запускали генератор файлом, к примеру AIMP2- 2.6.0.499 rc1.exe, а потом переименовали в AIMP2.exe, не забудьте переименовать и файл ответов из AIMP2- 2.6.0.499 rc1.ini в AIMP2.ini, иначе он не подцепится.
Скрипт будет дорабатываться, а код скрипта - оптимизироваться.
Сборка с TOOLS и файлом ответов, размер 6.3 метра(так, чтобы поиграться. Что в неё включать, а что нет - решу позднее, после плотного знакомства с новой версией.):
http://files.mail.ru/VN8AD5