Skip to content

Instantly share code, notes, and snippets.

@RFullum
Created April 18, 2023 19:52
Show Gist options
  • Save RFullum/c9c9c8da38cfa358d5f4ea8352f680a6 to your computer and use it in GitHub Desktop.
Save RFullum/c9c9c8da38cfa358d5f4ea8352f680a6 to your computer and use it in GitHub Desktop.
Find all unused BinaryData in Juce app
/*
Put this somewhere in the Juce app (ie. the MainComponent ctor).
When you build in debug, it prints to console all the files in BinaryData
that aren't being used in your code.
*/
DBG(" ");
auto SourceDir = juce::File("~/ /*ABSOLUTE/PATH/TO/SOURCE/DIRECTORY/GOES/HERE*/");
std::vector<juce::File> sourceFiles;
std::array<bool, (size_t)BinaryData::namedResourceListSize> usedBinaryItemIndexes { false };
for (juce::DirectoryEntry entry : juce::RangedDirectoryIterator(SourceDir, true))
if (!entry.isHidden())
sourceFiles.emplace_back(entry.getFile());
for (auto file : sourceFiles)
{
auto fileText = file.loadFileAsString();
for (int item = 0; item < BinaryData::namedResourceListSize; ++item)
{
auto binaryItem = juce::String(BinaryData::namedResourceList[item]);
if (fileText.contains(binaryItem))
usedBinaryItemIndexes[item] = true;
}
}
std::vector<juce::String> usedItems;
std::vector<juce::String> unusedItems;
for (int i = 0; i < usedBinaryItemIndexes.size(); ++i)
{
if (usedBinaryItemIndexes[i])
usedItems.emplace_back(juce::String(BinaryData::namedResourceList[i]));
else
unusedItems.emplace_back(juce::String(BinaryData::namedResourceList[i]));
}
DBG("--- USED BINARYDATA ITEMS ---");
for (auto bdItm : usedItems)
DBG(bdItm);
DBG(" ");
DBG("--- UNUSED BINARYDATA ITEMS ---");
for (auto bdItm : unusedItems)
DBG(bdItm);
DBG(" ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment