Skip to content

Commit

Permalink
Added new sparkle version, deprecated 10.5 and 32 Bit support,
Browse files Browse the repository at this point in the history
converted to ARC, fixed some memory management issues, Donation
Reminder Screen
  • Loading branch information
hholtmann committed Oct 21, 2014
1 parent 4a94a92 commit f271718
Show file tree
Hide file tree
Showing 211 changed files with 1,456 additions and 2,242 deletions.
7 changes: 4 additions & 3 deletions Classes/FanControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@
IBOutlet id DefaultsController;

MachineDefaults *mdefaults;
NSDictionary *s_sed;

NSDictionary *undo_dic;

NSImage *menu_image;
NSImage *menu_image_alt;
}

@property (nonatomic, strong ) NSMutableDictionary *machineDefaultsDict;


-(void)terminate:(id)sender;

Expand Down Expand Up @@ -137,8 +138,8 @@


@interface NSNumber (NumberAdditions)
- (NSString *) tohex;
- (NSNumber*) celsius_fahrenheit;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *tohex;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSNumber *celsius_fahrenheit;

@end

209 changes: 104 additions & 105 deletions Classes/FanControl.m

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Classes/MachineDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
int machine_num;
}

+ (NSString *)computerModel;
- (id)init:(NSString*)p_machine;
-(NSDictionary*)get_machine_defaults;
- (void)dealloc;
+ (NSString *)computerModel;
- (instancetype)init:(NSString*)p_machine ;

@property (NS_NONATOMIC_IOSONLY, getter=get_machine_defaults, readonly, copy) NSDictionary *_machine_defaults;

@end
97 changes: 46 additions & 51 deletions Classes/MachineDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,97 +23,97 @@
#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
xmldata = [NSPropertyListSerialization dataFromPropertyList:supported_m
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
Expand All @@ -124,18 +124,13 @@ + (NSString *)computerModel
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
2 changes: 1 addition & 1 deletion Classes/NSFileManager+DirectoryLocations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
inDomain:(NSSearchPathDomainMask)domainMask
appendPathComponent:(NSString *)appendComponent
error:(NSError **)errorOut;
- (NSString *)applicationSupportDirectory;
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *applicationSupportDirectory;

@end
2 changes: 1 addition & 1 deletion Classes/NSFileManager+DirectoryLocations.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
*/
- (NSString *)applicationSupportDirectory
{
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSString *executableName = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];

NSError *error = nil;

Expand Down
5 changes: 2 additions & 3 deletions Classes/Power.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@

}

- (id)init;
- (instancetype)init NS_DESIGNATED_INITIALIZER;

- (id)delegate;
- (void)setDelegate:(id)new_delegate;
@property (NS_NONATOMIC_IOSONLY, unsafe_unretained) id delegate;

- (void)registerForSleepWakeNotification;
- (void)deregisterForSleepWakeNotification;
Expand Down
19 changes: 9 additions & 10 deletions Classes/Power.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation Power


void SleepWatcher( void * refCon, io_service_t service, natural_t messageType, void * messageArgument ){
[(Power *)refCon powerMessageReceived: messageType withArgument: messageArgument];
[(__bridge Power *)refCon powerMessageReceived: messageType withArgument: messageArgument];
}


Expand All @@ -48,14 +48,14 @@ static void powerSourceChanged(void * refCon)
powerSource = CFArrayGetValueAtIndex(powerSourcesList, i);
description = IOPSGetPowerSourceDescription(powerBlob, powerSource);
//work with NSArray from here
NSDictionary *n_description = (NSDictionary *)description;
[(Power *)refCon powerSourceMesssageReceived:n_description];
NSDictionary *n_description = (__bridge NSDictionary *)description;
[(__bridge Power *)refCon powerSourceMesssageReceived:n_description];
}
CFRelease(powerBlob);
CFRelease(powerSourcesList);
}

