From ac192857f7a93654f1ac25eac1231f303c760e81 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 9 Mar 2013 15:36:07 +0100 Subject: add status command + batch mode --- main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index ea6bd0b..656d4ca 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "CCommandLine.h" @@ -21,6 +22,9 @@ #define strcasecmp _stricmp #endif +#define EXIT_GAME_UPDATED (1 << 2) +#define EXIT_UPDATE_RELEASED EXIT_GAME_UPDATED + IClientEngine* g_pClientEngine = NULL; IClientUser* g_pClientUser = NULL; IClientAppManager* g_pClientAppManager = NULL; @@ -63,6 +67,7 @@ private: void ProgressMsg(const char* cszFormat, ...); bool m_bWasProgressMsg; unsigned int m_uLastProgressMsgSize; + bool m_batch; CCommandLine commandLine; @@ -140,6 +145,10 @@ int CApplication::GetExitCode() void CApplication::Exit(int iCode) { + /* convert to failure/success exit codes only in non-batch mode (-autoupdate requirement) */ + if (!m_batch && iCode != EXIT_FAILURE) + iCode = EXIT_SUCCESS; + if(m_bWaitingForCredentials && g_pClientUser->BLoggedOn()) { Msg("Waiting for credentials to cache.\n"); @@ -218,13 +227,13 @@ void CApplication::OnLicensesUpdated(LicensesUpdated_t* pParam) ShowAvailableApps(); this->Exit(EXIT_SUCCESS); } - else if(strcasecmp(cszCommand, "update") == 0) + else if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "status") == 0) { Msg("Requesting appinfo update.\n"); AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); - if(!g_pClientApps->RequestAppInfoUpdate(&uAppId, 1, true)) + if(!g_pClientApps->RequestAppInfoUpdate(&uAppId, 1)) { Error("Failed to request appinfo update.\n"); this->Exit(EXIT_FAILURE); @@ -265,7 +274,7 @@ void CApplication::OnAppEventStateChange(AppEventStateChange_t* pParam) Msg("Up to date.\n", m_uInstallingAppId); m_uInstallingAppId = k_uAppIdInvalid; g_pClientAppManager->SetDownloadingEnabled(false); - this->Exit(EXIT_SUCCESS); + this->Exit(EXIT_GAME_UPDATED); } } } @@ -335,7 +344,7 @@ CApplication::EUpdateResult CApplication::InstallOrUpdateApp(AppId_t uAppId, boo if(eState == k_EAppStateInvalid || eState & k_EAppStateUninstalled) { Msg("Installing %u:%s ...\n", uAppId, GetAppName(uAppId)); - EAppUpdateError eError = g_pClientAppManager->InstallApp(uAppId, NULL, 0, false); + EAppUpdateError eError = g_pClientAppManager->InstallApp(uAppId, NULL, 0, false); //TODO if(eError != k_EAppErrorNone) { Error("Installation failed: %s\n", EAppUpdateError2String(eError)); @@ -389,14 +398,20 @@ CApplication::CApplication(int argc, char** argv) : m_bWasProgressMsg = false; m_uInstallingAppId = k_uAppIdInvalid; m_uUninstallingAppId = k_uAppIdInvalid; + + char *batch = getenv("BATCH"); + m_batch = (batch != NULL && strcmp(batch, "1") == 0); } void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) { - if(m_bWaitingForAppInfoUpdate && strcasecmp(commandLine.ParmValue("-command", ""), "update") == 0) - { - m_bWaitingForAppInfoUpdate = false; + if (!m_bWaitingForAppInfoUpdate) + return; + m_bWaitingForAppInfoUpdate = false; + const char* cszCommand = commandLine.ParmValue("-command"); + if(strcasecmp(cszCommand, "update") == 0) + { AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); bool bVerifyAll = commandLine.FindParm("-verify_all") != 0; @@ -406,6 +421,22 @@ void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) else if(eResult == k_EUpdateResultAlreadyUpToDate) this->Exit(EXIT_SUCCESS); } + else if(strcasecmp(cszCommand, "status") == 0) + { + AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); + + if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) + { + Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); + this->Exit(EXIT_FAILURE); + } + else + { + bool uptodate = g_pClientAppManager->BIsAppUpToDate(uAppId); + Msg("%u:%s %s\n", uAppId, GetAppName(uAppId), (uptodate) ? "is up to date" : "needs updating"); + this->Exit((uptodate) ? EXIT_SUCCESS : EXIT_UPDATE_RELEASED); + } + } } void CApplication::OnDisconnected(SteamServersDisconnected_t* pParam) @@ -722,6 +753,7 @@ bool CApplication::CheckCommandline() " update: Install or update a game\n" " uninstall: Remove a game\n" " list: View available games and their status\n" + " status: View status of a game\n" "\n" "Parameters:\n" " -game - Game AppID to install / update / uninstall\n" @@ -791,13 +823,14 @@ bool CApplication::CheckCommandline() return false; } - if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0) + if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0 + && strcasecmp(cszCommand, "status") != 0) { Error("Invalid command specified.\n"); return false; } - if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0) + if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0 || strcasecmp(cszCommand, "status") == 0) { if(commandLine.FindParm("-game") == 0) { @@ -817,6 +850,12 @@ bool CApplication::CheckCommandline() return false; } + if (m_batch && commandLine.FindParm("-autoupdate") != 0) + { + Msg("Batch mode and -autoupdate is mutually exclusive. Disabling batch mode...\n"); + m_batch = false; + } + return true; } -- cgit v1.2.3