35
36:- module(swish_paths, []). 37:- use_module(library(http/http_path), []). 38
41
42:- initialization initialize_paths. 43
44:- multifile
45 user:file_search_path/2,
46 http:location/3. 47
48user:file_search_path(data, data).
49user:file_search_path(config_enabled, 'config-enabled').
50user:file_search_path(config_enabled, swish('config-enabled')).
51user:file_search_path(config, config_enabled(.)).
52user:file_search_path(config, swish('config-available')).
53user:file_search_path(swish_web, swish(web)).
54user:file_search_path(swish_pack, swish(pack)).
55user:file_search_path(js, config('web/js')).
56user:file_search_path(js, swish_web(js)).
57user:file_search_path(css, swish_web(css)).
58user:file_search_path(icons, config('web/icons')).
59user:file_search_path(icons, swish_web(icons)).
60user:file_search_path(plugin, config('web/plugin')).
61
65
66set_swish_path :-
67 absolute_file_name(swish('swish.pl'), _,
68 [file_errors(fail), access(read)]), !.
69set_swish_path :-
70 prolog_load_context(directory, Dir),
71 !,
72 asserta(user:file_search_path(swish, Dir)).
73set_swish_path :-
74 current_prolog_flag(saved_program, true).
75
79
80attach_local_packs :-
81 ( current_prolog_flag(swish_ide, true)
82 -> Duplicate = keep
83 ; Duplicate = replace
84 ),
85 attach_packs(swish_pack(.), [duplicate(Duplicate), search(first)]).
86
90
91set_data_path :-
92 absolute_file_name(data(.), _,
93 [ file_type(directory),
94 access(write),
95 file_errors(fail)
96 ]), !.
97set_data_path :-
98 absolute_file_name(data(.), Dir,
99 [ solutions(all)
100 ]),
101 \+ exists_directory(Dir),
102 catch(make_directory(Dir),
103 error(permission_error(create,directory,Dir), _),
104 fail), !,
105 print_message(informational, swish(created_data_dir(Dir))).
106set_data_path :-
107 print_message(error, swish(no_data_dir)),
108 halt(1).
109
110initialize_paths :-
111 set_swish_path,
112 attach_local_packs,
113 set_data_path.
114
116
117http:location(swish, root(.), [priority(-100)])