auto-sync

This commit is contained in:
rusEfi 2015-12-23 22:01:26 -05:00
parent 0c8e5b434d
commit 40acea4416
4 changed files with 143 additions and 3 deletions

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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>
</project>
</project>

View File

@ -93,4 +93,11 @@
<java classpath="${jar_file}" classname="com.rusefi.RealHwTest" failonerror="true">
</java>
</target>
<target name="before_IDEA_Build">
<copy todir=".">
<fileset dir="../firmware/tunerstudio" includes="rusefi.ini"/>
</copy>
</target>
</project>

View File

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

View File

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