unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

recvol.cpp
Go to the documentation of this file.
1#include "rar.hpp"
2
3#include "recvol3.cpp"
4#include "recvol5.cpp"
5
6
7
8bool RecVolumesRestore(RAROptions *Cmd,const wchar *Name,bool Silent)
9{
10 Archive Arc(Cmd);
11 if (!Arc.Open(Name))
12 {
13 if (!Silent)
15 return false;
16 }
17
19 if (Arc.IsArchive(true))
20 Fmt=Arc.Format;
21 else
22 {
23 byte Sign[REV5_SIGN_SIZE];
24 Arc.Seek(0,SEEK_SET);
25 if (Arc.Read(Sign,REV5_SIGN_SIZE)==REV5_SIGN_SIZE && memcmp(Sign,REV5_SIGN,REV5_SIGN_SIZE)==0)
26 Fmt=RARFMT50;
27 }
28 Arc.Close();
29
30 // We define RecVol as local variable for proper stack unwinding when
31 // handling exceptions. So it can close and delete files on Cancel.
32 if (Fmt==RARFMT15)
33 {
34 RecVolumes3 RecVol(Cmd,false);
35 return RecVol.Restore(Cmd,Name,Silent);
36 }
37 else
38 {
39 RecVolumes5 RecVol(Cmd,false);
40 return RecVol.Restore(Cmd,Name,Silent);
41 }
42}
43
44
45void RecVolumesTest(RAROptions *Cmd,Archive *Arc,const wchar *Name)
46{
47 wchar RevName[NM];
48 *RevName=0;
49 if (Arc!=NULL)
50 {
51 // We received .rar or .exe volume as a parameter, trying to find
52 // the matching .rev file number 1.
53 bool NewNumbering=Arc->NewNumbering;
54
55 wchar ArcName[NM];
56 wcsncpyz(ArcName,Name,ASIZE(ArcName));
57
58 wchar *VolNumStart=VolNameToFirstName(ArcName,ArcName,ASIZE(ArcName),NewNumbering);
59 wchar RecVolMask[NM];
60 wcsncpyz(RecVolMask,ArcName,ASIZE(RecVolMask));
61 size_t BaseNamePartLength=VolNumStart-ArcName;
62 wcsncpyz(RecVolMask+BaseNamePartLength,L"*.rev",ASIZE(RecVolMask)-BaseNamePartLength);
63
64 FindFile Find;
65 Find.SetMask(RecVolMask);
66 FindData RecData;
67
68 while (Find.Next(&RecData))
69 {
70 wchar *Num=GetVolNumPart(RecData.Name);
71 if (*Num!='1') // Name must have "0...01" numeric part.
72 continue;
73 bool FirstVol=true;
74 while (--Num>=RecData.Name && IsDigit(*Num))
75 if (*Num!='0')
76 {
77 FirstVol=false;
78 break;
79 }
80 if (FirstVol)
81 {
82 wcsncpyz(RevName,RecData.Name,ASIZE(RevName));
83 Name=RevName;
84 break;
85 }
86 }
87 if (*RevName==0) // First .rev file not found.
88 return;
89 }
90
91 File RevFile;
92 if (!RevFile.Open(Name))
93 {
94 ErrHandler.OpenErrorMsg(Name); // It also sets RARX_OPEN.
95 return;
96 }
97 mprintf(L"\n");
98 byte Sign[REV5_SIGN_SIZE];
99 bool Rev5=RevFile.Read(Sign,REV5_SIGN_SIZE)==REV5_SIGN_SIZE && memcmp(Sign,REV5_SIGN,REV5_SIGN_SIZE)==0;
100 RevFile.Close();
101 if (Rev5)
102 {
103 RecVolumes5 RecVol(Cmd,true);
104 RecVol.Test(Cmd,Name);
105 }
106 else
107 {
108 RecVolumes3 RecVol(Cmd,true);
109 RecVol.Test(Cmd,Name);
110 }
111}
RARFORMAT
Definition: archive.hpp:13
@ RARFMT50
Definition: archive.hpp:13
@ RARFMT15
Definition: archive.hpp:13
ErrorHandler ErrHandler
bool IsArchive(bool EnableBroken)
Definition: archive.cpp:126
RARFORMAT Format
Definition: archive.hpp:117
bool NewNumbering
Definition: archive.hpp:124
void OpenErrorMsg(const wchar *FileName)
Definition: errhnd.cpp:164
Definition: file.hpp:57
virtual void Seek(int64 Offset, int Method)
Definition: file.cpp:514
virtual int Read(void *Data, size_t Size)
Definition: file.cpp:374
virtual bool Open(const wchar *Name, uint Mode=FMF_READ)
Definition: file.cpp:48
virtual bool Close()
Definition: file.cpp:241
void SetMask(const wchar *Mask)
Definition: find.cpp:27
bool Next(FindData *fd, bool GetSymLink=false)
Definition: find.cpp:34
bool Restore(RAROptions *Cmd, const wchar *Name, bool Silent)
Definition: recvol3.cpp:102
void Test(RAROptions *Cmd, const wchar *Name)
Definition: recvol3.cpp:500
void Test(RAROptions *Cmd, const wchar *Name)
Definition: recvol5.cpp:497
bool Restore(RAROptions *Cmd, const wchar *Name, bool Silent)
Definition: recvol5.cpp:144
void mprintf(const wchar *fmt,...)
Definition: consio.cpp:118
wchar * VolNameToFirstName(const wchar *VolName, wchar *FirstName, size_t MaxSize, bool NewNumbering)
Definition: pathfn.cpp:632
wchar * GetVolNumPart(const wchar *ArcName)
Definition: pathfn.cpp:320
#define ASIZE(x)
Definition: rardefs.hpp:10
wchar_t wchar
Definition: rartypes.hpp:13
bool RecVolumesRestore(RAROptions *Cmd, const wchar *Name, bool Silent)
Definition: recvol.cpp:8
void RecVolumesTest(RAROptions *Cmd, Archive *Arc, const wchar *Name)
Definition: recvol.cpp:45
#define REV5_SIGN_SIZE
Definition: recvol.hpp:5
#define REV5_SIGN
Definition: recvol.hpp:4
void wcsncpyz(wchar *dest, const wchar *src, size_t maxlen)
Definition: strfn.cpp:275
bool IsDigit(int ch)
Definition: strfn.cpp:151
Definition: find.hpp:9
wchar Name[NM]
Definition: find.hpp:10