@@ -141,6 +141,21 @@ impl Config {
141141
142142 let mut port_config = if let Ok ( data) = read_to_string ( & port_config_file) {
143143 toml:: from_str ( & data) . into_diagnostic ( ) ?
144+ } else if let Ok ( data) = read_to_string ( & project_config_file) {
145+ if data. contains ( "[connection]" ) || data. contains ( "[[usb_device]]" ) {
146+ log:: info!(
147+ "espflash@3 configuration detected. Migrating port config to port_config_file: {:#?}" ,
148+ & port_config_file
149+ ) ;
150+ // Write the updated configs
151+ let port_config = toml:: from_str ( & data) . into_diagnostic ( ) ?;
152+ Self :: write_config ( & port_config, & port_config_file) ?;
153+ Self :: write_config ( & project_config, & project_config_file) ?;
154+
155+ port_config
156+ } else {
157+ PortConfig :: default ( )
158+ }
144159 } else {
145160 PortConfig :: default ( )
146161 } ;
@@ -153,26 +168,28 @@ impl Config {
153168 } )
154169 }
155170
171+ fn write_config < T : Serialize > ( config : & T , path : & PathBuf ) -> Result < ( ) > {
172+ let serialized = toml:: to_string ( config)
173+ . into_diagnostic ( )
174+ . wrap_err ( "Failed to serialize config" ) ?;
175+
176+ if let Some ( parent) = path. parent ( ) {
177+ create_dir_all ( parent)
178+ . into_diagnostic ( )
179+ . wrap_err ( "Failed to create config directory" ) ?;
180+ }
181+
182+ write ( path, serialized)
183+ . into_diagnostic ( )
184+ . wrap_err_with ( || format ! ( "Failed to write config to {}" , path. display( ) ) )
185+ }
186+
156187 /// Save port configuration to the configuration file
157188 pub fn save_with < F : Fn ( & mut Self ) > ( & self , modify_fn : F ) -> Result < ( ) > {
158189 let mut copy = self . clone ( ) ;
159190 modify_fn ( & mut copy) ;
160191
161- let serialized = toml:: to_string ( & copy. port_config )
162- . into_diagnostic ( )
163- . wrap_err ( "Failed to serialize config" ) ?;
164-
165- create_dir_all ( self . port_config . save_path . parent ( ) . unwrap ( ) )
166- . into_diagnostic ( )
167- . wrap_err ( "Failed to create config directory" ) ?;
168- write ( & self . port_config . save_path , serialized)
169- . into_diagnostic ( )
170- . wrap_err_with ( || {
171- format ! (
172- "Failed to write config to {}" ,
173- self . port_config. save_path. display( )
174- )
175- } )
192+ Self :: write_config ( & copy. port_config , & self . port_config . save_path )
176193 }
177194
178195 fn project_config_path ( ) -> Result < PathBuf , Error > {
0 commit comments