Something went wrong. Try again.
Completely reimplimented in zig (eventually)
Something went wrong. Try again.
Java
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419package com.microchip.mplab.ipecmd.common;
import com.microchip.crownking.mplabinfo.DeviceSupport;import com.microchip.crownking.mplabinfo.DeviceSupportException;import com.microchip.crownking.mplabinfo.DeviceSupport.Device;import com.microchip.mplab.ipecmd.FilterSystemMessage;import com.microchip.mplab.ipecmd.commandline.CommandCodes;import com.microchip.mplab.ipecmd.errorlog.LoggingOutputStream;import com.microchip.mplab.ipecmd.errorlog.StdOutErrLevel;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintStream;import java.io.PrintWriter;import java.util.Properties;import java.util.ResourceBundle;import java.util.logging.LogManager;import java.util.logging.Logger;
public class SharedData { private boolean quitModeFlag = false; private Properties corePeroperties = null; private ResourceBundle bundle = null; private int errorCode = 0; private boolean jtagArgNotUsed; PrintWriter outputstream = null; private int portNumber = 2012; private static SharedData ref;
public String getSystemAppLocation() { String wd = System.getProperty("user.home"); if (System.getProperty("os.name").contains("Windows")) { wd = System.getenv("APPDATA").replace("\\", "/") + "/MPLABX IPE/"; }
return wd; }
public void initOutputData() { String appConfigFilePath = this.getSystemAppLocation() + "socketoutput.ini";
try { File f = new File(appConfigFilePath); if (f.exists()) { f.delete(); } } catch (Exception var4) { } }
public void writeOutputData(String dataToGo) { String appConfigFilePath = this.getSystemAppLocation() + "socketoutput.ini";
try { File f = new File(appConfigFilePath); FileOutputStream fos = new FileOutputStream(f, true); if (dataToGo.trim().length() > 0) { fos.write(dataToGo.getBytes()); }
fos.close(); } catch (IOException var5) { } }
public void setSystemErrorFilter() { if (System.getProperty("java.util.logging.config.file") == null) { LogManager logManager = LogManager.getLogManager(); logManager.reset(); PrintStream stderr = System.err; Logger logger = Logger.getLogger("stderr"); LoggingOutputStream los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR); System.setErr(new PrintStream(los, true)); } }
public void setSystemOutFilter() { PrintStream origOut = System.out; PrintStream interceptor = new FilterSystemMessage(origOut); System.setOut(interceptor); }
public void setOutputStreamObj(PrintWriter os) { this.outputstream = os; }
public void setQuitMode(boolean flag) { this.quitModeFlag = flag; }
public void quitAndSendErrorCode(String msg, int errorCode) { this.IPEPrint(msg); this.setLastErrorCode(errorCode); }
public void IPEPrint(String msg) { if (!this.quitModeFlag) { System.out.print("IPE:" + msg); if (this.outputstream != null) { this.outputstream.println(msg.trim()); this.outputstream.flush(); } } }
public void getPropertyInfo(String msg) { if (!this.quitModeFlag) { System.out.println(msg); } }
public boolean verifyDeviceName(String deviceName) { boolean retVal = false;
try { DeviceSupport devSupport = DeviceSupport.getInstance(); Device dv = devSupport.getDeviceFromDeviceName(deviceName); if (dv == null) { retVal = false; } else { retVal = true; } } catch (DeviceSupportException var5) { retVal = false; }
return retVal; }
public boolean isNumeric(String str) { try { int nfe = Integer.parseInt(str); return true; } catch (NumberFormatException var3) { return false; } }
public boolean isDouble(String str) { try { double nfe = Double.parseDouble(str); return true; } catch (NumberFormatException var4) { return false; } }
public boolean setCoreParameters(String key, String value) { if (this.corePeroperties != null) { this.corePeroperties.setProperty(key, value); return true; } else { return false; } }
public Properties getCoreParameters() { return this.corePeroperties; }
public long hexToDecimal(String hexString) { long retVal = -1L;
try { if (!hexString.startsWith("0x") && !hexString.startsWith("0X")) { retVal = Long.valueOf(hexString, 16); } else { retVal = Long.decode(hexString); } } catch (Exception var5) { retVal = -1L; }
return retVal; }
public String getStringFromBundle(String keyName) { String retVal = null; return this.bundle.getString(keyName); }
public void printScreen(String keyName) { String retVal = null; retVal = this.bundle.getString(keyName); this.IPEPrint(retVal); }
public void disableNetworkToolsProperty() { System.getProperties().setProperty("com.microchip.mplab.libs.comm.enableNetworkTools", "false"); }
public String getExtention(String fullPath) { if (fullPath.contains(".")) { int dot = fullPath.lastIndexOf("."); return fullPath.substring(dot + 1); } else { return null; } }
public String getFileNameOnly(String fileNameOnly) { if (fileNameOnly.contains(".")) { int dot = fileNameOnly.lastIndexOf("."); return fileNameOnly.substring(0, dot); } else { return null; } }
public String getVersion() { return this.getStringFromBundle("IPECMD.VERSION"); }
public String getShortName(String toolName) { String retValue = ""; if (toolName.contains("Real ICE")) { retValue = "RICE"; }
if (toolName.contains("PICkit3")) { retValue = "PK3"; }
if (toolName.contains("ICD 3")) { retValue = "ICD3"; }
if (toolName.contains("PK3OB")) { retValue = "PKOB"; }
if (toolName.contains("PKOB SKDE")) { retValue = "PKOB"; }
if (toolName.contains("PKOB4")) { retValue = "PKOB4"; }
if (toolName.contains("PICkit 4")) { retValue = "PK4"; }
if (toolName.contains("PICkit 5")) { retValue = "PK5"; }
if (toolName.contains("ICD 4")) { retValue = "ICD4"; }
if (toolName.contains("ICD 5")) { retValue = "ICD5"; }
if (toolName.contains("ICE 4")) { retValue = "ICE4"; }
if (toolName.contains("Atmel-ICE")) { retValue = "AICE"; }
if (toolName.contains("Snap")) { retValue = "SNAP"; }
if (toolName.contains("J-32")) { retValue = "J32"; }
if (toolName.contains("EDBG")) { retValue = "Edbg"; }
if (toolName.contains("MEDBG")) { retValue = "MEdbg"; }
if (toolName.contains("NEDBG")) { retValue = "NEdbg"; }
if (toolName.contains("PM5 Program Adapter")) { retValue = "PM5PA"; }
if (toolName.contains("PM5 S.No")) { retValue = "PM5"; }
return retValue; }
public String getPlatformToolID(String toolName) { String toolID = null; if (toolName.equalsIgnoreCase("ICD4")) { toolID = "ICD4Tool"; } else if (toolName.equalsIgnoreCase("ICD5")) { toolID = "ICD5Tool"; } else if (toolName.equalsIgnoreCase("ICE4")) { toolID = "ri4hybrid"; } else if (toolName.equalsIgnoreCase("PK4")) { toolID = "pk4hybrid"; } else if (toolName.equalsIgnoreCase("PK5")) { toolID = "PK5Tool"; } else if (toolName.equalsIgnoreCase("SNAP")) { toolID = "snap"; } else if (toolName.equalsIgnoreCase("PKOB4")) { toolID = "pkob4hybrid"; } else if (toolName.equalsIgnoreCase("AICE")) { toolID = "AtmelIceTool"; } else if (toolName.equalsIgnoreCase("EDBG")) { toolID = "EdbgTool"; } else if (toolName.equalsIgnoreCase("MEDBG")) { toolID = "mEdbgTool"; } else if (toolName.equalsIgnoreCase("NEDBG")) { toolID = "nEdbgTool"; } else if (toolName.equalsIgnoreCase("ICD3")) { toolID = "ICD3PlatformTool"; } else if (toolName.equalsIgnoreCase("PK3")) { toolID = "PICkit3PlatformTool"; } else if (toolName.equalsIgnoreCase("PM3")) { toolID = "PM3PlatformTool"; } else if (toolName.equalsIgnoreCase("RICE")) { toolID = "RealICEPlatformTool"; } else if (toolName.equalsIgnoreCase("PKOB")) { toolID = "PK3OBPlatformTool"; } else if (toolName.equalsIgnoreCase("PM5PA")) { toolID = "pm5"; } else if (toolName.equalsIgnoreCase("J32")) { toolID = "j32"; }
return toolID; }
public void setLastErrorCode(int code) { this.errorCode = code; }
public int getLastErrorCode() { return this.errorCode; }
public void setPortNumber(int port) { this.portNumber = port; }
public int getPortNumber() { return this.portNumber; }
public String getSystemAppData() { String wd = System.getProperty("user.home"); File dir = new File(wd + "/.mchp_ipe"); if (!dir.exists()) { dir.mkdirs(); }
return wd.replace("\\", "/") + "/.mchp_ipe/"; }
public void getNotifyLock(int portNumber) { try { String appLockFilePath = this.getSystemAppData() + portNumber + ".lock"; File f = new File(appLockFilePath); if (f.exists()) { f.delete(); } } catch (Exception var4) { this.outputstream.println("Could not able to delete process file."); this.outputstream.flush(); System.exit(CommandCodes.OP_FALED); } }
public void deleteProcessID(int localPortNo) { try { String appLockFilePath = this.getSystemAppData() + localPortNo + ".ini"; File f = new File(appLockFilePath); if (f.exists()) { f.delete(); } } catch (Exception var4) { this.outputstream.println("Could not able to delete process ID file."); this.outputstream.flush(); System.exit(CommandCodes.OP_FALED); } }
private SharedData() { this.corePeroperties = new Properties(); this.bundle = ResourceBundle.getBundle("com.microchip.mplab.ipecmd.common.ipeproperty"); this.jtagArgNotUsed = false; }
public static SharedData getSingletonObject() { if (ref == null) { ref = new SharedData(); }
return ref; }
@Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); }
public void setJtagArgNotUsedFlag(boolean val) { this.jtagArgNotUsed = val; }
public boolean getJtagArgNotUsedFlag() { return this.jtagArgNotUsed; }}