only:refactoring: get rid of redundant `UpdateOperationCallbacks.append` and `UpdateOperationCallbacks.appendLine` methods because they duplicate `UpdateOperationCallbacks.log` and `UpdateOperationCallbacks.logLine` methods #7199

This commit is contained in:
kifir23917 2025-01-23 16:25:58 +03:00 committed by rusefillc
parent 3f9193bb6a
commit a461d40a7e
5 changed files with 28 additions and 41 deletions

View File

@ -7,14 +7,6 @@ public interface UpdateOperationCallbacks {
log(message, true, true); log(message, true, true);
} }
default void append(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
log(message, breakLineOnTextArea, sendToLogger);
}
default void appendLine(final String message) {
append(message, true, true);
}
void done(); void done();
void error(); void error();

View File

@ -52,8 +52,8 @@ public class DfuFlasher {
return; return;
if (isSignatureValidated.get()) { if (isSignatureValidated.get()) {
if (!FileLog.isWindows()) { if (!FileLog.isWindows()) {
callbacks.appendLine("Switched to DFU mode!"); callbacks.logLine("Switched to DFU mode!");
callbacks.appendLine("rusEFI console can only program on Windows"); callbacks.logLine("rusEFI console can only program on Windows");
return; return;
} }
@ -93,14 +93,14 @@ public class DfuFlasher {
return null; return null;
}); });
if (signature.get() == null) { if (signature.get() == null) {
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine("Make sure TUNERSTUDIO IS DISCONNECTED FROM ECU"); callbacks.logLine("Make sure TUNERSTUDIO IS DISCONNECTED FROM ECU");
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine(""); callbacks.logLine("");
callbacks.appendLine("*** ERROR *** rusEFI has not responded on selected " + port + "\n" + callbacks.logLine("*** ERROR *** rusEFI has not responded on selected " + port + "\n" +
"Maybe try automatic serial port detection?"); "Maybe try automatic serial port detection?");
callbacks.error(); callbacks.error();
return null; return null;
@ -119,11 +119,11 @@ public class DfuFlasher {
return null; return null;
}).getSerialPort(); }).getSerialPort();
if (port == null) { if (port == null) {
callbacks.appendLine("*** ERROR *** rusEFI serial port not detected"); callbacks.logLine("*** ERROR *** rusEFI serial port not detected");
callbacks.error(); callbacks.error();
return null; return null;
} else { } else {
callbacks.appendLine("Detected rusEFI on " + port + "\n"); callbacks.logLine("Detected rusEFI on " + port + "\n");
} }
} }
return isSignatureValidated; return isSignatureValidated;
@ -170,7 +170,7 @@ public class DfuFlasher {
private static void executeDFU(UpdateOperationCallbacks callbacks, String firmwareBinFile) { private static void executeDFU(UpdateOperationCallbacks callbacks, String firmwareBinFile) {
boolean driverIsHappy = detectSTM32BootloaderDriverState(callbacks); boolean driverIsHappy = detectSTM32BootloaderDriverState(callbacks);
if (!driverIsHappy) { if (!driverIsHappy) {
callbacks.appendLine("*** DRIVER ERROR? *** Did you have a chance to try 'Install Drivers' button on top of rusEFI console start screen?"); callbacks.logLine("*** DRIVER ERROR? *** Did you have a chance to try 'Install Drivers' button on top of rusEFI console start screen?");
callbacks.error(); callbacks.error();
return; return;
} }
@ -193,10 +193,10 @@ public class DfuFlasher {
callbacks.logLine("Please power cycle device to exit DFU mode"); callbacks.logLine("Please power cycle device to exit DFU mode");
callbacks.done(); callbacks.done();
} else if (stdout.toString().contains("Target device not found")) { } else if (stdout.toString().contains("Target device not found")) {
callbacks.appendLine("ERROR: Device not connected or STM32 Bootloader driver not installed?"); callbacks.logLine("ERROR: Device not connected or STM32 Bootloader driver not installed?");
appendWindowsVersion(callbacks); appendWindowsVersion(callbacks);
callbacks.appendLine("ERROR: Please try installing drivers using 'Install Drivers' button on rusEFI splash screen"); callbacks.logLine("ERROR: Please try installing drivers using 'Install Drivers' button on rusEFI splash screen");
callbacks.appendLine("ERROR: Alternatively please install drivers using Device Manager pointing at 'drivers/silent_st_drivers/DFU_Driver' folder"); callbacks.logLine("ERROR: Alternatively please install drivers using Device Manager pointing at 'drivers/silent_st_drivers/DFU_Driver' folder");
appendDeviceReport(callbacks); appendDeviceReport(callbacks);
callbacks.error(); callbacks.error();
} else { } else {

View File

@ -52,7 +52,7 @@ public class DriverInstall {
log.info("IsWindows=" + FileLog.isWindows()); log.info("IsWindows=" + FileLog.isWindows());
if (!new File(FOLDER).exists()) { if (!new File(FOLDER).exists()) {
String message = FOLDER + " not found"; String message = FOLDER + " not found";
wnd.appendLine(message); wnd.logLine(message);
log.info(message); log.info(message);
return; return;
} }
@ -65,7 +65,7 @@ public class DriverInstall {
String batch = isWindows7orBelow() ? WINDOWS7_BATCH : WINDOWS8_BATCH; String batch = isWindows7orBelow() ? WINDOWS7_BATCH : WINDOWS8_BATCH;
ExecHelper.executeCommand(UNPACKED_FOLDER, ExecHelper.getBatchCommand(batch), batch, wnd); ExecHelper.executeCommand(UNPACKED_FOLDER, ExecHelper.getBatchCommand(batch), batch, wnd);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
wnd.appendLine(e.toString()); wnd.logLine(e.toString());
wnd.error(); wnd.error();
} }
} }

View File

@ -50,7 +50,7 @@ public class StLinkFlasher {
private static void doFlashFirmware(UpdateOperationCallbacks wnd, String fileName) { private static void doFlashFirmware(UpdateOperationCallbacks wnd, String fileName) {
if (!new File(fileName).exists()) { if (!new File(fileName).exists()) {
wnd.appendLine(fileName + " not found, cannot proceed !!!"); wnd.logLine(fileName + " not found, cannot proceed !!!");
wnd.error(); wnd.error();
return; return;
} }
@ -60,16 +60,16 @@ public class StLinkFlasher {
fileName + fileName +
" verify reset exit 0x08000000\"", wnd); " verify reset exit 0x08000000\"", wnd);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
wnd.appendLine(e.toString()); wnd.logLine(e.toString());
wnd.error(); wnd.error();
return; return;
} }
if (error.contains(SUCCESS_MESSAGE_TAG) && !error.toLowerCase().contains(FAILED_MESSAGE_TAG)) { if (error.contains(SUCCESS_MESSAGE_TAG) && !error.toLowerCase().contains(FAILED_MESSAGE_TAG)) {
wnd.appendLine("Flashing looks good!"); wnd.logLine("Flashing looks good!");
wnd.done(); wnd.done();
} else { } else {
wnd.error(); wnd.error();
wnd.appendLine("!!! FIRMWARE FLASH: DOES NOT LOOK RIGHT !!!"); wnd.logLine("!!! FIRMWARE FLASH: DOES NOT LOOK RIGHT !!!");
} }
} }

