Download | Plain Text | No Line Numbers


  1. * new command "status" to display current status of an app
  2. * new batch mode (environment BATCH=1) which enables different exit codes for
  3. easier integration into scripts.
  4. steamcmd will exit with exit code = 4 if an app needs updating (status command)
  5. or an app has been updated (update command).
  6. --- steamcmd.old/main.cpp 2012-08-26 00:00:12.000000000 +0200
  7. +++ steamcmd/main.cpp 2012-08-27 17:23:36.000000000 +0200
  8. @@ -7,6 +7,7 @@
  9.  
  10. #include <stdarg.h>
  11. #include <math.h>
  12. +#include <stdlib.h>
  13.  
  14. #include "CCommandLine.h"
  15.  
  16. @@ -21,6 +22,9 @@
  17. #define strcasecmp _stricmp
  18. #endif
  19.  
  20. +#define EXIT_GAME_UPDATED (1 << 2)
  21. +#define EXIT_UPDATE_RELEASED EXIT_GAME_UPDATED
  22. +
  23. IClientEngine* g_pClientEngine = NULL;
  24. IClientUser* g_pClientUser = NULL;
  25. IClientAppManager* g_pClientAppManager = NULL;
  26. @@ -63,6 +67,7 @@
  27. void ProgressMsg(const char* cszFormat, ...);
  28. bool m_bWasProgressMsg;
  29. unsigned int m_uLastProgressMsgSize;
  30. + bool m_batch;
  31.  
  32. CCommandLine commandLine;
  33.  
  34. @@ -140,6 +145,10 @@
  35.  
  36. void CApplication::Exit(int iCode)
  37. {
  38. + /* convert to failure/success exit codes only in non-batch mode (-autoupdate requirement) */
  39. + if (!m_batch && iCode != EXIT_FAILURE)
  40. + iCode = EXIT_SUCCESS;
  41. +
  42. if(m_bWaitingForCredentials && g_pClientUser->BLoggedOn())
  43. {
  44. Msg("Waiting for credentials to cache.\n");
  45. @@ -218,7 +227,7 @@
  46. ShowAvailableApps();
  47. this->Exit(EXIT_SUCCESS);
  48. }
  49. - else if(strcasecmp(cszCommand, "update") == 0)
  50. + else if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "status") == 0)
  51. {
  52. Msg("Requesting appinfo update.\n");
  53.  
  54. @@ -265,7 +274,7 @@
  55. Msg("Up to date.\n", m_uInstallingAppId);
  56. m_uInstallingAppId = k_uAppIdInvalid;
  57. g_pClientAppManager->SetDownloadingEnabled(false);
  58. - this->Exit(EXIT_SUCCESS);
  59. + this->Exit(EXIT_GAME_UPDATED);
  60. }
  61. }
  62. }
  63. @@ -389,14 +398,20 @@
  64. m_bWasProgressMsg = false;
  65. m_uInstallingAppId = k_uAppIdInvalid;
  66. m_uUninstallingAppId = k_uAppIdInvalid;
  67. +
  68. + char *batch = getenv("BATCH");
  69. + m_batch = (batch != NULL && strcmp(batch, "1") == 0);
  70. }
  71.  
  72. void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam)
  73. {
  74. - if(m_bWaitingForAppInfoUpdate && strcasecmp(commandLine.ParmValue("-command", ""), "update") == 0)
  75. - {
  76. - m_bWaitingForAppInfoUpdate = false;
  77. + if (!m_bWaitingForAppInfoUpdate)
  78. + return;
  79. + m_bWaitingForAppInfoUpdate = false;
  80.  
  81. + const char* cszCommand = commandLine.ParmValue("-command");
  82. + if(strcasecmp(cszCommand, "update") == 0)
  83. + {
  84. AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid);
  85.  
  86. bool bVerifyAll = commandLine.FindParm("-verify_all") != 0;
  87. @@ -406,6 +421,22 @@
  88. else if(eResult == k_EUpdateResultAlreadyUpToDate)
  89. this->Exit(EXIT_SUCCESS);
  90. }
  91. + else if(strcasecmp(cszCommand, "status") == 0)
  92. + {
  93. + AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid);
  94. +
  95. + if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled)
  96. + {
  97. + Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId));
  98. + this->Exit(EXIT_FAILURE);
  99. + }
  100. + else
  101. + {
  102. + bool uptodate = g_pClientAppManager->BIsAppUpToDate(uAppId);
  103. + Msg("%u:%s %s\n", uAppId, GetAppName(uAppId), (uptodate) ? "is up to date" : "needs updating");
  104. + this->Exit((uptodate) ? EXIT_SUCCESS : EXIT_UPDATE_RELEASED);
  105. + }
  106. + }
  107. }
  108.  
  109. void CApplication::OnDisconnected(SteamServersDisconnected_t* pParam)
  110. @@ -728,6 +759,7 @@
  111. " update: Install or update a game\n"
  112. " uninstall: Remove a game\n"
  113. " list: View available games and their status\n"
  114. + " status: View status of a game\n"
  115. "\n"
  116. "Parameters:\n"
  117. " -game <appid> - Game AppID to install / update / uninstall\n"
  118. @@ -797,13 +829,14 @@
  119. return false;
  120. }
  121.  
  122. - if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0)
  123. + if(strcasecmp(cszCommand, "list") != 0 && strcasecmp(cszCommand, "update") != 0 && strcasecmp(cszCommand, "uninstall") != 0
  124. + && strcasecmp(cszCommand, "status") != 0)
  125. {
  126. Error("Invalid command specified.\n");
  127. return false;
  128. }
  129.  
  130. - if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0)
  131. + if(strcasecmp(cszCommand, "update") == 0 || strcasecmp(cszCommand, "uninstall") == 0 || strcasecmp(cszCommand, "status") == 0)
  132. {
  133. if(commandLine.FindParm("-game") == 0)
  134. {
  135. @@ -829,6 +862,12 @@
  136. return false;
  137. }
  138.  
  139. + if (m_batch && commandLine.FindParm("-autoupdate") != 0)
  140. + {
  141. + Msg("Batch mode and -autoupdate is mutually exclusive. Disabling batch mode...\n");
  142. + m_batch = false;
  143. + }
  144. +
  145. return true;
  146. }
  147.  
  148.