home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil2B8DF52B887F0BBE99452EBFA2BCF73F
< prev
next >
Wrap
Text File
|
2010-07-12
|
10KB
|
267 lines
function SysUtils() {
this._uconv = this._Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(
this._Ci.nsIScriptableUnicodeConverter);
this._uconv.charset = "UTF-8";
}
SysUtils.prototype = {
readTextFile: function SysUtils_readTextFile(file) {
var fileContents = "";
var is = this._Cc["@mozilla.org/network/file-input-stream;1"].createInstance(this._Ci.nsIFileInputStream);
is.init(file, 0x01, 0, is.CLOSE_ON_EOF);
try {
var sis = this._Cc["@mozilla.org/scriptableinputstream;1"].createInstance(this._Ci.nsIScriptableInputStream);
sis.init(is);
try {
while(sis.available() > 0)
fileContents += this._uconv.ConvertToUnicode(sis.read(sis.available()));
} finally {
sis.close();
}
} finally {
is.close();
}
return fileContents;
},
writeTextFile: function SysUtils_writeTextFile(file, text, accessRights) {
var fileOutStream = this._Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(this._Ci.nsIFileOutputStream);
let accessRights = accessRights || 0644;
fileOutStream.init(file, 0x02 | 0x08 | 0x20, accessRights, 0);
var converter = this._Cc["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(this._Ci.nsIConverterOutputStream);
converter.init(fileOutStream, "UTF-8", 0, 0);
converter.writeString(text);
converter.close();
},
writeStreamToFile: function SysUtils_writeStreamToFile(inputStream, destFile, accessRights, processWatcher) {
if ( !(inputStream instanceof this._Ci.nsIInputStream) )
throw new TypeError("First argument must be nsIInputStream");
if ( !(destFile instanceof this._Ci.nsIFile) )
throw new TypeError("Second argument must be nsIFile");
if ( (accessRights !== undefined) && !this.isNumber(accessRights) )
throw new TypeError("Third argument must be Number or undefined");
var fileOutStream = this._Cc["@mozilla.org/network/file-output-stream;1"].createInstance(this._Ci.nsIFileOutputStream);
try {
let accessRights = accessRights || 0644;
fileOutStream.init(destFile, 0x02 | 0x08 | 0x20, accessRights, 0);
var binInputStream = this._Cc["@mozilla.org/binaryinputstream;1"].createInstance(this._Ci.nsIBinaryInputStream);
binInputStream.setInputStream(inputStream);
try {
var size;
var buf;
while (size = binInputStream.available()) {
buf = binInputStream.readBytes(size);
fileOutStream.write(buf, size);
if (processWatcher) {
processWatcher.onWrite(size);
if (processWatcher.shouldStop())
break;
}
}
} finally {
binInputStream.close();
}
}
finally {
fileOutStream.close();
}
},
extractZipArchive: function SysUtils_extractZipArchive(archiveFile, destDirFile) {
if ( !(archiveFile instanceof this._Ci.nsIFile) || !(destDirFile instanceof this._Ci.nsIFile) )
throw new TypeError("nsIFile required");
function getItemFile(filePath) {
var itemLocation = destDirFile.clone();
var parts = filePath.split("/");
for (var i = 0; i < parts.length; ++i)
itemLocation.append(parts[i]);
return itemLocation;
}
var zReader = this._Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(this._Ci.nsIZipReader);
zReader.open(archiveFile);
try {
let entries = zReader.findEntries("*/");
while (entries.hasMore()) {
var entryName = entries.getNext();
var target = getItemFile(entryName);
if (!target.exists()) {
target.create(Ci.nsILocalFile.DIRECTORY_TYPE, destDirFile.permissions);
}
}
entries = zReader.findEntries(null);
while (entries.hasMore()) {
var entryName = entries.getNext();
target = getItemFile(entryName);
if (target.exists())
continue;
target.create(Ci.nsILocalFile.DIRECTORY_TYPE, destDirFile.permissions);
zReader.extract(entryName, target);
}
}
finally {
zReader.close();
}
},
xmlDocFromFile: function SysUtils_xmlDocFromFile(file) {
file = file.QueryInterface(this._Ci.nsILocalFile);
var inStream = this._Cc["@mozilla.org/network/file-input-stream;1"].createInstance(this._Ci.nsIFileInputStream);
inStream.init(file, 0x01, 0600, 0);
return this.xmlDocFromStream(inStream, null, null);
},
xmlDocFromStream: function SysUtils_xmlDocFromStream(docStream, docURI, baseURI) {
docStream = docStream.QueryInterface(this._Ci.nsIInputStream);
try {
var domParser = XB._Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(this._Ci.nsIDOMParser);
if (docURI || baseURI)
domParser.init(null, docURI, baseURI);
var XMLDoc = domParser.parseFromStream(docStream, null, docStream.available(), "text/xml");
if (XMLDoc.documentElement.localName == "parsererror")
throw new Error(XMLDoc.documentElement.textContent);
return XMLDoc;
}
finally {
docStream.close();
}
},
createFixupURIFromString: function SysUtils_createFixupURIFromString(aString) {
let uri = null;
if (aString) {
let URIFixup = this._Cc["@mozilla.org/docshell/urifixup;1"].getService(this._Ci.nsIURIFixup);
try {
uri = URIFixup.createFixupURI(aString, URIFixup.FIXUP_FLAG_NONE);
} catch(e) {}
}
return uri;
},
insertBreaksInString: function(s) {
return ("" + s || "").replace(/^\s+/, '')
.replace(/\s+$/, '')
.replace(/([\/\-&\?\.])/g, "$1\u200B")
.replace(/(\S{5})(\S{5})/g, "$1\u200B$2");
},
normalizeString: function(s) {
return s ? s.replace(/^[\u0020\n\r\t]*/, "").replace(/[\u0020\n\r\t]+/g, " ").replace(/[\u0020\n\r\t]*$/, "") : "";
},
trimSpaces: function SysUtils_trimSpaces(s) {
return s ? s.replace(/^[\u0020\n\r\t]*/, "").replace(/[\u0020\n\r\t]*$/, "") : "";
},
trimAllSpaces: function SysUtils_trimAllSpaces(s) {
return s ? s.replace(/^\s\s*/, "").replace(/\s\s*$/, "") : "";
},
strcmp: function SysUtils_strcmp(str1, str2) {
if ( !(this.isString(str1) && this.isString(str2)) )
throw new TypeError("Strings expected");
return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
},
strdup: function SysUtils_strdup(str, num) {
var result = "";
for (; num > 0; num--)
result += str;
return result;
},
isEmptyObject: function SysUtils_isEmptyObject(obj) {
return this.objectsAreEqual(obj, this._emptyObj);
},
objectsAreEqual: function SysUtils_objectsAreEqual(obj1, obj2) {
if (typeof obj1 != "object" || typeof obj2 != "object")
throw new TypeError("Objects expected");
var props1 = [],
props2 = [];
for (let propName in obj1)
props1.push(propName);
for (let propName in obj2)
props2.push(propName);
if (props1.length != props2.length)
return false;
var prop1, prop2;
for each (let propName in props1) {
if ( !(propName in obj2) )
return false;
prop1 = obj1[propName];
prop2 = obj2[propName];
if ( (typeof prop1 == "object") && (typeof prop2 == "object") ) {
if ( !this.objectsAreEqual(prop1, prop2) )
return false;
}
else {
if (prop1 !== prop2)
return false;
}
}
return true;
},
copyObj: function SysUtils_copyObj(src, deep) {
if ( !(src instanceof Object) )
throw new TypeError("Object required");
var result = new src.constructor(src);
for (let propName in src) {
let prop = src[propName];
result[propName] = (deep && (prop instanceof Object))? this.copyObj(prop): prop;
}
return result;
},
isNumber: function SysUtils_isNumber(x) {
return (typeof x == "number");
},
isString: function SysUtils_isString(x) {
return (typeof x == "string");
},
isBool: function SysUtils_isBool(x) {
return (typeof x == "boolean");
},
RegExp: {
_escapeRe: /([.*+?^=!:${}()|[\]\/\\])/g,
escape: function(aString) {
return String(aString).replace(this._escapeRe, '\\$1');
},
createFromString: function(aString, aFlags) {
return new RegExp(this.escape(aString), aFlags);
}
},
_emptyObj: {},
_Ci: Components.interfaces,
_Cc: Components.classes
};
var sysutils = new SysUtils();