; Script
DECLARE_GLOBAL_MACRO(KEYBOARD_PDA_FOLDER,"%PROGRAMFILES_FOLDER%\Dolphin\Keyboard")
DECLARE_GLOBAL_MACRO(KEYBOARD_NAME, "Dolphin Keyboard Driver")
DECLARE_GLOBAL_MACRO(KEYBOARD_FOLDER, "%THIS_FOLDER%")

DECLARE_GROUP("KEYBOARD")
{
	SET_DISPLAY_NAME("%KEYBOARD_NAME%")
	SELECTED_BY_DEFAULT;

	; copy regsvrce.exe - needed to register screen input panel component
	COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\regsvrce.exe, %WINDOWS_FOLDER%\regsvrce.exe, ALWAYS_OVERWRITE);	
	if(REPAIRING)
		RUNREMOTEPROCESS(%KEYBOARD_PDA_FOLDER%\KillKbd.exe, , TRUE);
		; DolBluetooth.dll and DolphinKbd.exe may be in use until a reboot happens
		; however the system allows a rename of the in-use file so that a new one can be copied!
		; NOTE: FALSE below means that any file will be deleted before the rename happens
		REN(%WINDOWS_FOLDER%\DolBluetooth.dll,%WINDOWS_FOLDER%\DolBluetooth.dl~,FALSE);
		REN(%KEYBOARD_PDA_FOLDER%\DolphinKbd.exe,%KEYBOARD_PDA_FOLDER%\DolphinKbd.ex~,FALSE);
		COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\SIP_Numpad.dll, %WINDOWS_FOLDER%\zxyzxyzxyz.dll, ALWAYS_OVERWRITE);
		RUNREMOTEPROCESS(%WINDOWS_FOLDER%\regsvrce.exe, /s /u %WINDOWS_FOLDER%\zxyzxyzxyz.dll, TRUE);
		DEL(%WINDOWS_FOLDER%\zxyzxyzxyz.dll);
		REN(%WINDOWS_FOLDER%\SIP_Numpad.dll,%WINDOWS_FOLDER%\SIP_Numpad.dl~,FALSE);
	endif
	; Technically this should not be needed, However do it just in case!
	if(INSTALLING)
		RUNREMOTEPROCESS(%KEYBOARD_PDA_FOLDER%\KillKbd.exe, , TRUE);
		; DolBluetooth.dll and DolphinKbd.exe may be in use until a reboot happens
		; however the system allows a rename of the in-use file so that a new one can be copied!
		; NOTE: FALSE below means that any file will be deleted before the rename happens
		REN(%WINDOWS_FOLDER%\DolBluetooth.dll,%WINDOWS_FOLDER%\DolBluetooth.dl~,FALSE);
		REN(%KEYBOARD_PDA_FOLDER%\DolphinKbd.exe,%KEYBOARD_PDA_FOLDER%\DolphinKbd.ex~,FALSE);
		COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\SIP_Numpad.dll, %WINDOWS_FOLDER%\zxyzxyzxyz.dll, ALWAYS_OVERWRITE);
		RUNREMOTEPROCESS(%WINDOWS_FOLDER%\regsvrce.exe, /s /u %WINDOWS_FOLDER%\zxyzxyzxyz.dll, TRUE);
		DEL(%WINDOWS_FOLDER%\zxyzxyzxyz.dll);
		REN(%WINDOWS_FOLDER%\SIP_Numpad.dll,%WINDOWS_FOLDER%\SIP_Numpad.dl~,FALSE);
	endif

	; core component - there is only one!
	MKDIR(%KEYBOARD_PDA_FOLDER%);
	MCOPY(%KEYBOARD_FOLDER%\PPC2003\ARMv4\*.*, %KEYBOARD_PDA_FOLDER%, ALWAYS_OVERWRITE, FALSE);
	MCOPY(%KEYBOARD_FOLDER%\PPC2003\ARMv4\%BLUETOOTH_STACK%\*.*, %WINDOWS_FOLDER%, ALWAYS_OVERWRITE, FALSE);

	; documentation - quick reference guide is now in Hal!
	; MKDIR(%KEYBOARD_PDA_FOLDER%\docs);
	; COPY(%KEYBOARD_FOLDER%\docs\hps%INSTALL_LANG%.psw, %KEYBOARD_PDA_FOLDER%\docs\hps%INSTALL_LANG%.psw, ALWAYS_OVERWRITE);
	; COPY(%KEYBOARD_FOLDER%\docs\hpb%INSTALL_LANG%.psw, %KEYBOARD_PDA_FOLDER%\docs\hpb%INSTALL_LANG%.psw, ALWAYS_OVERWRITE);
	; COPY(%KEYBOARD_FOLDER%\docs\frb%INSTALL_LANG%.psw, %KEYBOARD_PDA_FOLDER%\docs\frb%INSTALL_LANG%.psw, ALWAYS_OVERWRITE);

	MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\Keyboard.lnk, %KEYBOARD_PDA_FOLDER%\DolphinKbd.exe);
	MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\Quit Keyboard.lnk, %KEYBOARD_PDA_FOLDER%\KillKbd.exe);

	; documentation - quick reference guide is now in Hal!
	; MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\HP Plugin Keyboard.lnk, %KEYBOARD_PDA_FOLDER%\docs\hps%INSTALL_LANG%.psw);
	; MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\HP Bluetooth Keyboard.lnk, %KEYBOARD_PDA_FOLDER%\docs\hpb%INSTALL_LANG%.psw);
	; MKSHORTCUT(%START_MENU_PROGRAMS%\Dolphin\Freedom Bluetooth Keyboard.lnk, %KEYBOARD_PDA_FOLDER%\docs\frb%INSTALL_LANG%.psw);

	; copy screen input panel component
	COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\SIP_Numpad.dll, %WINDOWS_FOLDER%\SIP_Numpad.dll, ALWAYS_OVERWRITE);
	
	; register the screen input panel component
	; this dll registers SIP_numpad.dll whatever its name is
	COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\SIP_Numpad.dll, %WINDOWS_FOLDER%\zxyzxyzxyz.dll, ALWAYS_OVERWRITE);
	RUNREMOTEPROCESS(%WINDOWS_FOLDER%\regsvrce.exe, /s %WINDOWS_FOLDER%\zxyzxyzxyz.dll, TRUE);
	DEL(%WINDOWS_FOLDER%\zxyzxyzxyz.dll);

	; remove before uninstalling (NOTE: ******* UNINSTALL IS DONE IN REVERSE ORDER *******)
	if(UNINSTALLING)
		REN(%WINDOWS_FOLDER%\SIP_Numpad.dll,%WINDOWS_FOLDER%\SIP_Numpad.dl~,FALSE);
		DEL(%WINDOWS_FOLDER%\zxyzxyzxyz.dll);
		RUNREMOTEPROCESS(%WINDOWS_FOLDER%\regsvrce.exe, /s /u %WINDOWS_FOLDER%\zxyzxyzxyz.dll, TRUE);
		COPY(%THIS_FOLDER%\PPC2003\ARMv4\Windows\SIP_Numpad.dll, %WINDOWS_FOLDER%\zxyzxyzxyz.dll, ALWAYS_OVERWRITE);
		; DolBluetooth.dll and DolphinKbd.exe may be in use until a reboot happens
		; however the system allows a rename of the in-use file so that a new one can be copied!
		; NOTE: FALSE below means that any file will be deleted before the rename happens
		REN(%WINDOWS_FOLDER%\DolBluetooth.dll,%WINDOWS_FOLDER%\DolBluetooth.dl~,FALSE);
		REN(%KEYBOARD_PDA_FOLDER%\DolphinKbd.exe,%KEYBOARD_PDA_FOLDER%\DolphinKbd.ex~,FALSE);
		RUNREMOTEPROCESS(%KEYBOARD_PDA_FOLDER%\KillKbd.exe, , TRUE);
	endif
	; Install the keyboard driver...
	if(INSTALLING)
		DEL(%WINDOWS_FOLDER%\SIP_Numpad.dl~);
		DEL(%WINDOWS_FOLDER%\DolBluetooth.dl~);
		DEL(%KEYBOARD_PDA_FOLDER%\DolphinKbd.ex~);
		RUNREMOTEPROCESS(%KEYBOARD_PDA_FOLDER%\DolphinKbd.exe, /s, TRUE);
	endif
	; If we are repairing then make sure the keyboard driver is installed
	if(REPAIRING)
		DEL(%WINDOWS_FOLDER%\SIP_Numpad.dl~);
		DEL(%WINDOWS_FOLDER%\DolBluetooth.dl~);
		DEL(%KEYBOARD_PDA_FOLDER%\DolphinKbd.ex~);
		RUNREMOTEPROCESS(%KEYBOARD_PDA_FOLDER%\DolphinKbd.exe, /s, TRUE);
	endif

}

; One group per keyboard
DECLARE_GROUP("KEYBOARD\HP_PLUGIN_FOLDABLE")
{
	SET_DISPLAY_NAME("Enable HP Plugin Foldable Keyboard")
	MKREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\HP Plug-in Foldable\Port, REG_DWORD, 1);
	MKREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\HP Plug-in Foldable\Enabled, REG_DWORD, 1);
}

DECLARE_GROUP("KEYBOARD\HP_BLUETOOTH_FOLDABLE")
{
	SELECTED_BY_DEFAULT;
	SET_DISPLAY_NAME("Enable HP Bluetooth Foldable Keyboard")
	MKREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\HP Bluetooth Foldable\Enabled, REG_DWORD, 1);
	RMREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\HP Bluetooth Foldable\Address);
}

DECLARE_GROUP("KEYBOARD\EASYLINK")
{
	SET_DISPLAY_NAME("Enable EasyLink")
	MKREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\EasyLink\Enabled, REG_DWORD, 1);
	RMREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\EasyLink\Address);
}

DECLARE_GROUP("KEYBOARD\FREEDOM_BLUETOOTH_FOLDABLE")
{
	SET_DISPLAY_NAME("Enable Freedom Bluetooth Foldable Keyboard")
	MKREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\Freedom Bluetooth Foldable\Enabled, REG_DWORD, 1);
	RMREG(HKEY_LOCAL_MACHINE, Software\Dolphin\Keyboard Driver\Freedom Bluetooth Foldable\Address);
}

