Advertisement
Guest User

XBMCLauncher 4.0 with DVBViewer

a guest
Sep 2nd, 2013
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * * * Compile_AHK SETTINGS BEGIN * * *
  3.  
  4. [AHK2EXE]
  5. Exe_File=%In_Dir%\XBMCLauncher.exe
  6. Created_Date=1
  7. [VERSION]
  8. Set_Version_Info=1
  9. Company_Name=baijuxavior@gmail.com
  10. File_Description=XBMCLauncher
  11. File_Version=4.0.0.0
  12. Inc_File_Version=0
  13. Internal_Name=XBMCLauncher
  14. Legal_Copyright=C@P Baiju Xavior
  15. Original_Filename=XBMCLauncher
  16. Product_Name=XBMCLauncher
  17. Product_Version=4.0.0.0
  18. [ICONS]
  19. Icon_1=%In_Dir%\XBMCLauncher.ico
  20. Icon_2=%In_Dir%\XBMCLauncher.ico
  21.  
  22. * * * Compile_AHK SETTINGS END * * *
  23. */
  24.  
  25. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  26. #Warn  ; Recommended for catching common errors.
  27. #SingleInstance ignore ; create only one running instance
  28.  
  29. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  30. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  31.  
  32. DllCall("CreateMutex", "uint", 0, "int", false, "str", "xbmc_launcher_mutex") ; create a mutex to find whether the application is already running while installation.
  33.  
  34. ProgFiles32() ;get 32 bit program files folder
  35. {
  36.     EnvGet, ProgFiles32, ProgramFiles(x86)
  37.     if ProgFiles32 = ; Probably not on a 64-bit system.
  38.     EnvGet, ProgFiles32, ProgramFiles
  39.     Return %ProgFiles32%
  40. }
  41.  
  42.  
  43. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>           GLOBAL VARIABLES DECLARATION AND DEFAULT VALUES     <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  44.  
  45.  
  46. objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" A_ComputerName "\root\cimv2")
  47. For objOperatingSystem in objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
  48. Global OSVersion :=     objOperatingSystem.Version
  49. global AppVersion = 4.0
  50.  
  51. Global ProgFiles := ProgFiles32() ;Program files path
  52. global FocusDelay := GetSettings("FocusDelay", 10000)
  53. global FocusOnce := GetSettings("FocusOnce", 0)
  54. global DisableFocusTemporarily = 0
  55. global DisableFocusPermanently := GetSettings("DisableFocusPermanently", 0)
  56. global FocussedOnce = 0
  57. global FocusCount = 0
  58. global CloseXBMCatSleep := GetSettings("CloseXBMCatSleep", 0)
  59. global ForceCloseXBMC := GetSettings("ForceCloseXBMC", 0)
  60. global StartExplorer := GetSettings("StartExplorer", 1)
  61. global StartMetroUI := GetSettings("StartMetroUI", 1)
  62. global WinKeySent = 0
  63. global ShowCustomShutdownMenu := GetSettings("ShowCustomShutdownMenu", 0)
  64. global ShutdownAction := GetSettings("ShutdownAction", "u")
  65. global ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
  66.  
  67.  
  68. global ExternalPlayerRunning = 0
  69. global Suspending = 0
  70. global StartupDelay := GetSettings("StartupDelay", 0)
  71. global StartXBMCatWinLogon := GetSettings("StartXBMCatWinLogon", 1)
  72. global StartXBMCatWinResume := GetSettings("StartXBMCatWinResume", 0)
  73. global StartXBMCPortable := GetSettings("StartXBMCPortable", 0)
  74. global BreakFocus = 0 ; break focus while setting xbmclauncher settings
  75.  
  76.  
  77. global XBMCPath := GetSettings("XBMC_Path", ProgFiles . "\XBMC\XBMC.exe")
  78. global XBMConiMONPath := GetSettings("XBMConiMON_Path", "")
  79. global iMONPath := GetSettings("iMON_Path", ProgFiles . "\SoundGraph\iMON\iMON.exe")
  80. global ExternalPlayerPath := GetSettings("ExternalPlayer_Path", "")
  81.  
  82. global DVBViewerPath := GetSettings("DVBViewer_Path", ProgFiles . "\DVBViewer\dvbviewer.exe")
  83. global DVBViewerRunning = 0
  84. global DVBViewerGetStatus := GetSettings("DVBViewerGetStatus", 0)
  85. global DVBViewerSize = 0
  86. global DVBViewerActive = 0
  87.  
  88. Global App1 := GetSettings("App1_Path", "")
  89. Global App2 := GetSettings("App2_Path", "")
  90. Global App3 := GetSettings("App3_Path", "")
  91. global StartApps1 := GetSettings("StartApps1", 0)
  92. global PreventFocusApps1 := GetSettings("PreventFocusApps1", 0)
  93.  
  94. Global App4 := GetSettings("App4_Path", "")
  95. Global App5 := GetSettings("App5_Path", "")
  96. Global App6 := GetSettings("App6_Path", "")
  97. global StartApps2 := GetSettings("StartApps2", 0)
  98. global PreventFocusApps2 := GetSettings("PreventFocusApps2", 0)
  99. global ReloadXBMCLauncher := GetSettings("ReloadXBMCLauncher", 0)
  100. SaveSettings("ReloadXBMCLauncher", 0)
  101. SaveSettings("RestartXBMC", 0)
  102.  
  103. global ShellName
  104. RegRead, ShellName, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell
  105.     SplitPath, ShellName, ShellName ;get file name only
  106.         ;MsgBox %ShellName%
  107.    
  108.  
  109.  
  110. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    CREATE MENU ITEMS      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  111.  
  112. fdelay := FocusDelay // 1000 ; variable to show menu name with delay
  113. sdelay := StartupDelay // 1000
  114. IfExist, %A_WorkingDir%\XBMCLauncher.ico
  115. Menu, Tray, Icon, %A_WorkingDir%\XBMCLauncher.ico ; create tray icon.
  116. Menu, Tray, Tip, XBMCLauncher V%AppVersion% `nRight click to view menu
  117. Menu, Tray, add, Start XBMC [Win+Alt+Enter], MenuStartXBMCHandler
  118. Menu, Tray, add, Force Close XBMC Now, MenuCloseXBMCNow
  119. Menu, Tray, add ;add separator
  120. Menu, Tray, add, Start Explorer [Win+E], MenuStartExplorer
  121. Menu, Tray, add, Show Settings GUI [Win+S], MenuShowSettingsGUI
  122. Menu, Tray, add ;add separator
  123. Menu, XBMCStartSubMenu, add, Start XBMC When Windows Starts, MenuStartXBMCAtWindowsLogonHandler
  124. Menu, XBMCStartSubMenu, add, Start XBMC When Windows Resumes from Sleep, MenuStartXBMCAtWindowsResumeHandler
  125. Menu, XBMCStartSubMenu, add, Start XBMC in Portable Mode, MenuStartXBMCPortableModeHandler
  126. Menu, XBMCStartSubMenu, add,
  127. Menu, XBMCStartSubMenu, add, Change Startup Delay [%sdelay% sec], MenuSetStartupDelayHandler
  128. Menu, XBMCStartSubMenu, UnCheck, Start XBMC When Windows Starts
  129. Menu, XBMCStartSubMenu, UnCheck, Start XBMC When Windows Resumes from Sleep
  130. Menu, XBMCStartSubMenu, UnCheck, Start XBMC in Portable Mode
  131. Menu, Tray, add, XBMC Startup Settings, :XBMCStartSubMenu
  132.  
  133. Menu, FocusSubMenu, add, Change Focus Delay [%fdelay% sec], MenuSetFocusDelayHandler
  134. Menu, FocusSubMenu, add,
  135. Menu, FocusSubMenu, add, Disable Focus Permanently, MenuDisableFocusPermanentlyHandler
  136. Menu, FocusSubMenu, UnCheck, Disable Focus Permanently
  137. Menu, FocusSubMenu, add, Disable Focus Temporarily [Win+F9], MenuDisableFocusHandler
  138. Menu, FocusSubMenu, UnCheck, Disable Focus Temporarily [Win+F9]
  139. Menu, FocusSubMenu, add, Check Focus Only Once, MenuCheckFocusOnceHandler
  140. Menu, FocusSubMenu, UnCheck, Check Focus Only Once
  141. Menu, Tray, add, XBMC Focus Settings, :FocusSubMenu
  142.  
  143. if (ShowCustomShutdownMenu = 1)
  144.     {   global currentshutdownaction := "Shutdown"
  145.         If (ShutdownAction = "u")
  146.             currentshutdownaction := "Shutdown"
  147.         If (ShutdownAction = "h")
  148.             currentshutdownaction := "Hibernate"
  149.         If (ShutdownAction = "s")
  150.             currentshutdownaction := "Sleep"
  151.         Menu, XBMCExitSubMenu, add, Set Shutdown Button Action [for custom shutdown menu only] - %currentshutdownaction%, MenuSetShutdownActionHandler
  152.        
  153.         Menu, XBMCExitSubMenu, add, Force Close XBMC instead of Normal Close [for custom shutdown menu only], MenuForceCloseXBMCHandler
  154.         Menu, XBMCExitSubMenu, UnCheck, Force Close XBMC instead of Normal Close [for custom shutdown menu only]
  155.         Menu, XBMCExitSubMenu, add,
  156.        
  157.     }  
  158. Menu, XBMCExitSubMenu, add, Close XBMC on Suspend, MenuCloseXBMCatSleepHandler
  159. Menu, XBMCExitSubMenu, UnCheck, Close XBMC on Suspend
  160.  
  161. Menu, XBMCExitSubMenu, add, Start Windows Explorer when XBMC is closed, MenuStartExplorerHandler
  162. Menu, XBMCExitSubMenu, UnCheck, Start Windows Explorer when XBMC is closed
  163. if (OSVersion >= 6.2)
  164.     {
  165.     Menu, XBMCExitSubMenu, add, Start Windows8 Metro UI when XBMC is closed, MenuStartMetroUIHandler
  166.     Menu, XBMCExitSubMenu, UnCheck, Start Windows8 Metro UI when XBMC is closed
  167.     }
  168. Menu, Tray, add, XBMC Exit Settings, :XBMCExitSubMenu
  169.    
  170. Menu, XBMCPathSubMenu, add, Set XBMC Path, MenuSetXBMCPathHandler
  171. Menu, XBMCPathSubMenu, add, Set XBMConiMON Path, MenuSetXBMConiMONPathHandler
  172. Menu, XBMCPathSubMenu, add, Set iMON Path, MenuSetiMONPathHandler
  173. Menu, XBMCPathSubMenu, add, Set External Player Path (for focus disable), MenuSetExternalPlayerHandler
  174. Menu, Tray, add, XBMC Path Settings, :XBMCPathSubMenu
  175.  
  176. Menu, Tray, add ;add separator
  177. shell := RTrim(ShellName, "`.exe")
  178. Menu, Tray, add, Change Windows Shell [Current Shell - %shell%], MenuChangeShellHandler
  179. Menu, Tray, add ;add separator
  180.  
  181. SplitPath, App1, AppName
  182. if (AppName = "")
  183.     AppName = Not Set
  184. Menu, ExternalAppsSubMenu, add, Set Application 1 - %AppName%, MenuSetApp1Handler
  185.  
  186. SplitPath, App2, AppName
  187. if (AppName = "")
  188.     AppName = Not Set
  189. Menu, ExternalAppsSubMenu, add, Set Application 2 - %AppName%, MenuSetApp2Handler
  190.  
  191. SplitPath, App3, AppName
  192. if (AppName = "")
  193.     AppName = Not Set
  194. Menu, ExternalAppsSubMenu, add, Set Application 3 - %AppName%, MenuSetApp3Handler
  195.  
  196. Menu, ExternalAppsSubMenu, add, Start First Group Applications with XBMC Launcher, MenuStartApps1Handler
  197. Menu, ExternalAppsSubMenu, UnCheck, Start First Group Applications with XBMC Launcher
  198. Menu, ExternalAppsSubMenu, add, First Group Apps Prevent XBMC Focus, MenuApps1PreventFocusHandler
  199. Menu, ExternalAppsSubMenu, UnCheck, First Group Apps Prevent XBMC Focus
  200.  
  201. Menu, ExternalAppsSubMenu, add ;add separator
  202.  
  203. SplitPath, App4, AppName
  204. if (AppName = "")
  205.     AppName = Not Set
  206. Menu, ExternalAppsSubMenu, add, Set Application 4 - %AppName%, MenuSetApp4Handler
  207.  
  208. SplitPath, App5, AppName
  209. if (AppName = "")
  210.     AppName = Not Set
  211. Menu, ExternalAppsSubMenu, add, Set Application 5 - %AppName%, MenuSetApp5Handler
  212.  
  213. SplitPath, App6, AppName
  214. if (AppName = "")
  215.     AppName = Not Set
  216. Menu, ExternalAppsSubMenu, add, Set Application 6 - %AppName%, MenuSetApp6Handler
  217.  
  218. Menu, ExternalAppsSubMenu, add, Start Second Group Applications with XBMC Launcher, MenuStartApps2Handler
  219. Menu, ExternalAppsSubMenu, UnCheck, Start Second Group Applications with XBMC Launcher
  220. Menu, ExternalAppsSubMenu, add, Second Group Apps Prevent XBMC Focus, MenuApps2PreventFocusHandler
  221. Menu, ExternalAppsSubMenu, UnCheck, Second Group Apps Prevent XBMC Focus
  222.  
  223. Menu, Tray, add, External Applications, :ExternalAppsSubMenu
  224.  
  225.  
  226. Menu, FolderSubMenu, add, Open XBMC Programs Folder, MenuOpenXBMCFolderHandler
  227. Menu, FolderSubMenu, add, Open XBMC Application Data Folder, MenuOpenXBMCAppFolderHandler
  228. Menu, FolderSubMenu, add
  229. Menu, FolderSubMenu, add, Open XBMCLauncher Programs Folder, MenuOpenXBMCLauncherFolderHandler
  230. Menu, FolderSubMenu, add, Open XBMCLauncher Settings Folder, MenuOpenXBMCLauncherSettingsHandler
  231. Menu, Tray, add, Application Folders, :FolderSubMenu
  232. Menu, Tray, add
  233. Menu, Tray, add, Set DVBViewer Path (for focus disable), MenuSetDVBViewerHandler
  234. Menu, Tray, add, Ignore if DVBViewer is minimized, MenuCheckDVBViewerGetStatusHandler
  235. Menu, Tray, UnCheck, Ignore if DVBViewer is minimized
  236. Menu, Tray, add
  237. Menu, Tray, add, Turn off Display [Win+F11], MenuTurnOffDisplay
  238. Menu, Tray, add, About XBMCLauncher, MenuAboutHandler
  239. Menu, Tray, add
  240. Menu, tray, NoStandard
  241. Menu, tray, Standard
  242.  
  243. if (FocusOnce = 1)
  244.     Menu, FocusSubMenu, Check, Check Focus Only Once
  245.  
  246. if (CloseXBMCatSleep = 1)
  247.     Menu, XBMCExitSubMenu, Check, Close XBMC on Suspend
  248.  
  249. if (ForceCloseXBMC = 1)
  250.     Menu, XBMCExitSubMenu, Check, Force Close XBMC instead of Normal Close [for custom shutdown menu only]
  251.  
  252. if (StartExplorer = 1)
  253.     Menu, XBMCExitSubMenu, Check, Start Windows Explorer when XBMC is closed
  254.  
  255. if (OSVersion >= 6.2 and StartMetroUI = 1)
  256.     Menu, XBMCExitSubMenu, Check, Start Windows8 Metro UI when XBMC is closed
  257.  
  258. if (StartXBMCatWinLogon = 1)
  259.     Menu, XBMCStartSubMenu, Check, Start XBMC When Windows Starts
  260.  
  261. if (StartXBMCatWinResume = 1)
  262.     Menu, XBMCStartSubMenu, Check, Start XBMC When Windows Resumes from Sleep
  263.  
  264. if (StartXBMCPortable = 1)
  265.     Menu, XBMCStartSubMenu, Check, Start XBMC in Portable Mode
  266.  
  267. if (StartApps1 = 1)
  268.     Menu, ExternalAppsSubMenu, Check, Start First Group Applications with XBMC Launcher
  269.  
  270. if (PreventFocusApps1 = 1)
  271.     Menu, ExternalAppsSubMenu, Check, First Group Apps Prevent XBMC Focus
  272.  
  273. if (StartApps2 = 1)
  274.     Menu, ExternalAppsSubMenu, Check, Start Second Group Applications with XBMC Launcher
  275.  
  276. if (PreventFocusApps2 = 1)
  277.     Menu, ExternalAppsSubMenu, Check, Second Group Apps Prevent XBMC Focus
  278.  
  279. if (DisableFocusPermanently = 1)
  280.     Menu, FocusSubMenu, Check, Disable Focus Permanently
  281.    
  282. if (DVBViewerGetStatus = 1)
  283.     Menu, Tray, Check, Ignore if DVBViewer is minimized
  284. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>       PROMPT FOR XBMC IF NOT FOUND        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  285.  
  286.  
  287.  
  288. IfNotExist, %XBMCPath% ; if xbmc.exe is not found, prompt to select xbmc.exe manually
  289.     {
  290.         PromptXBMCPath := GetSettings("PromptXBMCPath", 1)
  291.         if (PromptXBMCPath = 1)
  292.         MsgBox, 36, Select XBMC.exe, Could not locate XBMC executable file. Do you want to select the file manually?, 10
  293.         ifMsgBox Yes
  294.         {
  295.             XBMCPath := SaveApplicationPath("XBMC", XBMCPath)
  296.             if (ShowCustomShutdownMenu = 1)
  297.             {   SplitPath, XBMCPath, ,newpath
  298.                 FileCopy, %A_WorkingDir%\ShutdownAction.exe, %newpath%, 1
  299.                 FileCopy, %A_WorkingDir%\ShutdownAction.py, %newpath%, 1
  300.                 FileCopy, %A_WorkingDir%\CloseXBMC.exe, %newpath%, 1
  301.                 FileCopy, %A_WorkingDir%\CloseXBMC.py, %newpath%, 1
  302.                 FileCopy, %newpath%\addons\skin.confluence\720p\DialogButtonMenu.xml, %newpath%\addons\skin.confluence\720p\DialogButtonMenu_Backup.xmlbk, 0
  303.                 FileCopy, %A_WorkingDir%\DialogButtonMenu.xml, %newpath%\addons\skin.confluence\720p, 1
  304.             }
  305.         }  
  306.         ifMsgBox No
  307.             SaveSettings("PromptXBMCPath", 0)
  308.            
  309.     }
  310.  
  311.  
  312.  
  313. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>           LAUNCH APPLICATIONS         <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  314.  
  315. If (StartXBMCatWinLogon = 1 and ReloadXBMCLauncher = 0)
  316. {
  317.    
  318. Sleep %StartupDelay%
  319. LaunchApplication(XBMCPath)
  320. WinWait,XBMC,,2 ; wait 2 seconds
  321. WinActivate, ahk_class XBMC ; activate and bring to front.
  322. }
  323.  
  324.  
  325. If (StartApps1 = 1 and ReloadXBMCLauncher = 0)
  326. {
  327. LaunchApplication(App1)
  328. LaunchApplication(App2)
  329. LaunchApplication(App3)
  330. }
  331.  
  332. If (StartApps2 = 1 and ReloadXBMCLauncher = 0)
  333. {
  334. LaunchApplication(App4)
  335. LaunchApplication(App5)
  336. LaunchApplication(App6)
  337. }
  338.  
  339. if (ReloadXBMCLauncher = 0)
  340.     {LaunchApplication(iMONPath)
  341.     LaunchApplication(XBMConiMONPath)
  342.     }
  343.  
  344. ReloadXBMCLauncher = 0
  345.  
  346.     ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     START XBMC ON WINDOWS RESUME FROM HIBERNATION OR SLEEP     <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  347.  
  348.  
  349. OnMessage(0x218, "WM_POWERBROADCAST")
  350.  
  351. WM_POWERBROADCAST(wParam, lParam)
  352.  
  353. {
  354.    
  355.        
  356.     If (wParam=4) ;suspend
  357.     {
  358.         ;BROADCAST_QUERY_DENY := 1112363332
  359.         ;return, BROADCAST_QUERY_DENY
  360.        
  361.         Suspending = 1 ;System is suspending. Do not start Explorer.       
  362.         if (CloseXBMCatSleep = 1) ; force close xbmc
  363.         {
  364.             Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  365.             If (ErrorLevel >= 1) ; If it is running
  366.             {
  367.                 Process, Close, %ErrorLevel%  
  368.                 Process, WaitClose, %ErrorLevel%
  369.                 sleep 1000
  370.             }
  371.         }
  372.     }  
  373.    
  374.     If (wParam=7 and StartXBMCatWinResume = 1) ;on resuming from suspend state
  375.         {
  376.                 LaunchApplication(XBMConiMONPath)
  377.            
  378.                 Sleep %StartupDelay%
  379.                 ;WinWait,XBMC,,6 ; wait 6 seconds
  380.                 WinActivate, ahk_class XBMC ; activate and bring to front.
  381.  
  382.                 LaunchApplication(XBMCPath)
  383.            
  384.                 if (DisableFocusTemporarily = 1)
  385.                 {
  386.                     DisableFocusTemporarily() ;re enable focus
  387.                 }      
  388.            
  389.                 Suspending = 0
  390.                 FocussedOnce = 0
  391.            
  392.                
  393.         }
  394.        
  395. }
  396.  
  397.  
  398. ;DllCall("kernel32.dll\SetProcessShutdownParameters", UInt, 0x4FF, UInt, 0)
  399. OnMessage(0x11, "WM_QUERYENDSESSION")
  400.  
  401. WM_QUERYENDSESSION(wParam, lParam)
  402. {
  403.     ENDSESSION_LOGOFF = 0x80000000
  404.     if (lParam & ENDSESSION_LOGOFF)  ; User is logging off.
  405.         ExitApp
  406.         ;EventType = Logoff
  407.     else  ; System is either shutting down or restarting.
  408.         ;EventType = Shutdown
  409.         ExitApp
  410. }
  411.  
  412.  
  413. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TIMER DECLARATIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  414.  
  415.  
  416. SetTimer, MonitorEvents, 500
  417.  
  418. MonitorEvents:
  419. KeepFocus()
  420. CheckDVBViewerRunning()
  421. GetDVBViewerSize()
  422. StartExplorer()
  423. if (OSVersion >= 6.2)
  424.     StartMetroUI()
  425. MonitorCustomShutdown()
  426. DisableFocusOnExternalPlayer()
  427. DisableFocusOnDVBViewer()
  428. return
  429.  
  430.  
  431. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  SYSTEM TRAY MENU HANDLERS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  432.  
  433.  
  434. MenuStartXBMCHandler:
  435. {
  436. LaunchApplication(XBMCPath)
  437. Sleep, 2000
  438. WinActivate, ahk_class XBMC
  439. FocussedOnce = 0
  440. }
  441. return
  442.  
  443.  
  444.  
  445. MenuCloseXBMCNow:
  446. {
  447.     BreakFocus = 1
  448.         Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  449.             If (ErrorLevel > 0) ; If it is running
  450.             {
  451.                
  452.                 MsgBox, 36, , Do you want to Force close XBMC?
  453.                 ifmsgbox yes
  454.                 Process, Close, %ErrorLevel%
  455.                    
  456.             }
  457.             else
  458.                 MsgBox, 64, , XBMC is not running.
  459.     BreakFocus = 0
  460. }
  461. return
  462.  
  463.  
  464. MenuStartExplorer:
  465. {Process, Exist, explorer.exe ; check to see if explorer.exe is running
  466.     If (ErrorLevel = 0)
  467.         Run,  %A_WinDir%\Explorer.exe, %A_WinDir%
  468.     else
  469.         Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ;my computer
  470. }
  471. return
  472.  
  473.  
  474. MenuShowSettingsGUI:
  475. run %A_ScriptDir% \XBMCLauncherGUI.exe
  476. return
  477.  
  478. MenuStartXBMCAtWindowsLogonHandler:
  479. StartXBMCAtWinLogon()
  480. return
  481.  
  482. MenuStartXBMCAtWindowsResumeHandler:
  483. StartXBMCAtWinResume()
  484. return
  485.  
  486.  
  487. MenuStartXBMCPortableModeHandler:
  488. StartXBMCPortableMode()
  489. return
  490.  
  491. MenuSetStartupDelayHandler:
  492. SetStartupDelay()
  493. return
  494.  
  495.  
  496. MenuSetFocusDelayHandler:
  497. SetFocusDelay()
  498. return
  499.  
  500. MenuDisableFocusPermanentlyHandler:
  501. DisableFocusPermanently()
  502. return
  503.  
  504. MenuDisableFocusHandler:
  505. DisableFocusTemporarily()
  506. return
  507.  
  508. MenuCheckFocusOnceHandler:
  509. CheckFocusOnce()
  510. return
  511.  
  512.  
  513. MenuSetXBMCPathHandler:
  514. XBMCPath := SaveApplicationPath("XBMC", XBMCPath)
  515. return
  516.  
  517. MenuSetXBMConiMONPathHandler:
  518. XBMConiMONPath := SaveApplicationPath("XBMConiMON", XBMConiMONPath)
  519. return
  520.  
  521. MenuSetiMONPathHandler:
  522. iMONPath := SaveApplicationPath("iMON", iMONPath)
  523. return
  524.  
  525. MenuSetExternalPlayerHandler:
  526. ExternalPlayerPath := SaveApplicationPath("ExternalPlayer", ExternalPlayerPath)
  527. return
  528.  
  529. MenuSetDVBViewerHandler:
  530. DVBViewerPath := SaveApplicationPath("DVBViewer", DVBViewerPath)
  531. return
  532.  
  533. MenuCheckDVBViewerGetStatusHandler:
  534. CheckDVBViewerGetStatus()
  535. return
  536.  
  537.  
  538. MenuSetApp1Handler:
  539. SplitPath, App1, AppName
  540. if (AppName = "")
  541.     AppName = Not Set
  542. oldmenuname = Set Application 1 - %AppName%
  543. App1 := SaveApplicationPath("App1", App1)
  544.  
  545. SplitPath, App1, AppName
  546. if (AppName = "")
  547.     AppName = Not Set
  548. newmenuname = Set Application 1 - %AppName%
  549.  
  550. if (oldmenuname != newmenuname)
  551.         {
  552.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  553.         }
  554. return
  555.  
  556. MenuSetApp2Handler:
  557. SplitPath, App2, AppName
  558. if (AppName = "")
  559.     AppName = Not Set
  560. oldmenuname = Set Application 2 - %AppName%
  561. App2 := SaveApplicationPath("App2", App2)
  562.  
  563. SplitPath, App2, AppName
  564. if (AppName = "")
  565.     AppName = Not Set
  566. newmenuname = Set Application 2 - %AppName%
  567.  
  568. if (oldmenuname != newmenuname)
  569.         {
  570.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  571.         }
  572. return
  573.  
  574. MenuSetApp3Handler:
  575. SplitPath, App3, AppName
  576. if (AppName = "")
  577.     AppName = Not Set
  578. oldmenuname = Set Application 3 - %AppName%
  579. App3 := SaveApplicationPath("App3", App3)
  580.  
  581. SplitPath, App3, AppName
  582. if (AppName = "")
  583.     AppName = Not Set
  584. newmenuname = Set Application 3 - %AppName%
  585.  
  586. if (oldmenuname != newmenuname)
  587.         {
  588.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  589.         }
  590. return
  591.  
  592. MenuSetApp4Handler:
  593. SplitPath, App4, AppName
  594. if (AppName = "")
  595.     AppName = Not Set
  596. oldmenuname = Set Application 4 - %AppName%
  597. App4 := SaveApplicationPath("App4", App4)
  598.  
  599. SplitPath, App4, AppName
  600. if (AppName = "")
  601.     AppName = Not Set
  602. newmenuname = Set Application 4 - %AppName%
  603.  
  604. if (oldmenuname != newmenuname)
  605.         {
  606.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  607.         }
  608. return
  609.  
  610.  
  611. MenuSetApp5Handler:
  612. SplitPath, App5, AppName
  613. if (AppName = "")
  614.     AppName = Not Set
  615. oldmenuname = Set Application 5 - %AppName%
  616. App5 := SaveApplicationPath("App5", App5)
  617.  
  618. SplitPath, App5, AppName
  619. if (AppName = "")
  620.     AppName = Not Set
  621. newmenuname = Set Application 5 - %AppName%
  622.  
  623. if (oldmenuname != newmenuname)
  624.         {
  625.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  626.         }
  627. return
  628.  
  629. MenuSetApp6Handler:
  630. SplitPath, App6, AppName
  631. if (AppName = "")
  632.     AppName = Not Set
  633. oldmenuname = Set Application 6 - %AppName%
  634. App6 := SaveApplicationPath("App6", App6)
  635.  
  636. SplitPath, App6, AppName
  637. if (AppName = "")
  638.     AppName = Not Set
  639. newmenuname = Set Application 6 - %AppName%
  640.  
  641. if (oldmenuname != newmenuname)
  642.         {
  643.             menu, ExternalAppsSubMenu, rename, %oldmenuname%, %newmenuname%
  644.         }
  645. return
  646.  
  647. MenuStartApps1Handler:
  648. SetStartApps1()
  649. return
  650.  
  651. MenuApps1PreventFocusHandler:
  652. SetPreventFocusApps1()
  653. return
  654.  
  655. MenuStartApps2Handler:
  656. SetStartApps2()
  657. return
  658.  
  659. MenuApps2PreventFocusHandler:
  660. SetPreventFocusApps2()
  661. return
  662.  
  663. MenuSetShutdownActionHandler:
  664. SetShutdownAction()
  665. return
  666.  
  667. MenuCloseXBMCatSleepHandler:
  668. CloseXBMCatSleep()
  669. return
  670.  
  671. MenuForceCloseXBMCHandler:
  672. SetForceCloseXBMC()
  673. return
  674.  
  675. MenuStartExplorerHandler:
  676. SetStartExplorer()
  677. return
  678.  
  679. MenuStartMetroUIHandler:
  680. SetStartMetroUI()
  681. return
  682.  
  683. MenuChangeShellHandler:
  684. ChangeShell()
  685. return
  686.  
  687. MenuOpenXBMCAppFolderHandler:
  688. {
  689.     appfolder := A_AppData . "\XBMC"
  690.     ifexist, %appfolder%
  691.         run %appfolder%
  692.     else
  693.         MsgBox, Folder not found.
  694. }
  695.  
  696. return
  697.  
  698. MenuOpenXBMCFolderHandler:
  699. {
  700.     SplitPath, XBMCPath, , xbmcfolder
  701.     IfExist, %xbmcfolder%
  702.         run %xbmcfolder%
  703.     else
  704.         MsgBox, Folder not found.
  705. }
  706.  
  707. return
  708.  
  709.  
  710. MenuOpenXBMCLauncherFolderHandler:
  711.  
  712. {
  713.     run %A_ScriptDir%
  714. }
  715.  
  716. return
  717.  
  718.  
  719. MenuOpenXBMCLauncherSettingsHandler:
  720. {
  721.     SettingsPath := A_AppData . "\XBMCLauncher"
  722.     IfExist, %SettingsPath%
  723.         run %SettingsPath%
  724.     else
  725.         MsgBox, Folder not found.
  726. }
  727. return
  728.  
  729. MenuTurnOffDisplay:
  730. {
  731.     Sleep 1000
  732.     SendMessage 0x112, 0xF170, 2,,Program Manager
  733. }
  734. return
  735.  
  736.  
  737. MenuAboutHandler:
  738. {
  739.     BreakFocus = 1
  740. MsgBox XBMCLauncher %AppVersion% `n`nAn application to customize your XBMC HTPC. `nDesigned and programmed by baijuxavior@gmail.com`n`n *********************************************************`n`nSpecial credits: `n`n  'EliteGamer360' for GSB code. `n  'Snood' for additional apps support and winkey programming.
  741. }
  742. BreakFocus = 0
  743. return
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>               FUNCTIONS                   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  753.  
  754.  
  755. GetSettings(SettingsName, DefaultValue) ;Get settings from registry
  756. {
  757.     RegRead, result, HKCU, Software\XBMCLauncher, %SettingsName%
  758.     if (result = "")
  759.         return %DefaultValue%
  760.     else
  761.         return %result%
  762. }
  763.  
  764.  
  765. SaveSettings(SettingsName, Value)
  766. {
  767.     RegWrite,reg_sz,HKCU,Software\XBMCLauncher, %SettingsName%, %Value%
  768. }
  769.  
  770.  
  771.  
  772. KeepFocus()
  773. {
  774.     if (FocusDelay = 0 or DisableFocusTemporarily = 1 or DisableFocusPermanently = 1 or ExternalPlayerRunning = 1 or DVBViewerActive = 1)
  775.         {
  776.         FocusCount = 0
  777.         return
  778.         }
  779.        
  780.     FocusCount := FocusCount + 1
  781.        
  782.        
  783.     If (FocusCount = (FocusDelay * 2) // 1000)
  784.         {
  785.            
  786.             FocusCount = 0
  787.         if (FocusOnce = 0)
  788.             {
  789.             SendFocus()
  790.             return
  791.             }
  792.        
  793.         if (FocusOnce = 1 and FocussedOnce = 0)
  794.             {
  795.             SendFocus()
  796.             FocussedOnce = 1
  797.             }
  798.         }
  799.    
  800. }
  801.  
  802.  
  803. SendFocus()
  804. {
  805.     Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  806.     If (ErrorLevel >= 1 and BreakFocus = 0)
  807.         IfWinNotActive, ahk_class XBMC ;if xbmc is not active
  808.         { ; code courtesy onyx00 @ http://forum.xbmc.org/showthread.php?tid=136798&pid=1463619#pid1463619
  809.             WinGet, hWnd, ID, ahk_class XBMC
  810.             WinRestore, ahk_class XBMC
  811.             DllCall("SetForegroundWindow", UInt, hWnd)
  812.         }
  813.            
  814. }
  815.  
  816.  
  817.  
  818. SetFocusDelay() ;function to Change Focus Delay
  819. {
  820.     BreakFocus = 1
  821.     currentdelay := FocusDelay // 1000
  822.     if currentdelay is not number
  823.         currentdelay = 5
  824.    
  825.     InputBox, Delay, XBMCLauncher - Specify Time Delay, Specify the delay between refocussing of XBMC in seconds. `n `nEnter '0' seconds to prevent refocus permanently., , , , , , , , %currentdelay%
  826.  
  827.     If ErrorLevel ; If cancel was pressed
  828.         {
  829.             ;MsgBox cancel
  830.         }
  831.     else
  832.         {
  833.             If Delay is not number
  834.                 {
  835.                 Delay = 5000
  836.                 }
  837.             Else
  838.                 {
  839.                 Delay := Delay * 1000
  840.                 }
  841.        
  842.                 SaveSettings("FocusDelay", Delay)
  843.                 FocusDelay := Delay
  844.                 fdelaynew := FocusDelay // 1000
  845.                 old_name = Change Focus Delay [%currentdelay% sec]
  846.                 new_name = Change Focus Delay [%fdelaynew% sec]
  847.                                
  848.                 if (old_name != new_name)
  849.                 {
  850.                     menu, FocusSubMenu, rename, %old_name%, %new_name%
  851.                 }
  852.                
  853.                    
  854.         }
  855.        
  856.     BreakFocus = 0 
  857. }
  858.  
  859.  
  860.  
  861. LaunchApplication(AppPath) ; function to start applications
  862. {
  863. SplitPath, AppPath, FileName ;get filename without path
  864. Process, Exist, %FileName% ; check to see if 'FileName' is running
  865. If (ErrorLevel = 0) ;if not running
  866.     {
  867.     if FileExist(AppPath)
  868.         {
  869.         if (FileName = "XBMC.exe" and StartXBMCPortable = 1)
  870.             run %AppPath% -p
  871.         else
  872.             run %AppPath%
  873.         }
  874.     Else
  875.         {
  876.         ;traytip, Message, %AppPath% not found, 5, 1
  877.         }
  878.     }
  879.     Else ; file already running
  880.     {
  881.     ;traytip, Message, %FileName% already running, 5, 1
  882.     }
  883. }
  884.  
  885.  
  886. SaveApplicationPath(AppName, StartPath)
  887. {
  888.     BreakFocus = 1
  889. FileSelectFile, SelectedFileName,1 ,%StartPath%, Select %AppName%.exe, *.exe
  890. if SelectedFileName !=
  891.     {
  892.         BreakFocus = 0
  893.         SaveSettings(AppName . "_Path", SelectedFileName)
  894.         return %SelectedFileName%
  895.     }
  896. else
  897.     BreakFocus = 0
  898.     return  %StartPath%
  899.    
  900. }
  901.  
  902.  
  903. StartXBMCAtWinLogon()
  904. {
  905.     menu, XBMCStartSubMenu, ToggleCheck, Start XBMC When Windows Starts
  906.     if (StartXBMCatWinLogon = 0)
  907.         StartXBMCatWinLogon = 1 ;enable. load xbmc
  908.     else
  909.         StartXBMCatWinLogon = 0 ;disable. don't load
  910.         SaveSettings("StartXBMCatWinLogon", StartXBMCatWinLogon)
  911.         return
  912. }
  913.  
  914. StartXBMCAtWinResume()
  915. {
  916.     menu, XBMCStartSubMenu, ToggleCheck, Start XBMC When Windows Resumes from Sleep
  917.     if (StartXBMCatWinResume = 0)
  918.         StartXBMCatWinResume = 1 ;enable. load xbmc
  919.     else
  920.         StartXBMCatWinResume = 0 ;disable. don't load
  921.        
  922.         SaveSettings("StartXBMCatWinResume", StartXBMCatWinResume)
  923.         return
  924. }
  925.  
  926.  
  927.  
  928. StartXBMCPortableMode()
  929. {
  930.     menu, XBMCStartSubMenu, ToggleCheck, Start XBMC in Portable Mode
  931.     if (StartXBMCPortable = 0)
  932.         StartXBMCPortable = 1 ;enable. load xbmc in portable mode
  933.     else
  934.         StartXBMCPortable = 0 ;disable.
  935.        
  936.         SaveSettings("StartXBMCPortable", StartXBMCPortable)
  937.         return
  938. }
  939.  
  940.  
  941. DisableFocusTemporarily()
  942. {
  943.     menu, FocusSubMenu, ToggleCheck, Disable Focus Temporarily [Win+F9]
  944.     if (DisableFocusTemporarily = 0)
  945.         DisableFocusTemporarily = 1 ;disable focus
  946.     else
  947.         DisableFocusTemporarily = 0 ;enable focus
  948.    
  949. }
  950.  
  951. DisableFocusPermanently()
  952. {
  953.     menu, FocusSubMenu, ToggleCheck, Disable Focus Permanently
  954.     if (DisableFocusPermanently = 0)
  955.         DisableFocusPermanently = 1 ;disable focus
  956.     else
  957.         DisableFocusPermanently = 0 ;enable focus
  958.     SaveSettings("DisableFocusPermanently", DisableFocusPermanently)
  959. }
  960.  
  961. DisableFocusOnExternalPlayer()
  962. {
  963.     global appsname
  964.     ExternalPlayerRunning = 0
  965.    
  966.     if (ExternalPlayerPath != "")
  967.     {
  968.         SplitPath, ExternalPlayerPath, playername
  969.         Process, exist, %playername%
  970.         If (ErrorLevel >= 1)
  971.             ExternalPlayerRunning = 1
  972.     }
  973.    
  974.     if (PreventFocusApps1 = 1)
  975.     {
  976.         if (FileExist(App1))
  977.             {SplitPath, App1, appsname
  978.             ;if (appsname <> "")
  979.             Process, exist, %appsname%
  980.             If (ErrorLevel >= 1)
  981.             ExternalPlayerRunning = 1
  982.             }
  983.        
  984.         if (FileExist(App2))
  985.             {SplitPath, App2, appsname
  986.             ;if (appsname <> "")
  987.             Process, exist, %appsname%
  988.             If (ErrorLevel >= 1)
  989.             ExternalPlayerRunning = 1
  990.             }
  991.        
  992.         if (FileExist(App3))
  993.             {SplitPath, App3, appsname
  994.             ;if (appsname <> "")
  995.             Process, exist, %appsname%
  996.             If (ErrorLevel >= 1)
  997.             ExternalPlayerRunning = 1
  998.             }
  999.     }
  1000.    
  1001.     if (PreventFocusApps2 = 1)
  1002.     {
  1003.                
  1004.         if (FileExist(App4))
  1005.             {SplitPath, App4, appsname
  1006.             ;if (appsname <> "")
  1007.             Process, exist, %appsname%
  1008.             If (ErrorLevel >= 1)
  1009.             ExternalPlayerRunning = 1
  1010.             }
  1011.        
  1012.         if (FileExist(App5))
  1013.             {SplitPath, App5, appsname
  1014.             ;if (appsname <> "")
  1015.             Process, exist, %appsname%
  1016.             If (ErrorLevel >= 1)
  1017.             ExternalPlayerRunning = 1
  1018.             }
  1019.        
  1020.         if (FileExist(App6))
  1021.             {SplitPath, App6, appsname
  1022.             ;if (appsname <> "")
  1023.             Process, exist, %appsname%
  1024.             If (ErrorLevel >= 1)
  1025.             ExternalPlayerRunning = 1
  1026.             }
  1027.     }
  1028.    
  1029. }
  1030.  
  1031.  
  1032. CheckFocusOnce()
  1033. {
  1034.     menu, FocusSubMenu, ToggleCheck, Check Focus Only Once
  1035.     if (FocusOnce = 0)
  1036.         FocusOnce = 1 ;enable. focus only once
  1037.     else
  1038.         FocusOnce = 0 ;disable. keep focussing
  1039.         SaveSettings("FocusOnce", FocusOnce)
  1040.         return
  1041. }
  1042.  
  1043.  
  1044.  
  1045. CloseXBMCatSleep()
  1046. {
  1047.     menu, XBMCExitSubMenu, ToggleCheck,Close XBMC on Suspend
  1048.     if (CloseXBMCatSleep = 0)
  1049.         CloseXBMCatSleep = 1 ;enable
  1050.     else
  1051.         CloseXBMCatSleep = 0 ;disable
  1052.         SaveSettings("CloseXBMCatSleep", CloseXBMCatSleep)
  1053.         return
  1054. }
  1055.  
  1056.  
  1057. SetForceCloseXBMC()
  1058. {
  1059.     menu, XBMCExitSubMenu, ToggleCheck,Force Close XBMC instead of Normal Close [for custom shutdown menu only]
  1060.     if (ForceCloseXBMC = 0)
  1061.         ForceCloseXBMC = 1 ;enable
  1062.     else
  1063.         ForceCloseXBMC = 0 ;disable
  1064.         SaveSettings("ForceCloseXBMC", ForceCloseXBMC)
  1065.         return
  1066. }
  1067.  
  1068.  
  1069. SetStartExplorer()
  1070. {
  1071.     menu, XBMCExitSubMenu, ToggleCheck,Start Windows Explorer when XBMC is closed
  1072.     if (StartExplorer = 0)
  1073.         StartExplorer = 1 ;enable
  1074.     else
  1075.         StartExplorer = 0 ;disable
  1076.                
  1077.         SaveSettings("StartExplorer", StartExplorer)
  1078.         return
  1079. }
  1080.  
  1081.  
  1082. SetStartMetroUI()
  1083. {
  1084.     menu, XBMCExitSubMenu, ToggleCheck,Start Windows8 Metro UI when XBMC is closed
  1085.     if (StartMetroUI = 0)
  1086.         StartMetroUI = 1 ;enable
  1087.     else
  1088.         StartMetroUI = 0 ;disable
  1089.                
  1090.         SaveSettings("StartMetroUI", StartMetroUI)
  1091.         return
  1092. }
  1093.  
  1094. SetStartApps1()
  1095. {
  1096.     menu, ExternalAppsSubMenu, ToggleCheck, Start First Group Applications with XBMC Launcher
  1097.     if (StartApps1 = 0)
  1098.         StartApps1 = 1 ;enable.
  1099.     else
  1100.         StartApps1 = 0 ;disable.
  1101.         SaveSettings("StartApps1", StartApps1)
  1102.         return
  1103. }
  1104.  
  1105. SetStartApps2()
  1106. {
  1107.     menu, ExternalAppsSubMenu, ToggleCheck, Start Second Group Applications with XBMC Launcher
  1108.     if (StartApps2 = 0)
  1109.         StartApps2 = 1 ;enable.
  1110.     else
  1111.         StartApps2 = 0 ;disable.
  1112.        
  1113.         SaveSettings("StartApps2", StartApps2)
  1114.         return
  1115. }
  1116.  
  1117. SetPreventFocusApps1()
  1118. {
  1119.     menu, ExternalAppsSubMenu, ToggleCheck, First Group Apps Prevent XBMC Focus
  1120.     if (PreventFocusApps1 = 0)
  1121.         PreventFocusApps1 = 1 ;enable.
  1122.     else
  1123.         PreventFocusApps1 = 0 ;disable.
  1124.        
  1125.         SaveSettings("PreventFocusApps1", PreventFocusApps1)
  1126.         return
  1127. }
  1128.  
  1129. SetPreventFocusApps2()
  1130. {
  1131.     menu, ExternalAppsSubMenu, ToggleCheck, Second Group Apps Prevent XBMC Focus
  1132.     if (PreventFocusApps2 = 0)
  1133.         PreventFocusApps2 = 1 ;enable.
  1134.     else
  1135.         PreventFocusApps2 = 0 ;disable.
  1136.        
  1137.         SaveSettings("PreventFocusApps2", PreventFocusApps2)
  1138.         return
  1139. }
  1140.  
  1141. SetShutdownAction() ;function to set shutdown
  1142. {
  1143.     BreakFocus = 1
  1144.     ShutdownAction := GetSettings("ShutdownAction", "u")
  1145.     global S1
  1146.     global S2
  1147.     global S3
  1148.    
  1149.    
  1150.         global currentshutdownaction := "Shutdown"
  1151.         If (ShutdownAction = "u")
  1152.             currentshutdownaction := "Shutdown"
  1153.         If (ShutdownAction = "h")
  1154.             currentshutdownaction := "Hibernate"
  1155.         If (ShutdownAction = "s")
  1156.             currentshutdownaction := "Sleep"
  1157.        
  1158.     global oldshutdownmenu  := "Set Shutdown Button Action [for custom shutdown menu only] - " . currentshutdownaction
  1159.    
  1160.    
  1161.     Gui, Add, GroupBox, x1 y4 w350 h111 +Center, Select XBMC Shutdown Menu Action
  1162.     Gui, Add, Radio,  % ( ShutdownAction = "u" ? "Checked" : "" ) " x10 y40 w70 h30 vS1" , Shutdown
  1163.     Gui, Add, Radio,  % ( ShutdownAction = "s" ? "Checked" : "" ) " x140 y40 w70 h30 vS2" , Sleep
  1164.     Gui, Add, Radio,  % ( ShutdownAction = "h" ? "Checked" : "" ) " x250 y40 w70 h30 vS3" , Hibernate
  1165.     Gui, Add, Button, x125 y78 w100 h30 , Apply
  1166.     Gui, Show, w352 h121, Select XBMC Shutdown Menu Action
  1167.     return
  1168.  
  1169.     ButtonApply:
  1170.    
  1171.     global newlabel
  1172.    Gui Submit, NoHide
  1173.    Gui Destroy
  1174.    If S1
  1175.     {
  1176.       Result = u
  1177.       newlabel = Shutdown
  1178.     }
  1179.    If S2
  1180.     {
  1181.       Result = s
  1182.       newlabel = Sleep
  1183.     }
  1184.    If S3
  1185.     {
  1186.       Result = h
  1187.       newlabel = Hibernate
  1188.     }
  1189.    
  1190.     global newshutdownmenu  = "Set Shutdown Button Action [for custom shutdown menu only] - " . newlabel   
  1191.    
  1192.     if (oldshutdownmenu != newshutdownmenu)
  1193.         {
  1194.             menu, XBMCExitSubMenu, rename, %oldshutdownmenu%, %newshutdownmenu%
  1195.         }
  1196.    
  1197.     SaveSettings("ShutdownAction", Result) 
  1198.        
  1199.     GuiClose:
  1200.     Gui, Destroy
  1201.     BreakFocus = 0
  1202.     Return
  1203. }
  1204.  
  1205.  
  1206.  
  1207. ChangeShell()
  1208. {
  1209.     RegRead, ShellName, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell
  1210.     global SelectedShellName := ShellName
  1211.     SplitPath, ShellName, ShellName
  1212.         global OtherShellName = "Other Shell"
  1213.     If(ShellName != "XBMCLauncher.exe" and ShellName != "Explorer.exe" and ShellName != "Explorer")
  1214.     {  
  1215.         OtherShellName := RTrim(ShellName, "`.exe")
  1216.         ;MsgBox %ShellName%
  1217.     }
  1218.    
  1219.     BreakFocus = 1
  1220.     global SH1
  1221.     global SH2
  1222.     global SH3
  1223.     global shelln := RTrim(ShellName, "`.exe")
  1224.     global old_shellname := "Change Windows Shell [Current Shell - " . shelln . "]"
  1225.        
  1226.     Gui, Add, GroupBox, x1 y4 w460 h111 +Center, Change Windows Shell
  1227.     Gui, Add, Radio,  % ( Shelln = "Explorer" ? "Checked" : "" ) " x10 y40 w70 h30 vSH1" , Explorer
  1228.     Gui, Add, Radio,  % ( Shelln = "XBMCLauncher" ? "Checked" : "" ) " x100 y40 w100 h30 vSH2" , XBMCLauncher
  1229.     Gui, Add, Radio,  % ( Shelln = OtherShellName ? "Checked" : "" ) " x230 y40 w130 h30 vSH3" , %OtherShellName%
  1230.     Gui, Add, Button, x380 y40 w70 h30 , Select
  1231.     Gui, Add, Button, x180 y78 w100 h30 , Save
  1232.     Gui, Show, w463 h121, Change Windows Shell
  1233.     return
  1234.    
  1235.     ButtonSelect:  
  1236.        
  1237.         FileSelectFile, SelectedShellName,1 ,%ProgFiles%, Select Shell, *.exe
  1238.         if SelectedShellName !=
  1239.             {
  1240.                 GuiControl,, %OtherShellName%, 1
  1241.                 SplitPath, SelectedShellName, NewName
  1242.                 NewName := RTrim(NewName, "`.exe")
  1243.                 GuiControl,Text, %OtherShellName%, %NewName%
  1244.             }
  1245.         ;Result = %SelectedFileName%
  1246.         ;else
  1247.         ;Result = "Explorer.exe"
  1248.         return
  1249.     ButtonSave:
  1250.     Result = Explorer
  1251.    Gui Submit, NoHide
  1252.    Gui Destroy
  1253.    If SH1
  1254.       {Result = Explorer.exe
  1255.       shelln = Explorer
  1256.       }
  1257.    If SH2
  1258.       {Result = %A_WorkingDir%\XBMCLauncher.exe
  1259.       shelln = XBMCLauncher
  1260.       }
  1261.      
  1262.     If SH3
  1263.       {
  1264.         Result = %SelectedShellName%
  1265.         SplitPath, Result, ShellName
  1266.         shelln := RTrim(ShellName, "`.exe")
  1267.       }
  1268.     RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell, %Result%
  1269.     new_shellname = Change Windows Shell [Current Shell - %shelln%]
  1270.    
  1271.     if (old_shellname != new_shellname)
  1272.         {
  1273.             menu, tray, rename, %old_shellname%, %new_shellname%
  1274.         }
  1275.        
  1276.     Gui1Close:
  1277.     Gui, Destroy
  1278.     BreakFocus = 0
  1279.     Return
  1280. }
  1281.  
  1282.  
  1283. MonitorCustomShutdown()
  1284. {
  1285.     ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
  1286.     if (ShutdownButtonClicked = 1)
  1287.     {  
  1288.        
  1289.            
  1290.         Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  1291.         If (ErrorLevel = 0) ; If it is closed
  1292.         {
  1293.             ShutdownAction := GetSettings("ShutdownAction", "u")
  1294.             SaveSettings("ShutdownButtonClicked", 0)   
  1295.             sleep 1000 ;wait one second
  1296.            
  1297.             if (ShutdownAction = "u") ;shutdown
  1298.                 {
  1299.                     if (OSVersion >= 6.2) ; if windows 8
  1300.                         {
  1301.                         if (ForceCloseXBMC = 1)
  1302.                             run, Shutdown.exe -s -hybrid -f -t 00, ,Hide
  1303.                         else
  1304.                             run, Shutdown.exe -s -hybrid -t 00, ,Hide
  1305.                         }
  1306.                     else
  1307.                         {
  1308.                         if (ForceCloseXBMC = 1)
  1309.                             Shutdown, 5 ;shutdown = 1, force = 4
  1310.                         else
  1311.                             Shutdown, 1
  1312.                         }
  1313.                     ExitApp
  1314.                 }
  1315.                
  1316.             if (ShutdownAction = "r") ;reboot
  1317.                 {
  1318.                 if (ForceCloseXBMC = 1)
  1319.                     Shutdown, 6 ;reboot = 2, force = 4
  1320.                 else
  1321.                     Shutdown, 2
  1322.                 ExitApp
  1323.                 }
  1324.                    
  1325.             if (ShutdownAction = "s")   ;sleep
  1326.                 {
  1327.                 DllCall("PowrProf\SetSuspendState", "int", 0)
  1328.                 }
  1329.                
  1330.             if (ShutdownAction = "h")   ;hibernate
  1331.                 {
  1332.                 DllCall("PowrProf\SetSuspendState", "int", 1)
  1333.                 }
  1334.                
  1335.         }
  1336.     }
  1337.    
  1338.     RestartXBMC := GetSettings("RestartXBMC", 0)
  1339.     ;MsgBox %RestartXBMC%
  1340.     If(RestartXBMC = 1)
  1341.         {
  1342.                 ;MsgBox sss
  1343.             Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  1344.             If (ErrorLevel > 0) ; If it is running
  1345.             {
  1346.                 if (ForceCloseXBMC = 1)
  1347.                     Process, Close, %ErrorLevel%  
  1348.                 else
  1349.                     WinClose, ahk_class XBMC
  1350.                     WinWaitClose, ahk_class XBMC
  1351.             }
  1352.             Loop
  1353.             {
  1354.                 sleep, 1000 ; wait one second
  1355.                 Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  1356.                 If (ErrorLevel = 0) ; not running
  1357.                 {
  1358.                     LaunchApplication(XBMCPath)
  1359.                     Sleep, 2000
  1360.                     WinActivate, ahk_class XBMC
  1361.                     SaveSettings("RestartXBMC", 0)
  1362.                     break
  1363.                 }
  1364.            
  1365.             }
  1366.                
  1367.         }
  1368. }
  1369.  
  1370.  
  1371.  
  1372. StartExplorer()
  1373. {  
  1374.     RestartXBMC := GetSettings("RestartXBMC", 0)
  1375.  
  1376.     If(RestartXBMC = 0)
  1377.     {
  1378.         ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
  1379.         if (StartExplorer = 1 and Suspending = 0 and ShutdownButtonClicked = 0) ;if not suspending
  1380.         {
  1381.             Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  1382.             If (ErrorLevel = 0) ;if not running
  1383.                 Process, Exist, explorer.exe ; check to see if explorer.exe is running
  1384.                 If (ErrorLevel = 0)
  1385.                     {Run,  %A_WinDir%\Explorer.exe, %A_WinDir%
  1386.                         ;if (OSVersion >= 6.2)
  1387.                             ;{sleep , 2000
  1388.                             ;SendInput ^{Esc}
  1389.                             ;}
  1390.                     }
  1391.         }
  1392.     }
  1393. }
  1394.  
  1395.  
  1396.  
  1397. StartMetroUI()
  1398.  
  1399. {
  1400.     RestartXBMC := GetSettings("RestartXBMC", 0)
  1401.     If(RestartXBMC = 0)
  1402.     {
  1403.             ShutdownButtonClicked := GetSettings("ShutdownButtonClicked", 0)
  1404.             if (StartMetroUI = 1 and Suspending = 0 and ShutdownButtonClicked = 0) ;if not suspending
  1405.             {
  1406.             Process, Exist, xbmc.exe ; check to see if xbmc.exe is running
  1407.             If (ErrorLevel = 0) ;if not running
  1408.                 {
  1409.                     Process, Exist, explorer.exe ; check to see if explorer.exe is running
  1410.                     If (ErrorLevel = 0)
  1411.                         Run,  %A_WinDir%\Explorer.exe, %A_WinDir%
  1412.                         If (WinKeySent = 0)
  1413.                         ;SendInput {Lwin}
  1414.                         SendInput ^{Esc} ;Ctrl+Escape Toggles Metro Start screen
  1415.                         WinKeySent = 1 ;prevents an infinite loop of win key presses
  1416.                 }
  1417.                 else
  1418.                     WinKeySent = 0
  1419.             }
  1420.     }
  1421. }
  1422.  
  1423.  
  1424. SetStartupDelay()
  1425. {
  1426.     BreakFocus = 1
  1427.     currentstartupdelay := StartupDelay // 1000
  1428.     if currentstartupdelay is not number
  1429.         currentstartupdelay = 0
  1430.    
  1431.     InputBox, StartDelay, XBMCLauncher - Specify Startup Delay, Specify the delay  in seconds for XBMC to start., , , , , , , , %currentstartupdelay%
  1432.  
  1433.     If ErrorLevel ; If cancel was pressed
  1434.         {
  1435.             ;MsgBox cancel
  1436.         }
  1437.     else
  1438.         {
  1439.             If StartDelay is not number
  1440.                 {
  1441.                 StartDelay = 0
  1442.                 }
  1443.             Else
  1444.                 {
  1445.                 StartDelay := StartDelay * 1000
  1446.                 }
  1447.                
  1448.                 StartupDelay := StartDelay
  1449.                 SaveSettings("StartupDelay", StartupDelay)
  1450.                 startdelaynew := StartupDelay // 1000
  1451.                 startdelayold_name = Change Startup Delay [%currentstartupdelay% sec]
  1452.                 startdelaynew_name = Change Startup Delay [%startdelaynew% sec]
  1453.                                
  1454.                 if (startdelayold_name != startdelaynew_name)
  1455.                 {
  1456.                     menu, XBMCStartSubMenu, rename, %startdelayold_name%, %startdelaynew_name%
  1457.                 }
  1458.                
  1459.                    
  1460.         }
  1461.     BreakFocus = 0 
  1462. }
  1463.  
  1464. return
  1465.  
  1466.  
  1467. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                           DVBViewer FUNCTIONS                                     <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1468.  
  1469.  
  1470. CheckDVBViewerGetStatus()
  1471. {
  1472.         menu, tray, ToggleCheck, Ignore if DVBViewer is minimized      
  1473.         if (DVBViewerGetStatus = 0)
  1474.                 DVBViewerGetStatus = 1 ;enable. check DVBViewer window size
  1475.         else
  1476.                 DVBViewerGetStatus = 0 ;disable. dont check DVBViewer window size
  1477.                
  1478.                 SaveSettings("DVBViewerGetStatus", DVBViewerGetStatus)
  1479.                 return
  1480. }
  1481.  
  1482.  
  1483.  
  1484. GetDVBViewerSize()
  1485. {
  1486.         WinGet, DVBViewerPresentSize, MinMax, ahk_class TfrmMain
  1487.         if DVBViewerPresentSize < 0
  1488.                 DVBViewerSize = 0
  1489.         if DVBViewerPresentSize = 0
  1490.                 DVBViewerSize = 1
  1491.         if DVBViewerPresentSize = 1
  1492.                 DVBViewerSize = 2
  1493. }
  1494.  
  1495.  
  1496.  
  1497. CheckDVBViewerRunning()
  1498. {
  1499.         SplitPath, DVBViewerPath, viewername
  1500.         Process, exist, %viewername%  
  1501.         If (ErrorLevel >= 1)
  1502.                 DVBViewerRunning = 1
  1503.         Else
  1504.                 DVBViewerRunning = 0
  1505. }
  1506.  
  1507.  
  1508.  
  1509. DisableFocusOnDVBViewer()
  1510. {
  1511.         IF (DVBViewerRunning = 1 and DVBViewerGetStatus = 0)
  1512.                 DVBViewerActive = 1
  1513.         Else If (DVBViewerRunning = 1 and DVBViewerGetStatus = 1)
  1514.                 {
  1515.                 If (DVBViewerSize > 0)
  1516.                         DVBViewerActive = 1
  1517.                 Else
  1518.                         DVBViewerActive = 0
  1519.                 }
  1520.         Else
  1521.                 DVBViewerActive = 0
  1522.        
  1523.        ;MsgBox Running:%DVBViewerRunning% Status:%DVBViewerGetStatus% Size:%DVBViewerSize% Active:%DVBViewerActive% Delay:%FocusDelay% Temp:%DisableFocusTemporarily% External:%ExternalPlayerRunning%
  1524. }
  1525.  
  1526.  
  1527.  
  1528.  
  1529. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HANDLE KEYBOARD SHORTCUTS FOR GREEN START BUTTON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1530.  
  1531. #F9:: ;Win+F9
  1532. DisableFocusTemporarily()
  1533. return
  1534.  
  1535. $!F4:: ;Alt+F4
  1536. IfWinActive, ahk_class XBMC ; check to see if xbmc.exe is running
  1537.     {
  1538.     Send s
  1539.     return
  1540.     }
  1541. IfWinNotActive, ahk_class XBMCLauncher
  1542.     Send !{F4}
  1543.     return 
  1544.  
  1545. ^!F10:: ;show traymenu
  1546. #F10:: ;show traymenu
  1547. DetectHiddenWindows, on
  1548. WinExist( "AHK_Pid " DllCall("GetCurrentProcessId") ) ; make this script's main window the last found window
  1549. WinActivate ; even though it's hidden, the target script's main window must be active for the menu to open
  1550. SendMessage, 0x404, 0, 0x205 ; AHK_NOTIFYICON = 0x404, WM_RBUTTONUP = 0x205
  1551. return
  1552.  
  1553. #f11:: ; Turn off Display Screen
  1554. ;Run,%A_WinDir%\System32\rundll32.exe user32.dll`,LockWorkStation
  1555. Sleep 1000
  1556. SendMessage 0x112, 0xF170, 2,,Program Manager
  1557. return
  1558.  
  1559. #E:: ;start explorer
  1560. Process, Exist, explorer.exe ; check to see if explorer.exe is running
  1561.     If (ErrorLevel = 0)
  1562.         Run,  %A_WinDir%\Explorer.exe, %A_WinDir%
  1563.     else
  1564.         Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ;my computer
  1565. return
  1566.  
  1567. #S:: ;show settings gui
  1568. run %A_ScriptDir% \XBMCLauncherGUI.exe
  1569. return
  1570.  
  1571. #!Enter:: ; Win+Alt+Enter shortcut key
  1572.  
  1573. LaunchApplication(XBMCPath)
  1574. ;Sleep, 2000
  1575. WinActivate, ahk_class XBMC
  1576. FocussedOnce = 0
  1577. LaunchApplication(iMONPath)
  1578. LaunchApplication(XBMConiMONPath)
  1579. Sleep, 1000
  1580. WinActivate, ahk_class XBMC
  1581.  
  1582. WinGet, Style, Style, ahk_class XBMC
  1583.     if (Style & 0xC00000)  ;Detects if XBMC has a title bar.
  1584.         Send {VKDC}  ;Maximize XBMC to fullscreen mode if its in a window mode.
  1585.     Return
  1586.  
  1587.  
  1588.         SetTitleMatchMode 2
  1589.         #IfWinActive XBMC ahk_class XBMC ; XBMC detection for XBMC/GSB Home Screen action.
  1590.         #!Enter::
  1591.         WinGet, Style, Style, ahk_class XBMC
  1592.         if (Style & 0xC00000)  ;Detects if XBMC has a title bar.
  1593.             Send {VKDC}  ;Maximize XBMC to fullscreen mode if its in a window mode.
  1594.         WinMaximize ;Maximize XBMC if Windowed.
  1595.         send, ^!{VK74} ; if XBMC is Active (GSB Home Jump will activate)
  1596.         Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement