Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: bootstrap/win/get_file.js

Issue 102004: Fix a typo in get_files.js. Also fix style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 function Download(url, path, verbose) { 5 function Download(url, path, verbose) {
6 if (verbose) { 6 if (verbose) {
7 WScript.StdOut.Write(" * GET " + url + "..."); 7 WScript.StdOut.Write(" * GET " + url + "...");
8 } 8 }
9 var response_body = null;
10 try { 9 try {
11 xml_http = new ActiveXObject("MSXML2.ServerXMLHTTP"); 10 xml_http = new ActiveXObject("MSXML2.ServerXMLHTTP");
12 } catch (e) { 11 } catch (e) {
13 WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() + 12 WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() +
14 ": Cannot create Active-X object (" + e.description) + ")."; 13 ": Cannot create Active-X object (" + e.description) + ").";
15 WScript.Quit(1); 14 WScript.Quit(1);
16 } 15 }
17 try { 16 try {
18 xml_http.open("GET", url, false); 17 xml_http.open("GET", url, false);
19 } catch (e) { 18 } catch (e) {
20 WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() + 19 WScript.StdOut.WriteLine("[-] XMLHTTP " + new Number(e.number).toHex() +
21 ": invalid URL."); 20 ": invalid URL.");
22 WScript.Quit(1); 21 WScript.Quit(1);
23 } 22 }
23
24 var response_body = null;
24 var size_description = "?"; 25 var size_description = "?";
25 var file_size 26 var file_size;
26 try { 27 try {
27 xml_http.send(null); 28 xml_http.send(null);
28 if (xml_http.status != 200) { 29 if (xml_http.status != 200) {
29 WScript.StdOut.WriteLine("[-] HTTP " + xml_http.status + " " + 30 WScript.StdOut.WriteLine("[-] HTTP " + xml_http.status + " " +
30 xml_http.statusText); 31 xml_http.statusText);
31 WScript.Quit(1); 32 WScript.Quit(1);
32 } 33 }
33 response_body = xml_http.responseBody; 34 response_body = xml_http.responseBody;
34 size_description = xml_http.getResponseHeader("Content-Length"); 35 size_description = xml_http.getResponseHeader("Content-Length");
35 if (size_description != "") { 36 if (size_description != "") {
(...skipping 17 matching lines...) Expand all
53 WScript.StdOut.WriteLine("ok (" + size_description + ")."); 54 WScript.StdOut.WriteLine("ok (" + size_description + ").");
54 WScript.StdOut.Write(" * Save " + path + "..."); 55 WScript.StdOut.Write(" * Save " + path + "...");
55 } 56 }
56 57
57 try { 58 try {
58 var adodb_stream = new ActiveXObject("ADODB.Stream"); 59 var adodb_stream = new ActiveXObject("ADODB.Stream");
59 adodb_stream.Mode = 3; // ReadWrite 60 adodb_stream.Mode = 3; // ReadWrite
60 adodb_stream.Type = 1; // 1= Binary 61 adodb_stream.Type = 1; // 1= Binary
61 adodb_stream.Open(); // Open the stream 62 adodb_stream.Open(); // Open the stream
62 adodb_stream.Write(response_body); // Write the data 63 adodb_stream.Write(response_body); // Write the data
63 adodb_stream.SaveTfile(path, 2); // Save to our destination 64 adodb_stream.SaveToFile(path, 2); // Save to our destination
64 adodb_stream.Close(); 65 adodb_stream.Close();
65 } catch(e) { 66 } catch(e) {
66 WScript.StdOut.WriteLine("[-] ADODB.Stream " + new Number( 67 WScript.StdOut.WriteLine("[-] ADODB.Stream " + new Number(
67 e.number).toHex() + ": Cannot save file (" + e.description + ")"); 68 e.number).toHex() + ": Cannot save file (" + e.description + ")");
68 WScript.Quit(1); 69 WScript.Quit(1);
69 } 70 }
70 if (typeof(file_size) != undefined) { 71 if (typeof(file_size) != undefined) {
71 file_system_object = WScript.CreateObject("Scripting.FileSystemObject") 72 var file_system_object = WScript.CreateObject("Scripting.FileSystemObject")
72 file = file_system_object.GetFile(path) 73 var file = file_system_object.GetFile(path)
73 if (file.Size < file_size) { 74 if (file.Size < file_size) {
74 WScript.StdOut.WriteLine("[-] File only partially downloaded."); 75 WScript.StdOut.WriteLine("[-] File only partially downloaded.");
75 WScript.Quit(1); 76 WScript.Quit(1);
76 } 77 }
77 } 78 }
78 if (verbose) { 79 if (verbose) {
79 WScript.StdOut.WriteLine("ok."); 80 WScript.StdOut.WriteLine("ok.");
80 } 81 }
81 } 82 }
82 83
84 // Utilities
83 Number.prototype.isInt = function NumberIsInt() { 85 Number.prototype.isInt = function NumberIsInt() {
84 return this % 1 == 0; 86 return this % 1 == 0;
85 }; 87 };
86 Number.prototype.toBytes = function NumberToBytes() { 88 Number.prototype.toBytes = function NumberToBytes() {
87 // Returns a "pretty" string representation of a number of bytes: 89 // Returns a "pretty" string representation of a number of bytes:
88 var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; 90 var units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
89 var unit = "bytes"; 91 var unit = "bytes";
90 var limit = 1; 92 var limit = 1;
91 while(this > limit * 1100 && units.length > 0) { 93 while(this > limit * 1100 && units.length > 0) {
92 limit *= 1024; 94 limit *= 1024;
(...skipping 14 matching lines...) Expand all
107 var result = (this + (this < 0 ? 0x100000000 : 0)).toString(16); 109 var result = (this + (this < 0 ? 0x100000000 : 0)).toString(16);
108 while (result.length < length) result = "0" + result; 110 while (result.length < length) result = "0" + result;
109 return result; 111 return result;
110 }; 112 };
111 113
112 if (WScript.Arguments.length != 2) { 114 if (WScript.Arguments.length != 2) {
113 WScript.StdOut.Write("Incorrect arguments to download.js") 115 WScript.StdOut.Write("Incorrect arguments to download.js")
114 } else { 116 } else {
115 Download(WScript.Arguments(0), WScript.Arguments(1), false); 117 Download(WScript.Arguments(0), WScript.Arguments(1), false);
116 } 118 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698