aboutsummaryrefslogtreecommitdiff
path: root/lib/UnrarXLib
diff options
context:
space:
mode:
authorJonathan Marshall <jmarshall@xbmc.org>2014-06-09 21:13:00 +1200
committerJonathan Marshall <jmarshall@xbmc.org>2014-07-14 14:21:22 +1200
commit2fcd1b4b6d77eb8eb4e56fc61b0bc1b3e230db4d (patch)
tree4cbeb332d8cf042c3504cc8f1a8703d81c02db3a /lib/UnrarXLib
parent7b8fcdbfa67b842fa427c79a0f75e940ddbdfb75 (diff)
[rar] add a callback class for unrarlib rather than calling into guilib direct from UnrarXLib
Diffstat (limited to 'lib/UnrarXLib')
-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
4 files changed, 14 insertions, 35 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;