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.200 by root, Sun Jan 4 10:22:19 2009 UTC vs.
Revision 1.202 by root, Sun Jan 11 22:11:23 2009 UTC

34use Pod::POM (); 34use Pod::POM ();
35use File::Path (); 35use File::Path ();
36use Storable (); # finally 36use Storable (); # finally
37use Fcntl (); 37use Fcntl ();
38use JSON::XS qw(encode_json decode_json); 38use JSON::XS qw(encode_json decode_json);
39 39use Guard qw(guard);
40=item guard { BLOCK }
41
42Returns an object that executes the given block as soon as it is destroyed.
43
44=cut
45
46sub guard(&) {
47 bless \(my $cb = $_[0]), "DC::Guard"
48}
49
50sub DC::Guard::DESTROY {
51 ${$_[0]}->()
52}
53 40
54=item shorten $string[, $maxlength] 41=item shorten $string[, $maxlength]
55 42
56=cut 43=cut
57 44
195} 182}
196 183
197sub read_cfg { 184sub read_cfg {
198 my ($file) = @_; 185 my ($file) = @_;
199 186
200 $::CFG = load_json $file; 187 $::CFG = (load_json $file) || (load_json "$file.bak");
201} 188}
202 189
203sub write_cfg { 190sub write_cfg {
204 my $file = "$Deliantra::VARDIR/client.cf"; 191 my $file = "$Deliantra::VARDIR/client.cf";
205 192
206 $::CFG->{VERSION} = $::VERSION; 193 $::CFG->{VERSION} = $::VERSION;
194 $::CFG->{layout} = DC::UI::get_layout ();
207 195
208 open my $fh, ">:utf8", $file 196 open my $fh, ">:utf8", "$file~"
209 or return; 197 or return;
210 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); 198 print $fh JSON::XS->new->utf8->pretty->encode ($::CFG);
199 close $fh;
200
201 rename $file, "$file.bak";
202 rename "$file~", $file;
211} 203}
212 204
213sub http_proxy { 205sub http_proxy {
214 my @proxy = win32_proxy_info; 206 my @proxy = win32_proxy_info;
215 207

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines