diff options
| author | manuel <manuel@mausz.at> | 2013-03-18 15:27:26 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-03-18 15:27:26 +0100 |
| commit | 8c417384e29635c680745425abd630d5208cbaf2 (patch) | |
| tree | 107f4824bb697fdef08cc30fea532159eca4171d | |
| parent | 7dd1948c98c3cf10fe142384f9756e197d9f5bff (diff) | |
| download | steamcmd-8c417384e29635c680745425abd630d5208cbaf2.tar.gz steamcmd-8c417384e29635c680745425abd630d5208cbaf2.tar.bz2 steamcmd-8c417384e29635c680745425abd630d5208cbaf2.zip | |
replace mod-param with generic "-config key=val"-param
| -rw-r--r-- | CCommandLine.cpp | 38 | ||||
| -rw-r--r-- | CCommandLine.h | 4 | ||||
| -rw-r--r-- | main.cpp | 81 |
3 files changed, 82 insertions, 41 deletions
diff --git a/CCommandLine.cpp b/CCommandLine.cpp index 3df07b1..afb115d 100644 --- a/CCommandLine.cpp +++ b/CCommandLine.cpp | |||
| @@ -31,18 +31,28 @@ void CCommandLine::AddParm(const char *psz) | |||
| 31 | m_argc++; | 31 | m_argc++; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | const char* CCommandLine::ParmValue(const char *psz, const char *pDefaultVal) const | 34 | const char* CCommandLine::ParmValues(const char *psz, unsigned int ix) const |
| 35 | { | 35 | { |
| 36 | int nIndex = FindParm(psz); | 36 | int nIndex = FindParm(psz, ix); |
| 37 | if((nIndex == 0) || (nIndex == m_argc - 1)) | 37 | if((nIndex == 0) || (nIndex == m_argc - 1)) |
| 38 | return pDefaultVal; | 38 | return NULL; |
| 39 | 39 | ||
| 40 | if(m_argv[nIndex + 1][0] == '-' || m_argv[nIndex + 1][0] == '+') | 40 | if(m_argv[nIndex + 1][0] == '-' || m_argv[nIndex + 1][0] == '+') |
| 41 | return pDefaultVal; | 41 | return NULL; |
| 42 | 42 | ||
| 43 | return m_argv[nIndex + 1]; | 43 | return m_argv[nIndex + 1]; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | const char* CCommandLine::ParmValue(const char *psz, const char *pDefaultVal) const | ||
| 47 | { | ||
| 48 | const char* cszValue = ParmValues(psz, 0); | ||
| 49 | |||
| 50 | if(!cszValue) | ||
| 51 | return pDefaultVal; | ||
| 52 | |||
| 53 | return cszValue; | ||
| 54 | } | ||
| 55 | |||
| 46 | int CCommandLine::ParmValue(const char *psz, int nDefaultVal) const | 56 | int CCommandLine::ParmValue(const char *psz, int nDefaultVal) const |
| 47 | { | 57 | { |
| 48 | const char* cszValue = ParmValue(psz); | 58 | const char* cszValue = ParmValue(psz); |
| @@ -58,12 +68,28 @@ unsigned int CCommandLine::ParmCount() const | |||
| 58 | return m_argc; | 68 | return m_argc; |
| 59 | } | 69 | } |
| 60 | 70 | ||
| 61 | unsigned int CCommandLine::FindParm(const char *psz) const | 71 | unsigned int CCommandLine::FindParmCount(const char *psz) const |
| 72 | { | ||
| 73 | unsigned cnt = 0; | ||
| 74 | for(int i = 1; i < m_argc; i++) | ||
| 75 | { | ||
| 76 | if(strcmp(m_argv[i], psz) == 0) | ||
| 77 | cnt++; | ||
| 78 | } | ||
| 79 | |||
| 80 | return cnt; | ||
| 81 | } | ||
| 82 | |||
| 83 | unsigned int CCommandLine::FindParm(const char *psz, unsigned int ix) const | ||
| 62 | { | 84 | { |
| 63 | for(int i = 1; i < m_argc; i++) | 85 | for(int i = 1; i < m_argc; i++) |
| 64 | { | 86 | { |
| 65 | if(strcmp(m_argv[i], psz) == 0) | 87 | if(strcmp(m_argv[i], psz) == 0) |
| 66 | return i; | 88 | { |
| 89 | if (ix == 0) | ||
| 90 | return i; | ||
| 91 | ix--; | ||
| 92 | } | ||
| 67 | } | 93 | } |
| 68 | 94 | ||
| 69 | return 0; | 95 | return 0; |
diff --git a/CCommandLine.h b/CCommandLine.h index 899a875..0d4817d 100644 --- a/CCommandLine.h +++ b/CCommandLine.h | |||
| @@ -13,11 +13,13 @@ public: | |||
| 13 | CCommandLine(int argc, char **argv); | 13 | CCommandLine(int argc, char **argv); |
| 14 | ~CCommandLine(); | 14 | ~CCommandLine(); |
| 15 | 15 | ||
| 16 | const char* ParmValues(const char *psz, unsigned int ix) const; | ||
| 16 | const char* ParmValue(const char *psz, const char *pDefaultVal = 0) const; | 17 | const char* ParmValue(const char *psz, const char *pDefaultVal = 0) const; |
| 17 | int ParmValue(const char *psz, int nDefaultVal) const; | 18 | int ParmValue(const char *psz, int nDefaultVal) const; |
| 18 | 19 | ||
| 19 | unsigned int ParmCount() const; | 20 | unsigned int ParmCount() const; |
| 20 | unsigned int FindParm(const char *psz) const; | 21 | unsigned int FindParmCount(const char *psz) const; |
| 22 | unsigned int FindParm(const char *psz, unsigned int ix = 0) const; | ||
| 21 | const char* GetParm(unsigned int nIndex) const; | 23 | const char* GetParm(unsigned int nIndex) const; |
| 22 | 24 | ||
| 23 | void AddParm(const char *psz); | 25 | void AddParm(const char *psz); |
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <stdarg.h> | 8 | #include <stdarg.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <sstream> | ||
| 11 | 12 | ||
| 12 | #include "CCommandLine.h" | 13 | #include "CCommandLine.h" |
| 13 | 14 | ||
| @@ -22,6 +23,12 @@ | |||
| 22 | #define strcasecmp _stricmp | 23 | #define strcasecmp _stricmp |
| 23 | #endif | 24 | #endif |
| 24 | 25 | ||
| 26 | #ifdef _WIN32 | ||
| 27 | #define _TOOL_EXT "" | ||
| 28 | #else | ||
| 29 | #define _TOOL_EXT ".sh" | ||
| 30 | #endif | ||
| 31 | |||
| 25 | #define EXIT_GAME_UPDATED (1 << 2) | 32 | #define EXIT_GAME_UPDATED (1 << 2) |
| 26 | #define EXIT_UPDATE_RELEASED EXIT_GAME_UPDATED | 33 | #define EXIT_UPDATE_RELEASED EXIT_GAME_UPDATED |
| 27 | 34 | ||
| @@ -61,7 +68,7 @@ private: | |||
| 61 | EUpdateResult InstallOrUpdateApp(AppId_t uAppId, bool bVerifyAll = false, const char* cszBetaKey = NULL, const char* cszBetaPassword = NULL); | 68 | EUpdateResult InstallOrUpdateApp(AppId_t uAppId, bool bVerifyAll = false, const char* cszBetaKey = NULL, const char* cszBetaPassword = NULL); |
| 62 | bool UninstallApp(AppId_t uAppId); | 69 | bool UninstallApp(AppId_t uAppId); |
| 63 | void ShowAvailableApps(); | 70 | void ShowAvailableApps(); |
| 64 | void ParseAppConfig(AppId_t uAppId); | 71 | bool ParseAppConfig(AppId_t uAppId); |
| 65 | 72 | ||
| 66 | void Msg(const char* cszFormat, ...); | 73 | void Msg(const char* cszFormat, ...); |
| 67 | void Error(const char* cszFormat, ...); | 74 | void Error(const char* cszFormat, ...); |
| @@ -161,7 +168,9 @@ void CApplication::Exit(int iCode) | |||
| 161 | 168 | ||
| 162 | bool CApplication::UninstallApp(AppId_t uAppId) | 169 | bool CApplication::UninstallApp(AppId_t uAppId) |
| 163 | { | 170 | { |
| 164 | ParseAppConfig(uAppId); | 171 | if (!ParseAppConfig(uAppId)) |
| 172 | return false; | ||
| 173 | |||
| 165 | if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) | 174 | if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) |
| 166 | { | 175 | { |
| 167 | Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); | 176 | Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); |
| @@ -257,11 +266,23 @@ void CApplication::OnLicensesUpdated(LicensesUpdated_t* pParam) | |||
| 257 | } | 266 | } |
| 258 | } | 267 | } |
| 259 | 268 | ||
| 260 | void CApplication::ParseAppConfig(AppId_t uAppId) | 269 | bool CApplication::ParseAppConfig(AppId_t uAppId) |
| 261 | { | 270 | { |
| 262 | const char* mod = commandLine.ParmValue("-mod"); | 271 | bool ret = true; |
| 263 | if (mod) | 272 | for(unsigned int i = 0; i < commandLine.FindParmCount("-config"); i++) |
| 264 | g_pClientAppManager->SetAppConfigValue(uAppId, "mod", mod); | 273 | { |
| 274 | std::string keyval = commandLine.ParmValues("-config", i); | ||
| 275 | size_t pos = keyval.find_first_of('='); | ||
| 276 | if (pos == std::string::npos) | ||
| 277 | { | ||
| 278 | Error("Invalid syntax for param \"-config %s\"\n", keyval.c_str()); | ||
| 279 | ret = false; | ||
| 280 | continue; | ||
| 281 | } | ||
| 282 | g_pClientAppManager->SetAppConfigValue(uAppId, keyval.substr(0, pos).c_str(), | ||
| 283 | keyval.substr(pos + 1).c_str()); | ||
| 284 | } | ||
| 285 | return ret; | ||
| 265 | } | 286 | } |
| 266 | 287 | ||
| 267 | void CApplication::OnAppEventStateChange(AppEventStateChange_t* pParam) | 288 | void CApplication::OnAppEventStateChange(AppEventStateChange_t* pParam) |
| @@ -348,7 +369,9 @@ CApplication::EUpdateResult CApplication::InstallOrUpdateApp(AppId_t uAppId, boo | |||
| 348 | } | 369 | } |
| 349 | } | 370 | } |
| 350 | 371 | ||
| 351 | ParseAppConfig(uAppId); | 372 | if (!ParseAppConfig(uAppId)) |
| 373 | return k_EUpdateResultFailed; | ||
| 374 | |||
| 352 | EAppState eState = g_pClientAppManager->GetAppInstallState(uAppId); | 375 | EAppState eState = g_pClientAppManager->GetAppInstallState(uAppId); |
| 353 | if(eState == k_EAppStateInvalid || eState & k_EAppStateUninstalled) | 376 | if(eState == k_EAppStateInvalid || eState & k_EAppStateUninstalled) |
| 354 | { | 377 | { |
| @@ -434,7 +457,12 @@ void CApplication::OnAppInfoUpdateComplete(AppInfoUpdateComplete_t* pParam) | |||
| 434 | { | 457 | { |
| 435 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); | 458 | AppId_t uAppId = commandLine.ParmValue("-game", (int)k_uAppIdInvalid); |
| 436 | 459 | ||
| 437 | ParseAppConfig(uAppId); | 460 | if (!ParseAppConfig(uAppId)) |
| 461 | { | ||
| 462 | this->Exit(EXIT_FAILURE); | ||
| 463 | return; | ||
| 464 | } | ||
| 465 | |||
| 438 | if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) | 466 | if(g_pClientAppManager->GetAppInstallState(uAppId) & k_EAppStateUninstalled) |
| 439 | { | 467 | { |
| 440 | Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); | 468 | Error("This app (%u:%s) isn't installed\n", uAppId, GetAppName(uAppId)); |
| @@ -751,10 +779,12 @@ bool CApplication::ParseScript(const char* szFilename) | |||
| 751 | } | 779 | } |
| 752 | else if(strcasecmp(argv[0], "app_set_config") == 0) | 780 | else if(strcasecmp(argv[0], "app_set_config") == 0) |
| 753 | { | 781 | { |
| 754 | if(argc >= 4 && strcasecmp(argv[2], "mod") == 0) | 782 | if(argc == 4) |
| 755 | { | 783 | { |
| 756 | commandLine.AddParm("-mod"); | 784 | commandLine.AddParm("-config"); |
| 757 | commandLine.AddParm(argv[3]); | 785 | std::ostringstream oss; |
| 786 | oss << argv[2] << "=" << argv[3]; | ||
| 787 | commandLine.AddParm(oss.str().c_str()); | ||
| 758 | } | 788 | } |
| 759 | } | 789 | } |
| 760 | } | 790 | } |
| @@ -770,8 +800,8 @@ bool CApplication::CheckCommandline() | |||
| 770 | { | 800 | { |
| 771 | printf | 801 | printf |
| 772 | ( | 802 | ( |
| 773 | "Use: %s%s -command <command> [parameters] [flags]\n" | 803 | "Use: %s"_TOOL_EXT" -command <command> [parameters] [flags]\n" |
| 774 | "Or: %s%s +runscript <steamcmd_script_file>\n" | 804 | "Or: %s"_TOOL_EXT" +runscript <steamcmd_script_file>\n" |
| 775 | "\n" | 805 | "\n" |
| 776 | "Commands:\n" | 806 | "Commands:\n" |
| 777 | " update: Install or update a game\n" | 807 | " update: Install or update a game\n" |
| @@ -782,7 +812,7 @@ bool CApplication::CheckCommandline() | |||
| 782 | "Parameters:\n" | 812 | "Parameters:\n" |
| 783 | " -game <appid> - Game AppID to install / update / uninstall\n" | 813 | " -game <appid> - Game AppID to install / update / uninstall\n" |
| 784 | " (use '-command list' to see available games)\n" | 814 | " (use '-command list' to see available games)\n" |
| 785 | " -mod <modname> - Set game mod to install / update / uninstall (e.g. czero)\n" | 815 | " -config <key>=<value> - Set app specific settings (e.g. -config mod=czero,dod)\n" |
| 786 | " -dir <installdir> - Game install dir\n" | 816 | " -dir <installdir> - Game install dir\n" |
| 787 | " (if dir not specified, will use %s/steamapps/common/<gamename>/)\n" | 817 | " (if dir not specified, will use %s/steamapps/common/<gamename>/)\n" |
| 788 | " -username <username> - Steam account username\n" | 818 | " -username <username> - Steam account username\n" |
| @@ -795,20 +825,9 @@ bool CApplication::CheckCommandline() | |||
| 795 | " -verify_all - Verify all game files are up to date\n" | 825 | " -verify_all - Verify all game files are up to date\n" |
| 796 | " -remember_password - Remember password\n" | 826 | " -remember_password - Remember password\n" |
| 797 | "\n" | 827 | "\n" |
| 798 | "For example: %s%s -command update -game 740 -dir %s -username foo -password bar\n" | 828 | "For example: %s"_TOOL_EXT" -command update -game 740 -dir %s -username foo -password bar\n", |
| 799 | , commandLine.GetParm(0), | 829 | commandLine.GetParm(0), |
| 800 | #ifdef _WIN32 | 830 | commandLine.GetParm(0), |
| 801 | "" | ||
| 802 | #else | ||
| 803 | ".sh" | ||
| 804 | #endif | ||
| 805 | , commandLine.GetParm(0), | ||
| 806 | #ifdef _WIN32 | ||
| 807 | "" | ||
| 808 | #else | ||
| 809 | ".sh" | ||
| 810 | #endif | ||
| 811 | , | ||
| 812 | #ifdef _WIN32 | 831 | #ifdef _WIN32 |
| 813 | ".", | 832 | ".", |
| 814 | #else | 833 | #else |
| @@ -816,12 +835,6 @@ bool CApplication::CheckCommandline() | |||
| 816 | #endif | 835 | #endif |
| 817 | commandLine.GetParm(0), | 836 | commandLine.GetParm(0), |
| 818 | #ifdef _WIN32 | 837 | #ifdef _WIN32 |
| 819 | "" | ||
| 820 | #else | ||
| 821 | ".sh" | ||
| 822 | #endif | ||
| 823 | , | ||
| 824 | #ifdef _WIN32 | ||
| 825 | "C:\\csgo" | 838 | "C:\\csgo" |
| 826 | #else | 839 | #else |
| 827 | "/csgo" | 840 | "/csgo" |
