-
Notifications
You must be signed in to change notification settings - Fork 0
/
WimTiVoClientView.cpp
758 lines (727 loc) · 30.2 KB
/
WimTiVoClientView.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
// This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface
// (the "Fluent UI") and is provided only as referential material to supplement the
// Microsoft Foundation Classes Reference and related electronic documentation
// included with the MFC C++ library software.
// License terms to copy, use or distribute the Fluent UI are available separately.
// To learn more about our Fluent UI licensing program, please visit
// http://go.microsoft.com/fwlink/?LinkId=238214.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.
// WimTiVoClientView.cpp : implementation of the CWimTiVoClientView class
//
#include "stdafx.h"
#include "CTiVo.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "WimTiVoClient.h"
#endif
#include "WimTiVoClientDoc.h"
#include "WimTiVoClientView.h"
#include "TiVoMAKDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CWimTiVoClientView
IMPLEMENT_DYNCREATE(CWimTiVoClientView, CListView)
BEGIN_MESSAGE_MAP(CWimTiVoClientView, CListView)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_TIVI_NOWPLAYING, &CWimTiVoClientView::OnTiviNowplaying)
ON_UPDATE_COMMAND_UI(ID_TIVI_NOWPLAYING, &CWimTiVoClientView::OnUpdateTiVoNowplaying)
ON_COMMAND(ID_TIVO_BEACON, &CWimTiVoClientView::OnTivoBeacon)
ON_UPDATE_COMMAND_UI(ID_TIVO_BEACON, &CWimTiVoClientView::OnUpdateTivoBeacon)
ON_COMMAND(ID_TIVO_LIST, &CWimTiVoClientView::OnTivoList)
ON_UPDATE_COMMAND_UI(ID_TIVO_LIST, &CWimTiVoClientView::OnUpdateTivoList)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, &CWimTiVoClientView::OnLvnColumnclick)
ON_UPDATE_COMMAND_UI(ID_TIVODECODE, &CWimTiVoClientView::OnUpdateTiVoDecode)
ON_COMMAND(ID_TIVODECODE, &CWimTiVoClientView::OnTiVoDecode)
ON_COMMAND(ID_FFMPEG, &CWimTiVoClientView::OnFFMPEG)
ON_UPDATE_COMMAND_UI(ID_FFMPEG, &CWimTiVoClientView::OnUpdateFFMPEG)
ON_COMMAND(ID_TIVO_GET_FILES, &CWimTiVoClientView::OnTivoGetFiles)
ON_UPDATE_COMMAND_UI(ID_TIVO_GET_FILES, &CWimTiVoClientView::OnUpdateTivoGetFiles)
ON_COMMAND(ID_TRANSFER_LOG, &CWimTiVoClientView::OnTransferLog)
ON_UPDATE_COMMAND_UI(ID_TRANSFER_LOG, &CWimTiVoClientView::OnUpdateTransferLog)
ON_WM_TIMER()
ON_COMMAND(ID_TIVO_FILE_LOCATION, &CWimTiVoClientView::OnTivoFileLocation)
END_MESSAGE_MAP()
// CWimTiVoClientView construction/destruction
CWimTiVoClientView::CWimTiVoClientView()
{
TRACE(__FUNCTION__ "\n");
// TODO: add construction code here
m_nWindowTimer = 666;
}
CWimTiVoClientView::~CWimTiVoClientView()
{
TRACE(__FUNCTION__ "\n");
}
BOOL CWimTiVoClientView::PreCreateWindow(CREATESTRUCT& cs)
{
TRACE(__FUNCTION__ "\n");
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
void CWimTiVoClientView::OnInitialUpdate()
{
TRACE(__FUNCTION__ "\n");
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
CListCtrl& ListCtrl = GetListCtrl();
ListCtrl.ModifyStyle(NULL, LVS_REPORT); // LVS_SORTASCENDING |
// see http://msdn.microsoft.com/en-us/library/windows/desktop/bb774732(v=vs.85).aspx
ListCtrl.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP);
// http://www.microsoft.com/mspress/books/sampchap/4110c.aspx
// insert columns
ListCtrl.InsertColumn(0, _T("Local File Name"), LVCFMT_LEFT, 330, 0);
ListCtrl.InsertColumn(1, _T("Title"), LVCFMT_LEFT, 110, 1);
ListCtrl.InsertColumn(2, _T("EpisodeTitle"), LVCFMT_LEFT, 100, 2);
ListCtrl.InsertColumn(3, _T("Description"), LVCFMT_LEFT, 100, 3);
ListCtrl.InsertColumn(4, _T("CaptureDate"), LVCFMT_LEFT, 105, 4);
ListCtrl.InsertColumn(5, _T("Duration"), LVCFMT_LEFT, 55, 5);
ListCtrl.InsertColumn(6, _T("Estimated Size"), LVCFMT_RIGHT, 90, 6);
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
pDoc->m_TiVoBeaconListenThreadStopRequested = false;
AfxBeginThread(pDoc->TiVoBeaconListenThread, (LPVOID) GetSafeHwnd());
}
CListView::OnInitialUpdate(); // This needed to be moved to the end because it call's Update, and that manipulated the ListCtrl.
TRACE(__FUNCTION__ " Exiting\n");
}
void CWimTiVoClientView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CWimTiVoClientView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CWimTiVoClientView diagnostics
#ifdef _DEBUG
void CWimTiVoClientView::AssertValid() const
{
CListView::AssertValid();
}
void CWimTiVoClientView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CWimTiVoClientDoc* CWimTiVoClientView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWimTiVoClientDoc)));
return (CWimTiVoClientDoc*)m_pDocument;
}
#endif //_DEBUG
// CWimTiVoClientView message handlers
void CWimTiVoClientView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
TRACE(__FUNCTION__ "\n");
// TODO: Add your specialized code here and/or call the base class
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
CListCtrl& ListCtrl = GetListCtrl();
if (!pDoc->m_TiVoTransferFileThreadRunning)
{
if (0 != ListCtrl.DeleteAllItems())
{
ASSERT(ListCtrl.GetItemCount() == 0);
for(auto TiVoFile = pDoc->m_TiVoFiles.begin(); TiVoFile != pDoc->m_TiVoFiles.end(); TiVoFile++)
{
int nItem = ListCtrl.InsertItem(
LVIF_TEXT | LVIF_STATE,
TiVoFile-pDoc->m_TiVoFiles.begin(),
TiVoFile->GetPathName(),
INDEXTOSTATEIMAGEMASK(1),
LVIS_STATEIMAGEMASK,
0,
NULL);
ListCtrl.SetItemText(nItem, 1, TiVoFile->GetTitle());
ListCtrl.SetItemText(nItem, 2, TiVoFile->GetEpisodeTitle());
ListCtrl.SetItemText(nItem, 3, TiVoFile->GetDescription());
ListCtrl.SetItemText(nItem, 4, TiVoFile->GetCaptureDate().Format(_T("%c")));
ListCtrl.SetItemText(nItem, 5, CTimeSpan(TiVoFile->GetDuration()/1000).Format(_T("%H:%M:%S")));
std::stringstream ss;
std::locale mylocale(""); // get global locale
ss.imbue(mylocale); // imbue global locale
ss << TiVoFile->GetSourceSize();
ListCtrl.SetItemText(nItem, 6, CString(ss.str().c_str()));
}
}
}
CMFCRibbonBar* pRibbon = ((CFrameWndEx*) GetTopLevelFrame())->GetRibbonBar();
if (pRibbon)
{
CMFCRibbonComboBox * TiVoList = DYNAMIC_DOWNCAST(CMFCRibbonComboBox, pRibbon->FindByID(ID_TIVO_LIST));
if (TiVoList)
{
pDoc->m_ccTiVoContainers.Lock();
for (auto TiVo = pDoc->m_TiVoContainers.begin(); TiVo != pDoc->m_TiVoContainers.end(); TiVo++)
TiVoList->AddItem(CString(TiVo->m_title.c_str()));
TiVoList->SelectItem(CString(pDoc->m_TiVoContainer.m_title.c_str()));
// Make sure that something is selected, in case that we didn't match anything in the list.
if (TiVoList->GetCurSel() == LB_ERR)
if (TiVoList->GetCount() > 0)
TiVoList->SelectItem(0);
pDoc->m_TiVoContainer.m_title = CStringA(TiVoList->GetItem(TiVoList->GetCurSel())).GetString();
auto pServer = std::find(pDoc->m_TiVoContainers.begin(), pDoc->m_TiVoContainers.end(), pDoc->m_TiVoContainer);
if (pServer != pDoc->m_TiVoContainers.end())
pDoc->m_TiVoContainer = *pServer;
pDoc->m_ccTiVoContainers.Unlock();
}
CMFCRibbonEdit* pEditTotalTime = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TIVO_TOTAL_TIME));
if (pEditTotalTime)
pEditTotalTime->SetEditText(pDoc->m_TiVoTotalTime.Format(_T("%D Days, %H:%M:%S")));
CMFCRibbonEdit* pEditTotalSize = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TIVO_TOTAL_SIZE));
if (pEditTotalSize)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
junk << pDoc->m_TiVoTotalSize << std::endl;
pEditTotalSize->SetEditText(CString(junk.str().c_str()));
//pEditTotalSize->SetTextAlign(ES_RIGHT);
//pEditTotalSize->SetTextAlwaysOnRight();
}
CMFCRibbonEdit* pEditTiVoFileDestination = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TIVO_FILE_LOCATION));
if (pEditTiVoFileDestination)
pEditTiVoFileDestination->SetEditText(pDoc->m_csTiVoFileDestination);
}
}
CListView::OnUpdate(pSender, lHint, pHint);
TRACE(__FUNCTION__ " Exiting\n");
}
void CWimTiVoClientView::OnTiviNowplaying()
{
TRACE(__FUNCTION__ "\n");
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
CWaitCursor wait;
CString csURL(pDoc->m_TiVoContainer.m_url.c_str());
#ifdef _DEBUG
// I added this on 2021-10-07 when I was attempting to debug a problem retrieving the file list from my Tivo. I'd deleted a football game, but it seems to be half hanging out on the TiVo. On the TV, I can see a group with 5 items listed, but when I look in the group, it only shows 4. That seems to be the stopper file in the normal date based transfer of file listing.
csURL.Append(_T("&SortOrder=Title"));
#endif // !_DEBUG
csURL.Append(_T("&Recurse=Yes"));
csURL.Append(_T("&ItemCount=32"));
if (pDoc->m_LogFile.is_open())
pDoc->m_LogFile << "[ ] XML_Parse_TiVoNowPlaying: " << CStringA(csURL).GetString() << std::endl;
//pDoc->m_LogFile << "[" << getTimeISO8601() << "] XML_Parse_TiVoNowPlaying: " << CStringA(csURL).GetString() << " ContainerCount: " << m_TiVoContainers.size() << std::endl;
pDoc->m_TiVoFiles.clear();
std::vector<CTiVoContainer> TiVoContainers;
if (!XML_Parse_TiVoNowPlaying(csURL, pDoc->m_TiVoFiles, TiVoContainers, pDoc->m_InternetSession))
{
if (pDoc->m_TiVoContainer.m_MAK.empty())
{
CTiVoMAKDlg myDlg;
if (IDOK == myDlg.DoModal())
{
myDlg.m_csMediaAccessKey.Trim();
pDoc->m_TiVoContainer.m_MAK = CStringA(myDlg.m_csMediaAccessKey).GetString();
pDoc->m_ccTiVoContainers.Lock();
auto pContainer = std::find(pDoc->m_TiVoContainers.begin(), pDoc->m_TiVoContainers.end(), pDoc->m_TiVoContainer);
if (pContainer != pDoc->m_TiVoContainers.end())
*pContainer = pDoc->m_TiVoContainer;
pDoc->m_ccTiVoContainers.Unlock();
}
}
TCHAR szScheme[_MAX_PATH];
DWORD dwSchemeLength = sizeof(szScheme) / sizeof(TCHAR);
TCHAR szHostName[_MAX_PATH];
DWORD dwHostNameLength = sizeof(szHostName) / sizeof(TCHAR);
TCHAR szUserName[_MAX_PATH];
DWORD dwUserNameLength = sizeof(szUserName) / sizeof(TCHAR);
TCHAR szPassword[_MAX_PATH];
DWORD dwPasswordLength = sizeof(szPassword) / sizeof(TCHAR);
TCHAR szUrlPath[_MAX_PATH];
DWORD dwUrlPathLength = sizeof(szUrlPath) / sizeof(TCHAR);
TCHAR szExtraInfo[_MAX_PATH];
DWORD dwExtraInfoLength = sizeof(szExtraInfo) / sizeof(TCHAR);
URL_COMPONENTS crackedURL;
crackedURL.dwStructSize = sizeof(URL_COMPONENTS);
crackedURL.lpszScheme = szScheme; // pointer to scheme name
crackedURL.dwSchemeLength = dwSchemeLength; // length of scheme name
crackedURL.nScheme; // enumerated scheme type (if known)
crackedURL.lpszHostName = szHostName; // pointer to host name
crackedURL.dwHostNameLength = dwHostNameLength; // length of host name
crackedURL.nPort; // converted port number
crackedURL.lpszUserName = szUserName; // pointer to user name
crackedURL.dwUserNameLength = dwUserNameLength; // length of user name
crackedURL.lpszPassword = szPassword; // pointer to password
crackedURL.dwPasswordLength = dwPasswordLength; // length of password
crackedURL.lpszUrlPath = szUrlPath; // pointer to URL-path
crackedURL.dwUrlPathLength = dwUrlPathLength; // length of URL-path
crackedURL.lpszExtraInfo = szExtraInfo; // pointer to extra information (e.g. ?foo or #foo)
crackedURL.dwExtraInfoLength = dwExtraInfoLength; // length of extra information
if (TRUE == InternetCrackUrl(csURL.GetString(), csURL.GetLength(), ICU_DECODE, &crackedURL))
{
std::stringstream ss;
ss << CStringA(crackedURL.lpszScheme).GetString() << "://";
ss << "tivo:" << pDoc->m_TiVoContainer.m_MAK << "@";
ss << CStringA(crackedURL.lpszHostName).GetString() << ":" << crackedURL.nPort;
ss << CStringA(crackedURL.lpszUrlPath).GetString() << CStringA(crackedURL.lpszExtraInfo).GetString(); // << "&Recurse=Yes" "&SortOrder=!CaptureDate";
if (pDoc->m_LogFile.is_open())
pDoc->m_LogFile << "[ ] XML_Parse_TiVoNowPlaying: " << CStringA(csURL).GetString() << std::endl;
//pDoc->m_LogFile << "[" << getTimeISO8601() << "] XML_Parse_TiVoNowPlaying: " << CStringA(csURL).GetString() << " ContainerCount: " << m_TiVoContainers.size() << std::endl;
XML_Parse_TiVoNowPlaying(CString(ss.str().c_str()), pDoc->m_TiVoFiles, TiVoContainers, pDoc->m_InternetSession);
}
}
pDoc->m_TiVoTotalTime = CTimeSpan::CTimeSpan();
pDoc->m_TiVoTotalSize = 0;
for (auto TiVoFile = pDoc->m_TiVoFiles.begin(); TiVoFile != pDoc->m_TiVoFiles.end(); TiVoFile++)
{
pDoc->m_TiVoTotalTime += CTimeSpan(TiVoFile->GetDuration()/1000);
pDoc->m_TiVoTotalSize += TiVoFile->GetSourceSize();
}
if (pDoc->m_LogFile.is_open())
pDoc->m_LogFile << "[ ] TiVoNowPlaying Details: Total Time: " << CStringA(pDoc->m_TiVoTotalTime.Format(_T("%D Days, %H:%M:%S"))).GetString() << " Total Size: " << pDoc->m_TiVoTotalSize << " ContainerCount: " << pDoc->m_TiVoContainers.size() << " FileCount: " << pDoc->m_TiVoFiles .size() << std::endl;
//pDoc->m_LogFile << "[" << getTimeISO8601() << "] TiVoNowPlaying Details: Total Time: " << CStringA(pDoc->m_TiVoTotalTime.Format(_T("%D Days, %H:%M:%S"))).GetString() << " Total Size: " << pDoc->m_TiVoTotalSize << " ContainerCount: " << pDoc->m_TiVoContainers.size() << std::endl;
pDoc->UpdateAllViews(NULL);
}
TRACE(__FUNCTION__ " Exiting\n");
}
void CWimTiVoClientView::OnUpdateTiVoNowplaying(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pCmdUI->Enable(!(pDoc->m_TiVoTransferFileThreadRunning));
}
void CWimTiVoClientView::OnTivoBeacon()
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
if (pDoc->m_TiVoBeaconListenThreadRunning)
{
pDoc->m_TiVoBeaconListenThreadStopRequested = true;
// Create a UDP/IP datagram socket
SOCKET theSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (theSocket != INVALID_SOCKET)
{
BOOL bBroadcastSocket = TRUE;
int nRet = setsockopt(theSocket, SOL_SOCKET, SO_BROADCAST, (const char *)&bBroadcastSocket, sizeof(bBroadcastSocket));
if (nRet != SOCKET_ERROR)
{
CStringA csServerBroadcast("tivoconnect=0\n"); // Garbage message that will make the thread accept a packet and check to see if it shoudl continue running.
SOCKADDR_IN saBroadCast;
saBroadCast.sin_family = AF_INET;
saBroadCast.sin_addr.S_un.S_addr = INADDR_BROADCAST;
saBroadCast.sin_port = htons(2190); // Port number
nRet = sendto(theSocket, csServerBroadcast.GetString(), csServerBroadcast.GetLength(), 0, (LPSOCKADDR)&saBroadCast, sizeof(struct sockaddr));
}
closesocket(theSocket);
}
}
else
{
pDoc->m_TiVoBeaconListenThreadStopRequested = false;
AfxBeginThread(pDoc->TiVoBeaconListenThread, (LPVOID) GetSafeHwnd());
}
}
}
void CWimTiVoClientView::OnUpdateTivoBeacon(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pCmdUI->SetCheck(pDoc->m_TiVoBeaconListenThreadRunning);
}
void CWimTiVoClientView::OnTivoList()
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
CMFCRibbonBar* pRibbon = ((CFrameWndEx*) GetTopLevelFrame())->GetRibbonBar();
if (pRibbon)
{
CMFCRibbonComboBox * PortList = DYNAMIC_DOWNCAST(CMFCRibbonComboBox, pRibbon->FindByID(ID_TIVO_LIST));
if (PortList)
{
CString csNewItem(PortList->GetItem(PortList->GetCurSel()));
if (pDoc->m_TiVoContainer.m_title != CStringA(csNewItem).GetString())
{
pDoc->m_TiVoContainer.m_title = CStringA(csNewItem).GetString();
pDoc->m_ccTiVoContainers.Lock();
auto pContainer = std::find(pDoc->m_TiVoContainers.begin(), pDoc->m_TiVoContainers.end(), pDoc->m_TiVoContainer);
if (pContainer != pDoc->m_TiVoContainers.end())
pDoc->m_TiVoContainer = *pContainer;
pDoc->m_ccTiVoContainers.Unlock();
}
}
}
}
}
void CWimTiVoClientView::OnUpdateTivoList(CCmdUI *pCmdUI)
{
//CWimTiVoClientDoc * pDoc = GetDocument();
//if (pDoc)
//{
// CMFCRibbonComboBox * TiVoList = STATIC_CAST(CMFCRibbonComboBox *) pCmdUI;
// if (TiVoList)
// {
// pDoc->m_ccTiVoContainers.Lock();
// for (auto TiVo = pDoc->m_TiVoContainers.begin(); TiVo != pDoc->m_TiVoContainers.end(); TiVo++)
// TiVoList->AddItem(CString(TiVo->m_title.c_str()));
// TiVoList->SelectItem(CString(pDoc->m_TiVoContainer.m_title.c_str()));
// // Make sure that something is selected, in case that we didn't match anything in the list.
// if (TiVoList->GetCurSel() == LB_ERR)
// if (TiVoList->GetCount() > 0)
// TiVoList->SelectItem(0);
// pDoc->m_TiVoContainer.m_title = CStringA(TiVoList->GetItem(TiVoList->GetCurSel())).GetString();
// auto pServer = std::find(pDoc->m_TiVoContainers.begin(), pDoc->m_TiVoContainers.end(), pDoc->m_TiVoContainer);
// if (pServer != pDoc->m_TiVoContainers.end())
// pDoc->m_TiVoContainer = *pServer;
// pDoc->m_ccTiVoContainers.Unlock();
// }
//}
}
void CWimTiVoClientView::OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult)
{
TRACE(__FUNCTION__ "\n");
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
if (pNMLV->iSubItem == 0)
{
static bool forward = true;
if (forward)
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileComparePath);
else
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileComparePathReverse);
forward = !forward;
pDoc->UpdateAllViews(NULL);
}
else if (pNMLV->iSubItem == 4)
{
static bool forward = true;
if (forward)
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileCompareDate);
else
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileCompareDateReverse);
forward = !forward;
pDoc->UpdateAllViews(NULL);
}
else if (pNMLV->iSubItem == 6)
{
static bool forward = true;
if (forward)
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileCompareSize);
else
std::sort(pDoc->m_TiVoFiles.begin(),pDoc->m_TiVoFiles.end(),cTiVoFileCompareSizeReverse);
forward = !forward;
pDoc->UpdateAllViews(NULL);
}
}
*pResult = 0;
TRACE(__FUNCTION__ " Exiting\n");
}
void CWimTiVoClientView::OnTiVoDecode()
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pDoc->m_bTiVoDecode = !pDoc->m_bTiVoDecode;
}
void CWimTiVoClientView::OnUpdateTiVoDecode(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
#ifndef _INTERNAL_TiVoDecode
pCmdUI->Enable(!pDoc->m_csTiVoDecodePath.IsEmpty());
#endif
pCmdUI->SetCheck(pDoc->m_bTiVoDecode);
}
}
void CWimTiVoClientView::OnFFMPEG()
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pDoc->m_bFFMPEG = !pDoc->m_bFFMPEG;
}
void CWimTiVoClientView::OnUpdateFFMPEG(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
pCmdUI->Enable(!pDoc->m_csFFMPEGPath.IsEmpty());
pCmdUI->SetCheck(pDoc->m_bFFMPEG);
}
}
void CWimTiVoClientView::OnTivoGetFiles()
{
TRACE(__FUNCTION__ "\n");
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
pDoc->m_ccTiVoFilesToTransfer.Lock();
while (!pDoc->m_TiVoFilesToTransfer.empty())
pDoc->m_TiVoFilesToTransfer.pop();
pDoc->m_ccTiVoFilesToTransfer.Unlock();
pDoc->m_TiVoFilesToTransferTotalSize = 0;
CListCtrl& ListCtrl = GetListCtrl();
int nItem = -1;
while (-1 < (nItem = ListCtrl.GetNextItem(nItem, LVNI_ALL)))
{
if (ListCtrl.GetCheck(nItem))
{
CString csItem(ListCtrl.GetItemText(nItem,0));
TRACE(_T("Item %d was Checked: %s\n"), nItem, csItem.GetString());
CString csPathToCheckExistence(csItem);
csPathToCheckExistence.Insert(0,pDoc->m_csTiVoFileDestination);
CFileStatus status;
if (TRUE != CFile::GetStatus(csPathToCheckExistence, status)) // Only do a bunch of this stuff if the TiVo file doesn't already exist
{
csPathToCheckExistence.Replace(_T(".TiVo"), _T(".mpeg"));
if (TRUE != CFile::GetStatus(csPathToCheckExistence, status)) // Only do a bunch of this stuff if the mpeg file doesn't already exist
{
csPathToCheckExistence.Replace(_T(".mpeg"), _T(".mp4"));
if (TRUE != CFile::GetStatus(csPathToCheckExistence, status)) // Only do a bunch of this stuff if the mpeg file doesn't already exist
{
cTiVoFile CrapFile;
CrapFile.SetPathName(csItem);
auto TiVoFile = std::find(pDoc->m_TiVoFiles.begin(), pDoc->m_TiVoFiles.end(), CrapFile);
if (pDoc->m_TiVoFiles.end() != TiVoFile)
{
pDoc->m_TiVoFilesToTransferTotalSize += TiVoFile->GetSourceSize();
pDoc->m_ccTiVoFilesToTransfer.Lock();
pDoc->m_TiVoFilesToTransfer.push(*TiVoFile);
pDoc->m_ccTiVoFilesToTransfer.Unlock();
}
}
#ifdef _DEBUG
else TRACE(_T("File Exists: %s\n"), status.m_szFullName);
#endif
}
#ifdef _DEBUG
else TRACE(_T("File Exists: %s\n"), status.m_szFullName);
#endif
}
#ifdef _DEBUG
else TRACE(_T("File Exists: %s\n"), status.m_szFullName);
#endif
}
}
CMFCRibbonBar* pRibbon = ((CFrameWndEx*) GetTopLevelFrame())->GetRibbonBar();
if (pRibbon)
{
CMFCRibbonEdit* pEditTransferCount = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_COUNT));
if (pEditTransferCount)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
pDoc->m_ccTiVoFilesToTransfer.Lock();
junk << pDoc->m_TiVoFilesToTransfer.size();
pDoc->m_ccTiVoFilesToTransfer.Unlock();
pEditTransferCount->SetEditText(CString(junk.str().c_str()));
}
CMFCRibbonEdit* pEditTransferSize = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_SIZE));
if (pEditTransferSize)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
junk << pDoc->m_TiVoFilesToTransferTotalSize;
pEditTransferSize->SetEditText(CString(junk.str().c_str()));
}
}
CFrameWndEx* mainFrm = dynamic_cast<CFrameWndEx*>(GetTopLevelFrame());
if (mainFrm)
{
mainFrm->SetProgressBarState(TBPF_NORMAL);
mainFrm->SetProgressBarRange(0, 100);
mainFrm->SetProgressBarPosition(pDoc->m_CurrentFileProgress);
}
m_csOriginalTitle = ((CFrameWndEx*) GetTopLevelFrame())->GetTitle();
pDoc->m_TiVoTransferFileThreadStopRequested = false;
if (!pDoc->m_TiVoTransferFileThreadRunning)
AfxBeginThread(pDoc->TiVoTransferFileThread, (LPVOID) GetSafeHwnd());
if (!pDoc->m_TiVoConvertFileThreadRunning)
AfxBeginThread(pDoc->TiVoConvertFileThread, (LPVOID) GetSafeHwnd());
m_nWindowTimer = SetTimer(m_nWindowTimer, 1000, NULL);
}
TRACE(__FUNCTION__ " Exiting\n");
}
void CWimTiVoClientView::OnUpdateTivoGetFiles(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pCmdUI->Enable(!(pDoc->m_TiVoTransferFileThreadRunning));
}
void CWimTiVoClientView::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (m_nWindowTimer == nIDEvent)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
{
if (!pDoc->m_TiVoTransferFileThreadRunning)
{
KillTimer(m_nWindowTimer);
((CFrameWndEx*) GetTopLevelFrame())->SetTitle(m_csOriginalTitle);
CFrameWndEx* mainFrm = dynamic_cast<CFrameWndEx*>(GetTopLevelFrame());
if (mainFrm)
mainFrm->SetProgressBarState(TBPF_NOPROGRESS);
pDoc->UpdateAllViews(NULL);
}
else
{
CFrameWndEx* mainFrm = dynamic_cast<CFrameWndEx*>(GetTopLevelFrame());
if (mainFrm)
mainFrm->SetProgressBarPosition(pDoc->m_CurrentFileProgress);
pDoc->m_ccTiVoFilesToTransfer.Lock();
std::queue<cTiVoFile> TiVoFilesToTransfer(pDoc->m_TiVoFilesToTransfer);
pDoc->m_ccTiVoFilesToTransfer.Unlock();
CListCtrl& ListCtrl = GetListCtrl();
if (ListCtrl.GetItemCount() != TiVoFilesToTransfer.size())
{
if (0 != ListCtrl.DeleteAllItems())
{
int ItemNum = 0;
ASSERT(ListCtrl.GetItemCount() == 0);
while (!TiVoFilesToTransfer.empty())
{
int nItem = ListCtrl.InsertItem(
LVIF_TEXT | LVIF_STATE,
ItemNum++,
TiVoFilesToTransfer.front().GetPathName(),
INDEXTOSTATEIMAGEMASK(1),
LVIS_STATEIMAGEMASK,
0,
NULL);
ListCtrl.SetItemText(nItem, 1, TiVoFilesToTransfer.front().GetTitle());
ListCtrl.SetItemText(nItem, 2, TiVoFilesToTransfer.front().GetEpisodeTitle());
ListCtrl.SetItemText(nItem, 3, TiVoFilesToTransfer.front().GetDescription());
ListCtrl.SetItemText(nItem, 4, TiVoFilesToTransfer.front().GetCaptureDate().Format(_T("%c")));
ListCtrl.SetItemText(nItem, 5, CTimeSpan(TiVoFilesToTransfer.front().GetDuration()/1000).Format(_T("%H:%M:%S")));
ListCtrl.SetCheck(nItem);
std::stringstream ss;
std::locale mylocale(""); // get global locale
ss.imbue(mylocale); // imbue global locale
ss << TiVoFilesToTransfer.front().GetSourceSize();
ListCtrl.SetItemText(nItem, 6, CString(ss.str().c_str()));
TiVoFilesToTransfer.pop();
}
}
}
}
CString csTitleBar(m_csOriginalTitle);
csTitleBar.AppendFormat(_T(" Transferring File: %s %ld %ld B/s"), pDoc->m_CurrentFileName.GetString(), pDoc->m_TiVoFilesToTransferTotalSize, pDoc->m_CurrentFileSpeed);
((CFrameWndEx*) GetTopLevelFrame())->SetTitle(csTitleBar);
CMFCRibbonBar* pRibbon = ((CFrameWndEx*) GetTopLevelFrame())->GetRibbonBar();
if (pRibbon)
{
CMFCRibbonEdit* pEditCurrentFileName = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_CURRENT_FILE_NAME));
if (pEditCurrentFileName)
pEditCurrentFileName->SetEditText(pDoc->m_CurrentFileName);
CMFCRibbonEdit* pEditCurrentFileSize = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_CURRENT_FILE_SIZE));
if (pEditCurrentFileSize)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
junk << pDoc->m_CurrentFileSize;
pEditCurrentFileSize->SetEditText(CString(junk.str().c_str()));
}
CMFCRibbonEdit* pEditCurrentSpeed = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_SPEED));
if (pEditCurrentSpeed)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
junk << pDoc->m_CurrentFileSpeed << " B/s";
pEditCurrentSpeed->SetEditText(CString(junk.str().c_str()));
}
CMFCRibbonEdit* pEditCurrentETR = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_ETR));
if (pEditCurrentETR)
pEditCurrentETR->SetEditText(pDoc->m_CurrentFileEstimatedTimeRemaining.Format(_T("%H:%M:%S")));
CMFCRibbonProgressBar* pEditCurrentFileProgress = DYNAMIC_DOWNCAST(CMFCRibbonProgressBar, pRibbon->FindByID(ID_TRANSFER_CURRENT_FILE_PROGRESS));
if (pEditCurrentFileProgress)
pEditCurrentFileProgress->SetPos(pDoc->m_CurrentFileProgress);
CMFCRibbonProgressBar* pEditTotalFileProgress = DYNAMIC_DOWNCAST(CMFCRibbonProgressBar, pRibbon->FindByID(ID_TRANSFER_TOTAL_FILE_PROGRESS));
if (pEditTotalFileProgress)
pEditTotalFileProgress->SetPos(pDoc->m_TotalFileProgress);
CMFCRibbonEdit* pEditTransferCount = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_COUNT));
if (pEditTransferCount)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
pDoc->m_ccTiVoFilesToTransfer.Lock();
junk << pDoc->m_TiVoFilesToTransfer.size();
pDoc->m_ccTiVoFilesToTransfer.Unlock();
pEditTransferCount->SetEditText(CString(junk.str().c_str()));
}
CMFCRibbonEdit* pEditTransferSize = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_SIZE));
if (pEditTransferSize)
{
std::stringstream junk;
std::locale mylocale(""); // get global locale
junk.imbue(mylocale); // imbue global locale
junk << pDoc->m_TiVoFilesToTransferTotalSize;
pEditTransferSize->SetEditText(CString(junk.str().c_str()));
}
CMFCRibbonEdit* pEditCurrentTTR = DYNAMIC_DOWNCAST(CMFCRibbonEdit, pRibbon->FindByID(ID_TRANSFER_TTR));
if (pEditCurrentTTR)
pEditCurrentTTR->SetEditText(pDoc->m_TotalFileEstimatedTimeRemaining.Format(_T("%H:%M:%S")));
}
}
}
else
CListView::OnTimer(nIDEvent); // If you pass your own timer event to the parent class it will kill off the timer.
}
void CWimTiVoClientView::OnTransferLog()
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
if (pDoc->m_LogFile.is_open())
pDoc->LogFileClose();
else
pDoc->LogFileOpen();
}
void CWimTiVoClientView::OnUpdateTransferLog(CCmdUI *pCmdUI)
{
CWimTiVoClientDoc * pDoc = GetDocument();
if (pDoc)
pCmdUI->SetCheck(pDoc->m_LogFile.is_open());
}
void CWimTiVoClientView::OnTivoFileLocation()
{
//BROWSEINFO bi;
//ZeroMemory(&bi, sizeof(BROWSEINFO));
//bi.hwndOwner = m_hWnd;
//bi.ulFlags = BIF_RETURNONLYFSDIRS;
//LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
//BOOL bRet = FALSE;
//TCHAR szFolder[MAX_PATH*2];
////SHGetFolderPath(NULL, CSIDL_MYVIDEO, NULL, 0, szFolder);
//szFolder[0] = _T('\0');
//if (pidl)
//{
// if (SHGetPathFromIDList(pidl, szFolder))
// {
// bRet = TRUE;
// }
// IMalloc *pMalloc = NULL;
// if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
// {
// pMalloc->Free(pidl);
// pMalloc->Release();
// }
//}
////Return value is kept in szFolder.
//AfxMessageBox(szFolder);
//CFolderPickerDlg
//CFileDialog myDlg(TRUE,0,0,FOS_PICKFOLDERS);
//myDlg.
//myDlg.DoModal();
// TODO: Add your command handler code here
}