extended configuration (to hande Kitkat issues)

This commit is contained in:
Arndt 2014-07-26 12:25:44 +02:00
parent a6878ba04e
commit 631057cd5f
10 changed files with 251 additions and 40 deletions

View file

@ -0,0 +1,58 @@
/**
* static helper class for handling datafiles
*
* @author ab
*/
package btools.router;
import java.io.File;
import btools.mapaccess.StorageConfigHelper;
public final class RoutingHelper
{
public static File getAdditionalMaptoolDir( String segmentDir )
{
return StorageConfigHelper.getAdditionalMaptoolDir(segmentDir);
}
public static File getSecondarySegmentDir( String segmentDir )
{
return StorageConfigHelper.getSecondarySegmentDir(segmentDir);
}
public static boolean hasDirectoryAnyDatafiles( String segmentDir )
{
if ( hasAnyDatafiles( new File( segmentDir ) ) )
{
return true;
}
// check secondary, too
File secondary = StorageConfigHelper.getSecondarySegmentDir( segmentDir );
if ( secondary != null )
{
return hasAnyDatafiles( secondary );
}
return false;
}
private static boolean hasAnyDatafiles( File dir )
{
String[] fileNames = dir.list();
for( String fileName : fileNames )
{
if ( fileName.endsWith( ".rd5" ) ) return true;
}
File carSubset = new File( dir, "carsubset" );
if ( carSubset.isDirectory() )
{
fileNames = carSubset.list();
for( String fileName : fileNames )
{
if ( fileName.endsWith( ".cd5" ) ) return true;
}
}
return false;
}
}

View file

@ -5,12 +5,8 @@
*/
package btools.mapcreator;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import sun.security.pkcs.SigningCertificateInfo;
import btools.util.ByteDataWriter;
public class OsmNodeP implements Comparable<OsmNodeP>

View file

