1%#!/usr/bin/swipl 
    2
    3:- module(logicmoo_packages,[ rescan_pack_autoload_packages/0]).    4
    5%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    6% PACK LOADER
    7%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    8:- use_module(library(prolog_pack)).    9:- if( \+ prolog_pack:current_pack(logicmoo_base)).   10:- multifile(user:file_search_path/2).   11:-   dynamic(user:file_search_path/2).   12:- prolog_load_context(directory,Dir),
   13   absolute_file_name('../../',Y,[relative_to(Dir),file_type(directory)]),
   14   (( \+ user:file_search_path(pack,Y)) ->asserta(user:file_search_path(pack,Y));true).   15:- initialization(attach_packs,now).   16:- pack_list_installed.   17:- endif.   18
   19
   20         
   21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   22:- dmsg("AUTOLOAD PACKAGES").   23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   24
   25/*
   26pack_autoload_packages(NeedExistingIndex):- 
   27 forall(user:expand_file_search_path(library(''),Dir),
   28  ignore(( (\+ NeedExistingIndex ; absolute_file_name('INDEX',_Absolute,[relative_to(Dir),access(read),file_type(prolog),file_errors(fail)]))->
   29   make_library_index(Dir, ['*.pl']) -> 
   30  (user:library_directory(Dir) -> true ; (asserta(user:library_directory(Dir)) , reload_library_index))))).
   31
   32:- before_boot(pack_autoload_packages(true)).
   33*/
   34
   35
   36rescan_pack_autoload_packages:- \+ access_file('.',write),dmsg("READONLY PACKAGES"),!.
   37rescan_pack_autoload_packages:- \+ app_argv('--all'),!.
   38rescan_pack_autoload_packages:- dmsg("AUTOLOADING PACKAGES..."),
   39 forall('$pack':pack(Pack, _),
   40  forall(((pack_property(Pack, directory(PackDir)),prolog_pack:pack_info_term(PackDir,autoload(true)))),
   41  (access_file(PackDir,write) -> prolog_pack:post_install_autoload(PackDir, [autoload(true)]) ; true))),
   42 dmsg(".. AUTOLOADING COMPLETE"),!.
   43
   44:- before_boot(rescan_pack_autoload_packages).   45:- during_boot(rescan_pack_autoload_packages).   46
   47
   48%:- reload_library_index.
   49%:- autoload([verbose(true)]).
   50:- reload_library_index.