Search in sources :

Example 6 with FileSystemParam

use of uk.me.parabola.imgfmt.FileSystemParam in project mkgmap by openstreetmap.

the class MapMaker method makeMap.

/**
 * Make a map from the given map data source.
 *
 * @param args User supplied arguments.
 * @param src The data source to load.
 * @param mapNameExt
 * @return The output filename for the map.
 */
private String makeMap(CommandArgs args, LoadableMapDataSource src, String mapNamePrefix) {
    if (src.getBounds().isEmpty())
        return null;
    FileSystemParam params = new FileSystemParam();
    params.setBlockSize(args.getBlockSize());
    params.setMapDescription(args.getDescription());
    log.info("Started making", args.getMapname(), "(" + args.getDescription() + ")");
    try {
        Map map = Map.createMap(mapNamePrefix + args.getMapname(), args.getOutputDir(), params, args.getMapname(), sort);
        setOptions(map, args);
        MapBuilder builder = new MapBuilder();
        builder.config(args.getProperties());
        if (!OverviewBuilder.OVERVIEW_PREFIX.equals(mapNamePrefix)) {
            if (args.getProperties().containsKey("route") || args.getProperties().containsKey("net"))
                builder.setDoRoads(true);
        }
        builder.makeMap(map, src);
        // Collect information on map complete.
        String outName = map.getFilename();
        log.info("finished making map", outName, "closing");
        map.close();
        return outName;
    } catch (FileExistsException e) {
        throw new MapFailedException("File exists already", e);
    } catch (FileNotWritableException e) {
        throw new MapFailedException("Could not create or write to file", e);
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) MapBuilder(uk.me.parabola.mkgmap.build.MapBuilder) Map(uk.me.parabola.imgfmt.app.map.Map) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 7 with FileSystemParam

use of uk.me.parabola.imgfmt.FileSystemParam in project mkgmap by openstreetmap.

the class FileInfo method imgInfo.

/**
 * An IMG file, this involves real work. We have to read in the file and
 * extract several pieces of information from it.
 *
 * @param inputName The name of the file.
 * @return The information obtained.
 * @throws FileNotFoundException If the file doesn't exist.
 */
private static FileInfo imgInfo(String inputName) throws FileNotFoundException {
    try (FileSystem imgFs = ImgFS.openFs(inputName)) {
        FileSystemParam params = imgFs.fsparam();
        log.info("Desc", params.getMapDescription());
        log.info("Blocksize", params.getBlockSize());
        FileInfo info = new FileInfo(inputName, UNKNOWN_KIND);
        info.setDescription(params.getMapDescription());
        File f = new File(inputName);
        String name = f.getName();
        if (OverviewBuilder.isOverviewImg(name))
            name = OverviewBuilder.getMapName(name);
        int dot = name.lastIndexOf('.');
        if (dot < 0) {
            name = "0";
        } else {
            if (dot > name.length())
                dot = name.length();
            if (dot > 8)
                dot = 8;
            name = name.substring(0, dot);
        }
        info.setMapname(name);
        boolean hasTre = false;
        DirectoryEntry treEnt = null;
        List<DirectoryEntry> entries = imgFs.list();
        for (DirectoryEntry ent : entries) {
            if (ent.isSpecial())
                continue;
            log.info("file", ent.getFullName());
            String ext = ent.getExt();
            if ("TRE".equals(ext)) {
                info.setTresize(ent.getSize());
                info.setInnername(ent.getName());
                hasTre = true;
                treEnt = ent;
            } else if ("RGN".equals(ext)) {
                int size = ent.getSize();
                info.setRgnsize(size);
            } else if ("LBL".equals(ext)) {
                info.setLblsize(ent.getSize());
                lblInfo(imgFs, ent, info);
            } else if ("NET".equals(ext)) {
                info.setNetsize(ent.getSize());
            } else if ("NOD".equals(ext)) {
                info.setNodsize(ent.getSize());
            } else if ("DEM".equals(ext)) {
                info.setDemsize(ent.getSize());
            } else if ("MDR".equals(ext)) {
                // It is not actually a regular img file, so change the kind.
                info.setKind(MDR_KIND);
            } else if ("MPS".equals(ext)) {
                // This is a gmapsupp file containing several maps.
                info.setKind(GMAPSUPP_KIND);
                info.mpsName = ent.getFullName();
            }
            info.subFiles.add(new SubFileInfo(ent.getFullName(), ent.getSize()));
        }
        if (hasTre)
            treInfo(imgFs, treEnt, info);
        if (info.getKind() == UNKNOWN_KIND && hasTre)
            info.setKind(IMG_KIND);
        return info;
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) DirectoryEntry(uk.me.parabola.imgfmt.fs.DirectoryEntry) File(java.io.File)

Example 8 with FileSystemParam

use of uk.me.parabola.imgfmt.FileSystemParam in project mkgmap by openstreetmap.

the class MdrBuilder method init.

/**
 * Create the mdr file and initialise.
 * It has a name that is based on the overview-mapname option, as does
 * the associated MDX file.
 *
 * @param args The command line arguments.
 */
public void init(CommandArgs args) {
    String name = args.get("overview-mapname", "osmmap");
    String outputDir = args.getOutputDir();
    outputName = Utils.joinPath(outputDir, name + "_mdr.img");
    ImgChannel mdrChan;
    try {
        // Create the .img file system/archive
        FileSystemParam params = new FileSystemParam();
        tmpName = File.createTempFile("mdr", null, new File(outputDir));
        tmpName.deleteOnExit();
        imgfs = ImgFS.createFs(tmpName.getPath(), params);
        // Create the MDR file within the .img
        mdrChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".MDR");
    } catch (IOException e) {
        throw new ExitException("Could not create global index file");
    }
    // Create the sort description
    Sort sort = SrtTextReader.sortForCodepage(args.getCodePage());
    // Set the options that we are using for the mdr.
    MdrConfig config = new MdrConfig();
    config.setHeaderLen(568);
    config.setWritable(true);
    config.setForDevice(false);
    config.setOutputDir(outputDir);
    config.setSort(sort);
    config.setIndexOptions(args);
    // Wrap the MDR channel with the MDRFile object
    mdrFile = new MDRFile(mdrChan, config);
    try {
        ImgChannel srtChan = imgfs.create(name.toUpperCase(Locale.ENGLISH) + ".SRT");
        SRTFile srtFile = new SRTFile(srtChan);
        srtFile.setSort(sort);
        srtFile.write();
    // Do not close srtFile here
    } catch (FileExistsException e) {
        throw new ExitException("Could not create SRT file within index file");
    }
}
Also used : ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MdrConfig(uk.me.parabola.imgfmt.app.mdr.MdrConfig) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) IOException(java.io.IOException) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) File(java.io.File) MDRFile(uk.me.parabola.imgfmt.app.mdr.MDRFile) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 9 with FileSystemParam

