--- deliantra/Deliantra-Client/DC.pm 2009/01/11 22:11:23 1.202 +++ deliantra/Deliantra-Client/DC.pm 2012/01/18 13:42:19 1.215 @@ -19,7 +19,7 @@ our $VERSION; BEGIN { - $VERSION = '2.02'; + $VERSION = '3.0'; use XSLoader; XSLoader::load "Deliantra::Client", $VERSION; @@ -38,6 +38,14 @@ use JSON::XS qw(encode_json decode_json); use Guard qw(guard); +# modules to support other DC::* packages +use List::Util (); +use IO::AIO (); +use Coro::AIO (); +use AnyEvent::AIO (); + +use Deliantra::Protocol::Constants (); + =item shorten $string[, $maxlength] =cut @@ -143,7 +151,7 @@ for (@RC_PATH, "") { $path = "$RC_BASE/$_/$_[0]"; - return $path if -r $path; + return $path if -e $path; } die "FATAL: can't find required file \"$_[0]\" in \"$RC_BASE\"\n"; @@ -156,7 +164,7 @@ or return; local $/; - JSON::XS->new->utf8->relaxed->decode (<$fh>) + eval { JSON::XS->new->utf8->relaxed->decode (<$fh>) } } sub set_theme($) { @@ -181,13 +189,13 @@ } } -sub read_cfg { +sub read_cfg($) { my ($file) = @_; $::CFG = (load_json $file) || (load_json "$file.bak"); } -sub write_cfg { +sub write_cfg($) { my $file = "$Deliantra::VARDIR/client.cf"; $::CFG->{VERSION} = $::VERSION; @@ -202,6 +210,69 @@ rename "$file~", $file; } +sub load_cfg() { + if (-e "$Deliantra::VARDIR/client.cf") { + DC::read_cfg "$Deliantra::VARDIR/client.cf"; + } else { + $::CFG = {}; + } +} + +sub save_cfg() { + write_cfg "$Deliantra::VARDIR/client.cf"; +} + +sub upgrade_cfg() { + my %DEF_CFG = ( + config_autosave => 1, + sdl_mode => undef, + fullscreen => 1, + fast => 0, + force_opengl11 => undef, + disable_alpha => 0, + smooth_movement => 1, + smooth_transitions => 1, + texture_compression => 1, + map_scale => 1, + fow_enable => 1, + fow_intensity => 0, + fow_texture => 0, + map_smoothing => 1, + gui_fontsize => 1, + log_fontsize => 0.7, + gauge_fontsize => 1, + gauge_size => 0.35, + stat_fontsize => 0.7, + mapsize => 100, + audio_enable => 1, + audio_hw_channels => 0, + audio_hw_frequency => 0, + audio_hw_chunksize => 0, + audio_mix_channels => 8, + effects_enable => 1, + effects_volume => 1, + bgm_enable => 1, + bgm_volume => 0.5, + output_rate => "", + pickup => Deliantra::Protocol::Constants::PICKUP_SPELLBOOK + | Deliantra::Protocol::Constants::PICKUP_SKILLSCROLL + | Deliantra::Protocol::Constants::PICKUP_VALUABLES, + inv_sort => "mtime", + default => "profile", # default profile + show_tips => 1, + logview_max_par => 1000, + shift_fire_stop => 0, + uitheme => "wood", + map_shift_x => -24, # arbitrary + map_shift_y => +24, # arbitrary + #db_schema => 0, + ); + + while (my ($k, $v) = each %DEF_CFG) { + $::CFG->{$k} = $v unless exists $::CFG->{$k}; + } +} + sub http_proxy { my @proxy = win32_proxy_info;