English 中文(简体)
I don t "get" how a program can update itself. How can I make my software update?
原标题:

Say I make an .exe file and everything is peachy. Wonderful it works.

Say I worked on a new feature on the software and I want it to be available for people who already have the older version, how can I make the software find my new version, patch it, and then go about it s business.

I can t seem to wrap my head around the issue.

Thank you.

EDIT: I m sorry for the confusion, but I was meaning a more code-wise answer. Is there something special in my code I should have to allow updating?

For example, if I want to add a new feature, how can I add a "method" to an already packaged .exe? :S That has me in a swivel.

最佳回答

You need to look at Click Once Deployment.

ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction. Visual Studio provides full support for publishing and updating applications deployed with ClickOnce technology if you have developed your projects with Visual Basic and Visual C#.

This creates a downloadable setup exe which you load up to the web. The user either runs this in place or downloads and runs it. This wraps your exe in the code that will check the web location (at a frequency of your choosing) for updates. If it finds one it will install it for the user.

You don t have to make any special changes to your code to enable this. beyond incrementing the version number. Just modify and extend your code as normal, compile, build, package and upload.

One thing to note is though that ClickOnce doesn t support installing applications that require administrative access:

ClickOnce deployment enables non-administrative users to install and grants only those Code Access Security permissions necessary for the application.

So if your application requires admin level access to run or even install then it s not the solution for you.

问题回答

Usually the process is as follows:

  • the user starts the applicataion
  • the application launches an "updater" (another program)
  • the updater retrieves from the Internet if a newer version exists
  • if that s the case, propose the user to update
  • the users accepts, the updater downlads the new install package (that can be incremental)
  • the updater shuts the application down (or better, asks the user to do it) and launches the new installer.
  • the installation package do the rest

Of course you can have many variation, but this is the basic way to do it.

On Windows, at least, some software install an updater deamon that is always on and checks for new updates of the software it takes care (GoogleUpdater, for example).

A popular solution is to actually have a separate process replace the necessary files.

Have you ever noticed that Firefox has to restart whenever it updates? Well, that is because a separate process (updater.exe) is downloading the files, closing firefox, replacing the files, and then starting firefox again.

edit of course this assumes you re hosting a list of updates online that the updater program can check (an RSS feed, or even a simple text file).

One idea - you could have a loader application that does the check for you, then if necessary updates the main app s exe before launching it?

For windows (generally due to windows locking the .exe file while it s being executed)

  • Software determines it needs updating
  • Software runs packaged update executable (at this point Software exits)
  • Update downloads required files into some temp folder
  • Update applies patches
  • Update restarts Software

Well, the usual way is that your application checks somewhere (usually on the Internet) regularly for new versions. This may be on every startup or once a week or whatever.

There you can simply put for example a text file containing the current version number. If that one would be newer than the version of the installed application you can download an updater (don t forget to sign and check signatures) and install the new version.

Make your app occasionally make a request over the web to your webserver. Have that request return a file that contains the version number and a link to the newest version of your installer. If that version number is greater than the version number the currently-running program thinks it is, have your program download the new setup file and launch it.

You don t modify your current .exe.

You launch a separate process that downloads a new version of the file. The new version replaces the old version. No modification needed.

From a code point of view I like to have an approach that consists on a simple interface called IRun and another one called IUpdated:

public interface IRun()
{
  public void Run();
}

public interface IUpdated()
{
  public void Update();
}

Now my main application will just load and "run" a library using reflection which in turns launch the real application.

The main application executable will do this steps:

  1. Read updater.cfg, connect to the provided location and check for updates to the updater.
  2. If there are updates download the updated dlls and updater.cfg
  3. Using reflection load updater.dll and launch Update() method.

The update method does the same steps for updates to the actual application.

Finally

  1. Load "core.dll" and launch the Run() method.

That s of course provided you want to "do it yourself", ClickOnce is actually a very good method too, probably better but gives you less control. The main application executable is simple enough to avoid having to update it itself or should be anyway.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签