Changes in the update process:
- Made UpdateAppsDB() functions static and added ForceUpdateAppsDB()
- EnumAvailableApplications() doesn't update DB on it's own
- Force updating now done only if bUpdateAtStart set or if no settings loaded (first run)
- Minor cleanup

svn path=/branches/GSoC_2017/rapps/; revision=75662
This commit is contained in:
Alexander Shaposhnikov 2017-08-24 22:04:44 +00:00
parent f65f506032
commit aa15934f23
6 changed files with 70 additions and 40 deletions

View file

@ -201,15 +201,28 @@ inline BOOL CAvailableApplicationInfo::GetString(LPCWSTR lpKeyName, ATL::CString
// CAvailableApplicationInfo // CAvailableApplicationInfo
// CAvailableApps // CAvailableApps
CAvailableApps::CAvailableApps() ATL::CStringW CAvailableApps::m_szPath;
ATL::CStringW CAvailableApps::m_szCabPath;
ATL::CStringW CAvailableApps::m_szAppsPath;
ATL::CStringW CAvailableApps::m_szSearchPath;
BOOL CAvailableApps::InitializeStaticStrings()
{ {
//set all paths //FIXME: maybe provide a fallback?
if (GetStorageDirectory(m_szPath)) if (m_szPath.IsEmpty() && GetStorageDirectory(m_szPath))
{ {
m_szAppsPath = m_szPath + L"\\rapps\\"; m_szAppsPath = m_szPath + L"\\rapps\\";
m_szCabPath = m_szPath + L"\\rappmgr.cab"; m_szCabPath = m_szPath + L"\\rappmgr.cab";
m_szSearchPath = m_szAppsPath + L"*.txt"; m_szSearchPath = m_szAppsPath + L"*.txt";
return TRUE;
} }
return FALSE;
}
CAvailableApps::CAvailableApps()
{
//set all paths
InitializeStaticStrings();
} }
VOID CAvailableApps::FreeCachedEntries() VOID CAvailableApps::FreeCachedEntries()
@ -235,7 +248,6 @@ VOID CAvailableApps::DeleteCurrentAppsDB()
if (m_szPath.IsEmpty()) if (m_szPath.IsEmpty())
return; return;
DeleteFileW(m_szCabPath.GetString());
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData); hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind != INVALID_HANDLE_VALUE) if (hFind != INVALID_HANDLE_VALUE)
@ -248,50 +260,62 @@ VOID CAvailableApps::DeleteCurrentAppsDB()
} while (FindNextFileW(hFind, &FindFileData) != 0); } while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind); FindClose(hFind);
} }
RemoveDirectoryW(m_szAppsPath);
RemoveDirectoryW(m_szPath);
} }
BOOL CAvailableApps::UpdateAppsDB() BOOL CAvailableApps::UpdateAppsDB()
{ {
DeleteCurrentAppsDB(); HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
if (m_szPath.IsEmpty() && !InitializeStaticStrings())
{
return FALSE;
}
if (!CreateDirectoryW(m_szPath.GetString(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
{
return FALSE;
}
//if there are some files in the db folder - we're good
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
return TRUE;
}
CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL); CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
if (m_szPath.IsEmpty())
return FALSE;
if (!ExtractFilesFromCab(m_szCabPath, m_szAppsPath)) if (!ExtractFilesFromCab(m_szCabPath, m_szAppsPath))
{ {
return FALSE; return FALSE;
} }
DeleteFileW(m_szCabPath.GetString());
return TRUE; return TRUE;
} }
BOOL CAvailableApps::ForceUpdateAppsDB()
{
DeleteCurrentAppsDB();
return UpdateAppsDB();
}
BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc) BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
{ {
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData; WIN32_FIND_DATAW FindFileData;
if (!CreateDirectoryW(m_szPath.GetString(), NULL) &&
GetLastError() != ERROR_ALREADY_EXISTS)
{
return FALSE;
}
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData); hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
if(!UpdateAppsDB()) { //no db yet
return FALSE; return FALSE;
}
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
return FALSE;
}
} }
do do

