From d2c69551d7eb05aca4e6537612518da41c022161 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 22 Jun 2024 10:49:23 -0400 Subject: [PATCH 1/2] lib/dtutils/file - reworked executable path management so that executable_manager can see new executables in case they need the user to find the path and assign it. Reworked check_if_bin_exists to use the preference if it exists to try and cut down on the "flickering windows" problem on windows. --- lib/dtutils/file.lua | 95 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/lib/dtutils/file.lua b/lib/dtutils/file.lua index b8717116..0d23abb0 100644 --- a/lib/dtutils/file.lua +++ b/lib/dtutils/file.lua @@ -265,7 +265,7 @@ end ]] local function _check_path_for_wine_bin(path) - local result = false + local result = false if string.len(path) > 0 then -- check for windows executable to run under wine @@ -294,7 +294,7 @@ local function _check_path_for_bin(bin) path = bin else path = dtutils_file.get_executable_path_preference(bin) - -- reset path preference is the returned preference is a directory + -- reset path preference if the returned preference is a directory if dtutils_file.test_file(path, "d") then dtutils_file.set_executable_path_preference(bin, "") path = nil @@ -318,6 +318,19 @@ local function _check_path_for_bin(bin) return result end +local function _check_preferences_for_bin(bin) + + local result = dtutils_file.get_executable_path_preference(bin) + + if result:len() == 0 then + result = false + end + + return result +end + + + --[[ local function to the old check_if_bin_exists functionality on windows in order to decrease the amount of windows being @@ -385,12 +398,22 @@ function dtutils_file.check_if_bin_exists(bin) result = _old_check_if_bin_exists(bin) else - result = _check_path_for_bin(bin) + result = _check_preferences_for_bin(bin) + + if not result then + result = _check_path_for_bin(bin) + end if not result then result = _search_for_bin(bin) end end + + if not result then + -- make an entry so that executable_manager can be used to fix it + dtutils_file.set_executable_path_preference(bin, "") + end + return result end @@ -674,6 +697,62 @@ function dtutils_file.create_unique_filename(filepath) return filepath end +-- sorted list of executable names +dtutils_file.known_executables = {} + +-- executable name/path pairs +dtutils_file.executable_paths = {} + +-- initialized flag +dtutils_file.executables_initialized = false + +local function _find_known_executable(name) + local found = false + for _, bin in ipairs(dtutils_file.known_executables) do + if name == bin then + found = true + end + end + + return found +end + +local function _get_known_executables() + -- read the known executables preference and populate the tables + + local executables = dt.preferences.read("executable_manager", "known_executables", "string") + + if executables then + local names = du.split(executables, ",") + + for _, name in ipairs(names) do + table.insert(dtutils_file.known_executables, name) + dtutils_file.executable_paths[name] = dtutils_file.get_executable_path_preference(name) + end + + table.sort(dtutils_file.known_executables) + + dtutils_file.executables_initialized = true + end +end + +local function _save_known_executables() + -- write the preference with the known executable names + local pref = du.join(dtutils_file.known_executables, ",") + dt.preferences.write("executable_manager", "known_executables", "string", pref) +end + +local function _add_known_executable(name) + -- add a known executable to the table + if not dtutils_file.executables_initialized then + _get_known_executables() + end + + table.insert(dtutils_file.known_executables, name) + table.sort(dtutils_file.known_executables) + _save_known_executables() +end + dtutils_file.libdoc.functions["set_executable_path_preference"] = { Name = [[set_executable_path_preference]], @@ -696,6 +775,10 @@ dtutils_file.libdoc.functions["set_executable_path_preference"] = { function dtutils_file.set_executable_path_preference(executable, path) dt.preferences.write("executable_paths", executable, "string", path) + dtutils_file.executable_paths[executable] = path + if not _find_known_executable(executable) then + _add_known_executable(executable) + end end @@ -718,7 +801,11 @@ dtutils_file.libdoc.functions["get_executable_path_preference"] = { } function dtutils_file.get_executable_path_preference(executable) - return dt.preferences.read("executable_paths", executable, "string") + if dtutils_file.executables_initialized then + return dtutils_file.executable_paths(executable) + else + return dt.preferences.read("executable_paths", executable, "string") + end end From 056cc245e906b7067af807eae21b45fed21ef713 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 22 Jun 2024 10:52:27 -0400 Subject: [PATCH 2/2] tools/executable_manager - reworked to use the executable paths enhancements in the file library so that executable paths can be assigned to new executables that they system was unable to detect. --- tools/executable_manager.lua | 51 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/tools/executable_manager.lua b/tools/executable_manager.lua index 0e286680..9cd3e67d 100644 --- a/tools/executable_manager.lua +++ b/tools/executable_manager.lua @@ -146,30 +146,53 @@ end -- M A I N P R O G R A M -- - - - - - - - - - - - - - - - - - - - - - - - - - - - -local DARKTABLERC = dt.configuration.config_dir .. PS .. "darktablerc" +local exec_table = {} +local DARKTABLERC = dt.configuration.config_dir .. PS .. "darktablerc" --- grep the executable_paths statements out of the darktablerc file +-- see if we have known executables -local matches = grep(DARKTABLERC, "executable_paths") +local known_executables = dt.preferences.read("executable_manager", "known_executables", "string") --- check if we have something to manage and exit if not +dt.print_log("known_executables is " .. tostring(known_executables)) -if #matches == 0 then - dt.print(_("no executable paths found, exiting...")) - return -end +if not known_executables or known_executables:len() == 0 then --- build a table of the path preferences + known_executables = "" -local exec_table = {} + -- grep the executable_paths statements out of the darktablerc file + + local matches = grep(DARKTABLERC, "executable_paths") -for _,pref in ipairs(matches) do - local parts = du.split(pref, "=") - local tmp = du.split(parts[1], "/") -- preferences are stored with forward slashes - table.insert(exec_table, tmp[#tmp]) + -- check if we have something to manage and exit if not + + if #matches == 0 then + dt.print(_("no executable paths found, exiting...")) + return + end + + for _,pref in ipairs(matches) do + dt.print_log("processing pref " .. pref) + local parts = du.split(pref, "=") + dt.print_log("parts 1 is " .. parts[1]) + local tmp = du.split(parts[1], "/") -- preferences are stored with forward slashes + known_executables = known_executables .. tmp[#tmp] .. "," + end + + -- remove the trailing comma + + known_executables = known_executables:sub(1, -2) + + dt.preferences.write("executable_manager", "known_executables", "string", known_executables) end +dt.print_log("known_executables is " .. known_executables) + + +-- build a table of the path preferences + +local exec_table = du.split(known_executables, ",") + local executable_path_widgets = {} local executable_path_values = {} local placeholder_text = dt.configuration.running_os == windows and _("select an executable") or _("search path for executable")