Include files in exe  
Author Message
Biche





PostPosted: Visual C# General, Include files in exe Top

Hi,

we want to create an utility tools for one of our customer, that can redistribute files over their clients.

The tool must act like the winzip exe file, so he choose the file to distribute, the tool is making a zip file an merge it to an exe file. Send the exe file to their client( with zip file embedded) and then the client just run the exe, uncompressing files and putting in the right directory.

The thing is, we do want our client to send only a file (the exe) that contain also the zip file, not two files, so my question is : Can we merge an exe file with an zip in one and only executable file

Note: our client is not a software company, so they don't use VS. We want our tool to do all the job for him.




Visual C#18  
 
 
TaylorMichaelL





PostPosted: Visual C# General, Include files in exe Top

You would have to store the ZIP file as a resource in the EXE. This is pretty easy to do using ResourceWriter but you'll end up having to create an EXE file which means you'll be using the CodeDom. I'd create the "extractor" console application and get it working by using a test resource. Then I'd take the source file and store it as a resource.

So you would actually have two tools. The creator tool would have a resource containing the skeleton console application in source format. You would take the ZIP file as input, pass it through ResourceWriter to generate a resource file, use the CodeDom to generate the code using the skeleton console application source file and the generate resource file to produce the final EXE. The extractor tool could be created and tested outside the creator tool. All it needs to do is load the ZIP file from the resource stream and extract it. You could combine the tools into one and use command line switches if you wanted. You could also support multiple files and provide users the option of extracting different ones. You can even get fancier and support directories but there comes a point when it might be better to simply use the existing ZIP2EXE tool from WinZip or another provider.

Honestly though you need to be careful. Most of the time it is better to send a ZIP file as it'll be smaller. Also note that it depends on the sending mechanism. Most e-mail clients, for example, won't allow you to send an EXE file but will let you send a ZIP file.

Michael Taylor - 12/12/06


 
 
Biche





PostPosted: Visual C# General, Include files in exe Top

We know about the ZIP2EXE, but we want to have the control about the output path of the files (Similar to a patch). And we don't zip any directories, just files. It's just a little utility tool that will create a single zip file, we don't want to expand the features, (it's for saving our support time with our client).

For the sending mechanism, for now it will be by email, and this is just a minor problem for now, since you can zip your exe().

Do you have any links to how create that skeleton and the CodeDom use by the creator tool, since I don't know nothing about this mechanism.



 
 
TaylorMichaelL





PostPosted: Visual C# General, Include files in exe Top

Assuming that you pre-build the extractor code and get it working stand alone then all you really need to do is load it into the DOM and compile it along with the resources. To do that you'll use code along the following lines.

CompilerParameters options = new CompilerParameters();
options.EmbeddedResources.Add(file path to resource file); //File must already be generated through ResourceWriter
options.GenerateExecutable = true;
options.GenerateInMemory = false;
options.MainClass = "..."; //The class where execution will begin
options.OutputAssembly = "..."; //Output file
options.ReferencedAssemblies.Add(...); //If any have any additional assemblies to compile against

CSharpCodeProvider prov = new CSharpCodeProvider(); //Can use any provider you want provided the skeleton code matches
CompilerResults res = prov.CompileAssemblyFromSource(options, sourceString);
if (res.Errors.Count > 0)
{
//errors
} else
{
//EXE now exists
};

You'll probably have to play around with the code a little bit to get it to work.

Michael Taylor - 12/12/06


 
 
Biche





PostPosted: Visual C# General, Include files in exe Top

Thanks,

I will give it a try