@@ -107,9 +107,9 @@ use std::env;
107107use std:: fs;
108108use std:: path:: PathBuf ;
109109
110- const STATIC_PREFS : & str = "../engine/ modules/libpref/init/zen-static-prefs.inc" ;
111- const FIREFOX_PREFS : & str = "../engine/ browser/app/profile/firefox.js" ;
112- const DYNAMIC_PREFS : & str = "../engine/ browser/app/profile/zen.js" ;
110+ const STATIC_PREFS : & str = "modules/libpref/init/zen-static-prefs.inc" ;
111+ const FIREFOX_PREFS : & str = "browser/app/profile/firefox.js" ;
112+ const DYNAMIC_PREFS : & str = "browser/app/profile/zen.js" ;
113113
114114#[ derive( Serialize , Deserialize , PartialEq , Debug ) ]
115115struct Preference {
@@ -124,12 +124,6 @@ struct Preference {
124124 sticky : Option < bool > ,
125125}
126126
127- fn get_config_path ( ) -> PathBuf {
128- let mut path = env:: current_dir ( ) . expect ( "Failed to get current directory" ) ;
129- path. push ( "prefs" ) ;
130- path
131- }
132-
133127fn ordered_prefs ( mut prefs : Vec < Preference > ) -> Vec < Preference > {
134128 // Sort preferences by name
135129 prefs. sort_by ( |a, b| a. name . cmp ( & b. name ) ) ;
@@ -153,11 +147,10 @@ fn get_prefs_files_recursively(dir: &PathBuf, files: &mut Vec<PathBuf>) {
153147 }
154148}
155149
156- fn load_preferences ( ) -> Vec < Preference > {
150+ fn load_preferences ( prefs_path : & PathBuf ) -> Vec < Preference > {
157151 let mut prefs = Vec :: new ( ) ;
158- let config_path = get_config_path ( ) ;
159152 let mut pref_files = Vec :: new ( ) ;
160- get_prefs_files_recursively ( & config_path , & mut pref_files) ;
153+ get_prefs_files_recursively ( & prefs_path , & mut pref_files) ;
161154 for file_path in pref_files {
162155 let content = fs:: read_to_string ( & file_path) . expect ( "Failed to read file" ) ;
163156 let mut parsed_prefs: Vec < Preference > =
@@ -263,14 +256,9 @@ fn get_value(pref: &Preference) -> String {
263256 }
264257}
265258
266- fn write_preferences ( prefs : & [ Preference ] ) {
267- let config_path = get_config_path ( ) ;
268- if !config_path. exists ( ) {
269- fs:: create_dir_all ( & config_path) . expect ( "Failed to create prefs directory" ) ;
270- }
271-
272- let static_prefs_path = config_path. join ( STATIC_PREFS ) ;
273- let dynamic_prefs_path = config_path. join ( DYNAMIC_PREFS ) ;
259+ fn write_preferences ( engine_path : & PathBuf , prefs : & [ Preference ] ) {
260+ let static_prefs_path = engine_path. join ( STATIC_PREFS ) ;
261+ let dynamic_prefs_path = engine_path. join ( DYNAMIC_PREFS ) ;
274262 println ! (
275263 "Writing preferences to:\n Static: {}\n Dynamic: {}" ,
276264 static_prefs_path. display( ) ,
@@ -300,10 +288,10 @@ fn write_preferences(prefs: &[Preference]) {
300288 fs:: write ( & dynamic_prefs_path, dynamic_content) . expect ( "Failed to write dynamic prefs" ) ;
301289}
302290
303- fn prepare_zen_prefs ( ) {
291+ fn prepare_zen_prefs ( engine_path : & PathBuf ) {
304292 // Add `#include zen.js` to the bottom of the firefox.js file if it doesn't exist
305293 let line = "#include zen.js" ;
306- let firefox_prefs_path = get_config_path ( ) . join ( FIREFOX_PREFS ) ;
294+ let firefox_prefs_path = engine_path . join ( FIREFOX_PREFS ) ;
307295 if let Ok ( mut content) = fs:: read_to_string ( & firefox_prefs_path) {
308296 if !content. contains ( line) {
309297 content. push_str ( format ! ( "\n {}\n " , line) . as_str ( ) ) ;
@@ -351,15 +339,14 @@ fn expand_pref_values(prefs: &mut [Preference]) {
351339
352340fn main ( ) {
353341 let args: Vec < String > = env:: args ( ) . collect ( ) ;
354- let root_path = if args. len ( ) > 1 {
355- PathBuf :: from ( & args[ 1 ] )
356- } else {
357- env:: current_dir ( ) . expect ( "Failed to get current directory" )
358- } ;
359- env:: set_current_dir ( & root_path) . expect ( "Failed to change directory" ) ;
342+ if args. len ( ) != 3 {
343+ panic ! ( "Must specify exactly two directories: prefs and engine" ) ;
344+ }
345+ let prefs_path = PathBuf :: from ( & args[ 1 ] ) ;
346+ let engine_path = PathBuf :: from ( & args[ 2 ] ) ;
360347
361- prepare_zen_prefs ( ) ;
362- let mut preferences = load_preferences ( ) ;
348+ prepare_zen_prefs ( & engine_path ) ;
349+ let mut preferences = load_preferences ( & prefs_path ) ;
363350 expand_pref_values ( & mut preferences) ;
364- write_preferences ( & preferences) ;
351+ write_preferences ( & engine_path , & preferences) ;
365352}
0 commit comments