Rewriting a portion of profiles.lua using LR SDK Utils
I've re-written a portion of profiles.lua in my ongoing attempt to get the profile loading location to be "dynamic." I know it "works" as it did previously, but I am still unable to get the behavior I want.
I am completely new to this, so I would guess I'm making some basic mistakes.
local function setDirectory(value)
local fullpath = LrPathUtils.child(profilepath,loadedprofile)
local path = LrPathUtils.standardizePath(fullpath) -- in case loadedprofile is relative
profilepath = path --problematic because it includes the profile in the path?
--the rest is included in case it does something I'm unaware of. It works without these lines--
local profile = path:match("(.-)([^\\/]+)$") -- functionally the same *I think*...
if profile ~= loadedprofile then
doprofilechange(profile)
end
end
local function setFile(value)
if loadedprofile ~= value then
doprofilechange(value)
end
end
--[[local function setFullPath(value)
local path, profile = value:match("(.-)([^\\/]-%.?([^%.\\/]*))$")
profilepath = path
if profile ~= loadedprofile then
doprofilechange(profile)
end
end]]
Version2... works the same... Is there something that says to search the default folder if the profile cannot be found in profilepath? If I comment out useDefaults it doesn't seem to make a difference).
local function setDirectory(value)
fullpath = LrPathUtils.child(profilepath,loadedprofile)
correctedpath = LrPathUtils.standardizePath(fullpath)
local path, profilepath = LrPathUtil.parent(correctedpath)
--remainder not required?--
local profile = profilepath:match("(.-)([^\\/]+)$")
if profile ~= loadedprofile then
doprofilechange(profile)
end
end
end
local function setFile(value)
if loadedprofile ~= value then
doprofilechange(value)
end
end
--[[local function setFullPath(value)
local path, profile = value:match("(.-)([^\\/]-%.?([^%.\\/]*))$")
profilepath = path
if profile ~= loadedprofile then
doprofilechange(profile)
end
end]]
Third rewrite of setDirectory. Also disabled the useDefaults section (and call to it)... and still no change in behavior. I was hoping that the miswrite of the parent path was the issue.
local function setDirectory(value)
fullpath = LrPathUtils.child(profilepath,loadedprofile)
correctedpath = LrPathUtils.standardizePath(fullpath)
local path, profilepath = LrPathUtils.parent(correctedpath) --LrPathUtils was missing the "s"
--remainder not required?--
local profile = LrPathUtils.leafName(correctedpath) -- instead of match function
if profile ~= loadedprofile then
doprofilechange(profile)
end
end
I'm stuck... I've commented out setFile, setFullPath, and useDefaults and I still cannot affect the behavior. It works the same as it did before. The only remaining relevant section that I can find I have re-written as above:
fullpath = LrPathUtils.child(profilepath,loadedprofile)
This should return the profile folder defined in the settings and the file displayed. I.e. "folder/folder/profile.xml" OR "folder/folder/..profile.xml" if loaded with a relative link.
correctedpath = LrPathUtils.standardizePath(fullpath)
This should return "folder/folder/profile.xml" OR "folder/profile.xml" if loaded w/ relative link
local path, profilepath = LrPathUtils.parent(correctedpath)
This should return "folder/folder" OR "folder/" w/o the profile and load that back as local path and local profilepath
local profile = LrPathUtils.leafName(correctedpath)
This should return "profile.xml" w/o the path
if profile ~= loadedprofile then
doprofilechange(profile)
This should then look for the called profile w/ in the new local profilepath... what am I missing? Offhand, from just this block of code it seems to me that profile = loaded profile because profile (last step) was defined as being loadedprofile (from first step)... Therefore, it shouldn't work at all.
Latest attempt breaking it out to replicate the original in layout. I'll test tomorrow...
local function setDirectory(value)
fullpath = LrPathUtils.child(profilepath,loadedprofile)
correctedpath = LrPathUtils.standardizePath(fullpath)
value = LrPathUtils.parent(correctedpath)
end
local function setFile(value)
if loadedprofile ~= value then
doprofilechange(value)
end
end
local function setFullPath(value)
local path, profile = LrPathUtils.leafName(correctedpath)
profile = value
profilepath = path
if profile ~= loadedprofile then
doprofilechange(profile)
end
end
continued in #183