windows support! and other stuff

This commit is contained in:
Lynne Megido 2021-02-20 03:57:19 +10:00
parent dc2f642171
commit 7fdc75c9e9
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
7 changed files with 10 additions and 8 deletions

1
.gitignore vendored
View File

@ -2,6 +2,5 @@
/imgs
fif_*
/old
/awful
*.sh
cargo-timing*.html

2
Cargo.lock generated
View File

@ -169,7 +169,7 @@ dependencies = [
[[package]]
name = "fif"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"cached",
"clap",

View File

@ -1,7 +1,7 @@
[package]
name = "fif"
description = "A command-line tool for detecting and optionally correcting files with incorrect extensions."
version = "0.2.1"
version = "0.2.2"
authors = ["Lynnesbian <lynne@bune.city>"]
edition = "2018"
license = "GPL-3.0-or-later"

2
Cross.toml Normal file
View File

@ -0,0 +1,2 @@
[build.env]
passthrough = ["RUST_BACKTRACE", "RUST_LOG"]

View File

@ -18,7 +18,9 @@ impl ExtensionSet {
Self::Videos => vec!["webm", "mp4", "mkv", "mov", "avi", "m4v", "wmv", "bik", "ogv", "qt", "3gp", "3g2", "divx"],
Self::Audio => vec!["ogg", "oga", "opus", "mp3", "m4a", "aac", "flac", "ape", "midi", "mid", "alac", "wav",
"aiff", "aa3", "at3"],
Self::Documents => vec!["doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "pdf", "odt", "ods", "odp"],
Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2"],
_ => todo!()
}
}
}
}

View File

@ -1,8 +1,6 @@
use std::io::{self, Write};
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
#[cfg(windows)]
use std::os::windows::ffi::OsStrExt;
use std::path::PathBuf;
use snailquote::escape;
@ -24,7 +22,8 @@ fn write_pathbuf<W: Write>(f: &mut W, path: &PathBuf) -> io::Result<()> {
#[cfg(unix)]
f.write_all(&*path.as_os_str().as_bytes())?;
#[cfg(windows)]
f.write_all(&*path.as_os_str().encode_wide().collect())?; // TODO: TEST THIS
write!(f, "{}", path.as_os_str().to_string_lossy())?; // TODO: implement bonked strings for windows
// f.write_all(&*path.as_os_str().encode_wide().collect::<Vec<u16>>())?;
write!(f, "'")
}
}

View File

@ -49,7 +49,7 @@ static MIMEDB: OnceCell<mimedb::XdgDb> = OnceCell::new();
#[cfg(windows)]
fn is_hidden(entry: &DirEntry) -> bool {
use std::os::windows::prelude::*;
std::fs::metadata(entry) // try to get metadata for file
std::fs::metadata(entry.path()) // try to get metadata for file
.map_or(
false, // if getting metadata/attributes fails, assume it's not hidden
|f| f.file_attributes() & 0x2 > 0, // flag for hidden - https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants