/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitMapDownloader.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitMapDownloader.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations) (download)
Wed Jun 22 07:33:35 2016 UTC (7 years, 9 months ago) by zoff99
File size: 125932 byte(s)
v2.0.51
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.io.BufferedInputStream;
42 import java.io.BufferedReader;
43 import java.io.File;
44 import java.io.FileInputStream;
45 import java.io.FileNotFoundException;
46 import java.io.FileOutputStream;
47 import java.io.FileReader;
48 import java.io.IOException;
49 import java.io.InputStream;
50 import java.io.InputStreamReader;
51 import java.io.OutputStreamWriter;
52 import java.io.RandomAccessFile;
53 import java.net.HttpURLConnection;
54 import java.net.URL;
55 import java.net.URLEncoder;
56 import java.security.MessageDigest;
57 import java.security.NoSuchAlgorithmException;
58 import java.security.SecureRandom;
59 import java.text.DecimalFormat;
60 import java.text.NumberFormat;
61 import java.text.SimpleDateFormat;
62 import java.util.ArrayList;
63 import java.util.Date;
64 import java.util.Iterator;
65 import java.util.List;
66 import java.util.Locale;
67 import java.util.TimeZone;
68
69 import javax.net.ssl.HostnameVerifier;
70 import javax.net.ssl.HttpsURLConnection;
71 import javax.net.ssl.SSLContext;
72 import javax.net.ssl.SSLSession;
73 import javax.net.ssl.SSLSocketFactory;
74 import javax.net.ssl.X509TrustManager;
75
76 import android.annotation.SuppressLint;
77 import android.os.Bundle;
78 import android.os.Handler;
79 import android.os.Message;
80 import android.util.Log;
81 import android.view.View;
82
83 public class NavitMapDownloader
84 {
85 static final String ZANAVI_MAPS_AGE_URL = "http://maps.zanavi.cc/maps_age.html";
86
87 // ------- RELEASE SETTINGS --------
88 // ------- RELEASE SETTINGS --------
89 static String ZANAVI_MAPS_BASE_URL = "http://dl.zanavi.cc/data/";
90 static String ZANAVI_MAPS_SEVERTEXT_URL = "http://dl.zanavi.cc/server.txt";
91 static final String ZANAVI_MAPS_BASE_URL_PROTO = "http://";
92 static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/data/";
93 // ------- RELEASE SETTINGS --------
94 // ------- RELEASE SETTINGS --------
95
96 // ------- DEBUG DEBUG SETTINGS --------
97 // ------- DEBUG DEBUG SETTINGS --------
98 //static final String ZANAVI_MAPS_BASE_URL = "https://192.168.0.3:446/maps/";
99 //static final String ZANAVI_MAPS_SEVERTEXT_URL = "https://192.168.0.3:446/maps/server.txt";
100 //static final String ZANAVI_MAPS_BASE_URL_PROTO = "https://";
101 //static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/maps/";
102 // ------- DEBUG DEBUG SETTINGS --------
103 // ------- DEBUG DEBUG SETTINGS --------
104
105 static int MULTI_NUM_THREADS_MAX = 4;
106 static int MULTI_NUM_THREADS = 1; // how many download streams for a file
107 static int MULTI_NUM_THREADS_LOCAL = 1; // how many download streams for the current file from the current server
108
109 public static class zanavi_osm_map_values
110 {
111 String map_name = "";
112 String url = "";
113 long est_size_bytes = 0;
114 String est_size_bytes_human_string = "";
115 String text_for_select_list = "";
116 Boolean is_continent = false;
117 int continent_id = 0;
118
119 public zanavi_osm_map_values(String mapname, String url, long bytes_est, Boolean is_con, int con_id)
120 {
121 this.is_continent = is_con;
122 this.continent_id = con_id;
123 this.map_name = mapname;
124 this.url = url;
125 this.est_size_bytes = bytes_est;
126 if (this.est_size_bytes <= 0)
127 {
128 // dummy entry, dont show size!
129 this.est_size_bytes_human_string = "";
130 }
131 else
132 {
133 if (((int) ((float) (this.est_size_bytes) / 1024f / 1024f)) > 0)
134 {
135 this.est_size_bytes_human_string = " " + (int) ((float) (this.est_size_bytes) / 1024f / 1024f) + "MB";
136 }
137 else
138 {
139 this.est_size_bytes_human_string = " " + (int) ((float) (this.est_size_bytes) / 1024f) + "kB";
140 }
141 }
142 this.text_for_select_list = this.map_name + " " + this.est_size_bytes_human_string;
143 }
144 }
145
146 //
147 // define the maps here
148 //
149 //
150 static final zanavi_osm_map_values z_Caribbean = new zanavi_osm_map_values("Caribbean", "caribbean.bin", -2, true, 136);
151 //
152 static final zanavi_osm_map_values z_North_America = new zanavi_osm_map_values("North America", "north_america.bin", -2, true, 6);
153 static final zanavi_osm_map_values z_Country_borders = new zanavi_osm_map_values("Country borders [detail]", "borders.bin", 6271108L, true, 0);
154 static final zanavi_osm_map_values z_Coastline = new zanavi_osm_map_values("Coastline", "coastline.bin", 202836110L, true, 0);
155 static final zanavi_osm_map_values z_Restl_welt = new zanavi_osm_map_values("Rest of the World", "restl_welt.bin", 128693232L, true, 0);
156 static zanavi_osm_map_values z_Planet = new zanavi_osm_map_values("Planet", "planet.bin", 12602823892L, true, 1);
157 static zanavi_osm_map_values z_Europe = new zanavi_osm_map_values("Europe", "europe.bin", 4591607513L, true, 3);
158 static final zanavi_osm_map_values z_Africa = new zanavi_osm_map_values("Africa", "africa.bin", 181729912L, true, 4);
159 static final zanavi_osm_map_values z_Asia = new zanavi_osm_map_values("Asia", "asia.bin", 1060290831L, true, 5);
160 static zanavi_osm_map_values z_USA = new zanavi_osm_map_values("USA", "usa.bin", 2004502679L, true, 27);
161 static final zanavi_osm_map_values z_Central_America = new zanavi_osm_map_values("Central America", "central_america.bin", 85755028L, true, 7);
162 static final zanavi_osm_map_values z_South_America = new zanavi_osm_map_values("South America", "south_america.bin", 198785352L, true, 8);
163 static final zanavi_osm_map_values z_Australia_and_Oceania = new zanavi_osm_map_values("Australia and Oceania", "australia_oceania.bin", 100802136L, true, 9);
164 static final zanavi_osm_map_values z_Albania = new zanavi_osm_map_values("Albania", "albania.bin", 2707162L, false, 3);
165 static final zanavi_osm_map_values z_Alps = new zanavi_osm_map_values("Alps", "alps.bin", 607357380L, false, 3);
166 static final zanavi_osm_map_values z_Andorra = new zanavi_osm_map_values("Andorra", "andorra.bin", 209729L, false, 3);
167 static final zanavi_osm_map_values z_Austria = new zanavi_osm_map_values("Austria", "austria.bin", 135024402L, false, 3);
168 static final zanavi_osm_map_values z_Azores = new zanavi_osm_map_values("Azores", "azores.bin", 786952L, false, 3);
169 static final zanavi_osm_map_values z_Belarus = new zanavi_osm_map_values("Belarus", "belarus.bin", 35370454L, false, 3);
170 static final zanavi_osm_map_values z_Belgium = new zanavi_osm_map_values("Belgium", "belgium.bin", 59776296L, false, 3);
171 static final zanavi_osm_map_values z_Bosnia_Herzegovina = new zanavi_osm_map_values("Bosnia-Herzegovina", "bosnia-herzegovina.bin", 20965766L, false, 3);
172 static final zanavi_osm_map_values z_British_Isles = new zanavi_osm_map_values("British Isles", "british_isles.bin", 287714717L, false, 3);
173 static final zanavi_osm_map_values z_Bulgaria = new zanavi_osm_map_values("Bulgaria", "bulgaria.bin", 187458L, false, 3);
174 static final zanavi_osm_map_values z_Croatia = new zanavi_osm_map_values("Croatia", "croatia.bin", 19816810L, false, 3);
175 static final zanavi_osm_map_values z_Cyprus = new zanavi_osm_map_values("Cyprus", "cyprus.bin", 3062844L, false, 3);
176 static final zanavi_osm_map_values z_Czech_Republic = new zanavi_osm_map_values("Czech Republic", "czech_republic.bin", 163908356L, false, 3);
177 static final zanavi_osm_map_values z_Denmark = new zanavi_osm_map_values("Denmark", "denmark.bin", 67254793L, false, 3);
178 static final zanavi_osm_map_values z_Estonia = new zanavi_osm_map_values("Estonia", "estonia.bin", 16299316L, false, 3);
179 static final zanavi_osm_map_values z_Faroe_Islands = new zanavi_osm_map_values("Faroe Islands", "faroe_islands.bin", 601782L, false, 3);
180 static final zanavi_osm_map_values z_Finland = new zanavi_osm_map_values("Finland", "finland.bin", 79130118L, false, 3);
181 static final zanavi_osm_map_values z_France = new zanavi_osm_map_values("France", "france.bin", 1326166093L, false, 3);
182 static final zanavi_osm_map_values z_Germany = new zanavi_osm_map_values("Germany", "germany.bin", 753234730L, false, 3);
183 static final zanavi_osm_map_values z_Great_Britain = new zanavi_osm_map_values("Great Britain", "great_britain.bin", 256173213L, false, 3);
184 static final zanavi_osm_map_values z_Greece = new zanavi_osm_map_values("Greece", "greece.bin", 36331613L, false, 3);
185 static final zanavi_osm_map_values z_Hungary = new zanavi_osm_map_values("Hungary", "hungary.bin", 20996247L, false, 3);
186 static final zanavi_osm_map_values z_Iceland = new zanavi_osm_map_values("Iceland", "iceland.bin", 5949356L, false, 3);
187 static final zanavi_osm_map_values z_Ireland = new zanavi_osm_map_values("Ireland", "ireland.bin", 30020687L, false, 3);
188 static final zanavi_osm_map_values z_Isle_of_man = new zanavi_osm_map_values("Isle of man", "isle_of_man.bin", 876966L, false, 3);
189 static final zanavi_osm_map_values z_Italy = new zanavi_osm_map_values("Italy", "italy.bin", 344050769L, false, 3);
190 static final zanavi_osm_map_values z_Kosovo = new zanavi_osm_map_values("Kosovo", "kosovo.bin", 2726077L, false, 3);
191 static final zanavi_osm_map_values z_Latvia = new zanavi_osm_map_values("Latvia", "latvia.bin", 19153876L, false, 3);
192 static final zanavi_osm_map_values z_Liechtenstein = new zanavi_osm_map_values("Liechtenstein", "liechtenstein.bin", 329042L, false, 3);
193 static final zanavi_osm_map_values z_Lithuania = new zanavi_osm_map_values("Lithuania", "lithuania.bin", 15062324L, false, 3);
194 static final zanavi_osm_map_values z_Luxembourg = new zanavi_osm_map_values("Luxembourg", "luxembourg.bin", 5555131L, false, 3);
195 static final zanavi_osm_map_values z_Macedonia = new zanavi_osm_map_values("Macedonia", "macedonia.bin", 3652744L, false, 3);
196 static final zanavi_osm_map_values z_Malta = new zanavi_osm_map_values("Malta", "malta.bin", 665042L, false, 3);
197 static final zanavi_osm_map_values z_Moldova = new zanavi_osm_map_values("Moldova", "moldova.bin", 7215780L, false, 3);
198 static final zanavi_osm_map_values z_Monaco = new zanavi_osm_map_values("Monaco", "monaco.bin", 91311L, false, 3);
199 static final zanavi_osm_map_values z_Montenegro = new zanavi_osm_map_values("Montenegro", "montenegro.bin", 2377175L, false, 3);
200 static final zanavi_osm_map_values z_Netherlands = new zanavi_osm_map_values("Netherlands", "netherlands.bin", 231414741L, false, 3);
201 static final zanavi_osm_map_values z_Norway = new zanavi_osm_map_values("Norway", "norway.bin", 45117034L, false, 3);
202 static final zanavi_osm_map_values z_Poland = new zanavi_osm_map_values("Poland", "poland.bin", 113291596L, false, 3);
203 static final zanavi_osm_map_values z_Portugal = new zanavi_osm_map_values("Portugal", "portugal.bin", 30029993L, false, 3);
204 static final zanavi_osm_map_values z_Romania = new zanavi_osm_map_values("Romania", "romania.bin", 39689553L, false, 3);
205 static final zanavi_osm_map_values z_Russia_European_part = new zanavi_osm_map_values("Russia European part", "russia-european-part.bin", 264245236L, false, 3);
206 static final zanavi_osm_map_values z_Serbia = new zanavi_osm_map_values("Serbia", "serbia.bin", 11166698L, false, 3);
207 static final zanavi_osm_map_values z_Slovakia = new zanavi_osm_map_values("Slovakia", "slovakia.bin", 69898534L, false, 3);
208 static final zanavi_osm_map_values z_Slovenia = new zanavi_osm_map_values("Slovenia", "slovenia.bin", 10406937L, false, 3);
209 static final zanavi_osm_map_values z_Spain = new zanavi_osm_map_values("Spain", "spain.bin", 183072016L, false, 3);
210 static final zanavi_osm_map_values z_Sweden = new zanavi_osm_map_values("Sweden", "sweden.bin", 79947733L, false, 3);
211 static final zanavi_osm_map_values z_Switzerland = new zanavi_osm_map_values("Switzerland", "switzerland.bin", 73051065L, false, 3);
212 static final zanavi_osm_map_values z_Turkey = new zanavi_osm_map_values("Turkey", "turkey.bin", 33231427L, false, 3);
213 static final zanavi_osm_map_values z_Ukraine = new zanavi_osm_map_values("Ukraine", "ukraine.bin", 58070734L, false, 3);
214 static final zanavi_osm_map_values z_Canari_Islands = new zanavi_osm_map_values("Canari Islands", "canari_islands.bin", 7125254L, false, 4);
215 static final zanavi_osm_map_values z_India = new zanavi_osm_map_values("India", "india.bin", 46569907L, false, 5);
216 static final zanavi_osm_map_values z_Israel_and_Palestine = new zanavi_osm_map_values("Israel and Palestine", "israel_and_palestine.bin", 15630491L, false, 5);
217 static final zanavi_osm_map_values z_China = new zanavi_osm_map_values("China", "china.bin", 49738512L, false, 5);
218 static final zanavi_osm_map_values z_Japan = new zanavi_osm_map_values("Japan", "japan.bin", 413065433L, false, 5);
219 static final zanavi_osm_map_values z_Taiwan = new zanavi_osm_map_values("Taiwan", "taiwan.bin", 5689334L, false, 5);
220 static final zanavi_osm_map_values z_Canada = new zanavi_osm_map_values("Canada", "canada.bin", 830908722L, false, 6);
221 static final zanavi_osm_map_values z_Greenland = new zanavi_osm_map_values("Greenland", "greenland.bin", 500803L, false, 6);
222 static final zanavi_osm_map_values z_Mexico = new zanavi_osm_map_values("Mexico", "mexico.bin", 29858297L, false, 6);
223 static zanavi_osm_map_values z_US_Midwest = new zanavi_osm_map_values("US-Midwest", "us-midwest.bin", 495302706L, false, 27);
224 static zanavi_osm_map_values z_US_Northeast = new zanavi_osm_map_values("US-Northeast", "us-northeast.bin", 206503509L, false, 27);
225 static zanavi_osm_map_values z_US_Pacific = new zanavi_osm_map_values("US-Pacific", "us-pacific.bin", 11527206L, false, 27);
226 static zanavi_osm_map_values z_US_South = new zanavi_osm_map_values("US-South", "us-south.bin", 803391332L, false, 27);
227 static zanavi_osm_map_values z_US_West = new zanavi_osm_map_values("US-West", "us-west.bin", 506304481L, false, 27);
228 static final zanavi_osm_map_values z_Alabama = new zanavi_osm_map_values("Alabama", "alabama.bin", 35081542L, false, 27);
229 static final zanavi_osm_map_values z_Alaska = new zanavi_osm_map_values("Alaska", "alaska.bin", 7844950L, false, 27);
230 static final zanavi_osm_map_values z_Arizona = new zanavi_osm_map_values("Arizona", "arizona.bin", 33938704L, false, 27);
231 static final zanavi_osm_map_values z_Arkansas = new zanavi_osm_map_values("Arkansas", "arkansas.bin", 22029069L, false, 27);
232 static final zanavi_osm_map_values z_California = new zanavi_osm_map_values("California", "california.bin", 203758150L, false, 27);
233 static final zanavi_osm_map_values z_North_Carolina = new zanavi_osm_map_values("North Carolina", "north-carolina.bin", 128642801L, false, 27);
234 static final zanavi_osm_map_values z_South_Carolina = new zanavi_osm_map_values("South Carolina", "south-carolina.bin", 41257655L, false, 27);
235 static final zanavi_osm_map_values z_Colorado = new zanavi_osm_map_values("Colorado", "colorado.bin", 67174144L, false, 27);
236 static final zanavi_osm_map_values z_North_Dakota = new zanavi_osm_map_values("North Dakota", "north-dakota.bin", 45925872L, false, 27);
237 static final zanavi_osm_map_values z_South_Dakota = new zanavi_osm_map_values("South Dakota", "south-dakota.bin", 13888265L, false, 27);
238 static final zanavi_osm_map_values z_District_of_Columbia = new zanavi_osm_map_values("District of Columbia", "district-of-columbia.bin", 5693682L, false, 27);
239 static final zanavi_osm_map_values z_Connecticut = new zanavi_osm_map_values("Connecticut", "connecticut.bin", 7189491L, false, 27);
240 static final zanavi_osm_map_values z_Delaware = new zanavi_osm_map_values("Delaware", "delaware.bin", 3089068L, false, 27);
241 static final zanavi_osm_map_values z_Florida = new zanavi_osm_map_values("Florida", "florida.bin", 49772033L, false, 27);
242 static final zanavi_osm_map_values z_Georgia = new zanavi_osm_map_values("Georgia", "georgia.bin", 83076475L, false, 27);
243 static final zanavi_osm_map_values z_New_Hampshire = new zanavi_osm_map_values("New Hampshire", "new-hampshire.bin", 13900082L, false, 27);
244 static final zanavi_osm_map_values z_Hawaii = new zanavi_osm_map_values("Hawaii", "hawaii.bin", 3670926L, false, 27);
245 static final zanavi_osm_map_values z_Idaho = new zanavi_osm_map_values("Idaho", "idaho.bin", 27122570L, false, 27);
246 static final zanavi_osm_map_values z_Illinois = new zanavi_osm_map_values("Illinois", "illinois.bin", 64992622L, false, 27);
247 static final zanavi_osm_map_values z_Indiana = new zanavi_osm_map_values("Indiana", "indiana.bin", 23877847L, false, 27);
248 static final zanavi_osm_map_values z_Iowa = new zanavi_osm_map_values("Iowa", "iowa.bin", 47021367L, false, 27);
249 static final zanavi_osm_map_values z_New_Jersey = new zanavi_osm_map_values("New Jersey", "new-jersey.bin", 25412463L, false, 27);
250 static final zanavi_osm_map_values z_Kansas = new zanavi_osm_map_values("Kansas", "kansas.bin", 22432235L, false, 27);
251 static final zanavi_osm_map_values z_Kentucky = new zanavi_osm_map_values("Kentucky", "kentucky.bin", 34892443L, false, 27);
252 static final zanavi_osm_map_values z_Louisiana = new zanavi_osm_map_values("Louisiana", "louisiana.bin", 40739401L, false, 27);
253 static final zanavi_osm_map_values z_Maine = new zanavi_osm_map_values("Maine", "maine.bin", 14716304L, false, 27);
254 static final zanavi_osm_map_values z_Maryland = new zanavi_osm_map_values("Maryland", "maryland.bin", 27470086L, false, 27);
255 static final zanavi_osm_map_values z_Massachusetts = new zanavi_osm_map_values("Massachusetts", "massachusetts.bin", 42398142L, false, 27);
256 static final zanavi_osm_map_values z_New_Mexico = new zanavi_osm_map_values("New Mexico", "new-mexico.bin", 26815652L, false, 27);
257 static final zanavi_osm_map_values z_Michigan = new zanavi_osm_map_values("Michigan", "michigan.bin", 44192808L, false, 27);
258 static final zanavi_osm_map_values z_Minnesota = new zanavi_osm_map_values("Minnesota", "minnesota.bin", 82203062L, false, 27);
259 static final zanavi_osm_map_values z_Mississippi = new zanavi_osm_map_values("Mississippi", "mississippi.bin", 31680044L, false, 27);
260 static final zanavi_osm_map_values z_Missouri = new zanavi_osm_map_values("Missouri", "missouri.bin", 39762823L, false, 27);
261 static final zanavi_osm_map_values z_Montana = new zanavi_osm_map_values("Montana", "montana.bin", 22707427L, false, 27);
262 static final zanavi_osm_map_values z_Nebraska = new zanavi_osm_map_values("Nebraska", "nebraska.bin", 25624308L, false, 27);
263 static final zanavi_osm_map_values z_Nevada = new zanavi_osm_map_values("Nevada", "nevada.bin", 21979548L, false, 27);
264 static final zanavi_osm_map_values z_Ohio = new zanavi_osm_map_values("Ohio", "ohio.bin", 40769081L, false, 27);
265 static final zanavi_osm_map_values z_Oklahoma = new zanavi_osm_map_values("Oklahoma", "oklahoma.bin", 55866120L, false, 27);
266 static final zanavi_osm_map_values z_Oregon = new zanavi_osm_map_values("Oregon", "oregon.bin", 36940277L, false, 27);
267 static final zanavi_osm_map_values z_Pennsylvania = new zanavi_osm_map_values("Pennsylvania", "pennsylvania.bin", 51500049L, false, 27);
268 static final zanavi_osm_map_values z_Rhode_Island = new zanavi_osm_map_values("Rhode Island", "rhode-island.bin", 3691209L, false, 27);
269 static final zanavi_osm_map_values z_Tennessee = new zanavi_osm_map_values("Tennessee", "tennessee.bin", 30511825L, false, 27);
270 static final zanavi_osm_map_values z_Texas = new zanavi_osm_map_values("Texas", "texas.bin", 108367999L, false, 27);
271 static final zanavi_osm_map_values z_Utah = new zanavi_osm_map_values("Utah", "utah.bin", 19254246L, false, 27);
272 static final zanavi_osm_map_values z_Vermont = new zanavi_osm_map_values("Vermont", "vermont.bin", 7917383L, false, 27);
273 static final zanavi_osm_map_values z_Virginia = new zanavi_osm_map_values("Virginia", "virginia.bin", 98109314L, false, 27);
274 static final zanavi_osm_map_values z_West_Virginia = new zanavi_osm_map_values("West Virginia", "west-virginia.bin", 12267128L, false, 27);
275 static final zanavi_osm_map_values z_Washington = new zanavi_osm_map_values("Washington", "washington.bin", 34281164L, false, 27);
276 static final zanavi_osm_map_values z_Wisconsin = new zanavi_osm_map_values("Wisconsin", "wisconsin.bin", 44033160L, false, 27);
277 static final zanavi_osm_map_values z_Wyoming = new zanavi_osm_map_values("Wyoming", "wyoming.bin", 15865183L, false, 27);
278 static final zanavi_osm_map_values z_New_York = new zanavi_osm_map_values("New York", "new-york.bin", 39570304L, false, 27);
279 static final zanavi_osm_map_values z_USA_minor_Islands = new zanavi_osm_map_values("USA minor Islands", "usa_minor_islands.bin", 82368743L, false, 27);
280 static final zanavi_osm_map_values z_Panama = new zanavi_osm_map_values("Panama", "panama.bin", 1083594L, false, 7);
281 static final zanavi_osm_map_values z_Haiti_and_Dom_Rep_ = new zanavi_osm_map_values("Haiti and Dom.Rep.", "haiti_and_domrep.bin", 11542018L, false, 136);
282 static final zanavi_osm_map_values z_Cuba = new zanavi_osm_map_values("Cuba", "cuba.bin", 4227465L, false, 136);
283 static final zanavi_osm_map_values z_Rest_of_World = new zanavi_osm_map_values("Rest of World", "restl_welt.bin", 200171328L, false, 1);
284 //
285 //
286 //
287 static final zanavi_osm_map_values[] z_OSM_MAPS = new zanavi_osm_map_values[] { z_Country_borders, z_Coastline, z_Rest_of_World, z_Planet, z_Europe, z_North_America, z_USA, z_Central_America, z_South_America, z_Africa, z_Asia, z_Australia_and_Oceania, z_Caribbean, z_Albania, z_Alps, z_Andorra, z_Austria, z_Azores, z_Belarus, z_Belgium, z_Bosnia_Herzegovina, z_British_Isles, z_Bulgaria, z_Croatia, z_Cyprus, z_Czech_Republic, z_Denmark, z_Estonia, z_Faroe_Islands, z_Finland, z_France,
288 z_Germany, z_Great_Britain, z_Greece, z_Hungary, z_Iceland, z_Ireland, z_Isle_of_man, z_Italy, z_Kosovo, z_Latvia, z_Liechtenstein, z_Lithuania, z_Luxembourg, z_Macedonia, z_Malta, z_Moldova, z_Monaco, z_Montenegro, z_Netherlands, z_Norway, z_Poland, z_Portugal, z_Romania, z_Russia_European_part, z_Serbia, z_Slovakia, z_Slovenia, z_Spain, z_Sweden, z_Switzerland, z_Turkey, z_Ukraine, z_Canari_Islands, z_India, z_Israel_and_Palestine, z_China, z_Japan, z_Taiwan, z_Canada,
289 z_Greenland, z_Mexico, z_US_Midwest, z_US_Northeast, z_US_Pacific, z_US_South, z_US_West, z_Alabama, z_Alaska, z_Arizona, z_Arkansas, z_California, z_North_Carolina, z_South_Carolina, z_Colorado, z_North_Dakota, z_South_Dakota, z_District_of_Columbia, z_Connecticut, z_Delaware, z_Florida, z_Georgia, z_New_Hampshire, z_Hawaii, z_Idaho, z_Illinois, z_Indiana, z_Iowa, z_New_Jersey, z_Kansas, z_Kentucky, z_Louisiana, z_Maine, z_Maryland, z_Massachusetts, z_New_Mexico, z_Michigan,
290 z_Minnesota, z_Mississippi, z_Missouri, z_Montana, z_Nebraska, z_Nevada, z_Ohio, z_Oklahoma, z_Oregon, z_Pennsylvania, z_Rhode_Island, z_Tennessee, z_Texas, z_Utah, z_Vermont, z_Virginia, z_West_Virginia, z_Washington, z_Wisconsin, z_Wyoming, z_New_York, z_USA_minor_Islands, z_Panama, z_Haiti_and_Dom_Rep_, z_Cuba };
291
292 //
293 //
294 //
295 //
296 //
297 public static String[] OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = null;
298 public static String[] OSM_MAP_NAME_LIST_ondisk = null;
299
300 public static int[] OSM_MAP_NAME_ORIG_ID_LIST = null;
301 public static String[] OSM_MAP_NAME_ondisk_ORIG_LIST = null;
302
303 private static Boolean already_inited = false;
304
305 public Boolean stop_me = false;
306 static final int SOCKET_CONNECT_TIMEOUT = 6000; // 22000; // 22 secs.
307 static final int SOCKET_READ_TIMEOUT = 9000; // 18000; // 18 secs.
308 // static final int MAP_WRITE_FILE_BUFFER = 1024 * 8;
309 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64;
310 static final int MAP_READ_FILE_BUFFER = 1024 * 64;
311 static final int UPDATE_PROGRESS_EVERY_CYCLE = 256; // 12; // 8 -> is nicer, but maybe to fast for some devices
312 static final int RETRIES = 9000; // 75; // this many retries on map download
313 static final int MD5_CALC_BUFFER_KB = 128;
314
315 static final long MAX_SINGLE_BINFILE_SIZE = 3 * 512 * 1024 * 1024; // split map at this size into pieces [1.5GB] [1.610.612.736 Bytes]
316 // static final long MAX_SINGLE_BINFILE_SIZE = 800 * 1024 * 1024; // split map at this size into pieces [~800 MBytes]
317 // --- DEBUG ONLY --- // static final long MAX_SINGLE_BINFILE_SIZE = 80 * 1024 * 1024; // 80 MBytes // --- DEBUG ONLY --- //
318
319 static final String DOWNLOAD_FILENAME = "navitmap.tmp";
320 static final String MD5_DOWNLOAD_TEMPFILE = "navitmap_tmp.md5";
321 static final String CAT_FILE = "maps_cat.txt";
322 public static List<String> map_catalogue = new ArrayList<String>();
323 public static List<String> map_catalogue_date = new ArrayList<String>();
324 public static List<String> map_servers_used = new ArrayList<String>();
325 static final String MAP_CAT_HEADER = "# ZANavi maps -- do not edit by hand --";
326 public static final String MAP_URL_NAME_UNKNOWN = "* unknown map *";
327 public static final String MAP_DISK_NAME_UNKNOWN = "-> unknown map";
328
329 static final String MAP_FILENAME_PRI = "navitmap_001.bin";
330 static final String MAP_FILENAME_SEC = "navitmap_002.bin";
331 static final String MAP_FILENAME_BASE = "navitmap_%03d.bin";
332 static final int MAP_MAX_FILES = 19;
333 static final String MAP_FILENAME_BORDERS = "borders.bin";
334 static final String MAP_FILENAME_COASTLINE = "coastline.bin";
335
336 static long[] mapdownload_already_read = null;
337 static float[] mapdownload_byte_per_second_overall = null;
338 static float[] mapdownload_byte_per_second_now = null;
339 static int mapdownload_error_code = 0;
340 static Boolean mapdownload_stop_all_threads = false;
341
342 static final int MAX_MAP_COUNT = 500;
343
344 public class ProgressThread extends Thread
345 {
346 Handler mHandler;
347 zanavi_osm_map_values map_values;
348 int map_num;
349 int my_dialog_num;
350
351 ProgressThread(Handler h, zanavi_osm_map_values map_values, int map_num2)
352 {
353 this.mHandler = h;
354 this.map_values = map_values;
355 this.map_num = map_num2;
356 if (this.map_num == Navit.MAP_NUM_PRIMARY)
357 {
358 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
359 }
360 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
361 {
362 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
363 }
364 }
365
366 public void run()
367 {
368 stop_me = false;
369 mapdownload_stop_all_threads = false;
370 System.out.println("DEBUG_MAP_DOWNLOAD::map_num=" + this.map_num + " v=" + map_values.map_name + " " + map_values.url);
371
372 // ----- service start -----
373 // ----- service start -----
374 // Navit.getBaseContext_.startService(Navit.ZANaviMapDownloaderServiceIntent);
375 // ----- service start -----
376 // ----- service start -----
377
378 //
379 //Navit.dim_screen_wrapper(); // brightness ---------
380 int exit_code = download_osm_map(mHandler, map_values, this.map_num);
381 //Navit.default_brightness_screen_wrapper(); // brightness ---------
382 //
383
384 try
385 {
386 // hide download actionbar icon
387 Message msg2 = Navit.Navit_progress_h.obtainMessage();
388 Bundle b2 = new Bundle();
389 msg2.what = 24;
390 msg2.setData(b2);
391 Navit.Navit_progress_h.sendMessage(msg2);
392 }
393 catch (Exception e)
394 {
395 }
396
397 // ----- service stop -----
398 // ----- service stop -----
399 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
400 // ----- service stop -----
401 // ----- service stop -----
402
403 // clean up always
404 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME);
405 tmp_downloadfile.delete();
406 for (int jkl = 1; jkl < 51; jkl++)
407 {
408 File tmp_downloadfileSplit = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + "." + String.valueOf(jkl));
409 tmp_downloadfileSplit.delete();
410 }
411 //
412 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
413 tmp_downloadfile_md5.delete();
414 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + ".idx");
415 tmp_downloadfile_idx.delete();
416 Log.d("NavitMapDownloader", "(a)removed " + tmp_downloadfile.getAbsolutePath());
417 // ok, remove dialog
418 Message msg = mHandler.obtainMessage();
419 Bundle b = new Bundle();
420 msg.what = 0;
421 b.putInt("dialog_num", this.my_dialog_num);
422 // only exit_code=0 will try to use the new map
423 b.putInt("exit_code", exit_code);
424 b.putString("map_name", map_values.map_name);
425 msg.setData(b);
426 mHandler.sendMessage(msg);
427 }
428
429 public void stop_thread()
430 {
431 stop_me = true;
432 mapdownload_stop_all_threads = true;
433 Log.d("NavitMapDownloader", "stop_me -> true");
434
435 // ----- service stop -----
436 // ----- service stop -----
437 // Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
438 // ----- service stop -----
439 // ----- service stop -----
440
441 //
442 //Navit.default_brightness_screen(); // brightness ---------
443 //
444 // remove the tmp download file (if there is one)
445 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME);
446 tmp_downloadfile.delete();
447 for (int jkl = 1; jkl < 51; jkl++)
448 {
449 File tmp_downloadfileSplit = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + "." + String.valueOf(jkl));
450 tmp_downloadfileSplit.delete();
451 }
452 //
453 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
454 tmp_downloadfile_md5.delete();
455 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + ".idx");
456 tmp_downloadfile_idx.delete();
457 Log.d("NavitMapDownloader", "(b)removed " + tmp_downloadfile.getAbsolutePath());
458
459 try
460 {
461 Message msg2 = Navit.Navit_progress_h.obtainMessage();
462 Bundle b2 = new Bundle();
463 msg2.what = 24;
464 msg2.setData(b2);
465 Navit.Navit_progress_h.sendMessage(msg2);
466 }
467 catch (Exception e)
468 {
469 }
470
471 // close cancel dialoag activity
472 Message msg2 = new Message();
473 Bundle b2 = new Bundle();
474 msg2.what = 1;
475 msg2.setData(b2);
476 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg2);
477
478 }
479 }
480
481 private class MultiStreamDownloaderThread extends Thread
482 {
483 Boolean running = false;
484 Handler handler;
485 zanavi_osm_map_values map_values;
486 int map_num;
487 int my_dialog_num;
488 int my_num = 0;
489 int num_threads = 0;
490 String PATH = null;
491 String PATH2 = null;
492 String fileName = null;
493 String final_fileName = null;
494 String this_server_name = null;
495 String up_map = null;
496 long start_byte = 0L;
497 long start_byte_count_now = 0L;
498 long end_byte = 0L;
499
500 MultiStreamDownloaderThread(int num_threads, Handler h, zanavi_osm_map_values map_values, int map_num2, int c, String p, String p2, String fn, String ffn, String sn, String upmap, long start_byte, long end_byte)
501 {
502 running = false;
503
504 this.start_byte = start_byte;
505 this.end_byte = end_byte;
506
507 // System.out.println("DEBUG_MAP_DOWNLOAD::" + c + "bytes=" + this.start_byte + ":" + this.end_byte);
508 // System.out.println("DEBUG_MAP_DOWNLOAD::" + c + "Server=" + sn);
509
510 PATH = p;
511 PATH2 = p2;
512 fileName = fn;
513 final_fileName = ffn;
514 this_server_name = sn;
515 up_map = upmap;
516 this.my_num = c;
517 this.handler = h;
518 this.map_values = map_values;
519 this.map_num = map_num2;
520 this.num_threads = num_threads;
521 if (this.map_num == Navit.MAP_NUM_PRIMARY)
522 {
523 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
524 }
525 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
526 {
527 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
528 }
529 // System.out.println("MultiStreamDownloaderThread " + this.my_num + " init");
530 }
531
532 public void run()
533 {
534 running = true;
535
536 try
537 {
538 // update srv text
539 Message msg_prog88 = new Message();
540 Bundle b_prog88 = new Bundle();
541 b_prog88.putString("srv", this.this_server_name);
542 b_prog88.putInt("threadnum", (this.my_num - 1));
543 msg_prog88.what = 4;
544 msg_prog88.setData(b_prog88);
545 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog88);
546 }
547 catch (Exception e_srv)
548 {
549 }
550
551 // System.out.println("DEBUG_MAP_DOWNLOAD::MultiStreamDownloaderThread " + this.my_num + " run");
552 while (running)
553 {
554 if (mapdownload_stop_all_threads == true)
555 {
556 running = false;
557 mapdownload_error_code_inc();
558 break;
559 }
560
561 int try_number = 0;
562 Boolean download_success = false;
563
564 File file = new File(PATH);
565 File file2 = new File(PATH2);
566 File outputFile = new File(file2, fileName);
567 File final_outputFile = new File(file, final_fileName);
568 // tests have shown that deleting the file first is sometimes faster -> so we delete it (who knows)
569 //**outputFile.delete();
570 RandomAccessFile f_rnd = null;
571
572 if (this.start_byte > (MAX_SINGLE_BINFILE_SIZE - 1))
573 {
574 // split file, we need to compensate
575 int split_num = (int) (this.start_byte / MAX_SINGLE_BINFILE_SIZE);
576 long real_start_byte = this.start_byte - (MAX_SINGLE_BINFILE_SIZE * split_num);
577 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_start_byte, this.my_num);
578 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(a2):split_num=" + split_num + " real_start_byte=" + real_start_byte + " this.start_byte=" + this.start_byte);
579 // Log.d("NavitMapDownloader", this.my_num + "split file calc(a2):split_num=" + split_num + " real_start_byte=" + real_start_byte + " this.start_byte=" + this.start_byte);
580 }
581 else
582 {
583 f_rnd = d_open_file(PATH2 + "/" + fileName, this.start_byte, this.my_num);
584 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(a1): this.start_byte=" + this.start_byte);
585 // Log.d("NavitMapDownloader", this.my_num + "split file calc(a1): this.start_byte=" + this.start_byte);
586 }
587
588 if (f_rnd == null)
589 {
590 Message msg = handler.obtainMessage();
591 Bundle b = new Bundle();
592 msg.what = 2;
593 b.putInt("dialog_num", my_dialog_num);
594 b.putString("text", Navit.get_text("Error downloading map!")); //TRANS
595 msg.setData(b);
596 handler.sendMessage(msg);
597
598 this.running = false;
599 mapdownload_error_code_inc();
600 break;
601 // return 1;
602 }
603
604 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer
605 int len1 = 0;
606 long already_read = this.start_byte;
607 long read_per_interval = 0L;
608 int count_read_per_interval = 0;
609
610 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces
611 int alt_cur = 0;
612 long alt_progress_update_timestamp = 0L;
613 int progress_update_intervall = 700; // show progress about every xx milliseconds
614
615 String kbytes_per_second = "";
616 long start_timestamp = System.currentTimeMillis();
617 long start_timestamp_count_now = System.currentTimeMillis();
618 NumberFormat formatter = new DecimalFormat("00000.0");
619 String eta_string = "";
620 float per_second_overall = 0f;
621 float per_second_now = 0f;
622 long bytes_remaining = 0;
623 int eta_seconds = 0;
624
625 int current_split = 0;
626 int next_split = 0;
627
628 Message msg;
629 Bundle b = new Bundle();
630
631 // while -------
632 while ((try_number < RETRIES) && (!download_success))
633 {
634 if (mapdownload_stop_all_threads == true)
635 {
636 running = false;
637 mapdownload_error_code_inc();
638 break;
639 }
640
641 if (stop_me)
642 {
643 // ok we need to be stopped! close all files and end
644 this.running = false;
645 mapdownload_error_code_inc();
646 break;
647 // return 2;
648 }
649
650 try_number++;
651 // Log.d("NavitMapDownloader", this.my_num + "download try number " + try_number);
652 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "download try number " + try_number);
653
654 HttpURLConnection c = d_url_connect(map_values, this_server_name, map_num, this.my_num);
655 // set http header to resume download
656 //if (this.end_byte == map_values.est_size_bytes)
657 //{
658 // c = d_url_resume_download_at(c, already_read, this.my_num);
659 //}
660 //else
661 //{
662
663 if (already_read >= this.end_byte)
664 {
665 // something has gone wrong, the server seems to give us more bytes than there are in the file? what now?
666 // just start from a few bytes back and lets hope it will work this time
667 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " problem with resuming: already_read=" + already_read + " this.end_byte=" + this.end_byte + " need to correct!!");
668 already_read = this.end_byte - 10;
669 }
670
671 // Log.d("NavitMapDownloader", this.my_num + "resume values: already_read=" + already_read + " this.start_byte=" + this.start_byte + " this.end_byte=" + this.end_byte);
672 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "resume values: already_read=" + already_read + " this.start_byte=" + this.start_byte + " this.end_byte=" + this.end_byte);
673 c = d_url_resume_download_at(c, already_read, this.end_byte, this.my_num);
674 //}
675
676 if (try_number > 1)
677 {
678 // seek to resume position in download file
679 // ---------------------
680 // close file
681 d_close_file(f_rnd, this.my_num);
682
683 // open file
684 if (already_read > (MAX_SINGLE_BINFILE_SIZE - 1))
685 {
686 // split file, we need to compensate
687 int split_num = (int) (already_read / MAX_SINGLE_BINFILE_SIZE);
688 long real_already_read = already_read - (MAX_SINGLE_BINFILE_SIZE * split_num);
689 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_already_read, this.my_num);
690 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(b2):split_num=" + split_num + " real_already_read=" + real_already_read + " already_read=" + already_read);
691 // Log.d("NavitMapDownloader", this.my_num + "split file calc(b2):split_num=" + split_num + " real_already_read=" + real_already_read + " already_read=" + already_read);
692 }
693 else
694 {
695 f_rnd = d_open_file(PATH2 + "/" + fileName, already_read, this.my_num);
696 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(b1): already_read=" + already_read);
697 // Log.d("NavitMapDownloader", this.my_num + "split file calc(b1): already_read=" + already_read);
698 }
699 }
700
701 if (stop_me)
702 {
703 // ok we need to be stopped! close all files and end
704 d_url_disconnect(c);
705 this.running = false;
706 mapdownload_error_code_inc();
707 break;
708 }
709
710 // BufferedInputStream bif = d_url_get_bif(c);
711 InputStream bif = (InputStream) d_url_get_bif(c);
712 if (bif != null)
713 {
714
715 // do the real downloading here
716 try
717 {
718 if (stop_me)
719 {
720 // ok we need to be stopped! close all files and end
721 bif.close();
722 d_url_disconnect(c);
723 this.running = false;
724 mapdownload_error_code_inc();
725 break;
726 }
727
728 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "buf avail1=" + bif.available());
729
730 // len1 -> number of bytes actually read
731 //while (((len1 = bif.read(buffer)) != -1) && (already_read <= this.end_byte))
732
733 Message msg_prog = null;
734 Bundle b_prog = null;
735
736 while ((len1 = bif.read(buffer)) != -1)
737 {
738 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " buf avail2=" + bif.available() + " len1=" + len1);
739
740 if (stop_me)
741 {
742 // ok we need to be stopped! close all files and end
743 bif.close();
744 d_url_disconnect(c);
745 this.running = false;
746 mapdownload_error_code_inc();
747 break;
748 // return 2;
749 }
750
751 if (len1 > 0)
752 {
753 already_read = already_read + len1;
754 read_per_interval = read_per_interval + len1;
755 alt_cur++;
756 if (alt_progress_update_timestamp + progress_update_intervall < System.currentTimeMillis())
757 {
758 alt_cur = 0;
759 alt_progress_update_timestamp = System.currentTimeMillis();
760
761 count_read_per_interval++;
762
763 if (count_read_per_interval == 15)
764 {
765 // int rate = (int) ((float) read_per_interval / ((float) progress_update_intervall * 10f / 1000f * 1024f));
766 // if (rate < 1)
767 // {
768 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " downloadrate: 0 kbytes/s");
769 // }
770 // else
771 // {
772 // if (this.my_num == 1)
773 // {
774 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "+downloadrate:" + rate + " kbytes/s");
775 // }
776 // else if (this.my_num == 2)
777 // {
778 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "O downloadrate:" + rate + " kbytes/s");
779 // }
780 // else
781 // {
782 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "M downloadrate:" + rate + " kbytes/s");
783 // }
784 // }
785 read_per_interval = 0L;
786 count_read_per_interval = 0;
787 }
788
789 msg = handler.obtainMessage();
790 b = new Bundle();
791 msg.what = 1;
792
793 b.putInt("dialog_num", my_dialog_num);
794 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
795 // per_second_overall = (float) (already_read - this.start_byte) / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
796 per_second_now = (int) (already_read - this.start_byte_count_now) / (((float) (System.currentTimeMillis() - start_timestamp_count_now)) / 1000.0f);
797 // System.out.println("DL:TH=" + (this.my_num - 1) + " psn=" + per_second_now + " " + already_read + " " + this.start_byte_count_now + " " + System.currentTimeMillis() + " " + start_timestamp_count_now + " :" + ((long) (System.currentTimeMillis() - start_timestamp_count_now)));
798 this.start_byte_count_now = already_read;
799 start_timestamp_count_now = System.currentTimeMillis();
800
801 mapdownload_already_read[this.my_num - 1] = already_read - this.start_byte;
802 // mapdownload_byte_per_second_overall[this.my_num - 1] = per_second_overall;
803
804 if (Math.abs(mapdownload_byte_per_second_now[this.my_num - 1] - per_second_now) > 600000)
805 {
806 mapdownload_byte_per_second_now[this.my_num - 1] = per_second_now;
807 }
808 else
809 {
810 mapdownload_byte_per_second_now[this.my_num - 1] = per_second_now + ((mapdownload_byte_per_second_now[this.my_num - 1] - per_second_now) / 2.0f);
811 }
812
813 //b.putInt("max", (int) (this.end_byte / 1024));
814 //b.putInt("cur", (int) ((already_read - this.start_byte) / 1024));
815 float f1 = 0;
816 long l1 = 0L;
817 int k;
818 for (k = 0; k < mapdownload_already_read.length; k++)
819 {
820 l1 = l1 + mapdownload_already_read[k];
821 // *long time* // f1 = f1 + mapdownload_byte_per_second_overall[k];
822 //
823 // *now*
824 f1 = f1 + mapdownload_byte_per_second_now[k];
825 }
826 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
827 b.putInt("cur", (int) (l1 / 1024));
828
829 // update progressbar
830 msg_prog = new Message();
831 b_prog = new Bundle();
832 b_prog.putInt("pg", (int) (((l1 / 1024.0f) / (map_values.est_size_bytes / 1024.0f)) * 100.0f));
833 msg_prog.what = 2;
834 msg_prog.setData(b_prog);
835 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
836
837 // update speedbar
838 msg_prog = new Message();
839 b_prog = new Bundle();
840 b_prog.putInt("speed_kb_per_sec", (int) (mapdownload_byte_per_second_now[this.my_num - 1] / 1024.0f));
841 b_prog.putInt("threadnum", (this.my_num - 1));
842 msg_prog.what = 3;
843 msg_prog.setData(b_prog);
844 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
845
846 kbytes_per_second = formatter.format((f1 / 1024f));
847 // kbytes_per_second = formatter.format((per_second_overall / 1024f));
848 // bytes_remaining = this.end_byte - already_read;
849 bytes_remaining = map_values.est_size_bytes - l1;
850 // eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
851 eta_seconds = (int) ((float) bytes_remaining / (float) f1);
852 if (eta_seconds > 60)
853 {
854 eta_string = (int) (eta_seconds / 60f) + " m";
855 }
856 else
857 {
858 eta_string = eta_seconds + " s";
859 }
860 //b.putString("text", Navit.get_text("downloading") + ": " + map_values.map_name + "\n" + " " + (int) (already_read / 1024f / 1024f) + "Mb / " + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " " + kbytes_per_second + "kb/s" + " " + Navit.get_text("ETA") + ": " + eta_string); //TRANS
861 b.putString("text", Navit.get_text("downloading") + ": " + map_values.map_name + "\n" + " " + (int) (l1 / 1024f / 1024f) + "Mb / " + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " " + kbytes_per_second + "kb/s" + " " + Navit.get_text("ETA") + ": " + eta_string); //TRANS
862 msg.setData(b);
863 //if (this.my_num == num_threads - 1)
864 //{
865 handler.sendMessage(msg);
866 //}
867
868 try
869 {
870 ZANaviMapDownloaderService.set_noti_text(map_values.map_name + ":" + (int) (l1 / 1024f / 1024f) + "Mb/" + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + " " + Navit.get_text("ETA") + ": " + eta_string);
871 ZANaviMapDownloaderService.set_large_text(Navit.get_text("downloading") + ": " + map_values.map_name + "\n" + " " + (int) (l1 / 1024f / 1024f) + "Mb / " + (int) (map_values.est_size_bytes / 1024f / 1024f) + "Mb" + "\n" + " " + kbytes_per_second + "kb/s" + " " + Navit.get_text("ETA") + ": " + eta_string);
872 }
873 catch (Exception e)
874 {
875 e.printStackTrace();
876 }
877
878 // try
879 // {
880 // Thread.sleep(70); // give a little time to catch breath, and write to disk
881 // }
882 // catch (Exception sleep_e)
883 // {
884 // sleep_e.printStackTrace();
885 // }
886
887 // System.out.println("" + this.my_num + " " + already_read + " - " + (already_read - this.start_byte));
888 // System.out.println("+++++++++++++ still downloading +++++++++++++");
889 }
890 // if (already_read > this.end_byte)
891 // {
892 // int len2 = len1 - (int) (already_read - this.end_byte);
893 // if (len2 > 0)
894 // {
895 // f_rnd.write(buffer, 0, len2);
896 // }
897 // }
898 // else
899 // {
900
901 // ********
902 current_split = 0;
903 next_split = 0;
904 if (already_read > (MAX_SINGLE_BINFILE_SIZE - 1))
905 {
906 // split file, we need to compensate
907 current_split = (int) ((long) (already_read - len1) / MAX_SINGLE_BINFILE_SIZE);
908 next_split = (int) (already_read / MAX_SINGLE_BINFILE_SIZE);
909
910 // System.out.println("DEBUG_MAP_DOWNLOAD::" + "split file, we need to compensate: current_split=" + current_split + " next_split=" + next_split + " already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1);
911 }
912
913 if (current_split != next_split)
914 {
915 int len1_part2 = (int) (already_read % MAX_SINGLE_BINFILE_SIZE);
916 int len1_part1 = len1 - len1_part2;
917 // part1
918 f_rnd.write(buffer, 0, len1_part1);
919 // close file
920 d_close_file(f_rnd, this.my_num);
921 // open next split file (and seek to pos ZERO)
922 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + next_split, 0, this.my_num);
923 // part2, only if more than ZERO bytes left to write
924 if (len1_part2 > 0)
925 {
926 f_rnd.write(buffer, len1_part1, len1_part2);
927 }
928 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "next split file: current_split=" + current_split + " next_split=" + next_split + " already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1 + " len1_part2=" + len1_part2 + " len1_part1=" + len1_part1);
929 }
930 else
931 {
932 // actually write len1 bytes to output file
933 // System.out.println("MultiStreamDownloaderThread " + this.my_num + " XX 011.08 len1=" + len1 + " cur pos=" + f_rnd.getFilePointer());
934 // !!!!!! this command can take up to 2 minutes to finish on large files !!!!!!
935 f_rnd.write(buffer, 0, len1);
936 // System.out.println("MultiStreamDownloaderThread " + this.my_num + " XX 011.09");
937 }
938 // ********
939
940 // }
941 // try
942 // {
943 // // System.out.println("" + this.my_num + " pos=" + f_rnd.getFilePointer() + " len=" + f_rnd.length());
944 // }
945 // catch (Exception e)
946 // {
947 // e.printStackTrace();
948 // }
949 }
950 }
951 d_close_file(f_rnd, this.my_num);
952 bif.close();
953 d_url_disconnect(c);
954
955 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
956 // update speedbar
957 Message msg_prog77 = new Message();
958 Bundle b_prog77 = new Bundle();
959 b_prog77.putInt("speed_kb_per_sec", 0);
960 b_prog77.putInt("threadnum", (this.my_num - 1));
961 msg_prog77.what = 3;
962 msg_prog77.setData(b_prog77);
963 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
964
965 // delete an already final filename, first
966 //**final_outputFile.delete();
967 // rename file to final name
968 //**outputFile.renameTo(final_outputFile);
969
970 // delete an already there md5 file, first
971 //**File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + map_values.url + ".md5");
972 //**md5_final_filename.delete();
973 // rename file to final name
974 //**File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
975 //**tmp_downloadfile_md5.renameTo(md5_final_filename);
976
977 // remove
978 //**NavitMapDownloader.remove_from_cat_file(up_map);
979 // remove any duplicates (junk in file)
980 //**NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName);
981 // add to the catalogue file for downloaded maps
982 //**NavitMapDownloader.add_to_cat_file(final_fileName, map_values.url);
983
984 // ------ check if we got enough bytes from the server here! if NOT, then continue downloading and reconnect
985 if (already_read < this.end_byte)
986 {
987 // continue download loop
988 System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " server did NOT send enough bytes! already_read=" + already_read + " this.end_byte=" + this.end_byte);
989 }
990 else
991 {
992 // ok downloaded ok, set flag!!
993 download_success = true;
994 this.running = false;
995 }
996 }
997 catch (IOException e)
998 {
999 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
1000 // update speedbar
1001 Message msg_prog77 = new Message();
1002 Bundle b_prog77 = new Bundle();
1003 b_prog77.putInt("speed_kb_per_sec", 0);
1004 b_prog77.putInt("threadnum", (this.my_num - 1));
1005 msg_prog77.what = 3;
1006 msg_prog77.setData(b_prog77);
1007 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
1008
1009 msg = handler.obtainMessage();
1010 b = new Bundle();
1011 msg.what = 2;
1012 b.putInt("dialog_num", my_dialog_num);
1013 b.putString("text", Navit.get_text("Error downloading map, resuming")); //TRANS
1014 msg.setData(b);
1015 handler.sendMessage(msg);
1016
1017 Log.d("NavitMapDownloader", this.my_num + " Error7: " + e);
1018 // ******* ********* D/NavitMapDownloader( 266): 1 Error7: java.io.IOException: No space left on device
1019 System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "IOException11: already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1);
1020
1021 try
1022 {
1023 bif.close();
1024 }
1025 catch (IOException e1)
1026 {
1027 e1.printStackTrace();
1028 }
1029 d_url_disconnect(c);
1030 }
1031 catch (Exception e)
1032 {
1033
1034 try
1035 {
1036 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
1037 // update speedbar
1038 Message msg_prog77 = new Message();
1039 Bundle b_prog77 = new Bundle();
1040 b_prog77.putInt("speed_kb_per_sec", 0);
1041 b_prog77.putInt("threadnum", (this.my_num - 1));
1042 msg_prog77.what = 3;
1043 msg_prog77.setData(b_prog77);
1044 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
1045 }
1046 catch (Exception e4)
1047 {
1048 e4.printStackTrace();
1049 }
1050
1051 try
1052 {
1053 bif.close();
1054 }
1055 catch (IOException e1)
1056 {
1057 e1.printStackTrace();
1058 }
1059 d_url_disconnect(c);
1060
1061 System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "Exception22: already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1);
1062
1063 e.printStackTrace();
1064 if (stop_me)
1065 {
1066 // ok we need to be stopped! close all files and end
1067 this.running = false;
1068 mapdownload_error_code_inc();
1069 break;
1070 // return 2;
1071 }
1072 }
1073 }
1074 else
1075 // bif == null
1076 {
1077 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
1078 // update speedbar
1079 Message msg_prog77 = new Message();
1080 Bundle b_prog77 = new Bundle();
1081 b_prog77.putInt("speed_kb_per_sec", 0);
1082 b_prog77.putInt("threadnum", (this.my_num - 1));
1083 msg_prog77.what = 3;
1084 msg_prog77.setData(b_prog77);
1085 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
1086
1087 d_url_disconnect(c);
1088 try
1089 {
1090 // sleep for 2 second
1091 Thread.sleep(2000);
1092 }
1093 catch (Exception ex)
1094 {
1095 ex.printStackTrace();
1096 }
1097 }
1098 // bif null ------
1099
1100 if (!download_success)
1101 {
1102 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
1103 // update speedbar
1104 Message msg_prog77 = new Message();
1105 Bundle b_prog77 = new Bundle();
1106 b_prog77.putInt("speed_kb_per_sec", 0);
1107 b_prog77.putInt("threadnum", (this.my_num - 1));
1108 msg_prog77.what = 3;
1109 msg_prog77.setData(b_prog77);
1110 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
1111
1112 try
1113 {
1114 // sleep for 2 second (also here)
1115 Thread.sleep(2000);
1116 }
1117 catch (Exception ex2)
1118 {
1119 ex2.printStackTrace();
1120 }
1121 }
1122 }
1123 // while -------
1124
1125 try
1126 {
1127 Thread.sleep(150);
1128 }
1129 catch (InterruptedException e)
1130 {
1131 e.printStackTrace();
1132 }
1133 }
1134
1135 mapdownload_byte_per_second_now[this.my_num - 1] = 0;
1136 // update speedbar
1137 Message msg_prog77 = new Message();
1138 Bundle b_prog77 = new Bundle();
1139 b_prog77.putInt("speed_kb_per_sec", 0);
1140 b_prog77.putInt("threadnum", (this.my_num - 1));
1141 msg_prog77.what = 3;
1142 msg_prog77.setData(b_prog77);
1143 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog77);
1144
1145 System.out.println("MultiStreamDownloaderThread " + this.my_num + " finished");
1146 }
1147 }
1148
1149 //public Navit navit_jmain = null;
1150
1151 public NavitMapDownloader(Navit main)
1152 {
1153 //this.navit_jmain = main;
1154
1155 if (Navit.FDBL)
1156 {
1157 ZANAVI_MAPS_BASE_URL = "http://dlfd.zanavi.cc/data/";
1158 ZANAVI_MAPS_SEVERTEXT_URL = "http://dlfd.zanavi.cc/server.txt";
1159 }
1160 }
1161
1162 public static void init_maps_without_donate_largemaps()
1163 {
1164 if (Navit.Navit_Largemap_DonateVersion_Installed != true)
1165 {
1166 z_Planet.est_size_bytes = -2;
1167 z_Planet.est_size_bytes_human_string = "";
1168 z_Planet.text_for_select_list = z_Planet.map_name + " " + z_Planet.est_size_bytes_human_string;
1169
1170 z_USA.est_size_bytes = -2;
1171 z_USA.est_size_bytes_human_string = "";
1172 z_USA.text_for_select_list = z_USA.map_name + " " + z_USA.est_size_bytes_human_string;
1173
1174 z_Europe.est_size_bytes = -2;
1175 z_Europe.est_size_bytes_human_string = "";
1176 z_Europe.text_for_select_list = z_Europe.map_name + " " + z_Europe.est_size_bytes_human_string;
1177 }
1178 }
1179
1180 public static void init_cat_file()
1181 {
1182 // read the file from sdcard
1183 read_cat_file();
1184 // make a copy
1185 List<String> temp_list = new ArrayList<String>();
1186 temp_list.clear();
1187 Iterator<String> k = map_catalogue.listIterator();
1188 while (k.hasNext())
1189 {
1190 temp_list.add(k.next());
1191 }
1192 int temp_list_prev_size = temp_list.size();
1193 Boolean[] bits = new Boolean[temp_list_prev_size];
1194 for (int h = 0; h < temp_list_prev_size; h++)
1195 {
1196 bits[h] = false;
1197 }
1198 // compare it with directory contents
1199 File map_dir = new File(Navit.MAP_FILENAME_PATH);
1200 File map_file_absolute_path = null;
1201 String dateInUTC = "";
1202 SimpleDateFormat lv_formatter = new SimpleDateFormat("yyyyMMddHHmm", Locale.US);
1203 lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
1204 if (map_dir.isDirectory())
1205 {
1206 String[] files_in_mapdir = map_dir.list();
1207 if (files_in_mapdir != null)
1208 {
1209 for (int i = 0; i < files_in_mapdir.length; i++)
1210 {
1211 dateInUTC = "";
1212 System.out.println("found file in mapdir: " + files_in_mapdir[i]);
1213 // ignore filename with ":" in them
1214 if (!files_in_mapdir[i].contains(":"))
1215 {
1216 // use only files with ending ".bin"
1217 if (files_in_mapdir[i].endsWith(".bin"))
1218 {
1219 // ignore cat. file itself
1220 if (!files_in_mapdir[i].equals(CAT_FILE))
1221 {
1222 // ignore tmp download file
1223 if (!files_in_mapdir[i].equals(DOWNLOAD_FILENAME))
1224 {
1225 System.out.println("checking file in mapdir: " + files_in_mapdir[i]);
1226 Boolean found_in_maplist = false;
1227 Iterator<String> j = temp_list.listIterator();
1228 int t = 0;
1229 while (j.hasNext())
1230 {
1231 String st = j.next();
1232 if (st.split(":", 2)[0].equals(files_in_mapdir[i]))
1233 {
1234 found_in_maplist = true;
1235 bits[t] = true;
1236 System.out.println("found map: t=" + t + " map: " + files_in_mapdir[i]);
1237
1238 map_file_absolute_path = new File(map_dir + "/" + files_in_mapdir[i]);
1239 if (map_file_absolute_path.exists())
1240 {
1241 Date lastModified = new Date(map_file_absolute_path.lastModified());
1242 dateInUTC = lv_formatter.format(lastModified);
1243 System.out.println("found map: st=" + st + " modified=" + dateInUTC);
1244 }
1245 }
1246 t++;
1247 }
1248
1249 if (!found_in_maplist)
1250 {
1251 // if file is on sdcard but not in maplist
1252 // then add this line:
1253 //
1254 // line=mapfilename on sdcard:mapfilename on server
1255 if (files_in_mapdir[i].equals("borders.bin"))
1256 {
1257 System.out.println("adding to maplist: " + files_in_mapdir[i] + ":" + "borders.bin");
1258 temp_list.add(files_in_mapdir[i] + ":" + "borders.bin");
1259 }
1260 else
1261 {
1262 System.out.println("adding to maplist: " + files_in_mapdir[i] + ":" + MAP_URL_NAME_UNKNOWN);
1263 temp_list.add(files_in_mapdir[i] + ":" + MAP_URL_NAME_UNKNOWN);
1264 }
1265 }
1266 }
1267 }
1268 }
1269 }
1270 }
1271 }
1272 }
1273 // check for all maps that are in the maplist, but are missing from sdcard
1274 // use prev size, because values have been added to the end of the list!!
1275 for (int h = 0; h < temp_list_prev_size; h++)
1276 {
1277 if (bits[h] == false)
1278 {
1279 String unknown_map = temp_list.get(h);
1280 // check if its already commented out
1281 if (!unknown_map.startsWith("#"))
1282 {
1283 System.out.println("commenting out: h=" + h + " map: " + unknown_map);
1284 // temp_list.set(h, "#" + unknown_map);
1285 // to avoid download to wrong filename
1286 temp_list.set(h, "#################");
1287 }
1288 }
1289 }
1290 // use the corrected copy
1291 map_catalogue.clear();
1292 Iterator<String> m = temp_list.listIterator();
1293 while (m.hasNext())
1294 {
1295 map_catalogue.add(m.next());
1296 }
1297 // write the corrected file back to sdcard
1298 write_cat_file();
1299 }
1300
1301 public static int cat_file_maps_have_installed_any()
1302 {
1303 Iterator<String> k = map_catalogue.listIterator();
1304 int ret = 0;
1305 while (k.hasNext())
1306 {
1307 String m = k.next();
1308
1309 if (!m.equals("borders.bin:borders.bin"))
1310 {
1311 // System.out.println("MMMM=" + m);
1312 ret++;
1313 }
1314 }
1315
1316 return ret;
1317 }
1318
1319 public static void init_cat_file_maps_timestamps()
1320 {
1321 map_catalogue_date.clear();
1322 // make a copy of current map_catalogue
1323 List<String> temp_list = new ArrayList<String>();
1324 temp_list.clear();
1325 Iterator<String> k = map_catalogue.listIterator();
1326 while (k.hasNext())
1327 {
1328 temp_list.add(k.next());
1329 }
1330 int temp_list_prev_size = temp_list.size();
1331 Boolean[] bits = new Boolean[temp_list_prev_size];
1332 for (int h = 0; h < temp_list_prev_size; h++)
1333 {
1334 bits[h] = false;
1335 }
1336 // compare it with directory contents
1337 File map_dir = new File(Navit.MAP_FILENAME_PATH);
1338 File map_file_absolute_path = null;
1339 String dateInUTC = "";
1340 SimpleDateFormat lv_formatter = new SimpleDateFormat("yyyyMMddHHmm", Locale.US);
1341 lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
1342 if (map_dir.isDirectory())
1343 {
1344 String[] files_in_mapdir = map_dir.list();
1345 if (files_in_mapdir != null)
1346 {
1347 for (int i = 0; i < files_in_mapdir.length; i++)
1348 {
1349 dateInUTC = "";
1350 System.out.println("found file in mapdir: " + files_in_mapdir[i]);
1351 // ignore filename with ":" in them
1352 if (!files_in_mapdir[i].contains(":"))
1353 {
1354 // use only files with ending ".bin"
1355 if (files_in_mapdir[i].endsWith(".bin"))
1356 {
1357 // ignore cat. file itself
1358 if (!files_in_mapdir[i].equals(CAT_FILE))
1359 {
1360 // ignore tmp download file
1361 if (!files_in_mapdir[i].equals(DOWNLOAD_FILENAME))
1362 {
1363 // ignore borders.bin
1364 if (!files_in_mapdir[i].equals("borders.bin"))
1365 {
1366 System.out.println("checking file in mapdir: " + files_in_mapdir[i]);
1367 Boolean found_in_maplist = false;
1368 Iterator<String> j = temp_list.listIterator();
1369 int t = 0;
1370 while (j.hasNext())
1371 {
1372 String st = j.next();
1373 if (st.split(":", 2)[0].equals(files_in_mapdir[i]))
1374 {
1375 found_in_maplist = true;
1376 bits[t] = true;
1377 System.out.println("found map: t=" + t + " map: " + files_in_mapdir[i]);
1378
1379 map_file_absolute_path = new File(map_dir + "/" + files_in_mapdir[i]);
1380 if (map_file_absolute_path.exists())
1381 {
1382 Date lastModified = new Date(map_file_absolute_path.lastModified());
1383 dateInUTC = lv_formatter.format(lastModified);
1384 System.out.println("found map: st=" + st + " modified=" + dateInUTC);
1385 map_catalogue_date.add(dateInUTC + ":" + st.split(":", 2)[1]);
1386 }
1387 }
1388 t++;
1389 }
1390 }
1391 }
1392 }
1393 }
1394 }
1395 }
1396 }
1397 }
1398 }
1399
1400 public static void read_cat_file()
1401 {
1402 //Get the text file
1403 File file = new File(Navit.CFG_FILENAME_PATH + CAT_FILE);
1404
1405 //Read text from file
1406 try
1407 {
1408 BufferedReader br = new BufferedReader(new FileReader(file), 1000);
1409 map_catalogue.clear();
1410 String line;
1411 while ((line = br.readLine()) != null)
1412 {
1413 // line=mapfilename on sdcard:mapfilename on server
1414 // or
1415 // line=#comment
1416 if (!line.startsWith("#"))
1417 {
1418 if (line != null)
1419 {
1420 map_catalogue.add(line);
1421 System.out.println("line=" + line);
1422 }
1423 }
1424 }
1425
1426 if (br != null)
1427 {
1428 br.close();
1429 }
1430 }
1431 catch (IOException e)
1432 {
1433 }
1434
1435 Navit.send_installed_maps_to_plugin();
1436 }
1437
1438 @SuppressLint("NewApi")
1439 public static void write_cat_file()
1440 {
1441 //Get the text file
1442 File file = new File(Navit.CFG_FILENAME_PATH + CAT_FILE);
1443 FileOutputStream fOut = null;
1444 OutputStreamWriter osw = null;
1445 try
1446 {
1447 fOut = new FileOutputStream(file);
1448 osw = new OutputStreamWriter(fOut);
1449 osw.write(MAP_CAT_HEADER + "\n");
1450
1451 Iterator<String> i = map_catalogue.listIterator();
1452 while (i.hasNext())
1453 {
1454 String st = i.next();
1455 osw.write(st + "\n");
1456 System.out.println("write line=" + st);
1457 }
1458 osw.close();
1459 fOut.close();
1460 }
1461 catch (Exception e)
1462 {
1463 e.printStackTrace(System.err);
1464 }
1465
1466 Navit.send_installed_maps_to_plugin();
1467
1468 try
1469 {
1470 if (!Navit.have_maps_installed())
1471 {
1472 // System.out.println("MMMM=no maps installed");
1473 // show semi transparent box "no maps installed" ------------------
1474 // show semi transparent box "no maps installed" ------------------
1475 NavitGraphics.no_maps_container.setVisibility(View.VISIBLE);
1476 try
1477 {
1478 NavitGraphics.no_maps_container.setActivated(true);
1479 }
1480 catch (NoSuchMethodError e)
1481 {
1482 }
1483
1484 Navit.Global_Navit_Object.show_case_001();
1485
1486 // show semi transparent box "no maps installed" ------------------
1487 // show semi transparent box "no maps installed" ------------------
1488 }
1489 else
1490 {
1491 NavitGraphics.no_maps_container.setVisibility(View.INVISIBLE);
1492 try
1493 {
1494 NavitGraphics.no_maps_container.setActivated(false);
1495 }
1496 catch (NoSuchMethodError e)
1497 {
1498 }
1499 }
1500 }
1501 catch (Exception e)
1502 {
1503 e.printStackTrace();
1504 }
1505 }
1506
1507 public static void add_to_cat_file(String disk_name, String server_name)
1508 {
1509 System.out.println("adding: " + disk_name + ":" + server_name);
1510 map_catalogue.add(disk_name + ":" + server_name);
1511 write_cat_file();
1512 }
1513
1514 public static void remove_from_cat_file(String disk_name, String server_name)
1515 {
1516 System.out.println("removing: " + disk_name + ":" + server_name);
1517 map_catalogue.remove(disk_name + ":" + server_name);
1518 write_cat_file();
1519 }
1520
1521 public static void remove_from_cat_file_disk_name(String disk_name)
1522 {
1523 System.out.println("removing: " + disk_name);
1524
1525 int find_count = 0;
1526 String[] saved_lines = new String[50];
1527 for (int x = 0; x < 50; x++)
1528 {
1529 saved_lines[x] = new String();
1530
1531 }
1532
1533 Iterator<String> i = map_catalogue.listIterator();
1534 while (i.hasNext())
1535 {
1536 String st = i.next();
1537 if (st.split(":", 2)[0].equals(disk_name))
1538 {
1539 saved_lines[find_count] = st;
1540 find_count++;
1541 }
1542 }
1543
1544 if (find_count == 0)
1545 {
1546 // clean up
1547 saved_lines = null;
1548 System.out.println("nothing to delete");
1549 return;
1550 }
1551 for (int x = 0; x < find_count; x++)
1552 {
1553 System.out.println("removing: " + saved_lines[x]);
1554 map_catalogue.remove(saved_lines[x]);
1555 }
1556 // clean up
1557 saved_lines = null;
1558 // write file
1559 write_cat_file();
1560 }
1561
1562 public static void remove_from_cat_file(String full_line)
1563 {
1564 System.out.println("removing: " + full_line);
1565 map_catalogue.remove(full_line);
1566 write_cat_file();
1567 }
1568
1569 public static Boolean is_in_cat_file(String disk_name, String server_name)
1570 {
1571 return map_catalogue.contains(disk_name + ":" + server_name);
1572 }
1573
1574 public static String is_in_cat_file_disk_name(String name)
1575 {
1576 String is_here = null;
1577 Iterator<String> i = map_catalogue.listIterator();
1578 while (i.hasNext())
1579 {
1580 String st = i.next();
1581 if (st.split(":", 2)[0].equals(name))
1582 {
1583 // map is here
1584 is_here = st;
1585 return is_here;
1586 }
1587 }
1588 return is_here;
1589 }
1590
1591 public static String is_in_cat_file_server_name(String name)
1592 {
1593 String is_here = null;
1594 Iterator<String> i = map_catalogue.listIterator();
1595 while (i.hasNext())
1596 {
1597 String st = i.next();
1598 if (!st.startsWith("#"))
1599 {
1600 if (st.split(":", 2)[1].equals(name))
1601 {
1602 // map is here
1603 is_here = st;
1604 return is_here;
1605 }
1606 }
1607 }
1608 return is_here;
1609 }
1610
1611 public static int find_lowest_mapnumber_free()
1612 {
1613 int ret = MAP_MAX_FILES;
1614 String tmp_name = null;
1615 for (int j = 1; j < MAP_MAX_FILES + 1; j++)
1616 {
1617 tmp_name = String.format(MAP_FILENAME_BASE, j);
1618 Iterator<String> i = map_catalogue.listIterator();
1619 Boolean is_here = false;
1620 while (i.hasNext())
1621 {
1622 String st = i.next();
1623 if (st.split(":", 2)[0].equals(tmp_name))
1624 {
1625 // map is here
1626 is_here = true;
1627 }
1628 }
1629 if (!is_here)
1630 {
1631 ret = j;
1632 return j;
1633 }
1634 }
1635 return ret;
1636 }
1637
1638 public static void init()
1639 {
1640 // need only init once
1641 if (already_inited)
1642 {
1643 return;
1644 }
1645
1646 //String[] temp_m = new String[MAX_MAP_COUNT];
1647 String[] temp_ml = new String[MAX_MAP_COUNT];
1648 int[] temp_i = new int[MAX_MAP_COUNT];
1649 Boolean[] already_added = new Boolean[z_OSM_MAPS.length];
1650 int cur_continent = -1;
1651 int count = 0;
1652 Boolean last_was_continent = false;
1653 int last_continent_id = -1;
1654 Log.v("NavitMapDownloader", "init maps");
1655 for (int i = 0; i < z_OSM_MAPS.length; i++)
1656 {
1657 already_added[i] = false;
1658 }
1659 for (int i = 0; i < z_OSM_MAPS.length; i++)
1660 {
1661 //Log.v("NavitMapDownloader", "i=" + i);
1662 // look for continents only
1663 if (z_OSM_MAPS[i].is_continent)
1664 {
1665 if (!((last_was_continent) && (last_continent_id == z_OSM_MAPS[i].continent_id)))
1666 {
1667 if (count > 0)
1668 {
1669 // add a break into list
1670 //temp_m[count] = "*break*";
1671 temp_ml[count] = "======";
1672 temp_i[count] = -1;
1673 count++;
1674 }
1675 }
1676 last_was_continent = true;
1677 last_continent_id = z_OSM_MAPS[i].continent_id;
1678
1679 cur_continent = z_OSM_MAPS[i].continent_id;
1680 if (z_OSM_MAPS[i].est_size_bytes == -2)
1681 {
1682 // only dummy entry to have a nice structure
1683 temp_ml[count] = z_OSM_MAPS[i].text_for_select_list;
1684 temp_i[count] = -1;
1685 }
1686 else
1687 {
1688 temp_ml[count] = z_OSM_MAPS[i].text_for_select_list;
1689 temp_i[count] = i;
1690 }
1691 count++;
1692 already_added[i] = true;
1693 Boolean skip = false;
1694 try
1695 {
1696 // get next item
1697 if ((z_OSM_MAPS[i + 1].is_continent) && (cur_continent == z_OSM_MAPS[i + 1].continent_id))
1698 {
1699 skip = true;
1700 }
1701 }
1702 catch (Exception e)
1703 {
1704 e.printStackTrace();
1705 }
1706 // only if not 2 contitents following each other
1707 if (!skip)
1708 {
1709 for (int j = 0; j < z_OSM_MAPS.length; j++)
1710 {
1711 // if (already_added[j] == null)
1712 if (!already_added[j])
1713 {
1714 // look for maps in that continent
1715 if ((z_OSM_MAPS[j].continent_id == cur_continent) && (!z_OSM_MAPS[j].is_continent))
1716 {
1717 //Log.v("NavitMapDownloader", "found map=" + j + " c=" + cur_continent);
1718 // add this map.
1719 //temp_m[count] = z_OSM_MAPS[j].map_name;
1720 temp_ml[count] = " * " + z_OSM_MAPS[j].text_for_select_list;
1721 temp_i[count] = j;
1722 count++;
1723 already_added[j] = true;
1724 }
1725 }
1726 }
1727 }
1728 }
1729 else
1730 {
1731 last_was_continent = false;
1732 }
1733 }
1734 // add the rest of the list (dont have a continent)
1735 cur_continent = 9999; // unknown
1736 int found = 0;
1737 for (int i = 0; i < z_OSM_MAPS.length; i++)
1738 {
1739 if (!already_added[i])
1740 {
1741 if (found == 0)
1742 {
1743 found = 1;
1744 // add a break into list
1745 //temp_m[count] = "*break*";
1746 temp_ml[count] = "======";
1747 temp_i[count] = -1;
1748 count++;
1749 }
1750
1751 //Log.v("NavitMapDownloader", "found map(loose)=" + i + " c=" + cur_continent);
1752 // add this map.
1753 //temp_m[count] = z_OSM_MAPS[i].map_name;
1754 temp_ml[count] = " # " + z_OSM_MAPS[i].text_for_select_list;
1755 temp_i[count] = i;
1756 count++;
1757 already_added[i] = true;
1758 }
1759 }
1760
1761 Log.e("NavitMapDownloader", "count=" + count);
1762 Log.e("NavitMapDownloader", "size1 " + z_OSM_MAPS.length);
1763 //Log.e("NavitMapDownloader", "size2 " + temp_m.length);
1764 Log.e("NavitMapDownloader", "size3 " + temp_ml.length);
1765
1766 //OSM_MAP_NAME_LIST = new String[count];
1767 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE = new String[count];
1768 OSM_MAP_NAME_ORIG_ID_LIST = new int[count];
1769
1770 for (int i = 0; i < count; i++)
1771 {
1772 //OSM_MAP_NAME_LIST[i] = temp_m[i];
1773 OSM_MAP_NAME_ORIG_ID_LIST[i] = temp_i[i];
1774 OSM_MAP_NAME_LIST_inkl_SIZE_ESTIMATE[i] = temp_ml[i];
1775 }
1776
1777 already_inited = true;
1778 }
1779
1780 public static void init_ondisk_maps()
1781 {
1782 Log.v("NavitMapDownloader", "init ondisk maps");
1783
1784 OSM_MAP_NAME_LIST_ondisk = new String[map_catalogue.size()];
1785 OSM_MAP_NAME_ondisk_ORIG_LIST = new String[map_catalogue.size()];
1786
1787 Iterator<String> i = map_catalogue.listIterator();
1788 int c = 0;
1789 String t;
1790 while (i.hasNext())
1791 {
1792 String st = i.next();
1793
1794 if (!st.startsWith("#"))
1795 {
1796 // full line <on disk name:server filename>
1797 OSM_MAP_NAME_ondisk_ORIG_LIST[c] = st;
1798 // server file name
1799 OSM_MAP_NAME_LIST_ondisk[c] = null;
1800 try
1801 {
1802 t = st.split(":", 2)[1];
1803
1804 for (int j = 0; j < z_OSM_MAPS.length; j++)
1805 {
1806 if (z_OSM_MAPS[j].url.equals(t))
1807 {
1808 OSM_MAP_NAME_LIST_ondisk[c] = z_OSM_MAPS[j].map_name;
1809 }
1810 }
1811 if (OSM_MAP_NAME_LIST_ondisk[c] == null)
1812 {
1813 // for unkown maps
1814 OSM_MAP_NAME_LIST_ondisk[c] = st.split(":", 2)[0] + MAP_DISK_NAME_UNKNOWN;
1815 }
1816 }
1817 catch (Exception e)
1818 {
1819 e.printStackTrace();
1820 }
1821 }
1822 c++;
1823 }
1824 }
1825
1826 public String find_file_on_other_mapserver(List<String> map_servers_list, String md5_sum, zanavi_osm_map_values map_values, int map_num3)
1827 {
1828 System.out.println("find_file_on_other_mapserver:first server name=" + map_servers_list);
1829
1830 String other_server_name = d_get_servername(false, map_values);
1831 int i = 0;
1832 for (i = 0; i < 4; i++)
1833 {
1834 // System.out.println("find_file_on_other_mapserver:found other mapserver (" + i + "): " + other_server_name);
1835 if ((other_server_name == null) || (map_servers_list.contains(other_server_name)))
1836 {
1837 // try again
1838 try
1839 {
1840 Thread.sleep(90);
1841 }
1842 catch (InterruptedException e)
1843 {
1844 }
1845 other_server_name = d_get_servername(false, map_values);
1846 }
1847 else
1848 {
1849 break;
1850 }
1851 }
1852
1853 if ((other_server_name == null) || (map_servers_list.contains(other_server_name)))
1854 {
1855 System.out.println("find_file_on_other_mapserver:no other server found");
1856 return null;
1857 }
1858
1859 String md5_server = d_get_md5_from_server(map_values, other_server_name, map_num3);
1860 if ((md5_server == null) || (!md5_server.equals(md5_sum)))
1861 {
1862 System.out.println("find_file_on_other_mapserver:wrong md5 on " + other_server_name);
1863 return null;
1864 }
1865
1866 System.out.println("find_file_on_other_mapserver:found other mapserver: " + other_server_name);
1867 return other_server_name;
1868 }
1869
1870 public int download_osm_map(Handler handler, zanavi_osm_map_values map_values, int map_num3)
1871 {
1872 int exit_code = 1;
1873
1874 int my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
1875 if (map_num3 == Navit.MAP_NUM_PRIMARY)
1876 {
1877 my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
1878 }
1879 else if (map_num3 == Navit.MAP_NUM_SECONDARY)
1880 {
1881 my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
1882 }
1883
1884 Message msg = handler.obtainMessage();
1885 Bundle b = new Bundle();
1886 msg.what = 1;
1887 b.putInt("max", 20); // use a dummy number here
1888 b.putInt("cur", 0);
1889 b.putInt("dialog_num", my_dialog_num);
1890 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
1891 b.putString("text", Navit.get_text("downloading") + ": " + map_values.map_name); //TRANS
1892 msg.setData(b);
1893 handler.sendMessage(msg);
1894
1895 // output filename
1896 String PATH = Navit.MAP_FILENAME_PATH;
1897 String PATH2 = Navit.CFG_FILENAME_PATH;
1898 String fileName = DOWNLOAD_FILENAME;
1899 String final_fileName = "xxx";
1900
1901 Boolean mode_update = false;
1902 String up_map = null;
1903
1904 if (map_values.url.equals("borders.bin"))
1905 {
1906 final_fileName = MAP_FILENAME_BORDERS;
1907 mode_update = true;
1908 up_map = is_in_cat_file_server_name("borders.bin");
1909 }
1910 else if (map_values.url.equals("coastline.bin"))
1911 {
1912 final_fileName = MAP_FILENAME_COASTLINE;
1913 mode_update = true;
1914 up_map = is_in_cat_file_server_name("coastline.bin");
1915 }
1916 else
1917 {
1918 // is it an update?
1919 up_map = is_in_cat_file_server_name(map_values.url);
1920 if (up_map == null)
1921 {
1922 final_fileName = String.format(MAP_FILENAME_BASE, find_lowest_mapnumber_free());
1923 }
1924 else
1925 {
1926 final_fileName = up_map.split(":", 2)[0];
1927 mode_update = true;
1928 }
1929 }
1930
1931 System.out.println("update=" + mode_update);
1932 System.out.println("final_fileName=" + final_fileName);
1933 System.out.println("up_map=" + up_map);
1934
1935 try
1936 {
1937 // show download actionbar icon
1938 Message msg2 = Navit.Navit_progress_h.obtainMessage();
1939 Bundle b2 = new Bundle();
1940 msg2.what = 23;
1941 msg2.setData(b2);
1942 Navit.Navit_progress_h.sendMessage(msg2);
1943 }
1944 catch (Exception e)
1945 {
1946 e.printStackTrace();
1947 }
1948
1949 String this_server_name = null;
1950 String md5_server = null;
1951
1952 int server_err = 0;
1953 int server_retries = 0;
1954 int server_max_retries = 8;
1955
1956 while (server_retries < server_max_retries)
1957 {
1958 Log.d("NavitMapDownloader", "init:try #" + server_retries);
1959
1960 this_server_name = d_get_servername(true, map_values);
1961 if (this_server_name == null)
1962 {
1963 Log.d("NavitMapDownloader", "init:try #" + server_retries + " srvname=null");
1964
1965 server_err = 1;
1966 server_retries++;
1967 continue;
1968 }
1969
1970 md5_server = d_get_md5_from_server(map_values, this_server_name, map_num3);
1971 if (md5_server == null)
1972 {
1973 Log.d("NavitMapDownloader", "init:try #" + server_retries + " md5=null" + " srvname=" + this_server_name);
1974
1975 server_err = 1;
1976 server_retries++;
1977 continue;
1978 }
1979 else
1980 {
1981 Log.d("NavitMapDownloader", "init:try #" + server_retries + " md5=" + md5_server + " srvname=" + this_server_name);
1982
1983 server_err = 0;
1984 break;
1985 }
1986
1987 }
1988
1989 if (server_err == 1)
1990 {
1991 //if (this_server_name == null)
1992 //{
1993 msg = handler.obtainMessage();
1994 b = new Bundle();
1995 msg.what = 2;
1996 b.putInt("dialog_num", my_dialog_num);
1997 b.putString("text", Navit.get_text("Error downloading map!")); //TRANS
1998 msg.setData(b);
1999 handler.sendMessage(msg);
2000
2001 return 1;
2002 //}
2003 }
2004
2005 // on disk md5 can be "null" , when downloading new map
2006 String md5_disk = d_get_md5_from_disk(map_values, this_server_name, map_num3);
2007
2008 if (d_match_md5sums(md5_disk, md5_server))
2009 {
2010 // ok we have a match, no need to update!
2011 msg = handler.obtainMessage();
2012 b = new Bundle();
2013 msg.what = 2;
2014 b.putInt("dialog_num", my_dialog_num);
2015 b.putString("text", Navit.get_text("Map already up to date")); //TRANS
2016 msg.setData(b);
2017 handler.sendMessage(msg);
2018
2019 Log.d("NavitMapDownloader", "MD5 matches, no need to update map");
2020 return 11;
2021 }
2022
2023 long real_file_size = d_get_real_download_filesize(map_values, this_server_name, map_num3);
2024 if (real_file_size <= 0)
2025 {
2026 msg = handler.obtainMessage();
2027 b = new Bundle();
2028 msg.what = 2;
2029 b.putInt("dialog_num", my_dialog_num);
2030 b.putString("text", Navit.get_text("Error downloading map!")); //TRANS
2031 msg.setData(b);
2032 handler.sendMessage(msg);
2033
2034 return 1;
2035 }
2036 map_values.est_size_bytes = real_file_size;
2037
2038 // check if file fits onto maps dir
2039 // check if file fits onto maps dir
2040 try
2041 {
2042 long avail_space = NavitAvailableSpaceHandler.getExternalAvailableSpaceInBytes(Navit.MAP_FILENAME_PATH);
2043 System.out.println("avail space=" + avail_space + " map size=" + real_file_size);
2044 if (avail_space <= real_file_size)
2045 {
2046 Message msg2 = Navit.Navit_progress_h.obtainMessage();
2047 Bundle b2 = new Bundle();
2048 msg2.what = 17;
2049 msg2.setData(b2);
2050 Navit.Navit_progress_h.sendMessage(msg2);
2051 }
2052 }
2053 catch (Exception e)
2054 {
2055 // just in case the device does not support this,
2056 // we catch the exception and continue with the download
2057 e.printStackTrace();
2058 }
2059 // check if file fits onto maps dir
2060 // check if file fits onto maps dir
2061
2062 int num_threads = 1;
2063 long bytes_diff = 0L;
2064 long bytes_leftover = 0;
2065 if (map_values.est_size_bytes < 1000000)
2066 {
2067 num_threads = 1;
2068 map_servers_used.clear();
2069 map_servers_used.add(this_server_name);
2070 bytes_diff = map_values.est_size_bytes;
2071 }
2072 else
2073 {
2074 // if (this_server_name.equals("zanavi.noaccess.de"))
2075 // {
2076 // num_threads = MULTI_NUM_THREADS;
2077 // bytes_diff = map_values.est_size_bytes;
2078 // }
2079 // else
2080 // {
2081 // num_threads = MULTI_NUM_THREADS;
2082 // bytes_diff = map_values.est_size_bytes;
2083 // }
2084 //{
2085
2086 num_threads = MULTI_NUM_THREADS;
2087 int num_threads2 = 0;
2088 map_servers_used.clear();
2089 String new_map_server = null;
2090 int k2 = 0;
2091 for (k2 = 0; k2 < num_threads; k2++)
2092 {
2093 if (k2 == 0)
2094 {
2095 // first thread always uses this server name
2096 new_map_server = this_server_name;
2097 map_servers_used.add(new_map_server);
2098 }
2099 else
2100 {
2101 new_map_server = find_file_on_other_mapserver(map_servers_used, md5_server, map_values, map_num3);
2102 if (new_map_server != null)
2103 {
2104 map_servers_used.add(new_map_server);
2105 }
2106 }
2107
2108 if (new_map_server != null)
2109 {
2110 num_threads2++;
2111 }
2112 }
2113 num_threads = num_threads2;
2114
2115 bytes_diff = (long) (map_values.est_size_bytes / num_threads);
2116 if (bytes_diff * num_threads < map_values.est_size_bytes)
2117 {
2118 bytes_leftover = map_values.est_size_bytes - (bytes_diff * num_threads);
2119 System.out.println("bytes_leftover=" + bytes_leftover);
2120 }
2121 //}
2122
2123 // bytes_diff is the part size in bytes!! but you must read from (start) to (bytes_diff - 1)!!
2124 }
2125
2126 // stupid workaround to have this value available :-(
2127 MULTI_NUM_THREADS_LOCAL = num_threads;
2128
2129 System.out.println("num_threads=" + num_threads + " bytes_diff=" + bytes_diff);
2130
2131 Boolean split_mapfile = false;
2132 int num_splits = 0;
2133 // check if we need to split the file into pieces
2134 if (map_values.est_size_bytes > MAX_SINGLE_BINFILE_SIZE)
2135 {
2136 split_mapfile = true;
2137 num_splits = (int) ((map_values.est_size_bytes - 1) / MAX_SINGLE_BINFILE_SIZE);
2138 }
2139 System.out.println("split_mapfile=" + split_mapfile);
2140 System.out.println("num_splits=" + num_splits);
2141 // check if we need to split the file into pieces
2142
2143 File file99 = new File(PATH2);
2144 File outputFile = new File(file99, fileName);
2145 outputFile.delete();
2146
2147 for (int jkl = 1; jkl < 51; jkl++)
2148 {
2149 File outputFileSplit = new File(file99, fileName + "." + String.valueOf(jkl));
2150 System.out.println("delete:" + file99 + "/" + fileName + "." + String.valueOf(jkl));
2151 outputFileSplit.delete();
2152 }
2153
2154 // -- DISABLED --
2155 // -- DISABLED --
2156 // // pre create the big file
2157 // msg = handler.obtainMessage();
2158 // b = new Bundle();
2159 // msg.what = 1;
2160 // b.putInt("max", 20); // use a dummy number here
2161 // b.putInt("cur", 0);
2162 // b.putInt("dialog_num", my_dialog_num);
2163 // b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2164 // b.putString("text", Navit.get_text("Creating outputfile, long time")); //TRANS
2165 // msg.setData(b);
2166 // handler.sendMessage(msg);
2167 //
2168 // d_pre_create_file(PATH2 + fileName, map_values.est_size_bytes, handler, my_dialog_num);
2169 // -- DISABLED --
2170 // -- DISABLED --
2171
2172 //
2173 //
2174 MultiStreamDownloaderThread[] m = new MultiStreamDownloaderThread[num_threads];
2175 int k;
2176 mapdownload_error_code_clear();
2177 mapdownload_already_read = new long[num_threads];
2178 mapdownload_byte_per_second_overall = new float[num_threads];
2179 mapdownload_byte_per_second_now = new float[num_threads];
2180 for (k = 0; k < num_threads; k++)
2181 {
2182 mapdownload_already_read[k] = 0;
2183 mapdownload_byte_per_second_overall[k] = 0;
2184 mapdownload_byte_per_second_now[k] = 0;
2185 }
2186
2187 for (k = 0; k < num_threads; k++)
2188 {
2189 // enale speedbar(s)
2190 // System.out.println("SPB:enable:#" + k);
2191
2192 Message msg_prog = new Message();
2193 Bundle b_prog = new Bundle();
2194 b_prog.putInt("speed_kb_per_sec", -2);
2195 b_prog.putInt("threadnum", k);
2196 msg_prog.what = 3;
2197 msg_prog.setData(b_prog);
2198 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
2199 }
2200
2201 // start downloader threads here --------------------------
2202 // start downloader threads here --------------------------
2203 String new_map_server = null;
2204 for (k = 0; k < num_threads; k++)
2205 {
2206 new_map_server = map_servers_used.get(k);
2207
2208 if (new_map_server != null)
2209 {
2210 if (k == (num_threads - 1))
2211 {
2212 m[k] = new MultiStreamDownloaderThread(num_threads, handler, map_values, map_num3, k + 1, PATH, PATH2, fileName, final_fileName, new_map_server, up_map, bytes_diff * k, map_values.est_size_bytes - 1);
2213 }
2214 else
2215 {
2216 m[k] = new MultiStreamDownloaderThread(num_threads, handler, map_values, map_num3, k + 1, PATH, PATH2, fileName, final_fileName, new_map_server, up_map, bytes_diff * k, (bytes_diff * (k + 1)) - 1);
2217 }
2218 m[k].start();
2219 }
2220 }
2221
2222 // wait for downloader threads to finish --------------------------
2223 for (k = 0; k < num_threads; k++)
2224 {
2225 try
2226 {
2227 m[k].join();
2228 }
2229 catch (InterruptedException e)
2230 {
2231 e.printStackTrace();
2232 }
2233 catch (Exception e)
2234 {
2235 e.printStackTrace();
2236 }
2237 }
2238
2239 if (mapdownload_error_code > 0)
2240 {
2241 mapdownload_error_code_clear();
2242 return 97;
2243 }
2244 //
2245 //
2246 // calc md5sum on device on print it to STDOUT
2247 //if (!split_mapfile)
2248 //{
2249
2250 // set progressbar to 100%
2251 Message msg_prog1 = new Message();
2252 Bundle b_prog1 = new Bundle();
2253 b_prog1.putInt("pg", 100);
2254 msg_prog1.what = 2;
2255 msg_prog1.setData(b_prog1);
2256 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog1);
2257
2258 for (k = 0; k < num_threads; k++)
2259 {
2260 // update speedbar
2261 Message msg_prog = new Message();
2262 Bundle b_prog = new Bundle();
2263 b_prog.putInt("speed_kb_per_sec", 0);
2264 b_prog.putInt("threadnum", k);
2265 msg_prog.what = 3;
2266 msg_prog.setData(b_prog);
2267 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
2268 }
2269
2270 try
2271 {
2272 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking map ..."));
2273 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking map ..."));
2274 }
2275 catch (Exception e)
2276 {
2277 e.printStackTrace();
2278 }
2279
2280 System.out.println("MD5 ok **start*");
2281 String md5sum_local_calculated = calc_md5sum_on_device(handler, my_dialog_num, map_values.est_size_bytes);
2282 if (!d_match_md5sums(md5sum_local_calculated, md5_server))
2283 {
2284 // some problem with download
2285 msg = handler.obtainMessage();
2286 b = new Bundle();
2287 msg.what = 2;
2288 b.putInt("dialog_num", my_dialog_num);
2289 b.putString("text", Navit.get_text("MD5 mismatch")); //TRANS
2290 msg.setData(b);
2291 handler.sendMessage(msg);
2292
2293 outputFile.delete();
2294 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
2295 tmp_downloadfile_md5.delete();
2296
2297 Log.d("NavitMapDownloader", "MD5 mismatch!!");
2298 System.out.println("MD5 mismatch ######");
2299 return 12;
2300 }
2301 else
2302 {
2303 Log.d("NavitMapDownloader", "MD5 ok");
2304 System.out.println("MD5 ok ******");
2305 }
2306 System.out.println("MD5 ok **end*");
2307 //}
2308 //
2309 File file = new File(PATH);
2310 File final_outputFile = new File(file, final_fileName);
2311 // delete an already final filename, first
2312 final_outputFile.delete();
2313 // delete split files
2314 for (int jkl = 1; jkl < 51; jkl++)
2315 {
2316 File outputFileSplit = new File(file, final_fileName + "." + String.valueOf(jkl));
2317 System.out.println("delete final filename:" + file + "/" + final_fileName + "." + String.valueOf(jkl));
2318 outputFileSplit.delete();
2319 }
2320 // rename file to final name
2321 outputFile.renameTo(final_outputFile);
2322 System.out.println("rename1:" + outputFile + " to:" + final_outputFile);
2323 if (split_mapfile)
2324 {
2325 for (int jkl = 1; jkl < (num_splits + 1); jkl++)
2326 {
2327 File outputFileSplit = new File(file, final_fileName + "." + String.valueOf(jkl));
2328 File outputFileSplitSrc = new File(file99, fileName + "." + String.valueOf(jkl));
2329 System.out.println("rename2:" + outputFileSplitSrc + " to:" + outputFileSplit);
2330 outputFileSplitSrc.renameTo(outputFileSplit);
2331 }
2332 }
2333
2334 // delete an already there md5 file, first
2335 File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + map_values.url + ".md5");
2336 md5_final_filename.delete();
2337 // rename file to final name
2338 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
2339 tmp_downloadfile_md5.renameTo(md5_final_filename);
2340
2341 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
2342 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
2343 final Thread thread_for_download_wakelock = new Thread()
2344 {
2345 @Override
2346 public void run()
2347 {
2348 try
2349 {
2350 if (Navit.wl != null)
2351 {
2352 Navit.wl.acquire();
2353 Log.e("Navit", "WakeLock: acquire 2a");
2354 }
2355 }
2356 catch (Exception e)
2357 {
2358 e.printStackTrace();
2359 }
2360
2361 try
2362 {
2363 // sleep for 10 seconds
2364 Thread.sleep(10000);
2365 }
2366 catch (Exception e)
2367 {
2368 }
2369
2370 try
2371 {
2372 if (Navit.wl != null)
2373 {
2374 if (Navit.wl.isHeld())
2375 {
2376 Navit.wl.release();
2377 Log.e("Navit", "WakeLock: release 3a");
2378 }
2379 }
2380 }
2381 catch (Exception e)
2382 {
2383 e.printStackTrace();
2384 }
2385 }
2386 };
2387 thread_for_download_wakelock.start();
2388 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
2389 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
2390
2391 // don't try to download index file for coastline and border maps
2392 if ((!final_fileName.equals(MAP_FILENAME_BORDERS)) && (!final_fileName.equals(MAP_FILENAME_COASTLINE)))
2393 {
2394 // ------------ download idx file ------------
2395 // ------------ download idx file ------------
2396 zanavi_osm_map_values z_dummy_for_idx = new zanavi_osm_map_values("index file", map_values.url + ".idx", 1000000, false, 3);
2397 // z_dummy_for_idx.map_name = "index file";
2398
2399 boolean index_file_download = false;
2400 if ((Navit.Navit_DonateVersion_Installed) || (Navit.Navit_Largemap_DonateVersion_Installed))
2401 {
2402 index_file_download = true;
2403 }
2404
2405 if (index_file_download == true)
2406 {
2407 long real_file_size_idx = d_get_real_download_filesize(z_dummy_for_idx, this_server_name, map_num3);
2408 if (real_file_size_idx <= 0)
2409 {
2410 msg = handler.obtainMessage();
2411 b = new Bundle();
2412 msg.what = 2;
2413 b.putInt("dialog_num", my_dialog_num);
2414 b.putString("text", Navit.get_text("Error downloading index!")); //TRANS
2415 msg.setData(b);
2416 handler.sendMessage(msg);
2417
2418 index_file_download = false;
2419 }
2420 else
2421 {
2422 z_dummy_for_idx.est_size_bytes = real_file_size_idx;
2423 }
2424 }
2425
2426 if (index_file_download == true)
2427 {
2428 num_threads = 1;
2429 bytes_leftover = 0;
2430 num_threads = 1;
2431 bytes_diff = z_dummy_for_idx.est_size_bytes;
2432
2433 Message msg_idx = handler.obtainMessage();
2434 Bundle b_idx = new Bundle();
2435 msg_idx.what = 1;
2436 b_idx.putInt("max", (int) (z_dummy_for_idx.est_size_bytes / 1024)); // use a dummy number here
2437 b_idx.putInt("cur", 0);
2438 b_idx.putInt("dialog_num", my_dialog_num);
2439 b_idx.putString("title", Navit.get_text("Index download")); //TRANS
2440 b_idx.putString("text", Navit.get_text("downloading indexfile")); //TRANS
2441 msg_idx.setData(b);
2442 handler.sendMessage(msg_idx);
2443
2444 MultiStreamDownloaderThread[] m_idx = new MultiStreamDownloaderThread[num_threads];
2445 int k_idx;
2446
2447 mapdownload_error_code_clear();
2448 mapdownload_already_read = new long[num_threads];
2449 mapdownload_byte_per_second_overall = new float[num_threads];
2450 mapdownload_byte_per_second_now = new float[num_threads];
2451 for (k_idx = 0; k_idx < num_threads; k_idx++)
2452 {
2453 mapdownload_already_read[k_idx] = 0;
2454 mapdownload_byte_per_second_overall[k_idx] = 0;
2455 mapdownload_byte_per_second_now[k_idx] = 0;
2456 }
2457
2458 // start downloader threads here --------------------------
2459 // start downloader threads here --------------------------
2460 for (k_idx = 0; k_idx < num_threads; k_idx++)
2461 {
2462 if (k_idx == (num_threads - 1))
2463 {
2464 m[k_idx] = new MultiStreamDownloaderThread(num_threads, handler, z_dummy_for_idx, map_num3, k_idx + 1, PATH, PATH2, fileName + ".idx", final_fileName + ".idx", this_server_name, "xyzdummydummy", bytes_diff * k_idx, z_dummy_for_idx.est_size_bytes);
2465 }
2466 else
2467 {
2468 m[k_idx] = new MultiStreamDownloaderThread(num_threads, handler, z_dummy_for_idx, map_num3, k_idx + 1, PATH, PATH2, fileName + ".idx", final_fileName + ".idx", this_server_name, "xyzdummydummy", bytes_diff * k_idx, bytes_diff * (k_idx + 1));
2469 }
2470 m[k_idx].start();
2471 }
2472
2473 // wait for downloader threads to finish --------------------------
2474 for (k_idx = 0; k_idx < num_threads; k_idx++)
2475 {
2476 try
2477 {
2478 m[k_idx].join();
2479 }
2480 catch (InterruptedException e)
2481 {
2482 e.printStackTrace();
2483 }
2484 catch (Exception e)
2485 {
2486 e.printStackTrace();
2487 }
2488 }
2489
2490 if (mapdownload_error_code > 0)
2491 {
2492 mapdownload_error_code_clear();
2493 index_file_download = false;
2494 }
2495 else
2496 {
2497 // set progressbar to 100%
2498 Message msg_prog2 = new Message();
2499 Bundle b_prog2 = new Bundle();
2500 b_prog2.putInt("pg", 100);
2501 msg_prog2.what = 2;
2502 msg_prog2.setData(b_prog2);
2503 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog2);
2504
2505 for (k_idx = 0; k_idx < num_threads; k_idx++)
2506 {
2507 // update speedbar
2508 Message msg_prog = new Message();
2509 Bundle b_prog = new Bundle();
2510 b_prog.putInt("speed_kb_per_sec", 0);
2511 b_prog.putInt("threadnum", k_idx);
2512 msg_prog.what = 3;
2513 msg_prog.setData(b_prog);
2514 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
2515 }
2516
2517 // delete an already there idx file, first
2518 //System.out.println("idx 001:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
2519 File idx_final_filename = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
2520 idx_final_filename.delete();
2521 // rename file to final name
2522 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, fileName + ".idx");
2523 //System.out.println("idx 002:" + Navit.CFG_FILENAME_PATH + fileName + ".idx");
2524 File final_outputFile_idx = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
2525 //System.out.println("idx 003:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
2526 tmp_downloadfile_idx.renameTo(final_outputFile_idx);
2527 }
2528 }
2529 // ------------ download idx file ------------
2530 // ------------ download idx file ------------
2531 }
2532
2533 // remove
2534 NavitMapDownloader.remove_from_cat_file(up_map);
2535 // remove any duplicates (junk in file)
2536 NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName);
2537 // add to the catalogue file for downloaded maps
2538 NavitMapDownloader.add_to_cat_file(final_fileName, map_values.url);
2539
2540 //
2541 //
2542
2543 msg = handler.obtainMessage();
2544 b = new Bundle();
2545 msg.what = 1;
2546 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
2547 b.putInt("cur", (int) (map_values.est_size_bytes / 1024));
2548 b.putInt("dialog_num", my_dialog_num);
2549 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2550 b.putString("text", map_values.map_name + " " + Navit.get_text("ready")); //TRANS
2551 msg.setData(b);
2552 handler.sendMessage(msg);
2553
2554 Log.d("NavitMapDownloader", "success");
2555 exit_code = 0;
2556
2557 return exit_code;
2558 }
2559
2560 static void default_ssl_cert()
2561 {
2562 HttpsURLConnection.setDefaultHostnameVerifier(hnv_default);
2563 HttpsURLConnection.setDefaultSSLSocketFactory(sslf_default);
2564 }
2565
2566 static HostnameVerifier hnv_default = null;
2567 static SSLSocketFactory sslf_default = null;
2568
2569 static void trust_Every_ssl_cert()
2570 {
2571 // NEVER enable this on a production release!!!!!!!!!!
2572 try
2573 {
2574 hnv_default = HttpsURLConnection.getDefaultHostnameVerifier();
2575 sslf_default = HttpsURLConnection.getDefaultSSLSocketFactory();
2576
2577 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
2578 {
2579 public boolean verify(String hostname, SSLSession session)
2580 {
2581 Log.d("NavitMapDownloader", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
2582 // return true -> mean we trust this cert !! DANGER !! DANGER !!
2583 return true;
2584 }
2585 });
2586 SSLContext context = SSLContext.getInstance("TLS");
2587 context.init(null, new X509TrustManager[] { new X509TrustManager()
2588 {
2589 public java.security.cert.X509Certificate[] getAcceptedIssuers()
2590 {
2591 return new java.security.cert.X509Certificate[0];
2592 }
2593
2594 @Override
2595 public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
2596 {
2597 }
2598
2599 @Override
2600 public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
2601 {
2602 }
2603 } }, new SecureRandom());
2604 HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
2605 }
2606 catch (Exception e)
2607 {
2608 e.printStackTrace();
2609 }
2610 // NEVER enable this on a production release!!!!!!!!!!
2611 }
2612
2613 public String d_get_servername(boolean first_run, zanavi_osm_map_values map_values)
2614 {
2615 // this is only for debugging
2616 // NEVER enable this on a production release!!!!!!!!!!
2617 // NEVER enable this on a production release!!!!!!!!!!
2618 // ------- // trust_Every_ssl_cert();
2619 // NEVER enable this on a production release!!!!!!!!!!
2620 // NEVER enable this on a production release!!!!!!!!!!
2621
2622 String servername = null;
2623 try
2624 {
2625 URL url = new URL(ZANAVI_MAPS_SEVERTEXT_URL);
2626
2627 if (!first_run)
2628 {
2629 url = new URL(ZANAVI_MAPS_SEVERTEXT_URL + "?SUBREQ=1");
2630 }
2631 else
2632 {
2633 try
2634 {
2635 url = new URL(ZANAVI_MAPS_SEVERTEXT_URL + "?MAP=" + URLEncoder.encode(map_values.url, "UTF-8"));
2636 }
2637 catch (Exception e_url)
2638 {
2639 }
2640 }
2641
2642 System.out.println(ZANAVI_MAPS_SEVERTEXT_URL);
2643
2644 HttpURLConnection c = (HttpURLConnection) url.openConnection();
2645 String ua_ = Navit.UserAgentString_bind.replace("@__THREAD__@", "0" + "T" + MULTI_NUM_THREADS_LOCAL);
2646 c.addRequestProperty("User-Agent", ua_);
2647 c.addRequestProperty("Pragma", "no-cache");
2648
2649 c.setRequestMethod("GET");
2650 c.setDoOutput(true);
2651 c.setReadTimeout(SOCKET_READ_TIMEOUT);
2652 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
2653
2654 try
2655 {
2656 c.connect();
2657 BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()), 4096);
2658 String str;
2659 str = in.readLine();
2660
2661 if (str != null)
2662 {
2663 if (str.length() > 2)
2664 {
2665 System.out.println("from server=" + str);
2666 servername = str;
2667 }
2668 }
2669 in.close();
2670 }
2671 catch (Exception e)
2672 {
2673 e.printStackTrace();
2674 }
2675 c.disconnect();
2676 }
2677 catch (Exception e)
2678 {
2679 e.printStackTrace();
2680 }
2681
2682 return servername;
2683 }
2684
2685 public String d_get_md5_from_server(zanavi_osm_map_values map_values, String servername, int map_num3)
2686 {
2687 // try to get MD5 file
2688 String md5_from_server = null;
2689 try
2690 {
2691 URL url = new URL(ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url + ".md5");
2692 System.out.println("md5 url:" + ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url + ".md5");
2693 HttpURLConnection c = (HttpURLConnection) url.openConnection();
2694 String ua_ = Navit.UserAgentString_bind.replace("@__THREAD__@", "0" + "T" + MULTI_NUM_THREADS_LOCAL);
2695 c.addRequestProperty("User-Agent", ua_);
2696 c.addRequestProperty("Pragma", "no-cache");
2697
2698 c.setRequestMethod("GET");
2699 c.setDoOutput(true);
2700 c.setReadTimeout(SOCKET_READ_TIMEOUT);
2701 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
2702 try
2703 {
2704 c.connect();
2705 BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()), 4096);
2706 String str;
2707 str = in.readLine();
2708 if (str != null)
2709 {
2710 if (str.length() > 5)
2711 {
2712 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
2713 tmp_downloadfile_md5.delete();
2714 System.out.println("md5 from server=" + str);
2715 FileOutputStream fos = null;
2716 try
2717 {
2718 fos = new FileOutputStream(tmp_downloadfile_md5);
2719 fos.write(str.getBytes());
2720 fos.close();
2721 md5_from_server = str;
2722 }
2723 catch (FileNotFoundException e1)
2724 {
2725 e1.printStackTrace();
2726 }
2727 }
2728 }
2729 in.close();
2730 }
2731 catch (Exception e)
2732 {
2733 e.printStackTrace();
2734 }
2735 c.disconnect();
2736 }
2737 catch (Exception e)
2738 {
2739 e.printStackTrace();
2740 }
2741 // try to get MD5 file
2742 return md5_from_server;
2743 }
2744
2745 public long d_get_real_download_filesize(zanavi_osm_map_values map_values, String servername, int map_num3)
2746 {
2747 long real_size_bytes = 0;
2748 try
2749 {
2750 URL url = new URL(ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url);
2751 System.out.println("url1:" + ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url);
2752 HttpURLConnection c = (HttpURLConnection) url.openConnection();
2753 String ua_ = Navit.UserAgentString_bind.replace("@__THREAD__@", "0" + "T" + MULTI_NUM_THREADS_LOCAL);
2754 c.addRequestProperty("User-Agent", ua_);
2755 c.addRequestProperty("Pragma", "no-cache");
2756
2757 c.setRequestMethod("GET");
2758 c.setDoOutput(true);
2759 c.setReadTimeout(SOCKET_READ_TIMEOUT);
2760 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
2761 // real_size_bytes = c.getContentLength(); -> only returns "int" value, its an android bug
2762 try
2763 {
2764 c.connect();
2765 System.out.println("header content-length=" + c.getHeaderField("content-length"));
2766 real_size_bytes = Long.parseLong(c.getHeaderField("content-length"));
2767 Log.d("NavitMapDownloader", "real_size_bytes=" + real_size_bytes);
2768 }
2769 catch (Exception e)
2770 {
2771 e.printStackTrace();
2772 Log.d("NavitMapDownloader", "error parsing content-length header field");
2773 }
2774 c.disconnect();
2775 }
2776 catch (Exception e)
2777 {
2778 e.printStackTrace();
2779 }
2780 return real_size_bytes;
2781 }
2782
2783 public String d_get_md5_from_disk(zanavi_osm_map_values map_values, String servername, int map_num3)
2784 {
2785 String md5_on_disk = null;
2786
2787 // try to read MD5 from disk - if it fails dont worry!!
2788 File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + map_values.url + ".md5");
2789 InputStream in2 = null;
2790 try
2791 {
2792 in2 = new BufferedInputStream(new FileInputStream(md5_final_filename));
2793 InputStreamReader inputreader = new InputStreamReader(in2);
2794 BufferedReader buffreader = new BufferedReader(inputreader, 4096);
2795 String tmp = buffreader.readLine();
2796 if (tmp != null)
2797 {
2798 if (tmp.length() > 5)
2799 {
2800 md5_on_disk = tmp;
2801 System.out.println("MD5 on disk=" + md5_on_disk);
2802 }
2803 }
2804 }
2805 catch (Exception e)
2806 {
2807 e.printStackTrace();
2808 }
2809 finally
2810 {
2811 if (in2 != null)
2812 {
2813 try
2814 {
2815 in2.close();
2816 }
2817 catch (Exception e)
2818 {
2819 e.printStackTrace();
2820 }
2821 }
2822 }
2823 // try to read MD5 from disk - if it fails dont worry!!
2824
2825 return md5_on_disk;
2826 }
2827
2828 public Boolean d_match_md5sums(String md5_1, String md5_2)
2829 {
2830 Boolean md5_match = false;
2831 //
2832 // check md5 sum
2833 //
2834 if ((md5_1 != null) && (md5_2 != null) && (md5_1.equals(md5_2)))
2835 {
2836 md5_match = true;
2837 }
2838 //
2839 // check md5 sum
2840 //
2841 return md5_match;
2842 }
2843
2844 public HttpURLConnection d_url_connect(zanavi_osm_map_values map_values, String servername, int map_num3, int current_thread_num)
2845 {
2846 URL url = null;
2847 HttpURLConnection c = null;
2848 try
2849 {
2850 url = new URL(ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url);
2851 System.out.println("url2:" + ZANAVI_MAPS_BASE_URL_PROTO + servername + ZANAVI_MAPS_BASE_URL_WO_SERVERNAME + map_values.url);
2852 c = (HttpURLConnection) url.openConnection();
2853 String ua_ = Navit.UserAgentString_bind.replace("@__THREAD__@", "" + current_thread_num + "T" + MULTI_NUM_THREADS_LOCAL);
2854 c.addRequestProperty("User-Agent", ua_);
2855 // c.addRequestProperty("Pragma", "no-cache");
2856 c.setRequestMethod("GET");
2857 c.setDoOutput(true);
2858 c.setReadTimeout(SOCKET_READ_TIMEOUT);
2859 c.setConnectTimeout(SOCKET_CONNECT_TIMEOUT);
2860 }
2861 catch (Exception e)
2862 {
2863 e.printStackTrace();
2864 c = null;
2865 }
2866 return c;
2867 }
2868
2869 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, int num)
2870 {
2871 c.setRequestProperty("Range", "bytes=" + old_download_size + "-");
2872 Log.d("NavitMapDownloader", num + " resuming download at " + old_download_size + " bytes");
2873 System.out.println("DEBUG_MAP_DOWNLOAD::" + num + " resuming download at " + old_download_size + " bytes");
2874 return c;
2875 }
2876
2877 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, long end_size, int num)
2878 {
2879 c.setRequestProperty("Range", "bytes=" + old_download_size + "-" + end_size);
2880 Log.d("NavitMapDownloader", num + "resuming download at " + old_download_size + " bytes" + ":" + end_size);
2881 System.out.println("DEBUG_MAP_DOWNLOAD::" + num + "resuming download at " + old_download_size + " bytes" + ":" + end_size);
2882
2883 return c;
2884 }
2885
2886 public BufferedInputStream d_url_get_bif(HttpURLConnection c)
2887 // public InputStream d_url_get_bif(HttpURLConnection c)
2888 {
2889 InputStream is = null;
2890 BufferedInputStream bif = null;
2891 try
2892 {
2893 c.setUseCaches(false);
2894 c.connect();
2895 is = c.getInputStream();
2896 bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer
2897 }
2898 catch (FileNotFoundException f)
2899 {
2900 // map file is not on server!!
2901 try
2902 {
2903 c.disconnect();
2904 }
2905 catch (Exception x)
2906 {
2907 x.printStackTrace();
2908 }
2909 System.out.println("map file is not on server!");
2910 f.printStackTrace();
2911 }
2912 catch (Exception e)
2913 {
2914 e.printStackTrace();
2915 }
2916
2917 return bif;
2918 // return is;
2919 }
2920
2921 public void d_url_disconnect(HttpURLConnection c)
2922 {
2923 try
2924 {
2925 c.disconnect();
2926 }
2927 catch (Exception ex)
2928 {
2929 ex.printStackTrace();
2930 }
2931 }
2932
2933 public void d_pre_create_file(String filename, long size, Handler handler, int my_dialog_num)
2934 {
2935 RandomAccessFile f = null;
2936 long size_2 = size - 2;
2937
2938 if (size > MAX_SINGLE_BINFILE_SIZE)
2939 {
2940 // skip this step with large mapfiles (or implement handling of split files)
2941 return;
2942 }
2943
2944 class FileProgress extends Thread
2945 {
2946 Handler handler;
2947 String file;
2948 int my_dialog_num;
2949 long file_size;
2950 Boolean running = false;
2951
2952 FileProgress(Handler h, String f, int dn, long fsize)
2953 {
2954 handler = h;
2955 file = f;
2956 my_dialog_num = dn;
2957 file_size = fsize;
2958 running = false;
2959 }
2960
2961 public void run()
2962 {
2963 Message msg;
2964 Bundle b;
2965 running = true;
2966 File f = null;
2967 while (running)
2968 {
2969 if (mapdownload_stop_all_threads)
2970 {
2971 System.out.println("FileProgress:mapdownload_stop_all_threads");
2972 break;
2973 }
2974
2975 try
2976 {
2977 f = new File(file);
2978 long cur_size = f.length();
2979 // System.out.println("cur_size=" + cur_size);
2980 msg = handler.obtainMessage();
2981 b = new Bundle();
2982 msg.what = 1;
2983 b.putInt("max", (int) (file_size / 1000));
2984 b.putInt("cur", (int) (cur_size / 1000));
2985 b.putInt("dialog_num", my_dialog_num);
2986 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2987 b.putString("text", Navit.get_text("Creating outputfile, long time")); //TRANS
2988 msg.setData(b);
2989 handler.sendMessage(msg);
2990 }
2991 catch (Exception e)
2992 {
2993 e.printStackTrace();
2994 }
2995 if (running)
2996 {
2997 try
2998 {
2999 Thread.sleep(700);
3000 }
3001 catch (InterruptedException e)
3002 {
3003 e.printStackTrace();
3004 }
3005 }
3006 }
3007 }
3008
3009 public void stop_me()
3010 {
3011 running = false;
3012 }
3013 }
3014
3015 FileProgress fp = new FileProgress(handler, filename, my_dialog_num, size);
3016 fp.start();
3017
3018 try
3019 {
3020 f = new RandomAccessFile(filename, "rw");
3021 if (size_2 > 1900000000L)
3022 {
3023 f.seek(1900000000L);
3024 System.out.println("pre 1");
3025 f.writeByte(1);
3026 System.out.println("pre 2");
3027 f.seek(1900000000L);
3028 System.out.println("pre 3");
3029 int buf_size = 1000 * 32;
3030 byte[] buffer_seek = new byte[buf_size];
3031 int num_loops = (int) ((size_2 - 1900000000L - 1) / buf_size);
3032 int j = 0;
3033 for (j = 0; j < num_loops; j++)
3034 {
3035 f.write(buffer_seek);
3036 try
3037 {
3038 Thread.sleep(2);
3039 }
3040 catch (Exception x)
3041 {
3042 x.printStackTrace();
3043 }
3044 }
3045
3046 long this_fp = 1900000000L + (num_loops * buf_size);
3047 System.out.println("pre 4 " + this_fp);
3048 buf_size = (int) (size - this_fp) - 1;
3049 if (buf_size > 0)
3050 {
3051 buffer_seek = new byte[buf_size];
3052 f.write(buffer_seek);
3053 }
3054 System.out.println("pre 5");
3055
3056 // int skipped = f.skipBytes((int) (size_2 - 1900000000L));
3057 }
3058 else
3059 {
3060 System.out.println("pre 6");
3061 f.seek(size_2);
3062 System.out.println("pre 7");
3063 }
3064 System.out.println("pre 8");
3065 f.writeByte(1);
3066 // ****EEEE**** W/System.err( 266): java.io.IOException: No space left on device
3067 System.out.println("pre 9");
3068
3069 try
3070 {
3071 System.out.println("d_pre_create_file:f len=" + f.length());
3072 }
3073 catch (Exception e)
3074 {
3075 e.printStackTrace();
3076 }
3077
3078 f.close();
3079 System.out.println("pre 10");
3080 }
3081 catch (FileNotFoundException e)
3082 {
3083 e.printStackTrace();
3084 }
3085 catch (Exception e)
3086 {
3087 e.printStackTrace();
3088 // ****EEEE**** W/System.err( 266): java.io.IOException: No space left on device
3089 }
3090
3091 fp.stop_me();
3092
3093 Message msg = handler.obtainMessage();
3094 Bundle b = new Bundle();
3095 msg.what = 1;
3096 b.putInt("max", (int) (size / 1000));
3097 b.putInt("cur", (int) (size / 1000));
3098 b.putInt("dialog_num", my_dialog_num);
3099 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
3100 b.putString("text", Navit.get_text("Creating outputfile, wait")); //TRANS
3101 msg.setData(b);
3102 handler.sendMessage(msg);
3103 }
3104
3105 public RandomAccessFile d_open_file(String filename, long pos, int my_num)
3106 {
3107 RandomAccessFile f = null;
3108 System.out.println("d_open_file: " + my_num + " " + filename + " seek (start):" + pos);
3109 try
3110 {
3111 f = new RandomAccessFile(filename, "rw");
3112 if (pos > 1900000000L)
3113 {
3114 System.out.println("open file: 1");
3115 f.seek(1900000000L);
3116 System.out.println("open file: 2");
3117
3118 int buf_size = 1000 * 64;
3119 byte[] buffer_seek = new byte[buf_size];
3120 int num_loops = (int) ((pos - 1900000000L - 1) / buf_size);
3121 int j = 0;
3122 for (j = 0; j < num_loops; j++)
3123 {
3124 f.readFully(buffer_seek);
3125 // try
3126 // {
3127 // Thread.sleep(2);
3128 // }
3129 // catch (Exception x)
3130 // {
3131 // x.printStackTrace();
3132 // }
3133 }
3134 long this_fp = 1900000000L + (num_loops * buf_size);
3135 System.out.println("open file: 3 " + this_fp);
3136 buf_size = (int) (pos - this_fp);
3137 if (buf_size > 0)
3138 {
3139 buffer_seek = new byte[buf_size];
3140 f.readFully(buffer_seek);
3141 }
3142 System.out.println("open file: 4");
3143
3144 // int skipped = f.skipBytes((int) (pos - 1900000000L));
3145 System.out.println("open file: 5");
3146 }
3147 else
3148 {
3149 System.out.println("open file: 6");
3150 f.seek(pos);
3151 System.out.println("open file: 7");
3152 }
3153 }
3154 catch (FileNotFoundException e)
3155 {
3156 e.printStackTrace();
3157 }
3158 catch (Exception e)
3159 {
3160 e.printStackTrace();
3161 }
3162 System.out.println("d_open_file:" + my_num + " seek (end):" + pos);
3163
3164 try
3165 {
3166 System.out.println("d_open_file:" + my_num + " f len(seek)=" + f.length());
3167 }
3168 catch (Exception e)
3169 {
3170 e.printStackTrace();
3171 }
3172
3173 return f;
3174 }
3175
3176 public void d_close_file(RandomAccessFile f, int my_num)
3177 {
3178 try
3179 {
3180 System.out.println("d_close_file:" + my_num + " f len=" + f.length());
3181 }
3182 catch (Exception e)
3183 {
3184 e.printStackTrace();
3185 }
3186
3187 try
3188 {
3189 f.close();
3190 System.out.println("d_close_file:" + my_num + " f.close()");
3191 }
3192 catch (Exception e)
3193 {
3194 e.printStackTrace();
3195 }
3196 }
3197
3198 public static synchronized void mapdownload_error_code_inc()
3199 {
3200 mapdownload_error_code++;
3201 }
3202
3203 public static void mapdownload_error_code_clear()
3204 {
3205 mapdownload_error_code = 0;
3206 }
3207
3208 public String calc_md5sum_on_device(Handler handler, int my_dialog_num, long size)
3209 {
3210 String md5sum = null;
3211 final int sleep_millis = 0;
3212 final int sleep_millis_long = 60;
3213 final int looper_mod = 100;
3214 int looper_count = 0;
3215
3216 if (size > MAX_SINGLE_BINFILE_SIZE)
3217 {
3218 try
3219 {
3220 String s = "";
3221 Message msg = null;
3222 Bundle b = null;
3223 int size2 = (int) (size / 1000);
3224 long cur_pos = 0L;
3225
3226 // Create MD5 Hash
3227 MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
3228 InputStream fis = null;
3229 boolean no_more_parts = false;
3230
3231 // find all pieces of the large map file
3232 int parts = 0;
3233
3234 // -------------- LOOP thru all the parts -------------
3235 // -------------- LOOP thru all the parts -------------
3236 // -------------- LOOP thru all the parts -------------
3237
3238 try
3239 {
3240 if (Navit.wl_cpu != null)
3241 {
3242 Navit.wl_cpu.acquire();
3243 Log.e("Navit", "WakeLock CPU: acquire 2a");
3244 }
3245 }
3246 catch (Exception e)
3247 {
3248 e.printStackTrace();
3249 }
3250
3251 while (!no_more_parts)
3252 {
3253 try
3254 {
3255 if (parts == 0)
3256 {
3257 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
3258 System.out.println("calc_md5sum_on_device(split):found file=" + Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
3259 }
3260 else
3261 {
3262 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME + "." + parts);
3263 System.out.println("calc_md5sum_on_device(split):found file=" + Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME + "." + parts);
3264 }
3265 parts++;
3266 }
3267 catch (FileNotFoundException e)
3268 {
3269 e.printStackTrace();
3270 no_more_parts = true;
3271 }
3272
3273 if (!no_more_parts)
3274 {
3275 byte[] buffer = new byte[1024 * MD5_CALC_BUFFER_KB];
3276 int numRead = 0;
3277 do
3278 {
3279 if (mapdownload_stop_all_threads)
3280 {
3281 System.out.println("calc_md5sum_on_device 1(split):mapdownload_stop_all_threads");
3282 break;
3283 }
3284
3285 try
3286 {
3287 numRead = fis.read(buffer);
3288 }
3289 catch (IOException e)
3290 {
3291 e.printStackTrace();
3292 }
3293
3294 if (numRead > 0)
3295 {
3296 try
3297 {
3298 looper_count++;
3299 if (looper_count > looper_mod)
3300 {
3301 looper_count = 0;
3302 // allow to catch breath
3303 Thread.sleep(sleep_millis_long);
3304 }
3305 else
3306 {
3307 // allow to catch breath
3308 Thread.sleep(sleep_millis);
3309 }
3310 }
3311 catch (InterruptedException e)
3312 {
3313 e.printStackTrace();
3314 }
3315 digest.update(buffer, 0, numRead);
3316 cur_pos = cur_pos + numRead;
3317 }
3318
3319 msg = handler.obtainMessage();
3320 b = new Bundle();
3321 msg.what = 1;
3322 b.putInt("max", size2);
3323 b.putInt("cur", (int) (cur_pos / 1000));
3324 b.putInt("dialog_num", my_dialog_num);
3325 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
3326 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
3327 msg.setData(b);
3328 handler.sendMessage(msg);
3329
3330 try
3331 {
3332 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3333 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3334
3335 // update progressbar
3336 Message msg_prog = new Message();
3337 Bundle b_prog = new Bundle();
3338 b_prog.putInt("pg", calc_percent((int) (cur_pos / 1000), size2));
3339 msg_prog.what = 2;
3340 msg_prog.setData(b_prog);
3341 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
3342 }
3343 catch (Exception e)
3344 {
3345 e.printStackTrace();
3346 }
3347
3348 }
3349 while (numRead != -1);
3350
3351 try
3352 {
3353 fis.close();
3354 }
3355 catch (IOException e)
3356 {
3357 e.printStackTrace();
3358 }
3359 catch (Exception e)
3360 {
3361 e.printStackTrace();
3362 }
3363
3364 }
3365
3366 if (mapdownload_stop_all_threads)
3367 {
3368
3369 try
3370 {
3371 if (Navit.wl_cpu != null)
3372 {
3373 Navit.wl_cpu.release();
3374 Log.e("Navit", "WakeLock CPU: release 2a");
3375 }
3376 }
3377 catch (Exception e)
3378 {
3379 e.printStackTrace();
3380 }
3381
3382 System.out.println("calc_md5sum_on_device 2(split):mapdownload_stop_all_threads");
3383 return null;
3384 }
3385
3386 }
3387
3388 try
3389 {
3390 if (Navit.wl_cpu != null)
3391 {
3392 Navit.wl_cpu.release();
3393 Log.e("Navit", "WakeLock CPU: release 2b");
3394 }
3395 }
3396 catch (Exception e)
3397 {
3398 e.printStackTrace();
3399 }
3400
3401 // -------------- LOOP thru all the parts -------------
3402 // -------------- LOOP thru all the parts -------------
3403 // -------------- LOOP thru all the parts -------------
3404
3405 msg = handler.obtainMessage();
3406 b = new Bundle();
3407 msg.what = 1;
3408 b.putInt("max", size2);
3409 b.putInt("cur", size2);
3410 b.putInt("dialog_num", my_dialog_num);
3411 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
3412 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
3413 msg.setData(b);
3414 handler.sendMessage(msg);
3415
3416 byte messageDigest[] = digest.digest();
3417 // Create Hex String
3418 StringBuffer hexString = new StringBuffer();
3419 String t = "";
3420 for (int i = 0; i < messageDigest.length; i++)
3421 {
3422 t = Integer.toHexString(0xFF & messageDigest[i]);
3423 if (t.length() == 1)
3424 {
3425 t = "0" + t;
3426 }
3427 hexString.append(t);
3428 }
3429 md5sum = hexString.toString();
3430 System.out.println("md5sum local(split)=" + md5sum);
3431
3432 }
3433 catch (Exception e)
3434 {
3435
3436 try
3437 {
3438 if (Navit.wl_cpu != null)
3439 {
3440 Navit.wl_cpu.release();
3441 Log.e("Navit", "WakeLock CPU: release 2c");
3442 }
3443 }
3444 catch (Exception e3)
3445 {
3446 e3.printStackTrace();
3447 }
3448
3449 return md5sum;
3450 }
3451
3452 return md5sum;
3453 }
3454
3455 try
3456 {
3457 String s = "";
3458 Message msg = null;
3459 Bundle b = null;
3460 int size2 = (int) (size / 1000);
3461 long cur_pos = 0L;
3462
3463 // Create MD5 Hash
3464 MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
3465
3466 InputStream fis = null;
3467
3468 try
3469 {
3470 if (Navit.wl_cpu != null)
3471 {
3472 Navit.wl_cpu.acquire();
3473 Log.e("Navit", "WakeLock CPU: acquire 3a");
3474 }
3475 }
3476 catch (Exception e)
3477 {
3478 e.printStackTrace();
3479 }
3480
3481 try
3482 {
3483 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
3484 }
3485 catch (FileNotFoundException e)
3486 {
3487 e.printStackTrace();
3488 }
3489
3490 byte[] buffer = new byte[1024 * MD5_CALC_BUFFER_KB];
3491 int numRead = 0;
3492 do
3493 {
3494 if (mapdownload_stop_all_threads)
3495 {
3496 System.out.println("calc_md5sum_on_device 1:mapdownload_stop_all_threads");
3497 break;
3498 }
3499
3500 try
3501 {
3502 numRead = fis.read(buffer);
3503 }
3504 catch (IOException e)
3505 {
3506 e.printStackTrace();
3507 }
3508
3509 if (numRead > 0)
3510 {
3511 try
3512 {
3513 looper_count++;
3514 if (looper_count > looper_mod)
3515 {
3516 looper_count = 0;
3517 // allow to catch breath
3518 Thread.sleep(sleep_millis_long);
3519 }
3520 else
3521 {
3522 // allow to catch breath
3523 Thread.sleep(sleep_millis);
3524 }
3525 }
3526 catch (InterruptedException e)
3527 {
3528 e.printStackTrace();
3529 }
3530 digest.update(buffer, 0, numRead);
3531 cur_pos = cur_pos + numRead;
3532 }
3533
3534 msg = handler.obtainMessage();
3535 b = new Bundle();
3536 msg.what = 1;
3537 b.putInt("max", size2);
3538 b.putInt("cur", (int) (cur_pos / 1000));
3539 b.putInt("dialog_num", my_dialog_num);
3540 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
3541 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
3542 msg.setData(b);
3543 handler.sendMessage(msg);
3544
3545 try
3546 {
3547 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3548 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3549
3550 // update progressbar
3551 Message msg_prog = new Message();
3552 Bundle b_prog = new Bundle();
3553 b_prog.putInt("pg", calc_percent((int) (cur_pos / 1000), size2));
3554 msg_prog.what = 2;
3555 msg_prog.setData(b_prog);
3556 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg_prog);
3557
3558 }
3559 catch (Exception e)
3560 {
3561 e.printStackTrace();
3562 }
3563
3564 }
3565 while (numRead != -1);
3566
3567 msg = handler.obtainMessage();
3568 b = new Bundle();
3569 msg.what = 1;
3570 b.putInt("max", size2);
3571 b.putInt("cur", size2);
3572 b.putInt("dialog_num", my_dialog_num);
3573 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
3574 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
3575 msg.setData(b);
3576 handler.sendMessage(msg);
3577
3578 try
3579 {
3580 fis.close();
3581 }
3582 catch (IOException e)
3583 {
3584 e.printStackTrace();
3585 }
3586 catch (Exception e)
3587 {
3588 e.printStackTrace();
3589 }
3590
3591 if (mapdownload_stop_all_threads)
3592 {
3593 try
3594 {
3595 if (Navit.wl_cpu != null)
3596 {
3597 Navit.wl_cpu.release();
3598 Log.e("Navit", "WakeLock CPU: release 3a");
3599 }
3600 }
3601 catch (Exception e)
3602 {
3603 e.printStackTrace();
3604 }
3605
3606 System.out.println("calc_md5sum_on_device 2:mapdownload_stop_all_threads");
3607 return null;
3608 }
3609
3610 byte messageDigest[] = digest.digest();
3611 // Create Hex String
3612 StringBuffer hexString = new StringBuffer();
3613 String t = "";
3614 for (int i = 0; i < messageDigest.length; i++)
3615 {
3616 t = Integer.toHexString(0xFF & messageDigest[i]);
3617 if (t.length() == 1)
3618 {
3619 t = "0" + t;
3620 }
3621 hexString.append(t);
3622 }
3623 md5sum = hexString.toString();
3624 System.out.println("md5sum local=" + md5sum);
3625 }
3626 catch (NoSuchAlgorithmException e)
3627 {
3628 e.printStackTrace();
3629 }
3630 catch (Exception e)
3631 {
3632 e.printStackTrace();
3633 }
3634
3635 try
3636 {
3637 if (Navit.wl_cpu != null)
3638 {
3639 Navit.wl_cpu.release();
3640 Log.e("Navit", "WakeLock CPU: release 3b");
3641 }
3642 }
3643 catch (Exception e)
3644 {
3645 e.printStackTrace();
3646 }
3647
3648 return md5sum;
3649 }
3650
3651 static int calc_percent(int cur, int max)
3652 {
3653 int percent = 0;
3654
3655 try
3656 {
3657 percent = (int) ((float) cur / (float) max * 100f);
3658 }
3659 catch (Exception e)
3660 {
3661 percent = 0;
3662 }
3663 return percent;
3664 }
3665 }

   
Visit the ZANavi Wiki