Browse Source

Basic port of the romfs example

pull/49/head
Andrea Ciliberti 3 years ago
parent
commit
c79aeeac76
  1. 1
      ctru-rs/Cargo.toml
  2. 48
      ctru-rs/examples/romfs.rs
  3. 1
      ctru-rs/examples/romfs/ファイル.txt

1
ctru-rs/Cargo.toml

@ -28,6 +28,7 @@ ferris-says = "0.2.1"
futures = "0.3" futures = "0.3"
time = "0.3.7" time = "0.3.7"
tokio = { version = "1.16", features = ["rt", "time", "sync", "macros"] } tokio = { version = "1.16", features = ["rt", "time", "sync", "macros"] }
cfg-if = "1.0.0"
[features] [features]
default = ["romfs"] default = ["romfs"]

48
ctru-rs/examples/romfs.rs

@ -0,0 +1,48 @@
use ctru::console::Console;
use ctru::gfx::Gfx;
use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad};
fn main() {
ctru::init();
let gfx = Gfx::default();
let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut());
cfg_if::cfg_if! {
// Run this code ff RomFS are wanted and available
// This never fails as `ctru-rs` examples inherit all of the `ctru` features,
// but it might in a normal user application wasn't setup correctly
if #[cfg(all(feature = "romfs", romfs_exists))] {
let _romfs = ctru::romfs::RomFS::new().unwrap();
let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap();
println!("Contents of test-file.txt: \n{f}\n");
let f = std::fs::read_to_string("romfs:/ファイル.txt").unwrap();
// While RomFS supports UTF-16 file paths, `Console` doesn't...
println!("Contents of [UTF-16 File]: \n{f}\n");
} else {
println!("No RomFS was found, are you sure you included it?")
}
}
println!("\nPress START to exit");
// Main loop
while apt.main_loop() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
break;
}
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank
gfx.wait_for_vblank();
}
}

1
ctru-rs/examples/romfs/ファイル.txt

@ -0,0 +1 @@
This filename has UTF-16 exclusive characters!
Loading…
Cancel
Save