57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
#![windows_subsystem = "windows"]
|
|
|
|
#[cfg(target_os = "windows")]
|
|
extern crate native_windows_derive as nwd;
|
|
#[cfg(target_os = "windows")]
|
|
extern crate native_windows_gui as nwg;
|
|
|
|
mod cmd;
|
|
mod errors;
|
|
mod gpx;
|
|
|
|
#[cfg(target_os = "windows")]
|
|
mod ui;
|
|
|
|
use cmd::args::EnvOpt;
|
|
use errors::{GenericError, MessagedError};
|
|
use std::fs::File;
|
|
use std::io::prelude::*;
|
|
use std::path::PathBuf;
|
|
use thingy_lib::api::{LocationModel, TagModel};
|
|
use thingy_lib::Config;
|
|
|
|
fn main() {
|
|
let env: EnvOpt = argh::from_env();
|
|
if env.subcommand.is_some() {
|
|
if let Err(e) = cmd::from_env(env) {
|
|
eprintln!("Critical Error: {}", e);
|
|
std::process::exit(1);
|
|
}
|
|
} else {
|
|
#[cfg(target_os = "windows")]
|
|
if let Err(e) = ui::start_windows_ui(env) {
|
|
eprintln!("Critical Error: {}", e);
|
|
std::process::exit(1);
|
|
}
|
|
#[cfg(not(target_os = "windows"))]
|
|
println!("non-windows ui not supported. Please run with --help");
|
|
}
|
|
}
|
|
|
|
pub fn config_from_path(path: &PathBuf) -> Result<Config, GenericError> {
|
|
let mut file =
|
|
File::open(&path).with_msg(format!("Could not find {}", path.to_str().unwrap_or("")))?;
|
|
let mut string = String::new();
|
|
file.read_to_string(&mut string)
|
|
.with_msg("config file is not valid UTF-8")?;
|
|
|
|
Ok(toml::from_str(&string).with_msg("given config file is not a valid config file")?)
|
|
}
|
|
|
|
pub fn write_to(config: &Config, path: &PathBuf) -> Result<(), GenericError> {
|
|
let mut file = File::create(&path).unwrap();
|
|
file.write_all(&toml::to_vec(config).unwrap())
|
|
.with_msg("Could not write config.toml, make sure you have correct permissions.")?;
|
|
Ok(())
|
|
}
|