@@ -5,86 +5,54 @@ use std::path::{Path, PathBuf};
5
5
use crate :: configuration:: consts:: {
6
6
CONFIGURATION_FILE , CONFIGURATION_FOLDER , INITIAL_PROMPT_FILE , PROMPTS_FOLDER ,
7
7
} ;
8
+ // Make sure you can access the embedded constants (either inline or in another mod)
9
+ use crate :: configuration:: embedded_assets:: { CONFIG_FILE_BYTES , INITIAL_PROMPT_FILE_BYTES } ;
8
10
9
11
pub fn init ( ) {
10
- let assets = get_runtime_assets_dir ( ) ;
11
- let in_project_config_path = assets. join ( CONFIGURATION_FILE ) ;
12
- let in_project_initial_prompt_path = assets. join ( PROMPTS_FOLDER ) . join ( INITIAL_PROMPT_FILE ) ;
13
-
14
12
create_application_config_folder ( ) ;
15
13
16
- let config_file_path = get_config_file_path ( ) ;
17
- create_application_config_file ( & config_file_path , in_project_config_path ) ;
14
+ let config_file_path = get_config_file_path ( ) ; // e.g. ~/.messy-folder-reorganizer-ai/config.toml
15
+ let initial_prompt_file_path = get_initial_prompt_file_path ( ) ; // e.g. ~/.messy-folder-reorganizer-ai/prompts/initial_prompt.txt
18
16
19
- let initial_prompt_file_path = get_initial_prompt_file_path ( ) ;
20
- create_application_config_file ( & initial_prompt_file_path, in_project_initial_prompt_path ) ;
17
+ create_application_file_if_missing ( & config_file_path , CONFIG_FILE_BYTES ) ;
18
+ create_application_file_if_missing ( & initial_prompt_file_path, INITIAL_PROMPT_FILE_BYTES ) ;
21
19
}
22
20
23
- /// Returns the correct path to the `assets/` directory for both `cargo run` and installed versions.
24
- fn get_runtime_assets_dir ( ) -> PathBuf {
25
- let exe_path = env:: current_exe ( ) . unwrap_or_else ( |_| PathBuf :: from ( "." ) ) ;
26
-
27
- // If running from Cargo (`target/debug/` or `target/release/`), go up twice to find `src/`
28
- if exe_path. to_string_lossy ( ) . contains ( "target/" ) {
29
- let manifest_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ; // Root of the project
30
- return manifest_dir. join ( "assets" ) ;
21
+ fn create_application_config_folder ( ) {
22
+ let home_dir = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
23
+ let config_dir = format ! ( "{}/.messy-folder-reorganizer-ai" , home_dir) ;
24
+ if !Path :: new ( & config_dir) . exists ( ) {
25
+ fs:: create_dir_all ( & config_dir) . expect ( "Failed to create config directory" ) ;
31
26
}
32
27
33
- // Otherwise, assume assets are in the same folder as the installed binary
34
- exe_path
35
- . parent ( )
36
- . map ( |dir| dir. join ( "assets" ) )
37
- . unwrap_or_else ( || PathBuf :: from ( "assets" ) )
28
+ let prompts_dir = format ! ( "{}/.messy-folder-reorganizer-ai/prompts" , home_dir) ;
29
+ if !Path :: new ( & prompts_dir) . exists ( ) {
30
+ fs:: create_dir_all ( & prompts_dir) . expect ( "Failed to create prompts directory" ) ;
31
+ }
38
32
}
39
33
40
34
pub fn get_config_file_path ( ) -> PathBuf {
41
- let home_dir: String = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
35
+ let home_dir = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
42
36
Path :: new ( & home_dir)
43
37
. join ( CONFIGURATION_FOLDER )
44
38
. join ( CONFIGURATION_FILE )
45
39
}
46
40
47
41
pub fn get_initial_prompt_file_path ( ) -> PathBuf {
48
- let home_dir: String = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
42
+ let home_dir = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
49
43
Path :: new ( & home_dir)
50
44
. join ( CONFIGURATION_FOLDER )
51
45
. join ( PROMPTS_FOLDER )
52
46
. join ( INITIAL_PROMPT_FILE )
53
47
}
54
48
55
- fn create_application_config_folder ( ) {
56
- let home_dir = env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
57
- let config_dir = format ! ( "{}/.messy-folder-reorganizer-ai" , home_dir) ;
58
- if !Path :: new ( & config_dir) . exists ( ) {
59
- fs:: create_dir_all ( & config_dir) . expect ( "Failed to create config directory" ) ;
60
- }
61
-
62
- let prompts_dir = format ! ( "{}/.messy-folder-reorganizer-ai/prompts" , home_dir) ;
63
- if !Path :: new ( & prompts_dir) . exists ( ) {
64
- fs:: create_dir_all ( & prompts_dir) . expect ( "Failed to create prompts directory" ) ;
65
- }
66
- }
67
-
68
- fn create_application_config_file ( config_file_path : & Path , source : PathBuf ) {
49
+ fn create_application_file_if_missing ( config_file_path : & Path , embedded_content : & [ u8 ] ) {
69
50
if !config_file_path. exists ( ) {
70
- // Ensure parent directory exists
71
51
if let Some ( parent) = config_file_path. parent ( ) {
72
52
fs:: create_dir_all ( parent) . expect ( "Failed to create parent directories" ) ;
73
53
}
74
54
75
- // Copy the file
76
- println ! ( "Copying from source: {:?}" , source) ;
77
- println ! ( "Copying to: {:?}" , config_file_path) ;
78
-
79
- match fs:: read ( & source) {
80
- Ok ( content) => {
81
- fs:: write ( config_file_path, content) . expect ( "Failed to copy config file" ) ;
82
- println ! ( "Initialized {:?} file." , config_file_path) ;
83
- }
84
- Err ( e) => {
85
- println ! ( "Warning: Could not read source file {:?} ({})" , source, e) ;
86
- panic ! ( "File one not found" ) ;
87
- }
88
- }
55
+ fs:: write ( config_file_path, embedded_content) . expect ( "Failed to write embedded content" ) ;
56
+ println ! ( "Initialized file: {:?}" , config_file_path) ;
89
57
}
90
58
}
0 commit comments