use of uk.me.parabola.imgfmt.FileSystemParam in project mkgmap by openstreetmap.

the class ImgHeader method setHeader.

void setHeader(ByteBuffer buf) {
    buf.flip();
    header.put(buf);
    byte exp1 = header.get(OFF_BLOCK_SIZE_EXPONENT1);
    byte exp2 = header.get(OFF_BLOCK_SIZE_EXPONENT2);
    log.debug("header exponent", exp1, exp2);
    fsParams = new FileSystemParam();
    fsParams.setBlockSize(1 << (exp1 + exp2));
    fsParams.setDirectoryStartEntry(header.get(OFF_DIRECTORY_START_BLOCK));
    StringBuffer sb = new StringBuffer();
    sb.append(Utils.bytesToString(buf, OFF_MAP_DESCRIPTION, LEN_MAP_DESCRIPTION));
    sb.append(Utils.bytesToString(buf, OFF_MAP_NAME_CONT, LEN_MAP_NAME_CONT));
    fsParams.setMapDescription(sb.toString().trim());
    byte h = header.get(OFF_END_HEAD);
    byte sc1 = header.get(OFF_END_SECTOR);
    byte sc2 = header.get(OFF_END_CYLINDER);
    CHS chs = new CHS();
    chs.setFromPartition(h, sc1, sc2);
    int lba = chs.toLba();
    log.info("partition sectors", lba);
// ... more to do
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam)

Aggregations

FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)9 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)4 ExitException (uk.me.parabola.imgfmt.ExitException)3 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)3 Map (uk.me.parabola.imgfmt.app.map.Map)3 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)3 File (java.io.File)2 Sort (uk.me.parabola.imgfmt.app.srt.Sort)2 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)2 MapBuilder (uk.me.parabola.mkgmap.build.MapBuilder)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 Area (uk.me.parabola.imgfmt.app.Area)1 MDRFile (uk.me.parabola.imgfmt.app.mdr.MDRFile)1 MdrConfig (uk.me.parabola.imgfmt.app.mdr.MdrConfig)1 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)1 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)1 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)1 DirectoryEntry (uk.me.parabola.imgfmt.fs.DirectoryEntry)1