Commit 9af21a00 authored by skylined@chromium.org's avatar skylined@chromium.org

Style guide compliance


Review URL: http://codereview.chromium.org/92150

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@14466 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e4bc468
......@@ -2,45 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function download(sURL, sPath, verbose) {
function Download(url, path, verbose) {
if (verbose) {
WScript.StdOut.Write(" * GET " + sURL + "...");
WScript.StdOut.Write(" * GET " + url + "...");
}
var oResponseBody = null;
var response_body = null;
try {
oXMLHTTP = new ActiveXObject("MSXML2.ServerXMLHTTP");
xml_http = new ActiveXObject("MSXML2.ServerXMLHTTP");
} catch (e) {
WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() +
": Cannot create Active-X object (" + e.description) + ").";
WScript.Quit(1);
}
try {
oXMLHTTP.open("GET", sURL, false);
xml_http.open("GET", url, false);
} catch (e) {
WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() +
": invalid URL.");
WScript.Quit(1);
}
var sSize = "?";
var iSize
var size_description = "?";
var file_size
try {
oXMLHTTP.send(null);
if (oXMLHTTP.status != 200) {
WScript.StdOut.WriteLine("[-] HTTP " + oXMLHTTP.status + " " +
oXMLHTTP.statusText);
xml_http.send(null);
if (xml_http.status != 200) {
WScript.StdOut.WriteLine("[-] HTTP " + xml_http.status + " " +
xml_http.statusText);
WScript.Quit(1);
}
oResponseBody = oXMLHTTP.responseBody;
sSize = oXMLHTTP.getResponseHeader("Content-Length");
if (sSize != "") {
iSize = parseInt(sSize)
sSize = iSize.toBytes();
response_body = xml_http.responseBody;
size_description = xml_http.getResponseHeader("Content-Length");
if (size_description != "") {
file_size = parseInt(size_description)
size_description = file_size.toBytes();
} else {
try {
iSize = new Number(oXMLHTTP.responseText.length)
sSize = iSize.toBytes();
file_size = new Number(xml_http.responseText.length)
size_description = file_size.toBytes();
} catch(e) {
sSize = "unknown size";
size_description = "unknown size";
}
}
} catch (e) {
......@@ -50,27 +50,27 @@ function download(sURL, sPath, verbose) {
}
if (verbose) {
WScript.StdOut.WriteLine("ok (" + sSize + ").");
WScript.StdOut.Write(" * Save " + sPath + "...");
WScript.StdOut.WriteLine("ok (" + size_description + ").");
WScript.StdOut.Write(" * Save " + path + "...");
}
try {
var oAS = new ActiveXObject("ADODB.Stream");
oAS.Mode = 3; // ReadWrite
oAS.Type = 1; // 1= Binary
oAS.Open(); // Open the stream
oAS.Write(oResponseBody); // Write the data
oAS.SaveToFile(sPath, 2); // Save to our destination
oAS.Close();
var adodb_stream = new ActiveXObject("ADODB.Stream");
adodb_stream.Mode = 3; // ReadWrite
adodb_stream.Type = 1; // 1= Binary
adodb_stream.Open(); // Open the stream
adodb_stream.Write(response_body); // Write the data
adodb_stream.SaveTfile(path, 2); // Save to our destination
adodb_stream.Close();
} catch(e) {
WScript.StdOut.WriteLine("[-] ADODB.Stream " + new Number(e.number).toHex() +
": Cannot save file (" + e.description + ")");
WScript.StdOut.WriteLine("[-] ADODB.Stream " + new Number(
e.number).toHex() + ": Cannot save file (" + e.description + ")");
WScript.Quit(1);
}
if (typeof(iSize) != undefined) {
oFSO = WScript.CreateObject("Scripting.FileSystemObject")
oFile = oFSO.GetFile(sPath)
if (oFile.Size < iSize) {
if (typeof(file_size) != undefined) {
file_system_object = WScript.CreateObject("Scripting.FileSystemObject")
file = file_system_object.GetFile(path)
if (file.Size < file_size) {
WScript.StdOut.WriteLine("[-] File only partially downloaded.");
WScript.Quit(1);
}
......@@ -80,35 +80,37 @@ function download(sURL, sPath, verbose) {
}
}
Number.prototype.isInt = function Number_isInt() {
Number.prototype.isInt = function NumberIsInt() {
return this % 1 == 0;
};
Number.prototype.toBytes = function Number_toBytes() {
Number.prototype.toBytes = function NumberToBytes() {
// Returns a "pretty" string representation of a number of bytes:
var aUnits = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var sUnit = "bytes";
var iLimit = 1;
while(this > iLimit * 1100 && aUnits.length > 0) {
iLimit *= 1024;
sUnit = aUnits.shift();
var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var unit = "bytes";
var limit = 1;
while(this > limit * 1100 && units.length > 0) {
limit *= 1024;
unit = units.shift();
}
return (Math.round(this * 100 / iLimit) / 100).toString() + " " + sUnit;
return (Math.round(this * 100 / limit) / 100).toString() + " " + unit;
};
Number.prototype.toHex = function Number_toHex(nLength) {
if (arguments.length == 0) nLength = 1;
if (typeof(nLength) != "number" && !(nLength instanceof Number)) {
throw Exception("Length must be a positive integer larger than 0.", TypeError, 0);
Number.prototype.toHex = function NumberToHex(length) {
if (arguments.length == 0) length = 1;
if (typeof(length) != "number" && !(length instanceof Number)) {
throw Exception("Length must be a positive integer larger than 0.",
TypeError, 0);
}
if (nLength < 1 || !nLength.isInt()) {
throw Exception("Length must be a positive integer larger than 0.", "RangeError", 0);
if (length < 1 || !length.isInt()) {
throw Exception("Length must be a positive integer larger than 0.",
"RangeError", 0);
}
var sResult = (this + (this < 0 ? 0x100000000 : 0)).toString(16);
while (sResult.length < nLength) sResult = "0" + sResult;
return sResult;
var result = (this + (this < 0 ? 0x100000000 : 0)).toString(16);
while (result.length < length) result = "0" + result;
return result;
};
if (WScript.Arguments.length != 2) {
WScript.StdOut.Write("Incorrect arguments to download.js")
} else {
download(WScript.Arguments(0), WScript.Arguments(1), false);
Download(WScript.Arguments(0), WScript.Arguments(1), false);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment