From 69d1dbb37111960539e1dff817660403596438d0 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Mon, 14 Aug 2017 17:00:20 +0000 Subject: [PATCH] [RAPPS] - Added /SETUP key support TODO: use the short names from db files - Some style changes - Conditional creation of the dialogs svn path=/branches/GSoC_2017/rapps/; revision=75542 --- reactos/base/applications/rapps/available.cpp | 28 +++++++- reactos/base/applications/rapps/gui.cpp | 14 ++-- .../applications/rapps/include/available.h | 63 +++++++++-------- .../base/applications/rapps/include/dialogs.h | 4 +- .../base/applications/rapps/installdlg.cpp | 2 +- reactos/base/applications/rapps/loaddlg.cpp | 29 +++++--- reactos/base/applications/rapps/winmain.cpp | 70 +++++++++++-------- 7 files changed, 131 insertions(+), 79 deletions(-) diff --git a/reactos/base/applications/rapps/available.cpp b/reactos/base/applications/rapps/available.cpp index 210a16375ca..0ae86ac4510 100644 --- a/reactos/base/applications/rapps/available.cpp +++ b/reactos/base/applications/rapps/available.cpp @@ -292,12 +292,13 @@ BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnu CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL); } - ExtractFilesFromCab(m_szCabPath, m_szAppsPath); hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) + { return FALSE; + } } do @@ -348,8 +349,8 @@ skip_if_cached: Info->RefreshAppInfo(); - if (!lpEnumProc(static_cast(Info), m_szAppsPath.GetString())) - break; + if (lpEnumProc) + lpEnumProc(static_cast(Info), m_szAppsPath.GetString()); } while (FindNextFileW(hFind, &FindFileData) != 0); @@ -357,6 +358,27 @@ skip_if_cached: return TRUE; } +const PAPPLICATION_INFO CAvailableApps::FindInfo(const ATL::CStringW& szAppName) +{ + if (m_InfoList.IsEmpty()) + { + return NULL; + } + + // linear search + POSITION CurrentListPosition = m_InfoList.GetHeadPosition(); + PAPPLICATION_INFO info; + while (CurrentListPosition != NULL) + { + info = m_InfoList.GetNext(CurrentListPosition); + if (info->szName == szAppName) + { + return info; + } + } + return NULL; +} + const ATL::CStringW & CAvailableApps::GetFolderPath() { return m_szPath; diff --git a/reactos/base/applications/rapps/gui.cpp b/reactos/base/applications/rapps/gui.cpp index f9e0767c63f..ca88fb07ae3 100644 --- a/reactos/base/applications/rapps/gui.cpp +++ b/reactos/base/applications/rapps/gui.cpp @@ -1053,7 +1053,7 @@ private: { if (IS_INSTALLED_ENUM(SelectedEnumType)) ShowInstalledAppInfo(ItemIndex); - if (IS_AVAILABLE_ENUM(SelectedEnumType)) + if (isAvailableEnum(SelectedEnumType)) CAvailableAppView::ShowAvailableAppInfo(ItemIndex); } /* Check if the item is checked */ @@ -1081,7 +1081,7 @@ private: { if (IS_INSTALLED_ENUM(SelectedEnumType)) ShowInstalledAppInfo(-1); - if (IS_AVAILABLE_ENUM(SelectedEnumType)) + if (isAvailableEnum(SelectedEnumType)) CAvailableAppView::ShowAvailableAppInfo(-1); } } @@ -1463,7 +1463,9 @@ private: if (EnumType < 0) EnumType = SelectedEnumType; if (IS_INSTALLED_ENUM(SelectedEnumType)) + { FreeInstalledAppList(); + } m_ListView->DeleteAllItems(); @@ -1478,21 +1480,21 @@ private: ImageList_Destroy(hImageListBuf); } - if (IS_AVAILABLE_ENUM(EnumType)) + if (isAvailableEnum(EnumType)) { /* Enum available applications */ m_AvailableApps.EnumAvailableApplications(EnumType, s_EnumAvailableAppProc); } SelectedEnumType = EnumType; - UpdateStatusBarText(); - SetWelcomeText(); - /* set automatic column width for program names if the list is not empty */ + /* Set automatic column width for program names if the list is not empty */ if (m_ListView->GetItemCount() > 0) + { ListView_SetColumnWidth(m_ListView->GetWindow(), 0, LVSCW_AUTOSIZE); + } bUpdating = FALSE; m_ListView->SetRedraw(TRUE); diff --git a/reactos/base/applications/rapps/include/available.h b/reactos/base/applications/rapps/include/available.h index c351dc17062..5221e762095 100644 --- a/reactos/base/applications/rapps/include/available.h +++ b/reactos/base/applications/rapps/include/available.h @@ -5,29 +5,34 @@ #include /* EnumType flags for EnumAvailableApplications */ -#define ENUM_ALL_AVAILABLE 0 -#define ENUM_CAT_AUDIO 1 -#define ENUM_CAT_VIDEO 2 -#define ENUM_CAT_GRAPHICS 3 -#define ENUM_CAT_GAMES 4 -#define ENUM_CAT_INTERNET 5 -#define ENUM_CAT_OFFICE 6 -#define ENUM_CAT_DEVEL 7 -#define ENUM_CAT_EDU 8 -#define ENUM_CAT_ENGINEER 9 -#define ENUM_CAT_FINANCE 10 -#define ENUM_CAT_SCIENCE 11 -#define ENUM_CAT_TOOLS 12 -#define ENUM_CAT_DRIVERS 13 -#define ENUM_CAT_LIBS 14 -#define ENUM_CAT_OTHER 15 - -#define ENUM_AVAILABLE_MIN ENUM_ALL_AVAILABLE -#define ENUM_AVAILABLE_MAX ENUM_CAT_OTHER - -#define IS_AVAILABLE_ENUM(a) (a >= ENUM_AVAILABLE_MIN && a <= ENUM_AVAILABLE_MAX) - -typedef enum +enum AvailableCategories +{ + ENUM_ALL_AVAILABLE, + ENUM_CAT_AUDIO, + ENUM_CAT_VIDEO, + ENUM_CAT_GRAPHICS, + ENUM_CAT_GAMES, + ENUM_CAT_INTERNET, + ENUM_CAT_OFFICE, + ENUM_CAT_DEVEL, + ENUM_CAT_EDU, + ENUM_CAT_ENGINEER, + ENUM_CAT_FINANCE, + ENUM_CAT_SCIENCE, + ENUM_CAT_TOOLS, + ENUM_CAT_DRIVERS, + ENUM_CAT_LIBS, + ENUM_CAT_OTHER, + ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE, + ENUM_AVAILABLE_MAX = ENUM_CAT_OTHER +}; + +inline BOOL isAvailableEnum(INT x) +{ + return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX); +} + +typedef enum LICENSE_TYPE { None, OpenSource, @@ -35,7 +40,7 @@ typedef enum Trial, Max = Trial, Min = None -} LICENSE_TYPE, *PLICENSE_TYPE; +} *PLICENSE_TYPE; class CConfigParser { @@ -62,7 +67,7 @@ public: UINT GetInt(const ATL::CStringW& KeyName); }; -typedef struct +typedef struct APPLICATION_INFO { INT Category; LICENSE_TYPE LicenseType; @@ -84,9 +89,7 @@ typedef struct // Optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form) ATL::CStringW szSHA1; -} APPLICATION_INFO, *PAPPLICATION_INFO; - -extern ATL::CAtlList InfoList; +} *PAPPLICATION_INFO; typedef BOOL(CALLBACK *AVAILENUMPROC)(PAPPLICATION_INFO Info, LPCWSTR szFolderPath); @@ -113,8 +116,7 @@ private: BOOL m_HasInstalledVersion = FALSE; CConfigParser m_Parser; - inline BOOL GetString(LPCWSTR lpKeyName, - ATL::CStringW& ReturnedString); + inline BOOL GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString); // Lazily load general info from the file VOID RetrieveGeneralInfo(); @@ -139,6 +141,7 @@ public: BOOL DeleteCurrentAppsDB(); BOOL UpdateAppsDB(); BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc); + const PAPPLICATION_INFO FindInfo(const ATL::CStringW& szAppName); const ATL::CStringW& GetFolderPath(); const ATL::CStringW& GetAppPath(); const ATL::CStringW& GetCabPath(); diff --git a/reactos/base/applications/rapps/include/dialogs.h b/reactos/base/applications/rapps/include/dialogs.h index db0e218d029..e90d351c1b1 100644 --- a/reactos/base/applications/rapps/include/dialogs.h +++ b/reactos/base/applications/rapps/include/dialogs.h @@ -26,9 +26,9 @@ public: static DWORD WINAPI ThreadFunc(LPVOID Context); static BOOL DownloadListOfApplications(const ATL::CSimpleArray& AppsList); - static BOOL DownloadApplication(PAPPLICATION_INFO pAppInfo); + static BOOL DownloadApplication(PAPPLICATION_INFO pAppInfo, BOOL modal = FALSE); static VOID DownloadApplicationsDB(LPCWSTR lpUrl); - static VOID LaunchDownloadDialog(); + static VOID LaunchDownloadDialog(BOOL); }; // Settings dialog (settingsdlg.cpp) diff --git a/reactos/base/applications/rapps/installdlg.cpp b/reactos/base/applications/rapps/installdlg.cpp index b80210d9832..08e1665c624 100644 --- a/reactos/base/applications/rapps/installdlg.cpp +++ b/reactos/base/applications/rapps/installdlg.cpp @@ -42,7 +42,7 @@ InstallDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) BOOL InstallApplication(INT Index) { - if (!IS_AVAILABLE_ENUM(SelectedEnumType)) + if (!isAvailableEnum(SelectedEnumType)) return FALSE; AppInfo = (PAPPLICATION_INFO) ListViewGetlParam(Index); diff --git a/reactos/base/applications/rapps/loaddlg.cpp b/reactos/base/applications/rapps/loaddlg.cpp index fdab59b95b9..564fda5e2d6 100644 --- a/reactos/base/applications/rapps/loaddlg.cpp +++ b/reactos/base/applications/rapps/loaddlg.cpp @@ -401,7 +401,7 @@ INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM w ShowWindow(Dlg, SW_SHOW); - //Start new download + // Start new download SendMessageW(Dlg, DL_START_NEW, 0, 0); return TRUE; @@ -804,12 +804,12 @@ BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArrayszDownloadDir, + ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString(), szDownloadDir.GetLength() + 1); @@ -119,13 +119,13 @@ VOID SaveSettings(HWND hwnd) SettingsInfo.Top = wp.rcNormalPosition.top; SettingsInfo.Width = wp.rcNormalPosition.right - wp.rcNormalPosition.left; SettingsInfo.Height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; - SettingsInfo.Maximized = (wp.showCmd == SW_MAXIMIZE - || (wp.showCmd == SW_SHOWMINIMIZED + SettingsInfo.Maximized = (wp.showCmd == SW_MAXIMIZE + || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED))); } if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL, - REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) == ERROR_SUCCESS) + REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) == ERROR_SUCCESS) { RegKey.SetBinaryValue(L"Settings", (const PVOID) &SettingsInfo, sizeof(SettingsInfo)); RegKey.Close(); @@ -133,28 +133,38 @@ VOID SaveSettings(HWND hwnd) } -#define CMD_KEY_SETUP L"//SETUP" +#define CMD_KEY_SETUP L"/SETUP" -VOID CmdParser(LPWSTR lpCmdLine) +// return TRUE if the SETUP key was valid +BOOL CmdParser(LPWSTR lpCmdLine) { INT argc; LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc); - if (!argv || argc < 2) + CAvailableApps apps; + PAPPLICATION_INFO appInfo; + ATL::CString szName; + + if (!argv || argc < 2 || StrCmpW(argv[0], CMD_KEY_SETUP)) { - return; + return FALSE; } - - if (!StrCmpW(argv[0], CMD_KEY_SETUP)) + + apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL); + appInfo = apps.FindInfo(argv[1]); + if (appInfo) { - //TODO: call cmd app installation + CDownloadManager::DownloadApplication(appInfo, TRUE); + return TRUE; } + + return FALSE; } INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { LPCWSTR szWindowClass = L"ROSAPPMGR"; HANDLE hMutex = NULL; - HACCEL KeyBrd; + HACCEL KeyBrd = NULL; MSG Msg; InitializeAtlModule(hInstance, TRUE); @@ -187,27 +197,31 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi InitCommonControls(); - hMainWnd = CreateMainWindow(); - if (hMainWnd) + //skip window creation if there were some keys + if (!CmdParser(lpCmdLine)) { - /* Maximize it if we must */ - ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd)); - UpdateWindow(hMainWnd); + hMainWnd = CreateMainWindow(); + if (hMainWnd) + { + /* Maximize it if we must */ + ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd)); + UpdateWindow(hMainWnd); - //TODO: get around the ugliness - if (SettingsInfo.bUpdateAtStart) - GetAvailableApps()->UpdateAppsDB(); + //TODO: get around the ugliness + if (SettingsInfo.bUpdateAtStart) + GetAvailableApps()->UpdateAppsDB(); - /* Load the menu hotkeys */ - KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS)); + /* Load the menu hotkeys */ + KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS)); - /* Message Loop */ - while (GetMessageW(&Msg, NULL, 0, 0)) - { - if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg)) + /* Message Loop */ + while (GetMessageW(&Msg, NULL, 0, 0)) { - TranslateMessage(&Msg); - DispatchMessageW(&Msg); + if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg)) + { + TranslateMessage(&Msg); + DispatchMessageW(&Msg); + } } } } -- 2.17.1