- (id)init{
- (instancetype)init{
if (self = [super init]) {

}
Expand All @@ -65,14 +65,14 @@ - (id)init{

- (void)registerForSleepWakeNotification
{
root_port = IORegisterForSystemPower(self, &notificationPort, SleepWatcher, &notifier);
root_port = IORegisterForSystemPower((__bridge void *)(self), &notificationPort, SleepWatcher, &notifier);
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopDefaultMode);
}


- (void)registerForPowerChange
{
powerNotifierRunLoopSource = IOPSNotificationCreateRunLoopSource(powerSourceChanged,self);
powerNotifierRunLoopSource = IOPSNotificationCreateRunLoopSource(powerSourceChanged,(__bridge void *)(self));
if (powerNotifierRunLoopSource) {
CFRunLoopAddSource(CFRunLoopGetCurrent(), powerNotifierRunLoopSource, kCFRunLoopDefaultMode);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ - (void)powerMessageReceived:(natural_t)messageType withArgument:(void *) messag
}

- (void)powerSourceMesssageReceived:(NSDictionary *)n_description{
if (([[n_description objectForKey:@"Power Source State"] isEqualToString:@"AC Power"] && [[n_description objectForKey:@"Is Charging"] intValue]==1) && lastsource!=1) {
if (([n_description[@"Power Source State"] isEqualToString:@"AC Power"] && [n_description[@"Is Charging"] intValue]==1) && lastsource!=1) {
lastsource=1;
if ([_delegate respondsToSelector:@selector(powerChangeToACLoading:)])
[_delegate powerChangeToACLoading:self];
Expand All @@ -129,7 +129,7 @@ - (void)powerSourceMesssageReceived:(NSDictionary *)n_description{
}


if (([[n_description objectForKey:@"Power Source State"] isEqualToString:@"AC Power"] && [[n_description objectForKey:@"Is Charging"] intValue]==0) && lastsource!=2) {
if (([n_description[@"Power Source State"] isEqualToString:@"AC Power"] && [n_description[@"Is Charging"] intValue]==0) && lastsource!=2) {
lastsource=2;
if ([_delegate respondsToSelector:@selector(powerChangeToAC:)])
[_delegate powerChangeToAC:self];
Expand All @@ -139,7 +139,7 @@ - (void)powerSourceMesssageReceived:(NSDictionary *)n_description{
}
}

if (([[n_description objectForKey:@"Power Source State"] isEqualToString:@"Battery Power"]) && lastsource!=3) {
if (([n_description[@"Power Source State"] isEqualToString:@"Battery Power"]) && lastsource!=3) {
lastsource=3;
if ([_delegate respondsToSelector:@selector(powerChangeToBattery:)])
[_delegate powerChangeToBattery:self];
Expand Down Expand Up @@ -171,7 +171,6 @@ - (void)dealloc
if (_delegate)
[nc removeObserver:_delegate name:nil object:self];

[super dealloc];
}


Expand Down
24 changes: 12 additions & 12 deletions Classes/SystemVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ + (void)initialize {
#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_3

#else // GTM_MACOS_SDK
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *systemVersionPlist
= [NSDictionary dictionaryWithContentsOfFile:kSystemVersionPlistPath];
NSString *version = [systemVersionPlist objectForKey:@"ProductVersion"];
NSArray *versionInfo = [version componentsSeparatedByString:@"."];
int length = [versionInfo count];
sGTMSystemVersionMajor = [[versionInfo objectAtIndex:0] intValue];
sGTMSystemVersionMinor = [[versionInfo objectAtIndex:1] intValue];
if (length == 3) {
sGTMSystemVersionBugFix = [[versionInfo objectAtIndex:2] intValue];
@autoreleasepool {
NSDictionary *systemVersionPlist
= [NSDictionary dictionaryWithContentsOfFile:kSystemVersionPlistPath];
NSString *version = systemVersionPlist[@"ProductVersion"];
NSArray *versionInfo = [version componentsSeparatedByString:@"."];
int length = [versionInfo count];
sGTMSystemVersionMajor = [versionInfo[0] intValue];
sGTMSystemVersionMinor = [versionInfo[1] intValue];
if (length == 3) {
sGTMSystemVersionBugFix = [versionInfo[2] intValue];
}
}
[pool release];
#endif // GTM_MACOS_SDK
}
}
Expand All @@ -104,7 +104,7 @@ + (NSString*)build {
if (!sBuild) {
NSDictionary *systemVersionPlist
= [NSDictionary dictionaryWithContentsOfFile:kSystemVersionPlistPath];
sBuild = [[systemVersionPlist objectForKey:@"ProductBuildVersion"] retain];
sBuild = systemVersionPlist[@"ProductBuildVersion"];
}
}
return sBuild;
Expand Down
Loading

0 comments on commit f271718

Please sign in to comment.