Skip to content

Commit

Permalink
Merge pull request #6 from mono606/remove-gui
Browse files Browse the repository at this point in the history
Remove GUI due to possible crashes
  • Loading branch information
ko1N authored Jun 9, 2024
2 parents 96077f4 + b32c06b commit 7e56a8d
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 1,589 deletions.
1,219 changes: 69 additions & 1,150 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,5 @@ memflow = { version = "=0.2.0-beta10", features = ["plugins"] }
serde = { version = "1.0", features = ["derive"] }
toml = "0.7"

# gui
glium = "0.29.0"
imgui = "0.7.0"
imgui-glium-renderer = "0.7.0"
imgui-winit-support = "0.7.0"

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod settings;
78 changes: 78 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use memflow::prelude::v1::*;
use serde::{Deserialize, Serialize};

// see https://github.com/serde-rs/serde/issues/368
fn default_string_info() -> String {
"info".to_string()
}
fn default_bool_true() -> bool {
true
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub connector: String,
#[serde(default)]
pub args: String,

#[serde(default = "default_string_info")]
pub log_level: String,

// TODO: expose caching options (lifetimes, etc)
#[serde(default = "default_bool_true")]
pub parse_sections: bool,
}

impl Default for Config {
fn default() -> Config {
Config {
connector: String::new(),
args: String::new(),

log_level: "info".to_string(),

parse_sections: false,
}
}
}

pub struct Settings {
config: Config,
}

impl Settings {
/// Loads the current config from the {PWD}/Plugins/memflow.toml file.
pub fn new() -> Self {
// load config file
let pwd = std::env::current_dir().expect("unable to get pwd");
let config = if let Ok(configstr) =
std::fs::read_to_string(pwd.join("Plugins").join("memflow.toml"))
{
toml::from_str::<Config>(&configstr).unwrap_or_default()
} else {
Config::default()
};

Self { config }
}

/// Saves the current configuration to the {PWD}/Plugins/memflow.toml file.
pub fn persist(&self) -> Result<()> {

Check warning on line 60 in src/config/settings.rs

View workflow job for this annotation

GitHub Actions / clippy

method `persist` is never used

warning: method `persist` is never used --> src/config/settings.rs:60:12 | 43 | impl Settings { | ------------- method in this implementation ... 60 | pub fn persist(&self) -> Result<()> { | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default

Check warning on line 60 in src/config/settings.rs

View workflow job for this annotation

GitHub Actions / clippy

method `persist` is never used

warning: method `persist` is never used --> src/config/settings.rs:60:12 | 43 | impl Settings { | ------------- method in this implementation ... 60 | pub fn persist(&self) -> Result<()> { | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default
let pwd = std::env::current_dir().map_err(|_| {
Error(ErrorOrigin::Other, ErrorKind::Unknown).log_error("unable to get pwd")
})?;
let configstr = toml::to_string_pretty(&self.config).map_err(|_| {
Error(ErrorOrigin::Other, ErrorKind::Configuration)
.log_error("unable to serialize config")
})?;
std::fs::write(pwd.join("Plugins").join("memflow.toml"), configstr).map_err(|_| {
Error(ErrorOrigin::Other, ErrorKind::NotFound).log_error("unable to write config file")
})?;
Ok(())
}

/// Retrieves the current config
pub fn config(&self) -> Config {
self.config.clone()
}
}
38 changes: 0 additions & 38 deletions src/gui/alert.rs

This file was deleted.

6 changes: 0 additions & 6 deletions src/gui/mod.rs

This file was deleted.

194 changes: 0 additions & 194 deletions src/gui/settings.rs

This file was deleted.

Loading

0 comments on commit 7e56a8d

Please sign in to comment.