mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
make config_management
This commit is contained in:
parent
a1969d6068
commit
cf6e694321
121
Cargo.lock
generated
121
Cargo.lock
generated
@ -1,5 +1,11 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.38"
|
||||
@ -45,6 +51,7 @@ dependencies = [
|
||||
"gio",
|
||||
"glib",
|
||||
"gtk",
|
||||
"rust-ini",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -79,6 +86,27 @@ version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "dlv-list"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
@ -245,6 +273,17 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gio"
|
||||
version = "0.9.1"
|
||||
@ -381,6 +420,15 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.2"
|
||||
@ -417,6 +465,16 @@ version = "1.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
|
||||
|
||||
[[package]]
|
||||
name = "ordered-multimap"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485"
|
||||
dependencies = [
|
||||
"dlv-list",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pango"
|
||||
version = "0.9.1"
|
||||
@ -462,6 +520,12 @@ version = "0.3.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "0.1.5"
|
||||
@ -525,6 +589,57 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_hc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-ini"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55b134767a87e0b086f73a4ce569ac9ce7d202f39c8eab6caa266e2617e73ac6"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"ordered-multimap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.123"
|
||||
@ -634,6 +749,12 @@ version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
glib = "0.10.3"
|
||||
rust-ini = "0.16"
|
||||
|
||||
[dependencies.gtk]
|
||||
version = "0.9.0"
|
||||
|
68
src/config_management.rs
Normal file
68
src/config_management.rs
Normal file
@ -0,0 +1,68 @@
|
||||
extern crate ini;
|
||||
extern crate glib;
|
||||
|
||||
use glib::get_user_data_dir;
|
||||
use ini::Ini;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::ops::Add;
|
||||
|
||||
pub fn initialize() -> PathBuf {
|
||||
let config_path: PathBuf = Path::new(&get_user_data_dir().unwrap())
|
||||
.join("blue-recorder")
|
||||
.join("config.ini");
|
||||
|
||||
// fatch and make the config file
|
||||
if !&config_path.exists() {
|
||||
let config_directories = &mut config_path.to_owned();
|
||||
config_directories.pop();
|
||||
std::fs::create_dir_all(&config_directories).unwrap_or_default();
|
||||
std::fs::File::create(&config_path).unwrap();
|
||||
default();
|
||||
}
|
||||
|
||||
config_path
|
||||
}
|
||||
|
||||
fn default() {
|
||||
set("default", "frame", "50");
|
||||
set("default", "delay", "0");
|
||||
set(
|
||||
"default",
|
||||
"folder",
|
||||
String::from("file://")
|
||||
.add(
|
||||
glib::get_user_special_dir(glib::UserDirectory::Videos)
|
||||
.expect(std::env::var("HOME").expect("/").as_str())
|
||||
.to_str().unwrap(),
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
set("default", "command", "");
|
||||
set("default", "filename", "");
|
||||
set("default", "videocheck", "true");
|
||||
set("default", "audiocheck", "true");
|
||||
set("default", "mousecheck", "true");
|
||||
set("default", "followmousecheck", "false");
|
||||
}
|
||||
|
||||
pub fn get(selection: &str, key: &str) -> String {
|
||||
let config_path: PathBuf = Path::new(&get_user_data_dir().unwrap())
|
||||
.join("blue-recorder")
|
||||
.join("config.ini");
|
||||
String::from(
|
||||
Ini::load_from_file(&config_path)
|
||||
.unwrap()
|
||||
.with_section(Some(selection))
|
||||
.get(key)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set(selection: &str, key: &str, value: &str) -> bool {
|
||||
let config_path: PathBuf = Path::new(&get_user_data_dir().unwrap())
|
||||
.join("blue-recorder")
|
||||
.join("config.ini");
|
||||
let mut config_init = Ini::load_from_file(&config_path).unwrap_or_default();
|
||||
config_init.with_section(Some(selection)).set(key, value);
|
||||
config_init.write_to_file(&config_path).is_ok()
|
||||
}
|
15
src/main.rs
15
src/main.rs
@ -1,12 +1,10 @@
|
||||
extern crate gio;
|
||||
extern crate gtk;
|
||||
extern crate glib;
|
||||
mod config_management;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use gio::prelude::*;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{Builder, Window};
|
||||
use glib::get_user_data_dir;
|
||||
use std::path::Path;
|
||||
fn main() {
|
||||
if gtk::init().is_err() {
|
||||
@ -15,15 +13,8 @@ fn main() {
|
||||
}
|
||||
let builder: Builder = Builder::from_file(Path::new("windows/ui.glade"));
|
||||
|
||||
// fatch and make the config file
|
||||
let config_path = Path::new(&get_user_data_dir().unwrap()).join("blue-recorder").join("config.ini");
|
||||
if !&config_path.exists() {
|
||||
let config_directories = &mut config_path.to_owned();
|
||||
config_directories.pop();
|
||||
std::fs::create_dir_all(&config_directories).unwrap_or_default();
|
||||
std::fs::File::create(&config_path).unwrap();
|
||||
}
|
||||
|
||||
config_management::initialize();
|
||||
config_management::set("default", "frame", "30");
|
||||
// get Objects from UI
|
||||
let main_window: Window = builder.get_object("window1").unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user