summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-03-18 15:27:26 +0100
committermanuel <manuel@mausz.at>2013-03-18 15:27:26 +0100
commit8c417384e29635c680745425abd630d5208cbaf2 (patch)
tree107f4824bb697fdef08cc30fea532159eca4171d /main.cpp
parent7dd1948c98c3cf10fe142384f9756e197d9f5bff (diff)
downloadsteamcmd-8c417384e29635c680745425abd630d5208cbaf2.tar.gz
steamcmd-8c417384e29635c680745425abd630d5208cbaf2.tar.bz2
steamcmd-8c417384e29635c680745425abd630d5208cbaf2.zip
replace mod-param with generic "-config key=val"-param
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp81
1 files changed, 47 insertions, 34 deletions
diff --git a/main.cpp b/main.cpp
index 394f5b8..d126fdf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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
162bool CApplication::UninstallApp(AppId_t uAppId) 169bool 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
260void CApplication::ParseAppConfig(AppId_t uAppId) 269bool 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
267void CApplication::OnAppEventStateChange(AppEventStateChange_t* pParam) 288void 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"