Пример #1
0
//------------------------------------------------------------------------
bool CPlayerProfileImplConsole::LoginUser(SUserEntry* pEntry)
{
	// lookup stored profiles of the user (pEntry->userId) and fill in the pEntry->profileDesc
	// vector 
	pEntry->profileDesc.clear();

	IPlatformOS *os = gEnv->pSystem->GetPlatformOS();

	unsigned int userIndex;
	bool signedIn = os->UserIsSignedIn(pEntry->userId.c_str(), userIndex);
	CryLogAlways("LoginUser::UserIsSignedIn %d\n", signedIn);

	if (signedIn)
	{
		pEntry->profileDesc.push_back(SLocalProfileInfo(pEntry->userId));

		// Check the profile data exists - if not create it
		string path;
		InternalMakeFSPath(pEntry, pEntry->userId, path);
		IPlatformOS::IFileFinderPtr fileFinder = os->GetFileFinder(userIndex);
		//this assumes there is a profile if a directory exists
		if(!fileFinder->FileExists(path))
		{
			// Create new profile based on the defaults
			CPlayerProfile* profile = m_pMgr->GetDefaultCPlayerProfile();
			string name = profile->GetName();
			profile->SetName(pEntry->userId);
			m_pMgr->LoadGamerProfileDefaults(profile);
#if !CRY_PLATFORM_DURANGO
			// Durango: no reason to overwrite user profile with default profile, mainly for that we're always online.
			SaveProfile(pEntry, profile, pEntry->userId.c_str(), true);
#endif
			profile->SetName(name);
		}
	}
	else
	{
		printf( "OS No User signed in\n" );
	}

	return signedIn;
}
Пример #2
0
bool CCommonSaveGameHelper::GetSaveGames(CPlayerProfileManager::SUserEntry* pEntry, CPlayerProfileManager::TSaveGameInfoVec& outVec, const char* altProfileName="")
{
	// Scan savegames directory for XML files
	// we scan only for save game meta information
	string path;
	string profileName = (altProfileName && *altProfileName) ? altProfileName : pEntry->pCurrentProfile->GetName();
	m_pImpl->InternalMakeFSSaveGamePath(pEntry, profileName, path, true); 

	const bool bNeedProfilePrefix = m_pImpl->GetManager()->IsSaveGameFolderShared();
	string profilePrefix = profileName;
	profilePrefix+='_';
	size_t profilePrefixLen = profilePrefix.length();

	path.TrimRight("/\\");
	string search;
	search.Format("%s/*%s", path.c_str(), CRY_SAVEGAME_FILE_EXT);

	IPlatformOS* os = GetISystem()->GetPlatformOS();
	IPlatformOS::IFileFinderPtr fileFinder = os->GetFileFinder(IPlatformOS::Unknown_User);
	_finddata_t fd;
	intptr_t handle = fileFinder->FindFirst(search.c_str(), &fd);
	if (handle != -1)
	{
		CPlayerProfileManager::SSaveGameInfo sgInfo;
		do
		{
			if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0)
				continue;

			if (bNeedProfilePrefix)
			{
				if (strnicmp(profilePrefix, fd.name, profilePrefixLen) != 0)
					continue;
			}

			sgInfo.name = fd.name;
			if (bNeedProfilePrefix) // skip profile_ prefix (we made sure this is valid by comparism above)
				sgInfo.humanName = fd.name+profilePrefixLen;
			else
				sgInfo.humanName = fd.name;
			PathUtil::RemoveExtension(sgInfo.humanName);
			sgInfo.description = "no description";

			bool ok = false;

			// filename construction
#if defined(PS3) || defined(XENON) //don't use meta files on PS3 or 360
			sgInfo.metaData.saveTime = static_cast<time_t>(fd.time_write); // the time gets used to find the most recent save
			sgInfo.metaData.loadTime = sgInfo.metaData.saveTime;
			ok = true;
#else
			string metaFilename = path;
			metaFilename.append("/");
			metaFilename.append(fd.name);
			metaFilename = PathUtil::ReplaceExtension(metaFilename, ".meta");
			XmlNodeRef rootNode = LoadXMLFile(metaFilename.c_str());
			// see if the root tag is o.k.
			if (rootNode && stricmp(rootNode->getTag(), "Metadata") == 0)
			{
				// get meta data
				ok = FetchMetaData(rootNode, sgInfo.metaData);
			}
			else
			{
				// when there is no meta information, we currently reject the savegame
				//ok = true; // un-comment this, if you want to accept savegames without meta
			}
			// Use the file modified time for the load time as we touch the saves when they are used to keep most recent checkpoint
			sgInfo.metaData.loadTime = static_cast<time_t>(fd.time_write);
#endif

			if (ok)
			{
				outVec.push_back(sgInfo);
			}
			else
			{
				GameWarning("CPlayerProfileImplFS::GetSaveGames: SaveGame '%s' of user '%s' is invalid", fd.name, pEntry->userId.c_str());
			}

		} while ( fileFinder->FindNext(handle, &fd) >= 0 );

		fileFinder->FindClose( handle );
	}

	return true;
}
Пример #3
0
//------------------------------------------------------------------------
bool CPlayerProfileImplFSDir::LoginUser(SUserEntry* pEntry)
{
	// lookup stored profiles of the user (pEntry->userId) and fill in the pEntry->profileDesc
	// vector 
	pEntry->profileDesc.clear();

	// scan directory for profiles

	string path;
	InternalMakeFSPath(pEntry, "", path);  // no profile name -> only path

	std::multimap<time_t, SLocalProfileInfo> profiles;

	ICryPak * pCryPak = gEnv->pCryPak;
	_finddata_t fd;

	path.TrimRight("/\\");
	string search = path + "/*.*";

	IPlatformOS* pOS = GetISystem()->GetPlatformOS();
	IPlatformOS::IFileFinderPtr fileFinder = pOS->GetFileFinder(IPlatformOS::Unknown_User);
	intptr_t handle = fileFinder->FindFirst(search.c_str(), &fd);
	if (handle != -1)
	{
		do
		{
			if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0)
				continue;

			if (fd.attrib & _A_SUBDIR)
			{
				// profile name = folder name
				// but make sure there is a profile.xml in it
				string filename = path + "/" + fd.name;
				filename += "/" ;
				filename += "profile.xml";
				XmlNodeRef rootNode = LoadXMLFile(filename.c_str());

				// see if the root tag is o.k.
				if (rootNode && stricmp(rootNode->getTag(), PROFILE_ROOT_TAG) == 0)
				{
					string profileName = fd.name;
					if (rootNode->haveAttr(PROFILE_NAME_TAG))
					{
						const char* profileHumanName = rootNode->getAttr(PROFILE_NAME_TAG);
						if (profileHumanName!=0 && stricmp(profileHumanName, profileName) == 0)
						{
							profileName = profileHumanName;
						}
					}
					time_t time = NULL;
					if (rootNode->haveAttr(PROFILE_LAST_PLAYED))
					{
						rootNode->getAttr(PROFILE_LAST_PLAYED, time);
					}
					SLocalProfileInfo info(profileName);
					info.SetLastLoginTime(time);
					profiles.insert(std::make_pair(time, info));
				}
				else
				{
					GameWarning("CPlayerProfileImplFSDir::LoginUser: Profile '%s' of User '%s' seems to exists but is invalid (File '%s). Skipped", fd.name, pEntry->userId.c_str(), filename.c_str());
				}
			}
		} while ( fileFinder->FindNext( handle, &fd ) >= 0 );

		fileFinder->FindClose( handle );
	}

	// Insert in most recently played order
	std::multimap<time_t, SLocalProfileInfo>::const_reverse_iterator itend = profiles.rend();
	for(std::multimap<time_t, SLocalProfileInfo>::const_reverse_iterator it = profiles.rbegin(); it != itend; ++it)
		pEntry->profileDesc.push_back(it->second);

	return true;
}