Skip to content

Commit 0023e6b

Browse files
fix empty exe dir crash
1 parent a2c95c3 commit 0023e6b

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ To build from source, you need to have a [rust toolchain](https://www.rust-lang.
165165
p8tool addcart <path to cart> --name <name of cart> --author <author of cart>
166166
```
167167

168+
## Adding custom external apps
169+
170+
**picolauncher** now supports launcher arbritrary external applications. Simply create `drive/exe` directory, and place a cart file with the following contents:
171+
```p8
172+
pico-8 cartridge // http://www.pico-8.com
173+
version 42
174+
__meta:picolauncher__
175+
name="curse of the lich king"
176+
author="johanpeitz"
177+
path="cotlk/cotlk"
178+
```
179+
Where `path` points to the location of the executable you wish to launch (relative to `drive/exe` directory).
180+
168181
## Contributing
169182

170183
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more details! Don't hesitate to report bugs and post feature requests!

drive/carts/serial.p8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ end
8080
function serial_ls_exe()
8181
serial_writeline('ls_exe:')
8282
local exes=serial_readline()
83+
if #exes == 0 then
84+
return {}
85+
end
8386
local split_exes=split(exes, ',', false)
8487
for k, v in pairs(split_exes) do
8588
split_exes[k]=table_from_string(v)

drive/config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ foreground_sleep_ms 2 // number of milliseconds to sleep each frame. Try 10 to c
3030

3131
background_sleep_ms 10 // number of milliseconds to sleep each frame when running in the background
3232

33-
sessions 295 // number of times program has been run
33+
sessions 302 // number of times program has been run
3434

3535
// (scancode) hold this key down and left-click to simulate right-click
3636
rmb_key 0 // 0 for none 226 for LALT

src/main.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,19 @@ fn main() {
207207
// fetch all carts in directory
208208
let dir = (&*CART_DIR).join(data); // TODO watch out for path traversal
209209
let mut carts = vec![];
210-
for entry in read_dir(dir).unwrap() {
211-
let entry = entry.unwrap().path();
212-
if entry.is_file() {
213-
// for each file read metadata and pack into table string
214-
let filename = entry.file_name().unwrap();
215-
let mut metapath = PathBuf::from(filename);
216-
metapath.set_extension("json");
217-
let metapath = METADATA_DIR.join(metapath);
218-
match parse_metadata(&metapath) {
219-
Ok(serialized) => carts.push(serialized),
220-
Err(e) => warn!("failed parsing metadata file: {e:?}"),
210+
if let Ok(read_dir) = read_dir(dir) {
211+
for entry in read_dir {
212+
let entry = entry.unwrap().path();
213+
if entry.is_file() {
214+
// for each file read metadata and pack into table string
215+
let filename = entry.file_name().unwrap();
216+
let mut metapath = PathBuf::from(filename);
217+
metapath.set_extension("json");
218+
let metapath = METADATA_DIR.join(metapath);
219+
match parse_metadata(&metapath) {
220+
Ok(serialized) => carts.push(serialized),
221+
Err(e) => warn!("failed parsing metadata file: {e:?}"),
222+
}
221223
}
222224
}
223225
}
@@ -241,35 +243,37 @@ fn main() {
241243
// path=picocad/picocad
242244
// ```
243245
let mut exes = vec![];
244-
for entry in read_dir(EXE_DIR.as_path()).unwrap() {
245-
let entry = entry.unwrap().path();
246-
if !entry.is_file() {
247-
continue;
248-
}
249-
// TODO can this fail?
250-
if entry.extension().unwrap() != "p8" {
251-
continue;
252-
}
253-
let Ok(mut cart) = Cart::from_file(&entry) else {
254-
warn!("failed to read exe meta file {entry:?}");
255-
continue;
256-
};
257-
let meta = cart
258-
.get_section(SectionName::Meta("picolauncher".into()))
259-
.join("\n");
246+
if let Ok(read_dir) = read_dir(EXE_DIR.as_path()) {
247+
for entry in read_dir {
248+
let entry = entry.unwrap().path();
249+
if !entry.is_file() {
250+
continue;
251+
}
252+
// TODO can this fail?
253+
if entry.extension().unwrap() != "p8" {
254+
continue;
255+
}
256+
let Ok(mut cart) = Cart::from_file(&entry) else {
257+
warn!("failed to read exe meta file {entry:?}");
258+
continue;
259+
};
260+
let meta = cart
261+
.get_section(SectionName::Meta("picolauncher".into()))
262+
.join("\n");
260263

261-
let Ok(meta_parsed) = toml::from_str::<ExeMeta>(&meta) else {
262-
warn!("failed to parse metadata section of file {entry:?}");
263-
continue;
264-
};
264+
let Ok(meta_parsed) = toml::from_str::<ExeMeta>(&meta) else {
265+
warn!("failed to parse metadata section of file {entry:?}");
266+
continue;
267+
};
265268

266-
println!("{meta_parsed:?}");
267-
let Ok(meta_string) = meta_parsed.to_lua_table() else {
268-
warn!("failed to serialize to lua table for meta file {entry:?}");
269-
continue;
270-
};
269+
println!("{meta_parsed:?}");
270+
let Ok(meta_string) = meta_parsed.to_lua_table() else {
271+
warn!("failed to serialize to lua table for meta file {entry:?}");
272+
continue;
273+
};
271274

272-
exes.push(meta_string);
275+
exes.push(meta_string);
276+
}
273277
}
274278
let mut in_pipe = open_in_pipe().expect("failed to open pipe");
275279
let exes_joined = exes.join(",");

0 commit comments

Comments
 (0)