steamroom-cli 0.2.0

Command-line tool for downloading Steam depot content
Documentation
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
//! Per-command argument shadows of the clap-derived structs in `cli.rs`.
//! These are rkyv-archivable: `PathBuf` becomes `String`, `Regex` becomes
//! a raw pattern string, clap enums become their wire mirrors.

use super::OutputFormat;
use rkyv::Archive;
use rkyv::Deserialize;
use rkyv::Serialize;

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct DownloadParams {
    pub app: u32,
    pub depot: Option<u32>,
    pub manifest: Option<u64>,
    pub filelist: Option<String>,
    pub file_regex: Option<String>,
    pub output: Option<String>,
    pub verify: bool,
    pub os: Option<String>,
    pub arch: Option<String>,
    pub language: Option<String>,
    pub login_id: Option<u32>,
    pub all_platforms: bool,
    pub all_architectures: bool,
    pub all_languages: bool,
    pub lancache: bool,
    pub max_downloads: Option<u32>,
    pub branch: Option<String>,
    pub branch_password: Option<String>,
    pub local_keys: bool,
    pub non_atomic: bool,
    pub save_manifests: bool,
    pub bytes: bool,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct InfoParams {
    pub app: u32,
    pub format: Option<OutputFormat>,
    pub os: Option<String>,
    pub show_all: bool,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct FilesParams {
    pub app: Option<u32>,
    pub depot: Option<u32>,
    pub manifest: Option<u64>,
    pub manifest_file: Option<String>,
    pub depot_key: Option<String>,
    pub branch: Option<String>,
    pub branch_password: Option<String>,
    pub os: Option<String>,
    pub format: Option<OutputFormat>,
    pub raw: bool,
    pub bytes: bool,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct ManifestsParams {
    pub app: u32,
    pub branch: Option<String>,
    pub branch_password: Option<String>,
    pub format: Option<OutputFormat>,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct DiffParams {
    pub app: u32,
    pub depot: u32,
    pub from: u64,
    pub to: u64,
    pub branch: Option<String>,
    pub format: Option<OutputFormat>,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct PackagesParams {
    pub packages: Vec<u32>,
    pub format: Option<OutputFormat>,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct SaveManifestParams {
    pub app: u32,
    pub depot: u32,
    pub manifest: Option<u64>,
    pub branch: Option<String>,
    pub output: String,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct WorkshopParams {
    pub app: u32,
    pub item: u64,
    pub output: Option<String>,
}

#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
#[rkyv(derive(Debug))]
pub struct LocalInfoParams {
    pub format: Option<OutputFormat>,
    pub user: Option<String>,
    pub users: bool,
}

fn pathbuf_to_string(p: std::path::PathBuf) -> String {
    p.to_string_lossy().into_owned()
}

impl From<crate::cli::DownloadArgs> for DownloadParams {
    fn from(a: crate::cli::DownloadArgs) -> Self {
        Self {
            app: a.app,
            depot: a.depot,
            manifest: a.manifest,
            filelist: a.filelist.map(pathbuf_to_string),
            file_regex: a.file_regex,
            output: a.output.map(pathbuf_to_string),
            verify: a.verify,
            os: a.os,
            arch: a.arch,
            language: a.language,
            login_id: a.login_id,
            all_platforms: a.all_platforms,
            all_architectures: a.all_architectures,
            all_languages: a.all_languages,
            lancache: a.lancache,
            // Saturate at u32::MAX: real CDN parallelism caps are far below this.
            max_downloads: a
                .max_downloads
                .map(|n| u32::try_from(n).unwrap_or(u32::MAX)),
            branch: a.branch,
            branch_password: a.branch_password,
            local_keys: a.local_keys,
            non_atomic: a.non_atomic,
            save_manifests: a.save_manifests,
            bytes: a.bytes,
        }
    }
}

impl From<crate::cli::InfoArgs> for InfoParams {
    fn from(a: crate::cli::InfoArgs) -> Self {
        Self {
            app: a.app,
            format: a.format.map(Into::into),
            os: a.os,
            show_all: a.show_all,
        }
    }
}

impl From<crate::cli::FilesArgs> for FilesParams {
    fn from(a: crate::cli::FilesArgs) -> Self {
        Self {
            app: a.app,
            depot: a.depot,
            manifest: a.manifest,
            manifest_file: a.manifest_file.map(pathbuf_to_string),
            depot_key: a.depot_key,
            branch: a.branch,
            branch_password: a.branch_password,
            os: a.os,
            format: a.format.map(Into::into),
            raw: a.raw,
            bytes: a.bytes,
        }
    }
}

impl From<crate::cli::ManifestsArgs> for ManifestsParams {
    fn from(a: crate::cli::ManifestsArgs) -> Self {
        Self {
            app: a.app,
            branch: a.branch,
            branch_password: a.branch_password,
            format: a.format.map(Into::into),
        }
    }
}

impl From<crate::cli::DiffArgs> for DiffParams {
    fn from(a: crate::cli::DiffArgs) -> Self {
        Self {
            app: a.app,
            depot: a.depot,
            from: a.from,
            to: a.to,
            branch: a.branch,
            format: a.format.map(Into::into),
        }
    }
}

impl From<crate::cli::PackagesArgs> for PackagesParams {
    fn from(a: crate::cli::PackagesArgs) -> Self {
        Self {
            packages: a.packages,
            format: a.format.map(Into::into),
        }
    }
}

impl From<crate::cli::SaveManifestArgs> for SaveManifestParams {
    fn from(a: crate::cli::SaveManifestArgs) -> Self {
        Self {
            app: a.app,
            depot: a.depot,
            manifest: a.manifest,
            branch: a.branch,
            output: pathbuf_to_string(a.output),
        }
    }
}

impl From<crate::cli::WorkshopArgs> for WorkshopParams {
    fn from(a: crate::cli::WorkshopArgs) -> Self {
        Self {
            app: a.app,
            item: a.item,
            output: a.output.map(pathbuf_to_string),
        }
    }
}

impl From<crate::cli::LocalInfoArgs> for LocalInfoParams {
    fn from(a: crate::cli::LocalInfoArgs) -> Self {
        Self {
            format: a.format.map(Into::into),
            user: a.user,
            users: a.users,
        }
    }
}

impl From<DownloadParams> for crate::cli::DownloadArgs {
    fn from(p: DownloadParams) -> Self {
        Self {
            app: p.app,
            depot: p.depot,
            manifest: p.manifest,
            filelist: p.filelist.map(std::path::PathBuf::from),
            file_regex: p.file_regex,
            output: p.output.map(std::path::PathBuf::from),
            verify: p.verify,
            os: p.os,
            arch: p.arch,
            language: p.language,
            login_id: p.login_id,
            all_platforms: p.all_platforms,
            all_architectures: p.all_architectures,
            all_languages: p.all_languages,
            lancache: p.lancache,
            max_downloads: p.max_downloads.map(|n| n as usize),
            branch: p.branch,
            branch_password: p.branch_password,
            local_keys: p.local_keys,
            non_atomic: p.non_atomic,
            save_manifests: p.save_manifests,
            bytes: p.bytes,
        }
    }
}

impl From<InfoParams> for crate::cli::InfoArgs {
    fn from(p: InfoParams) -> Self {
        Self {
            app: p.app,
            format: p.format.map(Into::into),
            os: p.os,
            show_all: p.show_all,
        }
    }
}

impl From<FilesParams> for crate::cli::FilesArgs {
    fn from(p: FilesParams) -> Self {
        Self {
            app: p.app,
            depot: p.depot,
            manifest: p.manifest,
            manifest_file: p.manifest_file.map(std::path::PathBuf::from),
            depot_key: p.depot_key,
            branch: p.branch,
            branch_password: p.branch_password,
            os: p.os,
            format: p.format.map(Into::into),
            raw: p.raw,
            bytes: p.bytes,
        }
    }
}

impl From<ManifestsParams> for crate::cli::ManifestsArgs {
    fn from(p: ManifestsParams) -> Self {
        Self {
            app: p.app,
            branch: p.branch,
            branch_password: p.branch_password,
            format: p.format.map(Into::into),
        }
    }
}

impl From<DiffParams> for crate::cli::DiffArgs {
    fn from(p: DiffParams) -> Self {
        Self {
            app: p.app,
            depot: p.depot,
            from: p.from,
            to: p.to,
            branch: p.branch,
            format: p.format.map(Into::into),
        }
    }
}

impl From<PackagesParams> for crate::cli::PackagesArgs {
    fn from(p: PackagesParams) -> Self {
        Self {
            packages: p.packages,
            format: p.format.map(Into::into),
        }
    }
}

impl From<SaveManifestParams> for crate::cli::SaveManifestArgs {
    fn from(p: SaveManifestParams) -> Self {
        Self {
            app: p.app,
            depot: p.depot,
            manifest: p.manifest,
            branch: p.branch,
            output: std::path::PathBuf::from(p.output),
        }
    }
}

impl From<WorkshopParams> for crate::cli::WorkshopArgs {
    fn from(p: WorkshopParams) -> Self {
        Self {
            app: p.app,
            item: p.item,
            output: p.output.map(std::path::PathBuf::from),
        }
    }
}

impl From<LocalInfoParams> for crate::cli::LocalInfoArgs {
    fn from(p: LocalInfoParams) -> Self {
        Self {
            format: p.format.map(Into::into),
            user: p.user,
            users: p.users,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use rkyv::rancor;

    #[test]
    fn download_params_round_trip() {
        let p = DownloadParams {
            app: 730,
            depot: Some(731),
            manifest: Some(1234),
            filelist: Some("files.txt".into()),
            file_regex: Some(r"\.dll$".into()),
            output: Some("out".into()),
            verify: true,
            os: None,
            arch: None,
            language: None,
            login_id: None,
            all_platforms: false,
            all_architectures: false,
            all_languages: false,
            lancache: false,
            max_downloads: Some(16),
            branch: Some("public".into()),
            branch_password: None,
            local_keys: false,
            non_atomic: false,
            save_manifests: false,
            bytes: false,
        };
        let bytes = rkyv::to_bytes::<rancor::Error>(&p).unwrap();
        let back = rkyv::from_bytes::<DownloadParams, rancor::Error>(&bytes).unwrap();
        assert_eq!(back.app, 730);
        assert_eq!(back.depot, Some(731));
        assert_eq!(back.file_regex.as_deref(), Some(r"\.dll$"));
        assert_eq!(back.max_downloads, Some(16));
    }

    #[test]
    fn packages_params_round_trip_with_vec() {
        let p = PackagesParams {
            packages: vec![1, 2, 3],
            format: Some(OutputFormat::Json),
        };
        let bytes = rkyv::to_bytes::<rancor::Error>(&p).unwrap();
        let back = rkyv::from_bytes::<PackagesParams, rancor::Error>(&bytes).unwrap();
        assert_eq!(back.packages, vec![1, 2, 3]);
        assert!(matches!(back.format, Some(OutputFormat::Json)));
    }
}