forked from mirror/smcFanControl
Added new sparkle version, deprecated 10.5 and 32 Bit support,
converted to ARC, fixed some memory management issues, Donation Reminder Screen
This commit is contained in:
@ -23,59 +23,60 @@
|
||||
#import "MachineDefaults.h"
|
||||
#import "NSFileManager+DirectoryLocations.h"
|
||||
|
||||
@interface MachineDefaults ()
|
||||
{
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MachineDefaults
|
||||
|
||||
|
||||
- (id)init:(NSString*)p_machine{
|
||||
- (instancetype)init:(NSString*)p_machine{
|
||||
if (self = [super init]){
|
||||
machine=[MachineDefaults computerModel];
|
||||
supported_machines=[[NSArray alloc] initWithContentsOfFile:[[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"]];
|
||||
[self refreshPlist];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
-(Boolean)is_supported{
|
||||
int i;
|
||||
supported=NO;
|
||||
for(i=0;i<[supported_machines count];i++) {
|
||||
if ([machine isEqualToString:[[supported_machines objectAtIndex:i] objectForKey:@"Machine"]]) {
|
||||
supported=YES;
|
||||
machine_num=i;
|
||||
}
|
||||
}
|
||||
return supported;
|
||||
-(void)refreshPlist
|
||||
{
|
||||
supported_machines=[[NSArray alloc] initWithContentsOfFile:[[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"]];
|
||||
supported=NO;
|
||||
int i;
|
||||
for(i=0;i<[supported_machines count];i++) {
|
||||
if ([machine isEqualToString:supported_machines[i][@"Machine"]]) {
|
||||
supported=YES;
|
||||
machine_num=i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(NSDictionary*) readfrom_plist{
|
||||
-(NSDictionary*) readFromPlist{
|
||||
if (!supported) {return nil;}
|
||||
return [supported_machines objectAtIndex:machine_num];
|
||||
return supported_machines[machine_num];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(NSDictionary*) readfrom_smc{
|
||||
if (supported) {return nil;}
|
||||
int num_fans,i;
|
||||
[smcWrapper init];
|
||||
num_fans=[smcWrapper get_fan_num];
|
||||
-(void) readFromSMC{
|
||||
NSUInteger num_fans=[smcWrapper get_fan_num];
|
||||
NSString *desc;
|
||||
NSNumber *min,*max;
|
||||
NSData *xmldata;
|
||||
NSString *error;
|
||||
NSMutableArray *fans=[[NSMutableArray alloc] init];
|
||||
for (i = 0; i < num_fans; i++) {
|
||||
min=[NSNumber numberWithInt:[smcWrapper get_min_speed:i]];
|
||||
max=[NSNumber numberWithInt:[smcWrapper get_max_speed:i]];
|
||||
for (NSUInteger i = 0; i < num_fans; i++) {
|
||||
min=@([smcWrapper get_min_speed:i]);
|
||||
max=@([smcWrapper get_max_speed:i]);
|
||||
desc=[smcWrapper get_fan_descr:i];
|
||||
[fans addObject:[NSDictionary dictionaryWithObjectsAndKeys:desc,@"Description",min,@"Minspeed",max,@"Maxspeed",min,@"selspeed",nil]];
|
||||
[fans addObject:[[NSMutableDictionary alloc] initWithDictionary:@{@"Description": desc,@"Minspeed": min,@"Maxspeed": max,@"selspeed": min}]];
|
||||
}
|
||||
//save to plist for future
|
||||
NSMutableArray *supported_m=[[NSMutableArray alloc] initWithContentsOfFile:[[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"]];
|
||||
NSDictionary *new_machine= [NSDictionary dictionaryWithObjectsAndKeys:fans,@"Fans",[NSNumber numberWithInt:num_fans],@"NumFans",machine,@"Machine",@"Autogenerated",@"Comment",nil];
|
||||
[fans release];
|
||||
NSMutableDictionary *new_machine= [[NSMutableDictionary alloc] initWithDictionary:@{@"Fans": fans,@"NumFans": @(num_fans),@"Machine": machine,@"Comment": @"Autogenerated",@"Minspeed": min,@"Maxspeed": max}];
|
||||
[supported_m addObject:new_machine];
|
||||
|
||||
//save to plist
|
||||
@ -83,37 +84,36 @@
|
||||
format:NSPropertyListXMLFormat_v1_0
|
||||
errorDescription:&error];
|
||||
[xmldata writeToFile:[[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"Machines.plist"] atomically:YES];
|
||||
[supported_m release];
|
||||
//return new machine-live-data
|
||||
return new_machine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
-(NSDictionary*)get_machine_defaults{
|
||||
NSDictionary *m_defaults=nil;
|
||||
if ([self is_supported]) {
|
||||
m_defaults=[self readfrom_plist];
|
||||
int i;
|
||||
//localize fan-descriptions
|
||||
for (i=0;i<[[m_defaults objectForKey:@"Fans"] count];i++) {
|
||||
NSString *newvalue=NSLocalizedString([[[m_defaults objectForKey:@"Fans"] objectAtIndex:i] objectForKey:@"Description"],nil);
|
||||
[[[m_defaults objectForKey:@"Fans"] objectAtIndex:i] setValue:newvalue forKey:@"Description"];
|
||||
}
|
||||
} else {
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Alert!",nil)
|
||||
|
||||
if (!supported) {
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Alert!",nil)
|
||||
defaultButton:NSLocalizedString(@"Continue",nil) alternateButton:NSLocalizedString(@"Quit",nil) otherButton:nil
|
||||
informativeTextWithFormat:NSLocalizedString(@"smcFanControl has not been tested on this machine yet, but it should run if you follow the instructions. \n\nIf you choose to continue, please make you have no other FanControl-software running. Otherwise please quit, deinstall the other software, restart your machine and rerun smcFanControl!",nil)];
|
||||
int code=[alert runModal];
|
||||
if (code==NSAlertDefaultReturn) {
|
||||
m_defaults=[self readfrom_smc];
|
||||
NSModalResponse code=[alert runModal];
|
||||
if (code == NSAlertDefaultReturn) {
|
||||
[self readFromSMC];
|
||||
[self refreshPlist];
|
||||
} else {
|
||||
[[NSApplication sharedApplication] terminate:nil];
|
||||
}
|
||||
|
||||
}
|
||||
return m_defaults;
|
||||
|
||||
NSDictionary *defaultsDict=[self readFromPlist];
|
||||
NSUInteger i;
|
||||
//localize fan-descriptions
|
||||
for (i=0;i<[defaultsDict[@"Fans"] count];i++) {
|
||||
NSString *newvalue=NSLocalizedString(defaultsDict[@"Fans"][i][@"Description"],nil);
|
||||
[defaultsDict[@"Fans"][i] setValue:newvalue forKey:@"Description"];
|
||||
}
|
||||
|
||||
return defaultsDict;
|
||||
}
|
||||
|
||||
+ (NSString *)computerModel
|
||||
@ -124,18 +124,13 @@
|
||||
if ((pexpdev = IOServiceGetMatchingService (kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))))
|
||||
{
|
||||
NSData *data;
|
||||
if ((data = (id)IORegistryEntryCreateCFProperty(pexpdev, CFSTR("model"), kCFAllocatorDefault, 0))) {
|
||||
if ((data = (id)CFBridgingRelease(IORegistryEntryCreateCFProperty(pexpdev, CFSTR("model"), kCFAllocatorDefault, 0)))) {
|
||||
computerModel = [[NSString allocWithZone:NULL] initWithCString:[data bytes] encoding:NSASCIIStringEncoding];
|
||||
[data release];
|
||||
}
|
||||
}
|
||||
}
|
||||
return computerModel;
|
||||
}
|
||||
|
||||
- (void)dealloc{
|
||||
[super dealloc];
|
||||
//[supported_machines release];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user