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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
//! Structs that define how the butlerd api responds to specific queries. These will often
//! be returned from functions or requests for you to use.
#![allow(non_snake_case)]
use serde_json::value::Map;
use serde_json::Value;
///What butlerd prints at startup
#[derive(Serialize, Deserialize, Debug)]
pub struct BStart {
    pub secret: String,
    pub http: Map<String, Value>,
    pub https: Map<String, Value>,
}
///Game Information
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Game {
    pub id: i32,
    pub url: String,
    pub title: String,
    pub short_text: String,
    pub cover_url: String,
    #[serde(default)]
    pub still_cover_url: String,
    #[serde(flatten)]
    pub dates: Dates,
    #[serde(default)]
    pub min_price: i32,
    pub can_be_bought: bool,
    #[serde(default)]
    pub has_demo: bool,
    #[serde(default)]
    pub in_press_system: bool,
    pub user: Option<User>,
    pub sale: Option<Sale>,
    pub user_id: Option<i32>,
    pub views_count: Option<i32>,
    pub downloads_count: Option<i32>,
    pub purchases_count: Option<i32>,
    pub published: Option<bool>,
}
/// A Game that the logged-in user's profile owns
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ProfileGame {
    pub game: Game,
    pub views_count: i32,
    pub downloads_count: i32,
    pub purchases_count: i32,
    pub published: bool,
}
/// A Profile gives more information about a user through its id, but requires login
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Profile {
    pub id: i32,
    pub last_connected: String,
    pub user: User,
}
///A downloadable file. Has a build only if the game is wharf-enabled
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Upload {
    pub id: i32,
    pub storage: String,
    #[serde(default)]
    pub host: String,
    pub filename: String,
    pub display_name: String,
    pub size: i32,
    #[serde(default)]
    pub channel_name: String,
    //    #[serde(default)]
    //    pub build: Build,
    #[serde(default)]
    pub build_id: i32,
    pub preorder: bool,
    pub demo: bool,
    #[serde(flatten)]
    pub dates: Dates,
    pub platforms: Platforms,
}
impl Upload {
    /// Given a str representing an OS, checks if an upload supports it
    /// Possible: windows, linux, osx
    pub fn supports(&self, os: &str) -> bool {
        match os {
            "windows" => self.platforms.windows.is_some(),
            "osx" => self.platforms.osx.is_some(),
            "linux" => self.platforms.linux.is_some(),
            _ => false,
        }
    }
}
/// The architectures that an Upload suppports
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum Archs {
    All,
    #[serde(rename = "386")]
    i386,
    Amd64,
}
/// A struct that holds the platforms an Upload is compatibile with
#[derive(Serialize, Deserialize, Debug)]
pub struct Platforms {
    windows: Option<Archs>,
    osx: Option<Archs>,
    linux: Option<Archs>,
}
///An itch user's basic public info
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct User {
    pub id: i32,
    pub username: String,
    pub display_name: String,
    /// Whether or not the user is a developer.
    pub developer: bool,
    pub press_user: bool,
    pub url: String,
    pub cover_url: String,
    #[serde(default)]
    pub still_cover_url: String,
}
/// A specific build of a Game. Game must be wharf-enabled
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Build {
    pub id: i32,
    pub parent_build_id: i32,
    pub state: String,
    /// The version of the Game
    pub version: i32,
    #[serde(default)]
    pub user_version: String,
    //  Todo
    //  pub files: BuildFiles[]
    /// The user that published the Build
    pub user: Option<User>,
    #[serde(flatten)]
    pub dates: Dates,
}
/// A Cave holds a Game and associated info
#[derive(Serialize, Deserialize, Debug)]
pub struct Cave {
    pub id: String,
    /// The game this cave is associated with
    pub game: Game,
    pub upload: Upload,
}
/// The base Response struct
#[derive(Serialize, Deserialize, Debug)]
pub struct Response {
    pub id: i32,
    /// The version of JSONRPC that butlerd is using
    pub jsonrpc: String,
}
/// The base struct for publish/update dates
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Dates {
    #[serde(default)]
    pub created_at: String,
    #[serde(default)]
    pub updated_at: String,
}
/// The base struct for responses with errors
#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseErr {
    #[serde(flatten)]
    pub response: Response,
    pub error: BError,
}
/// The base struct for responses with results
#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseRes {
    #[serde(flatten)]
    pub response: Response,
    pub result: Map<String, Value>,
}
/// A sale on a given Game
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Sale {
    pub id: i32,
    pub game_id: i32,
    pub rate: i32,
    ///Can be negative due to [reverse sales](https://itch.io/updates/introducing-reverse-sales)
    pub start_date: String,
    pub end_date: String,
}
/// Info on a game install location
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct InstallLocationSummary {
    pub id: String,
    pub path: String,
    pub size_info: InstallLocationSizeInfo,
}
/// Info on storage usage for an install location
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct InstallLocationSizeInfo {
    /// Number of bytes used by currently installed games
    pub installed_size: i64,
    /// Negative if unknown
    pub free_size: i64,
    /// Negative if unknown
    pub total_size: i64,
}
/// The reason you gave to download a game
#[derive(Serialize, Deserialize, Debug)]
pub enum DownloadReason {
    #[serde(rename = "install")]
    Install,
    #[serde(rename = "reinstall")]
    Reinstall,
    #[serde(rename = "update")]
    Update,
    #[serde(rename = "version-switch")]
    VersionSwitch,
}
/// The response from queueing a game to be downloaded
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct QueueResponse {
    pub id: String,
    pub reason: DownloadReason,
    pub cave_id: String,
    pub game: Game,
    pub upload: Upload,
    pub build: Build,
    pub install_folder: String,
    pub staging_folder: String,
    pub install_location_id: String,
}
/// The request to queue up a game installation
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct InstallQueueReq {
    pub install_location_id: String,
    pub reason: String,
    pub game: Game,
    pub upload: Upload,
}
/// A download from the download queue
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Download {
    pub id: String,
    pub error: Option<String>,
    pub error_message: Option<String>,
    pub error_code: Option<String>,
    pub reason: DownloadReason,
    pub position: i32,
    pub cave_id: String,
    pub game: Game,
    pub upload: Upload,
    pub build: Option<Build>,
    pub started_at: String,
    pub finished_at: Option<String>,
    pub staging_folder: String,
}
/// Butler daemon version info
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct VersionInfo {
    pub version: String,
    /// More verbose version
    pub version_string: String,
}
/// What you get back when you check for updates. Each item in updates represents a different game
#[derive(Serialize, Deserialize, Debug)]
pub struct CheckUpdate {
    pub updates: Option<Vec<GameUpdate>>,
    pub warnings: Option<Vec<String>>,
}
/// Information on an avavilable update for a game
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GameUpdate {
    pub cave_id: String,
    pub game: Game,
    /// Whether or not this is a direct update within the same channel. See [here](http://docs.itch.ovh/butlerd/master/#/?id=gameupdate)
    pub direct: bool,
    pub choices: Option<Vec<GameUpdateChoice>>,
}
/// A choice of a possible update for a game. Higher confidence is usually better.
#[derive(Serialize, Deserialize, Debug)]
pub struct GameUpdateChoice {
    pub upload: Upload,
    pub build: Option<Build>,
    /// How confident butler is that this is the `right` update
    pub confidence: f64,
}
/// Butler's response when you login using an username and password
#[derive(Serialize, Deserialize, Debug)]
pub struct PassLogRes {
    pub profile: Profile,
    pub cookie: Map<String, Value>,
}
/// Representation of a download key for a purchased non-free game
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct DownloadKey {
    pub id: i64,
    pub game_id: i32,
    pub game: Game,
    pub owner_id: i64,
    #[serde(flatten)]
    pub dates: Dates,
}
/// Returned from fetch_commons. Most of butler's cached info
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Commons {
    pub download_keys: Vec<DownloadKeySummary>,
    pub caves: Vec<CaveSummary>,
    pub install_locations: Vec<InstallLocationSummary>,
}
/// Summary of a DownloadKey, but not an actual DownloadKey
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct DownloadKeySummary {
    pub id: i64,
    pub game_id: i32,
    pub created_at: String,
}
/// Summary of a cave's info
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CaveSummary {
    pub id: String,
    pub game_id: i32,
    pub last_touched_at: Option<String>,
    pub seconds_run: i32,
    pub installed_size: i64,
}
/// Info on a game collection
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Collection {
    pub id: i32,
    pub title: String,
    #[serde(flatten)]
    pub dates: Dates,
    pub games_count: i32,
    /// Presence depends on whether fetched with fetch_collection or fetch_collection_games
    pub collection_games: Option<Vec<CollectionGame>>,
    pub user_id: i32,
    pub user: User,
}
/// Info on a game within a game collection
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CollectionGame {
    pub collection_id: i32,
    pub collection: Collection,
    pub game_id: i32,
    pub game: Game,
    pub position: i32,
    pub blurb: String,
    pub user_id: i32,
    #[serde(flatten)]
    pub dates: Dates,
}
/// Information on a filesystem. Returned by statfs
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FsInfo {
    pub free_size: i64,
    pub total_size: i64,
}
/// Describes a directory that butler could clean up
#[derive(Serialize, Deserialize, Debug)]
pub struct CleanDownloadsEntry {
    pub path: String,
    pub size: i64,
}
/// A generic error struct. If the code is -1 or -2, it was a problem on this crate's side.
/// Otherwise, butler returned this in response to a request
#[derive(Serialize, Deserialize, Debug)]
pub struct BError {
    pub code: i64,
    pub message: String,
}