265
265
]]
266
266
267
267
local function _check_path_for_wine_bin (path )
268
- local result = false
268
+ local result = false
269
269
270
270
if string.len (path ) > 0 then
271
271
-- check for windows executable to run under wine
@@ -294,7 +294,7 @@ local function _check_path_for_bin(bin)
294
294
path = bin
295
295
else
296
296
path = dtutils_file .get_executable_path_preference (bin )
297
- -- reset path preference is the returned preference is a directory
297
+ -- reset path preference if the returned preference is a directory
298
298
if dtutils_file .test_file (path , " d" ) then
299
299
dtutils_file .set_executable_path_preference (bin , " " )
300
300
path = nil
@@ -318,6 +318,19 @@ local function _check_path_for_bin(bin)
318
318
return result
319
319
end
320
320
321
+ local function _check_preferences_for_bin (bin )
322
+
323
+ local result = dtutils_file .get_executable_path_preference (bin )
324
+
325
+ if result :len () == 0 then
326
+ result = false
327
+ end
328
+
329
+ return result
330
+ end
331
+
332
+
333
+
321
334
--[[
322
335
local function to the old check_if_bin_exists functionality
323
336
on windows in order to decrease the amount of windows being
@@ -385,12 +398,22 @@ function dtutils_file.check_if_bin_exists(bin)
385
398
result = _old_check_if_bin_exists (bin )
386
399
else
387
400
388
- result = _check_path_for_bin (bin )
401
+ result = _check_preferences_for_bin (bin )
402
+
403
+ if not result then
404
+ result = _check_path_for_bin (bin )
405
+ end
389
406
390
407
if not result then
391
408
result = _search_for_bin (bin )
392
409
end
393
410
end
411
+
412
+ if not result then
413
+ -- make an entry so that executable_manager can be used to fix it
414
+ dtutils_file .set_executable_path_preference (bin , " " )
415
+ end
416
+
394
417
return result
395
418
end
396
419
@@ -674,6 +697,62 @@ function dtutils_file.create_unique_filename(filepath)
674
697
return filepath
675
698
end
676
699
700
+ -- sorted list of executable names
701
+ dtutils_file .known_executables = {}
702
+
703
+ -- executable name/path pairs
704
+ dtutils_file .executable_paths = {}
705
+
706
+ -- initialized flag
707
+ dtutils_file .executables_initialized = false
708
+
709
+ local function _find_known_executable (name )
710
+ local found = false
711
+ for _ , bin in ipairs (dtutils_file .known_executables ) do
712
+ if name == bin then
713
+ found = true
714
+ end
715
+ end
716
+
717
+ return found
718
+ end
719
+
720
+ local function _get_known_executables ()
721
+ -- read the known executables preference and populate the tables
722
+
723
+ local executables = dt .preferences .read (" executable_manager" , " known_executables" , " string" )
724
+
725
+ if executables then
726
+ local names = du .split (executables , " ," )
727
+
728
+ for _ , name in ipairs (names ) do
729
+ table.insert (dtutils_file .known_executables , name )
730
+ dtutils_file .executable_paths [name ] = dtutils_file .get_executable_path_preference (name )
731
+ end
732
+
733
+ table.sort (dtutils_file .known_executables )
734
+
735
+ dtutils_file .executables_initialized = true
736
+ end
737
+ end
738
+
739
+ local function _save_known_executables ()
740
+ -- write the preference with the known executable names
741
+ local pref = du .join (dtutils_file .known_executables , " ," )
742
+ dt .preferences .write (" executable_manager" , " known_executables" , " string" , pref )
743
+ end
744
+
745
+ local function _add_known_executable (name )
746
+ -- add a known executable to the table
747
+ if not dtutils_file .executables_initialized then
748
+ _get_known_executables ()
749
+ end
750
+
751
+ table.insert (dtutils_file .known_executables , name )
752
+ table.sort (dtutils_file .known_executables )
753
+ _save_known_executables ()
754
+ end
755
+
677
756
678
757
dtutils_file .libdoc .functions [" set_executable_path_preference" ] = {
679
758
Name = [[ set_executable_path_preference]] ,
@@ -696,6 +775,10 @@ dtutils_file.libdoc.functions["set_executable_path_preference"] = {
696
775
697
776
function dtutils_file .set_executable_path_preference (executable , path )
698
777
dt .preferences .write (" executable_paths" , executable , " string" , path )
778
+ dtutils_file .executable_paths [executable ] = path
779
+ if not _find_known_executable (executable ) then
780
+ _add_known_executable (executable )
781
+ end
699
782
end
700
783
701
784
@@ -718,7 +801,11 @@ dtutils_file.libdoc.functions["get_executable_path_preference"] = {
718
801
}
719
802
720
803
function dtutils_file .get_executable_path_preference (executable )
721
- return dt .preferences .read (" executable_paths" , executable , " string" )
804
+ if dtutils_file .executables_initialized then
805
+ return dtutils_file .executable_paths (executable )
806
+ else
807
+ return dt .preferences .read (" executable_paths" , executable , " string" )
808
+ end
722
809
end
723
810
724
811
0 commit comments