Cleanup base directory selection, use Context.getExternalFilesDirs and request WRITE_EXTERNAL_STORAGE permission, use AndroidX and raise minSdkVersion to 14. Use File instead of plain Strings for paths in some places, use try-with-resources, and some other small improvements.

This commit is contained in:
Niklas Guertler 2020-05-24 17:49:50 +02:00
parent 72e2e13d07
commit dbdfd36f88
17 changed files with 173 additions and 220 deletions

View file

@ -56,10 +56,10 @@ public final class NodesCache
return "collecting=" + garbageCollectionEnabled + " noGhosts=" + ghostCleaningDone + " cacheSum=" + cacheSum + " cacheSumClean=" + cacheSumClean + " ghostSum=" + ghostSum + " ghostWakeup=" + ghostWakeup ;
}
public NodesCache( String segmentDir, BExpressionContextWay ctxWay, boolean forceSecondaryData, long maxmem, NodesCache oldCache, boolean detailed )
public NodesCache( File segmentDir, BExpressionContextWay ctxWay, boolean forceSecondaryData, long maxmem, NodesCache oldCache, boolean detailed )
{
this.maxmemtiles = maxmem / 8;
this.segmentDir = new File( segmentDir );
this.segmentDir = segmentDir;
this.nodesMap = new OsmNodesMap();
this.nodesMap.maxmem = (2L*maxmem) / 3L;
this.expCtxWay = ctxWay;
@ -77,7 +77,7 @@ public final class NodesCache
first_file_access_name = null;
if ( !this.segmentDir.isDirectory() )
throw new RuntimeException( "segment directory " + segmentDir + " does not exist" );
throw new RuntimeException( "segment directory " + segmentDir.getAbsolutePath () + " does not exist" );
if ( oldCache != null )
{

View file

@ -11,21 +11,21 @@ import java.io.FileReader;
public class StorageConfigHelper
{
public static File getSecondarySegmentDir( String segmentDir )
public static File getSecondarySegmentDir( File segmentDir )
{
return getStorageLocation( segmentDir, "secondary_segment_dir=" );
}
public static File getAdditionalMaptoolDir( String segmentDir )
public static File getAdditionalMaptoolDir( File segmentDir )
{
return getStorageLocation( segmentDir, "additional_maptool_dir=" );
}
private static File getStorageLocation( String segmentDir, String tag )
private static File getStorageLocation( File segmentDir, String tag )
{
File res = null;
BufferedReader br = null;
String configFile = segmentDir + "/storageconfig.txt";
File configFile = new File (segmentDir, "storageconfig.txt");
try
{
br = new BufferedReader( new FileReader( configFile ) );
@ -38,7 +38,7 @@ public class StorageConfigHelper
if ( line.startsWith( tag ) )
{
String path = line.substring( tag.length() ).trim();
res = path.startsWith( "/" ) ? new File( path ) : new File( new File( segmentDir ), path );
res = path.startsWith( "/" ) ? new File( path ) : new File( segmentDir, path );
if ( !res.exists() ) res = null;
break;
}