--- deliantra/Deliantra-Client/DC.pm 2006/12/06 00:04:13 1.132 +++ deliantra/Deliantra-Client/DC.pm 2006/12/07 15:57:13 1.135 @@ -29,6 +29,7 @@ use BerkeleyDB; use Pod::POM (); use Scalar::Util (); +use File::Path (); use Storable (); # finally BEGIN { @@ -51,6 +52,16 @@ ${$_[0]}->() } +=item shorten $string[, $maxlength] + +=cut + +sub shorten($;$) { + my ($str, $len) = @_; + substr $str, $len, (length $str), "..." if $len + 3 <= length $str; + $str +} + sub asxml($) { local $_ = $_[0]; @@ -264,27 +275,34 @@ or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" } -{ - use strict; +our $DB_HOME = "$Crossfire::VARDIR/cfplus"; - my $HOME = "$Crossfire::VARDIR/cfplus-$BerkeleyDB::db_version"; +sub open_db { + use strict; - mkdir $HOME, 0777; + mkdir $DB_HOME, 0777; my $recover = $BerkeleyDB::db_version >= 4.4 ? eval "DB_REGISTER | DB_RECOVER" : 0; $DB_ENV = new BerkeleyDB::Env - -Home => $HOME, + -Home => $DB_HOME, -Cachesize => 1_000_000, - -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", + -ErrFile => "$DB_HOME/errorlog.txt", # -ErrPrefix => "DATABASE", -Verbose => 1, -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, - or die "unable to create/open database home $HOME: $BerkeleyDB::Error"; + or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error"; $DB_STATE = db_table "state"; + + 1 +} + +unless (eval { open_db }) { + File::Path::rmtree $DB_HOME; + open_db; } package CFPlus::Layout; @@ -393,6 +411,8 @@ $move_prefix = "take"; } + my $shortname = CFPlus::shorten $self->{name}, 14; + my @menu_items = ( ["examine", sub { $::CONN->send ("examine $self->{tag}") }], ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], @@ -437,7 +457,7 @@ ] ) ), - ["bind apply $self->{name} to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }], + ["bind apply $shortname to a key" => sub { $::BIND_EDITOR->do_quick_binding (["apply $self->{name}"]) }], ); CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);