|
7 | 7 | import java.io.File; |
8 | 8 | import java.io.IOException; |
9 | 9 | import java.nio.file.Files; |
| 10 | +import java.nio.file.Path; |
10 | 11 | import java.nio.file.Paths; |
11 | 12 | import java.util.ArrayList; |
12 | 13 | import java.util.List; |
@@ -47,7 +48,15 @@ public ToolInitializer(Preferences preferences) |
47 | 48 | public boolean isEimInstalled() |
48 | 49 | { |
49 | 50 | String eimExePathEnv = idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.EIM_PATH); |
50 | | - return !StringUtil.isEmpty(eimExePathEnv) && Files.exists(Paths.get(eimExePathEnv)); |
| 51 | + boolean exists = !StringUtil.isEmpty(eimExePathEnv) && Files.exists(Paths.get(eimExePathEnv)); |
| 52 | + if (!exists) |
| 53 | + { |
| 54 | + // Fallback: check in user home .espressif/eim_gui folder |
| 55 | + Path defaultEimPath = getDefaultEimPath(); |
| 56 | + if (defaultEimPath != null) |
| 57 | + exists = Files.exists(defaultEimPath); |
| 58 | + } |
| 59 | + return exists; |
51 | 60 | } |
52 | 61 |
|
53 | 62 | public boolean isEimIdfJsonPresent() |
@@ -113,4 +122,42 @@ public boolean isEspIdfSet() |
113 | 122 | { |
114 | 123 | return preferences.getBoolean(EimConstants.INSTALL_TOOLS_FLAG, false); |
115 | 124 | } |
| 125 | + |
| 126 | + private Path getDefaultEimPath() |
| 127 | + { |
| 128 | + String userHome = System.getProperty("user.home"); //$NON-NLS-1$ |
| 129 | + Path defaultEimPath; |
| 130 | + String os = Platform.getOS(); |
| 131 | + if (os.equals(Platform.OS_WIN32)) |
| 132 | + { |
| 133 | + defaultEimPath = Paths.get(userHome, ".espressif", "eim_gui", //$NON-NLS-1$//$NON-NLS-2$ |
| 134 | + "eim.exe"); //$NON-NLS-1$ |
| 135 | + } |
| 136 | + else if (os.equals(Platform.OS_MACOSX)) |
| 137 | + { |
| 138 | + defaultEimPath = Paths.get("/Applications", //$NON-NLS-1$ |
| 139 | + "eim.app", "Contents", //$NON-NLS-1$//$NON-NLS-2$ |
| 140 | + "MacOS", "eim"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 141 | + } |
| 142 | + else |
| 143 | + { |
| 144 | + defaultEimPath = Paths.get(userHome, ".espressif", //$NON-NLS-1$ |
| 145 | + "eim_gui", "eim"); //$NON-NLS-1$//$NON-NLS-2$ |
| 146 | + } |
| 147 | + |
| 148 | + return defaultEimPath; |
| 149 | + } |
| 150 | + |
| 151 | + public void findAndSetEimPath() |
| 152 | + { |
| 153 | + Path defaultEimPath = getDefaultEimPath(); |
| 154 | + |
| 155 | + if (defaultEimPath != null) |
| 156 | + setEimPathInEnvVar(defaultEimPath.toString()); |
| 157 | + } |
| 158 | + |
| 159 | + private void setEimPathInEnvVar(String eimPath) |
| 160 | + { |
| 161 | + idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.EIM_PATH, eimPath); |
| 162 | + } |
116 | 163 | } |
0 commit comments