59
59
60
60
local function _is_windows_executable (path )
61
61
local result = false
62
+ dt .print_log (" in -is_windows_executable" )
62
63
if dtutils_file .test_file (path , " f" ) then
63
64
if string.match (path , " .exe$" ) or string.match (path , " .EXE$" ) or
64
65
string.match (path , " .com$" ) or string.match (path , " .COM$" ) or
@@ -142,12 +143,22 @@ function dtutils_file.test_file(path, test)
142
143
return engine (cmdstring )
143
144
end
144
145
146
+ --[[
147
+ local function to return a case insensitive pattern for matching
148
+ i.e. gimp becomes [Gg][Ii][Mm][Pp] which should match any capitalization
149
+ of gimp.
150
+ ]]
151
+
145
152
local function _case_insensitive_pattern (pattern )
146
153
return pattern :gsub (" (.)" , function (letter )
147
154
return string.format (" [%s$s]" , letter :lower (), letter :upper ())
148
155
end )
149
156
end
150
157
158
+ --[[
159
+ local function to search windows for an executable
160
+ ]]
161
+
151
162
local function _search_for_bin_windows (bin )
152
163
local result = false
153
164
-- use where on path
@@ -175,24 +186,33 @@ local function _search_for_bin_windows(bin)
175
186
return result
176
187
end
177
188
189
+ --[[
190
+ local function to search *nix systems for an executable
191
+ ]]
192
+
178
193
local function _search_for_bin_nix (bin )
179
194
local result = false
180
195
local p = io.popen (" which " .. bin )
181
196
local output = p :read (" *a" )
182
197
p :close ()
183
198
if string.len (output ) > 0 then
184
- local spath = dtutils_file .sanitize_filename (output :sub (1 ,- 2 ))
199
+ local spath = dtutils_file .sanitize_filename (output :sub (1 , - 2 ))
185
200
if dtutils_file .test_file (spath , " f" ) and dtutils_file .test_file (spath , " x" ) then
201
+ dtutils_file .set_executable_path_preference (bin , spath )
186
202
result = spath
187
203
end
188
204
end
189
205
return result
190
206
end
191
207
208
+ --[[
209
+ local function to search macos systems for an executable
210
+ ]]
211
+
192
212
local function _search_for_bin_macos (bin )
193
213
local result = false
194
214
195
- result = _search_for_bin_nix (bin )
215
+ result = _search_for_bin_nix (bin ) -- see if it's in the path
196
216
197
217
if not result then
198
218
local search_start = " /Applications"
@@ -218,6 +238,11 @@ local function _search_for_bin_macos(bin)
218
238
return result
219
239
end
220
240
241
+ --[[
242
+ local function to provide a generic search call that can be
243
+ split into operating system specific calls
244
+ ]]
245
+
221
246
local function _search_for_bin (bin )
222
247
local result = false
223
248
@@ -235,6 +260,11 @@ local function _search_for_bin(bin)
235
260
return result
236
261
end
237
262
263
+ --[[
264
+ local function to check if an executable path is
265
+ a windows executable on linux or macos, thus requiring wine to run
266
+ ]]
267
+
238
268
local function _check_path_for_wine_bin (path )
239
269
local result = false
240
270
@@ -249,6 +279,12 @@ local function _check_path_for_wine_bin(path)
249
279
return result
250
280
end
251
281
282
+ --[[
283
+ local function to check if an executable path is
284
+ a valid executable. Some generic checks are done before
285
+ system specific checks are done.
286
+ ]]
287
+
252
288
local function _check_path_for_bin (bin )
253
289
local result = false
254
290
local path = nil
@@ -283,6 +319,12 @@ local function _check_path_for_bin(bin)
283
319
return result
284
320
end
285
321
322
+ --[[
323
+ local function to the old check_if_bin_exists functionality
324
+ on windows in order to decrease the amount of windows being
325
+ created and destroyed by system calls.
326
+ ]]
327
+
286
328
local function _old_check_if_bin_exists (bin ) -- only run on windows if preference checked
287
329
local result = false
288
330
local path = nil
@@ -325,7 +367,10 @@ dtutils_file.libdoc.functions["check_if_bin_exists"] = {
325
367
Return_Value = [[ result - string - the sanitized path of the binary, false if not found]] ,
326
368
Limitations = [[ If more than one executable that satisfies the search results is found, the
327
369
wrong one may be returned. If the wrong value is returned, the user can still specify the
328
- correct execuable using tools/executable_manager.]] ,
370
+ correct execuable using tools/executable_manager. Most packages are well behaved with the
371
+ notiable exception being GIMP on windows. Depending on the packager there are multiple
372
+ gimp executables, often with version numbers. In this case, the user needs to specify
373
+ the location of the correct executable using executable_manager.]] ,
329
374
Example = [[ ]] ,
330
375
See_Also = [[ executable_manager]] ,
331
376
Reference = [[ ]] ,
@@ -334,6 +379,7 @@ dtutils_file.libdoc.functions["check_if_bin_exists"] = {
334
379
}
335
380
336
381
function dtutils_file .check_if_bin_exists (bin )
382
+ dt .print_log (" in check_if_bin_exists" )
337
383
local result = false
338
384
339
385
if dt .configuration .running_os == " windows" and dt .preferences .read (" dtutils.file" , " use_old_check_if_bin_exists" , " bool" ) then
0 commit comments