@@ -57,35 +57,78 @@ dtutils_file.libdoc.functions["check_if_bin_exists"] = {
57
57
Copyright = [[ ]] ,
58
58
}
59
59
60
- function dtutils_file . check_if_bin_exists (bin )
60
+ local function _check_if_bin_exists_windows (bin )
61
61
local result = false
62
62
local path = nil
63
63
64
- if string.match (bin , " / " ) or string.match ( bin , " \\ " ) then
64
+ if string.match (bin , " \\ " ) then
65
65
path = bin
66
66
else
67
67
path = dtutils_file .get_executable_path_preference (bin )
68
68
end
69
69
70
- if string.len (path ) > 0 then
70
+ if (string.match (path , " .exe$" ) or string.match (path , " .EXE$" )) or
71
+ (string.match (path , " .com$" ) or string.match (path , " .COM$" )) or
72
+ (string.match (path , " .bat$" ) or string.match (path , " .BAT$" )) or
73
+ (string.match (path , " .cmd$" ) or string.match (path , " .CMD$" )) then
71
74
if dtutils_file .check_if_file_exists (path ) then
72
- if (string.match (path , " .exe$" ) or string.match (path , " .EXE$" )) and dt .configuration .running_os ~= " windows" then
73
- result = dtutils_file .sanitize_filename (" wine " .. path )
74
- else
75
+ result = dtutils_file .sanitize_filename (path )
76
+ end
77
+ end
78
+ return result
79
+ end
80
+
81
+ -- check_if_bin_exists for unix like systems (linux, macos)
82
+ local function _check_if_bin_exists_nix (bin )
83
+ local result = false
84
+ local path = nil
85
+
86
+ if string.match (bin , " /" ) then
87
+ path = bin
88
+ else
89
+ path = dtutils_file .get_executable_path_preference (bin )
90
+ end
91
+
92
+ if path then dt .print_log (" path is " .. path ) end
93
+
94
+ if string.len (path ) > 0 then
95
+ -- check for windows executable to run under wine
96
+ if string.match (path , " .exe$" ) or string.match (path , " .EXE$" ) then
97
+ if dtutils_file .check_if_file_exists (path ) then
75
98
result = dtutils_file .sanitize_filename (path )
76
99
end
100
+ else
101
+ if dtutils_file .check_if_file_exists (path ) then
102
+ local spath = dtutils_file .sanitize_filename (path )
103
+ -- check that it's an executable file
104
+ if os.execute (" test -f " .. spath .. " && test -x " .. spath ) then
105
+ result = spath
106
+ end
107
+ end
77
108
end
78
- elseif dt .configuration .running_os == " linux" then
109
+ end
110
+ if not result then
79
111
local p = io.popen (" which " .. bin )
80
112
local output = p :read (" *a" )
81
113
p :close ()
82
114
if string.len (output ) > 0 then
83
- result = dtutils_file .sanitize_filename (output :sub (1 ,- 2 ))
115
+ local spath = dtutils_file .sanitize_filename (output :sub (1 ,- 2 ))
116
+ if os.execute (" test -f " .. spath .. " && test -x " .. spath ) then
117
+ result = spath
118
+ end
84
119
end
85
120
end
86
121
return result
87
122
end
88
123
124
+ function dtutils_file .check_if_bin_exists (bin )
125
+ if dt .configuration .running_os == " windows" then
126
+ return _check_if_bin_exists_windows (bin )
127
+ else
128
+ return _check_if_bin_exists_nix (bin )
129
+ end
130
+ end
131
+
89
132
dtutils_file .libdoc .functions [" split_filepath" ] = {
90
133
Name = [[ split_filepath]] ,
91
134
Synopsis = [[ split a filepath into parts]] ,
@@ -542,7 +585,7 @@ function dtutils_file.executable_path_widget(executables)
542
585
is_directory = false ,
543
586
changed_callback = function (self )
544
587
if dtutils_file .check_if_bin_exists (self .value ) then
545
- dtutils_file .set_executable_path_preference (executable , self .value )
588
+ dtutils_file .set_executable_path_preference (executable , dtutils_file . check_if_bin_exists ( self .value ) )
546
589
end
547
590
end }
548
591
)
0 commit comments