| 1 | ################################################################################### | ||
| 2 | # Distribution Wx::Perl::Packager | ||
| 3 | # File Wx/Perl/Packager/Base.pm | ||
| 4 | # Description: base module for OS specific handlers | ||
| 5 | # File Revision: $Id: Base.pm 48 2010-04-25 00:26:34Z $ | ||
| 6 | # License: This program is free software; you can redistribute it and/or | ||
| 7 | # modify it under the same terms as Perl itself | ||
| 8 | # Copyright: Copyright (c) 2006 - 2010 Mark Dootson | ||
| 9 | ################################################################################### | ||
| 10 | |||
| 11 | package Wx::Perl::Packager::Base; | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use warnings; | ||
| 15 | require Class::Accessor; | ||
| 16 | use base qw( Class::Accessor ); | ||
| 17 | use File::Copy; | ||
| 18 | use Digest::MD5; | ||
| 19 | |||
| 20 | our $VERSION = '0.27'; | ||
| 21 | |||
| 22 | #------------------------------------- | ||
| 23 | # Accessors | ||
| 24 | #------------------------------------- | ||
| 25 | |||
| 26 | __PACKAGE__->follow_best_practice; # I like get/set | ||
| 27 | |||
| 28 | __PACKAGE__->mk_ro_accessors( qw( config debug_on is_mswin is_darwin is_linux path_delim dll_suffix) ); | ||
| 29 | |||
| 30 | __PACKAGE__->mk_accessors( qw( relocate_pdkcheck relocate_packaged | ||
| 31 | loadmode_pdkcheck loadmode_packaged loadcore_pdkcheck loadcore_packaged relocateable core_relocated require_overwrite | ||
| 32 | inner_wx_load_path inner_app_extract_path inner_app_relocate_path packaged runtime pdkautopackaged basemodule | ||
| 33 | modules unload_loaded_core core_loaded so_module_suffix path_separator pdkcheck_exit unload_loaded_plugins | ||
| 34 | unlink_relocated relocate_wx_main pdkcheck_handle | ||
| 35 | )); | ||
| 36 | |||
| 37 | #--------------------------------------- | ||
| 38 | # Constructor with default configuration | ||
| 39 | #--------------------------------------- | ||
| 40 | |||
| 41 | sub new { | ||
| 42 | my $class = shift; | ||
| 43 | my $self = $class->SUPER::new( { | ||
| 44 | debug_on => $Wx::Perl::Packager::_debug_print_on, | ||
| 45 | relocate_pdkcheck => 0, | ||
| 46 | relocate_packaged => 0, | ||
| 47 | relocate_wx_main => 0, | ||
| 48 | loadmode_pdkcheck => 'standard', # standard | nullsub | packload | ||
| 49 | loadmode_packaged => 'packload', | ||
| 50 | loadcore_pdkcheck => 0, | ||
| 51 | loadcore_packaged => 0, | ||
| 52 | unload_loaded_core => 1, | ||
| 53 | unload_loaded_plugins => 1, | ||
| 54 | require_overwrite => 0, | ||
| 55 | runtime => 'PERL', | ||
| 56 | packaged => 0, | ||
| 57 | path_delim => ( $^O =~ /^mswin/i ) ? ';' : ':', | ||
| 58 | dll_suffix => ( $^O =~ /^mswin/i ) ? '.dll' : '.so', | ||
| 59 | relocateable => 0, | ||
| 60 | core_relocated => 0, | ||
| 61 | core_loaded => 0, | ||
| 62 | pdkautopackaged => 0, | ||
| 63 | pdkcheck_exit => 0, | ||
| 64 | pdkcheck_handle => 0, | ||
| 65 | unlink_relocated => 0, | ||
| 66 | path_separator => ( $^O =~ /^mswin/i ) ? "\\" : '/', | ||
| 67 | is_mswin => ( $^O =~ /^mswin/i ) ? 1 : 0, | ||
| 68 | is_linux => ( $^O =~ /^linux$/i ) ? 1 : 0, | ||
| 69 | is_darwin => ( $^O =~ /^darwin$/i ) ? 1 : 0, | ||
| 70 | inner_wx_load_path => ( $Wx::wx_path ) ? $Wx::wx_path : '', | ||
| 71 | inner_app_extract_path => '', | ||
| 72 | inner_app_relocate_path => '', | ||
| 73 | modules => {}, | ||
| 74 | so_module_suffix => '', | ||
| 75 | } | ||
| 76 | ); | ||
| 77 | $self->debug_print('Initial wx_path is : ' . $self->get_wx_load_path); | ||
| 78 | |||
| 79 | return $self; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub cleanup_on_exit { $_[0]->debug_print('Clean up on Exit'); } | ||
| 83 | |||
| 84 | sub post_configure { | ||
| 85 | my $self = shift; | ||
| 86 | my $runtime = $self->get_runtime; | ||
| 87 | if($runtime eq 'PDKCHECK') { | ||
| 88 | exit(0) if $self->get_pdkcheck_exit; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | sub debug_print { | ||
| 93 | return 1 if !$_[0]->get_debug_on; | ||
| 94 | print STDERR 'DEBUG : ' . $_[1] . qq(\n); | ||
| 95 | } | ||
| 96 | |||
| 97 | sub get_core_modules { (qw( base core adv )) } | ||
| 98 | sub is_missing_fatal { ( $_[1] =~ /^(base|core|adv)$/ ) ? 1 : 0; } # not always same list as get_core_modules | ||
| 99 | |||
| 100 | sub configure { | ||
| 101 | my ($self, $requireoverwrite) = @_; | ||
| 102 | |||
| 103 | $self->set_require_overwrite($requireoverwrite); | ||
| 104 | |||
| 105 | $self->config_system(); | ||
| 106 | $self->config_modules(); | ||
| 107 | $self->config_environment(); | ||
| 108 | |||
| 109 | my $runtime = $self->get_runtime; | ||
| 110 | $self->debug_print('preparing Wx for runtime ' . $runtime); | ||
| 111 | |||
| 112 | $self->prepare_perl if $runtime eq 'PERL'; | ||
| 113 | $self->prepare_pdkcheck if $runtime eq 'PDKCHECK'; | ||
| 114 | $self->prepare_perlapp if $runtime eq 'PERLAPP'; | ||
| 115 | $self->prepare_parlexe if $runtime eq 'PARLEXE'; | ||
| 116 | |||
| 117 | $self->debug_print('Runtime ' . $runtime . ' Preparation complete'); | ||
| 118 | |||
| 119 | #---------------------------------------------------- | ||
| 120 | # return here for standard perl before Mini is loaded | ||
| 121 | #---------------------------------------------------- | ||
| 122 | |||
| 123 | return if $runtime eq 'PERL'; | ||
| 124 | |||
| 125 | $self->debug_print('Preparing Load Paths for Wx'); | ||
| 126 | |||
| 127 | $self->prepare_load_paths; | ||
| 128 | |||
| 129 | $self->debug_print('Load Paths Complete'); | ||
| 130 | |||
| 131 | my $requestrelocate; | ||
| 132 | if($runtime eq 'PDKCHECK') { | ||
| 133 | $requestrelocate = $self->get_relocate_pdkcheck; | ||
| 134 | } elsif( $runtime eq 'PERLAPP') { | ||
| 135 | $requestrelocate = $self->get_relocate_packaged; | ||
| 136 | } | ||
| 137 | |||
| 138 | if ($self->get_relocateable && $requestrelocate) { | ||
| 139 | $self->debug_print('Relocating extracted modules for Wx'); | ||
| 140 | $self->relocate_wx; | ||
| 141 | $self->debug_print('Relocation Complete'); | ||
| 142 | } | ||
| 143 | |||
| 144 | $self->debug_print('Preparing and Loading Wx'); | ||
| 145 | |||
| 146 | ################################################################# | ||
| 147 | |||
| 148 | $self->run_wx_start; # THIS LOADS WX | ||
| 149 | |||
| 150 | ################################################################# | ||
| 151 | |||
| 152 | $self->debug_print('Wx Load Complete'); | ||
| 153 | |||
| 154 | $self->before_config_return(); | ||
| 155 | } | ||
| 156 | |||
| 157 | sub config_system { 1; } | ||
| 158 | |||
| 159 | sub config_modules { | ||
| 160 | my $self = shift; | ||
| 161 | |||
| 162 | my $modulesuffix = $self->get_so_module_suffix || ''; # module suffix can be undef | ||
| 163 | |||
| 164 | foreach my $modulekey ( keys (%{ $Wx::dlls })) { | ||
| 165 | if(exists( $Wx::dlls->{$modulekey} ) && $Wx::dlls->{$modulekey}) { | ||
| 166 | |||
| 167 | $self->get_modules->{$modulekey} = | ||
| 168 | { filename => $Wx::dlls->{$modulekey} . $modulesuffix, | ||
| 169 | loaded => 0, | ||
| 170 | libref => undef, | ||
| 171 | missing_fatal => $self->is_missing_fatal($modulekey), | ||
| 172 | }; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | my $basemodule = ( exists($self->get_modules->{base}) ) | ||
| 177 | |||
| 178 | ? $self->get_modules->{base}->{filename} | ||
| 179 | : $self->get_modules->{core}->{filename}; | ||
| 180 | |||
| 181 | $self->set_basemodule($basemodule); | ||
| 182 | } | ||
| 183 | |||
| 184 | sub config_environment { | ||
| 185 | my $self = shift; | ||
| 186 | #------------------------------------------------------------ | ||
| 187 | # determine if we are run as script, PAR, PerlApp | ||
| 188 | #------------------------------------------------------------ | ||
| 189 | if(my $pdkversion = $PerlApp::VERSION) { | ||
| 190 | # PerlApp::VERSION is definitive for PerlApp | ||
| 191 | my @verparts = split(/\./, $pdkversion); | ||
| 192 | $pdkversion = ''; | ||
| 193 | for (@verparts) { | ||
| 194 | $pdkversion .= sprintf("%04d", $_); | ||
| 195 | } | ||
| 196 | $pdkversion =~ s/^0+//; | ||
| 197 | #die q(This version of Wx::Perl::Packager requires PDK version 7.1 or greater) if( $pdkversion < 700010000 ); | ||
| 198 | my $execpath = PerlApp::exe(); | ||
| 199 | |||
| 200 | if($execpath =~ /pdkcheck/) { | ||
| 201 | if($self->get_pdkcheck_handle) { | ||
| 202 | $self->set_runtime('PDKCHECK'); | ||
| 203 | $self->set_packaged(0); | ||
| 204 | } else { | ||
| 205 | $self->set_runtime('PERL'); | ||
| 206 | $self->set_packaged(0); | ||
| 207 | } | ||
| 208 | } else { | ||
| 209 | $self->set_runtime('PERLAPP'); | ||
| 210 | $self->set_packaged(1); | ||
| 211 | } | ||
| 212 | |||
| 213 | } elsif($ENV{PAR_0} && -f($ENV{PAR_0})) { | ||
| 214 | $self->set_runtime('PARLEXE'); | ||
| 215 | $self->set_packaged(1); | ||
| 216 | } else { | ||
| 217 | # we are perl - reiterate defaults | ||
| 218 | $self->set_runtime('PERL'); | ||
| 219 | $self->set_packaged(0); | ||
| 220 | } | ||
| 221 | #------------------------------------------------------------ | ||
| 222 | # set the extract paths and relocate paths | ||
| 223 | #------------------------------------------------------------ | ||
| 224 | |||
| 225 | #------------------------------------ | ||
| 226 | # RUNTIME PERL | ||
| 227 | #------------------------------------ | ||
| 228 | |||
| 229 | if($self->get_runtime() eq 'PERL') { | ||
| 230 | $self->set_relocateable(0); | ||
| 231 | |||
| 232 | #------------------------------------ | ||
| 233 | # RUNTIME PERLAPP & PDKCHECK | ||
| 234 | #------------------------------------ | ||
| 235 | |||
| 236 | } elsif($PerlApp::VERSION) { | ||
| 237 | #-------------------------------- | ||
| 238 | # IS Wx In the PerlApp::RUNLIB | ||
| 239 | #-------------------------------- | ||
| 240 | my $perlappset = 0; | ||
| 241 | my $basemodule = $self->get_basemodule; | ||
| 242 | my $runlib = $PerlApp::RUNLIB; | ||
| 243 | if( $runlib && (-d $PerlApp::RUNLIB )) { | ||
| 244 | my $checkpath = $PerlApp::RUNLIB . '/' . $basemodule; | ||
| 245 | if(-f $checkpath ) { | ||
| 246 | $self->set_pdkautopackaged(0); | ||
| 247 | $self->set_relocateable(0); | ||
| 248 | $self->set_wx_load_path( $checkpath ); | ||
| 249 | $perlappset = 1; | ||
| 250 | |||
| 251 | # final check | ||
| 252 | die qq(Cannot find directory $checkpath) if !-d $checkpath; | ||
| 253 | |||
| 254 | } | ||
| 255 | } | ||
| 256 | #-------------------------------- | ||
| 257 | # Were Wx modules bound manually | ||
| 258 | #-------------------------------- | ||
| 259 | if( !$perlappset ) { | ||
| 260 | my $basefile = PerlApp::extract_bound_file($basemodule); | ||
| 261 | # user packaged | ||
| 262 | if( $basefile ) { | ||
| 263 | if($basefile =~ /^(.*)[\\\/]\Q$basemodule\E$/) { | ||
| 264 | my $regpath = $1; | ||
| 265 | die qq(Cannot find directory $regpath) if !-d $regpath; | ||
| 266 | $self->set_app_extract_path($regpath); | ||
| 267 | $self->set_wx_load_path($regpath); | ||
| 268 | $self->set_relocateable(1); | ||
| 269 | $self->set_pdkautopackaged(0); | ||
| 270 | $perlappset = 1; | ||
| 271 | # final check | ||
| 272 | } | ||
| 273 | #------------------------------------------ | ||
| 274 | # OR Were Wx modules bound by PDK heuristic | ||
| 275 | #------------------------------------------ | ||
| 276 | } else { | ||
| 277 | # perlapp packaged (we hope ) | ||
| 278 | $self->set_pdkautopackaged(1); | ||
| 279 | #------------------------------------------------- | ||
| 280 | # see if user has packaged wxmain.dll | ||
| 281 | #------------------------------------------------- | ||
| 282 | { | ||
| 283 | my $wxmainfile = $self->get_module_filename('wx'); | ||
| 284 | $self->debug_print(qq(Module Mainfile Path is $wxmainfile)); | ||
| 285 | my $dllfile = PerlApp::extract_bound_file($wxmainfile); | ||
| 286 | if($dllfile && -f $dllfile) { | ||
| 287 | $self->debug_print(qq(Module Mainfile FilePath is $dllfile)); | ||
| 288 | if($dllfile =~ /^(.*)[\\\/]\Q$wxmainfile\E$/) { | ||
| 289 | my $regpath = $1; | ||
| 290 | die qq(Cannot find directory $regpath) if !-d $regpath; | ||
| 291 | $self->set_app_extract_path($regpath); | ||
| 292 | $self->set_wx_load_path($regpath); | ||
| 293 | $self->set_relocateable(1); | ||
| 294 | $perlappset = 1; | ||
| 295 | |||
| 296 | } | ||
| 297 | } | ||
| 298 | } | ||
| 299 | if(!$perlappset) { | ||
| 300 | #------------------------------------------------- | ||
| 301 | # user may also set a marker 'wxextractmarker' | ||
| 302 | #------------------------------------------------- | ||
| 303 | my $markerfile = PerlApp::extract_bound_file('wxextractmarker'); | ||
| 304 | if($markerfile && -f $markerfile) { | ||
| 305 | if($markerfile =~ /^(.*)[\\\/]wxextractmarker$/) { | ||
| 306 | my $regpath = $1; | ||
| 307 | die qq(Cannot find directory $regpath) if !-d $regpath; | ||
| 308 | $self->set_app_extract_path($regpath); | ||
| 309 | $self->set_wx_load_path($regpath); | ||
| 310 | $self->set_relocateable(1); | ||
| 311 | $perlappset = 1; | ||
| 312 | } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | if(!$perlappset) { | ||
| 316 | #------------------------------------------------- | ||
| 317 | # No handy marker :-( | ||
| 318 | #------------------------------------------------- | ||
| 319 | # check the first item in the path | ||
| 320 | # if author has placed Wx::Perl::Packager at start of | ||
| 321 | # script, that is where it will be. | ||
| 322 | # we will limit search to one level of | ||
| 323 | # path as unexpected stuff may (will) happen | ||
| 324 | # if we traverse further | ||
| 325 | |||
| 326 | my $delim = $self->get_path_delim(); | ||
| 327 | my @envpaths = split(/$delim/, $ENV{PATH}); | ||
| 328 | my $pdkdirpath = shift @envpaths; | ||
| 329 | $pdkdirpath =~ s/\\/\//g; | ||
| 330 | $pdkdirpath =~ s/\/$//; | ||
| 331 | my $fpath = qq($pdkdirpath/$basemodule); | ||
| 332 | if($fpath && (-f $fpath)) { | ||
| 333 | $self->set_relocateable(1); | ||
| 334 | $perlappset = 1; | ||
| 335 | $self->set_app_extract_path($pdkdirpath); | ||
| 336 | $self->set_wx_load_path($pdkdirpath); | ||
| 337 | } | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | #------------------------------------ | ||
| 342 | # RUNTIME PARLEXE | ||
| 343 | #------------------------------------ | ||
| 344 | |||
| 345 | } elsif($self->get_runtime() eq 'PARLEXE') { | ||
| 346 | $self->set_relocateable(0); | ||
| 347 | # the extract path we get from PAR | ||
| 348 | # could be wxlib + module | ||
| 349 | # or just module | ||
| 350 | my @ldpath = split(/[\\\/]/, $ENV{PAR_0}); | ||
| 351 | pop(@ldpath); | ||
| 352 | my $loadpath = join('/', @ldpath); | ||
| 353 | $self->set_app_extract_path($loadpath); | ||
| 354 | $self->set_wx_load_path($loadpath); | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | sub before_config_return { 1; } | ||
| 359 | |||
| 360 | sub prepare_perl { 1; }; | ||
| 361 | |||
| 362 | sub prepare_pdkcheck { 1;} | ||
| 363 | |||
| 364 | sub prepare_perlapp { | ||
| 365 | require Wx::Perl::Packager::Mini; | ||
| 366 | } | ||
| 367 | |||
| 368 | sub prepare_parlexe { 1;} | ||
| 369 | |||
| 370 | sub prepare_load_paths { | ||
| 371 | my $self = shift; | ||
| 372 | my $loadpath = $self->get_wx_load_path; | ||
| 373 | $self->debug_print(qq(Load Path set $loadpath)); | ||
| 374 | } | ||
| 375 | |||
| 376 | sub relocate_wx { | ||
| 377 | my $self = shift; | ||
| 378 | |||
| 379 | # set the relocate path | ||
| 380 | $self->config_relocate_path; | ||
| 381 | |||
| 382 | my @core = $self->get_core_modules; | ||
| 383 | |||
| 384 | my $targetpath = $self->get_app_relocate_path; | ||
| 385 | $self->debug_print(qq(Relocate Path is $targetpath)); | ||
| 386 | die 'relocate path does not exist' if !-d $targetpath; | ||
| 387 | |||
| 388 | my $sourcepath = $self->get_app_extract_path; | ||
| 389 | $self->debug_print(qq(Extract Path is $sourcepath)); | ||
| 390 | die 'extract path does not exist' if !-d $sourcepath; | ||
| 391 | |||
| 392 | my $forcewrite = $self->get_require_overwrite; | ||
| 393 | |||
| 394 | for my $dllkey ( @core, 'wx' ) { | ||
| 395 | next if !$self->module_exists($dllkey); | ||
| 396 | next if(($dllkey eq 'wx') && (!$self->get_relocate_wx_main)); | ||
| 397 | my $modulefile = $self->get_module_filename($dllkey); | ||
| 398 | my $targetmodulepath = qq($targetpath/$modulefile); | ||
| 399 | my $sourcemodulepath = qq($sourcepath/$modulefile); | ||
| 400 | next if !-f $sourcemodulepath; | ||
| 401 | my $copyrequired = 0; | ||
| 402 | $copyrequired = 1 if !-f $targetmodulepath; | ||
| 403 | $copyrequired = 1 if $forcewrite; | ||
| 404 | if( $copyrequired ) { | ||
| 405 | $self->delete_file($targetmodulepath); | ||
| 406 | $self->copy_file($sourcemodulepath, $targetmodulepath) | ||
| 407 | } | ||
| 408 | $self->delete_file($sourcemodulepath) if $self->get_unlink_relocated; | ||
| 409 | $self->debug_print(qq(Relocated $dllkey)); | ||
| 410 | } | ||
| 411 | |||
| 412 | $self->set_core_relocated(1); | ||
| 413 | |||
| 414 | } | ||
| 415 | |||
| 416 | sub do_core_load { | ||
| 417 | my $self = shift; | ||
| 418 | my $runtime = $self->get_runtime; | ||
| 419 | my $coreload = 0; | ||
| 420 | if($runtime eq 'PDKCHECK') { | ||
| 421 | $coreload = $self->get_loadcore_pdkcheck; | ||
| 422 | |||
| 423 | } elsif ($runtime eq 'PERLAPP') { | ||
| 424 | $coreload = $self->get_loadcore_packaged; | ||
| 425 | |||
| 426 | } elsif ($runtime eq 'PARLEXE') { | ||
| 427 | $coreload = $self->get_loadcore_packaged; | ||
| 428 | |||
| 429 | } | ||
| 430 | |||
| 431 | $self->debug_print(qq(Core Load = $coreload)); | ||
| 432 | |||
| 433 | #-------------------------------------------------------- | ||
| 434 | # Load Core Modules | ||
| 435 | #-------------------------------------------------------- | ||
| 436 | |||
| 437 | require DynaLoader; | ||
| 438 | |||
| 439 | if( $coreload ) { | ||
| 440 | |||
| 441 | for my $dll ( $self->get_core_modules ) { | ||
| 442 | next if !$self->module_exists($dll); | ||
| 443 | my $module = $self->get_modules->{$dll}; | ||
| 444 | my $filepath = $self->get_module_core_load_path($dll); | ||
| 445 | next if( (!-f $filepath) && ( $module->{missing_fatal} == 0) ); | ||
| 446 | $self->debug_print(qq(Loading Core Module $dll from $filepath) ); | ||
| 447 | my $libref = DynaLoader::dl_load_file($filepath, 0) or die qq(Failed to load $filepath); | ||
| 448 | $module->{libref} = $libref; | ||
| 449 | $module->{loaded} = 1; | ||
| 450 | push(@DynaLoader::dl_librefs,$libref) if $libref; | ||
| 451 | } | ||
| 452 | $self->set_core_loaded(1); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | sub run_wx_start { | ||
| 457 | my $self = shift; | ||
| 458 | |||
| 459 | $self->do_core_load; | ||
| 460 | |||
| 461 | my $runtime = $self->get_runtime; | ||
| 462 | my $method = 'standard'; | ||
| 463 | |||
| 464 | if($runtime eq 'PDKCHECK') { | ||
| 465 | |||
| 466 | $method = $self->get_loadmode_pdkcheck; | ||
| 467 | } elsif ($runtime eq 'PERLAPP') { | ||
| 468 | |||
| 469 | $method = $self->get_loadmode_packaged; | ||
| 470 | } elsif ($runtime eq 'PARLEXE') { | ||
| 471 | |||
| 472 | $method = $self->get_loadmode_packaged; | ||
| 473 | } | ||
| 474 | |||
| 475 | $self->debug_print(qq(Load Method = $method)); | ||
| 476 | |||
| 477 | return if(!$method || ($method eq 'standard') ); | ||
| 478 | |||
| 479 | #-------------------------------------------------------- | ||
| 480 | # Set Load / Unload Subs | ||
| 481 | #-------------------------------------------------------- | ||
| 482 | |||
| 483 | my @loadedmodules = (); | ||
| 484 | |||
| 485 | #--------------------------------- | ||
| 486 | # start Wx | ||
| 487 | #--------------------------------- | ||
| 488 | |||
| 489 | require Wx; | ||
| 490 | |||
| 491 | if( $method eq 'packload' ){ | ||
| 492 | Wx::set_load_function( sub { my $modulekey = shift; | ||
| 493 | my $module = $self->get_modules->{$modulekey}; | ||
| 494 | return if !$module; # maybe mono build | ||
| 495 | # don't load twice | ||
| 496 | return if( $module->{loaded} ); | ||
| 497 | |||
| 498 | my $filepath = $self->get_module_wx_load_path($modulekey); | ||
| 499 | $self->debug_print(qq(Loading Plugin $modulekey from $filepath\n)); | ||
| 500 | Wx::_load_plugin( $filepath ); | ||
| 501 | push( @loadedmodules, $filepath); | ||
| 502 | |||
| 503 | $module->{loaded} = 1; | ||
| 504 | |||
| 505 | 1; } ); | ||
| 506 | |||
| 507 | Wx::set_end_function( sub { | ||
| 508 | |||
| 509 | |||
| 510 | if ( $self->get_unload_loaded_plugins ) { | ||
| 511 | while( my $modulefilename = pop @loadedmodules ) { | ||
| 512 | $self->debug_print(qq(Unloading Plugin $modulefilename)); | ||
| 513 | Wx::_unload_plugin( $modulefilename ); | ||
| 514 | } | ||
| 515 | } | ||
| 516 | |||
| 517 | # if we don't specifically unload dl refs, we get a fault on | ||
| 518 | # exit if we close the app immediatley after startup without | ||
| 519 | # interacting with controls (e.g STC) from the keyboard | ||
| 520 | |||
| 521 | # conversely, the rmtree command fails when we DO interact | ||
| 522 | # with controls from the keyboard - which is why we relocate | ||
| 523 | # to a 'permanent' dir for MSWin | ||
| 524 | |||
| 525 | if( ( $self->get_core_loaded ) && ( $self->get_unload_loaded_core ) ) { | ||
| 526 | |||
| 527 | my @core = $self->get_core_modules; | ||
| 528 | |||
| 529 | while(my $dll = pop(@core) ) { | ||
| 530 | my $libref = $self->get_modules->{$dll}->{libref}; | ||
| 531 | if ($libref) { | ||
| 532 | $self->debug_print( qq(Unloading Core Module $dll) ); | ||
| 533 | DynaLoader::dl_unload_file($libref); | ||
| 534 | } | ||
| 535 | } | ||
| 536 | } | ||
| 537 | |||
| 538 | 1; } ); | ||
| 539 | |||
| 540 | } elsif( $method eq 'nullsub' ){ | ||
| 541 | |||
| 542 | Wx::set_load_function( sub { 1; } ); | ||
| 543 | Wx::set_end_function ( sub { 1; } ); | ||
| 544 | } | ||
| 545 | } | ||
| 546 | |||
| 547 | sub delete_file { | ||
| 548 | my( $self, $target) = @_; | ||
| 549 | return if !-f $target; | ||
| 550 | chmod 0700, $target; | ||
| 551 | unlink $target; | ||
| 552 | } | ||
| 553 | |||
| 554 | sub copy_file { | ||
| 555 | my( $self, $source, $target) = @_; | ||
| 556 | File::Copy::copy($source, $target); | ||
| 557 | } | ||
| 558 | |||
| 559 | sub move_file { | ||
| 560 | my( $self, $source, $target) = @_; | ||
| 561 | File::Copy::move($source, $target); | ||
| 562 | } | ||
| 563 | |||
| 564 | sub compare_paths { | ||
| 565 | my($self, $one, $two) = @_; | ||
| 566 | $one =~ s/\\/\//g; | ||
| 567 | $two =~ s/\\/\//g; | ||
| 568 | return ( $one eq $two ); | ||
| 569 | } | ||
| 570 | |||
| 571 | |||
| 572 | #------------------------------ | ||
| 573 | # Overloads for paths | ||
| 574 | #------------------------------ | ||
| 575 | |||
| 576 | sub set_app_extract_path { $_[0]->set_inner_app_extract_path( $_[0]->setsys_filepath($_[1]) ); } | ||
| 577 | sub get_app_extract_path { $_[0]->get_inner_app_extract_path; } | ||
| 578 | |||
| 579 | sub set_app_relocate_path { $_[0]->set_inner_app_relocate_path( $_[0]->setsys_filepath($_[1]) ); } | ||
| 580 | sub get_app_relocate_path { $_[0]->get_inner_app_relocate_path; } | ||
| 581 | |||
| 582 | sub set_wx_load_path { $_[0]->set_inner_wx_load_path( $_[0]->setsys_filepath($_[1]) ); } | ||
| 583 | sub get_wx_load_path { $_[0]->get_inner_wx_load_path; } | ||
| 584 | |||
| 585 | sub module_exists { exists($_[0]->get_modules->{$_[1]} ); } | ||
| 586 | |||
| 587 | sub get_module_filename { $_[0]->module_exists($_[1]) ? $_[0]->get_modules->{$_[1]}->{filename} : undef; } | ||
| 588 | |||
| 589 | sub get_module_wx_load_path { | ||
| 590 | if(my $filename = $_[0]->get_module_filename($_[1])) { | ||
| 591 | my $wxpath = $_[0]->get_wx_load_path(); | ||
| 592 | |||
| 593 | return ( $wxpath ) ? $wxpath . $_[0]->get_path_separator . $filename : $filename; | ||
| 594 | } else { | ||
| 595 | return undef; | ||
| 596 | } | ||
| 597 | } | ||
| 598 | |||
| 599 | sub get_module_app_relocate_path { | ||
| 600 | if(my $filename = $_[0]->get_module_filename($_[1])) { | ||
| 601 | my $dirpath = $_[0]->get_app_relocate_path(); | ||
| 602 | |||
| 603 | return $dirpath . $_[0]->get_path_separator . $filename; | ||
| 604 | } else { | ||
| 605 | return undef; | ||
| 606 | } | ||
| 607 | } | ||
| 608 | |||
| 609 | sub get_module_app_extract_path { | ||
| 610 | if(my $filename = $_[0]->get_module_filename($_[1])) { | ||
| 611 | my $dirpath = $_[0]->get_app_extract_path(); | ||
| 612 | |||
| 613 | return $dirpath . $_[0]->get_path_separator . $filename; | ||
| 614 | } else { | ||
| 615 | return undef; | ||
| 616 | } | ||
| 617 | } | ||
| 618 | |||
| 619 | sub get_module_core_load_path { | ||
| 620 | if(my $filename = $_[0]->get_module_filename($_[1])) { | ||
| 621 | my $dirpath = ( $_[0]->get_core_relocated ) | ||
| 622 | ? $_[0]->get_app_relocate_path | ||
| 623 | : $_[0]->get_wx_load_path; | ||
| 624 | my $sep = ( $_[0]->get_is_mswin ) ? "\\" : '/'; | ||
| 625 | |||
| 626 | return ( $dirpath ) ? $dirpath . $sep . $filename : $filename; | ||
| 627 | } else { | ||
| 628 | return undef; | ||
| 629 | } | ||
| 630 | } | ||
| 631 | |||
| 632 | sub setsys_filepath { | ||
| 633 | my($self, $filepath) = @_; | ||
| 634 | $filepath =~ s/\\/\//g; | ||
| 635 | return $filepath; | ||
| 636 | } | ||
| 637 | |||
| 638 | |||
| 639 | #------------------------------------------ | ||
| 640 | # If we have no alternative but to relocate | ||
| 641 | # wx dlls ........ | ||
| 642 | #------------------------------------------ | ||
| 643 | |||
| 644 | sub config_relocate_path { | ||
| 645 | my $self = shift; | ||
| 646 | return if !$self->get_relocateable(); # just in case | ||
| 647 | |||
| 648 | # app extract path is writable by us - so create our wxlib extract | ||
| 649 | # files side by side | ||
| 650 | |||
| 651 | my $appextractpath = $self->get_app_extract_path(); | ||
| 652 | die qq(error in determining extract paths) if !-d $appextractpath; | ||
| 653 | |||
| 654 | # determine where the standard PDK path is | ||
| 655 | |||
| 656 | # get a unique extract directory for this application build | ||
| 657 | my $runtime = $self->get_runtime(); | ||
| 658 | my $uid = getlogin || (getpwuid($<))[0]; | ||
| 659 | my $toplevel = 'wxppl-' . $uid; | ||
| 660 | $toplevel =~ s/[^A-Za-z0-9\-_]/_/g; | ||
| 661 | |||
| 662 | my $apprelocatedir; | ||
| 663 | |||
| 664 | if($runtime eq 'PERLAPP') { | ||
| 665 | # get a unique dir for this build in this location | ||
| 666 | my $ctx = Digest::MD5->new; | ||
| 667 | my $exec = PerlApp::exe(); | ||
| 668 | $ctx->add( $exec ); | ||
| 669 | my $basestatfile = $appextractpath . '/' . $self->get_basemodule(); | ||
| 670 | $self->debug_print(qq(Base Core extracted module = $basestatfile)); | ||
| 671 | my $filestat = (-f $basestatfile ) ? (stat($basestatfile))[7]: 'fixed data'; | ||
| 672 | $ctx->add( $filestat ); | ||
| 673 | |||
| 674 | if($self->get_relocate_wx_main) { | ||
| 675 | # we also relocate wxmain - which means we have to add that to uniqueness | ||
| 676 | if( my $wxmain = $self->get_module_filename('wx') ) { | ||
| 677 | my $mainstatfile = $appextractpath . '/' . $wxmain; | ||
| 678 | $self->debug_print(qq(Wx Main extracted module = $mainstatfile)); | ||
| 679 | my $mainfilestat = (-f $mainstatfile ) ? (stat($mainstatfile))[7]: 'wxmain data'; | ||
| 680 | $ctx->add( $mainfilestat ); | ||
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 | $apprelocatedir = $ctx->hexdigest; | ||
| 685 | |||
| 686 | } elsif( $runtime eq 'PDKCHECK' ) { | ||
| 687 | # we keep the same dir and overwrite | ||
| 688 | $apprelocatedir = 'PDKCHECKBUILDING'; | ||
| 689 | } | ||
| 690 | |||
| 691 | # build the directories | ||
| 692 | my @paths = split(/[\/\\]/, $appextractpath); | ||
| 693 | pop(@paths); | ||
| 694 | my $apprunpath = join('/', (@paths, $toplevel)); | ||
| 695 | mkdir($apprunpath, 0700) if !-d $apprunpath; | ||
| 696 | $apprunpath .= '/' . $apprelocatedir; | ||
| 697 | mkdir($apprunpath, 0700) if !-d $apprunpath; | ||
| 698 | |||
| 699 | $self->set_app_relocate_path($apprunpath); | ||
| 700 | } | ||
| 701 | |||
| 702 | 1; |