From d4906313415c4aded3d5ff4df8e7f28629939776 Mon Sep 17 00:00:00 2001 From: Couleur <82747632+couleurm@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:52:03 +0200 Subject: [PATCH 1/8] gate SM_ALLOW_MISC_OUTPUT --- src/cmd.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cmd.rs b/src/cmd.rs index 8b8c17a..72bc501 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -35,7 +35,14 @@ pub fn build_commands(args: Arguments, payloads: Vec, recipe: Recipe) - .display() .to_string() } else { - ff_path + let is_ffmpeg: bool = ff_path.ends_with("ffmpeg") || ff_path.ends_with("ffmpeg.exe"); + let r#override: bool = env::var("SM_ALLOW_MISC_OUTPUT") == Ok("1".to_owned()); + + if !is_ffmpeg && !r#override { + panic!("You specified an output process which does not have the filename 'ffmpeg', to override this error message please set the environment variable SM_ALLOW_MISC_OUTPUT to 1"); + } else { + ff_path + } } }; From bff2c8ddadfc7817318c65091b843e57f9f5040d Mon Sep 17 00:00:00 2001 From: Hzqkii <128440086+Hzqkii@users.noreply.github.com> Date: Fri, 7 Jun 2024 10:52:44 +0000 Subject: [PATCH 2/8] Fix issues for appimage. FIX: last args created in same folder --- src/cli.rs | 40 ++++++++++++++++++++++++++++++++++------ src/main.rs | 6 +++--- src/parse.rs | 12 +++++++++++- src/recipe.rs | 28 +++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 43bb03a..d9b5616 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -177,6 +177,11 @@ If you'd like help, take a screenshot of this message and your recipe and come o Some(arg) => arg, None => "".to_string(), }; + // Fix scoping issues + let _ini_path: PathBuf; + let home_dir: PathBuf; + let mut config_path: PathBuf = Default::default(); + let mut local_path: PathBuf = Default::default(); let current_exe = env::current_exe().expect("Could not determine exe"); let current_exe_path = current_exe @@ -186,18 +191,39 @@ If you'd like help, take a screenshot of this message and your recipe and come o let current_exe_path_dir = current_exe_path .parent() .expect("Could not get directory of directory's executable??"); - + + + // Linux stuff + #[cfg(not(target_os = "windows"))] { + home_dir = env::home_dir().expect("How do you not have a user dir?"); + config_path = home_dir.join(".config/smoothie-rs"); + if !config_path.exists() { + panic!("expected folder @ {}", config_path.display()); + } + local_path = home_dir.join(".local/share"); + local_path.push("smoothie-rs"); + if !local_path.exists() { + panic!("expected folder @ {}", local_path.display()); + } + + } + #[cfg(target_os = "windows")] let mut last_args = current_exe_path_dir.join("last_args.txt"); + + #[cfg(not(target_os = "windows"))] + let mut last_args = local_path.join("last_args.txt"); + if !last_args.exists() { if File::create(&last_args).is_err() { - panic!("Failed to create last_args.txt at {current_exe_path_dir:?}") + panic!("Failed to create last_args.txt at {}\nlocal_path: {}", last_args.display(), local_path.display()) }; } match first_arg.as_ref() { "enc" | "encoding" | "presets" | "encpresets" | "macros" => { - let presets_path = current_exe_path.join("..").join("encoding_presets.ini"); - + let _presets_path = current_exe_path.join("..").join("encoding_presets.ini"); + #[cfg(not(target_os = "windows"))] + let presets_path = config_path.join("encoding_presets.ini"); if !presets_path.exists() { panic!( "Could not find encoding presets (expected at {})", @@ -239,8 +265,10 @@ If you'd like help, take a screenshot of this message and your recipe and come o } } "rc" | "recipe" | "conf" | "config" => { - let ini_path = current_exe_path.join("..").join("recipe.ini"); - + #[cfg(target_os = "windows")] + let _ini_path = current_exe_path.join("..").join("recipe.ini"); + #[cfg(not(target_os = "windows"))] + let ini_path = config_path.join("recipe.ini"); if !ini_path.exists() { panic!("Could not find recipe at {}", ini_path.display()) } diff --git a/src/main.rs b/src/main.rs index f3b3e5d..d1afe90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ mod utils; mod video; use crate::{cli::Arguments, cmd::SmCommand, video::Payload}; -use std::{env, sync::mpsc::channel}; +use std::{sync::mpsc::channel}; use utils::verbosity_init; const VIDEO_EXTENSIONS: &[&str] = &[ @@ -94,7 +94,7 @@ fn main() { }; let env_var = std::env::var("SM_NOWINDOWINTERACT"); - let interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); + let _interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); #[cfg(windows)] if interact { @@ -119,7 +119,7 @@ fn main() { } } - if let Ok((args, recipe, hwnd)) = receiver.recv() { + if let Ok((args, recipe, _hwnd)) = receiver.recv() { #[cfg(windows)] unsafe { let _ret = windows::Win32::UI::WindowsAndMessaging::DestroyWindow(hwnd.unwrap()); diff --git a/src/parse.rs b/src/parse.rs index 2cc58bb..730e630 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -5,7 +5,6 @@ use color_eyre::owo_colors::OwoColorize; use colored::Colorize; use serde::Deserialize; use std::env; -use std::env::current_exe; use std::time::Duration; use ureq::{Agent, Error as uReqError}; @@ -17,6 +16,7 @@ pub fn parse_encoding_args(args: &Arguments, rc: &Recipe) -> String { }; let mut enc_arg_presets: Recipe = Recipe::new(); + #[cfg(target_os = "windows")] parse_recipe( current_exe() .expect("Failed getting exe path") @@ -30,6 +30,16 @@ pub fn parse_encoding_args(args: &Arguments, rc: &Recipe) -> String { &mut None, false, ); + #[cfg(not(target_os = "windows"))] + parse_recipe( + env::home_dir() + .expect("YOU DONT HAVE HOME DIR??????") + .join(".config/smoothie-rs/encoding_presets.ini"), + None, + &mut enc_arg_presets, + &mut None, + false, + ); // dbg!(&enc_arg_presets); let mut codec = String::new(); // e.g H264, H265 diff --git a/src/recipe.rs b/src/recipe.rs index 1056c6c..0ec3466 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -394,10 +394,36 @@ pub fn get_recipe(args: &mut Arguments) -> (Recipe, WidgetMetadata) { None => panic!("Could not resolve Smoothie's binary directory `{exe:?}`"), }; + let home_dir: PathBuf; + let config_path: PathBuf = Default::default(); + let local_path: PathBuf = Default::default(); + let cur_dir_sc: PathBuf = Default::default(); + + let mut config_path: PathBuf = Default::default(); + let mut local_path: PathBuf = Default::default(); + + #[cfg(not(target_os = "windows"))] + { + home_dir = env::home_dir().expect("How do you not have a user dir?"); + config_path = home_dir.join(".config/smoothie-rs"); + if !config_path.exists() { + panic!("ERROR: expected folder not found @ {}", config_path.display()); + } + + local_path = home_dir.join(".local/share/smoothie-rs"); + if !local_path.exists() { + panic!("ERROR: expected folder not found @ {}", local_path.display()); + } + } + let rc_path = if PathBuf::from(&args.recipe).exists() { PathBuf::from(&args.recipe) } else { - let cur_dir_rc = bin_dir.join(&args.recipe); + let cur_dir_rc = if cfg!(target_os = "windows") { + bin_dir.join(&args.recipe) + } else { + config_path.join(&args.recipe) + }; if !cur_dir_rc.exists() { panic!( "Recipe filepath does not exist (expected at {})", From 7f9c3f2cab2306514425a9926ad0727ab0d6d4f1 Mon Sep 17 00:00:00 2001 From: Hzqkii <128440086+Hzqkii@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:38:39 -0700 Subject: [PATCH 3/8] Update main.rs --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index d1afe90..f3b3e5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ mod utils; mod video; use crate::{cli::Arguments, cmd::SmCommand, video::Payload}; -use std::{sync::mpsc::channel}; +use std::{env, sync::mpsc::channel}; use utils::verbosity_init; const VIDEO_EXTENSIONS: &[&str] = &[ @@ -94,7 +94,7 @@ fn main() { }; let env_var = std::env::var("SM_NOWINDOWINTERACT"); - let _interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); + let interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); #[cfg(windows)] if interact { @@ -119,7 +119,7 @@ fn main() { } } - if let Ok((args, recipe, _hwnd)) = receiver.recv() { + if let Ok((args, recipe, hwnd)) = receiver.recv() { #[cfg(windows)] unsafe { let _ret = windows::Win32::UI::WindowsAndMessaging::DestroyWindow(hwnd.unwrap()); From 82f320cb61b2f2f3014c6a198a8245f856ad33b1 Mon Sep 17 00:00:00 2001 From: Hzqkii <128440086+Hzqkii@users.noreply.github.com> Date: Sun, 21 Jul 2024 05:55:54 +0000 Subject: [PATCH 4/8] Fix windows compilation. --- Cargo.toml | 2 +- src/cli.rs | 9 +++++---- src/parse.rs | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a561c0c..46f8ec2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ image = "0.25.1" # load icon copypasta = "0.10.1" # copy to clipboard winapi = "0.3.9" -windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"]} +windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging", "wincon"]} [build-dependencies] winres = "0.1" # give the exe an icon diff --git a/src/cli.rs b/src/cli.rs index d9b5616..582be20 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -178,7 +178,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o None => "".to_string(), }; // Fix scoping issues - let _ini_path: PathBuf; + let ini_path: PathBuf; let home_dir: PathBuf; let mut config_path: PathBuf = Default::default(); let mut local_path: PathBuf = Default::default(); @@ -215,13 +215,14 @@ If you'd like help, take a screenshot of this message and your recipe and come o if !last_args.exists() { if File::create(&last_args).is_err() { - panic!("Failed to create last_args.txt at {}\nlocal_path: {}", last_args.display(), local_path.display()) + panic!("Failed to create last_args.txt at {last_args:?}") }; } match first_arg.as_ref() { "enc" | "encoding" | "presets" | "encpresets" | "macros" => { - let _presets_path = current_exe_path.join("..").join("encoding_presets.ini"); + #[cfg(target_os = "windows")] + let presets_path = current_exe_path.join("..").join("encoding_presets.ini"); #[cfg(not(target_os = "windows"))] let presets_path = config_path.join("encoding_presets.ini"); if !presets_path.exists() { @@ -266,7 +267,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o } "rc" | "recipe" | "conf" | "config" => { #[cfg(target_os = "windows")] - let _ini_path = current_exe_path.join("..").join("recipe.ini"); + let ini_path = current_exe_path.join("..").join("recipe.ini"); #[cfg(not(target_os = "windows"))] let ini_path = config_path.join("recipe.ini"); if !ini_path.exists() { diff --git a/src/parse.rs b/src/parse.rs index 730e630..100a9cf 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -5,6 +5,7 @@ use color_eyre::owo_colors::OwoColorize; use colored::Colorize; use serde::Deserialize; use std::env; +use std::env::current_exe; use std::time::Duration; use ureq::{Agent, Error as uReqError}; From ea69fb63813cd3beffcaf60f5c9da2c3e0367f4d Mon Sep 17 00:00:00 2001 From: Hzqkii <128440086+Hzqkii@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:59:38 -0700 Subject: [PATCH 5/8] Update Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46f8ec2..7eb7cc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,8 +37,8 @@ winit = "0.30.0" # load icon image = "0.25.1" # load icon copypasta = "0.10.1" # copy to clipboard -winapi = "0.3.9" -windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging", "wincon"]} +winapi = { version = "0.3.9", features = ["wincon"] } +windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"]} [build-dependencies] winres = "0.1" # give the exe an icon From 2440624cee1f7d176ff0f5654143439ed79822ad Mon Sep 17 00:00:00 2001 From: Hzqkii <128440086+Hzqkii@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:38:39 -0700 Subject: [PATCH 6/8] Update main.rs Fix windows compilation. Update Cargo.toml --- Cargo.toml | 2 +- src/cli.rs | 9 +++++---- src/main.rs | 6 +++--- src/parse.rs | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a561c0c..7eb7cc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ winit = "0.30.0" # load icon image = "0.25.1" # load icon copypasta = "0.10.1" # copy to clipboard -winapi = "0.3.9" +winapi = { version = "0.3.9", features = ["wincon"] } windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"]} [build-dependencies] diff --git a/src/cli.rs b/src/cli.rs index d9b5616..582be20 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -178,7 +178,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o None => "".to_string(), }; // Fix scoping issues - let _ini_path: PathBuf; + let ini_path: PathBuf; let home_dir: PathBuf; let mut config_path: PathBuf = Default::default(); let mut local_path: PathBuf = Default::default(); @@ -215,13 +215,14 @@ If you'd like help, take a screenshot of this message and your recipe and come o if !last_args.exists() { if File::create(&last_args).is_err() { - panic!("Failed to create last_args.txt at {}\nlocal_path: {}", last_args.display(), local_path.display()) + panic!("Failed to create last_args.txt at {last_args:?}") }; } match first_arg.as_ref() { "enc" | "encoding" | "presets" | "encpresets" | "macros" => { - let _presets_path = current_exe_path.join("..").join("encoding_presets.ini"); + #[cfg(target_os = "windows")] + let presets_path = current_exe_path.join("..").join("encoding_presets.ini"); #[cfg(not(target_os = "windows"))] let presets_path = config_path.join("encoding_presets.ini"); if !presets_path.exists() { @@ -266,7 +267,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o } "rc" | "recipe" | "conf" | "config" => { #[cfg(target_os = "windows")] - let _ini_path = current_exe_path.join("..").join("recipe.ini"); + let ini_path = current_exe_path.join("..").join("recipe.ini"); #[cfg(not(target_os = "windows"))] let ini_path = config_path.join("recipe.ini"); if !ini_path.exists() { diff --git a/src/main.rs b/src/main.rs index d1afe90..f3b3e5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ mod utils; mod video; use crate::{cli::Arguments, cmd::SmCommand, video::Payload}; -use std::{sync::mpsc::channel}; +use std::{env, sync::mpsc::channel}; use utils::verbosity_init; const VIDEO_EXTENSIONS: &[&str] = &[ @@ -94,7 +94,7 @@ fn main() { }; let env_var = std::env::var("SM_NOWINDOWINTERACT"); - let _interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); + let interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned(); #[cfg(windows)] if interact { @@ -119,7 +119,7 @@ fn main() { } } - if let Ok((args, recipe, _hwnd)) = receiver.recv() { + if let Ok((args, recipe, hwnd)) = receiver.recv() { #[cfg(windows)] unsafe { let _ret = windows::Win32::UI::WindowsAndMessaging::DestroyWindow(hwnd.unwrap()); diff --git a/src/parse.rs b/src/parse.rs index 730e630..100a9cf 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -5,6 +5,7 @@ use color_eyre::owo_colors::OwoColorize; use colored::Colorize; use serde::Deserialize; use std::env; +use std::env::current_exe; use std::time::Duration; use ureq::{Agent, Error as uReqError}; From 4d41007dd256dd37d31a1c11ccc714fe82c27bb0 Mon Sep 17 00:00:00 2001 From: hybridkernel Date: Fri, 10 Jan 2025 04:54:35 +1100 Subject: [PATCH 7/8] FIX: silent fails with release build, and clean spaghetti code --- Cargo.toml | 1 + src/cli.rs | 35 +++++---------------- src/main.rs | 1 + src/parse.rs | 22 ++----------- src/portable.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ src/recipe.rs | 29 ++--------------- 6 files changed, 95 insertions(+), 75 deletions(-) create mode 100644 src/portable.rs diff --git a/Cargo.toml b/Cargo.toml index 7eb7cc2..d55bb6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ copypasta = "0.10.1" # copy to clipboard winapi = { version = "0.3.9", features = ["wincon"] } windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"]} +homedir = "0.3.4" [build-dependencies] winres = "0.1" # give the exe an icon diff --git a/src/cli.rs b/src/cli.rs index 582be20..dcc35f3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,7 +1,10 @@ use clap::Parser; use std::fs::File; +use std::fs; use std::io::{Read, Write}; use std::{env, path::PathBuf, process::Command}; +use crate::portable; +use homedir; /// Smoothen up your gameplay footage with Smoothie, yum! #[derive(Parser, Debug, Clone)] @@ -193,25 +196,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o .expect("Could not get directory of directory's executable??"); - // Linux stuff - #[cfg(not(target_os = "windows"))] { - home_dir = env::home_dir().expect("How do you not have a user dir?"); - config_path = home_dir.join(".config/smoothie-rs"); - if !config_path.exists() { - panic!("expected folder @ {}", config_path.display()); - } - local_path = home_dir.join(".local/share"); - local_path.push("smoothie-rs"); - if !local_path.exists() { - panic!("expected folder @ {}", local_path.display()); - } - - } - #[cfg(target_os = "windows")] - let mut last_args = current_exe_path_dir.join("last_args.txt"); - - #[cfg(not(target_os = "windows"))] - let mut last_args = local_path.join("last_args.txt"); + let mut last_args = portable::get_last_args_path(); if !last_args.exists() { if File::create(&last_args).is_err() { @@ -221,10 +206,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o match first_arg.as_ref() { "enc" | "encoding" | "presets" | "encpresets" | "macros" => { - #[cfg(target_os = "windows")] - let presets_path = current_exe_path.join("..").join("encoding_presets.ini"); - #[cfg(not(target_os = "windows"))] - let presets_path = config_path.join("encoding_presets.ini"); + let presets_path = portable::get_encoding_presets_path(); if !presets_path.exists() { panic!( "Could not find encoding presets (expected at {})", @@ -244,7 +226,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o } } "def" | "default" | "defaults" => { - let presets_path = current_exe_path.join("..").join("defaults.ini"); + let presets_path = portable::get_defaults_path(); if !presets_path.exists() { panic!( @@ -266,10 +248,7 @@ If you'd like help, take a screenshot of this message and your recipe and come o } } "rc" | "recipe" | "conf" | "config" => { - #[cfg(target_os = "windows")] - let ini_path = current_exe_path.join("..").join("recipe.ini"); - #[cfg(not(target_os = "windows"))] - let ini_path = config_path.join("recipe.ini"); + let ini_path = portable::get_recipe_path(); if !ini_path.exists() { panic!("Could not find recipe at {}", ini_path.display()) } diff --git a/src/main.rs b/src/main.rs index f3b3e5d..312853b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ mod smgui; // mod ffpb; // mod ffpb2; mod parse; +mod portable; mod recipe; mod render; mod utils; diff --git a/src/parse.rs b/src/parse.rs index 100a9cf..829526b 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,11 +1,11 @@ use crate::cli::Arguments; +use crate::portable; use crate::recipe::{parse_recipe, Recipe}; use crate::verb; use color_eyre::owo_colors::OwoColorize; use colored::Colorize; use serde::Deserialize; use std::env; -use std::env::current_exe; use std::time::Duration; use ureq::{Agent, Error as uReqError}; @@ -17,31 +17,13 @@ pub fn parse_encoding_args(args: &Arguments, rc: &Recipe) -> String { }; let mut enc_arg_presets: Recipe = Recipe::new(); - #[cfg(target_os = "windows")] parse_recipe( - current_exe() - .expect("Failed getting exe path") - .parent() - .expect("Failed getting exe parent path") - .parent() - .unwrap() - .join("encoding_presets.ini"), + portable::get_encoding_presets_path(), None, &mut enc_arg_presets, &mut None, false, ); - #[cfg(not(target_os = "windows"))] - parse_recipe( - env::home_dir() - .expect("YOU DONT HAVE HOME DIR??????") - .join(".config/smoothie-rs/encoding_presets.ini"), - None, - &mut enc_arg_presets, - &mut None, - false, - ); - // dbg!(&enc_arg_presets); let mut codec = String::new(); // e.g H264, H265 let mut ret = String::new(); diff --git a/src/portable.rs b/src/portable.rs new file mode 100644 index 0000000..ba7beff --- /dev/null +++ b/src/portable.rs @@ -0,0 +1,82 @@ +use std::{env, path::PathBuf, fs}; +use homedir; + +const DEFAULT_RECIPE: &str = include_str!("../target/recipe.ini"); +const DEFAULT_ENCODING_PRESETS: &str = include_str!("../target/encoding_presets.ini"); + +fn get_target_path() -> PathBuf { + let current_exe = env::current_exe().expect("Could not determine exe"); + let target_dir = current_exe.parent() + .expect("Could not get directory of executable") + .parent() + .expect("Could not get directory of directory's executable??"); + return target_dir.to_path_buf(); +} + +fn is_portable() -> bool { + let portable = get_target_path().join("linux-portable-enable"); + return portable.exists(); +} + +pub fn get_config_path() -> PathBuf { + let config_path: PathBuf; + + if cfg!(target_os = "windows") || is_portable() { + config_path = get_target_path(); + } else { + let home_dir = homedir::my_home() + .unwrap() + .expect("How do you not have a user dir?"); + config_path = home_dir.join(".config/smoothie-rs"); + if !config_path.exists() { + fs::create_dir_all(&config_path) + .expect("Failed to create config folder"); + } + } + + return config_path; +} + +pub fn get_recipe_path() -> PathBuf { + let recipe_path = get_config_path().join("recipe.ini"); + if !recipe_path.exists() { + fs::write(&recipe_path, DEFAULT_RECIPE).unwrap(); + } + return recipe_path; +} + +pub fn get_encoding_presets_path() -> PathBuf { + let encoding_presets_path = get_config_path().join("encoding_presets.ini"); + if !encoding_presets_path.exists() { + fs::write(&encoding_presets_path, DEFAULT_ENCODING_PRESETS).unwrap(); + } + return encoding_presets_path; +} + +pub fn get_defaults_path() -> PathBuf { + return get_target_path().join("defaults.ini"); +} + +pub fn get_last_args_path() -> PathBuf { + let last_args: PathBuf; + + if cfg!(target_os = "windows") || is_portable() { + last_args = get_target_path() + .join("last_args.txt"); + } else { + let home_dir = homedir::my_home() + .unwrap() + .expect("How do you not have a user dir?"); + last_args = home_dir.join(".local/share/smoothie-rs/last_args.txt"); + if !last_args.exists() { + fs::create_dir_all( + last_args + .parent() + .unwrap()) + .expect("Failed to create local folder" + ); + } + } + + return last_args; +} diff --git a/src/recipe.rs b/src/recipe.rs index 0ec3466..2efc532 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -1,6 +1,7 @@ use crate::cli::Arguments; use crate::verb; use crate::{NO, YES}; +use crate::portable; use indexmap::map::Entry; use indexmap::map::IndexMap; use indexmap::map::Keys; @@ -394,36 +395,10 @@ pub fn get_recipe(args: &mut Arguments) -> (Recipe, WidgetMetadata) { None => panic!("Could not resolve Smoothie's binary directory `{exe:?}`"), }; - let home_dir: PathBuf; - let config_path: PathBuf = Default::default(); - let local_path: PathBuf = Default::default(); - let cur_dir_sc: PathBuf = Default::default(); - - let mut config_path: PathBuf = Default::default(); - let mut local_path: PathBuf = Default::default(); - - #[cfg(not(target_os = "windows"))] - { - home_dir = env::home_dir().expect("How do you not have a user dir?"); - config_path = home_dir.join(".config/smoothie-rs"); - if !config_path.exists() { - panic!("ERROR: expected folder not found @ {}", config_path.display()); - } - - local_path = home_dir.join(".local/share/smoothie-rs"); - if !local_path.exists() { - panic!("ERROR: expected folder not found @ {}", local_path.display()); - } - } - let rc_path = if PathBuf::from(&args.recipe).exists() { PathBuf::from(&args.recipe) } else { - let cur_dir_rc = if cfg!(target_os = "windows") { - bin_dir.join(&args.recipe) - } else { - config_path.join(&args.recipe) - }; + let cur_dir_rc = portable::get_recipe_path(); if !cur_dir_rc.exists() { panic!( "Recipe filepath does not exist (expected at {})", From 2f53a995a75cddf0e986610b2ddb972d0e6033bb Mon Sep 17 00:00:00 2001 From: hybridkernel Date: Sun, 12 Jan 2025 03:00:55 +1100 Subject: [PATCH 8/8] Address overlooked --recipe --- src/portable.rs | 7 ++++++- src/recipe.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/portable.rs b/src/portable.rs index ba7beff..e00861e 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -37,8 +37,13 @@ pub fn get_config_path() -> PathBuf { return config_path; } +pub fn get_recipe_path_custom(recipe_name : &str) -> PathBuf { + let recipe_path = get_config_path().join(recipe_name); + return recipe_path; +} + pub fn get_recipe_path() -> PathBuf { - let recipe_path = get_config_path().join("recipe.ini"); + let recipe_path = get_recipe_path_custom("recipe.ini"); if !recipe_path.exists() { fs::write(&recipe_path, DEFAULT_RECIPE).unwrap(); } diff --git a/src/recipe.rs b/src/recipe.rs index 2efc532..c51690a 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -398,7 +398,7 @@ pub fn get_recipe(args: &mut Arguments) -> (Recipe, WidgetMetadata) { let rc_path = if PathBuf::from(&args.recipe).exists() { PathBuf::from(&args.recipe) } else { - let cur_dir_rc = portable::get_recipe_path(); + let cur_dir_rc = portable::get_recipe_path_custom(&args.recipe); if !cur_dir_rc.exists() { panic!( "Recipe filepath does not exist (expected at {})",