简体   繁体   中英

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.

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).

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).

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.

一个想法-您可以有一个加载程序应用程序为您进行检查,然后在启动前更新主应用程序的exe(如果需要)?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM