XPConnect:nsIRegistry
From MDC
XulPlanet documentation: nsIRegistry
Other documentation: libreg source, reg.h in particular
Okay!
It works like this.
var Cc = Components.classes; var Ci = Components.interfaces; var rc = Cc["@mozilla.org/registry;1"]; var rs = rc.getService(Ci.nsIRegistry);
Now you have the registry service.
rs.openWellKnownRegistry(2); // 2 signifies the ApplicationRegistry, if I understand right var st = rs.enumerateAllSubtrees(2); // 2 signifies "common", see libreg source (reg.h) for info
Now you have an nsIEnumerator that can report the subtrees.
try {
st.first();
do {
var data = st.currentItem();
if( data instanceof Ci.nsIRegistryNode )
print("nsIRegistryNode: " + data.nameUTF8 + " (" + data.key + ")");
st.next();
} while( Components.lastResult == 0 );
} catch(e) {}
Now, the output is something like:
Profiles (344) Profiles/default (530) Profiles/foo (1046) Profiles/bar (1518)
The number inside the parenthesis is the "key." You can use this key with the rest of the nsIRegistry API.
Now, I know from visual inspection that there's a key called "directory" for each profile. I don't know how to get the other keys' names automatically, but I do know how to look up the directory for a particular profile.
js> rs.getStringUTF8(530, "directory") // 530: key corresponding with Profiles/default
The output is something like:
/home/lion/.mozilla/default/awp83kud.slt
Boo-yah!
Can we change it?
js> rs.setStringUTF8(530, "directory", "/home/lion/somewhere/else") js> rs.getStringUTF8(530, "directory") /home/lion/somewhere/else
Yes!
Now, the only puzzle is: how do you save it?
js> rs.flush() // this is not enough...
Perhaps if we quit with the XPConnect:appShellService, it will work.