The first part of the code basically needs to find the extensions file path. To most, this is within the mozilla profile folder. This is needed if you want to keep the file in the same folder as your extension. Otherwise, you could leave it out or give it a different file path. Id is used to hold the id of my extension.
//get extensions file path
const id = "sample@foo.net";
var extension = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager)
.getInstallLocation(id)
.getItemLocation(id);
The second part of the code is used to check whether or not you have the proper permissions to write a file to the local machine. I have not thoroughly tested this though.
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert("Permission to write to file was denied.");
}
Next, I create a variable to hold my file path (just easier for me); this is done using the extension path that we found earlier. Then create the proper components needed to write the file. First we need nsILocalFile, which to my understanding is like creating an instance of a file object. This needs a path which is basically the filepath I created. Then you need to create it.
//create proper path for xml file
var theFile = extension.path + "\\" + "metrics.xml";
//create component for file writing
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( theFile );
if(file.exists() == false) //check to see if file exists
{
alert("creating file...");
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);
}
Now, we create an output stream; nsIFileOutputStream, and give it the proper modes. As shown in my comments, I have chosen to do only write, create file if not exists, and truncate which basically deletes the content (leave this out and add 0x10 if you want to append to a file).
Then, you write to the file; giving the content and the length of the content, and close close the stream.
//create file output stream and use write/create/truncate mode
//0x02 writing, 0x08 create file, 0x20 truncate length if exist
var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
stream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
//write data to file then close output stream
var content = this.xmldoc;
stream.write(content, content.length);
stream.close();
For more information on File I/O you can find it at
Mozilla Developer Center
Also check out the XPCOM reference at XUL Planet
. This is basically where I go to research each component used.
86 comments:
A little late now, but there is already some javascript objects to help with reading/writing to files called scriptable-io if you want to check it out.
viagra from canada viagra professional does viagra really work cheap viagra walmart videos viagra natural herbs used as viagra viagra alternatives viagra blood pressure cheapest viagra effect of viagra on women buying viagra homemade viagra recreational viagra use cheapest viagra
It agree, very much the helpful information
Hi
Does anyone know, is it possible to zip a folder from a firefox extension?
Thanks
Hey,
I mostly visits this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Plenty of useful information on simon-jung.blogspot.com. Do you pay attention towards your health?. Let me present you with one fact here. Research displays that closely 50% of all United States adults are either obese or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] So if you're one of these people, you're not alone. Its true that we all can't be like Brad Pitt, Angelina Jolie, Megan Fox, and have sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is not like piece of cake. Some improvement in of daily activity can help us in losing weight quickly.
About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also mentor who can help you lose weight quickly. If you do not want to go under hard training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for fast weight loss.
Splendidly done is better than well said.
Well done is better than spectacularly said.
Well done is better than well said.
Splendidly done is better than spectacularly said.
Well done is richer reconsider than spectacularly said.
A humankind who dares to barrens anyone hour of time has not discovered the value of life.
[url=http://biblestudynow.webs.com/apps/profile/profilePage?id=53375468]Gilda[/url]
Linda
A the huan race who dares to decay anyone hour of time has not discovered the value of life.
[url=http://purebredcatbreedrescue.org/forums/member.php?u=14746&vmid=165#vmessage165]Linda[/url]
Gilda
We should be careful and discriminating in all the advice we give. We should be extraordinarily painstaking in giving guidance that we would not about of following ourselves. Most of all, we ought to evade giving advise which we don't follow when it damages those who woo assume us at our word.
pipe clamps
[url=http://pipe-clamps-67.webs.com/apps/blog/]pipe clamps[/url]
A gink begins scathing his discernment teeth the senior time he bites out more than he can chew.
To be a adroit lenient being is to from a make of openness to the world, an ability to trust unsure things beyond your own pilot, that can govern you to be shattered in very extreme circumstances pro which you were not to blame. That says something remarkably important with the prerequisite of the honest compulsion: that it is based on a corporation in the fitful and on a willingness to be exposed; it's based on being more like a shop than like a jewel, something somewhat dainty, but whose acutely special handsomeness is inseparable from that fragility.
To be a noble human being is to from a make of openness to the world, an ability to trusteeship aleatory things beyond your own pilot, that can lead you to be shattered in unequivocally extreme circumstances for which you were not to blame. That says something uncommonly weighty relating to the prerequisite of the honest passion: that it is based on a corporation in the unpredictable and on a willingness to be exposed; it's based on being more like a shop than like a jewel, something somewhat tenuous, but whose very particular attraction is inseparable from that fragility.
Work out ferments the humors, casts them into their right channels, throws substandard redundancies, and helps nature in those hush-hush distributions, without which the body cannot subsist in its vigor, nor the incarnation dissimulate with cheerfulness.
Distress ferments the humors, casts them into their meet channels, throws eccentric redundancies, and helps cosmos in those hush-hush distributions, without which the association cannot subsist in its vigor, nor the typification fake with cheerfulness.
Your blog is outrageous! I mean, Ive never been so entertained by anything in my life! Your vids are perfect for this. I mean, how did you manage to find something that matches your style of writing so well? Im really happy I started reading this today. Youve got a follower in me for sure!
thankyou.
I wandered all over the wilderness and finally located the solution here
I liked this blog, i think is very interesting, most of all for the new ideas that this blog talk.
Thank You a ton for writing such a wonderful piece of information. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us.
Now, how will you do this, ff 17... ?
Now, how will you do this, ff 17... ?
I am sure you will love [URL=http://www.prada--outlet.com/]prada online outlet[/URL] and check coupon code available mBDnwZWa [URL=http://www.prada--outlet.com/ ] http://www.prada--outlet.com/ [/URL]
Hi mates, how is the whole thing, and what you want
to say concerning this post, in my view its in fact amazing for me.
Also visit my webpage ... african mango scam
For most up-to-date news you have to pay a quick visit internet and
on internet I found this website as a best website for newest updates.
My web blog ; Healthy Diet
[b][url=http://www.louisvuittonoutletmart.co.uk/]louis vuitton handbags[/url][/b] The IdeaSet up as numerous wi-fi IP surveillance cameras when you want. Position them in every home you prefer to to help keep an eye on, and buy cameras created for outdoor use to watch the outside of your property as well. Whenever you set up your cameras, make sure you put them substantial sufficient and at the right angle to open up the most important viewing area.
[b][url=http://www.cheapuggsstore.com/]ugg boots cheap[/url][/b] You see, official gowns will not be like other attire. Regardless of their reduce or model, these attire are made to flatter specific figures or overall body types. And no amount of short-term excess weight loss will alter your fundamental body sort! Thus, it is very important know which sort of robe flatters your determine before you start procuring..
[b][url=http://www.louisvuittonsalemarket.com/]louis vuitton outlet[/url][/b] These phony Chanel bags are classy and stylish with top quality. These Chanel purses made with a fantastic interest to facts, feature zippered compartments and comfy handles. So it really is hard to distinguish them through the primary ones..
[b][url=http://www.cheapuggsstore.com/]cheap uggs[/url][/b] Stella McCartney, for instance, has a beautiful clutch this period that may be completely vegan. While her bags are costly, they are now constructed from supplies you could experience great about! Donna Karan, too, makes an incredible black zippered bag this drop that's not just funky, but is created from pure lambskin. You should definitely look into her "Gotham" assortment.
[b][url=http://www.cheapuggsstore.com/]cheap ugg boots[/url][/b] You can find this sort of the broad variety of those Louis Vuitton bags reproduction which can demand a great function for yourself to get your pick out. A purchasing information on this site goes to revolutionize the complete idea of buying replicas. These replica bags are on par using the one of a kind not just in terms of bodily physical appearance, but also in high quality and sturdiness.
top [url=http://www.001casino.com/]001casino.com[/url] coincide the latest [url=http://www.casinolasvegass.com/]casinolasvegass.com[/url] unshackled no store hand-out at the leading [url=http://www.baywatchcasino.com/]www.baywatchcasino.com
[/url].
Hello. Facebook takes a [url=http://www.onlineroulette.gd]casino games[/url] punt invest in on 888 casino freight: Facebook is expanding its efforts to introduce real-money gaming to millions of British users after announcing a carry out with the online gambling companions 888 Holdings.And Bye.
So, for everyone who is interested, I'm going to exhibit you how you can draft patterns especially satisfy your child. Formulated by top doctors and nutrition experts in the USA phen375 the initial step to shedding pounds is usually to truly understand what you will be eating. Of course, it could be this type of relief in case you can be a whole new you in a very couple of days. Choose lean food options that say fat-free, low-fat, reduced-calorie and no added sugar, but understand that "low-fat" and "fat-free" can mask extra calories, so see the nutrition label carefully http://www.phen375factsheet.com of course, they'd lose teeth, muscle tissue, and then for any chance at a sound body. The best-known tea production regions in Korea are Boseong in Jeollanam-do, Jeju-do, and Hadong in Gyeongsangnam-do, because both versions annually holds an eco-friendly festival [url=http://www.phen375factsheet.com/]cheap phen375[/url] others may scream that they can can do more, but if you need to consider the simple and convenient road and achieving the results, then your idiot proof diet will be the right diet in your case.
dating for old fat ladys http://loveepicentre.com/success_stories.php german women dating website
[url=http://inchinaledlightmanufacturer.com ]led light manufacturer [/url]on his mind, and that he for certain was in the right, both as to the sum http://inchinaledlightmanufacturer.com led signs manufacturer led manufacturers This Web site includes information about Project Gutenberg-tm,
supplements have become nearly impossible to find in stores after Dr. Mehmet Oz, mentioning no specific brand, hailed it as "The No. 1 Miracle in a Bottle to Burn Fat" on his popular daytime African mango reviews
Hi All,
I have created code snippet to create a file into local system in firefox plugin on my own blog http://blog.anoopkumarsharma.com/use-jquery-while-creating-firefox-plugin/ . have a look and let me know your thoughts as well.
public ebook library http://audiobookscollection.co.uk/fr/Pip/p10226/ rca reb 1200 color ebook reader [url=http://audiobookscollection.co.uk/C-Builder-5-Developer-s-Guide/p151713/]intitle index of modified survival ebook[/url] make an ebook not printable
how to download google ebook http://audiobookscollection.co.uk/Telephony/c2461/ finescale modeler ebook [url=http://audiobookscollection.co.uk/de/Windhaven/p227335/]childrens ebook downloads[/url] ebook german language
longchamp kyossvtp longchamp sale ununcnie longchamp bags unntsawo longchamp uk jwjwvwkx longchamp bags uk cpufroso
simply dropping by to say hi
This website seems to be a legitimate source of information, will share it across my contacts.
Diet Pill
Capsiplex Reviews
I visited many web pages however the audio quality for audio songs existing at this web site is in fact
marvelous.
Here is my web page ... World Of Tanks Hack
geatrinee xaikalitag Elolafandfurn [url=http://uillumaror.com]iziananatt[/url] EleguigHefe http://gusannghor.com effedaytreata
[url=http://certifiedpharmacy.co.uk/products/digoxin.htm][img]http://onlinemedistore.com/2.jpg[/img][/url]
medco pharmacy locations http://certifiedpharmacy.co.uk/products/lotrisone.htm career day pharmacy [url=http://certifiedpharmacy.co.uk/products/bactrim.htm]troy pharmacy[/url]
cialis online pharmacy http://certifiedpharmacy.co.uk/products/risperdal.htm pharmacy schools in louisiana [url=http://certifiedpharmacy.co.uk/products/exelon.htm]exelon[/url]
pharmacy terms sod ext camyl http://certifiedpharmacy.co.uk/products/intagra.htm pharmacy technician jobs in pa [url=http://certifiedpharmacy.co.uk/refer-a-friend.htm]weldon pharmacy alabama[/url]
only online pharmacy that can overnite next day ship garuanteed http://certifiedpharmacy.co.uk/categories/pain-relief.htm canadian pharmacy and cialas [url=http://certifiedpharmacy.co.uk/products/lamisil.htm]lamisil[/url]
Hurrah, that's what I was exploring for, what a material! existing here at this blog, thanks admin of this site.
Here is my blog post - World Of Tanks Hack
Excellent post. I was checking constantly this blog and I am impressed!
Extremely useful info specially the last part :
) I care for such info a lot. I was looking for this particular info for a very
long time. Thank you and best of luck.
my webpage ... Microsoft Points
Thank you for the auspicious writeup. It in fact was a amusement account
it. Look advanced to more added agreeable from you! However, how can we communicate?
My web page; social bookmarking service
If you desire to grow your know-how just keep visiting this
site and be updated with the most up-to-date information posted here.
Visit my website ... isabellgnb14p.tblog.com
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you!
By the way, how could we communicate?
My homepage; Diaper Rash Remedies
If some one wishes expert view about blogging then i propose him/her to go to see this weblog, Keep up the
nice job.
Take a look at my web page; Unknown
This is a topic that's near to my heart... Many thanks! Where are your contact details though?
My homepage: unknown
You actually make it seem so easy together with your presentation however I find this
topic to be actually one thing which I feel I might never
understand. It sort of feels too complicated and very wide for me.
I am looking forward for your subsequent post, I'll attempt to get the grasp of it!
Review my website; unknown
Hey would you mind letting me know which hosting company you're utilizing? I've loaded your blog in
3 different browsers and I must say this blog loads a lot quicker then most.
Can you recommend a good internet hosting provider at a fair price?
Cheers, I appreciate it!
My web page - download 7zip
My partner and I stumbled over here by a different web address and thought I may as well
check things out. I like what I see so i am just following you.
Look forward to looking at your web page again.
Feel free to surf to my homepage; unknown
Your style is unique in comparison to other folks I've read stuff from. I appreciate you for posting when you have the opportunity, Guess I'll
just book mark this page.
Take a look at my blog post ... http://En.Netlog.com/julianeshirley/blog/blogid=22333045
Hello. And Bye.
I'm gone to inform my little brother, that he should also pay a quick visit this weblog on regular basis to obtain updated from most recent reports.
Also visit my homepage; Stretch Marks
http://louisvuittononline.citationguide.net louis vuitton outlet louis vuitton odeon pm cross body bag
Hi, yeah this piece of writing is in fact good and I have learned lot of things from it on the topic
of blogging. thanks.
My web page; unknown
Awesome site you have here but I was wondering if you knew
of any user discussion forums that cover the same topics talked about in this article?
I'd really love to be a part of online community where I can get suggestions from other experienced individuals that share the same interest. If you have any recommendations, please let me know. Thank you!
Feel free to visit my website ... Tammygate.Autisable.Com
It's truly very complex in this active life to listen news on TV, so I simply use world wide web for that purpose, and take the hottest news.
Also visit my page; Unknown
Link exchange is nothing else but it is just placing the other
person's web site link on your page at appropriate place and other person will also do similar in support of you.
Here is my weblog - unknown
Hello, I enjoy reading through your article. I like to write a little comment to support you.
my web site - ps3 jailbreak downgrade
There are many symptoms with cold sores, but the main symptom is the actual sore on your face.
You can curb this virus, and keep it dormant, with a good cold sore treatment plan.
These new viruses are complete and full size, identical to the original virus.
Stop by my website - cold sore cure
This is a very good tip particularly to those fresh to
the blogosphere. Short but very accurate info… Many thanks for sharing this one.
A must read article!
my page; World Of Tanks hack
Undeniably believe that which you said. Your favorite justification seemed to be on the internet the easiest thing to be aware
of. I say to you, I certainly get annoyed while people consider worries that they plainly
don't know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks
Also visit my web blog ... diaper rash home remedies
I don't even know the way I finished up right here, however I believed this put up used to be good. I don't recognise who
you might be but certainly you're going to a famous blogger in the event you are not already. Cheers!
Here is my page ... unknown
Hey this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!
Feel free to surf to my homepage diarrhea Remedies
Post writing is also a fun, if you be familiar with after that you can write otherwise it is
difficult to write.
my web page; Dailymotion.Com
Good day! Would you mind if I share your blog with my twitter group?
There's a lot of people that I think would really enjoy your content. Please let me know. Cheers
Feel free to surf to my web-site :: The Interlace
Your style is unique in comparison to other people I have read stuff from.
Many thanks for posting when you've got the opportunity, Guess I will just bookmark this web site.
Look at my page - Generateur de Code PSN
What's up, its fastidious piece of writing on the topic of media print, we all be familiar with media is a enormous source of information.
my web blog - psn code generator
And along with the user identity, it could also carry complete information on
a person's personal preferences for use across websites. In case your personal computer lets the Autoplay function, there'll be the Autoplay screen and then
select “Open folder to view files". Dean Hachamovitch, general manager, responsible for the explanation of the Internet Explorer, Microsoft decided in the company IEBlog:Office 2010 download is available now.
Here is my page - download internet download manager
I think this is among the so much significant information
for me. And i'm happy studying your article. But wanna remark on some common issues, The site style is great, the articles is actually great : D. Good process, cheers
my homepage :: Http://dailymotion.com
What's Going down i am new to this, I stumbled upon this I've found It
positively useful and it has aided me out loads. I am hoping to contribute & aid different users like its helped me.
Good job.
Also visit my blog post :: jailbreak my ps3 **
I have read so many posts about the blogger lovers however this post is really a
pleasant piece of writing, keep it up.
My page ... Ps3 jailbreak
Hey there! Do you know if they make any plugins to safeguard against hackers?
I'm kinda paranoid about losing everything I've worked hard on.
Any tips?
Visit my webpage - code Psn gratuit
fantastic post, very informative. I ponder why the other specialists of this sector don't understand this. You should continue your writing. I am sure, you have a huge readers' base already!
My web site - world of tanks hack
I'm not sure exactly why but this web site is loading very slow for me. Is anyone else having this problem or is it a issue on my end? I'll check back
later on and see if the problem still exists.
Also visit my page ... Psn Code Generator
This is very interesting, You are a very skilled blogger.
I've joined your feed and look forward to seeking more of your excellent post. Also, I have shared your site in my social networks!
Here is my web-site 3.60 ps3 Jailbreak
Hey there are using Wordpress for your blog platform?
I'm new to the blog world but I'm trying to get
started and create my own. Do you require any html coding knowledge to make your own blog?
Any help would be greatly appreciated!
Also visit my web-site Money
Superb website you have here but I was wondering if
you knew of any user discussion forums that cover the same
topics discussed in this article? I'd really love to be a part of community where I can get suggestions from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Thank you!
Check out my weblog: codes psn gratuit
Hi to every body, it's my first go to see of this webpage; this weblog includes remarkable and in fact excellent material for visitors.
Also visit my web page; Minecraft Crack
I got this web site from my friend who told me regarding
this website and at the moment this time I am browsing this site and reading very informative posts at this time.
My homepage - bandar bola
Today, I went to the beach with my kids. I found a sea shell and
gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear."
She placed the shell to her ear and screamed. There was a hermit crab inside
and it pinched her ear. She never wants to go back!
LoL I know this is entirely off topic but I had to tell someone!
Here is my web-site - Móveis
Great post however I was wanting to know if you could write a litte more on this subject?
I'd be very thankful if you could elaborate a little bit further. Thank you!
my web page - 24 hours glass repair
I just could not go away your site before suggesting that I extremely loved the
standard information a person provide on your guests?
Is going to be back regularly to investigate cross-check new posts
My webpage :: Code Psn Gratuit
Post a Comment