"Fossies" - the Fresh Open Source Software Archive

Member "unrar/recvol.cpp" (4 May 2022, 2609 Bytes) of package /linux/misc/unrarsrc-6.1.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "recvol.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "rar.hpp"
    2 
    3 #include "recvol3.cpp"
    4 #include "recvol5.cpp"
    5 
    6 
    7 
    8 bool RecVolumesRestore(RAROptions *Cmd,const wchar *Name,bool Silent)
    9 {
   10   Archive Arc(Cmd);
   11   if (!Arc.Open(Name))
   12   {
   13     if (!Silent)
   14       ErrHandler.OpenErrorMsg(Name);
   15     return false;
   16   }
   17 
   18   RARFORMAT Fmt=RARFMT15;
   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 
   45 void 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 }