mirror of
https://github.com/hholtmann/smcFanControl.git
synced 2025-11-04 19:49:16 +01:00
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:
@ -99,7 +99,6 @@
|
||||
IBOutlet id DefaultsController;
|
||||
|
||||
MachineDefaults *mdefaults;
|
||||
NSDictionary *s_sed;
|
||||
|
||||
NSDictionary *undo_dic;
|
||||
|
||||
@ -107,6 +106,8 @@
|
||||
NSImage *menu_image_alt;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong ) NSMutableDictionary *machineDefaultsDict;
|
||||
|
||||
|
||||
-(void)terminate:(id)sender;
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
@interface FanControl ()
|
||||
+ (void)copyMachinesIfNecessary;
|
||||
- (BOOL)isInAutoStart;
|
||||
@property (NS_NONATOMIC_IOSONLY, getter=isInAutoStart, readonly) BOOL inAutoStart;
|
||||
- (void)setStartAtLogin:(BOOL)enabled;
|
||||
+ (void)checkRightStatus:(OSStatus)status;
|
||||
@end
|
||||
@ -80,14 +80,14 @@ NSUserDefaults *defaults;
|
||||
for (i=0;i<[rfavorites count];i++)
|
||||
{
|
||||
BOOL selected = NO;
|
||||
NSArray *fans = [[rfavorites objectAtIndex:i] objectForKey:@"FanData"];
|
||||
NSArray *fans = rfavorites[i][@"FanData"];
|
||||
for (j=0;j<[fans count];j++) {
|
||||
if ([[[fans objectAtIndex:j] objectForKey:@"menu"] boolValue] == YES ) {
|
||||
if ([fans[j][@"menu"] boolValue] == YES ) {
|
||||
selected = YES;
|
||||
}
|
||||
}
|
||||
if (selected==NO) {
|
||||
[[[[rfavorites objectAtIndex:i] objectForKey:@"FanData"] objectAtIndex:0] setObject:[NSNumber numberWithBool:YES] forKey:@"menu"];
|
||||
rfavorites[i][@"FanData"][0][@"menu"] = @YES;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +95,6 @@ NSUserDefaults *defaults;
|
||||
|
||||
-(void) awakeFromNib {
|
||||
|
||||
s_sed = nil;
|
||||
pw=[[Power alloc] init];
|
||||
[pw setDelegate:self];
|
||||
[pw registerForSleepWakeNotification];
|
||||
@ -108,57 +107,51 @@ NSUserDefaults *defaults;
|
||||
|
||||
mdefaults=[[MachineDefaults alloc] init:nil];
|
||||
|
||||
s_sed=[mdefaults get_machine_defaults];
|
||||
self.machineDefaultsDict=[[NSMutableDictionary alloc] initWithDictionary:[mdefaults get_machine_defaults]];
|
||||
|
||||
|
||||
NSMutableArray *favorites=[NSMutableArray arrayWithObjects:
|
||||
[NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
@"Default", @"Title",
|
||||
[s_sed objectForKey:@"Fans"], @"FanData",nil],nil];
|
||||
NSMutableArray *favorites = [[NSMutableArray alloc] init];
|
||||
|
||||
NSMutableDictionary *defaultFav = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Default", @"Title",
|
||||
[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], @"FanData",nil];
|
||||
|
||||
[favorites addObject:defaultFav];
|
||||
|
||||
|
||||
NSRange range=[[MachineDefaults computerModel] rangeOfString:@"MacBook"];
|
||||
if (range.length>0) {
|
||||
//for macbooks add a second default
|
||||
MachineDefaults *msdefaults=[[MachineDefaults alloc] init:nil];
|
||||
NSMutableDictionary *sec_fav=[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Higher RPM", @"Title",
|
||||
[[msdefaults get_machine_defaults] objectForKey:@"Fans"], @"FanData",nil];
|
||||
[favorites addObject:sec_fav];
|
||||
int i;
|
||||
for (i=0;i<[[s_sed objectForKey:@"Fans"] count];i++) {
|
||||
int min_value=([[[[s_sed objectForKey:@"Fans"] objectAtIndex:i] valueForKey:@"Minspeed"] intValue])*2;
|
||||
[[[[favorites objectAtIndex:1] objectForKey:@"FanData"] objectAtIndex:i] setObject:[NSNumber numberWithInt:min_value] forKey:@"selspeed"];
|
||||
|
||||
NSMutableDictionary *higherFav=[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Higher RPM", @"Title",
|
||||
[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:[[mdefaults get_machine_defaults] objectForKey:@"Fans"]]], @"FanData",nil];
|
||||
for (NSUInteger i=0;i<[_machineDefaultsDict[@"Fans"] count];i++) {
|
||||
|
||||
int min_value=([[[[_machineDefaultsDict objectForKey:@"Fans"] objectAtIndex:i] objectForKey:@"Minspeed"] intValue])*2;
|
||||
[[[higherFav objectForKey:@"FanData"] objectAtIndex:i] setObject:[NSNumber numberWithInt:min_value] forKey:@"selspeed"];
|
||||
}
|
||||
[msdefaults release];
|
||||
}
|
||||
[favorites addObject:higherFav];
|
||||
|
||||
}
|
||||
|
||||
//sync option for Macbook Pro's
|
||||
NSRange range_mbp=[[MachineDefaults computerModel] rangeOfString:@"MacBookPro"];
|
||||
if (range_mbp.length>0 && [[s_sed objectForKey:@"Fans"] count] == 2) {
|
||||
if (range_mbp.length>0 && [_machineDefaultsDict[@"Fans"] count] == 2) {
|
||||
[sync setHidden:NO];
|
||||
}
|
||||
|
||||
|
||||
NSString *feedURL = nil;
|
||||
if ([SystemVersion isTiger]) {
|
||||
feedURL = @"http://www.eidac.de/smcfancontrol/smcfancontrol_tiger.xml";
|
||||
} else {
|
||||
feedURL = @"http://www.eidac.de/smcfancontrol/smcfancontrol.xml";
|
||||
}
|
||||
|
||||
//load user defaults
|
||||
defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults registerDefaults:
|
||||
[NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:0], @"Unit",
|
||||
[NSNumber numberWithInt:0], @"SelDefault",
|
||||
[NSNumber numberWithBool:NO], @"AutoStart",
|
||||
[NSNumber numberWithBool:NO],@"AutomaticChange",
|
||||
[NSNumber numberWithInt:0],@"selbatt",
|
||||
[NSNumber numberWithInt:0],@"selac",
|
||||
[NSNumber numberWithInt:0],@"selload",
|
||||
[NSNumber numberWithInt:0],@"MenuBar",
|
||||
@0, @"Unit",
|
||||
@0, @"SelDefault",
|
||||
@NO, @"AutoStart",
|
||||
@NO,@"AutomaticChange",
|
||||
@0,@"selbatt",
|
||||
@0,@"selac",
|
||||
@0,@"selload",
|
||||
@0,@"MenuBar",
|
||||
@"TC0D",@"TSensor",
|
||||
feedURL,@"SUFeedURL",
|
||||
@0,@"NumLaunches",
|
||||
@NO,@"DonationMessageShown",
|
||||
[NSArchiver archivedDataWithRootObject:[NSColor blackColor]],@"MenuColor",
|
||||
favorites,@"Favorites",
|
||||
nil]];
|
||||
@ -167,13 +160,11 @@ NSUserDefaults *defaults;
|
||||
|
||||
g_numFans = [smcWrapper get_fan_num];
|
||||
s_menus=[[NSMutableArray alloc] init];
|
||||
[s_menus autorelease];
|
||||
int i;
|
||||
for(i=0;i<g_numFans;i++){
|
||||
NSMenuItem *mitem=[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Fan: %d",i] action:NULL keyEquivalent:@""];
|
||||
[mitem setTag:(i+1)*10];
|
||||
[s_menus insertObject:mitem atIndex:i];
|
||||
[mitem release];
|
||||
}
|
||||
|
||||
[FavoritesController bind:@"content"
|
||||
@ -184,9 +175,9 @@ NSUserDefaults *defaults;
|
||||
|
||||
// set slider sync - only for MBP
|
||||
for (i=0;i<[[FavoritesController arrangedObjects] count];i++) {
|
||||
if([[[[FavoritesController arrangedObjects] objectAtIndex:i] objectForKey:@"sync"] boolValue]==YES) {
|
||||
if([[FavoritesController arrangedObjects][i][@"sync"] boolValue]==YES) {
|
||||
[FavoritesController setSelectionIndex:i];
|
||||
[self syncBinder:[[[[FavoritesController arrangedObjects] objectAtIndex:i] objectForKey:@"sync"] boolValue]];
|
||||
[self syncBinder:[[FavoritesController arrangedObjects][i][@"sync"] boolValue]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,24 +211,42 @@ NSUserDefaults *defaults;
|
||||
[menu_image_alt setTemplate:YES];
|
||||
}
|
||||
|
||||
//release MachineDefaults class first call
|
||||
//add timer for reading to RunLoop
|
||||
_readTimer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(readFanData:) userInfo:nil repeats:YES];
|
||||
if ([_readTimer respondsToSelector:@selector(setTolerance:)]) {
|
||||
[_readTimer setTolerance:2.0];
|
||||
}
|
||||
[_readTimer fire];
|
||||
|
||||
//autoapply settings if valid
|
||||
[self upgradeFavorites];
|
||||
|
||||
//autostart
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:[self isInAutoStart]] forKey:@"AutoStart"];
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@([self isInAutoStart]) forKey:@"AutoStart"];
|
||||
NSUInteger numLaunches = [[[NSUserDefaults standardUserDefaults] objectForKey:@"NumLaunches"] integerValue];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:@(numLaunches+1) forKey:@"NumLaunches"];
|
||||
if (numLaunches != 0 && (numLaunches % 5 == 0) && ![[[NSUserDefaults standardUserDefaults] objectForKey:@"DonationMessageShown"] boolValue]) {
|
||||
[self displayDonationMessage];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)displayDonationMessage
|
||||
{
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Consider a donation",nil)
|
||||
defaultButton:NSLocalizedString(@"Donate over Paypal",nil) alternateButton:NSLocalizedString(@"Never ask me again",nil) otherButton:NSLocalizedString(@"Remind me later",nil)
|
||||
informativeTextWithFormat:NSLocalizedString(@"smcFanControl keeps your Mac cool since 2006.\n\nIf smcFanControl is helfpul for you and you want to support further development, a small donation over Paypal is much appreciated.",nil)];
|
||||
NSModalResponse code=[alert runModal];
|
||||
if (code == NSAlertDefaultReturn) {
|
||||
[self paypal:nil];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"DonationMessageShown"];
|
||||
} else if (code == NSAlertAlternateReturn) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"DonationMessageShown"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)init_statusitem{
|
||||
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength] retain];
|
||||
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength];
|
||||
[statusItem setMenu: theMenu];
|
||||
|
||||
if ([statusItem respondsToSelector:@selector(button)]) {
|
||||
@ -249,7 +258,7 @@ NSUserDefaults *defaults;
|
||||
}
|
||||
int i;
|
||||
for(i=0;i<[s_menus count];i++) {
|
||||
[theMenu insertItem:[s_menus objectAtIndex:i] atIndex:i];
|
||||
[theMenu insertItem:s_menus[i] atIndex:i];
|
||||
};
|
||||
|
||||
// Sign up for menuNeedsUpdate call
|
||||
@ -284,21 +293,19 @@ NSUserDefaults *defaults;
|
||||
- (IBAction)save_favorite:(id)sender{
|
||||
MachineDefaults *msdefaults=[[MachineDefaults alloc] init:nil];
|
||||
if ([[newfavorite_title stringValue] length]>0) {
|
||||
NSMutableDictionary *toinsert=[[NSMutableDictionary alloc] initWithObjectsAndKeys:[newfavorite_title stringValue],@"Title",[[msdefaults get_machine_defaults] objectForKey:@"Fans"],@"FanData",nil]; //default as template
|
||||
[toinsert setValue:[NSNumber numberWithInt:0] forKey:@"Standard"];
|
||||
NSMutableDictionary *toinsert=[[NSMutableDictionary alloc] initWithObjectsAndKeys:[newfavorite_title stringValue],@"Title",[msdefaults get_machine_defaults][@"Fans"],@"FanData",nil]; //default as template
|
||||
[toinsert setValue:@0 forKey:@"Standard"];
|
||||
[FavoritesController addObject:toinsert];
|
||||
[toinsert release];
|
||||
[newfavoritewindow close];
|
||||
[[NSApplication sharedApplication] endSheet:newfavoritewindow];
|
||||
}
|
||||
[msdefaults release];
|
||||
[self upgradeFavorites];
|
||||
}
|
||||
|
||||
|
||||
-(void) check_deletion:(id)combo{
|
||||
if ([FavoritesController selectionIndex]==[[defaults objectForKey:combo] intValue]) {
|
||||
[defaults setObject:[NSNumber numberWithInt:0] forKey:combo];
|
||||
[defaults setObject:@0 forKey:combo];
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +324,7 @@ NSUserDefaults *defaults;
|
||||
|
||||
- (IBAction)delete_favorite:(id)sender{
|
||||
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Delete favorite",nil) defaultButton:NSLocalizedString(@"No",nil) alternateButton:NSLocalizedString(@"Yes",nil) otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the favorite %@?",nil), [ [ [FavoritesController arrangedObjects] objectAtIndex:[FavoritesController selectionIndex]] objectForKey:@"Title"] ]];
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Delete favorite",nil) defaultButton:NSLocalizedString(@"No",nil) alternateButton:NSLocalizedString(@"Yes",nil) otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the favorite %@?",nil), [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"Title"] ]];
|
||||
|
||||
[alert beginSheetModalForWindow:mainwindow modalDelegate:self didEndSelector:@selector(deleteAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
||||
}
|
||||
@ -331,7 +338,7 @@ NSUserDefaults *defaults;
|
||||
int i = 0;
|
||||
|
||||
//on init handling
|
||||
if (s_sed==nil) {
|
||||
if (_machineDefaultsDict==nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -370,16 +377,16 @@ NSUserDefaults *defaults;
|
||||
|
||||
if (bNeedRpm == true) {
|
||||
// Read the current fan speed for the desired fan and format text for display in the menubar.
|
||||
NSArray *fans = [[[FavoritesController arrangedObjects] objectAtIndex:[FavoritesController selectionIndex]] objectForKey:@"FanData"];
|
||||
NSArray *fans = [FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"FanData"];
|
||||
for (i=0; i<g_numFans && i<[fans count]; i++)
|
||||
{
|
||||
if ([[[fans objectAtIndex:i] objectForKey:@"menu"] boolValue]==YES) {
|
||||
if ([fans[i][@"menu"] boolValue]==YES) {
|
||||
selectedRpm = [smcWrapper get_fan_rpm:i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NSNumberFormatter *nc=[[[NSNumberFormatter alloc] init] autorelease];
|
||||
NSNumberFormatter *nc=[[NSNumberFormatter alloc] init];
|
||||
//avoid jumping in menu bar
|
||||
[nc setFormat:@"000;000;-000"];
|
||||
|
||||
@ -391,11 +398,11 @@ NSUserDefaults *defaults;
|
||||
c_temp = [smcWrapper get_maintemp];
|
||||
|
||||
if ([[defaults objectForKey:@"Unit"] intValue]==0) {
|
||||
temp = [NSString stringWithFormat:@"%@%CC",[NSNumber numberWithFloat:c_temp],(unsigned short)0xb0];
|
||||
temp = [NSString stringWithFormat:@"%@%CC",@(c_temp),(unsigned short)0xb0];
|
||||
} else {
|
||||
NSNumberFormatter *ncf=[[[NSNumberFormatter alloc] init] autorelease];
|
||||
NSNumberFormatter *ncf=[[NSNumberFormatter alloc] init];
|
||||
[ncf setFormat:@"00;00;-00"];
|
||||
temp = [NSString stringWithFormat:@"%@%CF",[ncf stringForObjectValue:[[NSNumber numberWithFloat:c_temp] celsius_fahrenheit]],(unsigned short)0xb0];
|
||||
temp = [NSString stringWithFormat:@"%@%CF",[ncf stringForObjectValue:[@(c_temp) celsius_fahrenheit]],(unsigned short)0xb0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,8 +500,6 @@ NSUserDefaults *defaults;
|
||||
break;
|
||||
}
|
||||
|
||||
[paragraphStyle release];
|
||||
[s_status release];
|
||||
}
|
||||
|
||||
|
||||
@ -521,17 +526,17 @@ NSUserDefaults *defaults;
|
||||
int i;
|
||||
[FanControl setRights];
|
||||
[FavoritesController setSelectionIndex:cIndex];
|
||||
for (i=0;i<[[[[FavoritesController arrangedObjects] objectAtIndex:cIndex] objectForKey:@"FanData"] count];i++) {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[[[FanController arrangedObjects] objectAtIndex:i] objectForKey:@"selspeed"] tohex]];
|
||||
for (i=0;i<[[FavoritesController arrangedObjects][cIndex][@"FanData"] count];i++) {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[FanController arrangedObjects][i][@"selspeed"] tohex]];
|
||||
}
|
||||
NSMenu *submenu = [[[NSMenu alloc] init] autorelease];
|
||||
NSMenu *submenu = [[NSMenu alloc] init];
|
||||
|
||||
for(i=0;i<[[FavoritesController arrangedObjects] count];i++){
|
||||
NSMenuItem *submenuItem = [[[NSMenuItem alloc] initWithTitle:[[[FavoritesController arrangedObjects] objectAtIndex:i] objectForKey:@"Title"] action:@selector(apply_quickselect:) keyEquivalent:@""] autorelease];
|
||||
NSMenuItem *submenuItem = [[NSMenuItem alloc] initWithTitle:[FavoritesController arrangedObjects][i][@"Title"] action:@selector(apply_quickselect:) keyEquivalent:@""];
|
||||
[submenuItem setTag:i*100]; //for later manipulation
|
||||
[submenuItem setEnabled:YES];
|
||||
[submenuItem setTarget:self];
|
||||
[submenuItem setRepresentedObject:[[FavoritesController arrangedObjects] objectAtIndex:i]];
|
||||
[submenuItem setRepresentedObject:[FavoritesController arrangedObjects][i]];
|
||||
[submenu addItem:submenuItem];
|
||||
}
|
||||
|
||||
@ -540,9 +545,9 @@ NSUserDefaults *defaults;
|
||||
[[[[theMenu itemWithTag:1] submenu] itemAtIndex:i] setState:NSOffState];
|
||||
}
|
||||
[[[[theMenu itemWithTag:1] submenu] itemAtIndex:cIndex] setState:NSOnState];
|
||||
[defaults setObject:[NSNumber numberWithInt:cIndex] forKey:@"SelDefault"];
|
||||
[defaults setObject:@(cIndex) forKey:@"SelDefault"];
|
||||
//change active setting display
|
||||
[[theMenu itemWithTag:1] setTitle:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Active Setting",nil),[ [ [FavoritesController arrangedObjects] objectAtIndex:[FavoritesController selectionIndex]] objectForKey:@"Title"] ]];
|
||||
[[theMenu itemWithTag:1] setTitle:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Active Setting",nil),[FavoritesController arrangedObjects][[FavoritesController selectionIndex]][@"Title"] ]];
|
||||
}
|
||||
|
||||
|
||||
@ -567,13 +572,6 @@ NSUserDefaults *defaults;
|
||||
[_readTimer invalidate];
|
||||
[pw deregisterForSleepWakeNotification];
|
||||
[pw deregisterForPowerChange];
|
||||
[pw release];
|
||||
[menu_image release];
|
||||
[menu_image_alt release];
|
||||
//[mdefaults release];
|
||||
//[statusItem release];
|
||||
//[s_menus release];
|
||||
//[theMenu release];
|
||||
[[NSApplication sharedApplication] terminate:self];
|
||||
}
|
||||
|
||||
@ -602,7 +600,7 @@ NSUserDefaults *defaults;
|
||||
int i;
|
||||
for (i=0;i<[[FanController arrangedObjects] count];i++) {
|
||||
if (i!=[sender selectedRow]) {
|
||||
[[[FanController arrangedObjects] objectAtIndex:i] setValue:[NSNumber numberWithBool:NO] forKey:@"menu"];
|
||||
[[FanController arrangedObjects][i] setValue:@NO forKey:@"menu"];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -612,16 +610,18 @@ NSUserDefaults *defaults;
|
||||
// menu items are now only updated here in order to
|
||||
// reduce the energy impact of -readFanData.
|
||||
- (void)menuNeedsUpdate:(NSMenu*)menu {
|
||||
if (theMenu == menu) {
|
||||
if (s_sed == nil)
|
||||
return;
|
||||
|
||||
int i;
|
||||
for(i=0; i<g_numFans; ++i){
|
||||
NSString *fandesc=[[[s_sed objectForKey:@"Fans"] objectAtIndex:i] objectForKey:@"Description"];
|
||||
[[theMenu itemWithTag:(i+1)*10] setTitle:[NSString stringWithFormat:@"%@: %@ rpm",fandesc,[[NSNumber numberWithInt:[smcWrapper get_fan_rpm:i]] stringValue]]];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (theMenu == menu) {
|
||||
if (_machineDefaultsDict == nil)
|
||||
return;
|
||||
|
||||
int i;
|
||||
for(i=0; i<g_numFans; ++i){
|
||||
NSString *fandesc=_machineDefaultsDict[@"Fans"][i][@"Description"];
|
||||
[[theMenu itemWithTag:(i+1)*10] setTitle:[NSString stringWithFormat:@"%@: %@ rpm",fandesc,[@([smcWrapper get_fan_rpm:i]) stringValue]]];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -633,7 +633,6 @@ NSUserDefaults *defaults;
|
||||
SUUpdater *updater = [[SUUpdater alloc] init];
|
||||
[updater checkForUpdates:sender];
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
[updater release];
|
||||
}
|
||||
|
||||
- (IBAction)visitHomepage:(id)sender{
|
||||
@ -649,11 +648,11 @@ NSUserDefaults *defaults;
|
||||
//in case plist is corrupt, don't bind
|
||||
if ([[FanController arrangedObjects] count]>1 ) {
|
||||
if (bind==YES) {
|
||||
[[[FanController arrangedObjects] objectAtIndex:1] bind:@"selspeed" toObject:[[FanController arrangedObjects] objectAtIndex:0] withKeyPath:@"selspeed" options:nil];
|
||||
[[[FanController arrangedObjects] objectAtIndex:0] bind:@"selspeed" toObject:[[FanController arrangedObjects] objectAtIndex:1] withKeyPath:@"selspeed" options:nil];
|
||||
[[FanController arrangedObjects][1] bind:@"selspeed" toObject:[FanController arrangedObjects][0] withKeyPath:@"selspeed" options:nil];
|
||||
[[FanController arrangedObjects][0] bind:@"selspeed" toObject:[FanController arrangedObjects][1] withKeyPath:@"selspeed" options:nil];
|
||||
} else {
|
||||
[[[FanController arrangedObjects] objectAtIndex:1] unbind:@"selspeed"];
|
||||
[[[FanController arrangedObjects] objectAtIndex:0] unbind:@"selspeed"];
|
||||
[[FanController arrangedObjects][1] unbind:@"selspeed"];
|
||||
[[FanController arrangedObjects][0] unbind:@"selspeed"];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -696,14 +695,14 @@ NSUserDefaults *defaults;
|
||||
BOOL found = NO;
|
||||
LSSharedFileListRef loginItems = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, /*options*/ NULL);
|
||||
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||
CFURLRef URLToToggle = (CFURLRef)[NSURL fileURLWithPath:path];
|
||||
CFURLRef URLToToggle = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
|
||||
//LSSharedFileListItemRef existingItem = NULL;
|
||||
|
||||
UInt32 seed = 0U;
|
||||
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
|
||||
NSArray *currentLoginItems = CFBridgingRelease(LSSharedFileListCopySnapshot(loginItems, &seed));
|
||||
|
||||
for (id itemObject in currentLoginItems) {
|
||||
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
|
||||
LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef)itemObject;
|
||||
|
||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
|
||||
CFURLRef URL = NULL;
|
||||
@ -730,14 +729,14 @@ NSUserDefaults *defaults;
|
||||
NSString *path = [[NSBundle mainBundle] bundlePath];
|
||||
|
||||
OSStatus status;
|
||||
CFURLRef URLToToggle = (CFURLRef)[NSURL fileURLWithPath:path];
|
||||
CFURLRef URLToToggle = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
|
||||
LSSharedFileListItemRef existingItem = NULL;
|
||||
|
||||
UInt32 seed = 0U;
|
||||
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
|
||||
NSArray *currentLoginItems = CFBridgingRelease(LSSharedFileListCopySnapshot(loginItems, &seed));
|
||||
|
||||
for (id itemObject in currentLoginItems) {
|
||||
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
|
||||
LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef)itemObject;
|
||||
|
||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
|
||||
CFURLRef URL = NULL;
|
||||
@ -769,7 +768,7 @@ NSUserDefaults *defaults;
|
||||
icon = NULL;
|
||||
}
|
||||
|
||||
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, (CFStringRef)displayName, icon, URLToToggle, /*propertiesToSet*/ NULL, /*propertiesToClear*/ NULL);
|
||||
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, (__bridge CFStringRef)displayName, icon, URLToToggle, /*propertiesToSet*/ NULL, /*propertiesToClear*/ NULL);
|
||||
} else if (!enabled && (existingItem != NULL))
|
||||
LSSharedFileListItemRemove(loginItems, existingItem);
|
||||
}
|
||||
@ -810,11 +809,11 @@ NSUserDefaults *defaults;
|
||||
[self checkRightStatus:status];
|
||||
|
||||
NSString *tool=@"/usr/sbin/chown";
|
||||
NSArray *argsArray = [NSArray arrayWithObjects: @"root:admin",smcpath,nil];
|
||||
NSArray *argsArray = @[@"root:admin",smcpath];
|
||||
int i;
|
||||
char *args[255];
|
||||
for(i = 0;i < [argsArray count];i++){
|
||||
args[i] = (char *)[[argsArray objectAtIndex:i]cString];
|
||||
args[i] = (char *)[argsArray[i]cString];
|
||||
}
|
||||
args[i] = NULL;
|
||||
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
||||
@ -823,9 +822,9 @@ NSUserDefaults *defaults;
|
||||
|
||||
//second call for suid-bit
|
||||
tool=@"/bin/chmod";
|
||||
argsArray = [NSArray arrayWithObjects: @"6555",smcpath,nil];
|
||||
argsArray = @[@"6555",smcpath];
|
||||
for(i = 0;i < [argsArray count];i++){
|
||||
args[i] = (char *)[[argsArray objectAtIndex:i]cString];
|
||||
args[i] = (char *)[argsArray[i]cString];
|
||||
}
|
||||
args[i] = NULL;
|
||||
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
||||
@ -849,7 +848,7 @@ NSUserDefaults *defaults;
|
||||
- (NSNumber*) celsius_fahrenheit{
|
||||
float celsius=[self floatValue];
|
||||
float fahrenheit=(celsius*9)/5+32;
|
||||
return [NSNumber numberWithFloat:fahrenheit];
|
||||
return @(fahrenheit);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -31,6 +31,6 @@
|
||||
inDomain:(NSSearchPathDomainMask)domainMask
|
||||
appendPathComponent:(NSString *)appendComponent
|
||||
error:(NSError **)errorOut;
|
||||
- (NSString *)applicationSupportDirectory;
|
||||
@property (NS_NONATOMIC_IOSONLY, readonly, copy) NSString *applicationSupportDirectory;
|
||||
|
||||
@end
|
||||
|
||||
@ -110,7 +110,7 @@ NSString * const DirectoryLocationDomain = @"DirectoryLocationDomain";
|
||||
*/
|
||||
- (NSString *)applicationSupportDirectory
|
||||
{
|
||||
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
|
||||
NSString *executableName = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -31,7 +31,7 @@ static int lastsource=0;
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
@ -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]) {
|
||||
|
||||
}
|
||||
@ -65,14 +65,14 @@ static void powerSourceChanged(void * refCon)
|
||||
|
||||
- (void)registerForSleepWakeNotification
|
||||
{
|
||||
root_port = IORegisterForSystemPower(self, ¬ificationPort, SleepWatcher, ¬ifier);
|
||||
root_port = IORegisterForSystemPower((__bridge void *)(self), ¬ificationPort, SleepWatcher, ¬ifier);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
|
||||
- (void)registerForPowerChange
|
||||
{
|
||||
powerNotifierRunLoopSource = IOPSNotificationCreateRunLoopSource(powerSourceChanged,self);
|
||||
powerNotifierRunLoopSource = IOPSNotificationCreateRunLoopSource(powerSourceChanged,(__bridge void *)(self));
|
||||
if (powerNotifierRunLoopSource) {
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), powerNotifierRunLoopSource, kCFRunLoopDefaultMode);
|
||||
}
|
||||
@ -118,7 +118,7 @@ static void powerSourceChanged(void * refCon)
|
||||
}
|
||||
|
||||
- (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];
|
||||
@ -129,7 +129,7 @@ static void powerSourceChanged(void * refCon)
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
@ -139,7 +139,7 @@ static void powerSourceChanged(void * refCon)
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
@ -171,7 +171,6 @@ static void powerSourceChanged(void * refCon)
|
||||
if (_delegate)
|
||||
[nc removeObserver:_delegate name:nil object:self];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -68,18 +68,18 @@ static NSString *const kSystemVersionPlistPath = @"/System/Library/CoreServices/
|
||||
#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
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ static NSString *const kSystemVersionPlistPath = @"/System/Library/CoreServices/
|
||||
if (!sBuild) {
|
||||
NSDictionary *systemVersionPlist
|
||||
= [NSDictionary dictionaryWithContentsOfFile:kSystemVersionPlistPath];
|
||||
sBuild = [[systemVersionPlist objectForKey:@"ProductBuildVersion"] retain];
|
||||
sBuild = systemVersionPlist[@"ProductBuildVersion"];
|
||||
}
|
||||
}
|
||||
return sBuild;
|
||||
|
||||
@ -24,15 +24,15 @@
|
||||
#import "smcWrapper.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
static NSArray *allSensors = nil;
|
||||
|
||||
NSArray *allSensors;
|
||||
|
||||
@implementation smcWrapper
|
||||
io_connect_t conn;
|
||||
|
||||
+(void)init{
|
||||
SMCOpen(&conn);
|
||||
allSensors = [[NSArray alloc] initWithObjects:@"TC0D",@"TC0H",@"TC0F",@"TCAH",@"TCBH",@"TC0P",nil];
|
||||
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
|
||||
}
|
||||
+(void)cleanUp{
|
||||
SMCClose(conn);
|
||||
@ -40,7 +40,6 @@ static NSArray *allSensors = nil;
|
||||
|
||||
+(float) get_maintemp{
|
||||
float c_temp;
|
||||
|
||||
SMCVal_t val;
|
||||
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:@"TSensor"];
|
||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||
@ -57,8 +56,6 @@ static NSArray *allSensors = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return c_temp;
|
||||
}
|
||||
|
||||
@ -116,7 +113,7 @@ static NSArray *allSensors = nil;
|
||||
//kern_return_t result;
|
||||
NSMutableString *desc;
|
||||
// desc=[[NSMutableString alloc] initWithFormat:@"Fan #%d: ",fan_number+1];
|
||||
desc=[[[NSMutableString alloc]init] autorelease];
|
||||
desc=[[NSMutableString alloc]init];
|
||||
sprintf(key, "F%dID", fan_number);
|
||||
SMCReadKey2(key, &val,conn);
|
||||
int i;
|
||||
@ -160,19 +157,25 @@ static NSArray *allSensors = nil;
|
||||
OSStatus status;
|
||||
|
||||
// obtain the cert info from the executable
|
||||
status = SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &ref);
|
||||
status = SecStaticCodeCreateWithPath((__bridge CFURLRef)url, kSecCSDefaultFlags, &ref);
|
||||
|
||||
if (status != noErr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
status = SecStaticCodeCheckValidity(ref, kSecCSDefaultFlags, nil);
|
||||
|
||||
if (status != noErr) {
|
||||
NSLog(@"Codesign verification failed: Error id = %d",status);
|
||||
@try {
|
||||
status = SecStaticCodeCheckValidity(ref, kSecCSDefaultFlags, nil);
|
||||
|
||||
if (status != noErr) {
|
||||
NSLog(@"Codesign verification failed: Error id = %d",status);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"Codesign exception %@",exception);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -187,13 +190,12 @@ static NSArray *allSensors = nil;
|
||||
NSLog(@"smcFanControl: Security Error: smc-binary is not the distributed one");
|
||||
return;
|
||||
}
|
||||
NSArray *argsArray = [NSArray arrayWithObjects: @"-k",key,@"-w",value,nil];
|
||||
NSArray *argsArray = @[@"-k",key,@"-w",value];
|
||||
NSTask *task;
|
||||
task = [[NSTask alloc] init];
|
||||
[task setLaunchPath: launchPath];
|
||||
[task setArguments: argsArray];
|
||||
[task launch];
|
||||
[task release];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user