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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 35 Revision 36
92 //static final String ZANAVI_MAPS_BASE_URL_PROTO = "https://"; 92 //static final String ZANAVI_MAPS_BASE_URL_PROTO = "https://";
93 //static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/maps/"; 93 //static final String ZANAVI_MAPS_BASE_URL_WO_SERVERNAME = "/maps/";
94 // ------- DEBUG DEBUG SETTINGS -------- 94 // ------- DEBUG DEBUG SETTINGS --------
95 // ------- DEBUG DEBUG SETTINGS -------- 95 // ------- DEBUG DEBUG SETTINGS --------
96 96
97 static int MULTI_NUM_THREADS_MAX = 6;
97 static int MULTI_NUM_THREADS = 1; // how many download streams for a file 98 static int MULTI_NUM_THREADS = 1; // how many download streams for a file
98 static int MULTI_NUM_THREADS_LOCAL = 1; // how many download streams for the current file from the current server 99 static int MULTI_NUM_THREADS_LOCAL = 1; // how many download streams for the current file from the current server
99 100
100 public static class zanavi_osm_map_values 101 public static class zanavi_osm_map_values
101 { 102 {
292 public static String[] OSM_MAP_NAME_ondisk_ORIG_LIST = null; 293 public static String[] OSM_MAP_NAME_ondisk_ORIG_LIST = null;
293 294
294 private static Boolean already_inited = false; 295 private static Boolean already_inited = false;
295 296
296 public Boolean stop_me = false; 297 public Boolean stop_me = false;
297 static final int SOCKET_CONNECT_TIMEOUT = 30000; // 30 secs. 298 static final int SOCKET_CONNECT_TIMEOUT = 2000; // 2 secs.
298 static final int SOCKET_READ_TIMEOUT = 25000; // 25 secs. 299 static final int SOCKET_READ_TIMEOUT = 10000; // 10 secs.
299 static final int MAP_WRITE_FILE_BUFFER = 1024 * 64; 300 // static final int MAP_WRITE_FILE_BUFFER = 1024 * 8;
300 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64; 301 static final int MAP_WRITE_MEM_BUFFER = 1024 * 64;
301 static final int MAP_READ_FILE_BUFFER = 1024 * 64; 302 static final int MAP_READ_FILE_BUFFER = 1024 * 64;
302 static final int UPDATE_PROGRESS_EVERY_CYCLE = 30; // 12; // 8 -> is nicer, but maybe to fast for some devices 303 static final int UPDATE_PROGRESS_EVERY_CYCLE = 256; // 12; // 8 -> is nicer, but maybe to fast for some devices
303 static final int RETRIES = 75; // this many retries on map download 304 static final int RETRIES = 75; // this many retries on map download
305 static final int MD5_CALC_BUFFER_KB = 128;
304 306
305 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] 307 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]
308 // static final long MAX_SINGLE_BINFILE_SIZE = 800 * 1024 * 1024; // split map at this size into pieces [~800 MBytes]
309 // --- DEBUG ONLY --- // static final long MAX_SINGLE_BINFILE_SIZE = 80 * 1024 * 1024; // 80 MBytes // --- DEBUG ONLY --- //
306 310
307 static final String DOWNLOAD_FILENAME = "navitmap.tmp"; 311 static final String DOWNLOAD_FILENAME = "navitmap.tmp";
308 static final String MD5_DOWNLOAD_TEMPFILE = "navitmap_tmp.md5"; 312 static final String MD5_DOWNLOAD_TEMPFILE = "navitmap_tmp.md5";
309 static final String CAT_FILE = "maps_cat.txt"; 313 static final String CAT_FILE = "maps_cat.txt";
310 public static List<String> map_catalogue = new ArrayList<String>(); 314 public static List<String> map_catalogue = new ArrayList<String>();
315 public static List<String> map_servers_used = new ArrayList<String>();
311 static final String MAP_CAT_HEADER = "# ZANavi maps -- do not edit by hand --"; 316 static final String MAP_CAT_HEADER = "# ZANavi maps -- do not edit by hand --";
312 public static final String MAP_URL_NAME_UNKNOWN = "* unknown map *"; 317 public static final String MAP_URL_NAME_UNKNOWN = "* unknown map *";
313 public static final String MAP_DISK_NAME_UNKNOWN = "-> unknown map"; 318 public static final String MAP_DISK_NAME_UNKNOWN = "-> unknown map";
314 319
315 static final String MAP_FILENAME_PRI = "navitmap_001.bin"; 320 static final String MAP_FILENAME_PRI = "navitmap_001.bin";
350 355
351 public void run() 356 public void run()
352 { 357 {
353 stop_me = false; 358 stop_me = false;
354 mapdownload_stop_all_threads = false; 359 mapdownload_stop_all_threads = false;
355 System.out.println("map_num=" + this.map_num + " v=" + map_values.map_name + " " + map_values.url); 360 System.out.println("DEBUG_MAP_DOWNLOAD::map_num=" + this.map_num + " v=" + map_values.map_name + " " + map_values.url);
361
362 // ----- service start -----
363 // ----- service start -----
364 // Navit.getBaseContext_.startService(Navit.ZANaviMapDownloaderServiceIntent);
365 // ----- service start -----
366 // ----- service start -----
367
356 // 368 //
357 Navit.dim_screen_wrapper(); // brightness --------- 369 //Navit.dim_screen_wrapper(); // brightness ---------
358 int exit_code = download_osm_map(mHandler, map_values, this.map_num); 370 int exit_code = download_osm_map(mHandler, map_values, this.map_num);
359 Navit.default_brightness_screen_wrapper(); // brightness --------- 371 //Navit.default_brightness_screen_wrapper(); // brightness ---------
360 // 372 //
373
374 // ----- service stop -----
375 // ----- service stop -----
376 Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
377 // ----- service stop -----
378 // ----- service stop -----
379
361 // clean up always 380 // clean up always
362 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME); 381 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME);
363 tmp_downloadfile.delete(); 382 tmp_downloadfile.delete();
364 for (int jkl = 1; jkl < 51; jkl++) 383 for (int jkl = 1; jkl < 51; jkl++)
365 { 384 {
377 Bundle b = new Bundle(); 396 Bundle b = new Bundle();
378 msg.what = 0; 397 msg.what = 0;
379 b.putInt("dialog_num", this.my_dialog_num); 398 b.putInt("dialog_num", this.my_dialog_num);
380 // only exit_code=0 will try to use the new map 399 // only exit_code=0 will try to use the new map
381 b.putInt("exit_code", exit_code); 400 b.putInt("exit_code", exit_code);
401 b.putString("map_name", map_values.map_name);
382 msg.setData(b); 402 msg.setData(b);
383 mHandler.sendMessage(msg); 403 mHandler.sendMessage(msg);
384 } 404 }
385 405
386 public void stop_thread() 406 public void stop_thread()
387 { 407 {
388 stop_me = true; 408 stop_me = true;
389 mapdownload_stop_all_threads = true; 409 mapdownload_stop_all_threads = true;
390 Log.d("NavitMapDownloader", "stop_me -> true"); 410 Log.d("NavitMapDownloader", "stop_me -> true");
411
412 // ----- service stop -----
413 // ----- service stop -----
414 // Navit.getBaseContext_.stopService(Navit.ZANaviMapDownloaderServiceIntent);
415 // ----- service stop -----
416 // ----- service stop -----
417
391 // 418 //
392 Navit.default_brightness_screen(); // brightness --------- 419 //Navit.default_brightness_screen(); // brightness ---------
393 // 420 //
394 // remove the tmp download file (if there is one) 421 // remove the tmp download file (if there is one)
395 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME); 422 File tmp_downloadfile = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME);
396 tmp_downloadfile.delete(); 423 tmp_downloadfile.delete();
397 for (int jkl = 1; jkl < 51; jkl++) 424 for (int jkl = 1; jkl < 51; jkl++)
403 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE); 430 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
404 tmp_downloadfile_md5.delete(); 431 tmp_downloadfile_md5.delete();
405 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + ".idx"); 432 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, DOWNLOAD_FILENAME + ".idx");
406 tmp_downloadfile_idx.delete(); 433 tmp_downloadfile_idx.delete();
407 Log.d("NavitMapDownloader", "(b)removed " + tmp_downloadfile.getAbsolutePath()); 434 Log.d("NavitMapDownloader", "(b)removed " + tmp_downloadfile.getAbsolutePath());
435
436 // close cancel dialoag activity
437 Message msg2 = new Message();
438 Bundle b2 = new Bundle();
439 msg2.what = 1;
440 msg2.setData(b2);
441 ZANaviDownloadMapCancelActivity.canceldialog_handler.sendMessage(msg2);
442
408 } 443 }
409 } 444 }
410 445
411 private class MultiStreamDownloaderThread extends Thread 446 private class MultiStreamDownloaderThread extends Thread
412 { 447 {
414 Handler handler; 449 Handler handler;
415 zanavi_osm_map_values map_values; 450 zanavi_osm_map_values map_values;
416 int map_num; 451 int map_num;
417 int my_dialog_num; 452 int my_dialog_num;
418 int my_num = 0; 453 int my_num = 0;
454 int num_threads = 0;
419 String PATH = null; 455 String PATH = null;
420 String PATH2 = null; 456 String PATH2 = null;
421 String fileName = null; 457 String fileName = null;
422 String final_fileName = null; 458 String final_fileName = null;
423 String this_server_name = null; 459 String this_server_name = null;
424 String up_map = null; 460 String up_map = null;
425 long start_byte = 0L; 461 long start_byte = 0L;
426 long end_byte = 0L; 462 long end_byte = 0L;
427 463
428 MultiStreamDownloaderThread(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) 464 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)
429 { 465 {
430 running = false; 466 running = false;
431 467
432 this.start_byte = start_byte; 468 this.start_byte = start_byte;
433 this.end_byte = end_byte; 469 this.end_byte = end_byte;
434 470
435 System.out.println("bytes=" + this.start_byte + ":" + this.end_byte); 471 // System.out.println("DEBUG_MAP_DOWNLOAD::" + c + "bytes=" + this.start_byte + ":" + this.end_byte);
472 // System.out.println("DEBUG_MAP_DOWNLOAD::" + c + "Server=" + sn);
436 473
437 PATH = p; 474 PATH = p;
438 PATH2 = p2; 475 PATH2 = p2;
439 fileName = fn; 476 fileName = fn;
440 final_fileName = ffn; 477 final_fileName = ffn;
442 up_map = upmap; 479 up_map = upmap;
443 this.my_num = c; 480 this.my_num = c;
444 this.handler = h; 481 this.handler = h;
445 this.map_values = map_values; 482 this.map_values = map_values;
446 this.map_num = map_num2; 483 this.map_num = map_num2;
484 this.num_threads = num_threads;
447 if (this.map_num == Navit.MAP_NUM_PRIMARY) 485 if (this.map_num == Navit.MAP_NUM_PRIMARY)
448 { 486 {
449 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG; 487 this.my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
450 } 488 }
451 else if (this.map_num == Navit.MAP_NUM_SECONDARY) 489 else if (this.map_num == Navit.MAP_NUM_SECONDARY)
452 { 490 {
453 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG; 491 this.my_dialog_num = Navit.MAPDOWNLOAD_SEC_DIALOG;
454 } 492 }
455 System.out.println("MultiStreamDownloaderThread " + this.my_num + " init"); 493 // System.out.println("MultiStreamDownloaderThread " + this.my_num + " init");
456 } 494 }
457 495
458 public void run() 496 public void run()
459 { 497 {
460 running = true; 498 running = true;
461 499
462 System.out.println("MultiStreamDownloaderThread " + this.my_num + " run"); 500 // System.out.println("DEBUG_MAP_DOWNLOAD::MultiStreamDownloaderThread " + this.my_num + " run");
463 while (running) 501 while (running)
464 { 502 {
465 if (mapdownload_stop_all_threads == true) 503 if (mapdownload_stop_all_threads == true)
466 { 504 {
467 running = false; 505 running = false;
483 if (this.start_byte > (MAX_SINGLE_BINFILE_SIZE - 1)) 521 if (this.start_byte > (MAX_SINGLE_BINFILE_SIZE - 1))
484 { 522 {
485 // split file, we need to compensate 523 // split file, we need to compensate
486 int split_num = (int) (this.start_byte / MAX_SINGLE_BINFILE_SIZE); 524 int split_num = (int) (this.start_byte / MAX_SINGLE_BINFILE_SIZE);
487 long real_start_byte = this.start_byte - (MAX_SINGLE_BINFILE_SIZE * split_num); 525 long real_start_byte = this.start_byte - (MAX_SINGLE_BINFILE_SIZE * split_num);
488 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_start_byte); 526 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_start_byte, this.my_num);
527 // 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);
528 // 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);
489 } 529 }
490 else 530 else
491 { 531 {
492 f_rnd = d_open_file(PATH2 + "/" + fileName, this.start_byte); 532 f_rnd = d_open_file(PATH2 + "/" + fileName, this.start_byte, this.my_num);
533 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(a1): this.start_byte=" + this.start_byte);
534 // Log.d("NavitMapDownloader", this.my_num + "split file calc(a1): this.start_byte=" + this.start_byte);
493 } 535 }
494 536
495 if (f_rnd == null) 537 if (f_rnd == null)
496 { 538 {
497 Message msg = handler.obtainMessage(); 539 Message msg = handler.obtainMessage();
509 } 551 }
510 552
511 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer 553 byte[] buffer = new byte[MAP_WRITE_MEM_BUFFER]; // buffer
512 int len1 = 0; 554 int len1 = 0;
513 long already_read = this.start_byte; 555 long already_read = this.start_byte;
556 long read_per_interval = 0L;
557 int count_read_per_interval = 0;
558
514 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces 559 int alt = UPDATE_PROGRESS_EVERY_CYCLE; // show progress about every xx cylces
515 int alt_cur = 0; 560 int alt_cur = 0;
561 long alt_progress_update_timestamp = 0L;
562 int progress_update_intervall = 600; // show progress about every xx milliseconds
563
516 String kbytes_per_second = ""; 564 String kbytes_per_second = "";
517 long start_timestamp = System.currentTimeMillis(); 565 long start_timestamp = System.currentTimeMillis();
518 NumberFormat formatter = new DecimalFormat("00000.0"); 566 NumberFormat formatter = new DecimalFormat("00000.0");
519 String eta_string = ""; 567 String eta_string = "";
520 float per_second_overall = 0f; 568 float per_second_overall = 0f;
521 long bytes_remaining = 0; 569 long bytes_remaining = 0;
522 int eta_seconds = 0; 570 int eta_seconds = 0;
523 571
572 int current_split = 0;
573 int next_split = 0;
574
575 Message msg;
576 Bundle b = new Bundle();
577
524 // while ------- 578 // while -------
525 while ((try_number < RETRIES) && (!download_success)) 579 while ((try_number < RETRIES) && (!download_success))
526 { 580 {
527 if (mapdownload_stop_all_threads == true) 581 if (mapdownload_stop_all_threads == true)
528 { 582 {
539 break; 593 break;
540 // return 2; 594 // return 2;
541 } 595 }
542 596
543 try_number++; 597 try_number++;
544 Log.d("NavitMapDownloader", this.my_num + "download try number " + try_number); 598 // Log.d("NavitMapDownloader", this.my_num + "download try number " + try_number);
599 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "download try number " + try_number);
545 600
546 HttpURLConnection c = d_url_connect(map_values, this_server_name, map_num, this.my_num); 601 HttpURLConnection c = d_url_connect(map_values, this_server_name, map_num, this.my_num);
547 // set http header to resume download 602 // set http header to resume download
603 //if (this.end_byte == map_values.est_size_bytes)
604 //{
605 // c = d_url_resume_download_at(c, already_read, this.my_num);
606 //}
607 //else
608 //{
609
610 if (already_read >= this.end_byte)
611 {
612 // something has gone wrong, the server seems to give us more bytes than there are in the file? what now?
613 // just start from a few bytes back and lets hope it will work this time
614 // 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!!");
615 already_read = this.end_byte - 10;
616 }
617
618 // Log.d("NavitMapDownloader", this.my_num + "resume values: already_read=" + already_read + " this.start_byte=" + this.start_byte + " this.end_byte=" + this.end_byte);
619 // 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);
548 c = d_url_resume_download_at(c, already_read, this.end_byte, this.my_num); 620 c = d_url_resume_download_at(c, already_read, this.end_byte, this.my_num);
621 //}
549 622
550 if (try_number > 1) 623 if (try_number > 1)
551 { 624 {
552 // seek to resume position in download file 625 // seek to resume position in download file
553 // --------------------- 626 // ---------------------
554 // close file 627 // close file
555 d_close_file(f_rnd); 628 d_close_file(f_rnd, this.my_num);
629
556 // open file 630 // open file
557 if (this.start_byte > (MAX_SINGLE_BINFILE_SIZE - 1)) 631 if (already_read > (MAX_SINGLE_BINFILE_SIZE - 1))
558 { 632 {
559 // split file, we need to compensate 633 // split file, we need to compensate
560 int split_num = (int) (already_read / MAX_SINGLE_BINFILE_SIZE); 634 int split_num = (int) (already_read / MAX_SINGLE_BINFILE_SIZE);
561 long real_already_read = already_read - (MAX_SINGLE_BINFILE_SIZE * split_num); 635 long real_already_read = already_read - (MAX_SINGLE_BINFILE_SIZE * split_num);
562 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_already_read); 636 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + split_num, real_already_read, this.my_num);
637 // 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);
638 // Log.d("NavitMapDownloader", this.my_num + "split file calc(b2):split_num=" + split_num + " real_already_read=" + real_already_read + " already_read=" + already_read);
563 } 639 }
564 else 640 else
565 { 641 {
566 f_rnd = d_open_file(PATH2 + "/" + fileName, already_read); 642 f_rnd = d_open_file(PATH2 + "/" + fileName, already_read, this.my_num);
643 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "split file calc(b1): already_read=" + already_read);
644 // Log.d("NavitMapDownloader", this.my_num + "split file calc(b1): already_read=" + already_read);
567 } 645 }
568 } 646 }
569 647
570 BufferedInputStream bif = d_url_get_bif(c); 648 // BufferedInputStream bif = d_url_get_bif(c);
649 InputStream bif = (InputStream) d_url_get_bif(c);
571 if (bif != null) 650 if (bif != null)
572 { 651 {
573 // do the real downloading here
574
575 // do the real downloading here 652 // do the real downloading here
576 try 653 try
577 { 654 {
655 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "buf avail1=" + bif.available());
656
578 // len1 -> number of bytes actually read 657 // len1 -> number of bytes actually read
579 //while (((len1 = bif.read(buffer)) != -1) && (already_read <= this.end_byte)) 658 //while (((len1 = bif.read(buffer)) != -1) && (already_read <= this.end_byte))
580 while ((len1 = bif.read(buffer)) != -1) 659 while ((len1 = bif.read(buffer)) != -1)
581 { 660 {
661 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " buf avail2=" + bif.available() + " len1=" + len1);
662
582 if (stop_me) 663 if (stop_me)
583 { 664 {
584 // ok we need to be stopped! close all files and end 665 // ok we need to be stopped! close all files and end
585 bif.close(); 666 bif.close();
586 d_url_disconnect(c); 667 d_url_disconnect(c);
587 this.running = false; 668 this.running = false;
588 mapdownload_error_code_inc(); 669 mapdownload_error_code_inc();
589 break; 670 break;
590 // return 2; 671 // return 2;
591 } 672 }
592 already_read = already_read + len1; 673
593 alt_cur++; 674 if (len1 > 0)
594 if (alt_cur > alt)
595 { 675 {
676 already_read = already_read + len1;
677 read_per_interval = read_per_interval + len1;
596 alt_cur = 0; 678 alt_cur++;
597 679 if (alt_progress_update_timestamp + progress_update_intervall < System.currentTimeMillis())
598 Message msg = handler.obtainMessage();
599 Bundle b = new Bundle();
600 msg.what = 1;
601
602 b.putInt("dialog_num", my_dialog_num);
603 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
604 per_second_overall = (float) (already_read - this.start_byte) / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
605
606 mapdownload_already_read[this.my_num - 1] = already_read - this.start_byte;
607 mapdownload_byte_per_second_overall[this.my_num - 1] = per_second_overall;
608
609 //b.putInt("max", (int) (this.end_byte / 1024));
610 //b.putInt("cur", (int) ((already_read - this.start_byte) / 1024));
611 float f1 = 0;
612 long l1 = 0L;
613 int k;
614 for (k = 0; k < mapdownload_already_read.length; k++)
615 { 680 {
681 alt_cur = 0;
682 alt_progress_update_timestamp = System.currentTimeMillis();
683
684 count_read_per_interval++;
685
686 if (count_read_per_interval == 10)
687 {
688 // int rate = (int) ((float) read_per_interval / ((float) progress_update_intervall * 10f / 1000f * 1024f));
689 // if (rate < 1)
690 // {
691 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + " downloadrate: 0 kbytes/s");
692 // }
693 // else
694 // {
695 // if (this.my_num == 1)
696 // {
697 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "+downloadrate:" + rate + " kbytes/s");
698 // }
699 // else if (this.my_num == 2)
700 // {
701 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "O downloadrate:" + rate + " kbytes/s");
702 // }
703 // else
704 // {
705 // System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "M downloadrate:" + rate + " kbytes/s");
706 // }
707 // }
708 read_per_interval = 0L;
709 count_read_per_interval = 0;
710 }
711
712 msg = handler.obtainMessage();
713 b = new Bundle();
714 msg.what = 1;
715
716 b.putInt("dialog_num", my_dialog_num);
717 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
718 per_second_overall = (float) (already_read - this.start_byte) / (float) ((System.currentTimeMillis() - start_timestamp) / 1000);
719
720 mapdownload_already_read[this.my_num - 1] = already_read - this.start_byte;
721 mapdownload_byte_per_second_overall[this.my_num - 1] = per_second_overall;
722
723 //b.putInt("max", (int) (this.end_byte / 1024));
724 //b.putInt("cur", (int) ((already_read - this.start_byte) / 1024));
725 float f1 = 0;
726 long l1 = 0L;
727 int k;
728 for (k = 0; k < mapdownload_already_read.length; k++)
729 {
616 l1 = l1 + mapdownload_already_read[k]; 730 l1 = l1 + mapdownload_already_read[k];
617 f1 = f1 + mapdownload_byte_per_second_overall[k]; 731 f1 = f1 + mapdownload_byte_per_second_overall[k];
732 }
733 b.putInt("max", (int) (map_values.est_size_bytes / 1024));
734 b.putInt("cur", (int) (l1 / 1024));
735
736 kbytes_per_second = formatter.format((f1 / 1024f));
737 // kbytes_per_second = formatter.format((per_second_overall / 1024f));
738 // bytes_remaining = this.end_byte - already_read;
739 bytes_remaining = map_values.est_size_bytes - l1;
740 // eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
741 eta_seconds = (int) ((float) bytes_remaining / (float) f1);
742 if (eta_seconds > 60)
743 {
744 eta_string = (int) (eta_seconds / 60f) + " m";
745 }
746 else
747 {
748 eta_string = eta_seconds + " s";
749 }
750 //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
751 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
752 msg.setData(b);
753 //if (this.my_num == num_threads - 1)
754 //{
755 handler.sendMessage(msg);
756 //}
757
758 try
759 {
760 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);
761 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);
762 }
763 catch (Exception e)
764 {
765 e.printStackTrace();
766 }
767
768 try
769 {
770 Thread.sleep(5);
771 }
772 catch (Exception sleep_e)
773 {
774 sleep_e.printStackTrace();
775 }
776 // System.out.println("" + this.my_num + " " + already_read + " - " + (already_read - this.start_byte));
777 // System.out.println("+++++++++++++ still downloading +++++++++++++");
618 } 778 }
619 b.putInt("max", (int) (map_values.est_size_bytes / 1024)); 779 // if (already_read > this.end_byte)
620 b.putInt("cur", (int) (l1 / 1024)); 780 // {
781 // int len2 = len1 - (int) (already_read - this.end_byte);
782 // if (len2 > 0)
783 // {
784 // f_rnd.write(buffer, 0, len2);
785 // }
786 // }
787 // else
788 // {
621 789
622 kbytes_per_second = formatter.format((f1 / 1024f)); 790 // ********
623 // kbytes_per_second = formatter.format((per_second_overall / 1024f)); 791 current_split = 0;
624 // bytes_remaining = this.end_byte - already_read; 792 next_split = 0;
625 bytes_remaining = map_values.est_size_bytes - l1; 793 if (already_read > (MAX_SINGLE_BINFILE_SIZE - 1))
626 // eta_seconds = (int) ((float) bytes_remaining / (float) per_second_overall);
627 eta_seconds = (int) ((float) bytes_remaining / (float) f1);
628 if (eta_seconds > 60)
629 { 794 {
630 eta_string = (int) (eta_seconds / 60f) + " m"; 795 // split file, we need to compensate
796 current_split = (int) ((long) (already_read - len1) / MAX_SINGLE_BINFILE_SIZE);
797 next_split = (int) (already_read / MAX_SINGLE_BINFILE_SIZE);
798
799 // 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);
800 }
801
802 if (current_split != next_split)
803 {
804 int len1_part2 = (int) (already_read % MAX_SINGLE_BINFILE_SIZE);
805 int len1_part1 = len1 - len1_part2;
806 // part1
807 f_rnd.write(buffer, 0, len1_part1);
808 // close file
809 d_close_file(f_rnd, this.my_num);
810 // open next split file (and seek to pos ZERO)
811 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + next_split, 0, this.my_num);
812 // part2, only if more than ZERO bytes left to write
813 if (len1_part2 > 0)
814 {
815 f_rnd.write(buffer, len1_part1, len1_part2);
816 }
817
818 // 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);
819
631 } 820 }
632 else 821 else
633 { 822 {
634 eta_string = eta_seconds + " s"; 823 // actually write len1 bytes to output file
824 f_rnd.write(buffer, 0, len1);
635 } 825 }
636 //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 826 // ********
637 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
638 msg.setData(b);
639 handler.sendMessage(msg);
640 827
641 try
642 {
643 Thread.sleep(20);
644 }
645 catch (Exception sleep_e)
646 {
647 sleep_e.printStackTrace();
648 }
649 // System.out.println("" + this.my_num + " " + already_read + " - " + (already_read - this.start_byte));
650 // System.out.println("+++++++++++++ still downloading +++++++++++++");
651 }
652 // if (already_read > this.end_byte)
653 // { 828 // }
654 // int len2 = len1 - (int) (already_read - this.end_byte); 829 // try
655 // if (len2 > 0)
656 // { 830 // {
657 // f_rnd.write(buffer, 0, len2); 831 // // System.out.println("" + this.my_num + " pos=" + f_rnd.getFilePointer() + " len=" + f_rnd.length());
658 // } 832 // }
659 // } 833 // catch (Exception e)
660 // else
661 // { 834 // {
662 835 // e.printStackTrace();
663 // ********
664 int current_split = 0;
665 int next_split = 0;
666 if (already_read > (MAX_SINGLE_BINFILE_SIZE - 1))
667 {
668 // split file, we need to compensate
669 current_split = (int) ((long) (already_read - len1) / MAX_SINGLE_BINFILE_SIZE);
670 next_split = (int) (already_read / MAX_SINGLE_BINFILE_SIZE);
671 }
672
673 if (current_split != next_split)
674 {
675 int len1_part2 = (int) (already_read % MAX_SINGLE_BINFILE_SIZE);
676 int len1_part1 = len1 - len1_part2;
677 // part1
678 f_rnd.write(buffer, 0, len1_part1);
679 // close file
680 d_close_file(f_rnd);
681 // open next split file (and seek to pos ZERO)
682 f_rnd = d_open_file(PATH2 + "/" + fileName + "." + next_split, 0);
683 // part2, only if more than ZERO bytes left to write
684 if (len1_part2 > 0)
685 {
686 f_rnd.write(buffer, len1_part1, len1_part2);
687 }
688 }
689 else
690 {
691 // actually write len1 bytes to output file
692 f_rnd.write(buffer, 0, len1);
693 }
694 // ********
695
696 // } 836 // }
697 try
698 {
699 // System.out.println("" + this.my_num + " pos=" + f_rnd.getFilePointer() + " len=" + f_rnd.length());
700 }
701 catch (Exception e)
702 {
703 e.printStackTrace();
704 } 837 }
705 } 838 }
706 d_close_file(f_rnd); 839 d_close_file(f_rnd, this.my_num);
707 840
708 bif.close(); 841 bif.close();
709 d_url_disconnect(c); 842 d_url_disconnect(c);
710 843
711 // delete an already final filename, first 844 // delete an already final filename, first
725 // remove any duplicates (junk in file) 858 // remove any duplicates (junk in file)
726 //**NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName); 859 //**NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName);
727 // add to the catalogue file for downloaded maps 860 // add to the catalogue file for downloaded maps
728 //**NavitMapDownloader.add_to_cat_file(final_fileName, map_values.url); 861 //**NavitMapDownloader.add_to_cat_file(final_fileName, map_values.url);
729 862
863 // ------ check if we got enough bytes from the server here! if NOT, then continue downloading and reconnect
864 if (already_read < this.end_byte)
865 {
866 // continue download loop
867 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);
868 }
869 else
870 {
730 // ok downloaded ok, set flag!! 871 // ok downloaded ok, set flag!!
731 download_success = true; 872 download_success = true;
732 this.running = false; 873 this.running = false;
874 }
733 } 875 }
734 catch (IOException e) 876 catch (IOException e)
735 { 877 {
736 Message msg = handler.obtainMessage(); 878 msg = handler.obtainMessage();
737 Bundle b = new Bundle(); 879 b = new Bundle();
738 msg.what = 2; 880 msg.what = 2;
739 b.putInt("dialog_num", my_dialog_num); 881 b.putInt("dialog_num", my_dialog_num);
740 b.putString("text", Navit.get_text("Error downloading map, resuming")); //TRANS 882 b.putString("text", Navit.get_text("Error downloading map, resuming")); //TRANS
741 msg.setData(b); 883 msg.setData(b);
742 handler.sendMessage(msg); 884 handler.sendMessage(msg);
743 885
744 Log.d("NavitMapDownloader", this.my_num + " Error7: " + e); 886 Log.d("NavitMapDownloader", this.my_num + " Error7: " + e);
745 // ******* ********* D/NavitMapDownloader( 266): 1 Error7: java.io.IOException: No space left on device 887 // ******* ********* D/NavitMapDownloader( 266): 1 Error7: java.io.IOException: No space left on device
888 System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "IOException11: already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1);
746 889
747 try 890 try
748 { 891 {
749 bif.close(); 892 bif.close();
750 } 893 }
764 { 907 {
765 e1.printStackTrace(); 908 e1.printStackTrace();
766 } 909 }
767 d_url_disconnect(c); 910 d_url_disconnect(c);
768 911
912 System.out.println("DEBUG_MAP_DOWNLOAD::" + this.my_num + "Exception22: already_read=" + already_read + " MAX_SINGLE_BINFILE_SIZE=" + MAX_SINGLE_BINFILE_SIZE + " len1=" + len1);
913
769 e.printStackTrace(); 914 e.printStackTrace();
770 if (stop_me) 915 if (stop_me)
771 { 916 {
772 // ok we need to be stopped! close all files and end 917 // ok we need to be stopped! close all files and end
773 this.running = false; 918 this.running = false;
781 // bif == null 926 // bif == null
782 { 927 {
783 d_url_disconnect(c); 928 d_url_disconnect(c);
784 try 929 try
785 { 930 {
786 // sleep for 5 second 931 // sleep for 2 second
787 Thread.sleep(5000); 932 Thread.sleep(2000);
788 } 933 }
789 catch (Exception ex) 934 catch (Exception ex)
790 { 935 {
791 ex.printStackTrace(); 936 ex.printStackTrace();
792 } 937 }
795 940
796 if (!download_success) 941 if (!download_success)
797 { 942 {
798 try 943 try
799 { 944 {
800 // sleep for 5 second (also here) 945 // sleep for 2 second (also here)
801 Thread.sleep(5000); 946 Thread.sleep(2000);
802 } 947 }
803 catch (Exception ex2) 948 catch (Exception ex2)
804 { 949 {
805 ex2.printStackTrace(); 950 ex2.printStackTrace();
806 } 951 }
808 } 953 }
809 // while ------- 954 // while -------
810 955
811 try 956 try
812 { 957 {
813 Thread.sleep(50); 958 Thread.sleep(150);
814 } 959 }
815 catch (InterruptedException e) 960 catch (InterruptedException e)
816 { 961 {
817 e.printStackTrace(); 962 e.printStackTrace();
818 } 963 }
1329 } 1474 }
1330 c++; 1475 c++;
1331 } 1476 }
1332 } 1477 }
1333 1478
1479 public String find_file_on_other_mapserver(List<String> map_servers_list, String md5_sum, zanavi_osm_map_values map_values, int map_num3)
1480 {
1481 System.out.println("find_file_on_other_mapserver:first server name=" + map_servers_list);
1482
1483 String other_server_name = d_get_servername();
1484 int i = 0;
1485 for (i = 0; i < 4; i++)
1486 {
1487 // System.out.println("find_file_on_other_mapserver:found other mapserver (" + i + "): " + other_server_name);
1488 if ((other_server_name == null) || (map_servers_list.contains(other_server_name)))
1489 {
1490 // try again
1491 try
1492 {
1493 Thread.sleep(110);
1494 }
1495 catch (InterruptedException e)
1496 {
1497 }
1498 other_server_name = d_get_servername();
1499 }
1500 else
1501 {
1502 break;
1503 }
1504 }
1505
1506 if ((other_server_name == null) || (map_servers_list.contains(other_server_name)))
1507 {
1508 System.out.println("find_file_on_other_mapserver:no other server found");
1509 return null;
1510 }
1511
1512 String md5_server = d_get_md5_from_server(map_values, other_server_name, map_num3);
1513 if ((md5_server == null) || (!md5_server.equals(md5_sum)))
1514 {
1515 System.out.println("find_file_on_other_mapserver:wrong md5 on " + other_server_name);
1516 return null;
1517 }
1518
1519 System.out.println("find_file_on_other_mapserver:found other mapserver: " + other_server_name);
1520 return other_server_name;
1521 }
1522
1334 public int download_osm_map(Handler handler, zanavi_osm_map_values map_values, int map_num3) 1523 public int download_osm_map(Handler handler, zanavi_osm_map_values map_values, int map_num3)
1335 { 1524 {
1336 int exit_code = 1; 1525 int exit_code = 1;
1337 1526
1338 int my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG; 1527 int my_dialog_num = Navit.MAPDOWNLOAD_PRI_DIALOG;
1485 long bytes_diff = 0L; 1674 long bytes_diff = 0L;
1486 long bytes_leftover = 0; 1675 long bytes_leftover = 0;
1487 if (map_values.est_size_bytes < 1000000) 1676 if (map_values.est_size_bytes < 1000000)
1488 { 1677 {
1489 num_threads = 1; 1678 num_threads = 1;
1679 map_servers_used.clear();
1680 map_servers_used.add(this_server_name);
1490 bytes_diff = map_values.est_size_bytes; 1681 bytes_diff = map_values.est_size_bytes;
1491 } 1682 }
1492 else 1683 else
1493 { 1684 {
1494 if (this_server_name.equals("zanavi.noaccess.de")) 1685 // if (this_server_name.equals("zanavi.noaccess.de"))
1495 { 1686 // {
1496 // use only 1 thread on this server 1687 // num_threads = MULTI_NUM_THREADS;
1497 num_threads = 1;
1498 bytes_diff = map_values.est_size_bytes; 1688 // bytes_diff = map_values.est_size_bytes;
1499 } 1689 // }
1500 else 1690 // else
1501 { 1691 // {
1502 // use only 1 thread ALWAYS!! (there seem to be some bugs on multithreaded downloads) 1692 // num_threads = MULTI_NUM_THREADS;
1503 num_threads = 1;
1504 bytes_diff = map_values.est_size_bytes; 1693 // bytes_diff = map_values.est_size_bytes;
1505 } 1694 // }
1506 //{ 1695 //{
1696
1507 // num_threads = MULTI_NUM_THREADS; 1697 num_threads = MULTI_NUM_THREADS;
1698 int num_threads2 = 0;
1699 map_servers_used.clear();
1700 String new_map_server = null;
1701 int k2 = 0;
1702 for (k2 = 0; k2 < num_threads; k2++)
1703 {
1704 if (k2 == 0)
1705 {
1706 // first thread always uses this server name
1707 new_map_server = this_server_name;
1708 map_servers_used.add(new_map_server);
1709 }
1710 else
1711 {
1712 new_map_server = find_file_on_other_mapserver(map_servers_used, md5_server, map_values, map_num3);
1713 if (new_map_server != null)
1714 {
1715 map_servers_used.add(new_map_server);
1716 }
1717 }
1718
1719 if (new_map_server != null)
1720 {
1721 num_threads2++;
1722 }
1723 }
1724 num_threads = num_threads2;
1725
1508 // bytes_diff = (long) (map_values.est_size_bytes / num_threads); 1726 bytes_diff = (long) (map_values.est_size_bytes / num_threads);
1509 // if (bytes_diff * num_threads < map_values.est_size_bytes) 1727 if (bytes_diff * num_threads < map_values.est_size_bytes)
1510 // { 1728 {
1511 // bytes_leftover = map_values.est_size_bytes - (bytes_diff * num_threads); 1729 bytes_leftover = map_values.est_size_bytes - (bytes_diff * num_threads);
1512 // System.out.println("bytes_leftover=" + bytes_leftover); 1730 System.out.println("bytes_leftover=" + bytes_leftover);
1513 // } 1731 }
1514 //} 1732 //}
1733
1734 // bytes_diff is the part size in bytes!! but you must read from (start) to (bytes_diff - 1)!!
1515 } 1735 }
1516 1736
1517 // stupid workaround to have this value available :-( 1737 // stupid workaround to have this value available :-(
1518 MULTI_NUM_THREADS_LOCAL = num_threads; 1738 MULTI_NUM_THREADS_LOCAL = num_threads;
1519 1739
1540 File outputFileSplit = new File(file99, fileName + "." + String.valueOf(jkl)); 1760 File outputFileSplit = new File(file99, fileName + "." + String.valueOf(jkl));
1541 System.out.println("delete:" + file99 + "/" + fileName + "." + String.valueOf(jkl)); 1761 System.out.println("delete:" + file99 + "/" + fileName + "." + String.valueOf(jkl));
1542 outputFileSplit.delete(); 1762 outputFileSplit.delete();
1543 } 1763 }
1544 1764
1545 /* 1765 // -- DISABLED --
1766 // -- DISABLED --
1546 * // pre create the big file 1767 // // pre create the big file
1547 * msg = handler.obtainMessage(); 1768 // msg = handler.obtainMessage();
1548 * b = new Bundle(); 1769 // b = new Bundle();
1549 * msg.what = 1; 1770 // msg.what = 1;
1550 * b.putInt("max", 20); // use a dummy number here 1771 // b.putInt("max", 20); // use a dummy number here
1551 * b.putInt("cur", 0); 1772 // b.putInt("cur", 0);
1552 * b.putInt("dialog_num", my_dialog_num); 1773 // b.putInt("dialog_num", my_dialog_num);
1553 * b.putString("title", Navit.get_text("Mapdownload")); //TRANS 1774 // b.putString("title", Navit.get_text("Mapdownload")); //TRANS
1554 * b.putString("text", Navit.get_text("Creating outputfile, long time")); //TRANS 1775 // b.putString("text", Navit.get_text("Creating outputfile, long time")); //TRANS
1555 * msg.setData(b); 1776 // msg.setData(b);
1556 * handler.sendMessage(msg); 1777 // handler.sendMessage(msg);
1557 */ 1778 //
1558
1559 // --disabled-- // d_pre_create_file(PATH2 + fileName, map_values.est_size_bytes, handler, my_dialog_num); 1779 // d_pre_create_file(PATH2 + fileName, map_values.est_size_bytes, handler, my_dialog_num);
1780 // -- DISABLED --
1781 // -- DISABLED --
1560 1782
1561 // 1783 //
1562 // 1784 //
1563 MultiStreamDownloaderThread[] m = new MultiStreamDownloaderThread[num_threads]; 1785 MultiStreamDownloaderThread[] m = new MultiStreamDownloaderThread[num_threads];
1564 int k; 1786 int k;
1571 mapdownload_byte_per_second_overall[k] = 0; 1793 mapdownload_byte_per_second_overall[k] = 0;
1572 } 1794 }
1573 1795
1574 // start downloader threads here -------------------------- 1796 // start downloader threads here --------------------------
1575 // start downloader threads here -------------------------- 1797 // start downloader threads here --------------------------
1798 String new_map_server = null;
1576 for (k = 0; k < num_threads; k++) 1799 for (k = 0; k < num_threads; k++)
1577 { 1800 {
1801 new_map_server = map_servers_used.get(k);
1802
1803 if (new_map_server != null)
1804 {
1578 if (k == (num_threads - 1)) 1805 if (k == (num_threads - 1))
1579 { 1806 {
1580 m[k] = new MultiStreamDownloaderThread(handler, map_values, map_num3, k + 1, PATH, PATH2, fileName, final_fileName, this_server_name, up_map, bytes_diff * k, map_values.est_size_bytes); 1807 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);
1581 } 1808 }
1582 else 1809 else
1583 { 1810 {
1584 m[k] = new MultiStreamDownloaderThread(handler, map_values, map_num3, k + 1, PATH, PATH2, fileName, final_fileName, this_server_name, up_map, bytes_diff * k, bytes_diff * (k + 1)); 1811 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);
1585 } 1812 }
1586 m[k].start(); 1813 m[k].start();
1814 }
1587 } 1815 }
1588 1816
1589 // wait for downloader threads to finish -------------------------- 1817 // wait for downloader threads to finish --------------------------
1590 for (k = 0; k < num_threads; k++) 1818 for (k = 0; k < num_threads; k++)
1591 { 1819 {
1608 mapdownload_error_code_clear(); 1836 mapdownload_error_code_clear();
1609 return 97; 1837 return 97;
1610 } 1838 }
1611 // 1839 //
1612 // 1840 //
1613 // calc md5sum on device on print it to STDOUT (unless file was split into pieces) 1841 // calc md5sum on device on print it to STDOUT
1614 if (!split_mapfile) 1842 //if (!split_mapfile)
1615 { 1843 //{
1844
1845 try
1846 {
1847 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking map ..."));
1848 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking map ..."));
1849 }
1850 catch (Exception e)
1851 {
1852 e.printStackTrace();
1853 }
1854
1616 System.out.println("MD5 ok **start*"); 1855 System.out.println("MD5 ok **start*");
1617 String md5sum_local_calculated = calc_md5sum_on_device(handler, my_dialog_num, map_values.est_size_bytes); 1856 String md5sum_local_calculated = calc_md5sum_on_device(handler, my_dialog_num, map_values.est_size_bytes);
1618 if (!d_match_md5sums(md5sum_local_calculated, md5_server)) 1857 if (!d_match_md5sums(md5sum_local_calculated, md5_server))
1619 { 1858 {
1620 // some problem with download 1859 // some problem with download
1621 msg = handler.obtainMessage(); 1860 msg = handler.obtainMessage();
1622 b = new Bundle(); 1861 b = new Bundle();
1623 msg.what = 2; 1862 msg.what = 2;
1624 b.putInt("dialog_num", my_dialog_num); 1863 b.putInt("dialog_num", my_dialog_num);
1625 b.putString("text", Navit.get_text("MD5 mismatch")); //TRANS 1864 b.putString("text", Navit.get_text("MD5 mismatch")); //TRANS
1626 msg.setData(b); 1865 msg.setData(b);
1627 handler.sendMessage(msg); 1866 handler.sendMessage(msg);
1628 1867
1629 outputFile.delete(); 1868 outputFile.delete();
1630 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE); 1869 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
1631 tmp_downloadfile_md5.delete(); 1870 tmp_downloadfile_md5.delete();
1632 1871
1633 Log.d("NavitMapDownloader", "MD5 mismatch!!"); 1872 Log.d("NavitMapDownloader", "MD5 mismatch!!");
1634 System.out.println("MD5 mismatch ######"); 1873 System.out.println("MD5 mismatch ######");
1635 return 12; 1874 return 12;
1636 } 1875 }
1637 else 1876 else
1638 { 1877 {
1639 Log.d("NavitMapDownloader", "MD5 ok"); 1878 Log.d("NavitMapDownloader", "MD5 ok");
1640 System.out.println("MD5 ok ******"); 1879 System.out.println("MD5 ok ******");
1641 } 1880 }
1642 System.out.println("MD5 ok **end*"); 1881 System.out.println("MD5 ok **end*");
1643 } 1882 //}
1644 // 1883 //
1645 File file = new File(PATH); 1884 File file = new File(PATH);
1646 File final_outputFile = new File(file, final_fileName); 1885 File final_outputFile = new File(file, final_fileName);
1647 // delete an already final filename, first 1886 // delete an already final filename, first
1648 final_outputFile.delete(); 1887 final_outputFile.delete();
1672 md5_final_filename.delete(); 1911 md5_final_filename.delete();
1673 // rename file to final name 1912 // rename file to final name
1674 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE); 1913 File tmp_downloadfile_md5 = new File(Navit.MAPMD5_FILENAME_PATH, MD5_DOWNLOAD_TEMPFILE);
1675 tmp_downloadfile_md5.renameTo(md5_final_filename); 1914 tmp_downloadfile_md5.renameTo(md5_final_filename);
1676 1915
1916 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
1917 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
1918 final Thread thread_for_download_wakelock = new Thread()
1919 {
1920 @Override
1921 public void run()
1922 {
1923 try
1924 {
1925 if (Navit.wl != null)
1926 {
1927 Navit.wl.acquire();
1928 Log.e("Navit", "WakeLock: acquire 2a");
1929 }
1930 }
1931 catch (Exception e)
1932 {
1933 e.printStackTrace();
1934 }
1935
1936 try
1937 {
1938 // sleep for 10 seconds
1939 Thread.sleep(10000);
1940 }
1941 catch (Exception e)
1942 {
1943 }
1944
1945 try
1946 {
1947 if (Navit.wl != null)
1948 {
1949 if (Navit.wl.isHeld())
1950 {
1951 Navit.wl.release();
1952 Log.e("Navit", "WakeLock: release 3a");
1953 }
1954 }
1955 }
1956 catch (Exception e)
1957 {
1958 e.printStackTrace();
1959 }
1960 }
1961 };
1962 thread_for_download_wakelock.start();
1963 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
1964 // ------------ activate screen and CPU (and WLAN) -- before index download starts ---------------------
1965
1966 // don't try to download index file for coastline and border maps
1967 if ((!final_fileName.equals(MAP_FILENAME_BORDERS)) && (!final_fileName.equals(MAP_FILENAME_COASTLINE)))
1968 {
1677 // ------------ download idx file ------------ 1969 // ------------ download idx file ------------
1678 // ------------ download idx file ------------ 1970 // ------------ download idx file ------------
1679 zanavi_osm_map_values z_dummy_for_idx = new zanavi_osm_map_values("index file", map_values.url + ".idx", 1000000, false, 3); 1971 zanavi_osm_map_values z_dummy_for_idx = new zanavi_osm_map_values("index file", map_values.url + ".idx", 1000000, false, 3);
1680 // z_dummy_for_idx.map_name = "index file"; 1972 // z_dummy_for_idx.map_name = "index file";
1681 1973
1682 boolean index_file_download = false; 1974 boolean index_file_download = false;
1683 if ((Navit.Navit_DonateVersion_Installed) || (Navit.Navit_Largemap_DonateVersion_Installed)) 1975 if ((Navit.Navit_DonateVersion_Installed) || (Navit.Navit_Largemap_DonateVersion_Installed))
1684 { 1976 {
1685 index_file_download = true; 1977 index_file_download = true;
1686 } 1978 }
1687 1979
1688 if (index_file_download == true) 1980 if (index_file_download == true)
1689 { 1981 {
1690 long real_file_size_idx = d_get_real_download_filesize(z_dummy_for_idx, this_server_name, map_num3); 1982 long real_file_size_idx = d_get_real_download_filesize(z_dummy_for_idx, this_server_name, map_num3);
1691 if (real_file_size_idx <= 0) 1983 if (real_file_size_idx <= 0)
1692 { 1984 {
1693 msg = handler.obtainMessage(); 1985 msg = handler.obtainMessage();
1694 b = new Bundle(); 1986 b = new Bundle();
1695 msg.what = 2; 1987 msg.what = 2;
1696 b.putInt("dialog_num", my_dialog_num); 1988 b.putInt("dialog_num", my_dialog_num);
1697 b.putString("text", Navit.get_text("Error downloading index!")); //TRANS 1989 b.putString("text", Navit.get_text("Error downloading index!")); //TRANS
1698 msg.setData(b); 1990 msg.setData(b);
1699 handler.sendMessage(msg); 1991 handler.sendMessage(msg);
1700 1992
1701 index_file_download = false; 1993 index_file_download = false;
1702 }
1703 else
1704 {
1705 z_dummy_for_idx.est_size_bytes = real_file_size_idx;
1706 }
1707 }
1708
1709 if (index_file_download == true)
1710 {
1711 num_threads = 1;
1712 bytes_leftover = 0;
1713 num_threads = 1;
1714 bytes_diff = z_dummy_for_idx.est_size_bytes;
1715
1716 Message msg_idx = handler.obtainMessage();
1717 Bundle b_idx = new Bundle();
1718 msg_idx.what = 1;
1719 b_idx.putInt("max", (int) (z_dummy_for_idx.est_size_bytes / 1024)); // use a dummy number here
1720 b_idx.putInt("cur", 0);
1721 b_idx.putInt("dialog_num", my_dialog_num);
1722 b_idx.putString("title", Navit.get_text("Index download")); //TRANS
1723 b_idx.putString("text", Navit.get_text("downloading indexfile")); //TRANS
1724 msg_idx.setData(b);
1725 handler.sendMessage(msg_idx);
1726
1727 MultiStreamDownloaderThread[] m_idx = new MultiStreamDownloaderThread[num_threads];
1728 int k_idx;
1729
1730 mapdownload_error_code_clear();
1731 mapdownload_already_read = new long[num_threads];
1732 mapdownload_byte_per_second_overall = new float[num_threads];
1733 for (k_idx = 0; k_idx < num_threads; k_idx++)
1734 {
1735 mapdownload_already_read[k_idx] = 0;
1736 mapdownload_byte_per_second_overall[k_idx] = 0;
1737 }
1738
1739 // start downloader threads here --------------------------
1740 // start downloader threads here --------------------------
1741 for (k_idx = 0; k_idx < num_threads; k_idx++)
1742 {
1743 if (k_idx == (num_threads - 1))
1744 {
1745 m[k_idx] = new MultiStreamDownloaderThread(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);
1746 } 1994 }
1747 else 1995 else
1748 { 1996 {
1749 m[k_idx] = new MultiStreamDownloaderThread(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)); 1997 z_dummy_for_idx.est_size_bytes = real_file_size_idx;
1750 }
1751 m[k_idx].start();
1752 } 1998 }
1753
1754 // wait for downloader threads to finish --------------------------
1755 for (k_idx = 0; k_idx < num_threads; k_idx++)
1756 {
1757 try
1758 {
1759 m[k_idx].join();
1760 } 1999 }
1761 catch (InterruptedException e) 2000
2001 if (index_file_download == true)
1762 { 2002 {
1763 e.printStackTrace(); 2003 num_threads = 1;
1764 } 2004 bytes_leftover = 0;
1765 catch (Exception e) 2005 num_threads = 1;
1766 { 2006 bytes_diff = z_dummy_for_idx.est_size_bytes;
1767 e.printStackTrace();
1768 }
1769 }
1770 2007
1771 if (mapdownload_error_code > 0) 2008 Message msg_idx = handler.obtainMessage();
1772 { 2009 Bundle b_idx = new Bundle();
2010 msg_idx.what = 1;
2011 b_idx.putInt("max", (int) (z_dummy_for_idx.est_size_bytes / 1024)); // use a dummy number here
2012 b_idx.putInt("cur", 0);
2013 b_idx.putInt("dialog_num", my_dialog_num);
2014 b_idx.putString("title", Navit.get_text("Index download")); //TRANS
2015 b_idx.putString("text", Navit.get_text("downloading indexfile")); //TRANS
2016 msg_idx.setData(b);
2017 handler.sendMessage(msg_idx);
2018
2019 MultiStreamDownloaderThread[] m_idx = new MultiStreamDownloaderThread[num_threads];
2020 int k_idx;
2021
1773 mapdownload_error_code_clear(); 2022 mapdownload_error_code_clear();
2023 mapdownload_already_read = new long[num_threads];
2024 mapdownload_byte_per_second_overall = new float[num_threads];
2025 for (k_idx = 0; k_idx < num_threads; k_idx++)
2026 {
2027 mapdownload_already_read[k_idx] = 0;
2028 mapdownload_byte_per_second_overall[k_idx] = 0;
2029 }
2030
2031 // start downloader threads here --------------------------
2032 // start downloader threads here --------------------------
2033 for (k_idx = 0; k_idx < num_threads; k_idx++)
2034 {
2035 if (k_idx == (num_threads - 1))
2036 {
2037 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);
2038 }
2039 else
2040 {
2041 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));
2042 }
2043 m[k_idx].start();
2044 }
2045
2046 // wait for downloader threads to finish --------------------------
2047 for (k_idx = 0; k_idx < num_threads; k_idx++)
2048 {
2049 try
2050 {
2051 m[k_idx].join();
2052 }
2053 catch (InterruptedException e)
2054 {
2055 e.printStackTrace();
2056 }
2057 catch (Exception e)
2058 {
2059 e.printStackTrace();
2060 }
2061 }
2062
2063 if (mapdownload_error_code > 0)
2064 {
2065 mapdownload_error_code_clear();
1774 index_file_download = false; 2066 index_file_download = false;
1775 } 2067 }
1776 else 2068 else
1777 { 2069 {
1778 // delete an already there idx file, first 2070 // delete an already there idx file, first
1779 //System.out.println("idx 001:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx"); 2071 //System.out.println("idx 001:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
1780 File idx_final_filename = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx"); 2072 File idx_final_filename = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
1781 idx_final_filename.delete(); 2073 idx_final_filename.delete();
1782 // rename file to final name 2074 // rename file to final name
1783 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, fileName + ".idx"); 2075 File tmp_downloadfile_idx = new File(Navit.CFG_FILENAME_PATH, fileName + ".idx");
1784 //System.out.println("idx 002:" + Navit.CFG_FILENAME_PATH + fileName + ".idx"); 2076 //System.out.println("idx 002:" + Navit.CFG_FILENAME_PATH + fileName + ".idx");
1785 File final_outputFile_idx = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx"); 2077 File final_outputFile_idx = new File(Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
1786 //System.out.println("idx 003:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx"); 2078 //System.out.println("idx 003:" + Navit.MAP_FILENAME_PATH + final_fileName + ".idx");
1787 tmp_downloadfile_idx.renameTo(final_outputFile_idx); 2079 tmp_downloadfile_idx.renameTo(final_outputFile_idx);
1788 } 2080 }
1789 } 2081 }
1790 // ------------ download idx file ------------ 2082 // ------------ download idx file ------------
1791 // ------------ download idx file ------------ 2083 // ------------ download idx file ------------
2084 }
1792 2085
1793 // remove 2086 // remove
1794 NavitMapDownloader.remove_from_cat_file(up_map); 2087 NavitMapDownloader.remove_from_cat_file(up_map);
1795 // remove any duplicates (junk in file) 2088 // remove any duplicates (junk in file)
1796 NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName); 2089 NavitMapDownloader.remove_from_cat_file_disk_name(final_fileName);
2098 2391
2099 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, int num) 2392 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, int num)
2100 { 2393 {
2101 c.setRequestProperty("Range", "bytes=" + old_download_size + "-"); 2394 c.setRequestProperty("Range", "bytes=" + old_download_size + "-");
2102 Log.d("NavitMapDownloader", num + " resuming download at " + old_download_size + " bytes"); 2395 Log.d("NavitMapDownloader", num + " resuming download at " + old_download_size + " bytes");
2396 System.out.println("DEBUG_MAP_DOWNLOAD::" + num + " resuming download at " + old_download_size + " bytes");
2103 return c; 2397 return c;
2104 } 2398 }
2105 2399
2106 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, long end_size, int num) 2400 public HttpURLConnection d_url_resume_download_at(HttpURLConnection c, long old_download_size, long end_size, int num)
2107 { 2401 {
2108 c.setRequestProperty("Range", "bytes=" + old_download_size + "-" + end_size); 2402 c.setRequestProperty("Range", "bytes=" + old_download_size + "-" + end_size);
2109 Log.d("NavitMapDownloader", num + "resuming download at " + old_download_size + " bytes" + ":" + end_size); 2403 Log.d("NavitMapDownloader", num + "resuming download at " + old_download_size + " bytes" + ":" + end_size);
2404 System.out.println("DEBUG_MAP_DOWNLOAD::" + num + "resuming download at " + old_download_size + " bytes" + ":" + end_size);
2405
2110 return c; 2406 return c;
2111 } 2407 }
2112 2408
2113 public BufferedInputStream d_url_get_bif(HttpURLConnection c) 2409 public BufferedInputStream d_url_get_bif(HttpURLConnection c)
2410 // public InputStream d_url_get_bif(HttpURLConnection c)
2114 { 2411 {
2115 InputStream is = null; 2412 InputStream is = null;
2116 BufferedInputStream bif = null; 2413 BufferedInputStream bif = null;
2117 try 2414 try
2118 { 2415 {
2416 c.setUseCaches(false);
2119 c.connect(); 2417 c.connect();
2120 is = c.getInputStream(); 2418 is = c.getInputStream();
2121 bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer 2419 bif = new BufferedInputStream(is, MAP_READ_FILE_BUFFER); // buffer
2122 } 2420 }
2123 catch (FileNotFoundException f) 2421 catch (FileNotFoundException f)
2138 { 2436 {
2139 e.printStackTrace(); 2437 e.printStackTrace();
2140 } 2438 }
2141 2439
2142 return bif; 2440 return bif;
2441 // return is;
2143 } 2442 }
2144 2443
2145 public void d_url_disconnect(HttpURLConnection c) 2444 public void d_url_disconnect(HttpURLConnection c)
2146 { 2445 {
2147 try 2446 try
2324 b.putString("text", Navit.get_text("Creating outputfile, wait")); //TRANS 2623 b.putString("text", Navit.get_text("Creating outputfile, wait")); //TRANS
2325 msg.setData(b); 2624 msg.setData(b);
2326 handler.sendMessage(msg); 2625 handler.sendMessage(msg);
2327 } 2626 }
2328 2627
2329 public RandomAccessFile d_open_file(String filename, long pos) 2628 public RandomAccessFile d_open_file(String filename, long pos, int my_num)
2330 { 2629 {
2331 RandomAccessFile f = null; 2630 RandomAccessFile f = null;
2332 System.out.println("d_open_file: " + filename + " seek (start):" + pos); 2631 System.out.println("d_open_file: " + my_num + " " + filename + " seek (start):" + pos);
2333 try 2632 try
2334 { 2633 {
2335 f = new RandomAccessFile(filename, "rw"); 2634 f = new RandomAccessFile(filename, "rw");
2336 if (pos > 1900000000L) 2635 if (pos > 1900000000L)
2337 { 2636 {
2381 } 2680 }
2382 catch (Exception e) 2681 catch (Exception e)
2383 { 2682 {
2384 e.printStackTrace(); 2683 e.printStackTrace();
2385 } 2684 }
2386 System.out.println("d_open_file:seek (end):" + pos); 2685 System.out.println("d_open_file:" + my_num + " seek (end):" + pos);
2387 2686
2388 try 2687 try
2389 { 2688 {
2390 System.out.println("d_open_file:f len(seek)=" + f.length()); 2689 System.out.println("d_open_file:" + my_num + " f len(seek)=" + f.length());
2391 } 2690 }
2392 catch (Exception e) 2691 catch (Exception e)
2393 { 2692 {
2394 e.printStackTrace(); 2693 e.printStackTrace();
2395 } 2694 }
2396 2695
2397 return f; 2696 return f;
2398 } 2697 }
2399 2698
2400 public void d_close_file(RandomAccessFile f) 2699 public void d_close_file(RandomAccessFile f, int my_num)
2401 { 2700 {
2402 try 2701 try
2403 { 2702 {
2404 System.out.println("d_close_file:f len=" + f.length()); 2703 System.out.println("d_close_file:" + my_num + " f len=" + f.length());
2405 } 2704 }
2406 catch (Exception e) 2705 catch (Exception e)
2407 { 2706 {
2408 e.printStackTrace(); 2707 e.printStackTrace();
2409 } 2708 }
2410 2709
2411 try 2710 try
2412 { 2711 {
2413 f.close(); 2712 f.close();
2414 System.out.println("d_close_file:f.close()"); 2713 System.out.println("d_close_file:" + my_num + " f.close()");
2415 } 2714 }
2416 catch (Exception e) 2715 catch (Exception e)
2417 { 2716 {
2418 e.printStackTrace(); 2717 e.printStackTrace();
2419 } 2718 }
2433 { 2732 {
2434 String md5sum = null; 2733 String md5sum = null;
2435 2734
2436 if (size > MAX_SINGLE_BINFILE_SIZE) 2735 if (size > MAX_SINGLE_BINFILE_SIZE)
2437 { 2736 {
2438 // skip this step with large mapfiles (or implement handling of split files) 2737 try
2738 {
2739 String s = "";
2740 Message msg = null;
2741 Bundle b = null;
2742 int size2 = (int) (size / 1000);
2743 long cur_pos = 0L;
2744
2745 // Create MD5 Hash
2746 MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
2747 InputStream fis = null;
2748 boolean no_more_parts = false;
2749
2750 // find all pieces of the large map file
2751 int parts = 0;
2752
2753 // -------------- LOOP thru all the parts -------------
2754 // -------------- LOOP thru all the parts -------------
2755 // -------------- LOOP thru all the parts -------------
2756
2757 try
2758 {
2759 if (Navit.wl_cpu != null)
2760 {
2761 Navit.wl_cpu.acquire();
2762 Log.e("Navit", "WakeLock CPU: acquire 2a");
2763 }
2764 }
2765 catch (Exception e)
2766 {
2767 e.printStackTrace();
2768 }
2769
2770 while (!no_more_parts)
2771 {
2772 try
2773 {
2774 if (parts == 0)
2775 {
2776 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
2777 System.out.println("calc_md5sum_on_device(split):found file=" + Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
2778 }
2779 else
2780 {
2781 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME + "." + parts);
2782 System.out.println("calc_md5sum_on_device(split):found file=" + Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME + "." + parts);
2783 }
2784 parts++;
2785 }
2786 catch (FileNotFoundException e)
2787 {
2788 e.printStackTrace();
2789 no_more_parts = true;
2790 }
2791
2792 if (!no_more_parts)
2793 {
2794 byte[] buffer = new byte[1024 * MD5_CALC_BUFFER_KB];
2795 int numRead = 0;
2796 do
2797 {
2798 if (mapdownload_stop_all_threads)
2799 {
2800 System.out.println("calc_md5sum_on_device 1(split):mapdownload_stop_all_threads");
2801 break;
2802 }
2803
2804 try
2805 {
2806 numRead = fis.read(buffer);
2807 }
2808 catch (IOException e)
2809 {
2810 e.printStackTrace();
2811 }
2812
2813 if (numRead > 0)
2814 {
2815 // try
2816 // {
2817 // // allow to catch breath
2818 // Thread.sleep(1);
2819 // }
2820 // catch (InterruptedException e)
2821 // {
2822 // e.printStackTrace();
2823 // }
2824 digest.update(buffer, 0, numRead);
2825 cur_pos = cur_pos + numRead;
2826 }
2827
2828 msg = handler.obtainMessage();
2829 b = new Bundle();
2830 msg.what = 1;
2831 b.putInt("max", size2);
2832 b.putInt("cur", (int) (cur_pos / 1000));
2833 b.putInt("dialog_num", my_dialog_num);
2834 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2835 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
2836 msg.setData(b);
2837 handler.sendMessage(msg);
2838
2839 try
2840 {
2841 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
2842 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
2843 }
2844 catch (Exception e)
2845 {
2846 e.printStackTrace();
2847 }
2848
2849 }
2850 while (numRead != -1);
2851
2852 try
2853 {
2854 fis.close();
2855 }
2856 catch (IOException e)
2857 {
2858 e.printStackTrace();
2859 }
2860 catch (Exception e)
2861 {
2862 e.printStackTrace();
2863 }
2864
2865 }
2866
2867 if (mapdownload_stop_all_threads)
2868 {
2869
2870 try
2871 {
2872 if (Navit.wl_cpu != null)
2873 {
2874 Navit.wl_cpu.release();
2875 Log.e("Navit", "WakeLock CPU: release 2a");
2876 }
2877 }
2878 catch (Exception e)
2879 {
2880 e.printStackTrace();
2881 }
2882
2883 System.out.println("calc_md5sum_on_device 2(split):mapdownload_stop_all_threads");
2439 return null; 2884 return null;
2885 }
2886
2887 }
2888
2889 try
2890 {
2891 if (Navit.wl_cpu != null)
2892 {
2893 Navit.wl_cpu.release();
2894 Log.e("Navit", "WakeLock CPU: release 2b");
2895 }
2896 }
2897 catch (Exception e)
2898 {
2899 e.printStackTrace();
2900 }
2901
2902 // -------------- LOOP thru all the parts -------------
2903 // -------------- LOOP thru all the parts -------------
2904 // -------------- LOOP thru all the parts -------------
2905
2906 msg = handler.obtainMessage();
2907 b = new Bundle();
2908 msg.what = 1;
2909 b.putInt("max", size2);
2910 b.putInt("cur", size2);
2911 b.putInt("dialog_num", my_dialog_num);
2912 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2913 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
2914 msg.setData(b);
2915 handler.sendMessage(msg);
2916
2917 byte messageDigest[] = digest.digest();
2918 // Create Hex String
2919 StringBuffer hexString = new StringBuffer();
2920 String t = "";
2921 for (int i = 0; i < messageDigest.length; i++)
2922 {
2923 t = Integer.toHexString(0xFF & messageDigest[i]);
2924 if (t.length() == 1)
2925 {
2926 t = "0" + t;
2927 }
2928 hexString.append(t);
2929 }
2930 md5sum = hexString.toString();
2931 System.out.println("md5sum local(split)=" + md5sum);
2932
2933 }
2934 catch (Exception e)
2935 {
2936
2937 try
2938 {
2939 if (Navit.wl_cpu != null)
2940 {
2941 Navit.wl_cpu.release();
2942 Log.e("Navit", "WakeLock CPU: release 2c");
2943 }
2944 }
2945 catch (Exception e3)
2946 {
2947 e3.printStackTrace();
2948 }
2949
2950 return md5sum;
2951 }
2952
2953 return md5sum;
2440 } 2954 }
2441 2955
2442 try 2956 try
2443 { 2957 {
2444 String s = ""; 2958 String s = "";
2449 2963
2450 // Create MD5 Hash 2964 // Create MD5 Hash
2451 MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); 2965 MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
2452 2966
2453 InputStream fis = null; 2967 InputStream fis = null;
2968
2454 try 2969 try
2455 { 2970 {
2971 if (Navit.wl_cpu != null)
2972 {
2973 Navit.wl_cpu.acquire();
2974 Log.e("Navit", "WakeLock CPU: acquire 3a");
2975 }
2976 }
2977 catch (Exception e)
2978 {
2979 e.printStackTrace();
2980 }
2981
2982 try
2983 {
2456 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME); 2984 fis = new FileInputStream(Navit.CFG_FILENAME_PATH + DOWNLOAD_FILENAME);
2457 } 2985 }
2458 catch (FileNotFoundException e) 2986 catch (FileNotFoundException e)
2459 { 2987 {
2460 e.printStackTrace(); 2988 e.printStackTrace();
2461 } 2989 }
2990
2462 byte[] buffer = new byte[1024 * 32]; 2991 byte[] buffer = new byte[1024 * MD5_CALC_BUFFER_KB];
2463 int numRead = 0; 2992 int numRead = 0;
2464 do 2993 do
2465 { 2994 {
2466 if (mapdownload_stop_all_threads) 2995 if (mapdownload_stop_all_threads)
2467 { 2996 {
2475 } 3004 }
2476 catch (IOException e) 3005 catch (IOException e)
2477 { 3006 {
2478 e.printStackTrace(); 3007 e.printStackTrace();
2479 } 3008 }
3009
2480 if (numRead > 0) 3010 if (numRead > 0)
2481 { 3011 {
2482 try 3012 // try
2483 { 3013 // {
2484 // allow to catch breath 3014 // // allow to catch breath
2485 Thread.sleep(15); 3015 // Thread.sleep(1);
2486 } 3016 // }
2487 catch (InterruptedException e) 3017 // catch (InterruptedException e)
2488 { 3018 // {
2489 e.printStackTrace(); 3019 // e.printStackTrace();
2490 } 3020 // }
2491 digest.update(buffer, 0, numRead); 3021 digest.update(buffer, 0, numRead);
2492 cur_pos = cur_pos + numRead; 3022 cur_pos = cur_pos + numRead;
2493 } 3023 }
2494 3024
2495 msg = handler.obtainMessage(); 3025 msg = handler.obtainMessage();
2501 b.putString("title", Navit.get_text("Mapdownload")); //TRANS 3031 b.putString("title", Navit.get_text("Mapdownload")); //TRANS
2502 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS 3032 b.putString("text", Navit.get_text("generating MD5 checksum")); //TRANS
2503 msg.setData(b); 3033 msg.setData(b);
2504 handler.sendMessage(msg); 3034 handler.sendMessage(msg);
2505 3035
3036 try
3037 {
3038 ZANaviMapDownloaderService.set_noti_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3039 ZANaviMapDownloaderService.set_large_text(Navit.get_text("checking") + ": " + calc_percent((int) (cur_pos / 1000), size2) + "%");
3040 }
3041 catch (Exception e)
3042 {
3043 e.printStackTrace();
3044 }
3045
2506 } 3046 }
2507 while (numRead != -1); 3047 while (numRead != -1);
2508 3048
2509 msg = handler.obtainMessage(); 3049 msg = handler.obtainMessage();
2510 b = new Bundle(); 3050 b = new Bundle();
2530 e.printStackTrace(); 3070 e.printStackTrace();
2531 } 3071 }
2532 3072
2533 if (mapdownload_stop_all_threads) 3073 if (mapdownload_stop_all_threads)
2534 { 3074 {
3075 try
3076 {
3077 if (Navit.wl_cpu != null)
3078 {
3079 Navit.wl_cpu.release();
3080 Log.e("Navit", "WakeLock CPU: release 3a");
3081 }
3082 }
3083 catch (Exception e)
3084 {
3085 e.printStackTrace();
3086 }
3087
2535 System.out.println("calc_md5sum_on_device 2:mapdownload_stop_all_threads"); 3088 System.out.println("calc_md5sum_on_device 2:mapdownload_stop_all_threads");
2536 return null; 3089 return null;
2537 } 3090 }
2538 3091
2539 byte messageDigest[] = digest.digest(); 3092 byte messageDigest[] = digest.digest();
2558 } 3111 }
2559 catch (Exception e) 3112 catch (Exception e)
2560 { 3113 {
2561 e.printStackTrace(); 3114 e.printStackTrace();
2562 } 3115 }
3116
3117 try
3118 {
3119 if (Navit.wl_cpu != null)
3120 {
3121 Navit.wl_cpu.release();
3122 Log.e("Navit", "WakeLock CPU: release 3b");
3123 }
3124 }
3125 catch (Exception e)
3126 {
3127 e.printStackTrace();
3128 }
3129
2563 return md5sum; 3130 return md5sum;
2564 } 3131 }
3132
3133 static int calc_percent(int cur, int max)
3134 {
3135 int percent = 0;
3136
3137 try
3138 {
3139 percent = (int) ((float) cur / (float) max * 100f);
3140 }
3141 catch (Exception e)
3142 {
3143 percent = 0;
3144 }
3145 return percent;
3146 }
2565} 3147}

Legend:
Removed from v.35  
changed lines
  Added in v.36

   
Visit the ZANavi Wiki