-
-
Save leo60228/6aafa8de1a7191470df75e1052407c80 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::path::PathBuf; | |
use std::ffi::CString; | |
use std::os::raw::c_char; | |
mod libnx { | |
use std::os::raw::c_char; | |
#[derive(Default)] | |
pub struct FsFileSystem; | |
pub unsafe fn fsOpenBisFileSystem(_fs: *mut FsFileSystem, _id: u32, _str: *const c_char) {} | |
pub unsafe fn fsdevMountDevice(_name: *const c_char, _fs: FsFileSystem) {} | |
} | |
pub fn mount_sdk_fs(fs: &str) -> PathBuf { | |
let mut bis_dev = libnx::FsFileSystem::default(); | |
let (bis_id, name, root) = match fs { | |
"SystemContent" => (31, "System", PathBuf::from("System:/Contents/")), | |
"UserContent" => (30, "User", PathBuf::from("User:/Contents/")), | |
_ => panic!("FS not implemented!") | |
}; | |
unsafe { libnx::fsOpenBisFileSystem(&mut bis_dev as *mut _, bis_id, &(0 as c_char) as *const _); } | |
unsafe { libnx::fsdevMountDevice(CString::new(name).unwrap().as_ptr(), bis_dev); } | |
root | |
} | |
pub struct SdkPath(PathBuf); | |
fn main() { | |
let path = SdkPath(PathBuf::from("@SystemContent://test/asdfasdf.nca")); | |
let mut segments: Vec<_> = path.0.ancestors().filter_map(|e| e.file_name()).map(|e| e.to_str().unwrap()).collect(); | |
let mut fs = segments.pop().unwrap()[1..].to_string(); | |
fs.pop(); | |
segments.reverse(); | |
let mut libnx_path = mount_sdk_fs(&fs); | |
for segment in &segments { | |
libnx_path.push(segment); | |
} | |
println!("path: {:?}", libnx_path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment