Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove unnecessary resources from my project?

I am working with a very big project (a solution that contains 16 projects and each project contains about 100 files).

It is written in C++/C# with Visual Studio 2005.
One of the projects has around 2000 resources out of which only 400 are actually used.
How do I remove those unused resources?

I tried to accomplish the task by searching for used ones.
It worked and I was able to build the solution, but it broke at runtime.

I guess because enums are used. (IMPORTANT)

How can I make sure that it doesn't break at runtime?

EDIT:
I think one method could be to generate the resource (that is not found) on the fly at runtime (somehow).
But I have no idea about ... anything.

NOTE: It's okay if a few unnecessary resources are still there.

like image 760
Pratik Deoghare Avatar asked Sep 30 '09 08:09

Pratik Deoghare


People also ask

How you can remove resource from your project?

Tip: To remove a resource from a project, on the View tab, choose Resource Sheet. Select the resource, and then press the DELETE key.

When can a project manager remove a resource from a project?

Delete a resource from the project when it is determined the resource is not needed. A project resource can only be deleted from the project where it is owned.


1 Answers

What I would do is write a custom tool to search your source code.

If you remove a resource ID from a header file (i.e. possibly called resource.h) and then recompile and get no warnings: then that's a good thing.

Here is how I would go about writing the app. Take as input the resource file (resource.h) you want to scrutinize. Open the header file (*.h) and parse all the resource constants (Or at least the onces you are interested in). Store those in a hash table for quick look up later. For each code file in your project, search the text for instances of each of your resource ID's. When a resource ID is used, increment the value in the hash table otherwise leave it at zero. At the end, dump all the resource ID's that are zero out a log file or something. Then test that indeed you can remove those specified resource ID's safely. Once you do that, then write another tool that removes the specified resource ID's given the results of your log file.

You could write such a tool in perl and it would execute in about 0.3 seconds: But would take days to debug. :) Or you could write this in .NET, and it would execute a little slower, but would take you an hour to debug. :)

like image 156
C Johnson Avatar answered Sep 19 '22 15:09

C Johnson