Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/rarfilesource.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOctaneSnail <os@v12pwr.com>2008-12-08 00:56:24 +0300
committerOctaneSnail <os@v12pwr.com>2008-12-08 00:56:24 +0300
commita659d55dbda866e014f7874c1f59736617a9bdc1 (patch)
tree63141f94dcc7cb7d9a1df2a66179cefe74fc3498 /RFS.cpp
parent6b637eab62c11ab63200f110f22f738f5f3b3333 (diff)
If the initial RAR file is in the middle of a multi-volume set, start from the first one instead.
Diffstat (limited to 'RFS.cpp')
-rw-r--r--RFS.cpp95
1 files changed, 65 insertions, 30 deletions
diff --git a/RFS.cpp b/RFS.cpp
index 1e9bee8..fc64b1d 100644
--- a/RFS.cpp
+++ b/RFS.cpp
@@ -205,6 +205,7 @@ STDMETHODIMP CRARFileSource::Load (LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE
DWORD mem_offset = 0;
char *filename = NULL;
wchar_t *current_rar_filename = NULL, *rar_ext;
+ bool first_archive_file = true;
bool multi_volume = false, file_complete = false, new_numbering = false;
rar_header_t rh;
BYTE marker [7];
@@ -314,8 +315,69 @@ STDMETHODIMP CRARFileSource::Load (LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE
return S_FALSE;
}
- new_numbering = new_numbering || (rh.ch.flags & MHD_NEWNUMBERING);
- multi_volume = multi_volume || (rh.ch.flags & MHD_FIRSTVOLUME);
+ if (first_archive_file)
+ {
+ first_archive_file = false;
+
+ new_numbering = rh.ch.flags & MHD_NEWNUMBERING;
+ multi_volume = rh.ch.flags & MHD_VOLUME;
+
+ if (multi_volume)
+ {
+ if (!rar_ext)
+ {
+ ErrorMsg (0, L"Input file does not end with .rar");
+ return S_FALSE;
+ }
+
+ // Locate volume counter
+ if (new_numbering)
+ {
+ volume_digits = 0;
+ do
+ {
+ rar_ext --;
+ volume_digits ++;
+ } while (iswdigit (*(rar_ext - 1)));
+ }
+ else
+ {
+ rar_ext += 2;
+ volume_digits = 2;
+ }
+
+ if (!(rh.ch.flags & MHD_FIRSTVOLUME))
+ {
+ DbgLog ((LOG_TRACE, 2, L"Rewinding to the first file in the set."));
+
+ if (new_numbering)
+ {
+ StringCchPrintf (rar_ext, volume_digits + 1, L"%0*d", volume_digits, 1);
+ rar_ext [volume_digits] = L'.';
+ }
+ else
+ {
+ rar_ext [0] = L'a';
+ rar_ext [1] = L'r';
+ }
+
+ DbgLog ((LOG_TRACE, 2, L"Loading file \"%s\".", current_rar_filename));
+ ha.Close();
+ hFile = CreateFile (current_rar_filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ ErrorMsg (GetLastError (), L"Could not open file \"%s\".", current_rar_filename);
+ return FALSE;
+ }
+ continue;
+ }
+ }
+ }
+ else
+ {
+ ASSERT (new_numbering == (bool) (rh.ch.flags & MHD_NEWNUMBERING));
+ ASSERT (rh.ch.flags & MHD_VOLUME);
+ }
// Find file headers
while (true)
@@ -350,7 +412,7 @@ STDMETHODIMP CRARFileSource::Load (LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE
DbgLog ((LOG_TRACE, 2, L"FILENAME \"%S\"", rh.fh.filename));
- multi_volume = multi_volume || (rh.ch.flags & LHD_SPLIT_AFTER);
+ ASSERT (multi_volume == (bool) (rh.ch.flags & LHD_SPLIT_AFTER));
if (filename)
{
@@ -483,33 +545,6 @@ STDMETHODIMP CRARFileSource::Load (LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE
// Open the next file.
- if (rar_ext)
- {
- if (!files)
- {
- // Locate volume counter
- if (new_numbering)
- {
- volume_digits = 0;
- do
- {
- rar_ext --;
- volume_digits ++;
- } while (iswdigit (*(rar_ext - 1)));
- }
- else
- {
- rar_ext += 2;
- volume_digits = 2;
- }
- }
- }
- else
- {
- ErrorMsg (0, L"Input file does not end with .rar");
- return S_FALSE;
- }
-
files ++;
StringCchPrintf (rar_ext, volume_digits + 1, L"%0*d", volume_digits, new_numbering ? files + 1 : files - 1);