Skip to content

Commit 61fa935

Browse files
authored
IEP-1577: Eim default directory added based on documentation (#1261)
1 parent 7f6c90c commit 61fa935

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/ToolInitializer.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88
import java.io.IOException;
99
import java.nio.file.Files;
10+
import java.nio.file.Path;
1011
import java.nio.file.Paths;
1112
import java.util.ArrayList;
1213
import java.util.List;
@@ -47,7 +48,15 @@ public ToolInitializer(Preferences preferences)
4748
public boolean isEimInstalled()
4849
{
4950
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;
5160
}
5261

5362
public boolean isEimIdfJsonPresent()
@@ -113,4 +122,42 @@ public boolean isEspIdfSet()
113122
{
114123
return preferences.getBoolean(EimConstants.INSTALL_TOOLS_FLAG, false);
115124
}
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+
}
116163
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/EspressifToolStartup.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ else if (toolInitializer.isEimIdfJsonPresent() && !toolInitializer.isEspIdfSet()
110110
{
111111
idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.EIM_PATH, eimJson.getEimPath());
112112
}
113+
else
114+
{
115+
// Fail-safe call to ensure if the eim is in Applications or user.home it is setup in env vars
116+
toolInitializer.findAndSetEimPath();
117+
}
113118

114119
if (stateChecker.wasModifiedSinceLastRun())
115120
{

0 commit comments

Comments
 (0)