BVB Source Codes

CRYENGINE Show PlayerProfileImplConsole.cpp Source code

Return Download CRYENGINE: download PlayerProfileImplConsole.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   PlayerProfileImplConsole.cpp
  5. //  Created:     21/12/2009 by Alex Weighell.
  6. //  Description: Player profile implementation for consoles which manage
  7. //               the profile data via the OS and not via a file system
  8. //               which may not be present.
  9. //
  10. //               Note:
  11. //               Currently only the user login code is implemented though.
  12. //               The save data is still (incorrectly) using the file system.
  13. //
  14. //               TODO:
  15. //               Change the save data to use the platforms OS save data API.
  16. //               Probably best to do this through the IPLatformOS interface.
  17. // -------------------------------------------------------------------------
  18. //  History:
  19. //
  20. ////////////////////////////////////////////////////////////////////////////
  21.  
  22. #include "StdAfx.h"
  23. #include <CrySystem/XML/IXml.h>
  24. #include <CryString/StringUtils.h>
  25. #include <CryCore/Platform/IPlatformOS.h>
  26. #include "PlayerProfileImplConsole.h"
  27. #include "PlayerProfile.h"
  28. #include "PlayerProfileImplRSFHelper.h"
  29. #include "CryActionCVars.h"
  30.  
  31. using namespace PlayerProfileImpl;
  32.  
  33. void CPlayerProfileImplConsole::Release()
  34. {
  35.         delete this;
  36. }
  37.  
  38. // Profile Implementation which stores most of the stuff ActionMaps/Attributes in separate files
  39.  
  40. //------------------------------------------------------------------------
  41. CPlayerProfileImplConsole::CPlayerProfileImplConsole() : m_pMgr(0)
  42. {
  43. }
  44.  
  45. //------------------------------------------------------------------------
  46. CPlayerProfileImplConsole::~CPlayerProfileImplConsole()
  47. {
  48. }
  49.  
  50. //------------------------------------------------------------------------
  51. bool CPlayerProfileImplConsole::Initialize(CPlayerProfileManager* pMgr)
  52. {
  53.         m_pMgr = pMgr;
  54.         return true;
  55. }
  56.  
  57. //------------------------------------------------------------------------
  58. void CPlayerProfileImplConsole::GetMemoryStatistics(ICrySizer* s)
  59. {
  60.         s->Add(*this);
  61. }
  62.  
  63. //------------------------------------------------------------------------
  64. void CPlayerProfileImplConsole::InternalMakeFSPath(SUserEntry* pEntry, const char* profileName, string& outPath)
  65. {
  66.         if (pEntry)
  67.         {
  68.                 outPath = ("%USER%/Profiles/");
  69.         }
  70.         else
  71.         {
  72.                 // default profile always in game folder
  73.                 outPath = PathUtil::GetGameFolder();
  74.                 outPath.append("/Libs/Config/Profiles/");
  75.         }
  76.         if (profileName && *profileName)
  77.         {
  78.                 // [Ian:11/10/10] We currently need to pass the profile name through the filename so we can figure out which user in PlatformOS.
  79.                 //if(!pEntry) // only do this for the default profile
  80.                 {
  81.                         outPath.append(profileName);
  82.                         outPath.append("/");
  83.                 }
  84.         }
  85. }
  86.  
  87. //------------------------------------------------------------------------
  88. void CPlayerProfileImplConsole::InternalMakeFSSaveGamePath(SUserEntry* pEntry, const char* profileName, string& outPath, bool bNeedFolder)
  89. {
  90.         assert(pEntry != 0);
  91.         assert(profileName != 0);
  92.  
  93.         if (m_pMgr->IsSaveGameFolderShared())
  94.         {
  95.                 outPath = m_pMgr->GetSharedSaveGameFolder();
  96.                 outPath.append("/");
  97.                 if (!bNeedFolder)
  98.                 {
  99.                         // [Ian:20/10/10] We currently need to pass the profile name through the filename so we can figure out which user in PlatformOS.
  100.                         outPath.append(profileName);
  101.                         outPath.append("_");
  102.                 }
  103.         }
  104.         else
  105.         {
  106.                 outPath = "%USER%/Profiles/";
  107.                 // [Ian:20/10/10] We currently need to pass the profile name through the filename so we can figure out which user in PlatformOS.
  108.                 outPath.append(profileName);
  109.                 outPath.append("/SaveGames/");
  110.         }
  111. }
  112.  
  113. //------------------------------------------------------------------------
  114. bool CPlayerProfileImplConsole::SaveProfile(SUserEntry* pEntry, CPlayerProfile* pProfile, const char* name, bool initialSave, int /*reason = ePR_All*/)
  115. {
  116.         IPlatformOS* os = gEnv->pSystem->GetPlatformOS();
  117.  
  118.         // save the profile into a specific location
  119.  
  120.         // check if it's a valid filename
  121.         if (IsValidFilename(name) == false)
  122.                 return false;
  123.  
  124.         string path;
  125.         InternalMakeFSPath(pEntry, name, path);
  126.  
  127.         XmlNodeRef rootNode = GetISystem()->CreateXmlNode(PROFILE_ROOT_TAG);
  128.         rootNode->setAttr(PROFILE_NAME_TAG, name);
  129.         CSerializerXML serializer(rootNode, false);
  130.         pProfile->SerializeXML(&serializer);
  131.  
  132.         XmlNodeRef attributes = serializer.GetSection(CPlayerProfileManager::ePPS_Attribute);
  133.         XmlNodeRef actionMap = serializer.GetSection(CPlayerProfileManager::ePPS_Actionmap);
  134.  
  135.         if (!rootNode->findChild("Attributes"))
  136.                 rootNode->addChild(attributes);
  137.         if (!rootNode->findChild("ActionMaps"))
  138.                 rootNode->addChild(actionMap);
  139.  
  140.         return SaveXMLFile(path + "profile.xml", rootNode);
  141. }
  142.  
  143. //------------------------------------------------------------------------
  144. bool CPlayerProfileImplConsole::LoadProfile(SUserEntry* pEntry, CPlayerProfile* pProfile, const char* name)
  145. {
  146.         // load the profile from a specific location
  147.  
  148.         // XML for now
  149.         string path;
  150.         InternalMakeFSPath(pEntry, name, path);
  151.  
  152.         XmlNodeRef rootNode = GetISystem()->CreateXmlNode(PROFILE_ROOT_TAG);
  153.         CSerializerXML serializer(rootNode, true);
  154.  
  155.         XmlNodeRef profile = LoadXMLFile(path + "profile.xml");
  156.  
  157.         bool ok = false;
  158.         if (profile)
  159.         {
  160.                 XmlNodeRef attrNode = profile->findChild("Attributes");
  161.                 XmlNodeRef actionNode = profile->findChild("ActionMaps");
  162.                 if (!(attrNode && actionNode)) //default (PC) profile?
  163.                 {
  164.                         attrNode = LoadXMLFile(path + "attributes.xml");
  165.                         actionNode = LoadXMLFile(path + "actionmaps.xml");
  166.                 }
  167.  
  168.                 if (attrNode && actionNode)
  169.                 {
  170.                         serializer.SetSection(CPlayerProfileManager::ePPS_Attribute, attrNode);
  171.                         serializer.SetSection(CPlayerProfileManager::ePPS_Actionmap, actionNode);
  172.  
  173.                         ok = pProfile->SerializeXML(&serializer);
  174.                 }
  175.         }
  176.  
  177.         return ok;
  178. }
  179.  
  180. //------------------------------------------------------------------------
  181. bool CPlayerProfileImplConsole::LoginUser(SUserEntry* pEntry)
  182. {
  183.         // lookup stored profiles of the user (pEntry->userId) and fill in the pEntry->profileDesc
  184.         // vector
  185.         pEntry->profileDesc.clear();
  186.  
  187.         IPlatformOS* os = gEnv->pSystem->GetPlatformOS();
  188.  
  189.         unsigned int userIndex;
  190.         bool signedIn = os->UserIsSignedIn(pEntry->userId.c_str(), userIndex);
  191.         CryLogAlways("LoginUser::UserIsSignedIn %d\n", signedIn);
  192.  
  193.         if (signedIn)
  194.         {
  195.                 pEntry->profileDesc.push_back(SLocalProfileInfo(pEntry->userId));
  196.  
  197.                 // Check the profile data exists - if not create it
  198.                 string path;
  199.                 InternalMakeFSPath(pEntry, pEntry->userId, path);
  200.                 IPlatformOS::IFileFinderPtr fileFinder = os->GetFileFinder(userIndex);
  201.                 //this assumes there is a profile if a directory exists
  202.                 if (!fileFinder->FileExists(path))
  203.                 {
  204.                         // Create new profile based on the defaults
  205.                         CPlayerProfile* profile = m_pMgr->GetDefaultCPlayerProfile();
  206.                         string name = profile->GetName();
  207.                         profile->SetName(pEntry->userId);
  208.                         m_pMgr->LoadGamerProfileDefaults(profile);
  209. #if !CRY_PLATFORM_DURANGO
  210.                         // Durango: no reason to overwrite user profile with default profile, mainly for that we're always online.
  211.                         SaveProfile(pEntry, profile, pEntry->userId.c_str(), true);
  212. #endif
  213.                         profile->SetName(name);
  214.                 }
  215.         }
  216.         else
  217.         {
  218.                 printf("OS No User signed in\n");
  219.         }
  220.  
  221.         return signedIn;
  222. }
  223.  
  224. //------------------------------------------------------------------------
  225. bool CPlayerProfileImplConsole::DeleteProfile(SUserEntry* pEntry, const char* name)
  226. {
  227.         string path;
  228.         InternalMakeFSPath(pEntry, name, path);  // no profile name -> only path
  229.         bool bOK = gEnv->pCryPak->RemoveDir(path.c_str(), true);
  230.         // in case the savegame folder is shared, we have to delete the savegames from the shared folder
  231.         if (bOK && m_pMgr->IsSaveGameFolderShared())
  232.         {
  233.                 CPlayerProfileManager::TSaveGameInfoVec saveGameInfoVec;
  234.                 if (GetSaveGames(pEntry, saveGameInfoVec, name)) // provide alternate profileName, because pEntry->pCurrentProfile points to the active profile
  235.                 {
  236.                         CPlayerProfileManager::TSaveGameInfoVec::iterator iter = saveGameInfoVec.begin();
  237.                         CPlayerProfileManager::TSaveGameInfoVec::iterator iterEnd = saveGameInfoVec.end();
  238.                         while (iter != iterEnd)
  239.                         {
  240.                                 DeleteSaveGame(pEntry, iter->name);
  241.                                 ++iter;
  242.                         }
  243.                 }
  244.         }
  245.         return bOK;
  246. }
  247.  
  248. //------------------------------------------------------------------------
  249. bool CPlayerProfileImplConsole::RenameProfile(SUserEntry* pEntry, const char* newName)
  250. {
  251.         // TODO: only rename in the filesystem. for now save new and delete old
  252.         const char* oldName = pEntry->pCurrentProfile->GetName();
  253.         bool ok = SaveProfile(pEntry, pEntry->pCurrentProfile, newName);
  254.         if (!ok)
  255.                 return false;
  256.  
  257.         // move the save games
  258.         if (CPlayerProfileManager::sUseRichSaveGames)
  259.         {
  260.                 CRichSaveGameHelper sgHelper(this);
  261.                 sgHelper.MoveSaveGames(pEntry, oldName, newName);
  262.         }
  263.         else
  264.         {
  265.                 CCommonSaveGameHelper sgHelper(this);
  266.                 sgHelper.MoveSaveGames(pEntry, oldName, newName);
  267.         }
  268.  
  269.         DeleteProfile(pEntry, oldName);
  270.         return true;
  271. }
  272.  
  273. //------------------------------------------------------------------------
  274. bool CPlayerProfileImplConsole::LogoutUser(SUserEntry* pEntry)
  275. {
  276.         return true;
  277. }
  278.  
  279. //------------------------------------------------------------------------
  280. bool CPlayerProfileImplConsole::GetSaveGames(SUserEntry* pEntry, CPlayerProfileManager::TSaveGameInfoVec& outVec, const char* altProfileName)
  281. {
  282.         if (CPlayerProfileManager::sUseRichSaveGames)
  283.         {
  284.                 CRichSaveGameHelper sgHelper(this);
  285.                 return sgHelper.GetSaveGames(pEntry, outVec, altProfileName);
  286.         }
  287.         else
  288.         {
  289.                 CCommonSaveGameHelper sgHelper(this);
  290.                 return sgHelper.GetSaveGames(pEntry, outVec, altProfileName);
  291.         }
  292. }
  293.  
  294. //------------------------------------------------------------------------
  295. ISaveGame* CPlayerProfileImplConsole::CreateSaveGame(SUserEntry* pEntry)
  296. {
  297.         if (CPlayerProfileManager::sUseRichSaveGames)
  298.         {
  299.                 CRichSaveGameHelper sgHelper(this);
  300.                 return sgHelper.CreateSaveGame(pEntry);
  301.         }
  302.         else
  303.         {
  304.                 CCommonSaveGameHelper sgHelper(this);
  305.                 return sgHelper.CreateSaveGame(pEntry);
  306.         }
  307. }
  308.  
  309. //------------------------------------------------------------------------
  310. ILoadGame* CPlayerProfileImplConsole::CreateLoadGame(SUserEntry* pEntry)
  311. {
  312.         if (CPlayerProfileManager::sUseRichSaveGames)
  313.         {
  314.                 CRichSaveGameHelper sgHelper(this);
  315.                 return sgHelper.CreateLoadGame(pEntry);
  316.         }
  317.         else
  318.         {
  319.                 CCommonSaveGameHelper sgHelper(this);
  320.                 return sgHelper.CreateLoadGame(pEntry);
  321.         }
  322. }
  323.  
  324. //------------------------------------------------------------------------
  325. bool CPlayerProfileImplConsole::DeleteSaveGame(SUserEntry* pEntry, const char* name)
  326. {
  327.         if (CPlayerProfileManager::sUseRichSaveGames)
  328.         {
  329.                 CRichSaveGameHelper sgHelper(this);
  330.                 return sgHelper.DeleteSaveGame(pEntry, name);
  331.         }
  332.         else
  333.         {
  334.                 CCommonSaveGameHelper sgHelper(this);
  335.                 return sgHelper.DeleteSaveGame(pEntry, name);
  336.         }
  337. }
  338.  
  339. //------------------------------------------------------------------------
  340. bool CPlayerProfileImplConsole::GetSaveGameThumbnail(SUserEntry* pEntry, const char* saveGameName, SThumbnail& thumbnail)
  341. {
  342.         if (CPlayerProfileManager::sUseRichSaveGames)
  343.         {
  344.                 CRichSaveGameHelper sgHelper(this);
  345.                 return sgHelper.GetSaveGameThumbnail(pEntry, saveGameName, thumbnail);
  346.         }
  347.         else
  348.         {
  349.                 CCommonSaveGameHelper sgHelper(this);
  350.                 return sgHelper.GetSaveGameThumbnail(pEntry, saveGameName, thumbnail);
  351.         }
  352. }
  353.  
  354. ILevelRotationFile* CPlayerProfileImplConsole::GetLevelRotationFile(SUserEntry* pEntry, const char* name)
  355. {
  356.         CCommonSaveGameHelper sgHelper(this);
  357.         return sgHelper.GetLevelRotationFile(pEntry, name);
  358. }
  359.  
downloadPlayerProfileImplConsole.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top