Download | Plain Text | Line Numbers
* new command "status" to display current status of an app
* new batch mode (environment BATCH=1) which enables different exit codes for
easier integration into scripts.
steamcmd will exit with exit code = 4 if an app needs updating (status command)
or an app has been updated (update command).
--- steamcmd.old/main.cpp 2012-08-26 00:00:12.000000000 +0200
+++ steamcmd/main.cpp 2012-08-27 17:23:36.000000000 +0200
@@ -7,6 +7,7 @@
#include <stdarg.h>
#include <math.h>
+#include <stdlib.h>
#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 @@
void ProgressMsg(const char* cszFormat, ...);
bool m_bWasProgressMsg;
unsigned int m_uLastProgressMsgSize;
+ bool m_batch;
CCommandLine commandLine;
@@ -140,6 +145,10 @@
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,7 +227,7 @@
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");
@@ -265,7 +274,7 @@
Msg("Up to date.\n", m_uInstallingAppId);
m_uInstallingAppId = k_uAppIdInvalid;
g_pClientAppManager->SetDownloadingEnabled(false);
- this->Exit(EXIT_SUCCESS);
+ this->Exit(EXIT_GAME_UPDATED);
}
}
}
@@ -389,14 +398,20 @@
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 @@
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)
@@ -728,6 +759,7 @@
" 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 <appid> - Game AppID to install / update / uninstall\n"
@@ -797,13 +829,14 @@
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)
{
@@ -829,6 +862,12 @@
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;
}