Files
core/Common/FileDownloader/FileDownloader.h
Oleg.Korshul 20c5758525 Merged revision(s) from AVS/Sources/TeamlabOffice/branches/TeamlabOffice_v3.5_CPP:
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@66199 954022d7-b5bf-4e40-9824-e11837661b57
2016-05-21 00:45:20 +03:00

96 lines
2.3 KiB
C++

#pragma once
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/graphics/BaseThread.h"
class CFileDownloaderBase
{
public :
CFileDownloaderBase(std::wstring sFileUrl, bool bDelete = true)
{
m_sFilePath = L"";
m_sFileUrl = sFileUrl;
m_bComplete = false;
m_bDelete = bDelete;
}
virtual ~CFileDownloaderBase ()
{
if ( m_sFilePath.length() > 0 && m_bDelete )
{
NSFile::CFileBinary::Remove(m_sFilePath);
m_sFilePath = L"";
}
}
virtual int DownloadFile() = 0;
public:
std::wstring m_sFilePath; // Путь к сохраненному файлу на диске
std::wstring m_sFileUrl; // Ссылка на скачивание файла
bool m_bComplete; // Закачался файл или нет
bool m_bDelete; // Удалять ли файл в деструкторе
};
class CFileDownloader : public NSThreads::CBaseThread
{
protected:
// создаем в зависимости от платформы
CFileDownloaderBase* m_pInternal;
public:
CFileDownloader(std::wstring sFileUrl, bool bDelete = true);
virtual ~CFileDownloader()
{
Stop();
if (NULL != m_pInternal)
delete m_pInternal;
}
void SetFilePath(const std::wstring& sPath)
{
m_pInternal->m_sFilePath = sPath;
}
std::wstring GetFilePath()
{
return m_pInternal->m_sFilePath;
}
bool IsFileDownloaded()
{
return m_pInternal->m_bComplete;
}
bool DownloadSync()
{
this->Start( 1 );
while ( this->IsRunned() )
{
NSThreads::Sleep( 10 );
}
return IsFileDownloaded();
}
protected :
virtual DWORD ThreadProc ()
{
m_pInternal->m_bComplete = false;
if ( true )
{
int hrResultAll = m_pInternal->DownloadFile();
if (0 != hrResultAll)
{
m_bRunThread = FALSE;
return 0;
}
}
m_pInternal->m_bComplete = true;
m_bRunThread = FALSE;
return 0;
}
};