Beispiel #1
0
    void share_callback(RemoteStorageFileShareResult_t * result, bool fail)
    {
        if (result && (result->m_eResult != k_EResultOK || fail)) {
            error = "Error: " + number_to_string(result->m_eResult);
            call_fail();
            return;
        }

        if (!(flags & SET_PREVIEW)) {
            preview_callback(NULL, false);
            return;
        }

        chowstring data;
        if (!read_file(preview.c_str(), data)) {
            error = "File not found";
            call_fail();
            return;
        }
        SteamRemoteStorage()->FileWrite(preview_cloud_file.c_str(),
                                        data.data(), data.size());
        SteamAPICall_t call_handle;
        call_handle = SteamRemoteStorage()->FileShare(
            preview_cloud_file.c_str());
        preview_call.Set(call_handle, this, &UploadCallback::preview_callback);
    }
Beispiel #2
0
 SteamReadFile(const char * filename)
 {
     int32 size = SteamRemoteStorage()->GetFileSize(filename);
     std::string v;
     v.resize(size, 0);
     SteamRemoteStorage()->FileRead(filename, &v[0], size);
     stream.str(v);
 }
void FOnlineUserCloudSteam::DumpCloudState(const FUniqueNetId& UserId)
{
	int32 TotalBytes, TotalAvailable;
	if (SteamRemoteStorage()->GetQuota(&TotalBytes, &TotalAvailable) == false)
	{
		TotalBytes = TotalAvailable = 0;
	}

	UE_LOG_ONLINE(Verbose, TEXT("Steam Disk Quota: %d / %d"), TotalAvailable, TotalBytes);
	UE_LOG_ONLINE(Verbose, TEXT("Game does %shave cloud storage enabled."), SteamRemoteStorage()->IsCloudEnabledForApp() ? TEXT("") : TEXT("NOT "));
	UE_LOG_ONLINE(Verbose, TEXT("User does %shave cloud storage enabled."), SteamRemoteStorage()->IsCloudEnabledForAccount() ? TEXT("") : TEXT("NOT "));
}
void FOnlineAsyncTaskSteamReadSharedFile::Tick()
{
	ISteamUtils* SteamUtilsPtr = SteamUtils();
	check(SteamUtilsPtr);

	if (!bInit)
	{
		if (SteamRemoteStorage() && SharedHandle.IsValid())
		{
			if (SteamUser()->BLoggedOn())
			{
				// Actual request to download the file from Steam
				CallbackHandle = SteamRemoteStorage()->UGCDownload(*(UGCHandle_t*)SharedHandle.GetBytes(), 0);

			}
			else
			{
				UE_LOG_ONLINE(Warning, TEXT("Steam user not logged in."));
			}
		}
		else
		{
			UE_LOG_ONLINE(Warning, TEXT("Steam remote storage API disabled."));
		}

		bInit = true;
	}

	if (CallbackHandle != k_uAPICallInvalid)
	{
		bool bFailedCall = false; 

		// Poll for completion status
		bIsComplete = SteamUtilsPtr->IsAPICallCompleted(CallbackHandle, &bFailedCall) ? true : false; 
		if (bIsComplete) 
		{ 
			bool bFailedResult;
			// Retrieve the callback data from the request
			bool bSuccessCallResult = SteamUtilsPtr->GetAPICallResult(CallbackHandle, &CallbackResults, sizeof(CallbackResults), CallbackResults.k_iCallback, &bFailedResult); 
			bWasSuccessful = (bSuccessCallResult ? true : false) &&
				(!bFailedCall ? true : false) &&
				(!bFailedResult ? true : false) &&
				((CallbackResults.m_eResult == k_EResultOK) ? true : false);
		} 
	}
	else
	{
		// Invalid API call
		bIsComplete = true;
		bWasSuccessful = false;
	}
}
void FOnlineAsyncTaskSteamDeleteUserFile::Tick()
{
	bWasSuccessful = false;

	if (SteamRemoteStorage() && FileName.Len() > 0)
	{
		CSteamID SteamId(*(uint64*)UserId.GetBytes());
		if (SteamUser()->BLoggedOn() && SteamUser()->GetSteamID() == SteamId)
		{
			bool bCloudDeleteSuccess = true;
			if (bShouldCloudDelete)
			{
				// Remove the cloud flag, the file remains safely available on the local machine
				bCloudDeleteSuccess = SteamRemoteStorage()->FileForget(TCHAR_TO_UTF8(*FileName));
			}

			bool bLocalDeleteSuccess = true;
			if (bShouldLocallyDelete)
			{
				bLocalDeleteSuccess = false;
				// Only clear the tables if we're permanently deleting the file
				// Need to make sure nothing async is happening	first (this is a formality as nothing in Steam actually is)
				IOnlineUserCloudPtr UserCloud = Subsystem->GetUserCloudInterface();
				if (UserCloud->ClearFile(UserId, FileName))
				{
					// Permanent delete
					bLocalDeleteSuccess = SteamRemoteStorage()->FileDelete(TCHAR_TO_UTF8(*FileName));
					Subsystem->ClearUserCloudMetadata(UserId, FileName);
				}
			}

			bWasSuccessful = bCloudDeleteSuccess && bLocalDeleteSuccess;
		}	
		else
		{
			UE_LOG_ONLINE(Warning, TEXT("Can only delete cloud files for logged in user."));
		}
	}
	else
	{
		UE_LOG_ONLINE(Warning, TEXT("Steam remote storage API disabled."));
	}

	bIsComplete = true;
}
void FOnlineAsyncTaskSteamEnumerateUserFiles::Tick()
{
	bIsComplete = true;
	bWasSuccessful = false;

	if (SteamRemoteStorage())
	{
		CSteamID SteamId(*(uint64*)UserId.GetBytes());
		if (SteamUser()->BLoggedOn() && SteamUser()->GetSteamID() == SteamId)
		{
			//SteamSubsystem->GetUserCloudInterface()->DumpCloudState(UserId);

			FScopeLock ScopeLock(&Subsystem->UserCloudDataLock);

			// Get or create the user metadata entry and empty it
			FSteamUserCloudData* UserMetadata = Subsystem->GetUserCloudEntry(UserId);

			UserMetadata->CloudMetadata.Empty();

			// Fill in the metadata entries
			const int32 FileCount = (int32) SteamRemoteStorage()->GetFileCount();
			for (int32 FileIdx = 0; FileIdx < FileCount; FileIdx++)
			{
				int32 FileSize = 0;
				const char *FileName = SteamRemoteStorage()->GetFileNameAndSize(FileIdx, &FileSize);
				new (UserMetadata->CloudMetadata) FCloudFileHeader(UTF8_TO_TCHAR(FileName), UTF8_TO_TCHAR(FileName), int32(FileSize));

				//SteamSubsystem->GetUserCloudInterface()->DumpCloudFileState(UserId, FileName);
			}

			bWasSuccessful = true;
		}
		else
		{
			UE_LOG_ONLINE(Warning, TEXT("Can only enumerate cloud files for logged in user."));
		}
	}
	else
	{
		UE_LOG_ONLINE(Warning, TEXT("Steam remote storage API disabled."));
	}
}
Beispiel #7
0
    void start()
    {
        uploading = true;

        if (!(flags & SET_FILE)) {
            share_callback(NULL, false);
            return;
        }

        chowstring data;
        if (!read_file(file.c_str(), data)) {
            error = "File not found";
            call_fail();
            return;
        }
        SteamRemoteStorage()->FileWrite(cloud_file.c_str(),
                                        data.data(), data.size());
        SteamAPICall_t call_handle;
        call_handle = SteamRemoteStorage()->FileShare(cloud_file.c_str());
        share_call.Set(call_handle, this, &UploadCallback::share_callback);
    }
Beispiel #8
0
void SteamObject::download(const chowstring & name)
{
#ifdef CHOWDREN_ENABLE_STEAM
    if (!global_steam_obj.initialized)
        return;
    chowstring filename = get_path_filename(name);
    const char * filename_c = filename.c_str();
    if (!SteamRemoteStorage()->FileExists(filename_c))
        return;

    int32 size = SteamRemoteStorage()->GetFileSize(filename_c);
    chowstring value;
    value.resize(size);
    SteamRemoteStorage()->FileRead(filename_c, &value[0], size);
    FSFile fp(name.c_str(), "w");
    if (!fp.is_open())
        return;
    fp.write(value.data(), value.size());
    fp.close();
#endif
}
Beispiel #9
0
    void do_update()
    {
        PublishedFileUpdateHandle_t handle;
        handle = SteamRemoteStorage()->CreatePublishedFileUpdateRequest(
            current_id);
        if (flags & SET_TITLE) {
            if (!SteamRemoteStorage()->UpdatePublishedFileTitle(
                    handle, title.c_str()))
                std::cout << "Could not set item title" << std::endl;
        }
        if (flags & SET_DESCRIPTION) {
            if (!SteamRemoteStorage()->UpdatePublishedFileDescription(
                    handle, description.c_str()))
                std::cout << "Could not set item description" << std::endl;
        }

        if (flags & SET_PREVIEW) {
            if (!SteamRemoteStorage()->UpdatePublishedFilePreviewFile(
                    handle, preview_cloud_file.c_str()))
                std::cout << "Could not set item preview" << std::endl;
        }

        if (flags & SET_FILE) {
            if (!SteamRemoteStorage()->UpdatePublishedFileFile(
                    handle, cloud_file.c_str()))
                std::cout << "Could not set item content" << std::endl;
        }

        if (flags & SET_TAGS) {
            if (!SteamRemoteStorage()->UpdatePublishedFileTags(
                    handle, &steam_tags))
                std::cout << "Could not set item tags" << std::endl;
        }

        if (flags & SET_VISIBILITY) {
            ERemoteStoragePublishedFileVisibility vis =
                (ERemoteStoragePublishedFileVisibility)visibility;
            if (!SteamRemoteStorage()->UpdatePublishedFileVisibility(
                    handle, vis))
                std::cout << "Could not set item visibility" << std::endl;
        }

        flags = 0;
        uploading = true;
        SteamAPICall_t call_handle;
        call_handle = SteamRemoteStorage()->CommitPublishedFileUpdate(handle);
        update_call.Set(call_handle, this,
                        &UploadCallback::on_update_callback);
    }
Beispiel #10
0
void SteamObject::upload(const chowstring & name)
{
#ifdef CHOWDREN_ENABLE_STEAM
    if (!global_steam_obj.initialized)
        return;
    chowstring filename = get_path_filename(name);
    const char * filename_c = filename.c_str();
    char * data;
    size_t size;
    if (!read_file(filename_c, &data, &size))
        return;
    SteamRemoteStorage()->FileWrite(filename_c, data, size);
#endif
}
void FOnlineUserCloudSteam::DumpCloudFileState(const FUniqueNetId& UserId, const FString& FileName)
{
	if (FileName.Len() > 0)
	{
		UE_LOG_ONLINE(Log, TEXT("Cloud File State file %s:"), *FileName);
		{
			FScopeLock(&SteamSubsystem->UserCloudDataLock);
			FSteamUserCloudData* UserCloud = SteamSubsystem->GetUserCloudEntry(UserId);
			FCloudFileHeader* FileMetadata = UserCloud->GetFileMetadata(FileName);
			if (FileMetadata)
			{
				UE_LOG_ONLINE(Log, TEXT("\tMeta: FileName:%s DLName:%s FileSize:%d Hash:%s"), *FileMetadata->FileName, *FileMetadata->DLName, FileMetadata->FileSize, *FileMetadata->Hash);
			}
			else
			{
				UE_LOG_ONLINE(Log, TEXT("\tNo metadata found!"));
			}

			FCloudFile* FileData = UserCloud->GetFileData(FileName);
			if (FileData)
			{
				UE_LOG_ONLINE(Log, TEXT("\tFileCache: FileName:%s State:%s CacheSize:%d"), *FileData->FileName, EOnlineAsyncTaskState::ToString(FileData->AsyncState), FileData->Data.Num());
			}
			else
			{
				UE_LOG_ONLINE(Log, TEXT("\tNo cache entry found!"));
			}
		}

		int32 FileSize = SteamRemoteStorage()->GetFileSize(TCHAR_TO_UTF8(*FileName));

		UE_LOG_ONLINE(Log, TEXT("\tSteam: FileName:%s Size:%d Exists:%s Persistent:%s"),
			*FileName, FileSize, 
			SteamRemoteStorage()->FileExists(TCHAR_TO_UTF8(*FileName)) ? TEXT("Y") : TEXT("N"),
			SteamRemoteStorage()->FilePersisted(TCHAR_TO_UTF8(*FileName)) ? TEXT("Y") : TEXT("N"));
	}
}
Beispiel #12
0
void SteamObject::download(const chowstring & name, int priority,
                           int content_id,
                           Frame::EventFunction success,
                           Frame::EventFunction fail)
{
#ifdef CHOWDREN_ENABLE_STEAM
    global_steam_obj.download_success = success;
    global_steam_obj.download_fail = fail;
    chowstring filename = convert_path(name);
    SteamAPICall_t handle;
    UGCHandle_t id = ugc_list_callback.details[content_id].m_hFile;
    handle = SteamRemoteStorage()->UGCDownloadToLocation(id, filename.c_str(),
                                                         priority);
    DownloadCall * call = new DownloadCall();
	call->call.Set(handle, call, &DownloadCall::on_callback);
    std::cout << "Download: " << id << " " << name << " " << priority
        << std::endl;
#endif
}
void FOnlineAsyncTaskSteamWriteSharedFile::Tick()
{
	ISteamUtils* SteamUtilsPtr = SteamUtils();
	check(SteamUtilsPtr);
	
	if (!bInit)
	{
		if (WriteUserFile(UserId, FileName, Contents))
		{
			// Simply mark the file as shared, will trigger a delegate when upload is complete
			CallbackHandle = SteamRemoteStorage()->FileShare(TCHAR_TO_UTF8(*FileName));
		}

		bInit = true;
	}

	if (CallbackHandle != k_uAPICallInvalid)
	{
		bool bFailedCall = false; 

		// Poll for completion status
		bIsComplete = SteamUtilsPtr->IsAPICallCompleted(CallbackHandle, &bFailedCall) ? true : false; 
		if (bIsComplete) 
		{ 
			bool bFailedResult;
			// Retrieve the callback data from the request
			bool bSuccessCallResult = SteamUtilsPtr->GetAPICallResult(CallbackHandle, &CallbackResults, sizeof(CallbackResults), CallbackResults.k_iCallback, &bFailedResult); 
			bWasSuccessful = (bSuccessCallResult ? true : false) &&
				(!bFailedCall ? true : false) &&
				(!bFailedResult ? true : false) &&
				((CallbackResults.m_eResult == k_EResultOK) ? true : false);
		} 
	}
	else
	{
		// Invalid API call
		bIsComplete = true;
		bWasSuccessful = false;
	}
}
void FOnlineAsyncTaskSteamReadSharedFile::Finalize()
{
	FOnlineAsyncTaskSteam::Finalize();

	FOnlineSharedCloudSteamPtr SharedCloud = StaticCastSharedPtr<FOnlineSharedCloudSteam>(Subsystem->GetSharedCloudInterface());
	FCloudFileSteam* SharedFile = SharedCloud->GetSharedCloudFile(SharedHandle);
	if (SharedFile)
	{
		if (bWasSuccessful)
		{
			// Currently don't support greater than 1 chunk (we read everything in at once)
			if (FSharedContentHandleSteam(CallbackResults.m_hFile) == SharedHandle && CallbackResults.m_nSizeInBytes > 0 && CallbackResults.m_nSizeInBytes <= k_unMaxCloudFileChunkSize)
			{
				SharedFile->Data.Empty(CallbackResults.m_nSizeInBytes);
				SharedFile->Data.AddUninitialized(CallbackResults.m_nSizeInBytes);

				uint32 FileOffset = 0;
				// This call only works once per call to UGCDownload()
				if (SteamRemoteStorage()->UGCRead(CallbackResults.m_hFile, SharedFile->Data.GetData(), SharedFile->Data.Num(), FileOffset, k_EUGCRead_ContinueReadingUntilFinished) != CallbackResults.m_nSizeInBytes)
				{
					// Failed to read the data from disk
					SharedFile->Data.Empty();
					bWasSuccessful = false;
				}
			}
			else
			{
				// Bad handle or bad filesize
				bWasSuccessful = false;
			}
		}
	
		SharedFile->AsyncState = bWasSuccessful ? EOnlineAsyncTaskState::Done : EOnlineAsyncTaskState::Failed;
	}
	else
	{
		// No file found
		bWasSuccessful = false;
	}
}
Beispiel #15
0
    void preview_callback(RemoteStorageFileShareResult_t * result, bool fail)
    {
        if (result && (result->m_eResult != k_EResultOK || fail)) {
            error = "Error: " + number_to_string(result->m_eResult);
            call_fail();
            return;
        }

        if (has_id) {
            do_update();
            return;
        }

        ERemoteStoragePublishedFileVisibility vis =
            (ERemoteStoragePublishedFileVisibility)visibility;
        SteamAPICall_t call_handle;
        call_handle = SteamRemoteStorage()->PublishWorkshopFile(
            cloud_file.c_str(), preview_cloud_file.c_str(), appid,
            title.c_str(), description.c_str(), vis, &steam_tags,
            k_EWorkshopFileTypeCommunity);
        new_call.Set(call_handle, this, &UploadCallback::new_callback);
    }
bool FOnlineAsyncTaskSteamWriteUserFile::WriteUserFile(const FUniqueNetId& InUserId, const FString& InFileToWrite, const TArray<uint8>& InContents)
{
	bool bSuccess = false;
	if (InFileToWrite.Len() > 0 && InContents.Num() > 0)
	{
		if (SteamRemoteStorage() && FileName.Len() > 0)
		{
			CSteamID SteamId(*(uint64*)InUserId.GetBytes());
			if (SteamUser()->BLoggedOn() && SteamUser()->GetSteamID() == SteamId)
			{
				// Currently don't support greater than 1 chunk
				if (InContents.Num() < k_unMaxCloudFileChunkSize)
				{
					if (SteamRemoteStorage()->FileWrite(TCHAR_TO_UTF8(*InFileToWrite), InContents.GetData(), InContents.Num()))
					{
						FScopeLock ScopeLock(&Subsystem->UserCloudDataLock);
						FSteamUserCloudData* UserCloud = Subsystem->GetUserCloudEntry(InUserId);
						if (UserCloud)
						{
							// Update the metadata table to reflect this write (might be new entry)
							FCloudFileHeader* UserCloudFileMetadata = UserCloud->GetFileMetadata(InFileToWrite, true);
							check(UserCloudFileMetadata);

							UserCloudFileMetadata->FileSize = SteamRemoteStorage()->GetFileSize(TCHAR_TO_UTF8(*InFileToWrite));
							UserCloudFileMetadata->Hash = FString(TEXT("0"));

							// Update the file table to reflect this write
							FCloudFile* UserCloudFileData = UserCloud->GetFileData(InFileToWrite, true);
							check(UserCloudFileData);

							UserCloudFileData->Data = InContents;
							bSuccess = true;
						}
					}
					else
					{
						UE_LOG_ONLINE(Warning, TEXT("Failed to write file to Steam cloud \"%s\"."), *InFileToWrite);
					}
				}
				else
				{
					UE_LOG_ONLINE(Warning, TEXT("File too large %d to write to Steam cloud."), InContents.Num());
				}
			}
			else
			{
				UE_LOG_ONLINE(Warning, TEXT("Can only write cloud files for logged in user."));
			}
		}
		else
		{
			UE_LOG_ONLINE(Warning, TEXT("Steam remote storage API disabled."));
		}
	}

	{
		FScopeLock ScopeLock(&Subsystem->UserCloudDataLock);
		FSteamUserCloudData* UserCloud = Subsystem->GetUserCloudEntry(InUserId);
		if (UserCloud)
		{
			FCloudFile* UserCloudFileData = UserCloud->GetFileData(InFileToWrite, true);
			check(UserCloudFileData);
			UserCloudFileData->AsyncState = bSuccess ? EOnlineAsyncTaskState::Done : EOnlineAsyncTaskState::Failed;
		}
	}

	//SteamSubsystem->GetUserCloudInterface()->DumpCloudFileState(InUserId, InFileToWrite);
	return bSuccess;
}
void FOnlineAsyncTaskSteamReadUserFile::Tick()
{
	// Going to be complete no matter what
	bIsComplete = true;

	if (SteamRemoteStorage() && FileName.Len() > 0)
	{
		CSteamID SteamId(*(uint64*)UserId.GetBytes());
		if (SteamUser()->BLoggedOn() && SteamUser()->GetSteamID() == SteamId)
		{
			// Currently don't support greater than 1 chunk
			const int32 FileSize = SteamRemoteStorage()->GetFileSize(TCHAR_TO_UTF8(*FileName));
			if (FileSize >= 0 && FileSize <= k_unMaxCloudFileChunkSize)
			{
				FScopeLock ScopeLock(&Subsystem->UserCloudDataLock);
				// Create or get the current entry for this file
				FSteamUserCloudData* UserCloud = Subsystem->GetUserCloudEntry(UserId);
				if (UserCloud)
				{
					FCloudFile* UserCloudFile = UserCloud->GetFileData(FileName, true);
					check(UserCloudFile);

					// Allocate and read in the file
					UserCloudFile->Data.Empty(FileSize);
					UserCloudFile->Data.AddUninitialized(FileSize);
					if (SteamRemoteStorage()->FileRead(TCHAR_TO_UTF8(*FileName), UserCloudFile->Data.GetData(), FileSize) == FileSize)
					{
						bWasSuccessful = true;
					}
					else
					{
						UserCloudFile->Data.Empty();
					}
				}
			}
			else
			{
				UE_LOG_ONLINE(Warning, TEXT("Requested file %s has invalid size %d."), *FileName, FileSize);
			}
		}	
		else
		{
			UE_LOG_ONLINE(Warning, TEXT("Can only read cloud files for logged in user."));
		}
	}
	else
	{
		UE_LOG_ONLINE(Warning, TEXT("Steam remote storage API disabled."));
	}

	{
		FScopeLock ScopeLock(&Subsystem->UserCloudDataLock);
		FSteamUserCloudData* UserCloud = Subsystem->GetUserCloudEntry(UserId);
		if (UserCloud)
		{
			FCloudFile* UserCloudFileData = UserCloud->GetFileData(FileName);
			if (UserCloudFileData)
			{
				UserCloudFileData->AsyncState = bWasSuccessful ? EOnlineAsyncTaskState::Done : EOnlineAsyncTaskState::Failed;
			}
		}
	}
}
Beispiel #18
0
 void close()
 {
     stream.seekp(0, std::ios_base::end);
     std::string v = stream.str();
     SteamRemoteStorage()->FileWrite(filename.c_str(), &v[0], v.size());
 }