예제 #1
0
unsigned int CArchiveScanner::GetArchiveCompleteChecksum(const std::string& name)
{
	const std::vector<std::string> ars = GetAllArchivesUsedBy(name);

	unsigned int checksum = 0;

	for (const std::string& depName: ars) {
		const std::string& archive = ArchiveFromName(depName);
		checksum ^= GetSingleArchiveChecksum(GetArchivePath(archive) + archive);
	}
	LOG_S(LOG_SECTION_ARCHIVESCANNER, "archive checksum %s: %d/%u", name.c_str(), checksum, checksum);
	return checksum;
}
예제 #2
0
	RESULTCODE ArchiveProcessorImpl::Compress()
	{
		const char* tpath = GetArchivePath();
		if(tpath==NULL)
		{
			return AG_FAILURE;
		}

		struct archive *a;
		struct archive_entry *entry;
		struct stat st;
		char buff[AUGE_BUFFER_MAX];
		int len;
		int fd;

		a = archive_write_new();
		if(a==NULL)
		{
			return AG_FAILURE;
		}
		//archive_write_add_filter_gzip(a);
		archive_write_set_format_zip(a);
		archive_write_set_format_pax_restricted(a);
		archive_write_open_filename(a,tpath);

		const char* fpath = NULL;
		char name[AUGE_NAME_MAX];
		char ext[AUGE_EXT_MAX];
		char fname[AUGE_NAME_MAX];
		std::vector<std::string>::iterator iter;
		for(iter=m_paths.begin(); iter!=m_paths.end();iter++)
		{
			fpath = (*iter).c_str();
			memset(fname,0,AUGE_NAME_MAX);
			memset(name,0,AUGE_NAME_MAX);
			memset(name,0,AUGE_EXT_MAX);
			auge_split_path(fpath, NULL, NULL, name, ext);
			auge_make_path(fname, NULL, NULL, name, ext);
			if(strlen(fname)==0)
			{
				continue;
			}

			stat(fpath,&st);

			entry = archive_entry_new();
			archive_entry_set_pathname(entry,fname);
			archive_entry_set_size(entry,st.st_size);
			archive_entry_set_filetype(entry, AE_IFREG);
			archive_entry_set_perm(entry,0644);
			archive_write_header(a,entry);

			fd = open(fpath,O_RDONLY);
			len = read(fd,buff,sizeof(buff));
			while(len>0)
			{
				archive_write_data(a,buff, len);
				len = read(fd,buff,sizeof(buff));
			}
			close(fd);
			archive_entry_free(entry);
		}

		archive_write_close(a);	
		archive_write_free(a);	

		return AG_SUCCESS;
	}
예제 #3
0
	RESULTCODE ArchiveProcessorImpl::Decompress()
	{
		const char* tpath = GetArchivePath();
		if(tpath==NULL)
		{
			return AG_FAILURE;
		}
		struct archive *a;
		struct archive *ext;
		struct archive_entry *entry;
		int flags;
		int r;

		/* Select which attributes we want to restore. */
		flags = ARCHIVE_EXTRACT_TIME;
		flags |= ARCHIVE_EXTRACT_PERM;
		flags |= ARCHIVE_EXTRACT_ACL;
		flags |= ARCHIVE_EXTRACT_FFLAGS;

		a = archive_read_new();
		archive_read_support_format_all(a);
		archive_read_support_compression_all(a);

		ext = archive_write_disk_new();
		archive_write_disk_set_options(ext, flags);
		archive_write_disk_set_standard_lookup(ext);
		if((r = archive_read_open_filename(a, tpath, 10240)))
		{
			return AG_FAILURE;
		}

		while(true)
		{
			r = archive_read_next_header(a, &entry);
			if( r== ARCHIVE_EOF)
			{
				break;
			}
			if( r < ARCHIVE_OK)
			{
				fprintf(stderr, "%s\n", archive_error_string(a));
			}
			if( r< ARCHIVE_WARN)
			{
				break;
			}

			r = archive_write_header(ext, entry);
			if (r < ARCHIVE_OK)
			{
				fprintf(stderr, "%s\n", archive_error_string(ext));
			}
			else if (archive_entry_size(entry) > 0) 
			{
				r = copy_data(a, ext);
			}
			if (r < ARCHIVE_OK)
			{
				fprintf(stderr, "%s\n", archive_error_string(ext));
			}
			if (r < ARCHIVE_WARN)
			{
				break;
			}

			r = archive_write_finish_entry(ext);
			if (r < ARCHIVE_OK)
			{
				fprintf(stderr, "%s\n", archive_error_string(ext));
			}
			if(r < ARCHIVE_WARN)
			{
				break;
			}
		}	

		archive_read_close(a);
		archive_read_free(a);	

		archive_write_close(ext);
		archive_write_free(ext);


		//return r==ARCHIVE_OK ? AG_SUCCESS : AG_FAILURE;
		return AG_SUCCESS;
	}
