File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,17 +56,28 @@ pub fn get() -> &'static Config {
5656}
5757
5858fn load_config ( ) -> Config {
59- let config_path = dirs:: config_dir ( ) . map ( |p| p. join ( "appimageupdate" ) . join ( "config.toml" ) ) ;
59+ let portable = std:: env:: current_exe ( ) . ok ( ) . and_then ( |exe| {
60+ let dir = exe. parent ( ) ?;
61+ let name = exe. file_stem ( ) ?. to_str ( ) ?;
62+ Some ( dir. join ( format ! ( "{name}.toml" ) ) )
63+ } ) ;
6064
61- let config_path = match config_path {
62- Some ( p) if p. exists ( ) => p,
63- _ => return Config :: default ( ) ,
64- } ;
65+ let user = dirs:: config_dir ( ) . map ( |p| p. join ( "appimageupdate/config.toml" ) ) ;
6566
66- match std:: fs:: read_to_string ( & config_path) {
67- Ok ( content) => toml:: from_str ( & content) . unwrap_or_default ( ) ,
68- Err ( _) => Config :: default ( ) ,
69- }
67+ let global = Some ( PathBuf :: from ( "/etc/appimageupdate/config.toml" ) ) ;
68+
69+ portable
70+ . into_iter ( )
71+ . chain ( user)
72+ . chain ( global)
73+ . find_map ( try_load_config)
74+ . unwrap_or_default ( )
75+ }
76+
77+ fn try_load_config ( path : PathBuf ) -> Option < Config > {
78+ std:: fs:: read_to_string ( & path)
79+ . ok ( )
80+ . and_then ( |content| toml:: from_str ( & content) . ok ( ) )
7081}
7182
7283pub fn get_proxies ( ) -> Vec < String > {
You can’t perform that action at this time.
0 commit comments