Skip to content

Commit

Permalink
Fix for not being able to save the config file on some systems #15
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKovacs committed Apr 22, 2020
1 parent 147b086 commit 519d437
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
69 changes: 69 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ winres = "0.1"
[dependencies]
gelatin = { path = "./subcrates/gelatin" }
reqwest = { version = "0.10", features = ["json", "blocking"], optional = true }
directories = "2.0.2"
open = "1.4.0"
sys-info = "=0.5.8"
error-chain = "0.12"
Expand Down
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::sync::{
use std::time::{Duration, Instant};

use serde_derive::Deserialize;
use directories::ProjectDirs;

use gelatin::glium::glutin::{
dpi::{PhysicalPosition, PhysicalSize},
Expand Down Expand Up @@ -50,14 +51,24 @@ mod shaders;
fn main() {
std::panic::set_hook(Box::new(handle_panic::handle_panic));

let exe_path = std::env::current_exe().unwrap();
let exe_folder = exe_path.parent().unwrap();
let img = image::load_from_memory(include_bytes!("../resource/emulsion48.png")).unwrap();
let rgba = img.into_rgba();
let (w, h) = rgba.dimensions();
let icon = Icon::from_rgba(rgba.into_raw(), w, h).unwrap();

let cfg_path = exe_folder.join("cfg.toml").to_owned();
let cfg_folder;
if let Some(project_dirs) = ProjectDirs::from("", "", "emulsion") {
cfg_folder = project_dirs.config_dir().to_owned();
} else {
let exe_path = std::env::current_exe().unwrap();
let exe_folder = exe_path.parent().unwrap();
cfg_folder = exe_folder.to_owned();
}
println!("Config folder is {:?}", cfg_folder);
if !cfg_folder.exists() {
std::fs::create_dir_all(&cfg_folder).unwrap();
}
let cfg_path = cfg_folder.join("cfg.toml").to_owned();
let first_lanuch;
let config: Rc<RefCell<Configuration>>;
if let Ok(cfg) = Configuration::load(cfg_path.as_path()) {
Expand Down

0 comments on commit 519d437

Please sign in to comment.