/slides
* PathInTree = "descarga/lectures/lecture_1/slides
*/
// Return: full size of directory contents
static unsigned long long ZIP_CloneDir (const char *Path,const char *PathClone,const char *PathInTree)
{
struct dirent **FileList;
int NumFile;
int NumFiles;
char PathFile[PATH_MAX + 1];
char PathFileClone[PATH_MAX + 1];
char PathFileInTree[PATH_MAX + 1];
struct stat FileStatus;
Brw_FileType_t FileType;
bool Hidden;
bool SeeDocsZone = Gbl.FileBrowser.Type == Brw_SHOW_DOC_INS ||
Gbl.FileBrowser.Type == Brw_SHOW_DOC_CTR ||
Gbl.FileBrowser.Type == Brw_SHOW_DOC_DEG ||
Gbl.FileBrowser.Type == Brw_SHOW_DOC_CRS ||
Gbl.FileBrowser.Type == Brw_SHOW_DOC_GRP;
bool SeeMarks = Gbl.FileBrowser.Type == Brw_SHOW_MRK_CRS ||
Gbl.FileBrowser.Type == Brw_SHOW_MRK_GRP;
unsigned long long FullSize = 0;
/***** Scan directory *****/
if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
{
/***** List files *****/
for (NumFile = 0;
NumFile < NumFiles;
NumFile++)
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
snprintf (PathFileInTree,sizeof (PathFileInTree),
"%s/%s",
PathInTree,FileList[NumFile]->d_name);
snprintf (PathFile,sizeof (PathFile),
"%s/%s",
Path,FileList[NumFile]->d_name);
snprintf (PathFileClone,sizeof (PathFileClone),
"%s/%s",
PathClone,FileList[NumFile]->d_name);
FileType = Brw_IS_UNKNOWN;
if (lstat (PathFile,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
FileType = Brw_IS_FOLDER;
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
FileType = Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK : // It's a link (URL inside a .url file)
Brw_IS_FILE; // It's a file
Hidden = (SeeDocsZone || SeeMarks) ? Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (FileType,PathFileInTree) :
false;
if (!Hidden) // If file/folder is not hidden
{
if (FileType == Brw_IS_FOLDER) // It's a directory
{
FullSize += (unsigned long long) FileStatus.st_size;
/***** Create clone of subdirectory *****/
if (mkdir (PathFileClone,(mode_t) 0xFFF))
Lay_ShowErrorAndExit ("Can not create temporary subfolder for compression.");
/***** Clone subtree starting at this this directory *****/
FullSize += ZIP_CloneDir (PathFile,PathFileClone,PathFileInTree);
}
else if (FileType == Brw_IS_FILE ||
FileType == Brw_IS_LINK) // It's a regular file
{
FullSize += (unsigned long long) FileStatus.st_size;
/***** Create a symbolic link (clone) to original file *****/
if (symlink (PathFile,PathFileClone) != 0)
Lay_ShowErrorAndExit ("Can not create temporary link for compression.");
/***** Update number of my views of this file *****/
Brw_UpdateMyFileViews (Brw_GetFilCodByPath (PathFileInTree,false)); // Any file, public or not
}
}
}
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
return FullSize;
}
/*****************************************************************************/
/********************* Show link to download a ZIP file **********************/
/*****************************************************************************/
static void ZIP_ShowLinkToDownloadZIP (const char *FileName,const char *URL,
off_t FileSize,unsigned long long UncompressedSize)
{
extern const char *The_ClassFormInBox[The_NUM_THEMES];
extern const char *Txt_ZIP_file;
extern const char *Txt_Download;
extern const char *Txt_Filename;
extern const char *Txt_File_size;
extern const char *Txt_FILE_uncompressed;
char FileSizeStr[Fil_MAX_BYTES_FILE_SIZE_STRING + 1];
/***** Start box and table *****/
Box_StartBoxTableShadow (NULL,NULL,NULL,NULL,2);
/***** Link to download the file *****/
Tbl_StartRow ();
fprintf (Gbl.F.Out,""
""
""
" %s "
""
"",
URL,FileName,
CfG_URL_ICON_FILEXT_PUBLIC,
Txt_ZIP_file,
Txt_ZIP_file,
FileName,
Cfg_URL_ICON_PUBLIC,
Txt_Download,
Txt_Download);
Tbl_EndCell ();
Tbl_EndRow ();
/***** Filename *****/
Tbl_StartRow ();
fprintf (Gbl.F.Out," | "
"%s:",
The_ClassFormInBox[Gbl.Prefs.Theme],Txt_Filename);
Tbl_EndCell ();
fprintf (Gbl.F.Out," | "
"%s",
URL,FileName,FileName);
Tbl_EndCell ();
Tbl_EndRow ();
/***** Write the file size *****/
Fil_WriteFileSizeFull ((double) FileSize,FileSizeStr);
Tbl_StartRow ();
fprintf (Gbl.F.Out," | "
"%s:",
The_ClassFormInBox[Gbl.Prefs.Theme],
Txt_File_size);
Tbl_EndCell ();
fprintf (Gbl.F.Out," | "
"%s",
FileSizeStr);
if (UncompressedSize)
{
Fil_WriteFileSizeFull ((double) UncompressedSize,FileSizeStr);
fprintf (Gbl.F.Out," (%s %s)",
FileSizeStr,Txt_FILE_uncompressed);
}
Tbl_EndCell ();
Tbl_EndRow ();
/***** End table and box *****/
Box_EndBoxTable ();
}
|