Skip to content

Commit ac224b6

Browse files
Run cargo fmt
1 parent 0fd1a6d commit ac224b6

30 files changed

+2810
-773
lines changed

cargo-psp/src/bin/mksfo.rs

Lines changed: 107 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clap::{App, Arg};
22
use std::collections::HashMap;
3-
use std::path::Path;
43
use std::fs::File;
54
use std::io::prelude::*;
65
use std::io::SeekFrom;
6+
use std::path::Path;
77

8-
#[repr(C,packed)]
8+
#[repr(C, packed)]
99
struct SfoHeader {
1010
magic: u32,
1111
version: u32,
@@ -15,8 +15,8 @@ struct SfoHeader {
1515
}
1616

1717
impl SfoHeader {
18-
fn to_le_bytes(self) -> [u8;20] {
19-
let mut buf = [0u8;20];
18+
fn to_le_bytes(self) -> [u8; 20] {
19+
let mut buf = [0u8; 20];
2020

2121
buf[0..=3].copy_from_slice(&self.magic.to_le_bytes());
2222
buf[4..=7].copy_from_slice(&self.version.to_le_bytes());
@@ -28,7 +28,7 @@ impl SfoHeader {
2828
}
2929
}
3030

31-
#[repr(C,packed)]
31+
#[repr(C, packed)]
3232
#[derive(Default, Debug, Copy, Clone)]
3333
struct SfoEntry {
3434
key_offset: u16,
@@ -40,8 +40,8 @@ struct SfoEntry {
4040
}
4141

4242
impl SfoEntry {
43-
fn to_le_bytes(self) -> [u8;16] {
44-
let mut buf = [0u8;16];
43+
fn to_le_bytes(self) -> [u8; 16] {
44+
let mut buf = [0u8; 16];
4545

4646
buf[0..=1].copy_from_slice(&self.key_offset.to_le_bytes());
4747
buf[2..=2].copy_from_slice(&self.alignment.to_le_bytes());
@@ -72,35 +72,40 @@ fn main() {
7272
.version("0.1")
7373
.author("Paul Sajna <[email protected]>")
7474
.about("Creates SFO files used for building Sony PSP EBOOT executables")
75-
.arg(Arg::with_name("bare")
76-
.long("bare")
77-
.help("Do not set any default values. Ignores the <title> value if set.")
75+
.arg(
76+
Arg::with_name("bare")
77+
.long("bare")
78+
.help("Do not set any default values. Ignores the <title> value if set."),
7879
)
79-
.arg(Arg::with_name("dword")
80-
.short("d")
81-
.long("dword")
82-
.help("key=VALUE Add a new DWORD value")
83-
.multiple(true)
84-
.number_of_values(1)
85-
.takes_value(true)
80+
.arg(
81+
Arg::with_name("dword")
82+
.short("d")
83+
.long("dword")
84+
.help("key=VALUE Add a new DWORD value")
85+
.multiple(true)
86+
.number_of_values(1)
87+
.takes_value(true),
8688
)
87-
.arg(Arg::with_name("string")
88-
.short("s")
89-
.long("string")
90-
.help("key=STRING Add a new string value")
91-
.multiple(true)
92-
.number_of_values(1)
93-
.takes_value(true)
89+
.arg(
90+
Arg::with_name("string")
91+
.short("s")
92+
.long("string")
93+
.help("key=STRING Add a new string value")
94+
.multiple(true)
95+
.number_of_values(1)
96+
.takes_value(true),
9497
)
95-
.arg(Arg::with_name("title")
96-
.takes_value(true)
97-
.required(true)
98-
.help("Display title")
98+
.arg(
99+
Arg::with_name("title")
100+
.takes_value(true)
101+
.required(true)
102+
.help("Display title"),
99103
)
100-
.arg(Arg::with_name("output")
101-
.takes_value(true)
102-
.required(true)
103-
.help("Output file name")
104+
.arg(
105+
Arg::with_name("output")
106+
.takes_value(true)
107+
.required(true)
108+
.help("Output file name"),
104109
)
105110
.get_matches();
106111

@@ -133,17 +138,44 @@ fn main() {
133138
("CATEGORY", (EntryType::String_, false, true, true, true)),
134139
("DISC_ID", (EntryType::String_, false, false, true, true)),
135140
("DISC_NUMBER", (EntryType::Dword, false, false, false, true)),
136-
("DISC_VERSION", (EntryType::String_, false, false, true, true)),
137-
("DRIVER_PATH", (EntryType::String_, false, false, true, false)),
141+
(
142+
"DISC_VERSION",
143+
(EntryType::String_, false, false, true, true),
144+
),
145+
(
146+
"DRIVER_PATH",
147+
(EntryType::String_, false, false, true, false),
148+
),
138149
("LANGUAGE", (EntryType::String_, false, false, true, false)),
139-
("PARENTAL_LEVEL", (EntryType::Dword, false, true, true, true)),
140-
("PSP_SYSTEM_VER", (EntryType::String_, false, false, true, true)),
150+
(
151+
"PARENTAL_LEVEL",
152+
(EntryType::Dword, false, true, true, true),
153+
),
154+
(
155+
"PSP_SYSTEM_VER",
156+
(EntryType::String_, false, false, true, true),
157+
),
141158
("REGION", (EntryType::Dword, false, false, true, true)),
142-
("SAVEDATA_DETAIL", (EntryType::String_, false, true, false, false)),
143-
("SAVEDATA_DIRECTORY", (EntryType::String_, false, true, false, false)),
144-
("SAVEDATA_FILE_LIST", (EntryType::Binary, false, true, false, false)),
145-
("SAVEDATA_PARAMS", (EntryType::Binary, false, true, false, false)),
146-
("SAVEDATA_TITLE", (EntryType::String_, false, true, false, false)),
159+
(
160+
"SAVEDATA_DETAIL",
161+
(EntryType::String_, false, true, false, false),
162+
),
163+
(
164+
"SAVEDATA_DIRECTORY",
165+
(EntryType::String_, false, true, false, false),
166+
),
167+
(
168+
"SAVEDATA_FILE_LIST",
169+
(EntryType::Binary, false, true, false, false),
170+
),
171+
(
172+
"SAVEDATA_PARAMS",
173+
(EntryType::Binary, false, true, false, false),
174+
),
175+
(
176+
"SAVEDATA_TITLE",
177+
(EntryType::String_, false, true, false, false),
178+
),
147179
("TITLE", (EntryType::String_, false, true, true, true)),
148180
("TITLE_0", (EntryType::String_, false, true, true, true)),
149181
("TITLE_2", (EntryType::String_, false, true, true, true)),
@@ -153,24 +185,28 @@ fn main() {
153185
("TITLE_6", (EntryType::String_, false, true, true, true)),
154186
("TITLE_7", (EntryType::String_, false, true, true, true)),
155187
("TITLE_8", (EntryType::String_, false, true, true, true)),
156-
("UPDATER_VER", (EntryType::String_, false, false, true, false)),
157-
].iter().cloned().collect();
188+
(
189+
"UPDATER_VER",
190+
(EntryType::String_, false, false, true, false),
191+
),
192+
]
193+
.iter()
194+
.cloned()
195+
.collect();
158196

159197
if matches.values_of("string").is_some() {
160198
for s in matches.values_of("string").unwrap() {
161-
let key_value_pair: Vec<String> =
162-
s.split("=").map(|s: &str| s.to_string()).collect();
199+
let key_value_pair: Vec<String> = s.split("=").map(|s: &str| s.to_string()).collect();
163200
strings.insert(key_value_pair[0].clone(), key_value_pair[1].clone());
164201
}
165202
}
166203

167204
if matches.values_of("dword").is_some() {
168205
for s in matches.values_of("dword").unwrap() {
169-
let key_value_pair: Vec<String> =
170-
s.split("=").map(|s: &str| s.to_string()).collect();
206+
let key_value_pair: Vec<String> = s.split("=").map(|s: &str| s.to_string()).collect();
171207
dwords.insert(
172208
key_value_pair[0].clone(),
173-
str::parse::<u32>(&key_value_pair[1]).unwrap()
209+
str::parse::<u32>(&key_value_pair[1]).unwrap(),
174210
);
175211
}
176212
}
@@ -188,16 +224,16 @@ fn main() {
188224
panic!("Key {} does not take a string value", key)
189225
}
190226
if category == "WG" && !wg {
191-
panic!("Key {} is not valid for category WG", key);
227+
panic!("Key {} is not valid for category WG", key);
192228
}
193229
if category == "MS" && !ms {
194-
panic!("Key {} is not valid for category MS", key);
230+
panic!("Key {} is not valid for category MS", key);
195231
}
196232
if category == "MG" && !mg {
197-
panic!("Key {} is not valid for category MG", key);
233+
panic!("Key {} is not valid for category MG", key);
198234
}
199235
if category == "UG" && !ug {
200-
panic!("Key {} is not valid for category UG", key);
236+
panic!("Key {} is not valid for category UG", key);
201237
}
202238
}
203239

@@ -210,16 +246,16 @@ fn main() {
210246
panic!("Key {} does not take a dword value", key)
211247
}
212248
if category == "WG" && !wg {
213-
panic!("Key {} is not valid for category WG", key);
249+
panic!("Key {} is not valid for category WG", key);
214250
}
215251
if category == "MS" && !ms {
216-
panic!("Key {} is not valid for category MS", key);
252+
panic!("Key {} is not valid for category MS", key);
217253
}
218254
if category == "MG" && !mg {
219-
panic!("Key {} is not valid for category MG", key);
255+
panic!("Key {} is not valid for category MG", key);
220256
}
221257
if category == "UG" && !ug {
222-
panic!("Key {} is not valid for category UG", key);
258+
panic!("Key {} is not valid for category UG", key);
223259
}
224260
}
225261

@@ -235,7 +271,10 @@ fn main() {
235271

236272
let num_options = dwords.len() + strings.len();
237273
if num_options > MAX_OPTIONS {
238-
panic!("Maximum number of options is {}, you have {}", MAX_OPTIONS, num_options);
274+
panic!(
275+
"Maximum number of options is {}, you have {}",
276+
MAX_OPTIONS, num_options
277+
);
239278
}
240279

241280
let mut keys = [0u8; 8192];
@@ -248,10 +287,10 @@ fn main() {
248287

249288
let mut sorted_keys: Vec<String> = Vec::new();
250289
for (key, _value) in dwords.iter() {
251-
sorted_keys.push(key.to_string());
290+
sorted_keys.push(key.to_string());
252291
}
253292
for (key, _value) in strings.iter() {
254-
sorted_keys.push(key.to_string());
293+
sorted_keys.push(key.to_string());
255294
}
256295
sorted_keys.sort();
257296

@@ -267,17 +306,15 @@ fn main() {
267306
..Default::default()
268307
};
269308
let idx = key_offset as usize;
270-
&keys[idx..idx+key.len()].copy_from_slice(key.as_bytes());
309+
&keys[idx..idx + key.len()].copy_from_slice(key.as_bytes());
271310
key_offset += key.len() as u16 + 1;
272311
sfo_entry.val_size = 4;
273312
sfo_entry.total_size = 4;
274313
let idx = data_offset as usize;
275-
data[idx..idx+4].copy_from_slice(&value.to_le_bytes());
314+
data[idx..idx + 4].copy_from_slice(&value.to_le_bytes());
276315
data_offset += 4;
277316
sfo_entries.push(sfo_entry);
278-
}
279-
280-
else if strings.contains_key(&key) {
317+
} else if strings.contains_key(&key) {
281318
let value = strings.get(&key).unwrap();
282319
header.count += 1;
283320
let mut sfo_entry = SfoEntry {
@@ -288,27 +325,22 @@ fn main() {
288325
..Default::default()
289326
};
290327
let idx = key_offset as usize;
291-
&keys[idx..idx+key.len()].copy_from_slice(key.as_bytes());
328+
&keys[idx..idx + key.len()].copy_from_slice(key.as_bytes());
292329
key_offset += key.len() as u16 + 1;
293330

294331
let val_size = value.len() + 1;
295332
let total_size = (val_size + 3) & !3;
296333
sfo_entry.val_size = val_size as u32;
297334
sfo_entry.total_size = total_size as u32;
298335
let idx = data_offset as usize;
299-
data[idx..idx + value.len()].copy_from_slice(
300-
value.as_bytes()
301-
);
336+
data[idx..idx + value.len()].copy_from_slice(value.as_bytes());
302337
data_offset += total_size as u32;
303338
sfo_entries.push(sfo_entry);
304339
}
305340
}
306341

307-
header.key_offset = (
308-
core::mem::size_of::<SfoHeader>() +
309-
sfo_entries.len() *
310-
core::mem::size_of::<SfoEntry>()
311-
) as u32;
342+
header.key_offset = (core::mem::size_of::<SfoHeader>()
343+
+ sfo_entries.len() * core::mem::size_of::<SfoEntry>()) as u32;
312344

313345
let aligned_val_offset = (header.key_offset + key_offset as u32 + 3) & !3;
314346
header.val_offset = aligned_val_offset;
@@ -319,6 +351,7 @@ fn main() {
319351
file.write_all(&sfo_entry.to_le_bytes()).unwrap();
320352
}
321353
file.write_all(&keys[0..key_offset as usize]).unwrap();
322-
file.seek(SeekFrom::Start(aligned_val_offset as u64)).unwrap();
354+
file.seek(SeekFrom::Start(aligned_val_offset as u64))
355+
.unwrap();
323356
file.write_all(&data[0..data_offset as usize]).unwrap();
324357
}

0 commit comments

Comments
 (0)