예제 #4
0
파일: on_button.cpp 프로젝트: billfm/billfm
gchar * Untar(const char * name,const char * destdir)
{
	ClassString archve = GetArchivePath();

	const char mes[]="Не в архиве ";

	if(strncmp(name,archve.s,strlen(archve.s)))
	{
		printf("%s '%s' \n",mes,name);
		return 0;
	}

	struct stat file_stat;
	if(!lstat(name, &file_stat))
	{	
		if(S_ISLNK(file_stat.st_mode))
		{
			return  g_strdup(name);
		}	
	}

	ClassString zip=g_strdup(&name[strlen(archve.s)]);
	ClassString inzip=g_strdup(zip.s);
			
	int inside=0;
	if(lstat(zip.s, &file_stat))
	{	
		inside=1;
		while(lstat(zip.s, &file_stat))
		{
			zip=g_path_get_dirname(zip.s);
		}
		inzip=g_strdup(&inzip.s[strlen(zip.s)+1]);
	} else
	{	
		printf("%s\n%s",mes,name);
		return 0;
	}	

	ClassString	cache=g_build_filename(PATH_CACHE_ARCHIVE,zip.s,NULL);
	CreateDirInDir(cache.s);


	ClassString com;
	const char * unpack_dir;
	if(!destdir) unpack_dir=cache.s;  else unpack_dir=destdir;

	if(IsTar(zip.s))
	{	
//        ClassString base=g_path_get_dirname(inzip.s);
//		printf("`%s` base `%s`",inzip.s,base.s);
//		if(!strcmp(base.s,"."))
//		{
//			com=g_strdup_printf("cd '%s'; tar -x --file='%s' './%s'", unpack_dir,zip.s,inzip.s);
//		}	else 
		com=g_strdup_printf("cd '%s'; tar -x --file='%s' '%s'", unpack_dir,zip.s,inzip.s);
		Execute(com.s);
	}	else

	if(IsDeb(zip.s))
	{	
		com=g_strdup_printf("cd '%s'; ar x '%s' '%s'", unpack_dir,zip.s,inzip.s);
		Execute(com.s);
	}	else
		
	if(IsZip(zip.s))
	{	
		
		if(!lstat(name, &file_stat))
		{	
			if(S_ISDIR(file_stat.st_mode) ) 
				com=g_strdup_printf("cd '%s'; unzip -o '%s' '%s/*'", unpack_dir, zip.s, inzip.s);
			else com=g_strdup_printf("cd '%s'; unzip -o '%s' '%s'", unpack_dir, zip.s, inzip.s);
		}
		Execute(com.s);
		
	}	else
	if(IsRar(zip.s))
	{	
		if(inzip.s[0]=='*')
		{
			ClassString password=InputPassword();
			printf("Треба пассворд <%s>\n",password.s);
			com=g_strdup_printf("cd '%s'; unrar -p'%s' x '%s' '%s'", 
			                    unpack_dir,password.s,zip.s,&inzip.s[1]);
			printf("%s\n",com.s);
		} 	else com=g_strdup_printf("cd '%s'; unrar -p- x '%s' '%s'", unpack_dir,zip.s,inzip.s);			
		Execute(com.s);
	}	else return 0;
	
	cache=g_build_filename(unpack_dir,inzip.s,NULL);
	if(!destdir)
	{	
		if(!lstat(cache.s, &file_stat))
		{	
			unlink(name);
			symlink(cache.s,name);
			return g_strdup(name);
		} else printf("file not create - '%s'\n",cache.s);
	}	
	return g_strdup(cache.s);
}
	FLocalizationConfigurationScript GenerateGatherScript(const FLocalizationTargetSettings& Target)
	{
		FLocalizationConfigurationScript Script;

		const bool HasSourceCode = IFileManager::Get().DirectoryExists( *FPaths::GameSourceDir() );

		const FString ConfigDirRelativeToGameDir = MakePathRelativeToProjectDirectory(FPaths::GameConfigDir());
		const FString SourceDirRelativeToGameDir = MakePathRelativeToProjectDirectory(FPaths::GameSourceDir());
		const FString ContentDirRelativeToGameDir = MakePathRelativeToProjectDirectory(FPaths::GameContentDir());

		// CommonSettings
		{
			FConfigSection& ConfigSection = Script.CommonSettings();

			const UProjectLocalizationSettings* const ProjectLocalizationSettings = GetDefault<UProjectLocalizationSettings>(UProjectLocalizationSettings::StaticClass());
			for (const FString& TargetDependencyName : Target.TargetDependencies)
			{
				ULocalizationTarget* const * OtherTarget = ProjectLocalizationSettings->TargetObjects.FindByPredicate([&TargetDependencyName](ULocalizationTarget* const OtherTarget)->bool{return OtherTarget->Settings.Name == TargetDependencyName;});
				if (OtherTarget)
				{
					ConfigSection.Add( TEXT("ManifestDependencies"), MakePathRelativeToProjectDirectory(GetManifestPath((*OtherTarget)->Settings)) );
				}
			}

			for (const FFilePath& Path : Target.AdditionalManifestDependencies)
			{
				ConfigSection.Add( TEXT("ManifestDependencies"), MakePathRelativeToProjectDirectory(Path.FilePath) );
			}

			const FString SourcePath = ContentDirRelativeToGameDir / TEXT("Localization") / Target.Name;
			ConfigSection.Add( TEXT("SourcePath"), SourcePath );
			const FString DestinationPath = ContentDirRelativeToGameDir / TEXT("Localization") / Target.Name;
			ConfigSection.Add( TEXT("DestinationPath"), DestinationPath );

			ConfigSection.Add( TEXT("ManifestName"), FPaths::GetCleanFilename(GetManifestPath(Target)) );
			ConfigSection.Add( TEXT("ArchiveName"), FPaths::GetCleanFilename(GetArchivePath(Target, FString())) );

			ConfigSection.Add( TEXT("SourceCulture"), Target.NativeCultureStatistics.CultureName );
			ConfigSection.Add( TEXT("CulturesToGenerate"), Target.NativeCultureStatistics.CultureName );
			for (const FCultureStatistics& CultureStatistics : Target.SupportedCulturesStatistics)
			{
				ConfigSection.Add( TEXT("CulturesToGenerate"), CultureStatistics.CultureName );
			}
		}

		uint32 GatherTextStepIndex = 0;
		// GatherTextFromSource
		{
			FConfigSection& ConfigSection = Script.GatherTextStep(GatherTextStepIndex++);

			// CommandletClass
			ConfigSection.Add( TEXT("CommandletClass"), TEXT("GatherTextFromSource") );

			// Include Paths
			if (HasSourceCode) 
			{
				ConfigSection.Add( TEXT("IncludePaths"), SourceDirRelativeToGameDir );
			}
			ConfigSection.Add( TEXT("IncludePaths"), ConfigDirRelativeToGameDir );

			// Exclude Paths
			ConfigSection.Add( TEXT("ExcludePaths"), ConfigDirRelativeToGameDir / TEXT("Localization") );

			// SourceFileSearchFilters
			if (HasSourceCode)
			{
				ConfigSection.Add( TEXT("SourceFileSearchFilters"), TEXT("*.h") );
				ConfigSection.Add( TEXT("SourceFileSearchFilters"), TEXT("*.cpp") );
			}
			ConfigSection.Add( TEXT("SourceFileSearchFilters"), TEXT("*.ini") );
		}

		// GatherTextFromAssets
		{
			FConfigSection& ConfigSection = Script.GatherTextStep(GatherTextStepIndex++);

			// CommandletClass
			ConfigSection.Add( TEXT("CommandletClass"), TEXT("GatherTextFromAssets") );

			// IncludePaths
			ConfigSection.Add( TEXT("IncludePaths"), ContentDirRelativeToGameDir );

			// ExcludePaths
			ConfigSection.Add( TEXT("ExcludePaths"), ContentDirRelativeToGameDir / TEXT("Localization") );

			// PackageExtensions
			ConfigSection.Add( TEXT("PackageExtensions"), TEXT("*.umap") );
			ConfigSection.Add( TEXT("PackageExtensions"), TEXT("*.uasset") );
		}

		// GenerateGatherManifest
		{
			FConfigSection& ConfigSection = Script.GatherTextStep(GatherTextStepIndex++);

			// CommandletClass
			ConfigSection.Add( TEXT("CommandletClass"), TEXT("GenerateGatherManifest") );
		}

		// GenerateGatherArchive
		if (Target.SupportedCulturesStatistics.Num())
		{
			FConfigSection& ConfigSection = Script.GatherTextStep(GatherTextStepIndex++);

			// CommandletClass
			ConfigSection.Add( TEXT("CommandletClass"), TEXT("GenerateGatherArchive") );
		}

		Script.Dirty = true;

		return Script;
	}
	FLocalizationConfigurationScript GenerateExportScript(const FLocalizationTargetSettings& Target, const TOptional<FString> CultureName, const TOptional<FString> OutputPathOverride)
	{
		FLocalizationConfigurationScript Script;

		const FString ContentDirRelativeToGameDir = MakePathRelativeToProjectDirectory(FPaths::GameContentDir());

		// GatherTextStep0 - InternationalizationExport
		{
			FConfigSection& ConfigSection = Script.GatherTextStep(0);

			// CommandletClass
			ConfigSection.Add( TEXT("CommandletClass"), TEXT("InternationalizationExport") );

			ConfigSection.Add( TEXT("bExportLoc"), TEXT("true") );

			const FString SourcePath = ContentDirRelativeToGameDir / TEXT("Localization") / Target.Name;
			ConfigSection.Add( TEXT("SourcePath"), SourcePath );

			FString DestinationPath;
			// Overriding output path changes the destination directory for the PO file.
			if (OutputPathOverride.IsSet())
			{
				// The output path for a specific culture is a file path.
				if (CultureName.IsSet())
				{
					DestinationPath = MakePathRelativeToProjectDirectory( FPaths::GetPath(OutputPathOverride.GetValue()) );
				}
				// Otherwise, it is a directory path.
				else
				{
					DestinationPath = MakePathRelativeToProjectDirectory( OutputPathOverride.GetValue() );
				}
			}
			// Use the default PO file's directory path.
			else
			{
				DestinationPath = ContentDirRelativeToGameDir / TEXT("Localization") / Target.Name;
			}
			ConfigSection.Add( TEXT("DestinationPath"), DestinationPath );

			TArray<const FCultureStatistics*> AllCultureStatistics;
			AllCultureStatistics.Add(&Target.NativeCultureStatistics);
			for (const FCultureStatistics& SupportedCultureStatistics : Target.SupportedCulturesStatistics)
			{
				AllCultureStatistics.Add(&SupportedCultureStatistics);
			}

			const auto& AddCultureToGenerate = [&](const int32 Index)
			{
				ConfigSection.Add( TEXT("CulturesToGenerate"), AllCultureStatistics[Index]->CultureName );
			};

			// Export for a specific culture.
			if (CultureName.IsSet())
			{
				const int32 CultureIndex = AllCultureStatistics.IndexOfByPredicate([CultureName](const FCultureStatistics* Culture) { return Culture->CultureName == CultureName.GetValue(); });
				AddCultureToGenerate(CultureIndex);
			}
			// Export for all cultures.
			else
			{
				for (int32 CultureIndex = 0; CultureIndex < AllCultureStatistics.Num(); ++CultureIndex)
				{
					AddCultureToGenerate(CultureIndex);
				}
			}

			// Do not use culture subdirectories if exporting a single culture to a specific directory.
			if (CultureName.IsSet() && OutputPathOverride.IsSet())
			{
				ConfigSection.Add( TEXT("bUseCultureDirectory"), "false" );
			}


			ConfigSection.Add( TEXT("ManifestName"), FPaths::GetCleanFilename(GetManifestPath(Target)) );
			ConfigSection.Add( TEXT("ArchiveName"), FPaths::GetCleanFilename(GetArchivePath(Target, FString())) );
			FString POFileName;
			// The output path for a specific culture is a file path.
			if (CultureName.IsSet() && OutputPathOverride.IsSet())
			{
				POFileName =  FPaths::GetCleanFilename( OutputPathOverride.GetValue() );
			}
			// Use the default PO file's name.
			else
			{
				POFileName = FPaths::GetCleanFilename( GetDefaultPOPath( Target, CultureName.Get( TEXT("") ) ) );
			}
			ConfigSection.Add( TEXT("PortableObjectName"), POFileName );
		}

		Script.Dirty = true;

		return Script;
	}