-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathiPodWizardDlg.cpp
More file actions
2281 lines (1983 loc) · 62.1 KB
/
iPodWizardDlg.cpp
File metadata and controls
2281 lines (1983 loc) · 62.1 KB
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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// iPodWizardDlg.cpp : implementation file
//
#include "stdafx.h"
#include "iPodWizard.h"
#include "iPodWizardDlg.h"
#include ".\ipodwizarddlg.h"
#include <afxctl.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "ResourceManager.h"
#include "Picture.h"
#include "ScanDialog.h"
#include "TweaksDialog.h"
#include "HelpDialog.h"
#include "TipDlg.h"
#define BUFSIZE 512
#include <windows.h>
//Help button
BOOL (WINAPI *_TransparentBlt)(HDC, int, int, int, int, HDC, int, int, int, int, UINT) = NULL;
//#import "Zip.lib"
class MyITunesServiceCallback : public IItunesServiceCallback
{
public:
CiPodWizardDlg *ipw;
UINT refCount;
DWORD cookie;
MyITunesServiceCallback(CiPodWizardDlg *pipw)
{
ipw=pipw;
refCount = 1;
cookie = 0;
}
STDMETHOD(QueryInterface)(REFIID iid, void** ppvObject)
{
if (iid == IID_IUnknown)
{
*ppvObject = static_cast<IUnknown*>(this);
}
else if (iid == IID_IDispatch)
{
*ppvObject = static_cast<IDispatch*>(this);
}
else if (iid == IID_IItunesServiceCallback)
{
*ppvObject = static_cast<IItunesServiceCallback*>(this);
}
else
{
*ppvObject = NULL;
return E_NOINTERFACE;
}
static_cast<IUnknown*>(*ppvObject)->AddRef();
return S_OK;
}
STDMETHOD_(ULONG,AddRef)(void)
{
refCount++;
return S_OK;
}
STDMETHOD_(ULONG,Release)(void)
{
refCount--;
if (refCount == 0)
delete this;
return S_OK;
}
STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
{
return E_FAIL;
}
STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
{
return E_FAIL;
}
STDMETHOD(GetIDsOfNames)(const IID &riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
return E_FAIL;
}
STDMETHOD(Invoke)(DISPID dispIdMember, const IID &riid, LCID lcid, WORD wFlags,
DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
return E_FAIL;
}
STDMETHOD(OnDeviceStateChanged)(long hDevice, EItunesDeviceClass devClass, _EDeviceStatus lNewState )
{
ipw->RefreshiPodDrives();
return S_OK;
}
STDMETHOD(OnRequestClientCookie)(unsigned long * pdwCookie)
{
if (pdwCookie)
{
*pdwCookie = cookie;
return S_OK;
}
else
return E_FAIL;
}
};
//Identify iPod
IItunesService *itsv;
IItunesDevices *itdv;
//IItunesServiceCallback *itcb;
//Downgrade
BOOL bEnumSuccess;
int iTotal;
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CiPodWizardDlg dialog
CiPodWizardDlg::CiPodWizardDlg(CWnd* pParent /*=NULL*/)
: CExDialog(CiPodWizardDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_FirmwareFileName.Empty();
m_FirmwareiPSWFileName.Empty();
m_TipFirst = TRUE;
}
void CiPodWizardDlg::DoDataExchange(CDataExchange* pDX)
{
CExDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FIRMWARE_COMBO, m_FirmwareCombo);
DDX_Control(pDX, IDC_MODE_COMBO, m_EditModeCombo);
DDX_Control(pDX, IDC_OPT_TAB, m_OptionsTab);
DDX_Control(pDX, IDC_FIRMWARE_LIST, m_FirmwareList);
DDX_Control(pDX, IDC_IPODDRIVE_COMBO, m_iPodDriveCombo);
}
BEGIN_MESSAGE_MAP(CiPodWizardDlg, CExDialog)
ON_WM_CREATE()
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_WM_TIMER()
//}}AFX_MSG_MAP
ON_BN_CLICKED(ID_OPEN, OnBnClickedOpen)
ON_BN_CLICKED(ID_LOAD_FIRMWARE, OnBnClickedLoadFirmware)
ON_NOTIFY(TCN_SELCHANGE, IDC_OPT_TAB, OnTcnSelchangeOptionTab)
ON_BN_CLICKED(IDC_WRITE_FIRMWARE_BUTTON, OnBnClickedWriteFirmwareButton)
ON_BN_CLICKED(ID_ABOUT, OnBnClickedAbout)
ON_BN_CLICKED(IDC_USYSINFO_BUTTON, OnBnClickedUpdateSysInfo)
//ON_BN_CLICKED(IDC_REFRESHDRV_BUTTON, OnBnClickedRefreshDrives)
ON_BN_CLICKED(ID_TWEAKS, OnBnClickedTweaks)
ON_CBN_SELCHANGE(IDC_IPODDRIVE_COMBO, OnCbnSelChangeiPodDriveCombo)
ON_BN_CLICKED(IDC_LOADIPODFW_BUTTON, OnBnClickedLoadipodfwButton)
ON_CBN_SELCHANGE(IDC_MODE_COMBO, OnCbnSelchangeModeCombo)
ON_BN_CLICKED(ID_EJECT_BUTTON, &CiPodWizardDlg::OnBnClickedEjectButton)
ON_MESSAGE(WM_APP, OniPodEvent)
ON_BN_CLICKED(ID_OPEN_FFILE, &CiPodWizardDlg::OnBnClickedOpenFfile)
ON_BN_CLICKED(IDC_WRITE2IPOD_FIRMWARE_BUTTON, &CiPodWizardDlg::OnBnClickedWrite2ipodFirmwareButton)
ON_NOTIFY(NM_RCLICK, IDC_FIRMWARE_LIST, &CiPodWizardDlg::OnLvnItemRightClickedFirmwareList)
END_MESSAGE_MAP()
// CiPodWizardDlg message handlers
BOOL CiPodWizardDlg::OnInitDialog()
{
CExDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
//ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
//ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//initialize modes
m_EditModeCombo.ResetContent();
m_EditModeCombo.AddString(_T("Updater"));
m_EditModeCombo.AddString(_T("iPod"));
m_EditModeCombo.AddString(_T("Firmware File"));
m_EditModeCombo.AddString(_T("iPodSoftware File"));
m_EditModeCombo.SetCurSel(0);
// initialize list
m_FirmwareList.SetExtendedStyle(m_FirmwareList.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
m_FirmwareList.InsertColumn(0, TEXT("#"), LVCFMT_LEFT, 20);
m_FirmwareList.InsertColumn(1, TEXT("Image Checksum"), LVCFMT_LEFT, 95);
m_FirmwareList.InsertColumn(2, TEXT("Table Checksum"), LVCFMT_LEFT, 95);
m_FirmwareList.InsertColumn(3, TEXT("Status"), LVCFMT_LEFT, 65);
//Initialize pages
CRect rect;
m_OptionsTab.InsertItem(0, TEXT("Firmware editor"));
m_OptionsTab.InsertItem(1, TEXT("Themes"));
m_OptionsTab.InsertItem(2, TEXT("Updater"));
m_OptionsTab.InsertItem(3, TEXT("Preferences"));
m_EditorDialog.Create(m_EditorDialog.IDD, &m_OptionsTab);
m_ThemesDialog.Create(m_ThemesDialog.IDD, &m_OptionsTab);
m_UpdaterDialog.Create(m_UpdaterDialog.IDD, &m_OptionsTab);
m_PrefsDialog.Create(m_PrefsDialog.IDD, &m_OptionsTab);
m_OptionsTab.GetClientRect(&rect);
m_OptionsTab.AdjustRect(FALSE, &rect);
m_EditorDialog.MoveWindow(rect);
m_ThemesDialog.MoveWindow(rect);
m_UpdaterDialog.MoveWindow(rect);
m_PrefsDialog.MoveWindow(rect);
UpdatePages();
CString inipath;
GetAppPath(inipath);
inipath.AppendFormat(TEXT("\\iPW.ini"));
theApp.m_IniPath.SetString(inipath);
// try to read last things
//
CWinApp *pApp = AfxGetApp();
m_Filename = pApp->GetProfileString(TEXT("Main"), TEXT("Updater"));
if (!m_Filename.IsEmpty())
{
OpenUpdater(TRUE);
}
int iChosenMode=0;
iChosenMode=_ttoi(pApp->GetProfileString(TEXT("Main"), TEXT("Mode")));
m_EditModeCombo.SetCurSel(iChosenMode);
OnCbnSelchangeModeCombo();
CString s;
CString firmware = pApp->GetProfileString(TEXT("Main"), TEXT("Firmware"));
if (!firmware.IsEmpty())
{
for (int i = 0; i < m_FirmwareCombo.GetCount(); i++)
{
//m_FirmwareCombo.GetLBText(i, s);
s=m_FirmwareNames.GetAt(i);
if (s == firmware)
{
m_FirmwareCombo.SetCurSel(i);
break;
}
}
}
//ipod detector
CoInitialize(NULL);
const char * gds={"iTunes"};
_bstr_t ghh(gds);
//m_pSink=new MFCSink;
//m_pSink->SetHandler((CWnd *)this);
//HRESULT gb=CoCreateInstance(CLSID_ItunesService, pUnkOuter,CLSCTX_LOCAL_SERVER,DIID_IItunesService,(void**) &itsv);
HRESULT gb=CoCreateInstance(CLSID_ItunesService, NULL,0x17,IID_IItunesService,(void**) &itsv);
if (gb != S_OK)
{
itsv=NULL;
CoUninitialize();
m_COMFindiPod=FALSE;
goto refresh;
}
m_COMFindiPod=TRUE;
IGlobalInterfaceTable *gpGIT;
HRESULT csdfdsf=CoCreateInstance(CLSID_StdGlobalInterfaceTable,NULL,CLSCTX_INPROC_SERVER,IID_IGlobalInterfaceTable,(void **)&gpGIT);
m_dwCookieGlobal=0;
//ServiceCallbackImp *y=new ServiceCallbackImp;
MyITunesServiceCallback *itcb=new MyITunesServiceCallback(this);
HRESULT dfbc=gpGIT->RegisterInterfaceInGlobal((IUnknown *)itcb, IID_IItunesServiceCallback, &m_dwCookieGlobal);
gpGIT->Release();
csdfdsf=CoCreateInstance(CLSID_StdGlobalInterfaceTable,NULL,CLSCTX_INPROC_SERVER,IID_IGlobalInterfaceTable,(void **)&gpGIT);
HRESULT ibb=gpGIT->GetInterfaceFromGlobal(m_dwCookieGlobal, IID_IItunesServiceCallback, (void **)&itcb);
HRESULT gdf=itsv->Login(4, ghh, (IItunesServiceCallback *)itcb, &m_dwCookie);
itsv->GetItunesDevices(m_dwCookie, (IItunesDevices **)&itdv);
HRESULT cvnn=gpGIT->RegisterInterfaceInGlobal((IUnknown *)itdv, IID_IItunesDevices, &m_dwCookieGlobal);
/*LPUNKNOWN m_pUnk=m_pSink->GetIDispatch(FALSE);
if(!AfxConnectionAdvise(y,IID_IItunesServiceCallback,m_pUnk,FALSE,&m_dwCookieSink))
{
itcb=NULL;
CoUninitialize();
goto refresh;
}*/
refresh:
RefreshiPodDrives();
//
//check automatic theme loader
ThemeChecker();
return TRUE; // return TRUE unless you set the focus to a control
}
LRESULT CiPodWizardDlg::OniPodEvent(WPARAM wParam, LPARAM lParam)
{
if (wParam == NULL || lParam == NULL)
return 0;
int mg=(int)wParam;
if (mg!=14)
return 0;
HIPOD ipodid=(HIPOD)lParam;
RefreshiPodDrives();
return 0;
}
void CiPodWizardDlg::ThemeChecker()
{
m_ThemeFirmware.Empty();
m_ThemeFile.Empty();
CString m_strCommandLine;
CString strParam;
CString strFlag;
int nParam = 0;
TCHAR seps1[] = _T("\"");
TCHAR seps2[] = _T(" ");
BOOL bRet = FALSE;
strFlag = _T("");
strParam = _T("");
m_strCommandLine = ::GetCommandLine();
m_strCommandLine.TrimLeft();
m_strCommandLine.TrimRight();
//MessageBox(m_strCommandLine);
int pos1=0,pos2=0;
strParam = m_strCommandLine.Tokenize(seps1, pos1);
strParam = m_strCommandLine.Tokenize(seps1, pos1);
strFlag = strParam.Tokenize(seps2, pos2);
if (strFlag.Compare(_TEXT("-theme"))==0)
{
strParam = m_strCommandLine.Tokenize(seps1, pos1);
if (PathFileExists(strParam)==TRUE)
{
m_ThemeFile = strParam;
CFile file;
if (!file.Open(m_ThemeFile, CFile::modeRead))
{
MessageBox(TEXT("Can't open theme file!"));
return;
}
WORD w;
WORD warr[255];
int n=0;
while (TRUE)
{
if (file.Read(&w, 2) < 2)
{
MessageBox(_T("Error reading theme file!"));
file.Close();
return;
}
warr[n]=w;
n++;
if (w==0)
break;
}
m_ThemeFirmware.Format(TEXT("%s"), (LPCTSTR)warr);
for (int n=0;n<m_FirmwareNames.GetCount();n++)
{
if (m_FirmwareNames.GetAt(n).Compare(m_ThemeFirmware)==0)
{
m_FirmwareCombo.SetCurSel(n);
UpdateData(FALSE);
file.Close();
OnBnClickedLoadFirmware();
return;
}
}
file.Close();
}
else
{
MessageBox(_TEXT("Theme file not found!"));
}
}
}
int CiPodWizardDlg::CheckiPod(BOOL bSilent)
{
if (GetDlgItem(IDC_STATIC_NOTFOUND)->IsWindowVisible()==TRUE)
{
if (bSilent==FALSE)
MessageBox(TEXT("No iPod is connected to the computer!"));
return -1;
}
return 0;
CString temp, path;
m_iPodDriveCombo.GetLBText(m_iPodDriveCombo.GetCurSel(), temp);
path.SetString(temp.Mid(0,2));
path.Append(TEXT("\\iPod_Control\\Device"));
theApp.m_iPodDRV.SetString(path);
if (PathFileExists(path)==FALSE)
{
if (bSilent==FALSE)
MessageBox(TEXT("The iPod drive you chose from the list below is not a valid iPod!"));
return -1;
}
return 0;
}
void CiPodWizardDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if ((nID & 0xFFF0) == SC_MINIMIZEHELP)
{
CHelpDialog dlg(this);
if (CheckiPod(TRUE)==-1)
dlg.DisableFind();
INT_PTR nRet = -1;
nRet = dlg.DoModal();
switch (nRet)
{
case -1:
MessageBox(TEXT("Could not open help dialog!"));
break;
default:
dlg.DestroyWindow();
break;
}
}
else
{
CExDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
int CiPodWizardDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CExDialog::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CiPodWizardDlg::ShowTipAtStartup(void)
{
// CG: This function added by 'Tip of the Day' component.
CCommandLineInfo cmdInfo;
theApp.ParseCommandLine(cmdInfo);
if (cmdInfo.m_bShowSplash)
{
CTipDlg dlg;
if (dlg.m_bStartup)
dlg.DoModal();
}
}
void CiPodWizardDlg::ShowTipOfTheDay(void)
{
// CG: This function added by 'Tip of the Day' component.
CTipDlg dlg;
dlg.DoModal();
}
void CiPodWizardDlg::OnDestroy()
{
if (itsv)
{
itsv->Logout(m_dwCookie);
//LPUNKNOWN m_pUnk=m_pSink->GetIDispatch(FALSE);
//AfxConnectionUnadvise(itcb,IID_IItunesServiceCallback,m_pUnk,FALSE,m_dwCookieSink);
//if(m_pSink!=NULL)
//{
// delete m_pSink;
// m_pSink=NULL;
itsv=NULL;
//itcb=NULL;
itdv=NULL;
//}
CoUninitialize();
}
CExDialog::OnDestroy();
}
void CiPodWizardDlg::OnTimer(UINT nIDEvent)
{
CDialogMinHelpBtn<CDialog>::OnTimer(nIDEvent);
}
void CiPodWizardDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else if (m_TipFirst)
{
m_TipFirst=FALSE;
ShowTipAtStartup();
}
else
{
CExDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CiPodWizardDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CiPodWizardDlg::OnBnClickedOpen()
{
CFileDialog dlg(TRUE, TEXT("exe"), TEXT("iPod Updater*.exe"), OFN_HIDEREADONLY, TEXT("EXE files (*.exe)|*.exe||"), this);
MO_LOAD_FIRMWARE_PATH(dlg)
if (dlg.DoModal() != IDOK)
return;
MO_SAVE_FIRMWARE_PATH(dlg)
m_Filename = dlg.GetPathName();
OpenUpdater(FALSE);
}
void CiPodWizardDlg::OnBnClickedTweaks()
{
if (CheckiPod(FALSE)==-1)
return;
CTweaksDialog dlg(this);
INT_PTR nRet = -1;
nRet = dlg.DoModal();
switch (nRet)
{
case -1:
MessageBox(TEXT("Could not open tweaks dialog!"));
break;
default:
dlg.DestroyWindow();
break;
}
}
/*void CiPodWizardDlg::OnBnClickedRefreshDrives()
{
RefreshiPodDrives();
}*/
LPCTSTR BSTR2TCHAR(_bstr_t st)
{
const int cchWideChar = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)st, -1, NULL, 0);
LPWSTR lpw = new WCHAR [cchWideChar];
if(lpw == NULL){
return NULL;
}
*lpw = L'\0';
const int nUnicodeCount = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)st, -1, lpw, cchWideChar);
if( nUnicodeCount <= 0 ){
delete[] lpw;
return NULL;
}
return (LPCTSTR)lpw;
}
CString CiPodWizardDlg::GetPhysicalDiskFromDevice(LPCTSTR lpDrive, BOOL macFormatted)
{
CString ipod_list;
CString sDrive;
TCHAR drive[9] = TEXT("\\\\.\\A:");
DWORD returned;
STORAGE_DEVICE_NUMBER sdn_drive;
drive[4]=*lpDrive;
TCHAR szName[12];
HANDLE hDrive = CreateFile(drive, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDrive != (HANDLE)-1)
{
if (DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn_drive, sizeof(sdn_drive), &returned, NULL))
sdn_drive.PartitionNumber=1;
else
sdn_drive.PartitionNumber=0;
CloseHandle(hDrive);
}
for (int y=1;y<10;y++)
{
TCHAR devstring[25];
wsprintf (devstring, TEXT("\\\\.\\PHYSICALDRIVE%i"), y);
HANDLE h = CreateFile(devstring, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != (HANDLE)-1)
{
STORAGE_DEVICE_NUMBER sdn;
if (DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &returned, NULL))
{
if (sdn_drive.DeviceNumber == sdn.DeviceNumber && sdn_drive.DeviceType == sdn.DeviceType)
{
if (macFormatted)
{
sDrive.Format(TEXT(" [Mac Formatted]"));
}
else
{
sDrive.Format(TEXT("%s:"), lpDrive);
if (GetVolumeInformation(sDrive, szName, 12, NULL, NULL, NULL, NULL, NULL))
{
if (!_tcscmp(szName, TEXT("")))
sDrive.Format(TEXT(" (No Name)"));
else
sDrive.Format(TEXT(" (%s)"), szName);
}
}
ipod_list.Format(TEXT("%s: %s|"), lpDrive, sDrive);
m_iPodDevices.Add(devstring);
if (lpDrive)
delete[] lpDrive;
CloseHandle(h);
break;
}
}
CloseHandle(h);
}
}
return ipod_list;
}
void CiPodWizardDlg::RefreshiPodDrives()
{
//clean combo
m_iPodDriveCombo.ResetContent();
m_iPodDevices.RemoveAll();
m_iPodHandles.RemoveAll();
CString sDrive;
CString ipod_list; //ipod drives list
if (m_COMFindiPod)
{
//#########COM WAY##############
long ipodid=-1;
int cn=1;
itdv->FindFirstDevice(&ipodid);
while (ipodid>0)
{
VARIANT_BOOL lMnt;
itdv->IsMounted(ipodid, &lMnt);
m_iPodHandles.Add((DWORD)ipodid);
EFormatState kFormat;
if (lMnt==FALSE) //check if mounted
{
unsigned short ver=0;
itdv->GetFirmwareVersion(ipodid, &ver);
//ipod->GetDeviceUniqueID(appid, ipodid)
//check for mac ipod
itdv->GetDriveFormat(ipodid, &kFormat);
if (kFormat==kFormatMac || kFormat==kFormatUnknown || kFormat==kFormatMacNoFirmware)
{
_bstr_t abc2("DDSDGFGFDSGFGDF");
itdv->GetDriveLetter(ipodid, abc2.GetAddress());
LPCTSTR lpDrive2=BSTR2TCHAR(abc2);
ipod_list.Append(GetPhysicalDiskFromDevice(lpDrive2, TRUE));
}
else
{
ipod_list.AppendFormat(TEXT("Unmounted%d (v%d)|"), cn, ver);
cn++;
m_iPodDevices.Add(TEXT(""));
}
}
else if (lMnt==-1)
{
itdv->GetDriveFormat(ipodid, &kFormat);
if (kFormat==kFormatFat32) //only format of fat32 is valid
{
//get physical disk
_bstr_t abc("DDSDGFGFDSGFGDF");
itdv->GetDriveLetter(ipodid, abc.GetAddress());
LPCTSTR lpDrive=BSTR2TCHAR(abc);
ipod_list.Append(GetPhysicalDiskFromDevice(lpDrive, FALSE));
}
}
itdv->FindNextDevice(&ipodid);
}
//#########COM WAY##############
}
else
{
//Find the iPod devices (check hidden partition == firmware)
unsigned char buffer[512];
int x,list[10]={0},y=0;
for (x = 1; x < 10; x++)
{
TCHAR devstring[25];
int j,dev=-1;
wsprintf (devstring, TEXT("\\\\.\\PHYSICALDRIVE%i"), x);
theApp.InitSectorSize(devstring, true);
dev = _wopen (devstring, O_RDONLY | _O_RAW);
if (dev == -1)
continue;
theApp.InitHDDValues(dev);
_lseek(dev, theApp.FIRMWARE_START, SEEK_SET);
_read(dev, buffer, theApp.BLOCK_SIZE);
for (j = 0; j < theApp.BLOCK_SIZE - 6; j++)
{
if (buffer [j] == 'S' && buffer [j+2] == 'T' && buffer [j+4] == 'O' && buffer [j+6] == 'P')
{
y++;
list[y]=x;
}
}
_close(dev);
}
if (y==0) //Why process all the code if there is no iPod device found?
goto ShowStatus;
//Get all volumes devicenumber/devicetype in order to compare with our ipod devices.
int idx;
STORAGE_DEVICE_NUMBER sdn_drives[26];
TCHAR drive[9] = TEXT("\\\\.\\A:");
DWORD driveMask = GetLogicalDrives();
for(idx = 0; idx < 26; idx++, driveMask >>= 1)
{
if (idx==0)
continue;
BOOL b = (driveMask & 1);
if (b)
{
drive[4] = 'A' + idx;
HANDLE hDrive = CreateFile(drive, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDrive != (HANDLE)-1)
{
DWORD returned2;
if (DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn_drives[idx], sizeof(sdn_drives[idx]), &returned2, NULL))
sdn_drives[idx].PartitionNumber=1;
else
sdn_drives[idx].PartitionNumber=0;
CloseHandle(hDrive);
}
}
}
//Check what volumes are compatible with the iPod devices we've found.
for (y=1;y<10;y++)
if (list[y]!=0)
{
TCHAR devstring2[25];
wsprintf (devstring2, TEXT("\\\\.\\PHYSICALDRIVE%i"), list[y]);
HANDLE h = CreateFile(devstring2, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h != (HANDLE)-1)
{
STORAGE_DEVICE_NUMBER sdn;
DWORD returned;
if (DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &returned, NULL))
{
for (idx=0;idx<26;idx++)
if (sdn_drives[idx].DeviceNumber == sdn.DeviceNumber && sdn_drives[idx].DeviceType == sdn.DeviceType)
{
ipod_list.AppendFormat(TEXT("%c:|"), 'A' + idx);
m_iPodDevices.Add(devstring2);
break;
}
}
CloseHandle(h);
}
y++;
}
}
if (ipod_list.Right(1).Compare(TEXT("|"))==0)
ipod_list.Truncate(ipod_list.GetLength()-1);
if (!m_COMFindiPod)
goto ShowStatus;
//Find all iPods
//TCHAR szName[12];
WORD wlast=0;
if (ipod_list.IsEmpty()==TRUE)
{
GetDlgItem(IDC_STATIC_FOUND)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_IPODDRIVE_COMBO)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_NOTFOUND)->ShowWindow(SW_SHOW);
GetDlgItem(ID_EJECT_BUTTON)->EnableWindow(FALSE);
if (m_FirmMode==1)
GetDlgItem(IDC_WRITE_FIRMWARE_BUTTON)->EnableWindow(FALSE);
theApp.m_DeviceSel.Empty();
}
else
{
GetDlgItem(IDC_STATIC_FOUND)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_IPODDRIVE_COMBO)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATIC_NOTFOUND)->ShowWindow(SW_HIDE);
GetDlgItem(ID_EJECT_BUTTON)->EnableWindow(TRUE);
if (ipod_list.Find(TEXT("|"),0)>0)
{
WORD i;
for (i=0;i<ipod_list.GetLength();i++)
if (ipod_list.Mid(i,1).Compare(TEXT("|"))==0)
{
m_iPodDriveCombo.AddString(ipod_list.Mid(wlast, i-wlast));
wlast=i+1;
}
m_iPodDriveCombo.AddString(ipod_list.Mid(wlast, i-wlast));
}
else
{
m_iPodDriveCombo.AddString(ipod_list);
}
sDrive.Format(TEXT("Found %d iPod drives:"), m_iPodDriveCombo.GetCount());
GetDlgItem(IDC_STATIC_FOUND)->SetWindowText(sDrive);
m_iPodDriveCombo.SetCurSel(0);
OnCbnSelChangeiPodDriveCombo();
//add something that if editing ipod firm, make sure the ipod editing isn't out
}
return;
ShowStatus:
//Find all iPods
TCHAR szName[12];
WORD last=0;
if (ipod_list.IsEmpty()==TRUE)
{
GetDlgItem(IDC_STATIC_FOUND)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_IPODDRIVE_COMBO)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_NOTFOUND)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_LOADIPODFW_BUTTON)->EnableWindow(FALSE);
if (m_FirmMode==1)
GetDlgItem(IDC_WRITE_FIRMWARE_BUTTON)->EnableWindow(FALSE);
theApp.m_DeviceSel.Empty();
}
else
{
GetDlgItem(IDC_STATIC_FOUND)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_IPODDRIVE_COMBO)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATIC_NOTFOUND)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_LOADIPODFW_BUTTON)->EnableWindow(TRUE);
CString sDrive;
if (ipod_list.Find(TEXT("|"),0)>0)
{
for (WORD i=0;i<ipod_list.GetLength();i++)
if (ipod_list.Mid(i,1).Compare(TEXT("|"))==0)
{
if (GetVolumeInformation(ipod_list.Mid(last, 3), szName, 12, NULL, NULL, NULL, NULL, NULL))
{
sDrive.Format(TEXT("%s"),ipod_list.Mid(last, 3));
if (!_tcscmp(szName, TEXT("")))
sDrive.AppendFormat(TEXT(" (No Name)"));
else
sDrive.AppendFormat(TEXT(" (%s)"), szName);
}
m_iPodDriveCombo.AddString(sDrive);
last=i+1;
}
if (GetVolumeInformation(ipod_list.Mid(last, 3), szName, 12, NULL, NULL, NULL, NULL, NULL))
{
sDrive.Format(TEXT("%s"),ipod_list.Mid(last, 3));
if (!_tcscmp(szName, TEXT("")))
sDrive.AppendFormat(TEXT(" (No Name)"));
else
sDrive.AppendFormat(TEXT(" (%s)"), szName);
}
m_iPodDriveCombo.AddString(sDrive);
}
else
{
if (GetVolumeInformation(ipod_list, szName, 12, NULL, NULL, NULL, NULL, NULL))
if (!_tcscmp(szName, TEXT("")))
ipod_list.AppendFormat(TEXT(" (No Name)"));
else
ipod_list.AppendFormat(TEXT(" (%s)"), szName);
m_iPodDriveCombo.AddString(ipod_list);
}
sDrive.Format(TEXT("Found %d iPod drives:"), m_iPodDriveCombo.GetCount());
GetDlgItem(IDC_STATIC_FOUND)->SetWindowText(sDrive);
m_iPodDriveCombo.SetCurSel(0);
theApp.m_DeviceSel=m_iPodDevices.GetAt(m_iPodDriveCombo.GetCurSel());
}
}
void CiPodWizardDlg::OnCbnSelChangeiPodDriveCombo()
{
if (m_FirmMode==1)
if (theApp.m_DeviceSel != m_iPodDevices.GetAt(m_iPodDriveCombo.GetCurSel()))
{
if (MessageBox(TEXT("Are you sure you want to select another iPod?\nYou are currently editing an iPod's firmware.\nIf you change now selection, you won't be able to write the changes you've made to the firmware.\nAre you sure you want to continue?"), TEXT("Warning"), MB_YESNO) != IDYES)
return;
}
theApp.m_DeviceSel=m_iPodDevices.GetAt(m_iPodDriveCombo.GetCurSel());
CString checkmac;