From 88d1524dce3a5f3260c5c11173af6dba3290d355 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 30 Sep 2024 16:05:08 -0400 Subject: [PATCH] console does not work for custom FW fix #6961 only:hellen-honda-k --- .../java/com/opensr5/ini/IniFileModelImpl.java | 7 ++++++- .../binaryprotocol/RealIniFileProvider.java | 15 ++++++++++++++- .../java/com/rusefi/core/SignatureHelper.java | 12 +++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModelImpl.java b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModelImpl.java index ff0a7da1e9..91a0c1f892 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModelImpl.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModelImpl.java @@ -3,6 +3,7 @@ package com.opensr5.ini; import com.devexperts.logging.Logging; import com.opensr5.ini.field.*; import com.rusefi.core.FindFileHelper; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.util.*; @@ -103,12 +104,16 @@ public class IniFileModelImpl implements IniFileModel { } private static String findMetaInfoFile(String iniFilePath) { - String iniFileName = FindFileHelper.findFile(iniFilePath, RUSEFI_INI_PREFIX, RUSEFI_INI_SUFFIX); + String iniFileName = findIniFile(iniFilePath); if (iniFileName == null) throw new IllegalStateException("Not found " + RUSEFI_INI_PREFIX + "*" + RUSEFI_INI_SUFFIX + " in " + iniFilePath); return iniFileName; } + public static @Nullable String findIniFile(String iniFilePath) { + return FindFileHelper.findFile(iniFilePath, RUSEFI_INI_PREFIX, RUSEFI_INI_SUFFIX); + } + private void finishDialog() { if (fieldsOfCurrentDialog.isEmpty()) return; diff --git a/java_console/io/src/main/java/com/rusefi/binaryprotocol/RealIniFileProvider.java b/java_console/io/src/main/java/com/rusefi/binaryprotocol/RealIniFileProvider.java index d528a620fb..5fe5ec8f12 100644 --- a/java_console/io/src/main/java/com/rusefi/binaryprotocol/RealIniFileProvider.java +++ b/java_console/io/src/main/java/com/rusefi/binaryprotocol/RealIniFileProvider.java @@ -7,9 +7,22 @@ import com.rusefi.core.SignatureHelper; public class RealIniFileProvider implements IniFileProvider { @Override public IniFileModel provide(String signature) { + /** + * first we look at {@link SignatureHelper#LOCAL_INI_CACHE_FOLDER} + * second we attempt downloading + * third we look via {@link SignatureHelper#EXTRA_INI_SOURCE} environment variable + */ String localIniFile = SignatureHelper.downloadIfNotAvailable(SignatureHelper.getUrl(signature)); + if (localIniFile == null) { + // 4th option: current folder + localIniFile = IniFileModelImpl.findIniFile("."); + } + if (localIniFile == null) { + // 5th option: one level up or environment variable direction + localIniFile = IniFileModelImpl.findIniFile(IniFileModelImpl.INI_FILE_PATH); + } if (localIniFile == null) - throw new IllegalStateException("Failed to download for " + signature); + throw new IllegalStateException("Failed to locate .ini file in five different places!"); return new IniFileModelImpl().readIniFile(localIniFile); } } diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/SignatureHelper.java b/java_console/shared_io/src/main/java/com/rusefi/core/SignatureHelper.java index b2aab43ac0..2efa4f1ba8 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/core/SignatureHelper.java +++ b/java_console/shared_io/src/main/java/com/rusefi/core/SignatureHelper.java @@ -13,7 +13,7 @@ import static com.rusefi.core.FileUtil.RUSEFI_SETTINGS_FOLDER; public class SignatureHelper { private static final Logging log = getLogging(SignatureHelper.class); - private final static String LOCAL_INI = RUSEFI_SETTINGS_FOLDER + File.separator + "ini_database"; + private final static String LOCAL_INI_CACHE_FOLDER = RUSEFI_SETTINGS_FOLDER + File.separator + "ini_database"; // todo: find a way to reference Fields.PROTOCOL_SIGNATURE_PREFIX private static final String PREFIX = "rusEFI "; @@ -42,15 +42,17 @@ public class SignatureHelper { public static String downloadIfNotAvailable(Pair p) { if (p == null) return null; - new File(LOCAL_INI).mkdirs(); - String localIniFile = LOCAL_INI + File.separator + p.second; + new File(LOCAL_INI_CACHE_FOLDER).mkdirs(); + String localIniFile = LOCAL_INI_CACHE_FOLDER + File.separator + p.second; File file = new File(localIniFile); - if (file.exists() && file.length() > 10000) + if (file.exists() && file.length() > 10000) { + log.info("Found cached at " + LOCAL_INI_CACHE_FOLDER); return localIniFile; + } if (EXTRA_INI_SOURCE != null) { return EXTRA_INI_SOURCE; } - log.info("Failed to locate " + localIniFile + ", trying to download " + p.first); + log.info(".ini not found in " + LOCAL_INI_CACHE_FOLDER + "(" + localIniFile + "), trying to download " + p.first); try (BufferedInputStream in = new BufferedInputStream(new URL(p.first).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(localIniFile)) { byte[] dataBuffer = new byte[32 * 1024];