예제 #1
0
void pack_directory( char * filespec)
{
	int find_handle;
	_finddata_t find;
	char tmp[512];
	char tmp1[512];

/*
	char dir_name[512];
	char *last_slash;

	last_slash = strrchr(filespec, '\\');
	if ( last_slash ) {
		strcpy(dir_name, last_slash+1);
	} else {
		strcpy(dir_name, filespec);
	}

	if ( !stricmp(dir_name, "voice") ) {
		return;
	}
*/

	strcpy( tmp1, filespec );
	add_directory(filespec);
	strcat( tmp1, "\\*.*" );
	
	printf( "In dir '%s'\n", tmp1 );

	find_handle = _findfirst( tmp1, &find );
	if( find_handle != -1 )	{
		if ( find.attrib & _A_SUBDIR )	{
			if (strcmp( "..", find.name) && strcmp( ".", find.name))	{
				strcpy( tmp, filespec );
				strcat( tmp, "\\" );
				strcat( tmp, find.name );
				pack_directory(tmp);
			}
		} else {
			pack_file( filespec, find.name, find.size, find.time_write );
		}

		while( !_findnext( find_handle, &find ) )	{
			if ( find.attrib & _A_SUBDIR )	{
				if (strcmp( "..", find.name) && strcmp( ".", find.name))	{
					strcpy( tmp, filespec );
					strcat( tmp, "\\" );
					strcat( tmp, find.name );
					pack_directory(tmp);

				}
			} else {
				pack_file( filespec, find.name, find.size, find.time_write );
			}
		}
	}
	add_directory("..");
}
예제 #2
0
void CSoliDire::pack_added_file(CFile * ofp)
{
	CInodeList::iterator i;
	m_files.clear();
	m_DirTree->serial(m_files);
	
	ofp->Seek(m_CSDHead.nTreeStart, CFile::begin);

	for (i=m_files.begin(); i->lpszFileName.Find(':')==-1; ++i);

	pack_file(ofp, i);
	SetModifiedFlag(FALSE);
}
예제 #3
0
void CSoliDire::pack_all_file(CFile * ofp)
{
	m_files.clear();
	m_DirTree->serial(m_files);

	CInode tmp;
	CInodeList::iterator i;

	CFile ifile;

	ofp->Seek(sizeof(CFileHead), CFile::begin);
	m_CSDHead.nDataStart = ofp->GetPosition();

	i = m_files.begin();
	pack_file(ofp, i);
	SetModifiedFlag(FALSE);
}
예제 #4
0
static void process_filelist(FILE *fp)
{
    char filename[PATH_MAX];
    char *sep;
    struct stat sb;

    while (fgets(filename, sizeof(filename), stdin)) {
        filename[strlen(filename) - 1] = '\0'; /* strip new line */

        for (sep = filename; (sep = strchr(sep, '\\'));)
            *sep = '/';

        if (stat(filename, &sb) == 0) {
            if (sb.st_mode & S_IFREG)
                pack_file(fp, filename, &sb);
            else
                fprintf(stderr, "%s: unsupported file type\n", filename);
        } else {
            fprintf(stderr, "%s: ", filename);
            perror("");
        }
    }
}
예제 #5
0
파일: tcfiler.c 프로젝트: wix/tcfiler
int main(int argc, char **argv) {

    TCXSTR *pattern, *key_root;
    int ecode;
    bool verbose, test, create, extract, optimize, resume;
    int o;

    verbose = test = create = extract = optimize = resume = false;
    pattern = tcxstrnew();
    key_root = tcxstrnew();
    db_file = tcxstrnew();
    tdb_host = tcxstrnew();

    tdb_port = 0;


    while (-1 != (o = getopt(argc, argv, "cxtvrof:p:k:H:P:"))) {

        switch (o) {
            case 'f':
                use_cabinet_lib = true;
                tcxstrcat2(db_file, optarg);

                /* create the object */
                hdb = tchdbnew();
                break;
            case 'H':
                use_cabinet_lib = false;
                tcxstrcat2(tdb_host, optarg);

                tdb = tcrdbnew();
                break;
            case 'P':
                tdb_port = strtol(optarg, NULL, 0);
                break;
            case 'k':
                tcxstrcat2(key_root, optarg);

                // add trailing slash if needed
                char *last_c;
                last_c = tcxstrptr(key_root) + tcxstrsize(key_root) - 1;
                if (*last_c != '/') {
                    tcxstrcat2(key_root, "/");
                }
                break;
            case 'p':
                tcxstrcat2(pattern, optarg);
                break;
            case 'v':
                verbose = true;
                break;
            case 't':
                test = true;
                break;
            case 'c':
                create = true;
                break;
            case 'x':
                extract = true;
                break;
            case 'r':
                resume = true;
                break;
            case 'o':
                optimize = true;
            case '?':
            default:
                break;
        }
    }

    if (!create && !extract) {
        fprintf(stdout, "No action specifed. Use -c to create DB and -x to extract files from dbfile.tch\n");
        return 1;
    }

    if ((use_cabinet_lib && NULL == hdb)
            ||
            (!use_cabinet_lib && NULL == tdb)) {
        fprintf(stdout, "No database specifed. Use -f dbfile.tch\n");
        return 1;
    }

    if (0 == tcxstrsize(pattern)) {
        fprintf(stdout, "No pattern is given. Using *. Use -p <glob_pattern> to override\n");
        tcxstrcat2(pattern, "*");
    }

    if (create) {
        glob_t gtree;
        glob(tcxstrptr(pattern), GLOB_NOSORT, NULL, &gtree);
        size_t found = gtree.gl_pathc;

        if (use_cabinet_lib && !open_cabinet_db((int64_t) found, optimize)) return 2;
        if (!use_cabinet_lib && !open_tyrant_db()) return 3;

        int i;
        for (i = 0; i < found; i++) {

            char * fname = gtree.gl_pathv[i];

            if (verbose || test) fprintf(stdout, "\n%d of %d - packing file: %s ...", i, found, fname);

            if (!test) pack_file(fname, key_root, resume);
        }

        fprintf(stdout, "Finished. Processed %d items\n", (int) found);
        globfree(&gtree);
    } else if (extract) {
        if (!open_cabinet_db(0, false)) return 2;

        int count;
        count = unpack_files(NULL, verbose, test);
        fprintf(stdout, "Finished. Processed %d items\n", count);
    }

    /* close the database */
    close_db();

    /* delete the objects */
    tcxstrdel(pattern);
    tcxstrdel(key_root);
    
    return 0;
}
예제 #6
0
// This function adds a directory marker to the header file
void add_directory( char * dirname)
{
	char path[256];
	char *pathptr = path;
	char *tmpptr;

	strcpy(path, dirname);
	fwrite(&Total_size, 1, 4, fp_out_hdr);
	int i = 0;
	fwrite(&i, 1, 4, fp_out_hdr);
	// strip out any directories that this dir is a subdir of
#ifndef PLAT_UNIX
	while ((tmpptr = strchr(pathptr, '\\')) != NULL) {
#else
	while ((tmpptr = strchr(pathptr, '/')) != NULL) {
#endif
		pathptr = tmpptr+1;
	}
	fwrite(pathptr, 1, 32, fp_out_hdr);
	fwrite(&i, 1, 4, fp_out_hdr); // timestamp = 0
	Num_files++;
}

void pack_directory( char * filespec)
{
#ifndef PLAT_UNIX
	int find_handle;
	_finddata_t find;
#endif
	char tmp[512];
	char tmp1[512];

/*
	char dir_name[512];
	char *last_slash;

	last_slash = strrchr(filespec, '\\');
	if ( last_slash ) {
		strcpy(dir_name, last_slash+1);
	} else {
		strcpy(dir_name, filespec);
	}

	if ( !stricmp(dir_name, "voice") ) {
		return;
	}
*/

#ifdef PLAT_UNIX
	char *ts;

	// strip trailing '/'
	ts = filespec+(strlen(filespec)-1);
	while(*ts == '/' && ts > filespec)
		*ts = '\0';

	strcpy( tmp1, filespec );

	add_directory(filespec);
	strcat( tmp1, "/*.*" );
#else
	strcpy( tmp1, filespec );

	add_directory(filespec);
	strcat( tmp1, "\\*.*" );
#endif
	
	printf( "In dir '%s'\n", tmp1 );

#ifndef PLAT_UNIX
	find_handle = _findfirst( tmp1, &find );
	if( find_handle != -1 )	{
		if ( find.attrib & _A_SUBDIR )	{
			if (strcmp( "..", find.name) && strcmp( ".", find.name))	{
				strcpy( tmp, filespec );
				strcat( tmp, "\\" );
				strcat( tmp, find.name );
				pack_directory(tmp);
			}
		} else {
			pack_file( filespec, find.name, find.size, (fs_time_t)find.time_write );
		}

		while( !_findnext( find_handle, &find ) )	{
			if ( find.attrib & _A_SUBDIR )	{
				if (strcmp( "..", find.name) && strcmp( ".", find.name))	{
					strcpy( tmp, filespec );
					strcat( tmp, "\\" );
					strcat( tmp, find.name );
					pack_directory(tmp);

				}
			} else {
				pack_file( filespec, find.name, find.size, find.time_write );
			}
		}
	}
#else
	DIR *dirp;
	struct dirent *dir;

	dirp = opendir (filespec);
	if ( dirp ) {
		while ((dir = readdir(dirp)) != NULL) {

			char fn[MAX_PATH];
			snprintf(fn, MAX_PATH-1, "%s/%s", filespec, dir->d_name);
			fn[MAX_PATH-1] = 0;
			
			struct stat buf;
			if (stat(fn, &buf) == -1) {
				continue;
			}

			if ( (strcmp(dir->d_name, ".") == 0) || (strcmp(dir->d_name, "..") == 0) ) {
				continue;
			}

			if (S_ISDIR(buf.st_mode)) {
				strcpy( tmp, filespec );
				strcat( tmp, "/" );
				strcat( tmp, dir->d_name );
				pack_directory(tmp);
			} else {
				pack_file( filespec, dir->d_name, buf.st_size, buf.st_mtime );
			}
		}
		closedir(dirp);
	} else {
		printf("Error: Source directory does not exist!\n");
		no_dir = 1;
	}
#endif
	add_directory("..");
}