Now we ignore `byFirmwareVersion` and `hash3` .ini-fields #7357
This commit is contained in:
parent
e0040f90fc
commit
73d262c5a8
|
@ -6,16 +6,15 @@ import com.opensr5.ini.field.*;
|
||||||
import com.rusefi.core.Pair;
|
import com.rusefi.core.Pair;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.devexperts.logging.Logging.getLogging;
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
public class IniFieldsAnalizer {
|
public class IniFieldsAnalizer {
|
||||||
private static final Logging log = getLogging(IniFieldsAnalizer.class);
|
private static final Logging log = getLogging(IniFieldsAnalizer.class);
|
||||||
|
|
||||||
|
private static final Set<String> INI_FIELDS_TO_IGNORE = Set.of("byFirmwareVersion", "hash3");
|
||||||
|
|
||||||
public static List<Pair<IniField, Constant>> findValuesToUpdate(
|
public static List<Pair<IniField, Constant>> findValuesToUpdate(
|
||||||
final IniFileModel prevIni,
|
final IniFileModel prevIni,
|
||||||
final Map<String, Constant> prevValues,
|
final Map<String, Constant> prevValues,
|
||||||
|
@ -100,52 +99,54 @@ public class IniFieldsAnalizer {
|
||||||
) {
|
) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
final String prevFieldName = prevField.getName();
|
final String prevFieldName = prevField.getName();
|
||||||
if (prevField instanceof ScalarIniField) {
|
if (!INI_FIELDS_TO_IGNORE.contains(prevFieldName)) {
|
||||||
if (newField instanceof ScalarIniField) {
|
if (prevField instanceof ScalarIniField) {
|
||||||
result = canScalarValueBeMigrated((ScalarIniField) prevField, (ScalarIniField) newField);
|
if (newField instanceof ScalarIniField) {
|
||||||
|
result = canScalarValueBeMigrated((ScalarIniField) prevField, (ScalarIniField) newField);
|
||||||
|
} else {
|
||||||
|
log.warn(String.format(
|
||||||
|
"Field `%s` cannot be migrated because it is no is no longer scalar in new .ini file: %s -> %s",
|
||||||
|
prevFieldName,
|
||||||
|
prevField,
|
||||||
|
newField
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (prevField instanceof StringIniField) {
|
||||||
|
if (newField instanceof StringIniField) {
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
log.warn(String.format(
|
||||||
|
"Field `%s` cannot be migrated because it is no longer string in new .ini file: %s -> %s",
|
||||||
|
prevFieldName,
|
||||||
|
prevField,
|
||||||
|
newField
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (prevField instanceof EnumIniField) {
|
||||||
|
if (newField instanceof EnumIniField) {
|
||||||
|
result = canEnumValueBeMigrated((EnumIniField) prevField, (EnumIniField) newField, prevValue);
|
||||||
|
} else {
|
||||||
|
log.warn(String.format(
|
||||||
|
"Field `%s` cannot be migrated because it is no longer enum in new .ini file: %s -> %s",
|
||||||
|
prevFieldName,
|
||||||
|
prevField,
|
||||||
|
newField
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (prevField instanceof ArrayIniField) {
|
||||||
|
if (newField instanceof ArrayIniField) {
|
||||||
|
result = canArrayValueBeMigrated((ArrayIniField) prevField, (ArrayIniField) newField);
|
||||||
|
} else {
|
||||||
|
log.warn(String.format(
|
||||||
|
"Field `%s` cannot be migrated because it is no longer array in new .ini file: %s -> %s",
|
||||||
|
prevFieldName,
|
||||||
|
prevField,
|
||||||
|
newField
|
||||||
|
));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.warn(String.format(
|
log.error(String.format("Unexpected field type: %s", prevField.getClass()));
|
||||||
"Field `%s` cannot be migrated because it is no is no longer scalar in new .ini file: %s -> %s",
|
|
||||||
prevFieldName,
|
|
||||||
prevField,
|
|
||||||
newField
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else if (prevField instanceof StringIniField) {
|
|
||||||
if (newField instanceof StringIniField) {
|
|
||||||
result = true;
|
|
||||||
} else {
|
|
||||||
log.warn(String.format(
|
|
||||||
"Field `%s` cannot be migrated because it is no longer string in new .ini file: %s -> %s",
|
|
||||||
prevFieldName,
|
|
||||||
prevField,
|
|
||||||
newField
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if (prevField instanceof EnumIniField) {
|
|
||||||
if (newField instanceof EnumIniField) {
|
|
||||||
result = canEnumValueBeMigrated((EnumIniField) prevField, (EnumIniField) newField, prevValue);
|
|
||||||
} else {
|
|
||||||
log.warn(String.format(
|
|
||||||
"Field `%s` cannot be migrated because it is no longer enum in new .ini file: %s -> %s",
|
|
||||||
prevFieldName,
|
|
||||||
prevField,
|
|
||||||
newField
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if (prevField instanceof ArrayIniField) {
|
|
||||||
if (newField instanceof ArrayIniField) {
|
|
||||||
result = canArrayValueBeMigrated((ArrayIniField) prevField, (ArrayIniField) newField);
|
|
||||||
} else {
|
|
||||||
log.warn(String.format(
|
|
||||||
"Field `%s` cannot be migrated because it is no longer array in new .ini file: %s -> %s",
|
|
||||||
prevFieldName,
|
|
||||||
prevField,
|
|
||||||
newField
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error(String.format("Unexpected field type: %s", prevField.getClass()));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue