ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Main.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Main.pm (file contents):
Revision 1.4 by root, Fri Dec 30 04:15:32 2011 UTC vs.
Revision 1.8 by root, Wed Jan 4 11:23:23 2012 UTC

142our $PL_NOTEBOOK; 142our $PL_NOTEBOOK;
143our $PL_WINDOW; 143our $PL_WINDOW;
144 144
145our $MUSIC_PLAYING_WIDGET; 145our $MUSIC_PLAYING_WIDGET;
146our $LICENSE_WIDGET; 146our $LICENSE_WIDGET;
147our $DOWNLOADS_WIDGET;
147 148
148our $PICKUP_PAGE; 149our $PICKUP_PAGE;
149our $INVENTORY_PAGE; 150our $INVENTORY_PAGE;
150our $STATS_PAGE; 151our $STATS_PAGE;
151our $SKILL_PAGE; 152our $SKILL_PAGE;
521 522
522 DC::Mix_CloseAudio if $SDL_MIXER; 523 DC::Mix_CloseAudio if $SDL_MIXER;
523 undef $SDL_MIXER; 524 undef $SDL_MIXER;
524 525
525 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO; 526 DC::SDL_QuitSubSystem DC::SDL_INIT_AUDIO;
527}
528
529#############################################################################
530# Over-the-air updates
531
532sub ota_update_finish {
533 $MESSAGE_DIST->message ({ type => "ota_update", markup => $_[0] });
534}
535
536sub ota_update_status {
537}
538
539sub 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
616sub 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
671sub 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 });
526} 699}
527 700
528############################################################################# 701#############################################################################
529 702
530sub destroy_query_dialog { 703sub destroy_query_dialog {
791 }, 964 },
792 965
793 on_connect => sub { 966 on_connect => sub {
794 if ($_[0]) { 967 if ($_[0]) {
795 DC::lowdelay fileno $CONN->{fh}; 968 DC::lowdelay fileno $CONN->{fh};
969
970 ota_update_check;
796 971
797 status "successfully connected to the server"; 972 status "successfully connected to the server";
798 } else { 973 } else {
799 undef $CONN; 974 undef $CONN;
800 status "unable to connect: $!"; 975 status "unable to connect: $!";
1850 2025
1851 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory"); 2026 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Data Directory");
1852 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => ""); 2027 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $Deliantra::VARDIR, tooltip => "");
1853 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory"); 2028 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Database Directory");
1854 $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 => "");
2030 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Urlader (Prebuilt)");
2031 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_VERSION}, tooltip => "");
1855 $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)");
1856 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_ID, tooltip => ""); 2033 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_ID}, tooltip => "");
1857 $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)");
1858 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::EXE_VER, tooltip => ""); 2035 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $ENV{URLADER_EXE_VER}, tooltip => "");
1859 $table->add_at (0, $row , new DC::UI::Label align => 1, text => "Update (Prebuilt)");
1860 $table->add_at (1, $row++, new DC::UI::Label align => 0, text => $::UPDPAR, tooltip => "");
1861 } 2036 }
1862 2037
1863 $vbox 2038 $vbox
1864} 2039}
1865 2040
2039 2214
2040sub media_window { 2215sub media_window {
2041 my $vb = new DC::UI::VBox; 2216 my $vb = new DC::UI::VBox;
2042 2217
2043 $vb->add (new DC::UI::FancyFrame 2218 $vb->add (new DC::UI::FancyFrame
2044 label => "Currently playing music", 2219 label => "Current background music",
2045 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, 2220 child => new DC::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
2046 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8), 2221 child => ($MUSIC_PLAYING_WIDGET = new DC::UI::Label ellipsise => 0, fontsize => 0.8),
2047 ); 2222 );
2223
2224 $vb->add (new DC::UI::FancyFrame
2225 label => "Current downloads",
2226 child => ($DOWNLOADS_WIDGET = new DC::UI::Table
2227 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2228 );
2229
2230 $DOWNLOADS_WIDGET->connect (visibility_change => sub {
2231 my ($self) = @_;
2232
2233 delete $self->{updater};
2234 return unless $_[1];
2235
2236 $self->{updater} = AE::timer 0, 0.7, sub {
2237 $self->clear;
2238
2239 return unless $CONN;
2240
2241 my @nums = sort { $b <=> $a } keys %{ $CONN->{ix_recv_buf} };
2242 return unless @nums;
2243
2244 $self->add_at (0, 0, new DC::UI::Label align => 1, text => "Face");
2245 $self->add_at (1, 0, new DC::UI::Label align => 0, text => "Octets/Total");
2246
2247 for my $row (0 .. $#nums) {
2248 my $num = $nums[$row];
2249
2250 my $total = length $CONN->{ix_recv_buf}{$num};
2251 my $got = $total - $CONN->{ix_recv_ofs}{$num};
2252
2253 $self->add_at (0, $row + 1, new DC::UI::Label align => 1, text => $num, tooltip => "");
2254 $self->add_at (1, $row + 1, new DC::UI::Label align => 0, text => "$got/$total", tooltip => "");
2255 }
2256 };
2257 });
2048 2258
2049 $vb->add (new DC::UI::FancyFrame 2259 $vb->add (new DC::UI::FancyFrame
2050 label => "Other media used in this session", 2260 label => "Other media used in this session",
2051 expand => 1, 2261 expand => 1,
2052 child => ($LICENSE_WIDGET = new DC::UI::TextScroller 2262 child => ($LICENSE_WIDGET = new DC::UI::TextScroller
2053 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), 2263 expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
2054 ); 2264 );
2055 2265
2056 $vb 2266 $vb
2057} 2267}
2058 2268

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines