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

Comparing deliantra/Deliantra-Client/DC/Util.pm (file contents):
Revision 1.9 by elmex, Fri Apr 7 19:58:55 2006 UTC vs.
Revision 1.10 by root, Fri Apr 7 20:13:13 2006 UTC

1package Crossfire::Client::Util; 1package Crossfire::Client::Util;
2
2use strict; 3use strict;
3use base 'Exporter'; 4
4use Data::Dumper; 5use Data::Dumper;
5our @EXPORT = qw(find_rcfile read_cfg write_cfg); 6
6use SDL; 7use SDL;
7use SDL::App;
8use SDL::Event;
9use SDL::Surface;
10
11use Gtk2; 8use Gtk2;
12
13sub find_rcfile($) {
14 my $path;
15
16 for (@INC) {
17 $path = "$_/Crossfire/resources/$_[0]";
18 return $path if -r $path;
19 }
20
21 die "FATAL: can't find required file $_[0]\n";
22}
23
24sub read_cfg {
25 my ($file) = @_;
26
27 open CFG, $file
28 or return;
29
30 my $CFG;
31
32 local $/;
33 $CFG = eval <CFG>;
34
35 $::CFG = $CFG;
36
37 close CFG;
38}
39
40sub write_cfg {
41 my ($file) = @_;
42
43 open CFG, ">$file"
44 or return;
45
46 {
47 local $Data::Dumper::Purity = 1;
48 $::CFG->{VERSION} = $::VERSION;
49 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]);
50 }
51
52 close CFG;
53}
54
55 9
56sub gtk_add_cfg_field { 10sub gtk_add_cfg_field {
57 my ($tbl, $cfg, $klbl, $key, $value) = @_; 11 my ($tbl, $cfg, $klbl, $key, $value) = @_;
58 my $i = $cfg->{_i}++; 12 my $i = $cfg->{_i}++;
59 $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); 13 $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1);
118 $cb->signal_connect (clicked => sub { 72 $cb->signal_connect (clicked => sub {
119 for (keys %$cfg) { 73 for (keys %$cfg) {
120 $::CFG->{$_} = $cfg->{$_} 74 $::CFG->{$_} = $cfg->{$_}
121 if $_ ne '_i'; 75 if $_ ne '_i';
122 } 76 }
123 write_cfg "$Crossfire::VARDIR/pclientrc"; 77 Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc";
124 }); 78 });
125 $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); 79 $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5);
126 $cb->signal_connect (clicked => sub { 80 $cb->signal_connect (clicked => sub {
127 for (keys %$cfg) { 81 for (keys %$cfg) {
128 $::CFG->{$_} = $cfg->{$_} 82 $::CFG->{$_} = $cfg->{$_}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines