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.191 by root, Wed Sep 3 06:07:39 2008 UTC vs.
Revision 1.201 by root, Sun Jan 11 03:19:47 2009 UTC

10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package Deliantra::Client; # work around CPAN breakage
16package App::Deliantra; # try to reserve namespace
17package DC; 15package DC;
18 16
19use Carp (); 17use Carp ();
20 18
21our $VERSION; 19our $VERSION;
22 20
23BEGIN { 21BEGIN {
24 $VERSION = '0.9975'; 22 $VERSION = '2.02';
25 23
26 use XSLoader; 24 use XSLoader;
27 XSLoader::load "Deliantra::Client", $VERSION; 25 XSLoader::load "Deliantra::Client", $VERSION;
28} 26}
29 27
30use utf8; 28use utf8;
31use strict qw(vars subs); 29use strict qw(vars subs);
32 30
31use Socket ();
33use AnyEvent (); 32use AnyEvent ();
33use AnyEvent::Util ();
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);
69 s/</&lt;/g; 69 s/</&lt;/g;
70 70
71 $_ 71 $_
72} 72}
73 73
74sub socketpipe() {
75 socketpair my $fh1, my $fh2, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC
76 or die "cannot establish bidirectional pipe: $!\n";
77
78 ($fh1, $fh2)
79}
80
81sub background(&;&) { 74sub background(&;&) {
82 my ($bg, $cb) = @_; 75 my ($bg, $cb) = @_;
83 76
84 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: $!";
85 79
86 my $pid = fork; 80 my $pid = fork;
87 81
88 if (defined $pid && !$pid) { 82 if (defined $pid && !$pid) {
89 local $SIG{__DIE__}; 83 local $SIG{__DIE__};
146} 140}
147 141
148package DC; 142package DC;
149 143
150our $RC_THEME; 144our $RC_THEME;
151our $THEME; 145our %THEME;
152our @RC_PATH; 146our @RC_PATH;
153our $RC_BASE; 147our $RC_BASE;
154 148
155for (grep !ref, @INC) { 149for (grep !ref, @INC) {
156 $RC_BASE = "$_/Deliantra/Client/private/resources"; 150 $RC_BASE = "$_/Deliantra/Client/private/resources";
166 } 160 }
167 161
168 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; 162 die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n";
169} 163}
170 164
165sub load_json($) {
166 my ($file) = @_;
167
168 open my $fh, $file
169 or return;
170
171 local $/;
172 JSON::XS->new->utf8->relaxed->decode (<$fh>)
173}
174
171sub set_theme($) { 175sub set_theme($) {
172 return if $RC_THEME eq $_[0]; 176 return if $RC_THEME eq $_[0];
173 $RC_THEME = $_[0]; 177 $RC_THEME = $_[0];
174 178
179 # kind of hacky, find the main theme file, then load all theme files and merge them
180
181 %THEME = ();
175 @RC_PATH = "theme-$RC_THEME"; 182 @RC_PATH = "theme-$RC_THEME";
176 183
177 { 184 my $theme = load_json find_rcfile "theme.json"
178 open my $fh, "<:raw", find_rcfile "theme.json" 185 or die "FATAL: theme resource file not found";
179 or die "cannot open theme description file";
180 186
181 local $/;
182 $THEME = JSON::XS->new->utf8->relaxed->decode (<$fh>);
183 }
184
185 @RC_PATH = @{ $THEME->{path} } if $THEME->{path}; 187 @RC_PATH = @{ $theme->{path} } if $theme->{path};
188
189 for (@RC_PATH, "") {
190 my $theme = load_json "$RC_BASE/$_/theme.json"
191 or next;
192
193 %THEME = ( %$theme, %THEME );
194 }
186} 195}
187 196
188sub read_cfg { 197sub read_cfg {
189 my ($file) = @_; 198 my ($file) = @_;
190 199
191 open my $fh, $file 200 $::CFG = (load_json $file) || (load_json "$file.bak");
192 or return;
193
194 local $/;
195 my $CFG = <$fh>;
196
197 $::CFG = decode_json $CFG;
198} 201}
199 202
200sub write_cfg { 203sub write_cfg {
201 my $file = "$Deliantra::VARDIR/client.cf"; 204 my $file = "$Deliantra::VARDIR/client.cf";
202 205
203 $::CFG->{VERSION} = $::VERSION; 206 $::CFG->{VERSION} = $::VERSION;
207 $::CFG->{layout} = DC::UI::get_layout ();
204 208
205 open my $fh, ">:utf8", $file 209 open my $fh, ">:utf8", "$file~"
206 or return; 210 or return;
207 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;
208} 216}
209 217
210sub http_proxy { 218sub http_proxy {
211 my @proxy = win32_proxy_info; 219 my @proxy = win32_proxy_info;
212 220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines