or NULL for all files.
libpassword - Password (for encrypted archives)
\*-------------------------------------------------------------------------*/
-int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libpassword = NULL, int64_t* iOffset=NULL, bool bShowProgress=false);
+typedef bool (*progress_callback)(void*, int, const char*);
+int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libpassword = NULL, int64_t* iOffset=NULL, progress_callback progress = NULL, void *context = NULL);
/*-------------------------------------------------------------------------*\
List the files in a RAR file
#include "rar.hpp"
#include "UnrarX.hpp"
#include "guilib/GUIWindowManager.h"
-#include "dialogs/GUIDialogProgress.h"
#include "filesystem/File.h"
#include "smallfn.cpp"
or NULL for all files.
libpassword - Password (for encrypted archives)
\*-------------------------------------------------------------------------*/
-int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libpassword, int64_t* iOffset, bool bShowProgress)
+int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libpassword, int64_t* iOffset, progress_callback progress, void *context)
{
InitCRC();
int bRes = 1;
pExtract->GetDataIO().TotalArcSize+=FD.Size;
pExtract->ExtractArchiveInit(pCmd.get(),*pArc);
- if (bShowProgress)
- {
- pExtract->GetDataIO().m_pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
- if (pExtract->GetDataIO().m_pDlgProgress)
- {
- pExtract->GetDataIO().m_pDlgProgress->SetHeading(fileToExtract);
- pExtract->GetDataIO().m_pDlgProgress->SetCanCancel(false);
- pExtract->GetDataIO().m_pDlgProgress->StartModal();
- }
- }
+ pExtract->GetDataIO().m_progress = progress;
+ pExtract->GetDataIO().m_context = context;
int64_t iOff=0;
bool bSeeked = false;
if (pExtract->GetDataIO().bQuit)
{
- if (pExtract->GetDataIO().m_pDlgProgress)
- pExtract->GetDataIO().m_pDlgProgress->Close();
bRes = 2;
break;
}
}
pExtract->GetDataIO().ProcessedArcSize+=FD.Size;
- if (pExtract->GetDataIO().m_pDlgProgress)
- pExtract->GetDataIO().m_pDlgProgress->ShowProgressBar(false);
}
- if (bShowProgress)
- if (pExtract->GetDataIO().m_pDlgProgress)
- pExtract->GetDataIO().m_pDlgProgress->Close();
}
}
}
#include "rar.hpp"
#include "URL.h"
-#include "dialogs/GUIDialogProgress.h"
ComprDataIO::ComprDataIO()
{
CurrentCommand=0;
ProcessedArcSize=TotalArcSize=0;
bQuit = false;
- m_pDlgProgress = NULL;
+ m_progress = NULL;
+ m_context = NULL;
}
int ComprDataIO::UnpRead(byte *Addr,uint Count)
return(-1);
}
CurUnpStart = CurUnpRead;
- if (m_pDlgProgress)
- {
- CURL url(SrcArc->FileName);
- m_pDlgProgress->SetLine(0,url.GetWithoutUserDetails()); // update currently extracted rar file
- m_pDlgProgress->Progress();
- }
+ if (m_progress)
+ m_progress(m_context, -1, SrcArc->FileName);
}
else
break;
}
ShowUnpWrite();
Wait();
- if (m_pDlgProgress)
+ if (m_progress)
{
- m_pDlgProgress->ShowProgressBar(true);
- m_pDlgProgress->SetPercentage(int(float(CurUnpWrite)/float(((Archive*)SrcFile)->NewLhd.FullUnpSize)*100));
- m_pDlgProgress->Progress();
- if (m_pDlgProgress->IsCanceled())
+ if (!m_progress(m_context, int(float(CurUnpWrite)/float(((Archive*)SrcFile)->NewLhd.FullUnpSize)*100), NULL))
bQuit = true;
}
}
#include "system.h"
#include "threads/Event.h"
-class CGUIDialogProgress;
+typedef bool (*progress_callback)(void*, int, const char*);
class ComprDataIO
{
CEvent* hSeek;
CEvent* hSeekDone;
CEvent* hQuit;
- CGUIDialogProgress* m_pDlgProgress;
+ progress_callback m_progress;
+ void* m_context;
bool bQuit;
Int64 m_iSeekTo;
Int64 m_iStartOfBuffer;
#include "FileItem.h"
#include "utils/log.h"
#include "filesystem/File.h"
+#include "URL.h"
#include "dialogs/GUIDialogYesNo.h"
+#include "dialogs/GUIDialogProgress.h"
#include "guilib/GUIWindowManager.h"
#include "utils/StringUtils.h"
ClearCache(true);
}
+class progress_info
+{
+public:
+ progress_info(const std::string &file) : heading(file), shown(false), showTime(200) // 200ms to show...
+ {
+ }
+ ~progress_info()
+ {
+ if (shown)
+ {
+ // close progress dialog
+ CGUIDialogProgress* dlg = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
+ if (dlg)
+ dlg->Close();
+ }
+ }
+ /*! \brief Progress callback from rar manager.
+ \return true to continue processing, false to cancel.
+ */
+ bool progress(int progress, const char *text)
+ {
+ bool cont(true);
+ if (shown || showTime.IsTimePast())
+ {
+ // grab the busy and show it
+ CGUIDialogProgress* dlg = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
+ if (dlg)
+ {
+ if (!shown)
+ {
+ dlg->SetHeading(heading);
+ dlg->StartModal();
+ }
+ if (progress >= 0)
+ {
+ dlg->ShowProgressBar(true);
+ dlg->SetPercentage(progress);
+ }
+ if (text)
+ dlg->SetLine(1, text);
+ cont = !dlg->IsCanceled();
+ shown = true;
+ // tell render loop to spin
+ dlg->Progress();
+ }
+ }
+ return cont;
+ };
+private:
+ std::string heading;
+ bool shown;
+ XbmcThreads::EndTime showTime;
+};
+
+/*! \brief Rar progress callback.
+ \return false to halt progress, true to continue
+ */
+bool ProgressCallback(void *context, int progress, const char *text)
+{
+ progress_info* info = (progress_info*)context;
+ if (info)
+ return info->progress(progress, text);
+ return true;
+}
+
bool CRarManager::CacheRarredFile(std::string& strPathInCache, const std::string& strRarPath, const std::string& strPathInRar, BYTE bOptions, const std::string& strDir, const int64_t iSize)
{
#ifdef HAS_FILESYSTEM_RAR
URIUtils::RemoveSlashAtEnd(strDir2);
if (!CDirectory::Exists(strDir2))
CDirectory::Create(strDir2);
+ progress_info info(CURL(strPath).GetWithoutUserDetails());
iRes = urarlib_get(const_cast<char*>(strRarPath.c_str()), const_cast<char*>(strDir2.c_str()),
- const_cast<char*>(strPath.c_str()),NULL,&iOffset,bShowProgress);
+ const_cast<char*>(strPath.c_str()),NULL,&iOffset,bShowProgress ? ProgressCallback : NULL, &info);
}
if (iRes == 0)
{