forked from GMMan/SteamCloudFileManagerLite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteStorage.cs
More file actions
119 lines (105 loc) · 3.25 KB
/
Copy pathRemoteStorage.cs
File metadata and controls
119 lines (105 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Steamworks;
namespace SteamCloudFileManager
{
class RemoteStorage : IRemoteStorage, IDisposable
{
static RemoteStorage instance;
static object sync = new object();
internal bool IsDisposed { get; private set; }
public bool IsCloudEnabledForAccount
{
get
{
//checkDisposed();
// Not static because we need to ensure Steamworks API is initted
return SteamRemoteStorage.IsCloudEnabledForAccount();
}
}
public bool IsCloudEnabledForApp
{
get
{
checkDisposed();
return SteamRemoteStorage.IsCloudEnabledForApp();
}
set
{
checkDisposed();
SteamRemoteStorage.SetCloudEnabledForApp(value);
}
}
internal RemoteStorage(uint appID)
{
Environment.SetEnvironmentVariable("SteamAppID", appID.ToString());
bool init = SteamAPI.Init();
if (!init)
{
// Setting environment variable didn't work, so use steam_appid.txt instead
try
{
File.WriteAllText("steam_appid.txt", appID.ToString());
init = SteamAPI.Init();
File.Delete("steam_appid.txt");
}
catch
{ }
}
if (!init) throw new Exception("Cannot initialize Steamworks API.");
}
public List<IRemoteFile> GetFiles()
{
checkDisposed();
List<IRemoteFile> files = new List<IRemoteFile>();
int fileCount = SteamRemoteStorage.GetFileCount();
for (int i = 0; i < fileCount; ++i)
{
int length;
string name = SteamRemoteStorage.GetFileNameAndSize(i, out length);
RemoteFile file = new RemoteFile(this, name);
files.Add(file);
}
return files;
}
public IRemoteFile GetFile(string name)
{
checkDisposed();
return new RemoteFile(this, name.ToLowerInvariant());
}
public bool GetQuota(out ulong totalBytes, out ulong availableBytes)
{
checkDisposed();
return SteamRemoteStorage.GetQuota(out totalBytes, out availableBytes);
}
void checkDisposed()
{
if (IsDisposed) throw new InvalidOperationException("Instance is no longer valid.");
}
public void Dispose()
{
if (!IsDisposed)
{
SteamAPI.Shutdown();
IsDisposed = true;
}
}
public static RemoteStorage CreateInstance(uint appID)
{
lock (sync)
{
if (instance != null)
{
instance.Dispose();
instance = null;
}
RemoteStorage rs = new RemoteStorage(appID);
instance = rs;
return rs;
}
}
}
}