fixed restoring firmware file info during reload

This commit is contained in:
fros4943 2008-02-08 14:30:28 +00:00
parent d2886875ec
commit c3bcf8569c

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MspMoteType.java,v 1.1 2008/02/07 14:53:29 fros4943 Exp $ * $Id: MspMoteType.java,v 1.2 2008/02/08 14:30:28 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -216,6 +216,7 @@ public abstract class MspMoteType implements MoteType {
try { try {
compiler.compileFirmware(getSourceFile(), null, null, compilationOutput, compiler.compileFirmware(getSourceFile(), null, null, compilationOutput,
true); true);
} catch (Exception e) { } catch (Exception e) {
MoteTypeCreationException newException = new MoteTypeCreationException( MoteTypeCreationException newException = new MoteTypeCreationException(
"Mote type creation failed: " + e.getMessage()); "Mote type creation failed: " + e.getMessage());
@ -224,11 +225,6 @@ public abstract class MspMoteType implements MoteType {
throw newException; throw newException;
} }
/*File parentFile = getSourceFile().getParentFile();*/
/*final String filenameNoExtension = getSourceFile().getName().substring(0,
getSourceFile().getName().length() - 2);*/
/*setELFFile(new File(parentFile, filenameNoExtension + firmwareFileExtension));*/
setSourceFile(compiler.getSourceFile()); setSourceFile(compiler.getSourceFile());
setELFFile(compiler.getOutputFile()); setELFFile(compiler.getOutputFile());
setCompileCommand(compiler.getLastCompileCommand()); setCompileCommand(compiler.getLastCompileCommand());
@ -239,46 +235,57 @@ public abstract class MspMoteType implements MoteType {
// Check dependency files // Check dependency files
if (getELFFile() == null || !getELFFile().exists()) { if (getELFFile() == null || !getELFFile().exists()) {
if (visAvailable) { if (!visAvailable) {
JFileChooser fc = new JFileChooser(); throw new MoteTypeCreationException("ELF file does not exist: " + getELFFile());
}
// Select previous directory JFileChooser fc = new JFileChooser();
if (lastParentDirectory != null) {
fc.setCurrentDirectory(lastParentDirectory); // Select previous directory
} else { if (lastParentDirectory != null) {
fc.setCurrentDirectory(new java.io.File(GUI fc.setCurrentDirectory(lastParentDirectory);
.getExternalToolsSetting("PATH_CONTIKI"))); } else {
} fc.setCurrentDirectory(new java.io.File(GUI
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); .getExternalToolsSetting("PATH_CONTIKI")));
fc.addChoosableFileFilter(new FileFilter() { }
public boolean accept(File f) { fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (f.isDirectory()) { fc.addChoosableFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String filename = f.getName();
if (filename != null) {
if (filename.endsWith(firmwareFileExtension)) {
return true; return true;
} }
String filename = f.getName();
if (filename != null) {
if (filename.endsWith(firmwareFileExtension)) {
return true;
}
}
return false;
} }
public String getDescription() {
return "ELF file";
}
});
fc.setDialogTitle("Select ELF file");
if (fc.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) {
lastParentDirectory = fc.getSelectedFile().getParentFile();
setELFFile(fc.getSelectedFile());
} else {
return false; return false;
} }
public String getDescription() {
return "ELF file";
}
});
fc.setDialogTitle("Select ELF file");
if (fc.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) {
File selectedFile = fc.getSelectedFile();
if (!selectedFile.exists()) {
logger.fatal("Selected file \"" + selectedFile + "\" does not exist");
return false;
}
if (!selectedFile.getName().endsWith(firmwareFileExtension)) {
logger.fatal("Selected file \"" + selectedFile + "\" does not end with " + firmwareFileExtension);
return false;
}
setELFFile(fc.getSelectedFile());
} else { } else {
throw new MoteTypeCreationException("No ELF file was created"); return false;
} }
} }
return true; return true;
@ -412,7 +419,7 @@ public abstract class MspMoteType implements MoteType {
final String filenameNoExtension = sourceFile.getName().substring(0, final String filenameNoExtension = sourceFile.getName().substring(0,
sourceFile.getName().length() - 2); sourceFile.getName().length() - 2);
String command = getCompileCommand(filenameNoExtension); final String command = getCompileCommand(filenameNoExtension);
logger.info("Compile command: " + command); logger.info("Compile command: " + command);
compilationOutput.clearMessages(); compilationOutput.clearMessages();
@ -514,6 +521,9 @@ public abstract class MspMoteType implements MoteType {
listNormal.println(""); listNormal.println("");
listNormal.println("Compilation succeded"); listNormal.println("Compilation succeded");
MspELFCompiler.this.lastCompileCommand = command;
MspELFCompiler.this.sourceFile = sourceFile;
MspELFCompiler.this.ELFFile = ELFFile;
if (successAction != null) { if (successAction != null) {
successAction.actionPerformed(null); successAction.actionPerformed(null);
} }
@ -579,7 +589,6 @@ public abstract class MspMoteType implements MoteType {
updateDialog(DialogState.COMPILED_SOURCE); updateDialog(DialogState.COMPILED_SOURCE);
File parentFile = selectedSourceFile.getParentFile(); File parentFile = selectedSourceFile.getParentFile();
lastCompileCommand = getCompileCommand(filenameNoExtension);
sourceFile = selectedSourceFile; sourceFile = selectedSourceFile;
ELFFile = new File(parentFile, filenameNoExtension + firmwareFileExtension); ELFFile = new File(parentFile, filenameNoExtension + firmwareFileExtension);
} }