Search in sources :

Example 1 with MapUnzip

use of com.junjunguo.pocketmaps.downloader.MapUnzip in project PocketMaps by junjunguo.

the class DownloadMapActivity method unzipBg.

private static void unzipBg(final MyMap myMap, final MyDownloadAdapter dlAdapter) {
    log("Unzipping map: " + myMap.getMapName());
    myMap.setStatus(MyMap.DlStatus.Unzipping);
    refreshMapEntry(myMap, dlAdapter);
    new AsyncTask<URL, Integer, MyMap>() {

        String errMsg = null;

        @Override
        protected MyMap doInBackground(URL... params) {
            File ghzFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlMapFile);
            if (ghzFile.exists()) {
                try {
                    new MapUnzip().unzip(ghzFile.getPath(), new File(Variable.getVariable().getMapsFolder(), myMap.getMapName() + "-gh").getAbsolutePath());
                } catch (IOException e) {
                    errMsg = "Error unpacking map: " + myMap.getMapName();
                }
            } else {
                errMsg = "Error, missing downloaded file: " + ghzFile.getPath();
            }
            clearDlFile(myMap);
            return myMap;
        }

        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(MyMap myMaps) {
            super.onPostExecute(myMaps);
            refreshMapEntry(myMap, dlAdapter);
            if (errMsg != null) {
                File idFile = MyMap.getMapFile(myMap, MyMap.MapFileType.DlIdFile);
                IO.writeToFile("" + MyMap.DlStatus.Error + ": " + errMsg, idFile, false);
                myMap.setStatus(MyMap.DlStatus.Error);
                return;
            }
            Variable.getVariable().getRecentDownloadedMaps().add(myMap);
            MyMap.setVersionCompatible(myMap.getMapName(), myMap);
            myMap.setStatus(MyMap.DlStatus.Complete);
        }
    }.execute();
}
Also used : MyMap(com.junjunguo.pocketmaps.model.MyMap) MapUnzip(com.junjunguo.pocketmaps.downloader.MapUnzip) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Aggregations

MapUnzip (com.junjunguo.pocketmaps.downloader.MapUnzip)1 MyMap (com.junjunguo.pocketmaps.model.MyMap)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1