diff options
| author | manuel <manuel@mausz.at> | 2013-03-09 15:36:07 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-03-09 15:36:07 +0100 |
| commit | ac192857f7a93654f1ac25eac1231f303c760e81 (patch) | |
| tree | 82da52de5c66e12f9d620dc0f55351b090a9a6af | |
| parent | 311378cdf120ac8f6cedb85a746506d2d2ea6589 (diff) | |
| download | steamcmd-ac192857f7a93654f1ac25eac1231f303c760e81.tar.gz steamcmd-ac192857f7a93654f1ac25eac1231f303c760e81.tar.bz2 steamcmd-ac192857f7a93654f1ac25eac1231f303c760e81.zip | |
add status command + batch mode
| -rw-r--r-- | main.cpp | 57 |
1 files changed, 48 insertions, 9 deletions
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include <stdarg.h> | 8 | #include <stdarg.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| 10 | #include <stdlib.h> | ||
| 10 | 11 | ||
| 11 | #include "CCommandLine.h" | 12 | #include "CCommandLine.h" |
| 12 | 13 | ||
| @@ -21,6 +22,9 @@ | |||
| 21 | #define strcasecmp _stricmp | 22 | #define strcasecmp _stricmp |
| 22 | #endif | 23 | #endif |
| 23 | 24 | ||
| 25 | #define EXIT_GAME_UPDATED (1 << 2) | ||
| 26 | #define EXIT_UPDATE_RELEASED EXIT_GAME_UPDATED | ||
| 27 | |||
| 24 | IClientEngine* g_pClientEngine = NULL; | 28 | IClientEngine* g_pClientEngine = NULL; |
| 25 | IClientUser* g_pClientUser = NULL; | 29 | IClientUser* g_pClientUser = NULL; |
| 26 | IClientAppManager* g_pClientAppManager = NULL; | 30 | IClientAppManager* g_pClientAppManager = NULL; |
| @@ -63,6 +67,7 @@ private: | |||
| 63 | void ProgressMsg(const char* cszFormat, ...); | 67 | void ProgressMsg(const char* cszFormat, ...); |
| 64 | bool m_bWasProgressMsg; | 68 | bool m_bWasProgressMsg; |
| 65 | unsigned int m_uLastProgressMsgSize; | 69 | unsigned int m_uLastProgressMsgSize; |
| 70 | bool m_batch; | ||
| 66 | 71 | ||
| 67 | CCommandLine commandLine; | 72 | CCommandLine commandLine; |
| 68 | 73 | ||
| @@ -140,6 +145,10 @@ int CApplication::GetExitCode() | |||
| 140 | 145 | ||
| 141 | void CApplication::Exit(int iCode) | 146 | void CApplication::Exit(int iCode) |
| 142 | { | 147 | { |
| 148 | /* convert to failure/success exit codes only in non-batch mode (-autoupdate requirement) */ | ||
| 149 | if (!m_batch && iCode != EXIT_FAILURE) | ||
| 150 | iCode = EXIT_SUCCESS; | ||
| 151 | |||
| 143 | if(m_bWaitingForCredentials && g_pClientUser->BLoggedOn()) | 152 | if(m_bWaitingForCredentials && g_pClientUser->BLoggedOn()) |
| 144 | { | 153 | { |
| 145 | Msg("Waiting for credentials to cache.\n"); | 154 | Msg("Waiting for credentials to cache.\n"); |
| @@ -218,13 +227,13 @@ void CApplication::OnLicensesUpdated(LicensesUpdated_t* pParam) | |||
| 218 | ShowAvailableApps(); | 227 | ShowAvailableApps(); |
| 219 | this->Exit(EXIT_SUCCESS); | 228 | this->Exit(EXIT_SUCCESS); |
| 220 | } | 229 | } |
| 221 | else if(strcasecmp(cszCommand, "update") == 0) | 230 | else if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "status") == 0) |
| 222 | { | 231 | { |
| 223 | Msg("Requesting appinfo update.\n"); | 232 | Msg("Requesting appinfo update.\n"); |
| 224 | 233 | ||
| 225 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); | 234 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); |
| 226 | 235 | ||
| 227 | if(!g_pClientApps->RequestAppInfoUpdate(&uAppId, 1, true)) | 236 | if(!g_pClientApps->RequestAppInfoUpdate(&uAppId, 1)) |
| 228 | { | 237 | { |
| 229 | Error("Failed to request appinfo update.\n"); | 238 | Error("Failed to request appinfo update.\n"); |
| 230 | this->Exit(EXIT_FAILURE); | 239 | this->Exit(EXIT_FAILURE); |
| @@ -265,7 +274,7 @@ void CApplication::OnAppEventStateChange(AppEventStateChange_t* pParam) | |||
| 265 | Msg("Up to date.\n", m_uInstallingAppId); | 274 | Msg("Up to date.\n", m_uInstallingAppId); |
| 266 | m_uInstallingAppId = k_uAppIdInvalid; | 275 | m_uInstallingAppId = k_uAppIdInvalid; |
| 267 | g_pClientAppManager->SetDownloadingEnabled(false); | 276 | g_pClientAppManager->SetDownloadingEnabled(false); |
| 268 | this->Exit(EXIT_SUCCESS); | 277 | this->Exit(EXIT_GAME_UPDATED); |
| 269 | } | 278 | } |
| 270 | } | 279 | } |
| 271 | } | 280 | } |
| @@ -335,7 +344,7 @@ CApplication::EUpdateResult CApplication::InstallOrUpdateApp(AppId_t uAppId, boo | |||
| 335 | if(eState == k_EAppStateInvalid || eState & k_EAppStateUninstalled) | 344 | if(eState == k_EAppStateInvalid || eState & k_EAppStateUninstalled) |
| 336 | { | 345 | { |
| 337 | Msg("Installing %u:%s ...\n", uAppId, GetAppName(uAppId)); | 346 | Msg("Installing %u:%s ...\n", uAppId, GetAppName(uAppId)); |
| 338 | EAppUpdateError eError = g_pClientAppManager->InstallApp(uAppId, NULL, 0, false); | 347 | EAppUpdateError eError = g_pClientAppManager->InstallApp(uAppId, NULL, 0, false); //TODO |
| 339 | if(eError != k_EAppErrorNone) | 348 | if(eError != k_EAppErrorNone) |
| 340 | { | 349 | { |
| 341 | Error("Installation failed: %s\n", EAppUpdateError2String(eError)); | 350 | Error("Installation failed: %s\n", EAppUpdateError2String(eError)); |
| @@ -389,14 +398,20 @@ CApplication::CApplication(int argc, char** argv) : | |||
| 389 | m_bWasProgressMsg = false; | 398 | m_bWasProgressMsg = false; |
| 390 | m_uInstallingAppId = k_uAppIdInvalid; | 399 | m_uInstallingAppId = k_uAppIdInvalid; |
| 391 | m_uUninstallingAppId = k_uAppIdInvalid; | 400 | m_uUninstallingAppId = k_uAppIdInvalid; |
| 401 | |||
| 402 | char *batch = getenv("BATCH"); | ||
| 403 | m_batch = (batch != NULL && strcmp(batch, "1") == 0); | ||
| 392 | } | 404 | } |
| 393 | 405 | ||
| 394 | void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) | 406 | void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) |
| 395 | { | 407 | { |
| 396 | if(m_bWaitingForAppInfoUpdate && strcasecmp(commandLine.ParmValue("-command", ""), "update") == 0) | 408 | if (!m_bWaitingForAppInfoUpdate) |
| 397 | { | 409 | return; |
| 398 | m_bWaitingForAppInfoUpdate = false; | 410 | m_bWaitingForAppInfoUpdate = false; |
| 399 | 411 | ||
| 412 | const char* cszCommand = commandLine.ParmValue("-command"); | ||
| 413 | if(strcasecmp(cszCommand, "update") == 0) | ||
| 414 | { | ||
| 400 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); | 415 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); |
| 401 | 416 | ||
| 402 | bool bVerifyAll = commandLine.FindParm("-verify_all") != 0; | 417 | bool bVerifyAll = commandLine.FindParm("-verify_all") != 0; |
| @@ -406,6 +421,22 @@ void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) | |||
| 406 | else if(eResult == k_EUpdateResultAlreadyUpToDate) | 421 | else if(eResult == k_EUpdateResultAlreadyUpToDate) |
| 407 | this->Exit(EXIT_SUCCESS); | 422 | this->Exit(EXIT_SUCCESS); |
| 408 | } | 423 | } |
| 424 | else if(strcasecmp(cszCommand, "status") == 0) | ||
| 425 | { | ||
| 426 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); | ||
| 427 | |||
| 428 | if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) | ||
| 429 | { | ||
| 430 | Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); | ||
| 431 | this->Exit(EXIT_FAILURE); | ||
| 432 | } | ||
| 433 | else | ||
| 434 | { | ||
| 435 | bool uptodate = g_pClientAppManager->BIsAppUpToDate(uAppId); | ||
| 436 | Msg("%u:%s %s\n", uAppId, GetAppName(uAppId), (uptodate) ? "is up to date" : "needs updating"); | ||
| 437 | this->Exit((uptodate) ? EXIT_SUCCESS : EXIT_UPDATE_RELEASED); | ||
| 438 | } | ||
| 439 | } | ||
| 409 | } | 440 | } |
| 410 | 441 | ||
| 411 | void CApplication::OnDisconnected(SteamServersDisconnected_t* pParam) | 442 | void CApplication::OnDisconnected(SteamServersDisconnected_t* pParam) |
| @@ -722,6 +753,7 @@ bool CApplication::CheckCommandline() | |||
| 722 | " update: Install or update a game\n" | 753 | " update: Install or update a game\n" |
| 723 | " uninstall: Remove a game\n" | 754 | " uninstall: Remove a game\n" |
| 724 | " list: View available games and their status\n" | 755 | " list: View available games and their status\n" |
| 756 | " status: View status of a game\n" | ||
| 725 | "\n" | 757 | "\n" |
| 726 | "Parameters:\n" | 758 | "Parameters:\n" |
| 727 | " -game <appid> - Game AppID to install / update / uninstall\n" | 759 | " -game <appid> - Game AppID to install / update / uninstall\n" |
| @@ -791,13 +823,14 @@ bool CApplication::CheckCommandline() | |||
| 791 | return false; | 823 | return false; |
| 792 | } | 824 | } |
| 793 | 825 | ||
| 794 | if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0) | 826 | if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0 |
| 827 | && strcasecmp(cszCommand, "status") != 0) | ||
| 795 | { | 828 | { |
| 796 | Error("Invalid command specified.\n"); | 829 | Error("Invalid command specified.\n"); |
| 797 | return false; | 830 | return false; |
| 798 | } | 831 | } |
| 799 | 832 | ||
| 800 | if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0) | 833 | if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0 || strcasecmp(cszCommand, "status") == 0) |
| 801 | { | 834 | { |
| 802 | if(commandLine.FindParm("-game") == 0) | 835 | if(commandLine.FindParm("-game") == 0) |
| 803 | { | 836 | { |
| @@ -817,6 +850,12 @@ bool CApplication::CheckCommandline() | |||
| 817 | return false; | 850 | return false; |
| 818 | } | 851 | } |
| 819 | 852 | ||
| 853 | if (m_batch && commandLine.FindParm("-autoupdate") != 0) | ||
| 854 | { | ||
| 855 | Msg("Batch mode and -autoupdate is mutually exclusive. Disabling batch mode...\n"); | ||
| 856 | m_batch = false; | ||
| 857 | } | ||
| 858 | |||
| 820 | return true; | 859 | return true; |
| 821 | } | 860 | } |
| 822 | 861 | ||
