-
Notifications
You must be signed in to change notification settings - Fork 60
/
mainwindow.cpp
846 lines (699 loc) · 25.4 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#define TEST
#define REAL
//#define WINDOWS
#define MAC
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::exit()
{
close();
qApp->quit();
}
void MainWindow::on_patchButton_clicked()
{
bool ok;
QProcess process;
QString errorOutput;
QString command;
QInputDialog *passwordDialog;
passwordDialog = new QInputDialog;
QString passwordDialogLabel = "Enter User Password :";
bool isErrorPatching=false;
//Search kext file
if(searchKernelExtensionFile(&kernelFile))
{
//Display Warning Message
#ifndef TEST
int answer = QMessageBox::question(this, "Warning", "This will patch the kernel configuration file.\nAre you sure you want to procede ?", QMessageBox::Yes | QMessageBox::No);
if(answer == QMessageBox::Yes)
#else
if(1)
#endif
{
do
{
#ifndef TEST
password = passwordDialog->getText(this,tr("Password"),passwordDialogLabel,QLineEdit::Password,"",&ok);
command = "sudo -S pwd";
process.start(command);
process.write(password.toLocal8Bit());
process.write("\n");
process.waitForFinished(1000);
errorOutput = process.readAllStandardError();
qDebug() << errorOutput;
process.closeWriteChannel();
if(errorOutput.contains("try again"))
{
qDebug() << "Wrong password, try again.\n";
passwordDialogLabel="Wrong password, try again.\nEnter User Password :";
}
#else
ok = 1;
#endif
if(!ok)
{
process.close();
return;
}
}while(errorOutput.contains("try again"));
logger->write(" ********** Starting MBP GPU Fix **********\n");
//Disable signing extension verification
disableKextSigning();
isErrorPatching = patchKernelExtensionFile(&kernelFile);
#ifndef TEST
if(isErrorPatching == false)
{
loadKernelExtension(&kernelFile);
}
else
{
logger->write("********************* MBP GPU Fix FAILED *********************\n");
}
#endif
}
else
{
logger->write(" ********** Discarded MBP GPU Fix **********\n");
return;
}
}
else
{
return;
}
}
void MainWindow::on_restoreButton_clicked()
{
//Display Warning Message
int answer = QMessageBox::question(this, "Warning", "This will restore the old configuration.\nAre you sure you want to procede ?", QMessageBox::Yes | QMessageBox::No);
if (answer == QMessageBox::Yes)
{
}
else
{
return;
}
}
bool MainWindow::init()
{
bool isInitOk = true;
MainWindow::setWindowTitle (APP_NAME);
//TODO : enable button when functionnality will be avaible
ui->restoreButton->setEnabled(false);
//Initialize logger
if (QFile::exists("log.txt"))
{
QFile::remove("log.txt");
}
QString fileName = "log.txt";
logger = new Logger(this, fileName, this->ui->logWindow);
logger->setShowDateTime(false);
//Configure GitHub icom
QString gitHubLogoPath = ":/ressource/githubicon.png";
QPixmap pix = QPixmap (gitHubLogoPath);
//int width = this->ui->labelgithubIcon->width();
//int height = this->ui->labelgithubIcon->height();
//pix = pix.scaled(width, height,Qt::KeepAspectRatio, Qt::SmoothTransformation);
QIcon gitHubButtonIcon(pix);
this->ui->gitHubButton->setIcon(gitHubButtonIcon);
this->ui->gitHubButton->setIconSize(pix.rect().size());
this->ui->gitHubButton->setFixedSize(pix.rect().size());
//this->ui->labelgithubIcon->setText("<a href=\"https://github.com/julian-poidevin/MBPMid2010_GPUFix/\">GitHub Link</a>");
//this->ui->labelgithubIcon->setTextFormat(Qt::RichText);
//this->ui->labelgithubIcon->setTextInteractionFlags(Qt::TextBrowserInteraction);
//this->ui->labelgithubIcon->setOpenExternalLinks(true);
//Configure version label
QString versionNumber = VERSION;
QString versionPrefix = "v";
QString versionName = versionPrefix + versionNumber;
this->ui->versionButton->setText(versionName);
//Search for compatibility
if(isCompatibleVersion(getMBPModelVersion()))
{
isInitOk = true;
logger->write("➔ Compatibility : OK ✓\n");
}
else
{
logger->write("➔ Compatibility : NOK ✗\n");
QMessageBox::information(this,"Mac not compatible","Sorry, your Mac is not compatible.\nThe application will close");
isInitOk = false;
return isInitOk;
}
//Search for SIP Status
if(isSIPEnabled())
{
ui->patchButton->setEnabled(false);
ui->restoreButton->setEnabled(false);
QMessageBox msgBox;
msgBox.setInformativeText("The System Integrity Protection is enabled\nPlease follow the instructions to disable it");
msgBox.setWindowTitle("SIP Enabled");
QAbstractButton* pButtonYes = msgBox.addButton(tr("Take me to tutorial"), QMessageBox::YesRole);
msgBox.addButton(tr("Nope"), QMessageBox::NoRole);
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
if (msgBox.clickedButton()== pButtonYes)
{
QString link = "https://www.youtube.com/watch?v=Wmhal4shmVo";
QDesktopServices::openUrl(QUrl(link));
}
}
return isInitOk;
}
QString MainWindow::getMBPModelVersion()
{
QString MBPModelVersion;
QProcess process;
logger->write(" | Checking compatibility\n");
//Execute commande line
process.start("sysctl -n hw.model");
//Wait forever until finished
process.waitForFinished(-1);
//Get command line output
MBPModelVersion = process.readAllStandardOutput();
//Close process
process.close();
//Remove carriage return ("\n") from string
MBPModelVersion = MBPModelVersion.simplified();
logger->write("MBPModelVersion : " + MBPModelVersion);
return MBPModelVersion;
}
bool MainWindow::isSIPEnabled(void)
{
QString SIPStatus;
QProcess process;
QOperatingSystemVersion macVersion = QOperatingSystemVersion::current();
logger->write(" | macOS version : \n");
logger->write(macVersion.name() + " " + QString::number(macVersion.majorVersion()) + "." + QString::number(macVersion.minorVersion()) + "\n");
logger->write(" | Checking SIP Status\n");
//SIP as been introduced since El Capitan
if(macVersion >= QOperatingSystemVersion::OSXElCapitan)
{
//Execute commande line
process.start("csrutil status");
//Wait forever until finished
process.waitForFinished(-1);
//Get command line output
SIPStatus = process.readAllStandardOutput();
//Close process
process.close();
}
else
{
logger->write("No SIP for this OS\n");
return false;
}
#ifndef WINDOWS
if(SIPStatus.contains("disable"))
{
logger->write("SIP Disabled\n");
return false;
}
else
{
logger->write("SIP Enabled\n");
return true;
}
#else
return false;
#endif
}
int MainWindow::disableKextSigning()
{
QProcess process;
QString command;
QStringList arguments;
logger->write("Disabling Kext Signing verification : ");
command = "sudo nvram boot-args=kext-dev-mode=1";
arguments.clear();
return executeProcess(&process,command,arguments);
}
int MainWindow::executeProcess(QProcess* process, QString command, QStringList arguments)
{
QString errorOutput;
QString stdOutput;
//Execute commande line
if (arguments.isEmpty())
{
process->start(command);
}
else
{
process->start(command,arguments);
}
process->write(password.toLocal8Bit());
process->write("\n");
process->waitForFinished(1000);
errorOutput = process->readAllStandardError();
stdOutput = process->readAllStandardOutput();
process->closeWriteChannel();
if (process->exitCode() == 0)
{
logger->write("✓ " + stdOutput + "\n");
return 0;
}
else
{
qDebug() << errorOutput;
logger->write("✗ : " + errorOutput + "\n");
errorOutput.clear();
return -1;
}
//Close process
process->close();
}
//Parse system directory searching for AppleGraphicsPowerManagement.kext file
bool MainWindow::searchKernelExtensionFile(QFile* kernelExtensionFile)
{
bool isFileFound;
#ifdef TEST
#ifdef MAC
QDir kextPath("/Users/Julian/Documents/Dev/Projects/MBPMid2010_GPUFix/");
#endif
#ifdef WINDOWS
QDir kextPath("C:/Users/jpoidevin/Desktop/Documents Pro/03 - Dev Temp/MBPMid2010_GPUFix/MBPMid2010_GPUFix/");
#endif
#endif
#ifdef REAL
QDir kextPath("/System/Library/Extensions/AppleGraphicsPowerManagement.kext/");
#endif
QStringList listOfFiles;
//Print Current app directory
qDebug() << "Current Dir :" <<kextPath.absolutePath();
//Recursively search for "Info.plist" file in appPath
QDirIterator it(kextPath.absolutePath(),
QStringList() << "Info.plist",
QDir::NoSymLinks | QDir::Files,
QDirIterator::Subdirectories);
logger->write(" | Searching for AppleGraphicsPowerManagement.kext\n");
//Check if the file was found
if(it.hasNext())
{
while(it.hasNext())
{
it.next();
if (it.filePath().contains("AppleGraphicsPowerManagement"))
{
listOfFiles.push_back(it.filePath());
}
}
}
//Print files found
qDebug() << "Files found :"<< listOfFiles;
if(listOfFiles.length() <= 1 && listOfFiles.length() > 0)
{
//qDebug() << "Moins de 1";
logger->write("AppleGraphicsPowerManagement.kext found\n");
kernelExtensionFile->setFileName(listOfFiles.at(0));
isFileFound = true;
}
else
{
//qDebug () << "No file was found...";
logger->write("AppleGraphicsPowerManagement.kext not found\n");
isFileFound = false;
}
//Start search manually and only allow loading of the perfect named file (or kext)
if(!isFileFound)
{
QMessageBox::information(this,"File not found","Any corresponding file was found, please search for the file");
//TODO : FileDialog won't let user browse into .kext files Contents
QString dir = QFileDialog::getOpenFileName(this, tr("Open Info.plist file"),
"/System/Library/Extensions/AppleGraphicsPowerManagement.kext/",
"Property List Files (Info.plist)");
if(!(dir.isNull()))
{
//kernelExtensionFile->setFileName(dir);
isFileFound = true;
}
else
{
isFileFound = false;
}
}
return isFileFound;
}
bool MainWindow::isCompatibleVersion(QString modelVersion)
{
//Compare version with compatible versions of MBPs
bool isCompatibleVersion;
#ifdef MAC
//TODO : Search in a list if several models compatible
if(modelVersion == "MacBookPro6,2")
{
isCompatibleVersion = true;
}
else
{
isCompatibleVersion = false;
}
#endif
#ifdef WINDOWS
isCompatibleVersion = true;
#endif
return isCompatibleVersion;
}
void MainWindow::backupOldKernelExtension()
{
//Save File to current location adding .bak extension
//qDebug() << "File Name" << kernelFile.fileName();
//Save original file in kernelExtension file folder
QFile::copy(kernelFile.fileName(), kernelFile.fileName() + ".bak");
}
bool MainWindow::patchKernelExtensionFile(QFile *kernelFile)
{
//TODO
//backupOldKernelExtension();
#ifdef MAC
#define PATCHED_FILE_PATH "/tmp/PatchedInfo.plist"
#endif
#ifdef WINDOWS
#define PATCHED_FILE_PATH "C:/temp/PatchedInfo.plist"
#endif
bool isErrorPatching = false;
logger->write("Copying Info.plist file\n");
//Remove file if already exists
if (QFile::exists(PATCHED_FILE_PATH))
{
QFile::remove(PATCHED_FILE_PATH);
logger->write("Previous Info.plist file removed\n");
}
//Copy file in tmp dir for patch
QFile::copy(kernelFile->fileName(), PATCHED_FILE_PATH);
QFile tmpFile(PATCHED_FILE_PATH);
if(!tmpFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
logger->write("Could not open Info.plist file\n");
qDebug() << "Could not open tmp File";
isErrorPatching = true;
return isErrorPatching;
}
//The QDomDocument class represents an XML document.
QDomDocument xmlBOM;
// Set data into the QDomDocument before processing
xmlBOM.setContent(&tmpFile);
/* Definition of struct and enum to automaticaly parse file*/
typedef enum
{
FindChild,
FindSibling,
NextSibling,
FirstChild,
ModifyIntValue,
FillArray,
RemoveSibling,
}EActions;
typedef struct{
QString nodeName;
QVector<int> ArrayValues;
EActions ActionToPerform;
}nodeTree;
QVector<nodeTree> confTree={
{"MacBookPro6,2" , {} , FindChild },
{"dict" , {} , NextSibling },
{"LogControl" , {} , FindChild },
{"" , {1} , ModifyIntValue },
{"Vendor10deDevice0a29" , {} , FindSibling },
{"BoostPState" , {} , FindSibling },
{"" , {2,2,2,2} , FillArray },
{"BoostTime" , {} , FindSibling },
{"" , {2,2,2,2} , FillArray },
{"Heuristic" , {} , FindSibling },
{"IdleInterval" , {} , FindSibling },
{"" , {10} , ModifyIntValue },
{"P3HistoryLength" , {} , RemoveSibling },
{"SensorSampleRate" , {} , FindSibling },
{"" , {10} , ModifyIntValue },
{"Threshold_High" , {} , FindSibling },
{"" , {0,0,100,200} , FillArray },
{"Threshold_High_v" , {} , FindSibling },
{"" , {0,0,98,100} , FillArray },
{"Threshold_Low" , {} , FindSibling },
{"" , {0,0,0,200} , FillArray },
{"Threshold_Low_v" , {} , FindSibling },
{"" , {0,0,4,200} , FillArray }
};
logger->write("Patching Info.plist\n");
QDomElement currentNode = xmlBOM.firstChildElement("plist");
QDomElement nextNode;
QDomElement removedNode;
for (int i = 0;(i < confTree.size()) && (isErrorPatching == false); ++i)
{
//qDebug() << confTree.at(i).nodeName << confTree.at(i).ActionToPerform;
switch (confTree.at(i).ActionToPerform){
case FindChild:
nextNode = findElementChild(currentNode,confTree.at(i).nodeName);
if(!nextNode.isNull())
{
qDebug() << "FindChild - " << nextNode.tagName() << "|" << nextNode.text();
logger->write(" - FindChild - " + nextNode.tagName() + "|" + nextNode.text() + "\n");
}
else
{
isErrorPatching = true;
qDebug() << "FindChild - ERROR \n";
logger->write(" - FindChild - ERROR \n");
}
break;
case FindSibling:
nextNode = findElementSibling(currentNode,confTree.at(i).nodeName);
if(!nextNode.isNull())
{
qDebug() << "FindSibling - " << nextNode.tagName() << "|" << nextNode.text();
logger->write(" - FindSibling - " + nextNode.tagName() + "|" + nextNode.text() + "\n");
}
else
{
isErrorPatching = true;
qDebug() << "FindSibling - ERROR \n";
logger->write(" - FindSibling - ERROR \n");
}
break;
case NextSibling:
nextNode = currentNode.nextSiblingElement(confTree.at(i).nodeName);
if(!nextNode.isNull())
{
qDebug() << "NextSibling - " << nextNode.tagName();
logger->write(" - NextSibling - " + nextNode.tagName() + "\n");
}
else
{
isErrorPatching = true;
qDebug() << "NextSibling - ERROR \n";
logger->write(" - NextSibling - ERROR \n");
}
break;
case FirstChild:
nextNode = currentNode.firstChildElement(confTree.at(i).nodeName);
if(!nextNode.isNull())
{
qDebug() << "FirstChild - " << nextNode.tagName();
logger->write(" - FirstChild - " + nextNode.tagName() + "\n");
}
else
{
isErrorPatching = true;
qDebug() << "FirstChild - ERROR \n";
logger->write(" - FirstChild - ERROR \n");
}
break;
case ModifyIntValue:
currentNode = currentNode.nextSiblingElement("integer");
if(!currentNode.isNull())
{
currentNode.firstChild().setNodeValue(QString::number(confTree.at(i).ArrayValues[0]));
//qDebug() << "Integer - " << currentNode.firstChild().nodeValue();
//logger->write(" - Integer - " + currentNode.firstChild().nodeValue() + "\n");
nextNode = currentNode;
qDebug() << "ModifyIntValue - " << nextNode.tagName() << "|" << nextNode.text();
logger->write(" - ModifyIntValue - " + nextNode.tagName() + "|" + nextNode.text() + "\n");
}
else
{
isErrorPatching = true;
qDebug() << "ModifyIntValue - ERROR \n";
logger->write(" - ModifyIntValue - ERROR \n");
}
break;
case FillArray:
currentNode = currentNode.nextSiblingElement("array").firstChildElement("integer");
if(!currentNode.isNull())
{
currentNode.firstChild().setNodeValue(QString::number(confTree.at(i).ArrayValues[0]));
currentNode.nextSibling().firstChild().setNodeValue(QString::number(confTree.at(i).ArrayValues[1]));
currentNode.nextSibling().nextSibling().firstChild().setNodeValue(QString::number(confTree.at(i).ArrayValues[2]));
currentNode.nextSibling().nextSibling().nextSibling().firstChild().setNodeValue(QString::number(confTree.at(i).ArrayValues[3]));
nextNode = currentNode.parentNode().toElement();
}
else
{
isErrorPatching = true;
qDebug() << "FillArray - ERROR \n";
logger->write(" - FillArray - ERROR \n");
}
break;
case RemoveSibling:
removedNode = findElementSibling(currentNode,confTree.at(i).nodeName);
if(!removedNode.isNull())
{
qDebug() << "RemoveSiblingLabel - " << removedNode.tagName() << "|" << removedNode.text();
logger->write(" - RemoveSiblingLabel - " + removedNode.tagName() + "|" + removedNode.text() + "\n");
currentNode.parentNode().removeChild(removedNode);
removedNode = currentNode.nextSiblingElement("integer");
if(!removedNode.isNull())
{
qDebug() << "RemoveSiblingValue - " << removedNode.tagName() << "|" << removedNode.text();
logger->write(" - RemoveSiblingValue - " + removedNode.tagName() + "|" + removedNode.text() + "\n");
currentNode.parentNode().removeChild(removedNode);
}
else
{
qDebug() << "RemoveSiblingValue - Not found";
logger->write(" - RemoveSiblingValue - Not found");
}
}
else
{
qDebug() << "RemoveSiblingLabel - " << confTree.at(i).nodeName << "Not found";
logger->write(" - RemoveSiblingLabel - " + confTree.at(i).nodeName + " Not found \n");
}
break;
default:
break;
}
currentNode = nextNode;
}
if(isErrorPatching != true)
{
logger->write("Info.plist successfully patched\n");
// Write changes to same file
tmpFile.resize(0);
QTextStream stream;
stream.setDevice(&tmpFile);
xmlBOM.save(stream, 4);
}
else
{
logger->write("Info.plist patching failed\n");
}
tmpFile.close();
return isErrorPatching;
}
int MainWindow::loadKernelExtension(QFile *kernelFile)
{
//Use Kext Utility or command lines utils to load the file in Kernel
//See here : http://osxdaily.com/2015/06/24/load-unload-kernel-extensions-mac-os-x/
int processStatus = 0;
logger->write(" | Loading Kernel Extension\n");
/* Copy real kext into tmp file */
QProcess process;
//QProcess *process = new QProcess(this);
QString command;
QStringList arguments;
QDir kextDir(kernelFile->fileName());
kextDir.cdUp();
kextDir.cdUp();
logger->write("Removing existing kext in tmp : ");
command = "sudo -S rm -rf /tmp/AppleGraphicsPowerManagement.kext";
arguments.clear();
processStatus |= executeProcess(&process,command,arguments);
logger->write("Copying actuel kext into tmp : ");
command = "sudo -S cp -rf /System/Library/Extensions/AppleGraphicsPowerManagement.kext /tmp/AppleGraphicsPowerManagement.kext";
arguments.clear();
processStatus |= executeProcess(&process,command,arguments);
logger->write("Copying patched Info.plist into kext : ");
/*** Copy patched file into kext ***/
command = "sudo -S cp -f /tmp/PatchedInfo.plist /tmp/AppleGraphicsPowerManagement.kext/Contents/Info.plist";
arguments.clear();
//Execute commande line
processStatus |= executeProcess(&process,command,arguments);
logger->write("Changing permission of kext : ");
/*** Change permission of modified kext File ***/
command = "sudo -S chown -R -v root:wheel /tmp/AppleGraphicsPowerManagement.kext";
arguments.clear();
//Execute commande line
processStatus |= executeProcess(&process,command,arguments);
logger->write("Removing existing kext : ");
command = "sudo -S rm -rf /System/Library/Extensions/AppleGraphicsPowerManagement.kext";
arguments.clear();
processStatus |= executeProcess(&process,command,arguments);
logger->write("Copying patched kext into Extension : ");
/*** Copy patched file into kext ***/
command = "sudo -S cp -rf /tmp/AppleGraphicsPowerManagement.kext /System/Library/Extensions/AppleGraphicsPowerManagement.kext";
arguments.clear();
//Execute commande line
processStatus |= executeProcess(&process,command,arguments);
logger->write("Loading modified kext : ");
/*** Finally load kext file ***/
command = "sudo -S kextload -v /tmp/AppleGraphicsPowerManagement.kext";
arguments.clear();
//Execute commande line
processStatus |= executeProcess(&process,command,arguments);
if(processStatus == 0)
{
logger->write("********************* MBP GPU Fixed Successfully *********************\n");
}
else
{
logger->write("********************* MBP GPU Fix FAILED *********************\n");
}
//Close process
process.close();
ui->patchButton->setEnabled(false);
return processStatus;
}
int MainWindow::restoreOldKernelExtension(QFile *kernelFile)
{
//Restore.bak extension
int Status = 0;
//QFile::copy(kernelFile->fileName() + ".bak", kernelFile->fileName());
return Status;
}
QDomElement MainWindow::findElementChild(QDomElement parent, const QString &textToFind)
{
for(QDomElement elem = parent.firstChildElement(); !elem.isNull(); elem = elem.nextSiblingElement())
{
if(elem.text()==textToFind) return elem;
QDomElement e = findElementChild(elem, textToFind);
if(!e.isNull()) return e;
}
return QDomElement();
}
QDomElement MainWindow::findElementSibling(QDomElement parent, const QString &textToFind)
{
for(QDomElement elem = parent.nextSiblingElement(); !elem.isNull(); elem = elem.nextSiblingElement())
{
if(elem.text()==textToFind) return elem;
QDomElement e = findElementChild(elem, textToFind);
if(!e.isNull()) return e;
}
return QDomElement();
}
void MainWindow::on_gitHubButton_clicked()
{
QString link = "https://github.com/julian-poidevin/MBPMid2010_GPUFix";
QDesktopServices::openUrl(QUrl(link));
return;
}
void MainWindow::on_versionButton_clicked()
{
QString link = "http://github.com/julian-poidevin/MBPMid2010_GPUFix/blob/master/CHANGELOG.md";
QDesktopServices::openUrl(QUrl(link));
return;
}
void MainWindow::on_pushButton_clicked()
{
QString link = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VR3QQDC6GMDCQ";
QDesktopServices::openUrl(QUrl(link));
return;
}