Index: chrome/installer/mac/app/downloader.m |
diff --git a/chrome/installer/mac/app/downloader.m b/chrome/installer/mac/app/downloader.m |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c7fca4a4d4fc54232ef680ee3d76e620036ecd57 |
--- /dev/null |
+++ b/chrome/installer/mac/app/downloader.m |
@@ -0,0 +1,41 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import <Foundation/Foundation.h> |
+#import "downloader.h" |
+#import "parser.h" |
+ |
+NSURL* getChromeImageURL(NSData* someData) { |
+ Parser *parser = [[Parser alloc] init]; |
+ [parser parseXML:someData]; |
+ [parser appendFilenameToURL]; |
+ |
+ NSArray *downloadLinks = [NSArray arrayWithArray: parser.chromeDownloadURLs]; |
Elly Fong-Jones
2016/06/24 17:26:01
no space after colon
|
+ NSString *chromeURLString = [downloadLinks firstObject]; |
Elly Fong-Jones
2016/06/24 17:26:01
can downloadLinks ever be empty? What if parser fa
|
+ |
+ return [NSURL URLWithString: chromeURLString]; |
+} |
+ |
+NSData* downloadChromeAsData(NSURL* chromeURL) { |
+ return [NSData dataWithContentsOfURL:chromeURL]; |
Elly Fong-Jones
2016/06/24 17:26:01
[NSData dataWithContentsOfURL:] will do the entire
|
+} |
+ |
+NSString* getDownloadsFilePath() { |
+ NSArray *downloadPaths = NSSearchPathForDirectoriesInDomains( |
+ NSDownloadsDirectory, NSUserDomainMask, YES); |
+ NSString *downloadDirectory = [downloadPaths objectAtIndex:0]; |
+ NSString *filePath = [NSString stringWithFormat:@"%@/%@", |
+ downloadDirectory, @"GoogleChrome.dmg"]; |
Elly Fong-Jones
2016/06/24 17:26:01
I think it would be nicer to use [NSString pathWit
|
+ return filePath; |
+} |
+ |
+void writeDataToDisk(NSData* topSecretData) { |
Elly Fong-Jones
2016/06/24 17:26:01
is it really top secret? :)
|
+ if (topSecretData) { |
+ NSString *filePath = getDownloadsFilePath(); |
+ [topSecretData writeToFile:filePath atomically:YES]; |
+ NSLog(@"File was downloaded to %@.", filePath); |
+ } else { |
+ NSLog(@"Error downloading file."); |
+ } |
+} |