--- deliantra/Deliantra-Client/DC.pm 2009/01/04 10:22:19 1.200 +++ deliantra/Deliantra-Client/DC.pm 2012/01/07 15:24:41 1.213 @@ -19,7 +19,7 @@ our $VERSION; BEGIN { - $VERSION = '2.02'; + $VERSION = '3.0'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; @@ -36,20 +36,13 @@ use Storable (); # finally use Fcntl (); use JSON::XS qw(encode_json decode_json); +use Guard qw(guard); -=item guard { BLOCK } - -Returns an object that executes the given block as soon as it is destroyed. - -=cut - -sub guard(&) { - bless \(my $cb = $_[0]), "DC::Guard" -} - -sub DC::Guard::DESTROY { - ${$_[0]}->() -} +# modules to support other DC::* packages +use List::Util (); +use IO::AIO (); +use Coro::AIO (); +use AnyEvent::AIO (); =item shorten $string[, $maxlength] @@ -156,7 +149,7 @@ for (@RC_PATH, "") { $path = "$RC_BASE/$_/$_[0]"; - return $path if -r $path; + return $path if -e $path; } die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; @@ -169,7 +162,7 @@ or return; local $/; - JSON::XS->new->utf8->relaxed->decode (<$fh>) + eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) } } sub set_theme($) { @@ -197,17 +190,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 {