console does not work for custom FW fix #6961

only:hellen-honda-k
This commit is contained in:
Andrey 2024-09-30 16:05:08 -04:00
parent 6141232256
commit 88d1524dce
3 changed files with 27 additions and 7 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<String, String> 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];