Skip to content

Commit

Permalink
Support for name.001, name.002, etc naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Panter committed Oct 29, 2011
1 parent 6eb70b9 commit c778bbb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
49 changes: 37 additions & 12 deletions rarfs/src/rararchive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,48 @@ RARArchive::Init(std::string filename)
// Hate this part
this->filename = filename;

volsuffix = ".rar";
voldigits = 0;
if ( filename.size() < extsize )
return false;
while(voldigits+extsize < filename.size() &&
isdigit(filename[filename.size()-extsize-voldigits-1]))
std::string numprefix;
std::size_t offset;

offset = volsuffix.size();
if ( offset <= filename.size() &&
filename.substr(filename.size()-offset) == volsuffix )
{
/* Ends in ".rar"; check for "part<N>.rar" */
numprefix = "part";
}
else
{
/* Try ".<N>" */
volsuffix = "";
numprefix = ".";
}

while(true)
{
offset = voldigits+volsuffix.size();
if ( offset >= filename.size() ||
!isdigit(filename[filename.size()-offset-1]))
{
break;
}

voldigits++;
if ( voldigits > 5 )
return false;
}

const int partsize = 4; /* "part".size() */
if ( filename.size() > partsize + voldigits + extsize &&
filename.substr(filename.size() - extsize - voldigits - partsize,
partsize) == "part" )
offset = numprefix.size() + voldigits + volsuffix.size();
if ( offset <= filename.size() && filename.substr(
filename.size() - offset, numprefix.size()) == numprefix )
{
offset = volsuffix.size()+voldigits;
volprefix = filename.substr(0, filename.size()-offset);
firstfile = atoi( filename.substr(
filename.size()-extsize-voldigits, voldigits).
c_str() );
filename.size()-offset, voldigits).c_str() );
}
else
voldigits = 0;

Expand All @@ -105,14 +129,15 @@ RARArchive::GetFileName(int n)
{
char prev;

f << filename_prefix;
f << volprefix;

prev = f.fill ('0');
f.width (voldigits);
f << n + firstfile;
f.fill(prev);
f.width(0);
f << ".rar";

f << volsuffix;
}

return f.str();
Expand Down
5 changes: 3 additions & 2 deletions rarfs/src/rararchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ class RARArchive
std::vector < std::string > GetFolders();
void GetDate(std::string file, struct timespec* tp);
protected:
static const int extsize = 4; /* ".rar".size() */

std::string filename;
int firstfile;

/* Number of digits used in volume naming scheme
0 => .rar, .r00, .r01, etc extension scheme used instead. */
int voldigits;

std::string volprefix;
std::string volsuffix;

int default_date;
std::vector<RARBlock *> blocks;
std::map<std::string, std::vector<FileBlock *> > fileblocks;
Expand Down

0 comments on commit c778bbb

Please sign in to comment.