|
From: <as...@us...> - 2002-10-20 16:35:41
|
Update of /cvsroot/decaldev/source/DenAgent
In directory usw-pr-cvs1:/tmp/cvs-serv32278
Modified Files:
DownloaderDlg.h DownloaderDlg.cpp AutoUpdate.cpp
Log Message:
Fixed deleting files when autoupdate server was unavailable
Index: DownloaderDlg.h
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/DownloaderDlg.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DownloaderDlg.h 26 May 2002 20:47:31 -0000 1.2
--- DownloaderDlg.h 20 Oct 2002 16:35:36 -0000 1.3
***************
*** 17,20 ****
--- 17,26 ----
// Construction
public:
+ enum DownloadStatus
+ {
+ DOWNLOAD_SUCCEEDED,
+ DOWNLOAD_FAILED
+ };
+
cDownloaderDlg(CWnd* pParent = NULL); // standard constructor
***************
*** 35,38 ****
--- 41,45 ----
bool m_bThreadDone;
+ DownloadStatus GetDownloadStatus();
unsigned long m_ulTotalData;
***************
*** 64,67 ****
--- 71,75 ----
private:
std::vector<FILELIST> m_FileList;
+ bool m_bDownloadSucceeded;
};
Index: DownloaderDlg.cpp
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/DownloaderDlg.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** DownloaderDlg.cpp 26 May 2002 20:47:31 -0000 1.10
--- DownloaderDlg.cpp 20 Oct 2002 16:35:36 -0000 1.11
***************
*** 19,23 ****
cDownloaderDlg::cDownloaderDlg(CWnd* pParent /*=NULL*/)
! : CDialog(cDownloaderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(cDownloaderDlg)
--- 19,23 ----
cDownloaderDlg::cDownloaderDlg(CWnd* pParent /*=NULL*/)
! : CDialog(cDownloaderDlg::IDD, pParent), m_bDownloadSucceeded(false)
{
//{{AFX_DATA_INIT(cDownloaderDlg)
***************
*** 107,113 ****
callback.m_pDlg = this;
-
- //char szFile[MAX_PATH+1];
-
CString strFullURL = m_FileList[i].strFile;
m_stIEMsg.SetWindowText ( strFullURL );
--- 107,110 ----
***************
*** 130,133 ****
--- 127,132 ----
sMsg.Format ( _T("Download failed."), (DWORD) hr );
+ m_bDownloadSucceeded = false;
+
AfxMessageBox ( sMsg );
PostMessage(WM_USER+1, 1, NULL);
***************
*** 135,152 ****
else
{
PostMessage(WM_USER+1, IDCANCEL, NULL);
AfxEndThread(0);
}
} else {
OFSTRUCT targetFile;
! if (OpenFile(m_FileList[i].strFile, &targetFile, OF_EXIST) != HFILE_ERROR)
! DeleteFile(m_FileList[i].strFile);
! MoveFile(m_FileList[i].strLFile, m_FileList[i].strFile);
}
if(g_fAbortDownload)
{
PostMessage(WM_USER+1, IDCANCEL, NULL);
AfxEndThread(0);
--- 134,161 ----
else
{
+ m_bDownloadSucceeded = false;
+
PostMessage(WM_USER+1, IDCANCEL, NULL);
AfxEndThread(0);
}
} else {
+ m_bDownloadSucceeded = true;
+
OFSTRUCT targetFile;
+ OFSTRUCT sourceFile;
! // Make sure we really got a source file
! if (OpenFile(m_FileList[i].strLFile, &sourceFile, OF_EXIST) != HFILE_ERROR)
! {
! if (OpenFile(m_FileList[i].strFile, &targetFile, OF_EXIST) != HFILE_ERROR)
! DeleteFile(m_FileList[i].strFile);
! MoveFile(m_FileList[i].strLFile, m_FileList[i].strFile);
! }
}
if(g_fAbortDownload)
{
+ m_bDownloadSucceeded = false;
PostMessage(WM_USER+1, IDCANCEL, NULL);
AfxEndThread(0);
***************
*** 226,228 ****
--- 235,246 ----
}
return 0;
+ }
+
+ cDownloaderDlg::DownloadStatus cDownloaderDlg::GetDownloadStatus()
+ {
+ if (m_bDownloadSucceeded)
+ return DownloadStatus::DOWNLOAD_SUCCEEDED;
+ else
+ return DownloadStatus::DOWNLOAD_FAILED;
+
}
Index: AutoUpdate.cpp
===================================================================
RCS file: /cvsroot/decaldev/source/DenAgent/AutoUpdate.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AutoUpdate.cpp 27 May 2002 22:44:04 -0000 1.5
--- AutoUpdate.cpp 20 Oct 2002 16:35:36 -0000 1.6
***************
*** 9,13 ****
static LPCSTR updateList = "updatelist.xml" ;
! // DownloadAGent
/* static */ bool DownloadAgent::downloadFile(std::string remoteFile, std::string localFile) {
--- 9,13 ----
static LPCSTR updateList = "updatelist.xml" ;
! // DownloadAgent
/* static */ bool DownloadAgent::downloadFile(std::string remoteFile, std::string localFile) {
***************
*** 20,24 ****
dlg.DoModal();
! return true;
}
--- 20,24 ----
dlg.DoModal();
! return (dlg.GetDownloadStatus() == cDownloaderDlg::DownloadStatus::DOWNLOAD_SUCCEEDED);
}
***************
*** 56,60 ****
dlg.DoModal();
! return true;
}
--- 56,60 ----
dlg.DoModal();
! return (dlg.GetDownloadStatus() == cDownloaderDlg::DownloadStatus::DOWNLOAD_SUCCEEDED);
}
***************
*** 203,212 ****
// Download the remote XML document to a local file
! DownloadAgent::downloadFile(m_RemoteXML, m_DecalDir + "/" + updateList);
// Parse it as an XML document
MSXML::IXMLDOMDocumentPtr pDoc;
! try {
pDoc.CreateInstance (__uuidof(MSXML::DOMDocument), NULL, CLSCTX_INPROC_SERVER);
pDoc->async = false;
--- 203,218 ----
// Download the remote XML document to a local file
! if (!DownloadAgent::downloadFile(m_RemoteXML, m_DecalDir + "/" + updateList))
! {
! // We couldn't download the update list. We must bail here, or suffer!
! ::MessageBox(NULL, "Could not obtain updatelist.xml. Cannot update - Hosting server down?", NULL, MB_OK);
!
! return false;
! }
// Parse it as an XML document
MSXML::IXMLDOMDocumentPtr pDoc;
! // try {
pDoc.CreateInstance (__uuidof(MSXML::DOMDocument), NULL, CLSCTX_INPROC_SERVER);
pDoc->async = false;
***************
*** 295,301 ****
m_RemoteSources.push_back(aUSource);
}
! } catch (...) {
! return false;
! }
return true;
--- 301,307 ----
m_RemoteSources.push_back(aUSource);
}
! // } catch (...) {
! // return false;
! // }
return true;
|