Skip to content

Commit be26266

Browse files
authored
IEP-952: Espressif IDE popup for old tool versions popping up after installing tools via IDE (#770)
Update the idf path in the esp_idf.json file in case user presses no
1 parent 377166f commit be26266

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.beans.PropertyChangeListener;
99
import java.io.File;
1010
import java.io.FileReader;
11+
import java.io.FileWriter;
1112
import java.io.IOException;
1213
import java.net.URL;
1314
import java.text.MessageFormat;
@@ -48,7 +49,7 @@ public class InitializeToolsStartup implements IStartup
4849
/**
4950
* esp-idf.json is file created by the installer
5051
*/
51-
private static final String ESP_IDF_JSON_FILE = "esp_idf.json"; //$NON-NLS-1$
52+
public static final String ESP_IDF_JSON_FILE = "esp_idf.json"; //$NON-NLS-1$
5253

5354
// Variables defined in the esp-idf.json file
5455
private static final String GIT_PATH = "gitPath"; //$NON-NLS-1$
@@ -118,6 +119,8 @@ else if (isInstallerConfigSet())
118119
int response = messageBox.open();
119120
if (response == SWT.NO)
120121
{
122+
IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables();
123+
updateEspIdfJsonFile(idf_json_file, idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.IDF_PATH));
121124
Preferences prefs = getPreferences();
122125
prefs.putBoolean(IS_INSTALLER_CONFIG_SET, true);
123126
try
@@ -194,6 +197,49 @@ else if (isInstallerConfigSet())
194197
Logger.log(e);
195198
}
196199
}
200+
201+
@SuppressWarnings("unchecked")
202+
private void updateEspIdfJsonFile(File idf_json_file, String newIdfPathToUpdate)
203+
{
204+
JSONParser parser = new JSONParser();
205+
JSONObject jsonObj = null;
206+
try (FileReader reader = new FileReader(idf_json_file))
207+
{
208+
jsonObj = (JSONObject) parser.parse(reader);
209+
String idfVersionId = (String) jsonObj.get(IDF_VERSIONS_ID);
210+
JSONObject list = (JSONObject) jsonObj.get(IDF_INSTALLED_LIST_KEY);
211+
if (list == null)
212+
{
213+
return;
214+
}
215+
// selected esp-idf version information
216+
JSONObject selectedIDFInfo = (JSONObject) list.get(idfVersionId);
217+
selectedIDFInfo.put(IDF_PATH, newIdfPathToUpdate);
218+
list.put(idfVersionId, selectedIDFInfo);
219+
jsonObj.put(IDF_INSTALLED_LIST_KEY, list);
220+
}
221+
catch (
222+
IOException
223+
| ParseException e)
224+
{
225+
Logger.log(e);
226+
}
227+
228+
if (jsonObj != null)
229+
{
230+
try (FileWriter fileWriter = new FileWriter(idf_json_file))
231+
{
232+
fileWriter.write(jsonObj.toJSONString());
233+
fileWriter.flush();
234+
235+
}
236+
catch (IOException e)
237+
{
238+
Logger.log(e);
239+
}
240+
}
241+
242+
}
197243

198244
private void checkForUpdatedVersion(File idf_json_file)
199245
{

0 commit comments

Comments
 (0)