… | |
… | |
522 | |
522 | |
523 | DC::Mix_CloseAudio if $SDL_MIXER; |
523 | DC::Mix_CloseAudio if $SDL_MIXER; |
524 | undef $SDL_MIXER; |
524 | undef $SDL_MIXER; |
525 | |
525 | |
526 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
526 | DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; |
|
|
527 | } |
|
|
528 | |
|
|
529 | ############################################################################# |
|
|
530 | # Over-the-air updates |
|
|
531 | |
|
|
532 | sub ota_update_finish { |
|
|
533 | $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] }); |
|
|
534 | } |
|
|
535 | |
|
|
536 | sub ota_update_status { |
|
|
537 | } |
|
|
538 | |
|
|
539 | sub ota_update { |
|
|
540 | my ($face, $size) = @_; |
|
|
541 | |
|
|
542 | my $coro = Coro::async_pool { |
|
|
543 | my $override = "$Urlader::EXE_DIR/override"; |
|
|
544 | |
|
|
545 | $MESSAGE_DIST->add_channel ({ |
|
|
546 | id => "ota_update", |
|
|
547 | title => "Update", |
|
|
548 | tooltip => "<b>Software Update Log</b>", |
|
|
549 | }); |
|
|
550 | |
|
|
551 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "preparing override..." }); |
|
|
552 | |
|
|
553 | my $fh = Coro::AIO::aio_open "$override.tmp", IO::AIO::O_WRONLY | IO::AIO::O_CREAT | IO::AIO::O_TRUNC, 0777; |
|
|
554 | |
|
|
555 | unless ($fh) { |
|
|
556 | ota_update_finish "unable to write software update:\n$Urlader::EXE_DIR/override.tmp:\n$!"; |
|
|
557 | return; |
|
|
558 | } |
|
|
559 | |
|
|
560 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "downloading $size bytes..." }); |
|
|
561 | |
|
|
562 | my $cv = AE::cv; |
|
|
563 | my $error; |
|
|
564 | |
|
|
565 | $cv->begin (Coro::rouse_cb); |
|
|
566 | |
|
|
567 | $CONN->ask_face ( |
|
|
568 | $face, |
|
|
569 | -1000, |
|
|
570 | sub { |
|
|
571 | $STATUSBOX->add ( |
|
|
572 | (sprintf "update download: %d/%d", $size - $_[1], $size), |
|
|
573 | pri => -9, group => "ota_update", timeout => 60, fg => [1, 1, 0, 1] |
|
|
574 | ); |
|
|
575 | |
|
|
576 | $cv->begin; |
|
|
577 | my $len = length $_[2]; |
|
|
578 | IO::AIO::aio_write $fh, $_[1], $len, $_[2], undef, sub { |
|
|
579 | $error ||= $_[0] != $len; |
|
|
580 | $cv->end; |
|
|
581 | }; |
|
|
582 | }, |
|
|
583 | sub { |
|
|
584 | $cv->end; |
|
|
585 | }, |
|
|
586 | ); |
|
|
587 | |
|
|
588 | Coro::rouse_wait; |
|
|
589 | |
|
|
590 | $STATUSBOX->clr_group ("ota_update"); |
|
|
591 | |
|
|
592 | $error ||= Coro::AIO::aio_fsync $fh; |
|
|
593 | $error ||= Coro::AIO::aio_close $fh; |
|
|
594 | |
|
|
595 | if ($error) { |
|
|
596 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "file write error, update aborted." }); |
|
|
597 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
598 | return; |
|
|
599 | } |
|
|
600 | |
|
|
601 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "replacing override file..." }); |
|
|
602 | |
|
|
603 | if (Coro::AIO::aio_rename "$override.tmp", $override) { |
|
|
604 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "unable to replace override file, update aborted." }); |
|
|
605 | Coro::AIO::aio_unlink "$override.tmp"; |
|
|
606 | } |
|
|
607 | |
|
|
608 | $MESSAGE_DIST->message ({ type => "ota_update", markup => "update successfull, changes become active at next start." }); |
|
|
609 | }; |
|
|
610 | |
|
|
611 | $CONN->{ota_update} = Guard::guard { |
|
|
612 | $coro->cancel; |
|
|
613 | }; |
|
|
614 | } |
|
|
615 | |
|
|
616 | sub ota_update_ask { |
|
|
617 | my ($ok, $face, $ver, $size, $changes) = @_; |
|
|
618 | |
|
|
619 | $CONN->{w}{ota_dialog} = my $dialog = new DC::UI::Toplevel |
|
|
620 | x => "center", |
|
|
621 | y => "center", |
|
|
622 | max_w => $::WIDTH * 0.7, |
|
|
623 | max_h => $::WIDTH * 0.7, |
|
|
624 | title => "Software update available", |
|
|
625 | child => my $vbox = new DC::UI::VBox, |
|
|
626 | ; |
|
|
627 | |
|
|
628 | $vbox->add (new DC::UI::Label |
|
|
629 | ellipsise => 0, |
|
|
630 | text => "The server offers a software update, " |
|
|
631 | . "do you want to start downloading this update in the background?", |
|
|
632 | ); |
|
|
633 | |
|
|
634 | $vbox->add (new DC::UI::FancyFrame |
|
|
635 | expand => 1, |
|
|
636 | label => "Changes", |
|
|
637 | child => (new DC::UI::TextScroller |
|
|
638 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4, |
|
|
639 | par => [{ |
|
|
640 | markup => "<tt>Old revision: $Urlader::EXE_VER\n" |
|
|
641 | . "New revision: $ver\n" |
|
|
642 | . "Download size: $size bytes</tt>\n\n" |
|
|
643 | . DC::asxml $changes |
|
|
644 | }], |
|
|
645 | ), |
|
|
646 | ); |
|
|
647 | |
|
|
648 | $vbox->add (my $hbox = new DC::UI::HBox); |
|
|
649 | |
|
|
650 | $hbox->add (new DC::UI::Button |
|
|
651 | expand => 1, |
|
|
652 | text => "Not now", |
|
|
653 | on_activate => sub { |
|
|
654 | $dialog->destroy; |
|
|
655 | 0 |
|
|
656 | } |
|
|
657 | ); |
|
|
658 | $hbox->add (new DC::UI::Button |
|
|
659 | expand => 1, |
|
|
660 | text => "Yes, start downloading", |
|
|
661 | on_activate => sub { |
|
|
662 | $dialog->destroy; |
|
|
663 | ota_update $face, $size; |
|
|
664 | 0 |
|
|
665 | }, |
|
|
666 | ); |
|
|
667 | |
|
|
668 | $dialog->show; |
|
|
669 | } |
|
|
670 | |
|
|
671 | sub ota_update_check { |
|
|
672 | return unless defined $Urlader::EXE_ID; |
|
|
673 | |
|
|
674 | ::message { markup => "Checking for software update..." }; |
|
|
675 | |
|
|
676 | $CONN->send_exti_req (ota_update => $Urlader::URLADER_VERSION, $Urlader::EXE_ID, $Urlader::EXE_VER, sub { |
|
|
677 | my ($ok, $face, $ver, $size, $changes) = @_; |
|
|
678 | |
|
|
679 | if ($ok) { |
|
|
680 | if (defined $ver) { |
|
|
681 | ::message { markup => "Server offers version $ver (we are version $Urlader::EXE_VER)." }; |
|
|
682 | &ota_update_ask; |
|
|
683 | } else { |
|
|
684 | ::message { markup => "Server has no newer version." }; |
|
|
685 | } |
|
|
686 | } else { |
|
|
687 | ::message { markup => "Server does not support software update." }; |
|
|
688 | } |
|
|
689 | |
|
|
690 | # $self->register_face_handler ($exp_table, sub { |
|
|
691 | # my ($face) = @_; |
|
|
692 | |
|
|
693 | # $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
694 | # $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
695 | # }); |
|
|
696 | |
|
|
697 | () |
|
|
698 | }); |
527 | } |
699 | } |
528 | |
700 | |
529 | ############################################################################# |
701 | ############################################################################# |
530 | |
702 | |
531 | sub destroy_query_dialog { |
703 | sub destroy_query_dialog { |
… | |
… | |
792 | }, |
964 | }, |
793 | |
965 | |
794 | on_connect => sub { |
966 | on_connect => sub { |
795 | if ($_[0]) { |
967 | if ($_[0]) { |
796 | DC::lowdelay fileno $CONN->{fh}; |
968 | DC::lowdelay fileno $CONN->{fh}; |
|
|
969 | |
|
|
970 | ota_update_check; |
797 | |
971 | |
798 | status "successfully connected to the server"; |
972 | status "successfully connected to the server"; |
799 | } else { |
973 | } else { |
800 | undef $CONN; |
974 | undef $CONN; |
801 | status "unable to connect: $!"; |
975 | status "unable to connect: $!"; |
… | |
… | |
1855 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); |
2029 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $DC::DB::DBDIR, tooltip => ""); |
1856 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); |
2030 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)"); |
1857 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); |
2031 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => ""); |
1858 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); |
2032 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Branch (Prebuilt)"); |
1859 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); |
2033 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => ""); |
1860 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Version (Prebuilt)"); |
2034 | $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Revision (Prebuilt)"); |
1861 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); |
2035 | $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => ""); |
1862 | } |
2036 | } |
1863 | |
2037 | |
1864 | $vbox |
2038 | $vbox |
1865 | } |
2039 | } |