Self-updating .net CF application

I need to self-update my CF application through a web service. I have found one article on MSDN since 2003 that explains this pretty well. However, I would like to talk about practice here. Has anyone really done this before, or does everyone rely on third-party solutions?

I was specifically asked to do it this way, so if you know any tips / cautions, any information is appreciated.

Thanks!

+3
source share
4 answers

This is relatively easy to do. Basically, your application calls a web service to compare its version with the version available on the server. If the server version is newer, your application loads the new EXE as an array of byte [].

Further, since you cannot delete or overwrite the executable EXE file, your application will rename the source EXE file to something like "MyApplication.old" (fortunately, the OS allows this). Then your application saves the downloaded byte [] in the same folder as the original EXE file and with the same original name (for example, "MyApplication.exe"). Then you show a message to the user (for example, "a new version has been detected, reboot") and close.

, , . ( "MyApplication.old" ), .

- ( , , ) 100% . .

+2

: Windows Mobile

.

App1: , CAB (). , CAB .

App2: . -, URL-, (). .

: , , ( , ..), .

: wceload.exe http://msdn.microsoft.com/en-us/library/bb158700.aspx

    private static bool LaunchInstaller(string cabFile)
    {
        // Info on WceLoad.exe
        //http://msdn.microsoft.com/en-us/library/bb158700.aspx
        const string installerExe = "\\windows\\wceload.exe";

        const string processOptions = ""; 
        try
        {
            ProcessStartInfo processInfo = new ProcessStartInfo();
            processInfo.FileName = installerExe;
            processInfo.Arguments = processOptions + " \"" + cabFile + "\"";

            var process = Process.Start(processInfo);
            if (process != null)
            {
                process.WaitForExit();
            }

            return InstallationSuccessCheck(cabFile);
        }
        catch (Exception e)
        {
            MessageBox.Show("Sorry, for some reason this installation failed.\n" + e.Message);
            Console.WriteLine(e);
            throw;
        }
    }

    private static bool InstallationSuccessCheck(string cabFile)
    {
        if (File.Exists(cabFile))
        {
            MessageBox.Show("Something in the install went wrong.  Please contact support.");

            return false;
        }
        return true;
    }

: Assembly.GetExecutingAssembly(). GetName(). Version.ToString()

:

        public void DownloadUpdatedVersion(string updateUrl)
    {
        var request = WebRequest.Create(updateUrl);
        request.Credentials = CredentialCache.DefaultCredentials;
        var response = request.GetResponse();

        try
        {
            var dataStream = response.GetResponseStream();
            string fileName = GetFileName();
            var fileStream = new FileStream(fileName, FileMode.CreateNew);

            ReadWriteStream(dataStream, fileStream);
        }
        finally
        {
            response.Close();
        }
    }
+2

What exactly do you mean by "self-renewal"? If you mean configuration or data, then web services should work just fine. If you're talking about automatically downloading and installing a new version of yourself, this is a different story.

Found this downloadable sample from Microsoft - it looks like it should help.

+1
source

If you want to use a third-party component, check out the AppToDate developed by the guys at MoDaCo.

0
source

Source: https://habr.com/ru/post/1703826/


All Articles