|
| 1 | +package it.baeyens.arduino.tools.uploaders; |
| 2 | + |
| 3 | +import it.baeyens.arduino.common.Const; |
| 4 | + |
| 5 | +import java.io.IOException; |
| 6 | + |
| 7 | +import org.eclipse.cdt.core.CCorePlugin; |
| 8 | +import org.eclipse.cdt.core.envvar.EnvironmentVariable; |
| 9 | +import org.eclipse.cdt.core.envvar.IContributedEnvironment; |
| 10 | +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; |
| 11 | +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; |
| 12 | +import org.eclipse.cdt.core.model.CoreModel; |
| 13 | +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; |
| 14 | +import org.eclipse.cdt.core.settings.model.ICProjectDescription; |
| 15 | +import org.eclipse.core.resources.IFile; |
| 16 | +import org.eclipse.core.resources.IProject; |
| 17 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 18 | +import org.eclipse.core.runtime.SubProgressMonitor; |
| 19 | +import org.eclipse.ui.console.MessageConsole; |
| 20 | + |
| 21 | +public class GenericNetworkUploader implements IRealUpload { |
| 22 | + private String mycConf; |
| 23 | + private String myUploadTool; |
| 24 | + private MessageConsole myConsole; |
| 25 | + private String myAdderss; |
| 26 | + private String myPort; |
| 27 | + private String myPassword; |
| 28 | + |
| 29 | + /** |
| 30 | + * @param project unused here |
| 31 | + */ |
| 32 | + GenericNetworkUploader(IProject project, String cConf, String UploadTool, MessageConsole Console, String address, String port, String password) { |
| 33 | + this.mycConf = cConf; |
| 34 | + this.myUploadTool = UploadTool; |
| 35 | + this.myConsole = Console; |
| 36 | + this.myAdderss = address; |
| 37 | + this.myPort = port; |
| 38 | + this.myPassword = password; |
| 39 | + } |
| 40 | + |
| 41 | + @SuppressWarnings("unused") |
| 42 | + @Override |
| 43 | + public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer, IProgressMonitor monitor) { |
| 44 | + IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager(); |
| 45 | + IContributedEnvironment contribEnv = envManager.getContributedEnvironment(); |
| 46 | + ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project); |
| 47 | + ICConfigurationDescription configurationDescription = prjDesc.getConfigurationByName(this.mycConf); |
| 48 | + |
| 49 | + IEnvironmentVariable var = new EnvironmentVariable(Const.ENV_KEY_SERIAL_PORT, this.myAdderss); |
| 50 | + contribEnv.addVariable(var, configurationDescription); |
| 51 | + var = new EnvironmentVariable(Const.ENV_KEY_NETWORK_PORT, this.myPort); |
| 52 | + contribEnv.addVariable(var, configurationDescription); |
| 53 | + var = new EnvironmentVariable(Const.ENV_KEY_NETWORK_PASSWORD, this.myPassword); |
| 54 | + contribEnv.addVariable(var, configurationDescription); |
| 55 | + |
| 56 | + String command = ""; |
| 57 | + try { |
| 58 | + command = envManager.getVariable("A.TOOLS." + this.myUploadTool.toUpperCase() + ".UPLOAD.NETWORK_PATTERN", configurationDescription, true).getValue(); |
| 59 | + } catch (Exception e) { |
| 60 | + try { |
| 61 | + command = envManager.getVariable("A.TOOLS." + this.myUploadTool.toUpperCase() + ".UPLOAD.PATTERN", configurationDescription, true).getValue(); |
| 62 | + } catch (Exception er){ |
| 63 | + return false; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + try { |
| 68 | + GenericLocalUploader.RunConsoledCommand(this.myConsole, command, new SubProgressMonitor(monitor, 1)); |
| 69 | + } catch (IOException e1) { |
| 70 | + e1.printStackTrace(); |
| 71 | + return false; |
| 72 | + } |
| 73 | + return true; |
| 74 | + } |
| 75 | +} |
0 commit comments