This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 9 - Pages: 1 - Last Post: 08-Feb-2018 14:41 Last Post By: davidekholm Threads: [ Previous | Next ]
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Modifying a .info file
Posted: 07-Feb-2018 19:54
 
  Click to reply to this thread Reply
I'm writing a little tool to do some variable conversion for Matrix. Taking care of the regular skin settings is no problem - my UI code has correction routines going back almost to version 1, and those all work just fine. In this case, however, what I need to alter are some folder-specific settings, which are stashed in the folder/.info files.

So, the tools traverses the project tree, and when it encounters a folder, it looks for the old variables and, if they're not empty, strings them together into a new variable:
String[] oldvars = {"locMusicTrack1FullPath", "locMusicTrack2FullPath", "locMusicTrack3FullPath", "locMusicTrack4FullPath", "locMusicTrack5FullPath"};
newvar = "";
for(oldvar:oldvars) {
	path = ao.getVars().get(oldvar);
	if(!path.equals("")) newvar += path + "\t";
}
Works like a champ.

But now I've got a new value that I want to write out to the .info file, like:
something.put("locMusicTracks", newvar);
This new variable isn't present in the .info file - it needs to be added.

At the same time, to prevent later errors, I need either to delete the old variables (the locMusicTrack1FullPath, 2, 3, etc.) or at least set their values to an empty string.

Can't quite figure out how to do either of these things.
davidekholm

Posts: 21,836
Registered: 18-Oct-2002
Re: Modifying a .info file
Posted: 07-Feb-2018 20:37   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
The best way forward is to modify the .info files via the AlbumObjectProperties API and not modify the .info files directly. If you have problems with any part of this, let me know and I'll provide an example.
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Re: Modifying a .info file
Posted: 07-Feb-2018 20:50   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
That's what I've been trying to do. A put() doesn't produce any errors, but the results don't land in the .info file, either, and for subsequent album builds, they need to be there. I'm obviously missing some piece of this puzzle.

And to clarify, this isn't something that would execute during project loading, or during album building. It's a one-shot, "fix this old project" tool.
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Re: Modifying a .info file
Posted: 07-Feb-2018 21:09   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Through trial and error, I'm getting closer. This actually does add the desired variable to the vars for the ao:
vars.put("locMusicTracks", newvar);
And a vars.remove(name) has the desired effect.

Now how do I save them? And at this point, the vars includes all the stuff from the project settings, as well as the folder-specific .info variables. Clearly, I don't want to write all of those out to the info file.

Edited by: jGromit on 07-Feb-2018 15:09
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Re: Modifying a .info file
Posted: 07-Feb-2018 21:56   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
With the able assistance of Rob "Mr. Tools" Marshall, I think I've got a working tool. More testing needed, but it looks promising.
davidekholm

Posts: 21,836
Registered: 18-Oct-2002
Re: Modifying a .info file
Posted: 07-Feb-2018 22:46   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Good. You need to call .save() on the AlbumObjectProperties object to persist the changes to disk.
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Re: Modifying a .info file
Posted: 08-Feb-2018 06:28   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Just one little twist that caught me off-guard. If you grab the value of a non-existent variable on an album object, it returns an empty string:
x = ao.getVars().get("nosuchthing");
 
x is empty
But if you grab the value of a non-existent variable from the album object properties, it returns null:
x = aop.get("nosuchthing");
 
x is null
And if you write a null value to .info, all hell breaks loose! In short, if you're doing something like this, make sure you're checking for null.
davidekholm

Posts: 21,836
Registered: 18-Oct-2002
Re: Modifying a .info file
Posted: 08-Feb-2018 12:12   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
You should get null back on both calls if "nosuchthing" doesn't exist. At least I do :-)
jGromit

Posts: 32,114
Registered: 31-Jan-2006
Re: Modifying a .info file
Posted: 08-Feb-2018 13:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Ah, you're correct, so I was puzzled by the lack of null pointer errors in my early testing. I could ao.getVars().get("someVar") even when someVar wasn't present in the .info file, and check it for emptiness, with no problem.

Turns out that if the variable has a default value in SlideModel.java, that's what you get when you ask for ao.getVars().get("definedVar"), even when that variable isn't called out in .info. But that doesn't apply when you're grabbing ao.getProperties().get("definedVar"). In that context, you get a null if definedVar isn't present in .info - no default value is present.
davidekholm

Posts: 21,836
Registered: 18-Oct-2002
Re: Modifying a .info file
Posted: 08-Feb-2018 14:41   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Correct

Point your RSS reader here for a feed of the latest messages in all forums