示例#1
0
void QgsCptCityArchive::initDefaultArchive()
{
  QgsSettings settings;
  // use CptCity/baseDir setting if set, default is user dir
  QString baseDir = settings.value( QStringLiteral( "CptCity/baseDir" ),
                                    QgsApplication::pkgDataPath() + "/resources" ).toString();
  // sub-dir defaults to
  QString defArchiveName = settings.value( QStringLiteral( "CptCity/archiveName" ), DEFAULT_CPTCITY_ARCHIVE ).toString();

  if ( ! sArchiveRegistry.contains( defArchiveName ) )
    initArchive( defArchiveName, baseDir + '/' + defArchiveName );
}
示例#2
0
ZipArchive::ZipArchive(SeekableFilePtr sArchive)
	:archive(sArchive)
	{
	/* Initialize the archive and handle errors: */
	switch(initArchive())
		{
		case -1:
			Misc::throwStdErr("IO::ZipArchive: Source file is not a valid ZIP archive");
			break;
		
		case -2:
			Misc::throwStdErr("IO::ZipArchive: Unable to locate central directory in ZIP archive");
			break;
		
		case -3:
			Misc::throwStdErr("IO::ZipArchive: Invalid central directory in ZIP archive");
			break;
		}
	}
示例#3
0
ZipArchive::ZipArchive(const char* archiveFileName)
	:archive(new StandardFile(archiveFileName,File::ReadOnly))
	{
	/* Initialize the archive and handle errors: */
	switch(initArchive())
		{
		case -1:
			Misc::throwStdErr("IO::ZipArchive: %s is not a valid ZIP archive",archiveFileName);
			break;
		
		case -2:
			Misc::throwStdErr("IO::ZipArchive: Unable to locate central directory in ZIP archive %s",archiveFileName);
			break;
		
		case -3:
			Misc::throwStdErr("IO::ZipArchive: Invalid central directory in ZIP archive %s",archiveFileName);
			break;
		}
	}
示例#4
0
void
do_ar(int argc, const char ** argv)
{
	const char *	options;
	const char *	archiveName;
	BOOL		doExtract;
	BOOL		doTable;
	BOOL		doPrint;
	BOOL		verbose;
	Archive		arch;

	verbose = FALSE;
	doExtract = FALSE;
	doTable = FALSE;
	doPrint = FALSE;

	if (argc < 3)
	{
		fprintf(stderr, "Too few arguments for ar\n");

		return;
	}

	/*
	 * Get the option string and archive file name.
	 */
	options = argv[1];
	archiveName = argv[2];

	/*
	 * Advance the arguments to the list of file names (if any).
	 */
	argc -= 3;
	argv += 3;

	/*
	 * Parse the option characters.
	 */
	for (; *options; options++)
	{
		switch (*options)
		{
		case 't':
			doTable = TRUE;
			break;

		case 'x':
			doExtract = TRUE;
			break;

		case 'p':
			doPrint = TRUE;
			break;

		case 'v':
			verbose = TRUE;
			break;

		case 'd': case 'm': case 'q': case 'r':
			fprintf(stderr, "Writing ar files is not supported\n");

			return;

		default:
			fprintf(stderr, "Unknown ar flag: %c\n", *options);

			return;
		}
	}

	if (doExtract + doTable + doPrint != 1)
	{
		fprintf(stderr,
			"Exactly one of 'x', 'p' or 't' must be specified\n");

		return;
	}

	/*
	 * Open the archive file.
	 */
	initArchive(&arch);

	if (!openArchive(archiveName, &arch))
		return;

	/*
	 * Read the first special member of the archive.
	 */
	if (!readSpecialMember(&arch))
		return;

	/*
	 * Read all of the normal members of the archive.
	 */
	while (readNormalMember(&arch))
	{
		/*
		 * If this file is not wanted then skip it.
		 */
		if (!wantMember(&arch, argc, argv))
		{
			if (!skipMember(&arch))
				break;

			continue;
		}

		/*
		 * This file is wanted.
		 */
		if (doTable)
		{
			if (verbose)
				listMember(&arch);
			else
				puts(arch.name);

			if (!skipMember(&arch))
				break;
		}
		else if (doPrint)
		{
			if (verbose)
			{
				/*
				 * The verbose format makes me gag,
				 * but 4.4BSD, GNU and even V7 all
				 * have the same lossage.
				 */
				printf("\n<%s>\n\n", arch.name);
				fflush(stdout);
			}

			if (!writeFile(&arch, STDOUT))
				break;
		}
		else if (doExtract)
		{
			int	outfd;
			BOOL	success;

			if (verbose)
				printf("x - %s\n", arch.name);

			outfd = createFile(&arch);

			if (outfd == -1)
				break;

			success = writeFile(&arch, outfd);

			if (close(outfd) == -1)
			{
				fprintf(stderr, "Can't close %s: %s\n",
					arch.name, strerror(errno));

				break;
			}

			if (!success)
				break;
		}
		else
		{
			fprintf(stderr, "Oops -- I don't know what to do\n");
			break;
		}
	}

	closeArchive(&arch);
}