Ejemplo n.º 1
0
bool ProjectResourcesAdder::AddAllMissingImages(gd::Project & project)
{
    gd::ImagesUsedInventorizer inventorizer;
    project.ExposeResources(inventorizer);
    std::set<gd::String> & allImages = inventorizer.GetAllUsedImages();

    ResourcesManager & resourcesManager = project.GetResourcesManager();
    for (std::set<gd::String>::const_iterator it = allImages.begin(); it != allImages.end(); ++it)
    {
        if (!resourcesManager.HasResource(*it))
        {
            std::cout << "Adding missing resource \""<<*it<<"\"to the project.";
            resourcesManager.AddResource(*it, /*filename=*/*it); //Note that AddResource add a image resource by default.
        }
    }

    return true;
}
Ejemplo n.º 2
0
std::vector<std::string> ProjectResourcesAdder::GetAllUselessResources(gd::Project & project)
{
    std::vector<std::string> unusedResources;

    //Search for used images
    gd::ImagesUsedInventorizer inventorizer;
    project.ExposeResources(inventorizer);
    std::set<std::string> & usedImages = inventorizer.GetAllUsedImages();

    //Search all images resources not used
    std::vector<std::string> resources = project.GetResourcesManager().GetAllResourcesList();
    for (unsigned int i = 0;i < resources.size();i++)
    {
        if (project.GetResourcesManager().GetResource(resources[i]).GetKind() != "image")
            continue;

        if (usedImages.find(resources[i]) == usedImages.end())
            unusedResources.push_back(resources[i]);
    }

    return unusedResources;
}
Ejemplo n.º 3
0
bool ProjectResourcesCopier::CopyAllResourcesTo(gd::Project & originalProject, AbstractFileSystem & fs,
    gd::String destinationDirectory, bool updateOriginalProject, wxProgressDialog * optionalProgressDialog,
    bool askAboutAbsoluteFilenames, bool preserveDirectoryStructure)
{
    //Check if there are some resources with absolute filenames
    gd::ResourcesAbsolutePathChecker absolutePathChecker(fs);
    originalProject.ExposeResources(absolutePathChecker);
    bool copyAlsoResourcesWithAbsolutePath = !askAboutAbsoluteFilenames;

    std::cout << "Copying all ressources to " << destinationDirectory;

    #if !defined(GD_NO_WX_GUI)
    if ( !copyAlsoResourcesWithAbsolutePath )
    {
        copyAlsoResourcesWithAbsolutePath = absolutePathChecker.HasResourceWithAbsoluteFilenames() &&
            wxMessageBox(_("Some resources are using absolute filenames.\nDo you want them to be copied in the new folder of the project? If you choose No, they won't be modified."),
            _("Some resources are using absolute filenames."), wxYES_NO | wxICON_QUESTION) == wxYES;
    }
    #endif

    //Get the resources to be copied
    gd::ResourcesMergingHelper resourcesMergingHelper(fs);
    resourcesMergingHelper.SetBaseDirectory(fs.DirNameFrom(originalProject.GetProjectFile()));
    resourcesMergingHelper.PreserveDirectoriesStructure(preserveDirectoryStructure);
    resourcesMergingHelper.PreserveAbsoluteFilenames(!copyAlsoResourcesWithAbsolutePath);

    if ( updateOriginalProject )
    {
        originalProject.ExposeResources(resourcesMergingHelper);
    }
    else
    {
        std::shared_ptr<gd::Project> project(new gd::Project(originalProject));
        project->ExposeResources(resourcesMergingHelper);
    }

    //Copy resources
    map<gd::String, gd::String> & resourcesNewFilename = resourcesMergingHelper.GetAllResourcesOldAndNewFilename();
    unsigned int i = 0;
    for(map<gd::String, gd::String>::const_iterator it = resourcesNewFilename.begin(); it != resourcesNewFilename.end(); ++it)
    {
        if ( !it->first.empty() )
        {
            #if !defined(GD_NO_WX_GUI)
            if ( optionalProgressDialog )
            {
                if ( !optionalProgressDialog->Update(i/static_cast<float>(resourcesNewFilename.size())*100.0f, _("Exporting ")+it->second) )
                    return false; //User choose to abort.
            }
            #endif

            //Create the destination filename
            gd::String destinationFile(destinationDirectory + "/" + it->second);
            fs.MakeAbsolute(destinationFile, destinationDirectory);

            if ( destinationFile != it->first )
            {
                //Be sure the directory exists
                gd::String dir = fs.DirNameFrom(destinationFile);
                if ( !fs.DirExists(dir) ) fs.MkDir(dir);

                //We can now copy the file
                if ( !fs.CopyFile(it->first, destinationFile) )
                {
                    gd::LogWarning( _( "Unable to copy \"")+it->first+_("\" to \"")+destinationFile+_("\"."));
                }
            }
        }

        ++i;
    }

    return true;
}