Self updating windows program part 2

by mderaeve 3. July 2009 13:40

In part 1 I explained how to write and implement a self updating windows program. The functionality was simple. Just before I close the program to be updated, I open the “update.bat“ file. Then I close the program. The bat file first pings to create a delay and after the ping it copies the new files to the directory. When its finished it will open the application again.

 

Because the interaction with the user is not so great, although I did not receive any complaints, I decided to improve this part of the application.

 

After some thinking I came up with the idea to create an updater program which can be used for multiple programs. So it had to be configurable.

 

The only thing you have to do is to copy the updater.exe and its configuration file to your solution. Make sure it is copied to the bin folder. Just add it to your solution and right-click on the files and choose properties. Then you will see the property copy to output directory. Set this property to: Copy always. Then you fill in the path in the configuration file. The configuration file could look something like this:

 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="UpdateFilesPath" value="\\fileserver\updates\myprogram\latestversion\"/>
  </appSettings>
</configuration>
 

Then in the directory where the new files are placed, you’ll have to add an XML file called:updateInfo.xml with the following format:

 
<?xml version="1.0" standalone="yes"?>
<UpdateInfoDS xmlns="http://tempuri.org/UpdateInfoDS.xsd">
  <UpdateInfo>
    <ApplicationName>MyProgram</ApplicationName>
    <NewVersion>2.1.1.2</NewVersion>
    <ExtraInfo>Test version for update</ExtraInfo>
    <DeletePrevVersion>false</DeletePrevVersion>
  </UpdateInfo>
</UpdateInfoDS>

So here we can set the parameters of the updater. The new version and extra info parameters are simply to inform the user during update about what is being updated. The application name is shown on the tool as well, but is also used to check if the program to be updated is still in use. So it is important this is exactly the same is the exe you are trying to update.

The delete previous version (DeletePrevVersion) parameter is like it suggests: deleting all the files of the previous version.

 

To check if a new version is needed and to start the updater is similar as in part 1, but I will explain it again:

 

Because I’m working on a network with a database, I’ll check the database for a new version:

 
Assembly asm = Assembly.GetExecutingAssembly();
//Check registration and version
if (CheckRegistration(asm.GetName().Version.ToString()))
  

If there is a newer version then the current version of the program I will start an update:

 
System.Diagnostics.Process.Start(Application.StartupPath + @"\Updater.exe");
 

After I started the updater program, I’ll write some information to the database and close the application. The updater will wait until the program is closed until it starts the update.

This check is performed like this:

 
bool into = false;
string updatePath = ConfigurationSettings.AppSettings["UpdateFilesPath"];
int counter = 0;
while (!into)
{
    try
    {
        File.Copy(updatePath + @"\" + appName + ".exe", appName + ".exe", true);
        into = true;
    }
    catch
    {
        if (counter > 10)
        {
            return;
        }
        else
  {
            System.Threading.Thread.Sleep(500);
            counter++;
        }
    }
}
 
 

The deletion an copying of the files are done in a seperate thread, so it doesn't interfear with the GUI. The progress is set with thread safe methods. Before the update starts, I count the number of files to be copied and use this to set the progress bar limit. So it will give you a windows like information, if there is a files in the upload that is much bigger then the rest, the progress will not be as accurate. But still it give a better view then nothing, or just a wiating arrow.

When the copy is successful the program will go on to copy all files and if requested first delete all old files. The only files that are not deleted and copied over are the files of the updater itself. So it is really important that your updater is working really good and tested through several times. The update files have to be on the network, I'm currently working on an update of this program that enables you to place the update files on the internet. Then I should rewrite the File.Copy part.

 

That’s why I look at the updater not as a part of any solution but a separate program that can be used throughout all kinds of windows applications. 

You can download the source of the updater at the dailycode.net download page.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: update

WIN.NET

Using Oracle client 32 bit on a 64 bit computer

by mderaeve 3. July 2009 08:08

I created an application that uses oracle client to connect to the database. Never had any troubles with this until a new workstation arrived with a 64 main board. We installed and configured the Oracle client 32 bit. There are some tricks to this, if you need to know just ask. When I attempted to open the application, I got this error:

When I deployed the application on this workstation I got the following error:Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed. 

   

The reason was my application was compiled for the platform target: Any CPU. I had to change this the x86 and then the application works. You can change this in the properties window of your application on the build section.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: error

WIN.NET

Directory structure generator

by mderaeve 2. July 2009 05:36

Many people have a certain logic in the way they build up their files system, and so they should. Sometimes you want to view this structure or export it because you want to use it for some kind of purpose. Then you will have a hard time in windows getting the structure in an organized way to a file or excel sheet.

 

For this reason I created a tool that helps you export a directory structure. It started out just exporting the structure if the directories and files, but now you can use checkboxes to add more information to the export.

You can:

-         Choose to see only file or dir names or the complete path.

-         Choose the depth of the search. (0 is only the root directory)

-         Choose to show the size of the files.

 

Then for extra information on the top right you can see the number of files and directories that are shown.

 

You can download this project as an executable and/or the source files to get the function you need out of it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: directory, download

WIN.NET

The data source control failed to execute the insert command

by mderaeve 28. June 2009 04:32

In my test evironment, just like that, the workflows on a document library sotp working. Normally it starts on creation of a new document and the other can only be started manually. None of them worked anymore.

So what I did to resolve the problem was to remove the workflow from the library together with the complete history of the workflow. Then I opened the SharePoint designer and associated the workflows again with the list. Problem solved. I don't know why it happened, but for all I can google its a bug in SharePoint.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: workflow, error

WSS 3.0

Free movie, books and CD database

by mderaeve 27. June 2009 19:35

Recently I started a new project, for personal use. I have a large collection of CD's and DVD's, this taking up more and more place. So now I was looking for software to keep an inventory of all these multimedia. I could find some, but the most interesting where not free. So I decided to make my own. This is a really nice porject in which I try some new stuff. When it is ready I will make it as a free download including the source code. For now you it will cover 3 types of multimedia: Audio CD's, Movies and books. There is a build in lend out system and some other cool stuff. I choose not to overload the objects with to much properties.

Here's a first look at the program:

I store all data in XML files. When data is first called I cache it, so the program runs smoothly. Since it is only text, it will not take to much memory.  

The caching is something I'm looking into with much interest. Before you start caching, you'll have to look into what to cache and when. For example, you could load all data at program startup, but then the startup takes long. The program I'm making consists of 3 big parts, Audio, Video and Books. I will create the system so that you can disable and enable these functionalities, so this makes caching more complicated. It's really fun to think of the best and most performant ways to cache.

What I also will implement in the system is an online update. I got some ideas in my head, just trying them out as soon as the first version of the program is almost ready. It's offcourse important to have the update procedure ready before I will release the first version.

I cann assure you that you will find updates on this program on regular basis. It's a hobby!

Greetings and God bless this world!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: movie, cd, book

WIN.NET

Powered by BlogEngine.NET 1.1.0.2
Theme by Mark Deraeve

Calendar

<<  July 2009  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar
Locations of visitors to this page

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in