aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/UnrarXLib/UnrarX.hpp3
-rw-r--r--lib/UnrarXLib/rar.cpp22
-rw-r--r--lib/UnrarXLib/rdwrfn.cpp19
-rw-r--r--lib/UnrarXLib/rdwrfn.hpp5
-rw-r--r--xbmc/filesystem/RarManager.cpp70
5 files changed, 83 insertions, 36 deletions
diff --git a/lib/UnrarXLib/UnrarX.hpp b/lib/UnrarXLib/UnrarX.hpp
index c2f7c03697..716d89ee2a 100644
--- a/lib/UnrarXLib/UnrarX.hpp
+++ b/lib/UnrarXLib/UnrarX.hpp
@@ -34,7 +34,8 @@ typedef struct archivelist
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
diff --git a/lib/UnrarXLib/rar.cpp b/lib/UnrarXLib/rar.cpp
index 7515f7e26d..a634d0ee97 100644
--- a/lib/UnrarXLib/rar.cpp
+++ b/lib/UnrarXLib/rar.cpp
@@ -1,7 +1,6 @@
#include "rar.hpp"
#include "UnrarX.hpp"
#include "guilib/GUIWindowManager.h"
-#include "dialogs/GUIDialogProgress.h"
#include "filesystem/File.h"
#include "smallfn.cpp"
@@ -142,7 +141,7 @@ int main(int argc, char *argv[])
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;
@@ -200,16 +199,8 @@ int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libp
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;
@@ -237,8 +228,6 @@ int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libp
if (pExtract->GetDataIO().bQuit)
{
- if (pExtract->GetDataIO().m_pDlgProgress)
- pExtract->GetDataIO().m_pDlgProgress->Close();
bRes = 2;
break;
}
@@ -269,12 +258,7 @@ int urarlib_get(char *rarfile, char *targetPath, char *fileToExtract, char *libp
}
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();
}
}
}
diff --git a/lib/UnrarXLib/rdwrfn.cpp b/lib/UnrarXLib/rdwrfn.cpp
index 4eae8fa696..0ca2208f94 100644
--- a/lib/UnrarXLib/rdwrfn.cpp
+++ b/lib/UnrarXLib/rdwrfn.cpp
@@ -1,6 +1,5 @@
#include "rar.hpp"
#include "URL.h"
-#include "dialogs/GUIDialogProgress.h"
ComprDataIO::ComprDataIO()
{
@@ -35,7 +34,8 @@ void ComprDataIO::Init()
CurrentCommand=0;
ProcessedArcSize=TotalArcSize=0;
bQuit = false;
- m_pDlgProgress = NULL;
+ m_progress = NULL;
+ m_context = NULL;
}
int ComprDataIO::UnpRead(byte *Addr,uint Count)
@@ -143,12 +143,8 @@ 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;
@@ -241,12 +237,9 @@ void ComprDataIO::UnpWrite(byte *Addr,uint Count)
}
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;
}
}
diff --git a/lib/UnrarXLib/rdwrfn.hpp b/lib/UnrarXLib/rdwrfn.hpp
index 69d7f5906e..cf6691da2d 100644
--- a/lib/UnrarXLib/rdwrfn.hpp
+++ b/lib/UnrarXLib/rdwrfn.hpp
@@ -7,7 +7,7 @@ class Unpack;
#include "system.h"
#include "threads/Event.h"
-class CGUIDialogProgress;
+typedef bool (*progress_callback)(void*, int, const char*);
class ComprDataIO
{
@@ -90,7 +90,8 @@ 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;
diff --git a/xbmc/filesystem/RarManager.cpp b/xbmc/filesystem/RarManager.cpp
index 5043aeb3f0..0415c1051c 100644
--- a/xbmc/filesystem/RarManager.cpp
+++ b/xbmc/filesystem/RarManager.cpp
@@ -30,8 +30,10 @@
#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"
@@ -64,6 +66,71 @@ CRarManager::~CRarManager()
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
@@ -182,8 +249,9 @@ bool CRarManager::CacheRarredFile(std::string& strPathInCache, const std::string
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)
{