00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Dlg_MakePortableVer.h"
00009 #include "FolderBrowser.h"
00010 #include "mfchelp.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 CDlg_MakePortableVer::CDlg_MakePortableVer(CWnd* pParent )
00019 : CDialog(CDlg_MakePortableVer::IDD, pParent)
00020 {
00021 m_bThreadRunning = false;
00022 m_bNeedStop = false;
00023 }
00024
00025 void CDlg_MakePortableVer::DoDataExchange(CDataExchange* pDX)
00026 {
00027 CDialog::DoDataExchange(pDX);
00028
00029 DDX_Control(pDX, IDC_PROGRESS, m_wndProgress);
00030 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00031
00032 }
00033
00034 BEGIN_MESSAGE_MAP(CDlg_MakePortableVer, CDialog)
00035
00036 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00037
00038 END_MESSAGE_MAP()
00039
00040 void CDlg_MakePortableVer::OnChoosefolder()
00041 {
00042 CString str;
00043 GetDlgItemText (IDC_OUTFOLDER, str);
00044
00045 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00046 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00047
00048 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00049 if (fb == NULL)
00050 return;
00051
00052 SetDlgItemText (IDC_OUTFOLDER, fb->GetPath ());
00053 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00054 }
00055
00056 void CDlg_MakePortableVer::OnOK()
00057 {
00058 CString str;
00059 GetDlgItemText (IDC_OUTFOLDER, str);
00060
00061 if (str.IsEmpty ())
00062 {
00063 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00064 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00065 return;
00066 }
00067
00068 DWORD dw;
00069 m_bThreadRunning = true;
00070 CloseHandle (
00071 CreateThread (NULL, 0, _threadCreatePortableVer, this, 0, &dw));
00072 }
00073
00074 BOOL CDlg_MakePortableVer::OnInitDialog()
00075 {
00076 CDialog::OnInitDialog();
00077
00078 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00079
00080 m_wndProgress.ShowWindow (SW_HIDE);
00081
00082 ApplyLanguage ();
00083
00084 return TRUE;
00085 }
00086
00087 void CDlg_MakePortableVer::ApplyLanguage()
00088 {
00089 fsDlgLngInfo lnginfo [] = {
00090 fsDlgLngInfo (IDC__PVDESC, L_PORTABLE_VER_DESC),
00091 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00092 };
00093
00094 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_MAKE_PORTABLE_VER);
00095 }
00096
00097 DWORD WINAPI CDlg_MakePortableVer::_threadCreatePortableVer(LPVOID lp)
00098 {
00099 CDlg_MakePortableVer *pthis = (CDlg_MakePortableVer*) lp;
00100
00101 pthis->GetDlgItem (IDC_OUTFOLDER)->ShowWindow (SW_HIDE);
00102 pthis->GetDlgItem (IDC_CHOOSEFOLDER)->ShowWindow (SW_HIDE);
00103 pthis->GetDlgItem (IDOK)->EnableWindow (FALSE);
00104
00105 pthis->m_wndProgress.ShowWindow (SW_SHOW);
00106
00107 CString str;
00108 pthis->GetDlgItemText (IDC_OUTFOLDER, str);
00109
00110 if (str [str.GetLength () - 1] != '\\' && str [str.GetLength () - 1] != '/')
00111 str += '\\';
00112 str += "Open Download Manager";
00113
00114 CString str2 = str + "\\1";
00115 fsBuildPathToFile (str2);
00116
00117 int nTotal = 0;
00118
00119 pthis->CopyDirTree (((CFdmApp*)AfxGetApp ())->m_strAppPath, str, nTotal, 0);
00120 pthis->m_wndProgress.SetRange32 (0, nTotal);
00121
00122 int i = 0;
00123 pthis->CopyDirTree (((CFdmApp*)AfxGetApp ())->m_strAppPath, str, i, nTotal);
00124
00125 pthis->m_bThreadRunning = false;
00126 pthis->PostMessage (WM_COMMAND, IDCANCEL);
00127
00128 return 0;
00129 }
00130
00131 void CDlg_MakePortableVer::CopyDirTree(CString SrcPath, CString DstPath, int& nCurIndex, int nTotalCount)
00132 {
00133 CString CrntSrcPath = SrcPath;
00134 CString CrntDstPath;
00135
00136 CFileFind Finder;
00137
00138 CrntSrcPath += _T("\\*");
00139
00140 BOOL bResult = Finder.FindFile(CrntSrcPath);
00141
00142 while (bResult)
00143 {
00144 bResult = Finder.FindNextFile();
00145
00146 if (Finder.IsDots()) continue;
00147
00148 CrntSrcPath = Finder.GetFilePath();
00149 CrntDstPath = DstPath + _T("\\") + Finder.GetFileName();
00150
00151 if (Finder.IsDirectory())
00152 {
00153 if (nTotalCount != 0)
00154 CreateDirectory(CrntDstPath, NULL);
00155 CopyDirTree(CrntSrcPath, CrntDstPath, nCurIndex, nTotalCount);
00156 }
00157 else
00158 {
00159 if (m_bNeedStop)
00160 {
00161 nTotalCount = 0;
00162 return;
00163 }
00164
00165 if (nTotalCount != 0)
00166 CopyFile(CrntSrcPath, CrntDstPath, FALSE);
00167 nCurIndex++;
00168 if (nTotalCount != 0)
00169 m_wndProgress.SetPos (nCurIndex);
00170 }
00171 }
00172
00173 Finder.Close();
00174 }
00175
00176 void CDlg_MakePortableVer::OnCancel()
00177 {
00178 if (m_bThreadRunning)
00179 {
00180 m_bNeedStop = true;
00181 GetDlgItem (IDCANCEL)->EnableWindow (FALSE);
00182 }
00183 else
00184 {
00185 CDialog::OnCancel();
00186 }
00187 }