View file

@ -1321,7 +1321,7 @@ private:
break; break;
case ID_RESETDB: case ID_RESETDB:
m_AvailableApps.UpdateAppsDB(); CAvailableApps::ForceUpdateAppsDB();
UpdateApplicationsList(-1); UpdateApplicationsList(-1);
break; break;

View file

@ -107,16 +107,21 @@ private:
class CAvailableApps class CAvailableApps
{ {
ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList; ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList;
ATL::CStringW m_szPath; static ATL::CStringW m_szPath;
ATL::CStringW m_szCabPath; static ATL::CStringW m_szCabPath;
ATL::CStringW m_szAppsPath; static ATL::CStringW m_szAppsPath;
ATL::CStringW m_szSearchPath; static ATL::CStringW m_szSearchPath;
static BOOL InitializeStaticStrings();
public: public:
CAvailableApps(); CAvailableApps();
static BOOL UpdateAppsDB();
static BOOL ForceUpdateAppsDB();
VOID FreeCachedEntries(); VOID FreeCachedEntries();
VOID DeleteCurrentAppsDB(); static VOID DeleteCurrentAppsDB();
BOOL UpdateAppsDB();
BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc); BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc);
const PAPPLICATION_INFO FindInfo(const ATL::CStringW& szAppName); const PAPPLICATION_INFO FindInfo(const ATL::CStringW& szAppName);
ATL::CSimpleArray<PAPPLICATION_INFO> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames); ATL::CSimpleArray<PAPPLICATION_INFO> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames);

View file

@ -565,7 +565,6 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
continue; continue;
} }
// build the path for the download // build the path for the download
p = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'/'); p = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'/');
q = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'?'); q = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'?');

View file

@ -56,6 +56,7 @@ BOOL CmdParser(LPWSTR lpCmdLine)
} }
CAvailableApps apps; CAvailableApps apps;
CAvailableApps::UpdateAppsDB();
apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL); apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL);
ATL::CSimpleArray<PAPPLICATION_INFO> arrAppInfo = apps.FindInfoList(arrNames); ATL::CSimpleArray<PAPPLICATION_INFO> arrAppInfo = apps.FindInfoList(arrNames);
if (arrAppInfo.GetSize() > 0) if (arrAppInfo.GetSize() > 0)

View file

@ -128,6 +128,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
HANDLE hMutex; HANDLE hMutex;
HACCEL KeyBrd; HACCEL KeyBrd;
MSG Msg; MSG Msg;
BOOL bFirstLaunch;
InitializeAtlModule(hInstance, TRUE); InitializeAtlModule(hInstance, TRUE);
@ -149,8 +150,8 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
SetForegroundWindow(hWindow); SetForegroundWindow(hWindow);
return 1; return 1;
} }
bFirstLaunch = LoadSettings();
if (!LoadSettings()) if (bFirstLaunch)
{ {
FillDefaultSettings(&SettingsInfo); FillDefaultSettings(&SettingsInfo);
} }
@ -158,20 +159,20 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
InitLogs(); InitLogs();
InitCommonControls(); InitCommonControls();
//skip window creation if there were some keys // skip window creation if there were some keys
if (!CmdParser(lpCmdLine)) if (!CmdParser(lpCmdLine))
{ {
if (SettingsInfo.bUpdateAtStart || bFirstLaunch)
CAvailableApps::ForceUpdateAppsDB();
hMainWnd = CreateMainWindow(); hMainWnd = CreateMainWindow();
if (hMainWnd) if (hMainWnd)
{ {
/* Maximize it if we must */ /* Maximize it if we must */
ShowWindow(hMainWnd, (SettingsInfo.bSaveWndPos && SettingsInfo.Maximized ? SW_MAXIMIZE : nShowCmd)); ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
UpdateWindow(hMainWnd); UpdateWindow(hMainWnd);
//TODO: get around the ugliness
if (SettingsInfo.bUpdateAtStart)
GetAvailableApps()->UpdateAppsDB();
/* Load the menu hotkeys */ /* Load the menu hotkeys */
KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS)); KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));