tmp_xfer.cpp 3.64 KB
Newer Older
1 2 3 4 5 6
/* Synchronet temp directory file transfer routines */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
rswindell's avatar
rswindell committed
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

/*****************************************************************************/
/* Temp directory section. Files must be extracted here and both temp_uler   */
/* and temp_uler fields should be filled before entrance.                    */
/*****************************************************************************/
void sbbs_t::temp_xfer()
{
30 31
	if(!cfg.tempxfer_mod[0]) {
		bprintf(text[DirectoryDoesNotExist], "temp (module)");
32 33
		return; 
	}
34
	exec_bin(cfg.tempxfer_mod, &main_csi);
35 36 37 38 39 40
}

/****************************************************************************/
/* Creates a text file named NEWFILES.DAT in the temp directory that        */
/* all new files since p-date. Returns number of files in list.             */
/****************************************************************************/
41
ulong sbbs_t::create_filelist(const char *name, long mode)
42 43
{
    char	str[256];
44
	FILE*	fp;
45 46 47
	uint	i,j,d;
	ulong	l,k;

48 49
	if(online == ON_REMOTE)
		bprintf(text[CreatingFileList],name);
50
	SAFEPRINTF2(str,"%s%s",cfg.temp_dir,name);
51
	if((fp = fopen(str,"ab")) == NULL) {
52
		errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_WRONLY|O_APPEND);
53
		return(0);
54
	}
55 56
	k=0;
	if(mode&FL_ULTIME) {
57
		fprintf(fp, "New files since: %s\r\n", timestr(ns_time));
58
	}
59 60 61
	unsigned total_dirs = 0;
	for(i=0; i < usrlibs ;i++)
		total_dirs += usrdirs[i];
62
	for(i=j=d=0;i<usrlibs;i++) {
63
		for(j=0;j<usrdirs[i];j++,d++) {
64
			progress(text[Scanning], d, total_dirs, 1);
65 66 67 68
			if(mode&FL_ULTIME /* New-scan */
				&& (cfg.lib[usrlib[i]]->offline_dir==usrdir[i][j]
				|| cfg.dir[usrdir[i][j]]->misc&DIR_NOSCAN))
				continue;
69
			l=listfiles(usrdir[i][j], nulstr, fp, mode);
70 71
			if((long)l==-1)
				break;
72
			k+=l;
73
		}
74
		if(j<usrdirs[i])
75
			break;
76
	}
77
	progress(text[Done], d, total_dirs);
78
	if(k>1) {
79
		fprintf(fp,"\r\n%ld Files Listed.\r\n",k);
80
	}
81
	fclose(fp);
82 83 84
	if(k)
		bprintf(text[CreatedFileList],name);
	else {
85 86
		if(online == ON_REMOTE)
			bputs(text[NoFiles]);
87
		SAFEPRINTF2(str,"%s%s",cfg.temp_dir,name);
88
		remove(str);
89
	}
90 91 92 93 94 95 96
	return(k);
}

/****************************************************************************/
/* This function returns the command line for the temp file extension for	*/
/* current user online. 													*/
/****************************************************************************/
97
const char* sbbs_t::temp_cmd(void)
98 99 100 101
{
	int i;

	if(!cfg.total_fcomps) {
102
		errormsg(WHERE,ERR_CHK,"compressible file types",0);
103 104
		return(nulstr); 
	}
105 106
	for(i=0;i<cfg.total_fcomps;i++)
		if(!stricmp(useron.tmpext,cfg.fcomp[i]->ext)
rswindell's avatar
rswindell committed
107
			&& chk_ar(cfg.fcomp[i]->ar,&useron,&client))
108 109 110
			return(cfg.fcomp[i]->cmd);
	return(cfg.fcomp[0]->cmd);
}