MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / NextVolumeName

Function NextVolumeName

Libraries/unrar/pathfn.cpp:354–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352
353
354void NextVolumeName(wchar *ArcName,uint MaxLength,bool OldNumbering)
355{
356 wchar *ChPtr;
357 if ((ChPtr=GetExt(ArcName))==NULL)
358 {
359 wcsncatz(ArcName,L".rar",MaxLength);
360 ChPtr=GetExt(ArcName);
361 }
362 else
363 if (ChPtr[1]==0 || wcsicomp(ChPtr,L".exe")==0 || wcsicomp(ChPtr,L".sfx")==0)
364 wcsncpyz(ChPtr,L".rar",MaxLength-(ChPtr-ArcName));
365
366 if (ChPtr==NULL || *ChPtr!='.' || ChPtr[1]==0)
367 {
368 // Normally we shall have some extension here. If we don't, it means
369 // the name has no extension and buffer has no free space to append one.
370 // Let's clear the name to prevent a new call with same name and return.
371 *ArcName=0;
372 return;
373 }
374
375 if (!OldNumbering)
376 {
377 ChPtr=GetVolNumPart(ArcName);
378
379 // We should not check for IsDigit(*ChPtr) here and should increment
380 // even non-digits. If we got a corrupt archive with volume flag,
381 // but without numeric part, we still need to modify its name somehow,
382 // so while (exist(name)) {NextVolumeName()} loops do not run infinitely.
383 while ((++(*ChPtr))=='9'+1)
384 {
385 *ChPtr='0';
386 ChPtr--;
387 if (ChPtr<ArcName || !IsDigit(*ChPtr))
388 {
389 // Convert .part:.rar (.part9.rar after increment) to part10.rar.
390 for (wchar *EndPtr=ArcName+wcslen(ArcName);EndPtr!=ChPtr;EndPtr--)
391 *(EndPtr+1)=*EndPtr;
392 *(ChPtr+1)='1';
393 break;
394 }
395 }
396 }
397 else
398 if (!IsDigit(ChPtr[2]) || !IsDigit(ChPtr[3]))
399 wcsncpyz(ChPtr+2,L"00",MaxLength-(ChPtr-ArcName)-2); // From .rar to .r00.
400 else
401 {
402 ChPtr+=wcslen(ChPtr)-1; // Set to last character.
403 while (++(*ChPtr)=='9'+1)
404 if (ChPtr<=ArcName || *(ChPtr-1)=='.')
405 {
406 *ChPtr='a'; // From .999 to .a00 if started from .001 or for too short names.
407 break;
408 }
409 else
410 {
411 *ChPtr='0';

Callers 6

RestoreMethod · 0.85
TestMethod · 0.85
RestoreMethod · 0.85
TestMethod · 0.85
MergeArchiveFunction · 0.85
ExtractArchiveMethod · 0.85

Calls 6

GetExtFunction · 0.85
wcsncatzFunction · 0.85
wcsicompFunction · 0.85
wcsncpyzFunction · 0.85
GetVolNumPartFunction · 0.85
IsDigitFunction · 0.85

Tested by 2

TestMethod · 0.68
TestMethod · 0.68