brouter/brouter-routing-app/src/main/java/btools/routingapp/ConfigMigration.java
Manuel Fuhr 54d5c5e943 Reformat files using Android Studio
android-studio/bin/format.sh -m '*.java' -r brouter-routing-app

To rebase active branches on top of the new master just rebase your
branch onto the commit prior to the reformatting and format every commit
of your branch using (<commit> should be replaced by this commit)

git rebase \
        --strategy-option=theirs \
        --onto <commit> \
        --exec 'format.sh -m "*.java" -r brouter-routing-app' \
        --exec 'git commit --all --no-edit --amend' \
        <commit>~

To ignore this mass edit during git blame see `.git-blame-ignore-revs`
2021-11-20 16:50:23 +01:00

111 lines
3 KiB
Java

package btools.routingapp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
public class ConfigMigration {
public static void tryMigrateStorageConfig(File srcFile, File dstFile) {
if (!srcFile.exists()) return;
String ssd = null;
String amd = null;
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new FileReader(srcFile));
for (; ; ) {
String line = br.readLine();
if (line == null) break;
if (line.trim().startsWith("secondary_segment_dir=")) {
if (!"secondary_segment_dir=../segments2".equals(line)) {
ssd = line;
}
}
if (line.trim().startsWith("additional_maptool_dir=")) {
amd = line;
}
}
br.close();
List<String> lines = new ArrayList<String>();
br = new BufferedReader(new FileReader(dstFile));
for (; ; ) {
String line = br.readLine();
if (line == null) break;
if (ssd != null && line.trim().startsWith("secondary_segment_dir=")) {
line = ssd;
}
if (amd != null && line.trim().startsWith("#additional_maptool_dir=")) {
line = amd;
}
lines.add(line);
}
br.close();
br = null;
bw = new BufferedWriter(new FileWriter(dstFile));
for (String line : lines) {
bw.write(line + "\n");
}
} catch (Exception e) { /* ignore */ } finally {
if (br != null) {
try {
br.close();
} catch (Exception ee) { /* ignore */ }
}
if (bw != null) {
try {
bw.close();
} catch (Exception ee) { /* ignore */ }
}
}
}
public static File saveAdditionalMaptoolDir(File segmentDir, String value) {
return saveStorageLocation(segmentDir, "additional_maptool_dir=", value);
}
private static File saveStorageLocation(File segmentDir, String tag, String value) {
File res = null;
BufferedReader br = null;
BufferedWriter bw = null;
File configFile = new File(segmentDir, "storageconfig.txt");
List<String> lines = new ArrayList<String>();
try {
br = new BufferedReader(new FileReader(configFile));
for (; ; ) {
String line = br.readLine();
if (line == null) break;
if (!line.trim().startsWith(tag)) {
lines.add(line);
}
}
lines.add(tag + value);
br.close();
br = null;
bw = new BufferedWriter(new FileWriter(configFile));
for (String line : lines) {
bw.write(line + "\r\n");
}
} catch (Exception e) { /* ignore */ } finally {
if (br != null) {
try {
br.close();
} catch (Exception ee) { /* ignore */ }
}
if (bw != null) {
try {
bw.close();
} catch (Exception ee) { /* ignore */ }
}
}
return res;
}
}