|
8 | 8 | import java.beans.PropertyChangeListener; |
9 | 9 | import java.io.File; |
10 | 10 | import java.io.FileReader; |
| 11 | +import java.io.FileWriter; |
11 | 12 | import java.io.IOException; |
12 | 13 | import java.net.URL; |
13 | 14 | import java.text.MessageFormat; |
@@ -48,7 +49,7 @@ public class InitializeToolsStartup implements IStartup |
48 | 49 | /** |
49 | 50 | * esp-idf.json is file created by the installer |
50 | 51 | */ |
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$ |
52 | 53 |
|
53 | 54 | // Variables defined in the esp-idf.json file |
54 | 55 | private static final String GIT_PATH = "gitPath"; //$NON-NLS-1$ |
@@ -118,6 +119,8 @@ else if (isInstallerConfigSet()) |
118 | 119 | int response = messageBox.open(); |
119 | 120 | if (response == SWT.NO) |
120 | 121 | { |
| 122 | + IDFEnvironmentVariables idfEnvironmentVariables = new IDFEnvironmentVariables(); |
| 123 | + updateEspIdfJsonFile(idf_json_file, idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.IDF_PATH)); |
121 | 124 | Preferences prefs = getPreferences(); |
122 | 125 | prefs.putBoolean(IS_INSTALLER_CONFIG_SET, true); |
123 | 126 | try |
@@ -194,6 +197,49 @@ else if (isInstallerConfigSet()) |
194 | 197 | Logger.log(e); |
195 | 198 | } |
196 | 199 | } |
| 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 | + } |
197 | 243 |
|
198 | 244 | private void checkForUpdatedVersion(File idf_json_file) |
199 | 245 | { |
|
0 commit comments