File downloader
This commit is contained in:
@@ -20,8 +20,35 @@
|
|||||||
|
|
||||||
|
|
||||||
@interface Controller : NSObject {
|
@interface Controller : NSObject {
|
||||||
|
// Main Window
|
||||||
|
NSString *localDownloadPath;
|
||||||
|
NSString *packageDirectory;
|
||||||
|
NSURLDownload *currentDownload;
|
||||||
|
long long expectedData;
|
||||||
|
long long downloadedData;
|
||||||
|
BOOL downloading;
|
||||||
|
|
||||||
|
|
||||||
|
IBOutlet NSWindow *mainWindow;
|
||||||
|
|
||||||
|
// Download Sheet
|
||||||
|
IBOutlet NSWindow *downloadSheet;
|
||||||
|
IBOutlet id infoText;
|
||||||
|
IBOutlet id downloadButton;
|
||||||
|
IBOutlet id cancelButton;
|
||||||
|
|
||||||
|
IBOutlet id downloadBar;
|
||||||
|
IBOutlet id statusText;
|
||||||
|
IBOutlet id abortButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(IBAction)showDownloadSheet:(id)sender;
|
||||||
|
- (IBAction)dismissDownloadSheet:(id)sender;
|
||||||
|
|
||||||
|
|
||||||
-(IBAction)launchApp:(id)sender;
|
-(IBAction)launchApp:(id)sender;
|
||||||
|
- (IBAction)startDownload:(id)sender;
|
||||||
|
- (IBAction)stopDownload:(id)sender;
|
||||||
|
- (void)extractPackages;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -27,5 +27,117 @@
|
|||||||
[NSApp terminate: nil];
|
[NSApp terminate: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(IBAction)showDownloadSheet:(id)sender
|
||||||
|
{
|
||||||
|
[NSApp beginSheet:downloadSheet modalForWindow:mainWindow
|
||||||
|
modalDelegate:self didEndSelector:NULL contextInfo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)dismissDownloadSheet:(id)sender
|
||||||
|
{
|
||||||
|
[NSApp endSheet:downloadSheet];
|
||||||
|
[downloadSheet orderOut:self];
|
||||||
|
[downloadSheet performClose:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)startDownload:(id)sender
|
||||||
|
{
|
||||||
|
// Change the sheet items
|
||||||
|
[downloadBar setHidden:NO];
|
||||||
|
[abortButton setHidden:NO];
|
||||||
|
[statusText setHidden:NO];
|
||||||
|
[infoText setHidden:YES];
|
||||||
|
[downloadButton setHidden:YES];
|
||||||
|
[cancelButton setHidden:YES];
|
||||||
|
|
||||||
|
// Create a request
|
||||||
|
NSURL *remoteURL = [NSURL URLWithString:@"http://open-ra.org/packages/ra-packages.zip"];
|
||||||
|
localDownloadPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"ra-packages.zip"];
|
||||||
|
packageDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mods/ra/packages/"];
|
||||||
|
|
||||||
|
NSLog(@"Downloading to %@",localDownloadPath);
|
||||||
|
NSURLRequest *theRequest=[NSURLRequest requestWithURL:remoteURL
|
||||||
|
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
||||||
|
timeoutInterval:60.0];
|
||||||
|
|
||||||
|
// Create a download object
|
||||||
|
currentDownload = [[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
|
||||||
|
|
||||||
|
if (currentDownload)
|
||||||
|
{
|
||||||
|
downloading = YES;
|
||||||
|
[currentDownload setDestination:localDownloadPath allowOverwrite:YES];
|
||||||
|
[statusText setStringValue:@"Connecting..."];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[statusText setStringValue:@"Cannot connect to server"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)stopDownload:(id)sender
|
||||||
|
{
|
||||||
|
// Stop the download
|
||||||
|
if (downloading)
|
||||||
|
[currentDownload cancel];
|
||||||
|
|
||||||
|
// Update the sheet status
|
||||||
|
[downloadBar setHidden:YES];
|
||||||
|
[abortButton setHidden:YES];
|
||||||
|
[statusText setHidden:YES];
|
||||||
|
[infoText setHidden:NO];
|
||||||
|
[downloadButton setHidden:NO];
|
||||||
|
[cancelButton setHidden:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark === Download Delegate Methods ===
|
||||||
|
|
||||||
|
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
|
||||||
|
{
|
||||||
|
[download release]; downloading = NO;
|
||||||
|
[statusText setStringValue:@"Error downloading file"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)downloadDidFinish:(NSURLDownload *)download
|
||||||
|
{
|
||||||
|
[download release]; downloading = NO;
|
||||||
|
[self extractPackages];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)extractPackages
|
||||||
|
{
|
||||||
|
[abortButton setEnabled:NO];
|
||||||
|
[downloadBar setDoubleValue:0];
|
||||||
|
[downloadBar setMaxValue:1];
|
||||||
|
[downloadBar setIndeterminate:YES];
|
||||||
|
[statusText setStringValue:@"Extracting..."];
|
||||||
|
|
||||||
|
// TODO: Extract and copy files
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
|
||||||
|
{
|
||||||
|
expectedData = [response expectedContentLength];
|
||||||
|
if (expectedData > 0.0)
|
||||||
|
{
|
||||||
|
downloadedData = 0;
|
||||||
|
[downloadBar setIndeterminate:NO];
|
||||||
|
[downloadBar setMaxValue:expectedData];
|
||||||
|
[downloadBar setDoubleValue:downloadedData];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
|
||||||
|
{
|
||||||
|
downloadedData += length;
|
||||||
|
if (downloadedData >= expectedData)
|
||||||
|
{
|
||||||
|
[downloadBar setIndeterminate:YES];
|
||||||
|
[statusText setStringValue:@"Downloading..."];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[downloadBar setDoubleValue:downloadedData];
|
||||||
|
[statusText setStringValue:[NSString stringWithFormat:@"Downloading %.1f of %f",downloadedData,expectedData]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
|
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
|
||||||
256AC3DA0F4B6AC300CF3369 /* OpenRAAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* OpenRAAppDelegate.m */; };
|
|
||||||
8990E7AF1151C0F20089C198 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 8990E7AE1151C0F20089C198 /* Controller.m */; };
|
8990E7AF1151C0F20089C198 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 8990E7AE1151C0F20089C198 /* Controller.m */; };
|
||||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||||
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
|
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
|
||||||
@@ -22,8 +21,6 @@
|
|||||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||||
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
||||||
1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||||
256AC3D80F4B6AC300CF3369 /* OpenRAAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenRAAppDelegate.h; sourceTree = "<group>"; };
|
|
||||||
256AC3D90F4B6AC300CF3369 /* OpenRAAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OpenRAAppDelegate.m; sourceTree = "<group>"; };
|
|
||||||
256AC3F00F4B6AF500CF3369 /* OpenRA_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenRA_Prefix.pch; sourceTree = "<group>"; };
|
256AC3F00F4B6AF500CF3369 /* OpenRA_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenRA_Prefix.pch; sourceTree = "<group>"; };
|
||||||
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||||
@@ -53,8 +50,6 @@
|
|||||||
children = (
|
children = (
|
||||||
8990E7AD1151C0F20089C198 /* Controller.h */,
|
8990E7AD1151C0F20089C198 /* Controller.h */,
|
||||||
8990E7AE1151C0F20089C198 /* Controller.m */,
|
8990E7AE1151C0F20089C198 /* Controller.m */,
|
||||||
256AC3D80F4B6AC300CF3369 /* OpenRAAppDelegate.h */,
|
|
||||||
256AC3D90F4B6AC300CF3369 /* OpenRAAppDelegate.m */,
|
|
||||||
);
|
);
|
||||||
name = Classes;
|
name = Classes;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -193,7 +188,7 @@
|
|||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "DIR=`pwd`\ncd ../../../\nmake clean\nmake all\nmake dist-osx\ncp -r OpenRA.app ${TARGET_BUILD_DIR}/OpenRA.app/Contents/Resources/";
|
shellScript = "cd ../../../\n#make clean\n#make all\n#make dist-osx\ncp -r OpenRA.app ${TARGET_BUILD_DIR}/OpenRA.app/Contents/Resources/";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
@@ -204,7 +199,6 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
8D11072D0486CEB800E47090 /* main.m in Sources */,
|
8D11072D0486CEB800E47090 /* main.m in Sources */,
|
||||||
256AC3DA0F4B6AC300CF3369 /* OpenRAAppDelegate.m in Sources */,
|
|
||||||
8990E7AF1151C0F20089C198 /* Controller.m in Sources */,
|
8990E7AF1151C0F20089C198 /* Controller.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@@ -272,7 +266,7 @@
|
|||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
PREBINDING = NO;
|
PREBINDING = NO;
|
||||||
SDKROOT = macosx10.6;
|
SDKROOT = macosx10.5;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
@@ -284,7 +278,7 @@
|
|||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
PREBINDING = NO;
|
PREBINDING = NO;
|
||||||
SDKROOT = macosx10.6;
|
SDKROOT = macosx10.5;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
|
||||||
* This file is part of OpenRA.
|
|
||||||
*
|
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
|
|
||||||
@interface OpenRAAppDelegate : NSObject <NSApplicationDelegate> {
|
|
||||||
NSWindow *window;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property (assign) IBOutlet NSWindow *window;
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
|
||||||
* This file is part of OpenRA.
|
|
||||||
*
|
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import "OpenRAAppDelegate.h"
|
|
||||||
|
|
||||||
@implementation OpenRAAppDelegate
|
|
||||||
|
|
||||||
@synthesize window;
|
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
||||||
// Insert code here to initialize your application
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -16,7 +16,7 @@ MODS_INCLUDE_FILES="find mods/$m ! -name \"*.mdb\" ! -name \"packages\""
|
|||||||
GAC_DYLIBS="/Library/Frameworks/Mono.framework/Versions/2.6.1/lib/libMonoPosixHelper.dylib /Library/Frameworks/Mono.framework/Versions/2.6.1/lib/libgdiplus.dylib"
|
GAC_DYLIBS="/Library/Frameworks/Mono.framework/Versions/2.6.1/lib/libMonoPosixHelper.dylib /Library/Frameworks/Mono.framework/Versions/2.6.1/lib/libgdiplus.dylib"
|
||||||
|
|
||||||
# Remove old app bundle
|
# Remove old app bundle
|
||||||
rm -r OpenRA.app OpenRA
|
rm -r OpenRA.app
|
||||||
|
|
||||||
# Recursively modify and copy the mono files depended on by OpenRA into the app bundle
|
# Recursively modify and copy the mono files depended on by OpenRA into the app bundle
|
||||||
function patch_mono {
|
function patch_mono {
|
||||||
|
|||||||
Reference in New Issue
Block a user