MIDI2LR icon indicating copy to clipboard operation
MIDI2LR copied to clipboard

Rewriting a portion of profiles.lua using LR SDK Utils

Open StevenKersting opened this issue 10 years ago • 5 comments

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]]

StevenKersting avatar Feb 07 '16 22:02 StevenKersting

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]]

StevenKersting avatar Feb 08 '16 15:02 StevenKersting

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

StevenKersting avatar Feb 08 '16 22:02 StevenKersting

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.

StevenKersting avatar Feb 09 '16 01:02 StevenKersting

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

StevenKersting avatar Feb 09 '16 02:02 StevenKersting

continued in #183

rsjaffe avatar Feb 10 '16 03:02 rsjaffe