Skip to content

Commit

Permalink
feat: work with idiomatic Unix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticLampyrid committed Feb 21, 2024
1 parent 26708cd commit e60a7cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
15 changes: 3 additions & 12 deletions cli/src/cmake_project_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use regex::Regex;
use rhai::serde::to_dynamic;
use serde::{Deserialize, Serialize};
use std::{
env, fs, io,
fs, io,
path::{Path, PathBuf},
};

Expand All @@ -15,23 +15,14 @@ struct FilterInfo {
#[serde(default)]
overwrite: bool,
}
use crate::cproject_reader::CProjectInfo;
use crate::{cproject_reader::CProjectInfo, resources_dir::get_resources_path};

pub struct CMakeProjectGeneratorParams<'a> {
pub info: &'a CProjectInfo,
}

fn get_cmake_project_template_path() -> io::Result<PathBuf> {
let mut path = env::current_exe()?;
path.pop(); // File name
if cfg!(debug_assertions) {
path.pop(); // Debug folder
path.pop(); // Target folder
path.push("cli");
} else {
path.pop(); // Bin folder
}
path.push("resources");
let mut path = get_resources_path()?;
path.push("templates");
path.push("gcc");
Ok(path)
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod ninja_install;
mod openocd_install;
mod path_env;
mod reqwest_unified_builder;
mod resources_dir;
mod simple_template;
use clap::{Parser, Subcommand};
use error::InstallError;
Expand Down
19 changes: 19 additions & 0 deletions cli/src/resources_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::{env, io, path::PathBuf};

pub fn get_resources_path() -> io::Result<PathBuf> {
let mut path = env::current_exe()?;
path.pop(); // File name
if cfg!(debug_assertions) {
path.pop(); // Debug folder
path.pop(); // Target folder
path.push("cli");
} else {
path.pop(); // Bin folder
}
path.push("resources");
#[cfg(not(target_os = "windows"))]
if !path.exists() {
path = PathBuf::from("/var/lib/stm32tesseract/resources");
}
Ok(path)
}
10 changes: 9 additions & 1 deletion gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ static PATH_OF_CLI: Lazy<PathBuf> = Lazy::new(|| {
} else {
path_of_cli.push("stm32tesseract");
}
path_of_cli
if path_of_cli.exists() {
return path_of_cli;
}

if cfg!(target_os = "windows") {
PathBuf::from("stm32tesseract.exe")
} else {
PathBuf::from("stm32tesseract")
}
});

fn do_env_check(ui_handle: &Weak<AppWindow>) {
Expand Down

0 comments on commit e60a7cc

Please sign in to comment.