View File

@ -43,11 +43,6 @@ public class StatusPanel extends JPanel implements UpdateOperationCallbacks, Sta
copyContentToClipboard(); copyContentToClipboard();
} }
@Override
public void log(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
append(message, breakLineOnTextArea, sendToLogger);
}
@Override @Override
public void done() { public void done() {
setSuccessState(); setSuccessState();
@ -68,20 +63,20 @@ public class StatusPanel extends JPanel implements UpdateOperationCallbacks, Sta
SwingUtilities.invokeLater(() -> Toolkit.getDefaultToolkit().getSystemClipboard() SwingUtilities.invokeLater(() -> Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(logTextArea.getText()), null)); .setContents(new StringSelection(logTextArea.getText()), null));
appendLine("hint: error state is already in your clipboard, please use PASTE or Ctrl-V while reporting issues"); logLine("hint: error state is already in your clipboard, please use PASTE or Ctrl-V while reporting issues");
} }
@Override @Override
public void clear() { public void clear() {
logTextArea.setText(""); logTextArea.setText("");
logTextArea.setBackground(Color.WHITE); logTextArea.setBackground(Color.WHITE);
appendLine("Console version " + rusEFIVersion.CONSOLE_VERSION); logLine("Console version " + rusEFIVersion.CONSOLE_VERSION);
appendLine(FileLog.getOsName() + " " + System.getProperty("os.version")); logLine(FileLog.getOsName() + " " + System.getProperty("os.version"));
appendLine("Bundle " + BundleUtil.readBundleFullNameNotNull()); logLine("Bundle " + BundleUtil.readBundleFullNameNotNull());
} }
@Override @Override
public void append(final String string, final boolean breakLineOnTextArea, final boolean sendToLogger) { public void log(final String string, final boolean breakLineOnTextArea, final boolean sendToLogger) {
// todo: check if AWT thread and do not invokeLater if already on AWT thread // todo: check if AWT thread and do not invokeLater if already on AWT thread
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
String s = string.replaceAll(Character.toString((char) 219), ""); String s = string.replaceAll(Character.toString((char) 219), "");
@ -103,6 +98,6 @@ public class StatusPanel extends JPanel implements UpdateOperationCallbacks, Sta
@Override @Override
public void appendStatus(final String string) { public void appendStatus(final String string) {
append(string, true, true); log(string, true, true);
} }
} }