// CAvailableApplicationInfo
// 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
- if (GetStorageDirectory(m_szPath))
+ //FIXME: maybe provide a fallback?
+ if (m_szPath.IsEmpty() && GetStorageDirectory(m_szPath))
{
m_szAppsPath = m_szPath + L"\\rapps\\";
m_szCabPath = m_szPath + L"\\rappmgr.cab";
m_szSearchPath = m_szAppsPath + L"*.txt";
+ return TRUE;
}
+ return FALSE;
+}
+
+CAvailableApps::CAvailableApps()
+{
+ //set all paths
+ InitializeStaticStrings();
}
VOID CAvailableApps::FreeCachedEntries()
if (m_szPath.IsEmpty())
return;
- DeleteFileW(m_szCabPath.GetString());
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
} while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind);
}
+
+ RemoveDirectoryW(m_szAppsPath);
+ RemoveDirectoryW(m_szPath);
}
BOOL CAvailableApps::UpdateAppsDB()
{
- DeleteCurrentAppsDB();
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATAW FindFileData;
- CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
+ if (m_szPath.IsEmpty() && !InitializeStaticStrings())
+ {
+ return FALSE;
+ }
- if (m_szPath.IsEmpty())
+ 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);
if (!ExtractFilesFromCab(m_szCabPath, m_szAppsPath))
{
return FALSE;
}
+ DeleteFileW(m_szCabPath.GetString());
+
return TRUE;
}
+BOOL CAvailableApps::ForceUpdateAppsDB()
+{
+ DeleteCurrentAppsDB();
+ return UpdateAppsDB();
+}
+
BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
- if (!CreateDirectoryW(m_szPath.GetString(), NULL) &&
- GetLastError() != ERROR_ALREADY_EXISTS)
- {
- return FALSE;
- }
-
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
- if(!UpdateAppsDB()) {
- return FALSE;
- }
-
- hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
-
- if (hFind == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
+ //no db yet
+ return FALSE;
}
do
class CAvailableApps
{
ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList;
- ATL::CStringW m_szPath;
- ATL::CStringW m_szCabPath;
- ATL::CStringW m_szAppsPath;
- ATL::CStringW m_szSearchPath;
+ static ATL::CStringW m_szPath;
+ static ATL::CStringW m_szCabPath;
+ static ATL::CStringW m_szAppsPath;
+ static ATL::CStringW m_szSearchPath;
+
+ static BOOL InitializeStaticStrings();
public:
CAvailableApps();
+
+ static BOOL UpdateAppsDB();
+ static BOOL ForceUpdateAppsDB();
+
VOID FreeCachedEntries();
- VOID DeleteCurrentAppsDB();
- BOOL UpdateAppsDB();
+ static VOID DeleteCurrentAppsDB();
BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc);
const PAPPLICATION_INFO FindInfo(const ATL::CStringW& szAppName);
ATL::CSimpleArray<PAPPLICATION_INFO> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames);
HANDLE hMutex;
HACCEL KeyBrd;
MSG Msg;
+ BOOL bFirstLaunch;
InitializeAtlModule(hInstance, TRUE);
SetForegroundWindow(hWindow);
return 1;
}
-
- if (!LoadSettings())
+ bFirstLaunch = LoadSettings();
+ if (bFirstLaunch)
{
FillDefaultSettings(&SettingsInfo);
}
InitLogs();
InitCommonControls();
- //skip window creation if there were some keys
+ // skip window creation if there were some keys
if (!CmdParser(lpCmdLine))
{
+ if (SettingsInfo.bUpdateAtStart || bFirstLaunch)
+ CAvailableApps::ForceUpdateAppsDB();
+
hMainWnd = CreateMainWindow();
+
if (hMainWnd)
{
/* 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);
- //TODO: get around the ugliness
- if (SettingsInfo.bUpdateAtStart)
- GetAvailableApps()->UpdateAppsDB();
-
/* Load the menu hotkeys */
KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));