//! This service lets the application access a virtual mounted device created using a folder included within the application bundle.
//! After mounting the RomFS file system, the included files and folders will be accessible exactly like any other file, just by using the drive prefix `romfs:/<file-path>`.
//!
//! # Usage
//!
//! This module only gets compiled if the configured RomFS directory is found and the `romfs`
//! This module only gets compiled if the configured RomFS directory is found and the `romfs`
//! feature is enabled.
//! feature is enabled.
//!
//!
//! Configure the path in Cargo.toml (the default path is "romfs"). Paths are relative to the
//! Configure the path in your project's `Cargo.toml` manifest (the default path is "romfs"). Paths are relative to the
//! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of
//! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of
//! your package.
//! your package.
//!
//!
@ -11,6 +16,8 @@
//! [package.metadata.cargo-3ds]
//! [package.metadata.cargo-3ds]
//! romfs_dir = "romfs"
//! romfs_dir = "romfs"
//! ```
//! ```
//!
//! Alternatively, you can include the RomFS archive manually when building with `3dsxtool`.
usecrate::error::ResultCode;
usecrate::error::ResultCode;
usestd::ffi::CStr;
usestd::ffi::CStr;
@ -19,11 +26,6 @@ use std::sync::Mutex;
usecrate::services::ServiceReference;
usecrate::services::ServiceReference;
/// Handle to the RomFS service.
/// Handle to the RomFS service.
///
/// This service lets the application access a virtual mounted device created using a folder included within the application bundle.
/// `ctru-rs` will include as RomFS the folder specified in the `Cargo.toml` manifest (or use `./romfs` by default). Look at the [`romfs`](self) module for more information.
///
/// After mounting the RomFS file system, the included files and folders will be accessible exactly like any other file, just by using the drive prefix `romfs:/`.
pubstructRomFS{
pubstructRomFS{
_service_handler: ServiceReference,
_service_handler: ServiceReference,
}
}
@ -31,7 +33,24 @@ pub struct RomFS {
staticROMFS_ACTIVE: Mutex<usize>=Mutex::new(0);
staticROMFS_ACTIVE: Mutex<usize>=Mutex::new(0);
implRomFS{
implRomFS{
/// Mount the specified RomFS folder as a virtual drive.
/// Mount the bundled RomFS archive as a virtual drive.
///
/// # Example
///
/// ```no_run
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::romfs::RomFS;
///
/// let romfs = RomFS::new()?;
///
/// // Remember to include the RomFS archive and to use your actual files!
/// let contents = std::fs::read_to_string("romfs:/test-file.txt");
//! By using this service the program enables the use of network sockets and utilities such as those found in `std::net`, which are completely inaccessible by default.
//! As such, remember to hold a handle to this service handle while using any network functionality, or else the `std::net` methods will return generic OS errors.
uselibc::memalign;
uselibc::memalign;
usestd::net::Ipv4Addr;
usestd::net::Ipv4Addr;
@ -8,10 +11,7 @@ use crate::error::ResultCode;
usecrate::services::ServiceReference;
usecrate::services::ServiceReference;
usecrate::Error;
usecrate::Error;
/// Network socket service
/// Handle to the Network Socket service.
///
/// Initializing this service will enable the use of network sockets and utilities
/// such as those found in `std::net`. The service will close once this struct gets dropped.
pubstructSoc{
pubstructSoc{
_service_handler: ServiceReference,
_service_handler: ServiceReference,
sock_3dslink: libc::c_int,
sock_3dslink: libc::c_int,
@ -20,22 +20,51 @@ pub struct Soc {
staticSOC_ACTIVE: Mutex<usize>=Mutex::new(0);
staticSOC_ACTIVE: Mutex<usize>=Mutex::new(0);
implSoc{
implSoc{
/// Initialize a new service handle using a socket buffer size of 0x100000 bytes.
/// Initialize a new service handle using a socket buffer size of `0x100000` bytes.
///
///
/// # Errors
/// # Errors
///
///
/// This function will return an error if the [`Soc`] service is already initialized
/// This function will return an error if the [`Soc`] service is already being used.
///
/// # Example
///
/// ```no_run
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::soc::Soc;
///
/// let soc = Soc::new()?;
/// #
/// # Ok(())
/// # }
/// ```
#[doc(alias = "socInit")]
#[doc(alias = "socInit")]
pubfnnew()-> crate::Result<Self>{
pubfnnew()-> crate::Result<Self>{
Self::init_with_buffer_size(0x100000)
Self::init_with_buffer_size(0x100000)
}
}
/// Initialize the Soc service with a custom buffer size in bytes. The size should be
/// Initialize a new service handle using a custom socket buffer size.
/// 0x100000 bytes or greater.
///
/// The size should be `0x100000` bytes or greater.
///
///
/// # Errors
/// # Errors
///
///
/// This function will return an error if the [`Soc`] service is already initialized
/// This function will return an error if the [`Soc`] service is already being used.
///
/// # Example
///
/// ```no_run
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::soc::Soc;
///
/// let soc = Soc::init_with_buffer_size(0x100000)?;