added jsdoc tags
This commit is contained in:
parent
47aa3228c1
commit
f4d6ff2f1f
@ -1,11 +1,17 @@
|
|||||||
|
/*
|
||||||
|
@author David Westgate, Rylan Doherty
|
||||||
|
@fileOverview The Input/Output functions of firerecord. Setting Path, creating files, and reading files
|
||||||
|
*/
|
||||||
var io = {
|
var io = {
|
||||||
openPath : function() {
|
/*
|
||||||
|
@description sets the paths of the script
|
||||||
|
@return path of script selected
|
||||||
|
@see <a href="https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFilePicker"> Mozilla Developer Network Example </a>
|
||||||
|
*/
|
||||||
|
openPath: function () {
|
||||||
const
|
const
|
||||||
nsIFilePicker = Components.interfaces.nsIFilePicker;
|
nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
|
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
||||||
.createInstance(nsIFilePicker);
|
|
||||||
fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
|
fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
|
||||||
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
|
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
|
||||||
var rv = fp.show();
|
var rv = fp.show();
|
||||||
@ -18,32 +24,34 @@ var io = {
|
|||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
appendPath : function(path, contents) {
|
/*
|
||||||
|
@description appends script by contents of event click
|
||||||
|
@see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
|
||||||
|
*/
|
||||||
|
appendPath: function (path, contents) {
|
||||||
alert("appended File");
|
alert("appended File");
|
||||||
var file1 = Components.classes["@mozilla.org/file/local;1"]
|
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||||
.createInstance(Components.interfaces.nsILocalFile);
|
file.initWithPath(path);
|
||||||
file1.initWithPath(path);
|
|
||||||
// alert("append file nullcheck: "+file1.toString());
|
// alert("append file nullcheck: "+file1.toString());
|
||||||
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
|
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
|
||||||
.createInstance(Components.interfaces.nsIFileOutputStream);
|
|
||||||
// use 0x02 | 0x10 to open file for appending.
|
// use 0x02 | 0x10 to open file for appending.
|
||||||
foStream.init(file1, 0x02 | 0x10, 438, 0);
|
foStream.init(file, 0x02 | 0x10, 438, 0);
|
||||||
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
|
||||||
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
|
||||||
converter.init(foStream, "UTF-8", 0, 0);
|
converter.init(foStream, "UTF-8", 0, 0);
|
||||||
converter.writeString(contents);
|
converter.writeString(contents);
|
||||||
converter.close();
|
converter.close();
|
||||||
},
|
},
|
||||||
newPath : function(path) {
|
/*
|
||||||
|
@description sets path to address of a new file
|
||||||
|
@return path of new file
|
||||||
|
@see <a href="https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFilePicker"> Mozilla Developer Network Example </a>
|
||||||
|
*/
|
||||||
|
newPath: function (path) {
|
||||||
const
|
const
|
||||||
nsIFilePicker = Components.interfaces.nsIFilePicker;
|
nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
|
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
||||||
.createInstance(nsIFilePicker);
|
|
||||||
fp.init(window, "Dialog Title", nsIFilePicker.modeSave);
|
fp.init(window, "Dialog Title", nsIFilePicker.modeSave);
|
||||||
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
|
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
|
||||||
|
|
||||||
var rv = fp.show();
|
var rv = fp.show();
|
||||||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||||
var file = fp.file;
|
var file = fp.file;
|
||||||
@ -51,48 +59,44 @@ var io = {
|
|||||||
// need to work with the string paths.
|
// need to work with the string paths.
|
||||||
var path = fp.file.path;
|
var path = fp.file.path;
|
||||||
// work with returned nsILocalFile...
|
// work with returned nsILocalFile...
|
||||||
|
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
createFile : function(path) {
|
/*
|
||||||
|
@description creates new file from path of newPath
|
||||||
|
@see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
|
||||||
|
*/
|
||||||
|
createFile: function (path) {
|
||||||
alert("created File");
|
alert("created File");
|
||||||
var file1 = Components.classes["@mozilla.org/file/local;1"]
|
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||||
.createInstance(Components.interfaces.nsILocalFile);
|
file.initWithPath(path);
|
||||||
file1.initWithPath(path);
|
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
|
||||||
|
|
||||||
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIFileOutputStream);
|
|
||||||
// use 0x02 | 0x10 to open file for appending.
|
// use 0x02 | 0x10 to open file for appending.
|
||||||
foStream.init(file1, 0x02 | 0x08 | 0x20, 438, 0);
|
foStream.init(file, 0x02 | 0x08 | 0x20, 438, 0);
|
||||||
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
|
||||||
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
|
||||||
converter.init(foStream, "UTF-8", 0, 0);
|
converter.init(foStream, "UTF-8", 0, 0);
|
||||||
|
|
||||||
converter.close(); // this closes foStream
|
converter.close(); // this closes foStream
|
||||||
},
|
},
|
||||||
getLine : function(path) {
|
/*
|
||||||
|
@description gets an entire script into an array, seperated by lines
|
||||||
|
@return array of lines
|
||||||
|
@see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
|
||||||
|
*/
|
||||||
|
getScript: function (path) {
|
||||||
// open an input stream from file
|
// open an input stream from file
|
||||||
|
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"]
|
|
||||||
.createInstance(Components.interfaces.nsILocalFile);
|
|
||||||
file.initWithPath(path);
|
file.initWithPath(path);
|
||||||
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
|
||||||
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
||||||
istream.init(file, 0x01, 0444, 0);
|
istream.init(file, 0x01, 0444, 0);
|
||||||
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
||||||
|
|
||||||
// read lines into array
|
// read lines into array
|
||||||
var line = {}, lines = [], hasmore;
|
var line = {}, lines = [],
|
||||||
|
hasmore;
|
||||||
do {
|
do {
|
||||||
hasmore = istream.readLine(line);
|
hasmore = istream.readLine(line);
|
||||||
lines.push(line.value);
|
lines.push(line.value);
|
||||||
} while (hasmore);
|
} while (hasmore);
|
||||||
|
|
||||||
istream.close();
|
istream.close();
|
||||||
|
|
||||||
// do something with read data
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user