views:

234

answers:

3

We have a Ruby-on-rails server-side deployment that needs to allow users to download a pre-compiled self-extracting Windows EXE file on their computer.

We also need to generate a text file dynamically (based on the users id) and deploy it somewhere on the client machine where the EXE can find it.

We have 2 options:

  1. Generate this text file on the linux server and SOMEHOW? embed it in the Windows EXE. This seems far-fetched
  2. Get the user to download the static EXE and somehow get the dynamic text information stored on the clients machine (either through an invisible download, cookies, vbscript or javascripting on client side).

Note that we have, for now, ruled out having 2 separate download links (1 for the exe and 1 for the dynamic text info) because of problems associated with that user experience (i.e. ugly UX, downloads could be stored on different paths etc).

I am not much of a web developer but after spending a few minutes on Google, I think both solutions are ridden with problems and ugly.

Anybody's got a smart idea?

A: 

It is possible to embed the text file into the executable as a resource.

Ignacio Vazquez-Abrams
+1  A: 

A couple of ideas:

1) Zip the exe and text file on the server file to be unzipped into the same location (creating a self extracting zip (exe) would be better.

2) Provide a KEY/PIN CODE after the user downloads the exe. When the application is first run, detecting no text file, it asks for the PIN, the exe then calls a webservice and downloads the information to save to the text file. This can be a Guid for instance.

Mark Redman
I like your first idea! Thanks!It is further discussed here:http://stackoverflow.com/questions/818482/creating-a-self-extracting-zip-archive-on-a-linux-box
bhavinb
+2  A: 

It is possible to simply append your text file to the exe. These additional bytes will be ignored by the operating system loader, but your program will be able to get them. This is how self-extracting EXEs work.

The exe, when run, opens args[0] (which is its own executable) and seeks the necessary number of bytes from the end and then reads the text.

It is straightforward for your web-script to serve the bytes of the exe in the response, and then send also the text file in the same response.

If the text is not a fixed length, you can also send the length of the text as an integer at the very end of the stream. The exe then reads first this fixed-size length field, before seeking the appropriate number of bytes from the end for reading the variable part.

The various examples [msdn] of appending data to the EXE show parsing the EXE structure from the beginning to find where the data starts. Simply appending the length of the data last to the EXE avoids needing to understand the EXE structure.

Will
Thanks for the detailed reply. I did not know you could do what you've suggested so that is quite useful to know. However, I think the suggestion by Mark Redman below of packing up a self-extracting exe on the linux box sounds an easy, elegant way to fix my problem so I am going to go with that.I have also found another similar thread on Stackoverflow which discussed this very same suggestion further with pointers to tools I can use.http://stackoverflow.com/questions/818482/creating-a-self-extracting-zip-archive-on-a-linux-box
bhavinb