mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-28 12:56:57 +02:00
convert to workspace, add suil bindings crate
This commit is contained in:
parent
bd6f8ff9bf
commit
dacce119c4
52 changed files with 1994 additions and 116 deletions
|
|
@ -1,51 +0,0 @@
|
|||
//! Global settings.
|
||||
|
||||
use crate::core::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::{File, create_dir_all};
|
||||
|
||||
const CONFIG_FILE_NAME: &'static str = "tek.toml";
|
||||
const PROJECT_FILE_NAME: &'static str = "project.toml";
|
||||
|
||||
/// Filesystem locations of things.
|
||||
pub struct AppPaths {
|
||||
config_dir: PathBuf,
|
||||
config_file: PathBuf,
|
||||
data_dir: PathBuf,
|
||||
project_file: PathBuf,
|
||||
}
|
||||
impl AppPaths {
|
||||
pub fn new (xdg: &XdgApp) -> Usually<Self> {
|
||||
let config_dir = PathBuf::from(xdg.app_config()?);
|
||||
let config_file = PathBuf::from(config_dir.join(CONFIG_FILE_NAME));
|
||||
let data_dir = PathBuf::from(xdg.app_data()?);
|
||||
let project_file = PathBuf::from(data_dir.join(PROJECT_FILE_NAME));
|
||||
Ok(Self { config_dir, config_file, data_dir, project_file })
|
||||
}
|
||||
pub fn should_create (&self) -> bool {
|
||||
for path in [
|
||||
&self.config_dir,
|
||||
&self.config_file,
|
||||
&self.data_dir,
|
||||
&self.project_file,
|
||||
].iter() {
|
||||
if !Path::new(path).exists() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
pub fn create (&self) -> Usually<()> {
|
||||
for dir in [&self.config_dir, &self.data_dir].iter() {
|
||||
if !Path::new(dir).exists() {
|
||||
create_dir_all(&dir)?;
|
||||
}
|
||||
}
|
||||
for file in [&self.config_file, &self.project_file].iter() {
|
||||
if !Path::new(file).exists() {
|
||||
File::create_new(&file)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue