1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | ############################################################################# |
3 | ############################################################################# |
4 | # if running under PAR, see if we have an updated version on disk, then use that |
|
|
5 | |
|
|
6 | # this code does more or less the same as the one in Deliantra.pm |
|
|
7 | |
|
|
8 | our $PAR; # true if running under PAR |
|
|
9 | our $EXE_ID; # identifies this binary "branch" (usually the name of the person who builds + os + some unique id per perl binary build) |
|
|
10 | our $EXE_VER; # the (string) version of this binary payload |
|
|
11 | our $VARDIR; |
|
|
12 | our $UPDDIR; |
|
|
13 | our $UPDPAR; |
|
|
14 | our %ORIG_INC; |
|
|
15 | |
|
|
16 | if (!$UPDDIR && %PAR::LibCache && require "par-info.pl") { |
|
|
17 | # must set EXE_ID and EXE_VER |
|
|
18 | $PAR = 1; |
|
|
19 | |
|
|
20 | $VARDIR = $ENV{HOME} ? "$ENV{HOME}/.deliantra" |
|
|
21 | : $ENV{AppData} ? "$ENV{APPDATA}/deliantra" |
|
|
22 | : do { require File::Spec; File::Spec->tmpdir . "/deliantra" }; |
|
|
23 | |
|
|
24 | $UPDDIR = "$VARDIR/upd-$EXE_ID"; |
|
|
25 | mkdir $UPDDIR; |
|
|
26 | if (opendir my $fh, $UPDDIR) { |
|
|
27 | my @files = sort grep /\.par$/, readdir $fh; |
|
|
28 | $UPDPAR = pop @files; # highest version == newest |
|
|
29 | |
|
|
30 | # try to unlink all older versions |
|
|
31 | unlink "$UPDDIR/$_" |
|
|
32 | for @files; |
|
|
33 | |
|
|
34 | # override exe par with downloaded par |
|
|
35 | %ORIG_INC = %INC; |
|
|
36 | # par apparently has no way of overriding, so we try to clear its state |
|
|
37 | @PAR::LibCache = (); |
|
|
38 | %PAR::LibCache = (); |
|
|
39 | PAR->import ("$UPDDIR/$UPDPAR"); |
|
|
40 | |
|
|
41 | # now we try to re-exec "script/deliantra" |
|
|
42 | if (my $member = eval { $zip->memberNamed ('script/deliantra') }) { |
|
|
43 | return PAR::_run_member ($member); |
|
|
44 | } |
|
|
45 | } |
|
|
46 | } |
|
|
47 | |
|
|
48 | |
|
|
49 | ############################################################################# |
|
|
50 | # splash-screen |
|
|
51 | |
|
|
52 | our @STARTUP_DONE; |
|
|
53 | |
|
|
54 | if ($PAR && $^O eq "MSWin32") { |
|
|
55 | while (my ($filename, $zip) = each %PAR::LibCache) { |
|
|
56 | $zip->extractMember ("SPLASH.bmp", "$ENV{PAR_TEMP}/SPLASH.bmp"); |
|
|
57 | } |
|
|
58 | |
|
|
59 | require Win32::GUI::SplashScreen; |
|
|
60 | |
|
|
61 | Win32::GUI::SplashScreen::Show ( |
|
|
62 | -file => "$ENV{PAR_TEMP}/SPLASH.bmp", |
|
|
63 | ); |
|
|
64 | |
|
|
65 | push @STARTUP_DONE, sub { |
|
|
66 | Win32::GUI::SplashScreen::Done (1); |
|
|
67 | }; |
|
|
68 | } |
|
|
69 | |
|
|
70 | ############################################################################# |
|
|
71 | # work around various deficiencies and bugs in PAR |
|
|
72 | |
|
|
73 | # do things only needed for single-binary version (par) |
|
|
74 | if ($PAR) { |
|
|
75 | @INC = grep ref, @INC; # weed out all paths except PAR's loader refs |
|
|
76 | # alternatively: @INC = (); PAR->import; |
|
|
77 | |
|
|
78 | my $root = $ENV{PAR_TEMP}; |
|
|
79 | |
|
|
80 | while (my ($filename, $zip) = each %PAR::LibCache) { |
|
|
81 | for ($zip->memberNames) { |
|
|
82 | next unless /^root\/(.*)/; |
|
|
83 | $zip->extractMember ($_, "$root/$1") |
|
|
84 | unless -e "$root/$1"; |
|
|
85 | } |
|
|
86 | } |
|
|
87 | |
|
|
88 | if ($^O eq "MSWin32") { |
|
|
89 | # pango is relocatable on win32 |
|
|
90 | } else { |
|
|
91 | # OS X |
|
|
92 | $ENV{PANGO_RC_FILE} = "$root/pango.rc"; |
|
|
93 | $ENV{DYLD_LIBRARY_PATH} = $root; |
|
|
94 | chdir $root; # for pango modules, maybe other things |
|
|
95 | } |
|
|
96 | |
|
|
97 | unshift @INC, $root; |
|
|
98 | } |
|
|
99 | |
|
|
100 | # prepend private library directory and prepare env |
4 | # prepend private library directory |
101 | for (grep !ref, @INC) { |
5 | for (grep !ref, @INC) { |
102 | my $path = "$_/Deliantra/Client/private"; |
6 | my $path = "$_/Deliantra/Client/private"; |
103 | if (-d $path) { |
7 | if (-d $path) { |
104 | unshift @INC, $path; |
8 | unshift @INC, $path; |
105 | last; |
9 | last; |
… | |
… | |
109 | ############################################################################# |
13 | ############################################################################# |
110 | # load and run the main program |
14 | # load and run the main program |
111 | |
15 | |
112 | require DC::Main; |
16 | require DC::Main; |
113 | |
17 | |
114 | # need to do it again because that pile of garbage called PAR nukes it before main |
18 | DC::Main::run (); |
115 | unshift @INC, $ENV{PAR_TEMP} |
|
|
116 | if $PAR; |
|
|
117 | |
19 | |
118 | DC::Main::run (); |
20 | 1; # this file is require'd in the binary client package |
119 | |
21 | |
120 | =head1 NAME |
22 | =head1 NAME |
121 | |
23 | |
122 | deliantra - A Deliantra MORPG game client |
24 | deliantra - A Deliantra MORPG game client |
123 | |
25 | |