--- deliantra/Deliantra-Client/DC.pm 2008/12/12 15:06:00 1.198 +++ deliantra/Deliantra-Client/DC.pm 2009/01/11 03:19:47 1.201 @@ -19,7 +19,7 @@ our $VERSION; BEGIN { - $VERSION = '2.01'; + $VERSION = '2.02'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; @@ -28,7 +28,9 @@ use utf8; use strict qw(vars subs); +use Socket (); use AnyEvent (); +use AnyEvent::Util (); use Pod::POM (); use File::Path (); use Storable (); # finally @@ -69,17 +71,11 @@ $_ } -sub socketpipe() { - socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC - or die "cannot establish bidirectional pipe: $!\n"; - - ($fh1, $fh2) -} - sub background(&;&) { my ($bg, $cb) = @_; - my ($fh_r, $fh_w) = DC::socketpipe; + my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair + or die "unable to create background socketpair: $!"; my $pid = fork; @@ -201,17 +197,22 @@ sub read_cfg { my ($file) = @_; - $::CFG = load_json $file; + $::CFG = (load_json $file) || (load_json "$file.bak"); } sub write_cfg { my $file = "$Deliantra::VARDIR/client.cf"; $::CFG->{VERSION} = $::VERSION; + $::CFG->{layout} = DC::UI::get_layout (); - open my $fh, ">:utf8", $file + open my $fh, ">:utf8", "$file~" or return; print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); + close $fh; + + rename $file, "$file.bak"; + rename "$file~", $file; } sub http_proxy {