… | |
… | |
17 | use Carp (); |
17 | use Carp (); |
18 | |
18 | |
19 | our $VERSION; |
19 | our $VERSION; |
20 | |
20 | |
21 | BEGIN { |
21 | BEGIN { |
22 | $VERSION = '2.02'; |
22 | $VERSION = '3.0'; |
23 | |
23 | |
24 | use XSLoader; |
24 | use XSLoader; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
25 | XSLoader::load "Deliantra::Client", $VERSION; |
26 | } |
26 | } |
27 | |
27 | |
… | |
… | |
34 | use Pod::POM (); |
34 | use Pod::POM (); |
35 | use File::Path (); |
35 | use File::Path (); |
36 | use Storable (); # finally |
36 | use Storable (); # finally |
37 | use Fcntl (); |
37 | use Fcntl (); |
38 | use JSON::XS qw(encode_json decode_json); |
38 | use JSON::XS qw(encode_json decode_json); |
|
|
39 | use Guard qw(guard); |
39 | |
40 | |
40 | =item guard { BLOCK } |
41 | # modules to support other DC::* packages |
41 | |
42 | use List::Util (); |
42 | Returns an object that executes the given block as soon as it is destroyed. |
43 | use IO::AIO (); |
43 | |
44 | use Coro::AIO (); |
44 | =cut |
45 | use AnyEvent::AIO (); |
45 | |
|
|
46 | sub guard(&) { |
|
|
47 | bless \(my $cb = $_[0]), "DC::Guard" |
|
|
48 | } |
|
|
49 | |
|
|
50 | sub DC::Guard::DESTROY { |
|
|
51 | ${$_[0]}->() |
|
|
52 | } |
|
|
53 | |
46 | |
54 | =item shorten $string[, $maxlength] |
47 | =item shorten $string[, $maxlength] |
55 | |
48 | |
56 | =cut |
49 | =cut |
57 | |
50 | |
… | |
… | |
154 | sub find_rcfile($) { |
147 | sub find_rcfile($) { |
155 | my $path; |
148 | my $path; |
156 | |
149 | |
157 | for (@RC_PATH, "") { |
150 | for (@RC_PATH, "") { |
158 | $path = "$RC_BASE/$_/$_[0]"; |
151 | $path = "$RC_BASE/$_/$_[0]"; |
159 | return $path if -r $path; |
152 | return $path if -e $path; |
160 | } |
153 | } |
161 | |
154 | |
162 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
155 | die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; |
163 | } |
156 | } |
164 | |
157 | |
… | |
… | |
167 | |
160 | |
168 | open my $fh, $file |
161 | open my $fh, $file |
169 | or return; |
162 | or return; |
170 | |
163 | |
171 | local $/; |
164 | local $/; |
172 | JSON::XS->new->utf8->relaxed->decode (<$fh>) |
165 | eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) } |
173 | } |
166 | } |
174 | |
167 | |
175 | sub set_theme($) { |
168 | sub set_theme($) { |
176 | return if $RC_THEME eq $_[0]; |
169 | return if $RC_THEME eq $_[0]; |
177 | $RC_THEME = $_[0]; |
170 | $RC_THEME = $_[0]; |
… | |
… | |
195 | } |
188 | } |
196 | |
189 | |
197 | sub read_cfg { |
190 | sub read_cfg { |
198 | my ($file) = @_; |
191 | my ($file) = @_; |
199 | |
192 | |
200 | $::CFG = load_json $file; |
193 | $::CFG = (load_json $file) || (load_json "$file.bak"); |
201 | } |
194 | } |
202 | |
195 | |
203 | sub write_cfg { |
196 | sub write_cfg { |
204 | my $file = "$Deliantra::VARDIR/client.cf"; |
197 | my $file = "$Deliantra::VARDIR/client.cf"; |
205 | |
198 | |
206 | $::CFG->{VERSION} = $::VERSION; |
199 | $::CFG->{VERSION} = $::VERSION; |
|
|
200 | $::CFG->{layout} = DC::UI::get_layout (); |
207 | |
201 | |
208 | open my $fh, ">:utf8", $file |
202 | open my $fh, ">:utf8", "$file~" |
209 | or return; |
203 | or return; |
210 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
204 | print $fh JSON::XS->new->utf8->pretty->encode ($::CFG); |
|
|
205 | close $fh; |
|
|
206 | |
|
|
207 | rename $file, "$file.bak"; |
|
|
208 | rename "$file~", $file; |
211 | } |
209 | } |
212 | |
210 | |
213 | sub http_proxy { |
211 | sub http_proxy { |
214 | my @proxy = win32_proxy_info; |
212 | my @proxy = win32_proxy_info; |
215 | |
213 | |