; Script
DECLARE_GLOBAL_MACRO(Sam_PDA_FOLDER,"%PROGRAMFILES_FOLDER%\Dolphin\SAM")
DECLARE_GLOBAL_MACRO(Sam_NAME, "Pocket Synthesizer Access Manager")
DECLARE_GLOBAL_MACRO(Sam_FOLDER, "%THIS_FOLDER%")
DECLARE_GLOBAL_MACRO(Sam_LANG_PDA_FOLDER,"%Sam_PDA_FOLDER%\language")

DECLARE_GROUP("Sam")
{
	SET_DISPLAY_NAME("%Sam_NAME%")
	INSTALL_ALWAYS;

	; core components
	MKDIR("%Sam_PDA_FOLDER%");

	if(REPAIRING)
		RUNREMOTEPROCESS(%Sam_PDA_FOLDER%\sam.exe, /q, TRUE);
	endif
	; Technically this should not be needed, However do it just in case!
	if(INSTALLING)
		RUNREMOTEPROCESS(%Sam_PDA_FOLDER%\sam.exe, /q, TRUE);
	endif

	COPY(%Sam_FOLDER%\sam%INSTALL_LANG%.ini, %Sam_PDA_FOLDER%\sam%INSTALL_LANG%.ini, OVERWRITE_IF_NEWER);
	COPY(%Sam_FOLDER%\unicows.dll, %Sam_PDA_FOLDER%\unicows.dll, OVERWRITE_IF_NEWER);
	COPY(%Sam_FOLDER%\SAM.SYS, %Sam_PDA_FOLDER%\SAM.SYS, OVERWRITE_IF_NEWER);
	COPY(%Sam_FOLDER%\PPC2003\ARMv4\sam.exe, %Sam_PDA_FOLDER%\sam.exe, OVERWRITE_IF_NEWER);
	COPY(%Sam_FOLDER%\PPC2003\ARMv4\Windows\sam32.dll, %WINDOWS_FOLDER%\sam32.dll, OVERWRITE_IF_NEWER);

	; create shortcuts

	MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\Configure SAM.lnk, ""%Sam_PDA_FOLDER%\sam.exe" /c")
	MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\Quit SAM.lnk, ""%Sam_PDA_FOLDER%\sam.exe" /q")

	CREATEPIIK(SC3, HKEY_LOCAL_MACHINE, Software\Dolphin\SAM, %Sam_PDA_FOLDER%);

	; remove before uninstalling (NOTE: Uninstall is done in the reverse order of this script)
	if(UNINSTALLING)
		; If we are uninstalling then we need to stop SAM
		RUNREMOTEPROCESS(%Sam_PDA_FOLDER%\sam.exe, /q, TRUE);
	endif

}

; Allow the user to select drivers

DECLARE_LOCAL_MACRO(DRIVERS_DIR,"%Sam_FOLDER%\PPC2003\ARMv4\Drivers")
DECLARE_LOCAL_MACRO(DRIVERS_DOC_DIR,"%Sam_FOLDER%\Drivers")

DECLARE_GROUP("Sam\orpheus")
{
	SET_DISPLAY_NAME("Orpheus Driver")
	SELECTED_BY_DEFAULT;
	MKDIR("%Sam_PDA_FOLDER%\orpheus");
	MCOPY(%DRIVERS_DIR%\orpheus\*.*, %Sam_PDA_FOLDER%\orpheus, OVERWRITE_IF_NEWER, FALSE);
	MCOPY(%DRIVERS_DOC_DIR%\orpheus\*.*, %Sam_PDA_FOLDER%\orpheus, OVERWRITE_IF_NEWER, FALSE);
	WRITEPRIVATEPROFILESTRING(Orpheus, Install, %PROGRAMFILES_FOLDER%\Dolphin\Orpheus\, %Sam_PDA_FOLDER%\orpheus\dolostub.ini);
}
DECLARE_GROUP("Sam\easylink")
{
	SET_DISPLAY_NAME("Optelec Easylink Driver")
	MKDIR("%Sam_PDA_FOLDER%\easylink");
	MCOPY(%DRIVERS_DIR%\easylink\*.*, %Sam_PDA_FOLDER%\easylink, OVERWRITE_IF_NEWER, FALSE);
	MCOPY(%DRIVERS_DOC_DIR%\easylink\*.*, %Sam_PDA_FOLDER%\easylink, OVERWRITE_IF_NEWER, FALSE);
}
DECLARE_GROUP("Sam\svario")
{
	SET_DISPLAY_NAME("SuperVario/Brailliant Braille Display")
	MKDIR("%Sam_PDA_FOLDER%\svario");
	MCOPY(%DRIVERS_DIR%\svario\*.*, %Sam_PDA_FOLDER%\svario, OVERWRITE_IF_NEWER, FALSE);
	MCOPY(%DRIVERS_DOC_DIR%\svario\*.*, %Sam_PDA_FOLDER%\svario, OVERWRITE_IF_NEWER, FALSE);
}
DECLARE_GROUP("Sam\htsam")
{
	SET_DISPLAY_NAME("Handy Tech Braille Display Driver")
	MKDIR("%Sam_PDA_FOLDER%\htsam");
	MCOPY(%DRIVERS_DIR%\htsam\*.*, %Sam_PDA_FOLDER%\htsam, OVERWRITE_IF_NEWER, FALSE);
	MCOPY(%DRIVERS_DOC_DIR%\htsam\*.*, %Sam_PDA_FOLDER%\htsam, OVERWRITE_IF_NEWER, FALSE);
}
