Browse Source

Update bitflags

pull/10/head
Fenrir 8 years ago
parent
commit
4e629ea378
  1. 2
      ctru-rs/Cargo.toml
  2. 35
      ctru-rs/src/services/fs.rs

2
ctru-rs/Cargo.toml

@ -15,7 +15,7 @@ path = "../ctru-sys"
version = "0.4" version = "0.4"
[dependencies.bitflags] [dependencies.bitflags]
version = "0.7.0" version = "0.9.0"
[dependencies.widestring] [dependencies.widestring]
version = "0.2.2" version = "0.2.2"

35
ctru-rs/src/services/fs.rs

@ -18,26 +18,29 @@ use std::sync::Arc;
use widestring::{WideCString, WideCStr}; use widestring::{WideCString, WideCStr};
bitflags! { bitflags! {
flags FsOpen: u32 { #[derive(Default)]
const FS_OPEN_READ = 1, struct FsOpen: u32 {
const FS_OPEN_WRITE = 2, const FS_OPEN_READ = 1;
const FS_OPEN_CREATE = 4, const FS_OPEN_WRITE = 2;
const FS_OPEN_CREATE = 4;
} }
} }
bitflags! { bitflags! {
flags FsWrite: u32 { #[derive(Default)]
const FS_WRITE_FLUSH = 1, struct FsWrite: u32 {
const FS_WRITE_UPDATE_TIME = 256, const FS_WRITE_FLUSH = 1;
const FS_WRITE_UPDATE_TIME = 256;
} }
} }
bitflags! { bitflags! {
flags FsAttribute: u32 { #[derive(Default)]
const FS_ATTRIBUTE_DIRECTORY = 1, struct FsAttribute: u32 {
const FS_ATTRIBUTE_HIDDEN = 256, const FS_ATTRIBUTE_DIRECTORY = 1;
const FS_ATTRIBUTE_ARCHIVE = 65536, const FS_ATTRIBUTE_HIDDEN = 256;
const FS_ATTRIBUTE_READ_ONLY = 16777216, const FS_ATTRIBUTE_ARCHIVE = 65536;
const FS_ATTRIBUTE_READ_ONLY = 16777216;
} }
} }
@ -467,7 +470,7 @@ impl File {
impl Metadata { impl Metadata {
/// Returns whether this metadata is for a directory. /// Returns whether this metadata is for a directory.
pub fn is_dir(&self) -> bool { pub fn is_dir(&self) -> bool {
self.attributes == self.attributes | FS_ATTRIBUTE_DIRECTORY.bits self.attributes == self.attributes | FS_ATTRIBUTE_DIRECTORY.bits()
} }
/// Returns whether this metadata is for a regular file. /// Returns whether this metadata is for a regular file.
@ -586,7 +589,7 @@ impl OpenOptions {
let path = to_utf16(path); let path = to_utf16(path);
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_OpenFile(&mut file_handle, self.arch_handle, let r = ::libctru::FSUSER_OpenFile(&mut file_handle, self.arch_handle,
fs_path, flags.bits, 0); fs_path, flags.bits(), 0);
if r < 0 { if r < 0 {
return Err(IoError::new(IoErrorKind::Other, ::Error::from(r))); return Err(IoError::new(IoErrorKind::Other, ::Error::from(r)));
} }
@ -685,7 +688,7 @@ pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_CreateDirectory(arch.handle, fs_path, let r = ::libctru::FSUSER_CreateDirectory(arch.handle, fs_path,
FS_ATTRIBUTE_DIRECTORY.bits); FS_ATTRIBUTE_DIRECTORY.bits());
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -722,7 +725,7 @@ pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
let maybe_dir = read_dir(&arch, path.as_ref()); let maybe_dir = read_dir(&arch, path.as_ref());
match (maybe_file, maybe_dir) { match (maybe_file, maybe_dir) {
(Ok(file), _) => file.metadata(), (Ok(file), _) => file.metadata(),
(_, Ok(_dir)) => Ok(Metadata { attributes: FS_ATTRIBUTE_DIRECTORY.bits, size: 0 }), (_, Ok(_dir)) => Ok(Metadata { attributes: FS_ATTRIBUTE_DIRECTORY.bits(), size: 0 }),
(Err(e), _) => Err(e), (Err(e), _) => Err(e),
} }
} }

Loading…
Cancel
Save