Skip to content

Commit

Permalink
chore(file): disable general file analysis for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Sep 17, 2024
1 parent 5e7d99d commit 83657f9
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 122 deletions.
13 changes: 12 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ use sysinfo::{Gid, Groups, Uid, Users};
use crate::error::Result;
use std::{
fs::{self, File, OpenOptions},
os::unix::fs::{MetadataExt, PermissionsExt},
path::PathBuf,
time::{Duration, SystemTime, UNIX_EPOCH},
};

#[cfg(not(target_os = "windows"))]
use std::os::unix::fs::{MetadataExt, PermissionsExt};

#[cfg(target_os = "windows")]
use std::os::windows::fs::MetadataExt;

/// General file information.
#[derive(Debug)]
pub struct FileInfo<'a> {
Expand Down Expand Up @@ -64,6 +69,7 @@ pub struct FileDateInfo {

impl<'a> FileInfo<'a> {
/// Constructs a new instance.
#[cfg(not(target_os = "windows"))]
pub fn new(path: &'a str, bytes: &'a [u8]) -> Result<Self> {
let metadata = fs::metadata(path)?;
let mode = metadata.permissions().mode();
Expand Down Expand Up @@ -143,6 +149,11 @@ impl<'a> FileInfo<'a> {
})
}

#[cfg(target_os = "windows")]
pub fn new(path: &'a str, bytes: &'a [u8]) -> Result<Self> {
unimplemented!()
}

/// Opens the file (with R/W if possible) and returns it.
pub fn open_file(&mut self) -> Result<File> {
Ok(
Expand Down
249 changes: 128 additions & 121 deletions src/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,127 +244,134 @@ pub fn render_general_info(state: &mut State, frame: &mut Frame, rect: Rect) {
banner_area[1],
);

let lines = vec![
Line::from(vec![
"Size".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.size.to_string().fg(state.accent_color),
]),
Line::from(vec![
" ".into(),
"Blocks".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.blocks
.to_string()
.fg(state.accent_color),
" ".into(),
]),
Line::from(vec![
"Block Size".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.block_size
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Device".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.links.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Inode".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.inode.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Links".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.links.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Access".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.mode
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Uid".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.uid
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Gid".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.gid
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Access".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.access
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Modify".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.modify
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Change".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.change
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Birth".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.birth
.to_string()
.fg(state.accent_color),
]),
];
let lines = if cfg!(target_os = "windows") {
vec![
Line::from("This feature is not implemented!"),
Line::from("See <https://github.com/orhun/binsider/issues/35>"),
]
} else {
vec![
Line::from(vec![
"Size".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.size.to_string().fg(state.accent_color),
]),
Line::from(vec![
" ".into(),
"Blocks".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.blocks
.to_string()
.fg(state.accent_color),
" ".into(),
]),
Line::from(vec![
"Block Size".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.block_size
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Device".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.links.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Inode".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.inode.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Links".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state.analyzer.file.links.to_string().fg(state.accent_color),
]),
Line::from(vec![
"Access".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.mode
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Uid".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.uid
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Gid".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.access
.gid
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Access".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.access
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Modify".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.modify
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Change".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.change
.to_string()
.fg(state.accent_color),
]),
Line::from(vec![
"Birth".cyan(),
Span::raw(": ").fg(Color::Rgb(100, 100, 100)),
state
.analyzer
.file
.date
.birth
.to_string()
.fg(state.accent_color),
]),
]
};

let info_width = lines.iter().map(|v| v.width()).max().unwrap_or_default() as u16 + 2;
let rect = area[2].inner(Margin {
Expand Down

0 comments on commit 83657f9

Please sign in to comment.