source: branches/CoreData/SapphireFrappliance/FRAppliance/SapphireAppliance.m @ 570

Revision 570, 7.2 KB checked in by gbooker, 6 years ago (diff)

Upgrading metadata isn't done when finder starts anymore

Line 
1/*
2 * SapphireAppliance.m
3 * Sapphire
4 *
5 * Created by pnmerrill on Jun. 20, 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
22#import "SapphireAppliance.h"
23#import "SapphireApplianceController.h"
24#import <BackRow/BackRow.h>
25#import <objc/objc-class.h>
26#import <SapphireCompatClasses/SapphireFrontRowCompat.h>
27#import "SapphireMetaDataUpgrading.h"
28
29#import <SapphireCompatClasses/BackRowUtils.h>
30
31#define TV_SHOW_IDENTIFIER      @"tv-shows"
32#define MOVIES_IDENTIFIER       @"movies"
33#define COLLECTIONS_IDENTIFIER  @"mounts"
34#define IMPORTER_IDENTIFIER     @"importer"
35#define SETTINGS_IDENTIFIER     @"settings"
36#define UPGRADE_IDENTIFIER @"upgrade"
37
38// BRAppliance protocol
39@interface BRApplianceInfo
40+(id)infoForApplianceBundle:(id)bundle;
41-(id)applianceCategoryDescriptors;
42@end
43
44@interface BRApplianceCategory
45+(id)categoryWithName:(NSString *)name identifier:(NSString *)identifier preferredOrder:(float)order;
46-(void)setIsStoreCategory:(BOOL)isStoreCategory;
47-(void)setIsDefaultCategory:(BOOL)isDefaultCategory;
48-(void)setShouldDisplayOnStartup:(BOOL)shouldDisplayOnStartup;
49@end
50
51
52@implementation SapphireAppliance
53
54+ (void) initialize
55{
56        NSString *myBundlePath = [[NSBundle bundleForClass:[self class]] bundlePath];
57        NSString *frameworkPath = [myBundlePath stringByAppendingPathComponent:@"Contents/Frameworks"];
58        SapphireLoadFramework(frameworkPath);
59        Class cls = NSClassFromString( @"BRFeatureManager" );
60        if ( cls == Nil )
61                return;
62        [[cls sharedInstance] enableFeatureNamed: [[NSBundle bundleForClass: self] bundleIdentifier]];
63}
64
65+ (NSString *) className
66{
67        // get around the whitelist
68        // this function will get the real class name from the runtime, and
69        // will assuredly not recurse back to here
70        NSString * className = NSStringFromClass( self );
71   
72        // BackRow has its own exception class which provides backtrace
73        // helpers. It returns a parsed trace, with function names. We'll
74        // look for the name of the function which is known to call this
75        // function to check against the whitelist, and if we find it we'll
76        // lie about our name, purely to escape that check.
77        // Also, the backtracer method is a class routine, meaning that we
78        // don't have to even generate an exception - woohoo!
79        NSString *backtrace = [BRBacktracingException backtrace];
80        NSRange range = [backtrace rangeOfString: @"_loadApplianceInfoAtPath:"];
81        if ( range.location != NSNotFound )
82        {
83                // this is the whitelist check -- tell a Great Big Fib
84                className = @"RUIMoviesAppliance";     // could be anything in the whitelist, really
85        }
86        if (range.location == NSNotFound)
87        {
88                //code from ATVFiles. Thx!
89                range = [backtrace rangeOfString: @"(in BackRow)"];
90                if(range.location != NSNotFound) {
91                        NSLog(@"+[%@ className] called for Leopard/ATV2 whitelist check, so I'm lying, m'kay?", className);
92                        // 10.5/ATV2 (and 1.1, but that's handled above)
93                        className = @"RUIDVDAppliance";
94                }
95        }
96        return ( className );
97}
98
99-(NSString *)applianceKey {
100        return @"SapphireAppliance";
101}
102
103-(NSString *)applianceName {
104        return @"SapphireAppliance";
105}
106
107- (NSString *) moduleIconName
108{
109        // replace this with your own icon name
110        return ( @"SapphireIcon.png" );
111}
112
113- (NSString *) moduleName
114{
115        // this doesn't appear to be actually *used*, but even so:
116        return ( BRLocalizedString(@"Sapphire", @"Main Menu item name") );
117}
118
119+ (NSString *) moduleKey
120{
121        // change this to match your CFBundleIdentifier
122        return ( @"Nanopi.net.UCIJoker.Sapphire" );
123}
124
125- (NSString *) moduleKey
126{
127        return ( [SapphireAppliance moduleKey] );
128}
129
130static SapphireApplianceController *mainCont = nil;
131- (id)applianceController
132{
133        @try {
134                mainCont = [[[SapphireApplianceController alloc] initWithScene: nil] autorelease];
135        }
136        @catch (NSException * e) {
137                [SapphireApplianceController logException:e];
138        }
139       
140        return mainCont;
141}
142
143- (id) applianceControllerWithScene: (id) scene
144{
145        // this function is called when your item is selected on the main menu
146        return ( [[[SapphireApplianceController alloc] initWithScene: scene] autorelease] );
147}
148
149/**
150 * This implements the BRAppliance protocol from ATV2.
151 */
152-(id)applianceInfo {
153        BRApplianceInfo* p = [BRApplianceInfo infoForApplianceBundle:[NSBundle bundleForClass:[self class]]];
154        NSMutableArray *categories = [NSMutableArray array];
155       
156        NSEnumerator *enumerator = [[p applianceCategoryDescriptors] objectEnumerator];
157        id obj;
158        while((obj = [enumerator nextObject]) != nil) {
159                BRApplianceCategory *category = [BRApplianceCategory categoryWithName:[obj valueForKey:@"name"] identifier:[obj valueForKey:@"identifier"] preferredOrder:[[obj valueForKey:@"preferred-order"] floatValue]];
160                [categories addObject:category];
161        }
162        [[self applianceController] setToMountsOnly];
163        return [BRApplianceInfo infoForApplianceBundle:[NSBundle bundleForClass:[self class]]];
164}
165
166-(id)applianceCategories {
167        NSMutableArray *categories = [NSMutableArray array];
168       
169        if([[self applianceController] upgradeNeeded])
170        {
171                categories = [NSArray arrayWithObject:
172                                          [BRApplianceCategory categoryWithName:BRLocalizedString(@"Upgrade Metadata", @"") identifier:UPGRADE_IDENTIFIER preferredOrder:1]];
173        }
174        else
175        {
176                NSEnumerator *enumerator = [[[self applianceInfo] applianceCategoryDescriptors] objectEnumerator];
177                id obj;
178                while((obj = [enumerator nextObject]) != nil) {
179                        BRApplianceCategory *category = [BRApplianceCategory categoryWithName:[obj valueForKey:@"name"] identifier:[obj valueForKey:@"identifier"] preferredOrder:[[obj valueForKey:@"preferred-order"] floatValue]];
180                        [categories addObject:category];
181                }               
182        }
183        [[self applianceController] setToMountsOnly];
184        return categories;
185}
186
187-(id)identifierForContentAlias:(id)fp8 {
188        return @"mounts";
189}
190
191-(id)controllerForIdentifier:(id)ident
192{
193        NSString *identifier = (NSString *)ident;
194        SapphireApplianceController *controller = [self applianceController];
195        if([identifier isEqualToString:UPGRADE_IDENTIFIER])
196        {
197                NSLog(@"Starting upgrade");
198                [mainCont release];
199                mainCont = nil;
200                return [[[SapphireMetaDataUpgrading alloc] initWithScene:nil title:BRLocalizedString(@"Importing Metadata", @"") text:BRLocalizedString(@"Importing Metadata", @"") showBack:NO isNetworkDependent:NO] autorelease];
201        }
202        if([identifier isEqualToString:TV_SHOW_IDENTIFIER])
203                return [controller tvBrowser];
204        if([identifier isEqualToString:MOVIES_IDENTIFIER])
205                return [controller movieBrowser];
206        if([identifier isEqualToString:IMPORTER_IDENTIFIER])
207                return [controller allImporter];
208        if([identifier isEqualToString:SETTINGS_IDENTIFIER])
209                return [controller settings];
210       
211        return controller;
212}
213
214-(id)initWithSettings:(id)settings {
215        return [super init];
216}
217
218-(id)version {
219        return @"1.0";
220}
221
222@end
Note: See TracBrowser for help on using the repository browser.