source: trunk/Software Loader/SLoadFrappInstaller.m @ 463

Revision 463, 3.2 KB checked in by gbooker, 6 years ago (diff)

Added the software loader

Line 
1/*
2 * SLoadFrappInstaller.m
3 * Software Loader
4 *
5 * Created by Graham Booker on Dec. 30 2007.
6 * Copyright 2007 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SLoadFrappInstaller.h"
22#import <SLoadUtilities/SLoadDelegateProtocol.h>
23#import <SLoadUtilities/NSData-HashSupport.h>
24#import <SLoadUtilities/SLoadDownloadDelegate.h>
25#import <SLoadUtilities/SLoadFileUtilities.h>
26
27@implementation SLoadFrappInstaller
28
29- (void) dealloc
30{
31        [installDict release];
32        [super dealloc];
33}
34
35enum{
36        FRAP_INSTALL_STAGE_DOWNLOAD = 0,
37        FRAP_INSTALL_STAGE_EXTRACTING,
38        FRAP_INSTALL_STAGE_INSTALL,
39        FRAP_INSTALL_STAGE_STAGES,
40};
41
42NSString *FrapInstallStrings[] = {
43        @"Downloading",
44        @"Extracting",
45        @"Installing",
46};
47
48#define FrapStageSet(stage) [delegate setStage:stage of:FRAP_INSTALL_STAGE_STAGES withName:BRLocalizedString(FrapInstallStrings[stage], nil)]
49
50- (void)install:(NSDictionary *)software
51{
52        [installDict release];
53        installDict = [software retain];
54        [delegate setHasDownload:YES];
55        FrapStageSet(FRAP_INSTALL_STAGE_DOWNLOAD);
56        NSString *downloadURL = [software objectForKey:INSTALL_URL_KEY];
57        NSString *md5 = [software objectForKey:INSTALL_MD5_KEY];
58        NSData *md5Data = [NSData dataFromHexString:md5];
59        if([md5Data length] != 16 || ![downloadURL length])
60        {
61                [self setError:BRLocalizedString(@"Could not locate download", @"URL not set error or the md5 hash is in an invalid format")];
62                [delegate instalFailed:[self error]];
63                return;
64        }
65        SLoadDownloadDelegate *downloadDelegate = [[SLoadDownloadDelegate alloc] initWithDest:@"/tmp/installtemp"];
66        [downloadDelegate setTarget:self success:@selector(installFrapDownloaded:) failure:@selector(downloadFailed:)];
67        [downloadDelegate setLoadDelegate:delegate];
68        [downloadDelegate setHash:md5Data];
69        downloader = [[fileUtils downloadURL:downloadURL withDelegate:downloadDelegate] retain];
70        [downloadDelegate release];
71}
72
73- (void)installFrapDownloaded:(NSString *)path
74{
75        [fileUtils remountReadWrite];
76        [downloader release];
77        downloader = nil;
78        [delegate downloadCompleted];
79        FrapStageSet(FRAP_INSTALL_STAGE_EXTRACTING);
80        BOOL success = YES;
81       
82        NSString *tmpPath = @"/tmp";
83        NSString *mypath = [[NSBundle mainBundle] bundlePath];
84        NSString *installPath = [mypath stringByDeletingLastPathComponent];
85        success = [fileUtils extract:path inDir:tmpPath];
86        FrapStageSet(FRAP_INSTALL_STAGE_INSTALL);
87        if(success)
88                success = [fileUtils move:[tmpPath stringByAppendingPathComponent:[installDict objectForKey:INSTALL_NAME_KEY]] toDir:installPath withReplacement:YES];
89        FrapStageSet(FRAP_INSTALL_STAGE_STAGES);
90        [fileUtils remountReadOnly];
91}
92
93@end
Note: See TracBrowser for help on using the repository browser.