Caching things inside an extension directory - Mozilla

This is a discussion on Caching things inside an extension directory - Mozilla ; Hi, I recently posted the following on the thunderbird forum. But I think applies to other products like Firefox, etc. So, I would like to ask the same question here. Thank you in advance, Francisco > On 29.11.2008 05:59 ğLeniĞ ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Caching things inside an extension directory

  1. Caching things inside an extension directory

    Hi,
    I recently posted the following on the thunderbird forum. But I think
    applies to other products like Firefox, etc. So, I would like to ask
    the same question here.

    Thank you in advance,
    Francisco

    > On 29.11.2008 05:59 ğLeniĞ wrote


    > > fherrera wrote:
    > > > I have an add on that creates a file "data.txt" inside its extension
    > > > directory under the user profile directory. The add on reads this file
    > > > on every start. Things work fine on each start.


    > > > However, when doing an upgrade/reinstalling, the full add on directory
    > > > is deleted and created again, therefore losing "data.txt". This
    > > > doesn't happen in Firefox.


    > > > Does anybody know if there is a way to avoid that ? If not, how can I
    > > > cache a file ?


    > > I'm not sure I fully understand how you are doing it at the moment.


    > > The profile directory returned by this:
    > > Cc["@mozilla.org/file/directory_service;1"].
    > > getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
    > > corresponds to this:
    > > http://kb.mozillazine.org/Profile_folder
    > > and it survives upgrade/reinstalling of addons. So if you create a
    > > subdirectory of that with a unique name (eg your extension's em:id
    > > UUID) and put data.txt in there it will persist as long as the profile
    > > stays around.


    > > Leni.


    > Yes, the point mentioned by Leni seems to be the solution for your
    > problem. Not storing inside the extension dir but using the "ProfD".
    > Have a look at "reminderfox.xpi". That extension is storing the the
    > "reminders/events" to separate dir under the ProfD. So with an
    > un-install or re-install you will not loose those user data.
    > Günter


    Interesting ... I've been using:

    var prefd = Cc["@mozilla.org/file/directory_service;1"].getService
    (Ci.nsIProperties);
    prefd = prefd.get('PrefD', Ci.nsILocalFile);

    I'm seeing both give me the same.

    What seems to be the problem is that I have been appending "extensions/
    /cache" to the prefd dir and store things there. In other
    words, I've been storing things inside the extension directory. And I
    am finding that doesn't survive uninstalls and upgrades.

    Looking at "reminderfox" I notice it creates its own dir "reminderfox"
    after "prefd".

    For the sake of learning more, and playing 'devil's advocate' a
    bit ... creating directories outside the extension dir obviously
    solves the problem of upgrade survival, but leaves potential 'garbage'
    on uninstalls.

    Is there or should there be some mechanism that differentiates an
    upgrade from a 'uninstallation' process ? The first case leaving
    things for the new version, the second completely removing all
    extension stuff and leaving no 'gargabe' behind.

    Maybe asking too much, thoughts ?

    Regards,
    Francisco

  2. Re: Caching things inside an extension directory

    On Nov 29, 6:19*pm, Mook +nntp.news.mozilla....@gmail.com.please-avoid-direct-mail> wrote:
    > fherrera wrote:
    > > Hi,
    > > I recently posted the following on the thunderbird forum. But I think
    > > applies to other products like Firefox, etc. So, I would like to ask
    > > the same question here.

    >
    > I see this as m.d.extensions, not m.d.extensions.firefox *(There's
    > just more people writing Firefox extensions, therefore more people who
    > know how to respond to Firefox extension questions.)
    >
    > > * * var prefd = Cc["@mozilla.org/file/directory_service;1"].getService
    > > (Ci.nsIProperties);
    > > * * prefd = prefd.get('PrefD', Ci.nsILocalFile);

    >
    > "ProfD" (profile, not preference).


    It does work with 'PrefD' as in that code.

    > > Is there or should there be some mechanism that differentiates an
    > > upgrade from a 'uninstallation' process ? The first case leaving
    > > things for the new version, the second completely removing all
    > > extension stuff and leaving no 'gargabe' behind.

    >
    > There is not; the extensions/(em:id)/ directory is wiped on uninstall,
    > and update is uninstall + install the new version. *You can try catching
    > the em-action-requested observer service topic and look for
    > item-uninstalled in the data; however, this won't catch all cases (e.g.
    > disabled due to app version change, then uninstalled).


    :-(

    >
    > --
    > Mook


    Thanks for the info

+ Reply to Thread