-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam.cpp
178 lines (143 loc) · 3.95 KB
/
steam.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <fstream>
#include <steam_api.h>
#include "steam.h"
void UpdateWorkshop::submit_callback(SubmitItemUpdateResult_t *result, bool failure)
{
std::cerr << "Submit callback called\n";
if (failure) {
m_result = k_EResultFail;
} else if (result->m_bUserNeedsToAcceptWorkshopLegalAgreement) {
m_result = (EResult) 0;
} else {
m_result = result->m_eResult;
}
m_finished = true;
}
UpdateWorkshop::UpdateWorkshop(PublishedFileId_t fileid, AppId_t game) : m_fileid(fileid), m_game(game)
{
}
void UpdateWorkshop::StartUpdateItem()
{
std::cerr << "Starting update\n";
m_handle = SteamUGC()->StartItemUpdate(m_game, m_fileid);
}
bool UpdateWorkshop::SetTitle(std::string title)
{
return SteamUGC()->SetItemTitle(m_handle, title.c_str());
}
bool UpdateWorkshop::SetDescription(std::string description)
{
return SteamUGC()->SetItemDescription(m_handle, description.c_str());
}
bool UpdateWorkshop::SetPreviewImage(std::string image)
{
return SteamUGC()->SetItemPreview(m_handle, image.c_str());
}
bool UpdateWorkshop::SetLanguage(std::string language)
{
return SteamUGC()->SetItemUpdateLanguage(m_handle, language.c_str());
}
bool UpdateWorkshop::SetVisibility(ERemoteStoragePublishedFileVisibility visibility)
{
return SteamUGC()->SetItemVisibility(m_handle, visibility);
}
bool UpdateWorkshop::SetItemContent(std::string path) {
return SteamUGC()->SetItemContent(m_handle, path.c_str());
}
void UpdateWorkshop::SetChangelog(std::string changelog)
{
m_changelog = changelog;
}
void UpdateWorkshop::FinishUpdateItem()
{
std::cerr << "Finishing update\n";
SteamAPICall_t call = SteamUGC()->SubmitItemUpdate(m_handle, m_changelog.c_str());
m_update_result.Set(call, this, &UpdateWorkshop::submit_callback);
}
bool UpdateWorkshop::IsFinished()
{
return m_finished;
}
EResult UpdateWorkshop::GetResult()
{
return m_result;
}
void UpdateWorkshop::UpdateStats()
{
m_status = SteamUGC()->GetItemUpdateProgress(m_handle, &m_bytes_uploaded, &m_bytes_total);
}
uint64 UpdateWorkshop::GetUploadedBytes()
{
return m_bytes_uploaded;
}
uint64 UpdateWorkshop::GetTotalBytes()
{
return m_bytes_total;
}
EItemUpdateStatus UpdateWorkshop::GetStatus()
{
return m_status;
}
void CreateWorkshop::create_callback(CreateItemResult_t *result, bool failure)
{
std::cerr << "Create callback called\n";
if (failure) {
m_result = EGeneral;
} else if (result->m_bUserNeedsToAcceptWorkshopLegalAgreement) {
m_result = ELegal;
} else {
switch (result->m_eResult) {
case k_EResultInsufficientPrivilege:
m_result = EPermissions;
break;
case k_EResultTimeout:
m_result = ETimeout;
break;
case k_EResultNotLoggedOn:
m_result = ELoggedOut;
break;
case k_EResultOK:
m_result = Success;
m_fileid = result->m_nPublishedFileId;
break;
default:
std::cerr << "What?\n";
m_result = EGeneral;
break;
}
}
m_finished = true;
}
CreateWorkshop::CreateWorkshop(AppId_t game) : m_game(game)
{
}
void CreateWorkshop::CreateItem()
{
std::cerr << "Creating item\na";
SteamAPICall_t result = SteamUGC()->CreateItem(m_game, k_EWorkshopFileTypeCommunity);
m_create_result.Set(result, this, &CreateWorkshop::create_callback);
}
bool CreateWorkshop::IsFinished()
{
return m_finished;
}
Result CreateWorkshop::GetResult()
{
return m_result;
}
PublishedFileId_t CreateWorkshop::GetFileID()
{
return m_fileid;
}
AppId_t GetAppIdFromFile()
{
AppId_t appid;
char* buffer = new char[33]; // Include 1 more character in case of newline
std::ifstream file_appid("steam_appid.txt", std::ios::in);
// Read whatever we can
file_appid >> buffer;
// Get the app id. Note that AppId_t is typedef'd to uint32
sscanf(buffer, "%zd", &appid);
return appid;
}