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

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.197 by root, Fri Dec 5 14:44:45 2008 UTC vs.
Revision 1.201 by root, Sun Jan 11 03:19:47 2009 UTC

17use Carp (); 17use Carp ();
18 18
19our $VERSION; 19our $VERSION;
20 20
21BEGIN { 21BEGIN {
22 $VERSION = '2.0'; 22 $VERSION = '2.02';
23 23
24 use XSLoader; 24 use XSLoader;
25 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
26} 26}
27 27
28use utf8; 28use utf8;
29use strict qw(vars subs); 29use strict qw(vars subs);
30 30
31use Socket ();
31use AnyEvent (); 32use AnyEvent ();
33use AnyEvent::Util ();
32use Pod::POM (); 34use Pod::POM ();
33use File::Path (); 35use File::Path ();
34use Storable (); # finally 36use Storable (); # finally
35use Fcntl (); 37use Fcntl ();
36use JSON::XS qw(encode_json decode_json); 38use JSON::XS qw(encode_json decode_json);
67 s/</&lt;/g; 69 s/</&lt;/g;
68 70
69 $_ 71 $_
70} 72}
71 73
72sub socketpipe() {
73 socketpair my $fh1, my $fh2, &Socket::AF_UNIX, &Socket::SOCK_STREAM, &Socket::PF_UNSPEC
74 or die "cannot establish bidirectional pipe: $!\n";
75
76 ($fh1, $fh2)
77}
78
79sub background(&;&) { 74sub background(&;&) {
80 my ($bg, $cb) = @_; 75 my ($bg, $cb) = @_;
81 76
82 my ($fh_r, $fh_w) = DC::socketpipe; 77 my ($fh_r, $fh_w) = AnyEvent::Util::portable_socketpair
78 or die "unable to create background socketpair: $!";
83 79
84 my $pid = fork; 80 my $pid = fork;
85 81
86 if (defined $pid && !$pid) { 82 if (defined $pid && !$pid) {
87 local $SIG{__DIE__}; 83 local $SIG{__DIE__};
199} 195}
200 196
201sub read_cfg { 197sub read_cfg {
202 my ($file) = @_; 198 my ($file) = @_;
203 199
204 $::CFG = load_json $file; 200 $::CFG = (load_json $file) || (load_json "$file.bak");
205} 201}
206 202
207sub write_cfg { 203sub write_cfg {
208 my $file = "$Deliantra::VARDIR/client.cf"; 204 my $file = "$Deliantra::VARDIR/client.cf";
209 205
210 $::CFG->{VERSION} = $::VERSION; 206 $::CFG->{VERSION} = $::VERSION;
207 $::CFG->{layout} = DC::UI::get_layout ();
211 208
212 open my $fh, ">:utf8", $file 209 open my $fh, ">:utf8", "$file~"
213 or return; 210 or return;
214 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); 211 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG);
212 close $fh;
213
214 rename $file, "$file.bak";
215 rename "$file~", $file;
215} 216}
216 217
217sub http_proxy { 218sub http_proxy {
218 my @proxy = win32_proxy_info; 219 my @proxy = win32_proxy_info;
219 220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines