Archive-Unzip-Burst

 view release on metacpan or  search on metacpan

unzip-6.0/macos/source/pathname.c  view on Meta::CPAN

{
char *tmpPtr, *namePtr;
short folderCount = 0;
unsigned short namelen, pathlen = strlen(thePath);

if (thePath[pathlen-1] == ':') thePath[pathlen-1] = 0x0;

for (tmpPtr = thePath; *tmpPtr; tmpPtr++)
    if (*tmpPtr == ':')
        {
        folderCount++;
        namePtr = tmpPtr;
        }

namelen = strlen(namePtr);

    /* we have to eliminate illegal chars:
     * The name space for Mac filenames and Zip filenames (unix style names)
     * do both include all printable extended-ASCII characters.  The only
     * difference we have to take care of is the single special character
     * used as path delimiter:
     * ':' on MacOS and '/' on Unix and '\\' on Dos.
     * So, to convert between Mac filenames and Unix filenames without any
     * loss of information, we simply interchange ':' and '/'.  Additionally,
     * we try to convert the coding of the extended-ASCII characters into
     * InfoZip's standard ISO 8859-1 codepage table.
     */
  MakeCompatibleString(namePtr, '/', '_', '.', '-', -1);

 /* Avoid filenames like: "Archive..zip"  */
if (thePath[pathlen-1] == '.')
    {
    thePath[pathlen-1] = 0;
    }

if (folderCount >= 1)
    { /* path contains at least one folder */

    if (namelen >= 28)
        {
        pathlen = pathlen-4;
        }

    thePath[pathlen]   = '.';
    thePath[pathlen+1] = 'z';
    thePath[pathlen+2] = 'i';
    thePath[pathlen+3] = 'p';
    thePath[pathlen+4] = 0x0;
    return;
    }
else
    {  /* path contains no folder */
    FindDesktopFolder(thePath);
    createArchiveName(thePath);
    }
}



/*
** finds the desktop-folder on a volume with
** largest amount of free-space.
*/

void FindDesktopFolder(char *Path)
{
char buffer[255];
FSSpec  volumes[50];        /* 50 Volumes should be enough */
short   actVolCount, volIndex = 1, VolCount = 0;
OSErr   err;
short     i, foundVRefNum;
FSSpec spec;
UInt64 freeBytes;
UInt64 totalBytes;
UInt64 MaxFreeBytes;

err = OnLine(volumes, 50, &actVolCount, &volIndex);
printerr("OnLine:", (err != -35) && (err != 0), err, __LINE__, __FILE__, "");

MaxFreeBytes = 0;

for (i=0; i < actVolCount; i++)
    {
    XGetVInfo(volumes[i].vRefNum,
              volumes[i].name,
              &volumes[i].vRefNum,
              &freeBytes,
              &totalBytes);

    if (MaxFreeBytes < freeBytes) {
        MaxFreeBytes = freeBytes;
        foundVRefNum = volumes[i].vRefNum;
    }

    if ((freeBytes == 0) && (MaxFreeBytes < freeBytes)) {
        MaxFreeBytes = freeBytes;
        foundVRefNum = volumes[i].vRefNum;
    }

}

 FSpFindFolder(foundVRefNum, kDesktopFolderType,
            kDontCreateFolder,&spec);

 GetFullPathFromSpec(buffer, &spec , &err);
 sstrcat(buffer,Path);
 sstrcpy(Path,buffer);
}


/*
**  return the path without the filename
**
*/

char *TruncFilename(char *DirPath, const char *FilePath)
{
char *tmpPtr;
char *dirPtr = NULL;

AssertStr(DirPath,"TruncFilename")



( run in 0.736 second using v1.01-cache-2.11-cpan-5b529ec07f3 )