auto-sync
This commit is contained in:
parent
0c8e5b434d
commit
40acea4416
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="AntConfiguration">
|
<component name="AntConfiguration">
|
||||||
<buildFile url="file://$PROJECT_DIR$/build.xml" />
|
<buildFile url="file://$PROJECT_DIR$/build.xml">
|
||||||
|
<executeOn event="beforeCompilation" target="before_IDEA_Build" />
|
||||||
|
</buildFile>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -93,4 +93,11 @@
|
||||||
<java classpath="${jar_file}" classname="com.rusefi.RealHwTest" failonerror="true">
|
<java classpath="${jar_file}" classname="com.rusefi.RealHwTest" failonerror="true">
|
||||||
</java>
|
</java>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="before_IDEA_Build">
|
||||||
|
<copy todir=".">
|
||||||
|
<fileset dir="../firmware/tunerstudio" includes="rusefi.ini"/>
|
||||||
|
</copy>
|
||||||
|
|
||||||
|
</target>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,100 @@
|
||||||
|
package com.rusefi.ui.config;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Andrey Belomutskiy
|
||||||
|
* 12/23/2015.
|
||||||
|
*/
|
||||||
|
public class IniFileModel {
|
||||||
|
// todo: https://sourceforge.net/p/rusefi/tickets/243/
|
||||||
|
private static final String FILENAME = "rusefi.ini";
|
||||||
|
|
||||||
|
private final static IniFileModel INSTANCE = new IniFileModel();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(IniFileModel.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IniFileModel() {
|
||||||
|
readIniFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readIniFile() {
|
||||||
|
File input = new File(FILENAME);
|
||||||
|
BufferedReader d = null;
|
||||||
|
try {
|
||||||
|
d = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("No such file: " + FILENAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
|
||||||
|
State state = State.SKIPPING;
|
||||||
|
|
||||||
|
while ((line = d.readLine()) != null) {
|
||||||
|
LinkedList<String> list = new LinkedList<>(Arrays.asList(line.split("[\t =,]")));
|
||||||
|
|
||||||
|
trim(list);
|
||||||
|
|
||||||
|
if (list.isEmpty())
|
||||||
|
continue;
|
||||||
|
String first = list.getFirst();
|
||||||
|
|
||||||
|
if ("dialog".equals(first)) {
|
||||||
|
list.removeFirst();
|
||||||
|
state = State.DIALOG;
|
||||||
|
trim(list);
|
||||||
|
String keyword = list.removeFirst();
|
||||||
|
trim(list);
|
||||||
|
String name = list.isEmpty() ? null : list.removeFirst();
|
||||||
|
|
||||||
|
System.out.println("Dialog " + keyword + ": " + name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trim(LinkedList<String> list) {
|
||||||
|
while (!list.isEmpty() && list.getFirst().isEmpty())
|
||||||
|
list.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
SKIPPING,
|
||||||
|
DIALOG
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] split(String str) {
|
||||||
|
ArrayList<String> strings = new ArrayList<>();
|
||||||
|
boolean inQuote = false;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
char c = str.charAt(i);
|
||||||
|
if (c == '\"' || c == ' ' && !inQuote) {
|
||||||
|
if (c == '\"')
|
||||||
|
inQuote = !inQuote;
|
||||||
|
if (!inQuote && sb.length() > 0) {
|
||||||
|
strings.add(sb.toString());
|
||||||
|
sb.delete(0, sb.length());
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
if (sb.length() > 0)
|
||||||
|
strings.add(sb.toString());
|
||||||
|
|
||||||
|
return strings.toArray(new String[strings.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.rusefi.ui.config.test;
|
||||||
|
|
||||||
|
import com.rusefi.ui.config.IniFileModel;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (c) Andrey Belomutskiy
|
||||||
|
* 12/23/2015.
|
||||||
|
*/
|
||||||
|
public class IniFileModelTest {
|
||||||
|
@Test
|
||||||
|
public void testSplit() {
|
||||||
|
{
|
||||||
|
String[] s = IniFileModel.split("1");
|
||||||
|
assertEquals(s.length, 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
String[] s = IniFileModel.split("hello");
|
||||||
|
assertEquals(s.length, 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
String[] s = IniFileModel.split("\"hello\"");
|
||||||
|
assertEquals(s.length, 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
String[] s = IniFileModel.split("\"hello\",\"w\"");
|
||||||
|
assertEquals(s.length, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue