Esempio n. 1
0
FileSource::~FileSource()
{
	CloseCurrentFile();

//	printf("Freeing memory for \"accum\" in destructor.\n" );
	free(accum);
	accum = NULL;

	while ( !filelist.empty() )
	{
//		printf("Freeing memory for \"filelist\" in destructor.\n" );
		free(filelist.top());
		filelist.pop();
	}
}
Esempio n. 2
0
void FileSource::IterateFileList()
{
	CloseCurrentFile();

	while (!file_p && !filelist.empty())
	{
		current_file_full_path = filelist.top();

		filelist.pop();


		printf("Opening file: %s\n", current_file_full_path );
		file_p = fopen( current_file_full_path, "rb" );

		if (!file_p)
		{
			printf("Error opening file: %s\n", current_file_full_path );
//			printf("Freeing memory for \"current_file_path\" in IterateFileList because file open error.\n" );
			free( current_file_full_path );
			current_file_full_path = NULL;
			continue;
		}


// The so called fseek/ftell dance
// http://www.aquaphoenix.com/ref/gnu_c_library/libc_68.html
// http://stackoverflow.com/questions/8621544/interaction-of-posix-file-descriptors-and-c-files
// http://stackoverflow.com/questions/9830788/how-to-get-file-size-in-ansi-c-without-fseek-and-ftell
//
//		fseek(file_p, 0, SEEK_END);			// seek to end of file
//		current_file_size = ftell(file_p);	// get current file pointer
//		fseek(file_p, 0, SEEK_SET);			// seek back to beginning of file

		struct stat stbuf;
		if ( fstat(fileno(file_p), &stbuf) == -1 ) {} 	// Handle Error 

		current_file_size = (size_t) stbuf.st_size;	// get current file pointer
		current_file_bytes_read = 0;
	}
}
Esempio n. 3
0
////////// ////////// ////////// ////////// //////////
SingleTreeMaker::~SingleTreeMaker()
{
  std::cout << "Instance of " << fClassName << " Destructed!" << std::endl;
  AutoSaveTree();
  CloseCurrentFile();
}//END of destructor
Esempio n. 4
0
int vtUnzip::Extract(bool bFullPath, bool bOverwrite, const char *lpszDst,
					 bool progress_callback(int))
{
	int iCount = 0;
	int iTotal = GetGlobalCount();

	bool bOK = true;
	for (bool bContinue = GoToFirstFile(); bContinue; bContinue = GoToNextFile())
	{
		char szFileName[MAX_PATH];
		unz_file_info info;
		bOK = GetCurrentFileInfo(&info, szFileName, MAX_PATH);
		if (!bOK)
			break;

		vtString src_filename = szFileName;

		const char *short_fname = (const char *)src_filename;
		for (const char *p = short_fname;
			(*p) != '\0';
			p++)
		{
			if (((*p)=='/') || ((*p)=='\\'))
			{
				short_fname = p+1;
			}
		}
		vtString short_filename = short_fname;

		if ((*short_filename)=='\0')
		{
			if (bFullPath)
			{
				VTLOG("creating directory: %s\n", (const char *)src_filename);
				vtCreateDir(src_filename);
			}
		}
		else
		{
			bOK = OpenCurrentFile();
			if (bOK)
			{
				vtString write_filename;
				write_filename = vtString(lpszDst) + (bFullPath ? src_filename : short_filename);

				vtString strResult;

				VTLOG("Extracting %s ...", (const char *) write_filename);
				if (ExtractAccept(write_filename, bOverwrite))
				{
					FILE* file = vtFileOpen(write_filename, "wb");

					bool bWrite = (file != NULL);
					if (bWrite)
					{
						char buf[4096];
						bWrite = ExtractCurrentFile(file, buf, 4096);
						fclose(file);
					}
					if (bWrite)
					{
						vtUnzip::change_file_date(write_filename,info.dosDate, info.tmu_date);
						iCount++;
						if (progress_callback != NULL)
						{
							progress_callback(iCount * 99 / iTotal);
						}
					}
					else
					{
						m_error_count++;
						OnError(write_filename);
					}
					strResult = bWrite ? "ok" : "failed";
				}
				else
				{
					strResult = "skipped";
				}
				VTLOG(" %s\n", (const char *) strResult);
				CloseCurrentFile();
			}
		}
	}
	if (bOK)
		return iCount;
	else
		return -1;
}