@ -13,7 +13,9 @@ import java.util.List;
public final class NodesCache
{
private String segmentDir;
private File segmentDir;
private File secondarySegmentsDir = null;
private OsmNodesMap nodesMap;
private int lookupVersion;
private int lookupMinorVersion;
@ -33,21 +35,25 @@ public final class NodesCache
private long cacheSum = 0;
private boolean garbageCollectionEnabled = false;
public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int minorVersion, boolean varLen, boolean carMode, NodesCache oldCache )
{
this.segmentDir = segmentDir;
this.segmentDir = new File( segmentDir );
this.nodesMap = nodesMap;
this.lookupVersion = lookupVersion;
this.lookupMinorVersion = minorVersion;
this.readVarLength = varLen;
this.carMode = carMode;
if ( !this.segmentDir.isDirectory() ) throw new RuntimeException( "segment directory " + segmentDir + " does not exist" );
if ( oldCache != null )
{
fileCache = oldCache.fileCache;
iobuffer = oldCache.iobuffer;
oom_carsubset_hint = oldCache.oom_carsubset_hint;
secondarySegmentsDir = oldCache.secondarySegmentsDir;
// re-use old, virgin caches
fileRows = oldCache.fileRows;
@ -65,8 +71,20 @@ public final class NodesCache
fileCache = new HashMap<String,PhysicalFile>(4);
fileRows = new OsmFile[180][];
iobuffer = new byte[65636];
secondarySegmentsDir = StorageConfigHelper.getSecondarySegmentDir( segmentDir );
}
}
private File getFileFromSegmentDir( String filename )
{
File f = new File( segmentDir, filename );
if ( secondarySegmentsDir != null && !f.exists() )
{
File f2 = new File( secondarySegmentsDir, filename );
if ( f2.exists() ) return f2;
}
return f;
}
// if the cache sum exceeded a threshold,
// clean all ghosts and enable garbage collection
@ -185,9 +203,6 @@ public final class NodesCache
private OsmFile fileForSegment( int lonDegree, int latDegree ) throws Exception
{
File base = new File( segmentDir );
if ( !base.isDirectory() ) throw new RuntimeException( "segment directory " + segmentDir + " does not exist" );
int lonMod5 = lonDegree % 5;
int latMod5 = latDegree % 5;
int tileIndex = lonMod5 * 5 + latMod5;
@ -207,12 +222,12 @@ public final class NodesCache
File f = null;
if ( carMode )
{
File carFile = new File( new File( base, "carsubset" ), filenameBase + ".cd5" );
File carFile = getFileFromSegmentDir( "carsubset/" + filenameBase + ".cd5" );
if ( carFile.exists() ) f = carFile;
}
if ( f == null )
{
File fullFile = new File( base, filenameBase + ".rd5" );
File fullFile = getFileFromSegmentDir( filenameBase + ".rd5" );
if ( fullFile.exists() ) f = fullFile;
if ( carMode && f != null ) oom_carsubset_hint = true;
}

View file

@ -0,0 +1,55 @@
/**
* Access to the storageconfig.txt config file
*
* @author ab
*/
package btools.mapaccess;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class StorageConfigHelper
{
public static File getSecondarySegmentDir( String segmentDir )
{
return getStorageLocation( segmentDir, "secondary_segment_dir=" );
}
public static File getAdditionalMaptoolDir( String segmentDir )
{
return getStorageLocation( segmentDir, "additional_maptool_dir=" );
}
private static File getStorageLocation( String segmentDir, String tag )
{
File res = null;
BufferedReader br = null;
String configFile = segmentDir + "/storageconfig.txt";
try
{
br = new BufferedReader( new FileReader (configFile ) );
for(;;)
{
String line = br.readLine();
if ( line == null ) break;
line = line.trim();
if ( line.startsWith( "#") ) continue;
if ( line.startsWith( tag ) )
{
String path = line.substring( tag.length() ).trim();
res = path.startsWith( "/" ) ? new File( path ) : new File( new File( segmentDir ) , path );
if ( !res.exists() ) res = null;
break;
}
}
}
catch( Exception e ) {}
finally
{
if ( br != null ) try { br.close(); } catch( Exception ee ) {}
}
return res;
}
}

Binary file not shown.

View file

@ -0,0 +1,68 @@
package btools.routingapp;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import android.os.Environment;
/**
* static logger interface to be used in the android app
*/
public class AppLogger
{
private static FileWriter debugLogWriter = null;
private static boolean initDone = false;
private static void init()
{
try
{
// open logfile if existing
File sd = Environment.getExternalStorageDirectory();
if ( sd == null ) return;
File debugLog = new File( sd, "brouterapp.txt" );
if ( debugLog.exists() )
{
debugLogWriter = new FileWriter( debugLog, true );
}
}
catch( IOException ioe ) {}
}
/**
* log an info trace to the app log file, if any
*/
public static boolean isLogging()
{
if ( !initDone )
{
initDone = true;
init();
log( "logging started at " + new Date() );
}
return debugLogWriter != null;
}
/**
* log an info trace to the app log file, if any
*/
public static void log( String msg )
{
if ( isLogging() )
{
try
{
debugLogWriter.write( msg );
debugLogWriter.write( '\n' );
debugLogWriter.flush();
}
catch( IOException e )
{
throw new RuntimeException( "cannot write appdebug.txt: " + e );
}
}
}
}

View file

@ -25,6 +25,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import btools.mapaccess.PhysicalFile;
import btools.router.RoutingHelper;
public class BInstallerView extends View
{
@ -209,8 +210,15 @@ public class BInstallerView extends View
{
clearTileSelection( MASK_INSTALLED_CD5 | MASK_INSTALLED_RD5 );
scanExistingFiles( new File( baseDir + "/brouter/segments2" ), ".rd5", MASK_INSTALLED_RD5 );
scanExistingFiles( new File( baseDir + "/brouter/segments2/carsubset" ), ".cd5", MASK_INSTALLED_CD5 );
scanExistingFiles( new File( baseDir + "/brouter/segments3" ), ".rd5", MASK_INSTALLED_RD5 );
scanExistingFiles( new File( baseDir + "/brouter/segments3/carsubset" ), ".cd5", MASK_INSTALLED_CD5 );
File secondary = RoutingHelper.getSecondarySegmentDir( baseDir + "/brouter/segments3" );
if ( secondary != null )
{
scanExistingFiles( secondary, ".rd5", MASK_INSTALLED_RD5 );
scanExistingFiles( new File( secondary, "carsubset" ), ".cd5", MASK_INSTALLED_CD5 );
}
StatFs stat = new StatFs(baseDir);
availableSize = (long)stat.getAvailableBlocks()*stat.getBlockSize();
@ -599,7 +607,7 @@ float tx, ty;
input = connection.getInputStream();
int slidx = surl.lastIndexOf( "segments3/" );
fname = baseDir + "/brouter/segments2/" + surl.substring( slidx+10 );
fname = baseDir + "/brouter/segments3/" + surl.substring( slidx+10 );
tmp_file = new File( fname + "_tmp" );
if ( new File( fname ).exists() ) return "internal error: file exists: " + fname;
output = new FileOutputStream( tmp_file );

View file

@ -57,7 +57,7 @@ public class BRouterService extends Service
{
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
br = new BufferedReader( new FileReader (modesFile ) );
worker.segmentDir = baseDir + "/brouter/segments2";
worker.segmentDir = baseDir + "/brouter/segments3";
for(;;)
{
String line = br.readLine();
@ -67,7 +67,7 @@ public class BRouterService extends Service
worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf";
worker.rawTrackPath = baseDir + "/brouter/modes/" + mode_key + "_rawtrack.dat";
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir );
CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir );
worker.nogoList = new ArrayList<OsmNodeNamed>();
// veto nogos by profiles veto list
for(OsmNodeNamed nogo : cor.nogopoints )

View file

@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -36,6 +37,7 @@ import btools.router.OsmNodeNamed;
import btools.router.OsmTrack;
import btools.router.RoutingContext;
import btools.router.RoutingEngine;
import btools.router.RoutingHelper;
public class BRouterView extends View
{
@ -71,6 +73,7 @@ public class BRouterView extends View
private int[] imgPixels;
public void startSimulation() {
}
@ -138,18 +141,19 @@ public class BRouterView extends View
ConfigHelper.writeBaseDir( getContext(), baseDir );
}
String basedir = fbd.getAbsolutePath();
AppLogger.log( "using basedir: " + basedir );
// create missing directories
assertDirectoryExists( "project directory", basedir + "/brouter", null );
segmentDir = basedir + "/brouter/segments2";
assertDirectoryExists( "data directory", segmentDir, null );
segmentDir = basedir + "/brouter/segments3";
assertDirectoryExists( "data directory", segmentDir, "segments3.zip" );
assertDirectoryExists( "carsubset directory", segmentDir + "/carsubset", null );
profileDir = basedir + "/brouter/profiles2";
assertDirectoryExists( "profile directory", profileDir, "profiles2.zip" );
modesDir = basedir + "/brouter/modes";
assertDirectoryExists( "modes directory", modesDir, "modes.zip" );
cor = CoordinateReader.obtainValidReader( basedir );
cor = CoordinateReader.obtainValidReader( basedir, segmentDir );
wpList = cor.waypoints;
nogoList = cor.nogopoints;
nogoVetoList = new ArrayList<OsmNodeNamed>();
@ -176,23 +180,7 @@ public class BRouterView extends View
}
}
boolean segmentFound = false;
String[] fileNames = new File( segmentDir ).list();
for( String fileName : fileNames )
{
if ( fileName.endsWith( ".rd5" ) ) segmentFound = true;
}
File carSubset = new File( segmentDir, "carsubset" );
if ( carSubset.isDirectory() )
{
fileNames = carSubset.list();
for( String fileName : fileNames )
{
if ( fileName.endsWith( ".cd5" ) ) segmentFound = true;
}
}
fileNames = new File( profileDir ).list();
String[] fileNames = new File( profileDir ).list();
ArrayList<String> profiles = new ArrayList<String>();
boolean lookupsFound = false;
@ -216,7 +204,7 @@ public class BRouterView extends View
+ " contains no routing profiles (*.brf)."
+ " see www.dr-brenschede.de/brouter for setup instructions." );
}
if ( !segmentFound )
if ( !RoutingHelper.hasDirectoryAnyDatafiles( segmentDir ) )
{
((BRouterActivity)getContext()).startDownloadManager();
waitingForSelection = true;
@ -295,7 +283,6 @@ public class BRouterView extends View
String[] wpts = new String[allpoints.size()];
int i = 0;
for( OsmNodeNamed wp : allpoints.values() ) wpts[i++] = wp.name;
System.out.println( "calling selectWaypoint..." );
((BRouterActivity)getContext()).selectWaypoint( wpts );
}
}
@ -304,7 +291,6 @@ System.out.println( "calling selectWaypoint..." );
{
wpList.add( cor.allpoints.get( waypoint ) );
cor.allpoints.remove( waypoint );
System.out.println( "updateWaypointList: " + waypoint + " wpList.size()=" + wpList.size() );
}
public void finishWaypointSelection()
@ -410,6 +396,7 @@ System.out.println( "updateWaypointList: " + waypoint + " wpList.size()=" + wpLi
}
}
private void assertDirectoryExists( String message, String path, String assetZip )
{
File f = new File( path );

View file

@ -2,12 +2,14 @@ package btools.routingapp;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Environment;
import btools.router.OsmNodeNamed;
import btools.router.RoutingHelper;
/**
* Read coordinates from a gpx-file
@ -96,7 +98,7 @@ public abstract class CoordinateReader
protected abstract void readPointmap() throws Exception;
public static CoordinateReader obtainValidReader( String basedir ) throws Exception
public static CoordinateReader obtainValidReader( String basedir, String segmentDir ) throws Exception
{
CoordinateReader cor = null;
ArrayList<CoordinateReader> rl = new ArrayList<CoordinateReader>();
@ -117,10 +119,32 @@ public abstract class CoordinateReader
}
}
// eventually add explicit directory
File additional = RoutingHelper.getAdditionalMaptoolDir(segmentDir);
if ( additional != null )
{
String base3 = additional.getAbsolutePath();
AppLogger.log( "additional maptool-base from storage-config: " + base3 );
rl.add( new CoordinateReaderOsmAnd(base3) );
rl.add( new CoordinateReaderLocus(base3) );
rl.add( new CoordinateReaderOrux(base3) );
}
long tmax = 0;
for( CoordinateReader r : rl )
{
long t = r.getTimeStamp();
if ( t != 0 )
{
if ( AppLogger.isLogging() )
{
AppLogger.log( "found coordinate source at " + r.basedir + r.rootdir + " with timestamp " + new Date( t ) );
}
}
if ( t > tmax )
{
tmax = t;