diff --git a/docs/manual.txt b/docs/manual.txt index aab52bb..5f1cbe2 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -280,7 +280,8 @@ Contents: key combination: CTRL+ALT+F1 that is, press and hold the CTRL key and the ALT key then depress the F1 key and release all three. A popup menu will appear at your mouse cursor location. This menu can be used recover from a broken - configuration. + configuration. Note that launching Explorer might not always work if there is + already an Explorer file manager window open. A) LiteStep Structure --------------------- diff --git a/litestep/RecoveryMenu.cpp b/litestep/RecoveryMenu.cpp index 81c511b..9fa36e1 100644 --- a/litestep/RecoveryMenu.cpp +++ b/litestep/RecoveryMenu.cpp @@ -37,6 +37,8 @@ #define ID_TERMINATE 3 #define ID_RUN 4 #define ID_SHUTDOWN 5 +#define ID_EXPLORER 6 +#define ID_ABOUT 7 const TCHAR szRecoveryMenuWndClass[] = _T("RecoveryMenuWndClass"); @@ -56,8 +58,10 @@ rgMenuCommands[] = \ { IDS_LITESTEP_RECYCLELS, ID_RECYCLE, "Re&cycle LiteStep" } ,{ IDS_LITESTEP_QUITLS, ID_QUIT, "&Quit LiteStep" } ,{ IDS_LITESTEP_TERMINATELS, ID_TERMINATE, "Forcibly &Terminate LiteStep" } + ,{ IDS_LITESTEP_ABOUTLS, ID_ABOUT, "&About LiteStep" } ,{ 0, -1, "" } ,{ IDS_LITESTEP_RUN, ID_RUN, "&Run..." } + ,{ IDS_LITESTEP_EXPLORER, ID_EXPLORER, "&Start Explorer as shell" } ,{ 0, -1, "" } ,{ IDS_LITESTEP_SHUTDOWNWIN, ID_SHUTDOWN, "Sh&utdown Windows..." } }; @@ -344,6 +348,21 @@ void RecoveryMenu::HandleMenuCommand(int nCommand) const PostMessage(GetLitestepWnd(), LM_RECYCLE, LR_QUIT, 0); } break; + + case ID_ABOUT: + { + // ditto + LMBANGCOMMAND lmbc = {sizeof(LMBANGCOMMAND), NULL, "!about", NULL}; + PostMessage(GetLitestepWnd(), LM_BANGCOMMAND, 0, (LPARAM)&lmbc); + } + break; + + case ID_EXPLORER: + { + // ditto + PostMessage(GetLitestepWnd(), LM_RECYCLE, LR_EXPLORER, 0); + } + break; case ID_TERMINATE: { diff --git a/litestep/WinMain.cpp b/litestep/WinMain.cpp index 0b30971..9dcd4aa 100644 --- a/litestep/WinMain.cpp +++ b/litestep/WinMain.cpp @@ -277,59 +277,76 @@ int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE, LPTSTR lpCmdLine, int) wStartFlags &= ~LSF_RUN_STARTUPAPPS; } - if (wStartFlags & LSF_RUN_EXPLORER) + bool bLoop; + do { - // - // Mode 2: (Try to) start Explorer - // - if (StartExplorerShell(EXPLORER_WAIT_TIMEOUT)) - { - // Explorer started as shell, no need try LiteStep as well - wStartFlags &= ~LSF_RUN_LITESTEP; - } - else - { - wStartFlags &= ~LSF_RUN_EXPLORER; - } - } - - if (wStartFlags & LSF_RUN_LITESTEP) - { - HANDLE hMutex = NULL; + // Loop back here if explorer is requested as the shell + // while LiteStep is already running - if (IsOtherInstanceRunning(&hMutex)) + if (wStartFlags & LSF_RUN_EXPLORER) { // - // Mode 3a: Other LiteStep instance already running + // Mode 2: (Try to) start Explorer // - RESOURCE_STR(hInst, IDS_LITESTEP_ERROR1, - "A previous instance of LiteStep was detected.\n" - "Are you sure you want to continue?"); - - // Can show a MessageBox here since the other instance - // should have closed the welcome screen already - INT idConfirm = RESOURCE_MSGBOX_F( - "LiteStep", MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2); - - if (idConfirm == IDNO) + if (StartExplorerShell(EXPLORER_WAIT_TIMEOUT)) { + // Explorer started as shell, no need try LiteStep as well wStartFlags &= ~LSF_RUN_LITESTEP; } + else + { + wStartFlags &= ~LSF_RUN_EXPLORER; + } } if (wStartFlags & LSF_RUN_LITESTEP) { - // - // Mode 3b: Start the shell! - // - nReturn = StartLitestep(hInst, wStartFlags, szAltConfigFile); + HANDLE hMutex = NULL; + + if (IsOtherInstanceRunning(&hMutex)) + { + // + // Mode 3a: Other LiteStep instance already running + // + RESOURCE_STR(hInst, IDS_LITESTEP_ERROR1, + "A previous instance of LiteStep was detected.\n" + "Are you sure you want to continue?"); + + // Can show a MessageBox here since the other instance + // should have closed the welcome screen already + INT idConfirm = RESOURCE_MSGBOX_F( + "LiteStep", MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2); + + if (idConfirm == IDNO) + { + wStartFlags &= ~LSF_RUN_LITESTEP; + } + } + + if (wStartFlags & LSF_RUN_LITESTEP) + { + // + // Mode 3b: Start the shell! + // + nReturn = StartLitestep(hInst, wStartFlags, szAltConfigFile); + } + + if (hMutex) + { + CloseHandle(hMutex); + } } - if (hMutex) + bLoop = false; + + if ((nReturn == LRV_EXPLORER_START) && (wStartFlags & LSF_RUN_LITESTEP)) { - CloseHandle(hMutex); + // User wants Explorer as the shell anyway + wStartFlags |= LSF_RUN_EXPLORER; + bLoop = true; } } + while (bLoop); } return nReturn; diff --git a/litestep/litestep.cpp b/litestep/litestep.cpp index 78870ed..b5965a5 100644 --- a/litestep/litestep.cpp +++ b/litestep/litestep.cpp @@ -147,7 +147,7 @@ int StartLitestep(HINSTANCE hInst, WORD wStartFlags, LPCTSTR pszAltConfigFile) if (FAILED(GetAppPath(szAppPath, COUNTOF(szAppPath)))) { // something really crappy is going on. - return -1; + return LRV_NO_APP_PATH; } if (wStartFlags & LSF_ALTERNATE_CONFIG) @@ -195,7 +195,7 @@ int StartLitestep(HINSTANCE hInst, WORD wStartFlags, LPCTSTR pszAltConfigFile) RESOURCE_MSGBOX_F("LiteStep", MB_ICONERROR); - return 2; + return LRV_NO_STEP; } // Initialize the LSAPI. Note: The LSAPI controls the bang and settings @@ -205,7 +205,7 @@ int StartLitestep(HINSTANCE hInst, WORD wStartFlags, LPCTSTR pszAltConfigFile) RESOURCE_MSGBOX(hInst, IDS_LSAPI_INIT_ERROR, "Failed to initialize the LiteStep API.", "LiteStep"); - return 3; + return LRV_LSAPI_FAIL; } // All child processes get this variable @@ -906,6 +906,12 @@ LRESULT CLiteStep::InternalWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l PostQuitMessage(0); } break; + + case LR_EXPLORER: + { + PostQuitMessage(4); + } + break; default: // wParam == LR_MSSHUTDOWN { diff --git a/litestep/litestep.rc b/litestep/litestep.rc index 4eb04e3..853bf3c 100644 --- a/litestep/litestep.rc +++ b/litestep/litestep.rc @@ -210,6 +210,8 @@ BEGIN IDS_LITESTEP_RUN "&Run..." IDS_LITESTEP_SHUTDOWNWIN "Sh&utdown Windows..." IDS_MODULEQUIT_ERROR "Exception while quitting module." + IDS_LITESTEP_ABOUTLS "&About LiteStep" + IDS_LITESTEP_EXPLORER "&Start Explorer as shell" END STRINGTABLE diff --git a/litestep/resource.h b/litestep/resource.h index 91daa8b..523017b 100644 --- a/litestep/resource.h +++ b/litestep/resource.h @@ -29,6 +29,8 @@ #define IDS_MATHEXCEPTION 25 #define IDS_LSAPI_INIT_ERROR 26 #define IDS_LITESTEP_INIT_ERROR 27 +#define IDS_LITESTEP_ABOUTLS 28 +#define IDS_LITESTEP_EXPLORER 29 #define IDI_LS 101 #define IDB_LS 102 #define IDD_ABOUTBOX 103 diff --git a/lsapi/lsapidefines.h b/lsapi/lsapidefines.h index db77329..7c6eb95 100644 --- a/lsapi/lsapidefines.h +++ b/lsapi/lsapidefines.h @@ -233,6 +233,7 @@ typedef struct LSDESKTOPINFO #define LR_LOGOFF 1 #define LR_QUIT 2 #define LR_MSSHUTDOWN 3 +#define LR_EXPLORER 4 //----------------------------------------------------------------------------- diff --git a/utility/shellhlp.cpp b/utility/shellhlp.cpp index 0c919cd..9585aab 100644 --- a/utility/shellhlp.cpp +++ b/utility/shellhlp.cpp @@ -405,7 +405,7 @@ void LSShutdownDialog(HWND hWnd) (GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_MENU) & 0x8000)) { - PostQuitMessage(1); + PostQuitMessage(LRV_SHUTDOWN_DLG); } } } diff --git a/utility/shellhlp.h b/utility/shellhlp.h index 0284f49..13da5f8 100644 --- a/utility/shellhlp.h +++ b/utility/shellhlp.h @@ -68,6 +68,17 @@ HANDLE LSActivateActCtxForDll(LPCTSTR pszDll, PULONG_PTR pulCookie); HANDLE LSActivateActCtxForClsid(REFCLSID rclsid, PULONG_PTR pulCookie); void LSDeactivateActCtx(HANDLE hActCtx, ULONG_PTR* pulCookie); +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// +// Litestep Return Values (LRV) +// +#define LRV_NO_APP_PATH -1 +#define LRV_OK 0 // is also S_OK from WinError +#define LRV_SHUTDOWN_DLG 1 +#define LRV_NO_STEP 2 +#define LRV_LSAPI_FAIL 3 +#define LRV_EXPLORER_START 4 + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //