Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/SteamCloudManager.cs
2026-02-21 16:45:37 +08:00

145 lines
3.4 KiB
C#

using BitStrap;
using Steamworks;
using UnityEngine;
public class SteamCloudManager : MonoBehaviour
{
private static SteamCloudManager instance;
[HideInInspector]
public SaveManager saveManager;
public static SteamCloudManager Instance
{
get
{
return instance;
}
}
private SteamCloudManager()
{
}
private void Awake()
{
if (instance == null)
{
instance = this;
Object.DontDestroyOnLoad(base.gameObject);
}
else
{
Object.Destroy(base.gameObject);
}
}
private void Start()
{
saveManager = GlobalSettings.Instance.saveManager;
ShowStats();
}
[Button]
public void OpenSteamUserData()
{
Application.OpenURL("C:/Program Files (x86)/Steam/userdata/75161268/" + SteamManager.Instance.gameId + "/remote");
}
[Button]
public void ShowStats()
{
if (SteamManager.Initialized && (bool)saveManager)
{
Debug.Log("SteamCloudManager GetFileCount: " + SteamRemoteStorage.GetFileCount());
Debug.Log("SteamCloudManager IsCloudEnabledForAccount: " + SteamRemoteStorage.IsCloudEnabledForAccount());
Debug.Log("SteamCloudManager IsCloudEnabledForApp: " + SteamRemoteStorage.IsCloudEnabledForApp());
for (int i = 0; i < SteamRemoteStorage.GetFileCount(); i++)
{
int pnFileSizeInBytes = 0;
string fileNameAndSize = SteamRemoteStorage.GetFileNameAndSize(i, out pnFileSizeInBytes);
Debug.Log("SteamCloudManager GetFileNameAndSize(i, out FileSize) : " + fileNameAndSize + " - " + pnFileSizeInBytes);
}
ulong pnTotalBytes;
ulong puAvailableBytes;
bool quota = SteamRemoteStorage.GetQuota(out pnTotalBytes, out puAvailableBytes);
Debug.Log("SteamCloudManager GetQuota(out m_TotalBytes, out AvailableBytes) : " + quota + " - " + pnTotalBytes + " - " + puAvailableBytes);
}
}
[Button]
public void FileWrite()
{
if (!saveManager || !SteamManager.Initialized)
{
return;
}
for (int i = 0; i < saveManager.profiles.Count; i++)
{
string prefix = saveManager.profiles[i].prefix;
if (!ES2.Exists(prefix))
{
continue;
}
using (ES2Reader eS2Reader = ES2Reader.Create(prefix))
{
if (eS2Reader.Length == 0 || !saveManager.IsSaveFileConsistent(eS2Reader))
{
Debug.LogError("Cloud FileWrite !IsSaveFileConsistent");
continue;
}
SteamRemoteStorage.FileWrite(prefix, eS2Reader.ReadRaw(), eS2Reader.Length);
Debug.Log("SteamCloudManager FileWrite: " + prefix);
}
}
}
[Button]
public void FileRead()
{
if (!saveManager || !SteamManager.Initialized)
{
return;
}
for (int i = 0; i < saveManager.profiles.Count; i++)
{
string prefix = saveManager.profiles[i].prefix;
byte[] array = null;
if (SteamRemoteStorage.FileExists(prefix))
{
int fileSize = SteamRemoteStorage.GetFileSize(prefix);
array = new byte[fileSize];
SteamRemoteStorage.FileRead(prefix, array, fileSize);
Debug.Log("SteamCloudManager FileRead: " + prefix);
if (ES2.Exists(prefix))
{
ES2.Delete(prefix);
}
using (ES2Writer eS2Writer = ES2Writer.Create(prefix))
{
eS2Writer.WriteRaw(array);
eS2Writer.Save();
}
}
}
}
[Button]
public void FileDelete()
{
if (!saveManager || !SteamManager.Initialized)
{
return;
}
for (int i = 0; i < saveManager.profiles.Count; i++)
{
string prefix = saveManager.profiles[i].prefix;
if (SteamRemoteStorage.FileExists(prefix))
{
SteamRemoteStorage.FileDelete(prefix);
Debug.Log("SteamCloudManager FileDelete: " + prefix);
}
}
}
}