2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // SaveDlg.cpp : implementation file
28 #include "..\..\filters\filters.h"
33 IMPLEMENT_DYNAMIC(CSaveDlg
, CCmdUIDialog
)
34 CSaveDlg::CSaveDlg(CString in
, CString out
, CWnd
* pParent
/*=NULL*/)
35 : CCmdUIDialog(CSaveDlg::IDD
, pParent
)
36 , m_in(in
), m_out(out
)
45 void CSaveDlg::DoDataExchange(CDataExchange
* pDX
)
47 CCmdUIDialog::DoDataExchange(pDX
);
48 DDX_Control(pDX
, IDC_ANIMATE1
, m_anim
);
49 DDX_Control(pDX
, IDC_PROGRESS1
, m_progress
);
50 DDX_Control(pDX
, IDC_REPORT
, m_report
);
51 DDX_Control(pDX
, IDC_FROMTO
, m_fromto
);
55 BEGIN_MESSAGE_MAP(CSaveDlg
, CCmdUIDialog
)
56 ON_BN_CLICKED(IDCANCEL
, OnBnClickedCancel
)
57 ON_MESSAGE(WM_GRAPHNOTIFY
, OnGraphNotify
)
62 // CSaveDlg message handlers
64 BOOL
CSaveDlg::OnInitDialog()
66 CCmdUIDialog::OnInitDialog();
68 m_anim
.Open(IDR_AVI_FILECOPY
);
69 m_anim
.Play(0, -1, -1);
71 CString str
, in
= m_in
, out
= m_out
;
72 if(in
.GetLength() > 60) in
= in
.Left(17) + _T("..") + in
.Right(43);
73 if(out
.GetLength() > 60) out
= out
.Left(17) + _T("..") + out
.Right(43);
74 str
.Format(_T("%s\r\n%s"), in
, out
);
75 m_fromto
.SetWindowText(str
);
77 m_progress
.SetRange(0, 100);
79 if(FAILED(pGB
.CoCreateInstance(CLSID_FilterGraph
)) || !(pMC
= pGB
) || !(pME
= pGB
) || !(pMS
= pGB
)
80 || FAILED(pME
->SetNotifyWindow((OAHWND
)m_hWnd
, WM_GRAPHNOTIFY
, 0)))
82 m_report
.SetWindowText(_T("Error"));
89 CComPtr
<IFileSourceFilter
> pReader
;
91 if(!pReader
&& m_in
.Mid(m_in
.ReverseFind('.')+1).MakeLower() == _T("cda"))
94 CComPtr
<IUnknown
> pUnk
= (IUnknown
*)(INonDelegatingUnknown
*)new CCDDAReader(NULL
, &hr
);
95 if(FAILED(hr
) || !(pReader
= pUnk
) || FAILED(pReader
->Load(fnw
, NULL
)))
102 CComPtr
<IUnknown
> pUnk
= (IUnknown
*)(INonDelegatingUnknown
*)new CCDXAReader(NULL
, &hr
);
103 if(FAILED(hr
) || !(pReader
= pUnk
) || FAILED(pReader
->Load(fnw
, NULL
)))
107 if(!pReader
/*&& ext == _T("ifo")*/)
110 CComPtr
<IUnknown
> pUnk
= (IUnknown
*)(INonDelegatingUnknown
*)new CVTSReader(NULL
, &hr
);
111 if(FAILED(hr
) || !(pReader
= pUnk
) || FAILED(pReader
->Load(fnw
, NULL
)))
116 pout
.RenameExtension(_T(".ifo"));
117 CopyFile(m_in
, pout
, FALSE
);
124 CComPtr
<IUnknown
> pUnk
;
125 pUnk
.CoCreateInstance(CLSID_AsyncReader
);
126 if(FAILED(hr
) || !(pReader
= pUnk
) || FAILED(pReader
->Load(fnw
, NULL
)))
133 CComPtr
<IUnknown
> pUnk
;
134 pUnk
.CoCreateInstance(CLSID_URLReader
);
135 if(CComQIPtr
<IBaseFilter
> pSrc
= pUnk
) // url reader has to be in the graph to load the file
137 pGB
->AddFilter(pSrc
, fnw
);
138 if(FAILED(hr
) || !(pReader
= pUnk
) || FAILED(hr
= pReader
->Load(fnw
, NULL
)))
141 pGB
->RemoveFilter(pSrc
);
146 CComQIPtr
<IBaseFilter
> pSrc
= pReader
;
147 if(FAILED(pGB
->AddFilter(pSrc
, fnw
)))
149 m_report
.SetWindowText(_T("Sorry, can't save this file, press cancel"));
153 CComQIPtr
<IBaseFilter
> pMid
= new CStreamDriveThruFilter(NULL
, &hr
);
154 if(FAILED(pGB
->AddFilter(pMid
, L
"StreamDriveThru")))
156 m_report
.SetWindowText(_T("Error"));
160 CComQIPtr
<IBaseFilter
> pDst
;
161 pDst
.CoCreateInstance(CLSID_FileWriter
);
162 CComQIPtr
<IFileSinkFilter2
> pFSF
= pDst
;
163 pFSF
->SetFileName(CStringW(m_out
), NULL
);
164 pFSF
->SetMode(AM_FILE_OVERWRITE
);
165 if(FAILED(pGB
->AddFilter(pDst
, L
"File Writer")))
167 m_report
.SetWindowText(_T("Error"));
172 GetFirstPin((pSrc
), PINDIR_OUTPUT
),
173 GetFirstPin((pMid
), PINDIR_INPUT
));
176 GetFirstPin((pMid
), PINDIR_OUTPUT
),
177 GetFirstPin((pDst
), PINDIR_INPUT
));
183 m_nIDTimerEvent
= SetTimer(1, 1000, NULL
);
185 return TRUE
; // return TRUE unless you set the focus to a control
186 // EXCEPTION: OCX Property Pages should return FALSE
189 void CSaveDlg::OnBnClickedCancel()
196 LRESULT
CSaveDlg::OnGraphNotify(WPARAM wParam
, LPARAM lParam
)
198 LONG evCode
, evParam1
, evParam2
;
199 while(pME
&& SUCCEEDED(pME
->GetEvent(&evCode
, (LONG_PTR
*)&evParam1
, (LONG_PTR
*)&evParam2
, 0)))
201 HRESULT hr
= pME
->FreeEventParams(evCode
, evParam1
, evParam2
);
203 if(EC_COMPLETE
== evCode
)
207 else if(EC_ERRORABORT
== evCode
)
209 TRACE(_T("CSaveDlg::OnGraphNotify / EC_ERRORABORT, hr = %08x\n"), (HRESULT
)evParam1
);
210 m_report
.SetWindowText(_T("Copying unexpectedly terminated!"));
217 void CSaveDlg::OnTimer(UINT nIDEvent
)
219 if(nIDEvent
== m_nIDTimerEvent
&& pGB
)
224 REFERENCE_TIME pos
= 0, dur
= 0;
225 pMS
->GetCurrentPosition(&pos
);
226 pMS
->GetDuration(&dur
);
227 REFERENCE_TIME time
= 0;
228 CComQIPtr
<IMediaSeeking
>(pGB
)->GetCurrentPosition(&time
);
229 REFERENCE_TIME speed
= time
> 0 ? pos
*10000000/time
/ 1024 : 0i64
;
230 str
.Format(_T("%I64d/%I64d KB, %I64d KB/s, %I64d s"),
231 pos
/1024, dur
/1024, speed
, speed
> 0 ? (dur
-pos
)/1024 / speed
: 0);
232 m_report
.SetWindowText(str
);
234 m_progress
.SetPos(dur
> 0 ? (int)(100*pos
/dur
) : 0);
238 CCmdUIDialog::OnTimer(nIDEvent
);