Crates.io | system-extensions |
lib.rs | system-extensions |
version | 0.0.4 |
source | src |
created_at | 2021-03-13 06:01:32.097376 |
updated_at | 2021-04-27 01:47:52.993277 |
description | A robust set of extensions for operating system operations. |
homepage | |
repository | https://github.com/ryandw11/system-extensions |
max_upload_size | |
id | 368181 |
size | 80,619 |
System Extensions is a cross-platform rust library that adds in additional functionality to manage opeartions of the operating system. System Extensions is split up into several modules that contain different functionality.
Add this to your Cargo.toml
file to use it.
system-extensions = {version = "0.0.4", features = ["metadata", "processes", "dialogues"]}
Features
Experimental Features
Experimental features are modules that might not support all platforms yet. API in experimental features might change in the future.
** Macos Not Supported
The processes module gives functionality to detect processes running on the operating system.
use system_extensions::processes::processes::find_process_id;
fn main() {
let result = find_process_id("Discord.exe");
println!("Program Id: {:?}", result.unwrap());
}
This module allows you to modify the metadata of a file.
You can change the creation, modified, and changed dates.
use std::path::Path;
use system_extensions::metadata::time::{FileTime, set_creation_date};
fn main() {
set_creation_date(Path::new("./my_file.txt"), &FileTime::new(25, 12, 2021));
}
You can also set the attributes of a file.
use std::path::Path;
use system_extensions::metadata::attribute::{Attributes, set_attribute};
fn main(){
set_attribute(Path::new("./my_file.txt"), Attributes::HIDDEN);
}
Or check to see if a file has an attribute:
use std::path::Path;
use system_extensions::metadata::attribute::{Attributes, has_attribute};
fn main(){
let value: bool = has_attribute(Path::new("./my_file.txt"), Attributes::HIDDEN);
}
Dialogues are GUI menus that function as user interaction.
Message boxes are GUI popup menus that displays information, warnings, or errors.
use system_extensions::dialogues::messagebox::{MessageBox, BoxReturn, IconType, WindowType};
fn main(){
let result = MessageBox::new("Error Message Dialogue", "This error is provided by System Extensions!")
.set_icon_type(IconType::ICON_ERROR)
.set_window_type(WindowType::OK_CANCEL)
.show();
if result.unwrap() == BoxReturn::OK {
println!("The user acknowledge the error!");
}
}
A FileBox is a box that allows the user to save or open files.
(Mac is currently not supported.)
use system_extensions::dialogues::filebox::FileBox;
use std::path::Path;
fn main(){
let result = FileBox::new()
.filter("PNG", "*.png")
.filter("JPG", "*.jpg")
.filter("GIF", "*.gif")
.directory(Path::new("D:\\"))
.save("image.png");
println!("{}", result.expect("The file was not saved!").to_str().unwrap());
}
** This features is experimental and only available for Windows. **
use system_extensions::notifications::notification::SimpleNotification;
fn main() {
let notif = SimpleNotification::new("Rust Notification".to_string())
.set_app_id("{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe".to_string())
.add_text("This notification was sent via rust!".to_string())
.add_text("This uses the Windows Notification Center.".to_string())
.display();
}