-1

どんなプログラムにも使えるプログラムアップデーター・ランチャーを作っています。クライアントに構成ファイルがあり、http サーバーに構成ファイルがあります。両方からバージョン番号を取得して比較し、そうでない場合はクライアントを更新します。

更新の開始時を除いて、すべてが機能しています。私が必要としているのは、誰かが私のアプリケーションをダウンロードして使用しない場合、たとえば 1 か月間、その間に 5 つほどの更新がある場合です。問題は、最初の更新プログラムをダウンロードしてインストールし、すべてのダウンロードが完了するまで次の更新プログラムをダウンロードする方法です。

私はプログラミングが初めてで、これは私が考えることができる唯一の種類のアプリであり、学習に取り組むことができます. ありがとう

http サーバー XML ファイルの私の settings.conf。

<Table>
<Product>
<Product_id>1</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.1</Product_version>
<Product_Url>http://localhost/update/v1.0.0.1.exe</Product_Url>
<Product_id>2</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.2</Product_version>
<Product_Url>http://localhost/update/v1.0.0.2.exe</Product_Url>

<Product_id>3</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.3</Product_version>
<Product_Url>http://localhost/update/v1.0.0.3.exe</Product_Url>

<Product_id>4</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.4</Product_version>
<Product_Url>http://localhost/update/v1.0.0.4.exe</Product_Url>

<Product_id>5</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.5</Product_version>
<Product_Url>http://localhost/update/v1.0.0.5.exe</Product_Url>


</Product>
</Table>

私のクライアント構成 XML ファイル。

<Table>
<Product>
<Product_id>1</Product_id>
<Product_name>Infected</Product_name>
<Product_version>1.0.0.0</Product_version>
<Product_Url>http://localhost/update/v1.0.0.1.exe</Product_Url>
</Product>
</Table>

私のC#フォーム。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.Remoting;

namespace Launcher
{
    public partial class Form1 : Form
    {

        public Form1()
        {

            InitializeComponent();
        }

        public string localversion { get; set; }
        public string remoteversion { get; set; }
        public string UpdateURL { get; set; }

        private void Form1_Load(object sender, EventArgs e)
        {

            webBrowser1.Navigate("http://www.kceoc.com/");
            webBrowser2.Navigate("http://www.kceoc.com/");

            button1.Enabled = false;    // Disable the launch button untill all updates are completed.
            GetLocalXMLFile();          //Run first xml function to start everything off.


        }

        private void GetLocalXMLFile()
        {
            try     //Start error checking.
            {
                using (XmlTextReader localxml = new XmlTextReader("settings.conf"))  //Load xml file in same folder as launcher.exe
                {
                    while (localxml.Read())  // Start reading the settings.conf file
                    {
                        switch (localxml.NodeType) //Get the Node that we will use.
                        {
                            case XmlNodeType.Text:
                                label1.Text = localxml.Value;  //Change the text of label1 to value of Node.
                                string localversion = localxml.Value;  // Store Node Value in string localversion for latter use.
                                GetRemoteXMLFile(localversion, remoteversion); //Everything went ok and got a value from Node so pass this all to our next function witch is get remote xml.
                                break;
                        }
                    }
                }

            }
            catch (FileNotFoundException)
            {
                label1.Text = "Local Config not found. Reinstall the application"; // Catch error incase file is not there.
            }
        }

        private void GetRemoteXMLFile(string localversion, string remoteversion)
        {
            try  //Start error checking
            {
                using (XmlTextReader remotexml = new XmlTextReader("http://localhost/update/settings.conf"))  //Load up remote xml on web server
                {
                    while (remotexml.Read())  //Start reading xml file from server.
                    {
                        switch (remotexml.NodeType)
                        {
                            case XmlNodeType.Text:
                                label2.Text = remotexml.Value; // Change value of label2 to remote xml node value
                                remoteversion = remotexml.Value; // Set the remoteversion string to remotexml.value
                                CompareXMLFileVersions(localversion, remoteversion); // Everything went ok so send localversion string and remoteversion string to compare function.
                                break;
                        }
                    }
                }

            }
            catch (FileNotFoundException)
            {
                label1.Text = "Remote config not found. Maby website id down?"; // Catch error incase file is not there.
            }
        }


        private void CompareXMLFileVersions(string localversion, string remoteversion)
        {

            label1.Text = localversion;         // Just so we can see the value in the lables to konw if they have value or not.
            label2.Text = remoteversion;         // Just so we can see the value in the lables to konw if they have value or not.

            if (localversion == remoteversion)  // Comparing the values of localversion and remoteversion and if they have same value then
            {                                   // change label3 to You have latest version.
                label3.Text = "You have the latest version";

            }
            else
            {
                label3.Text = "There is a new version. Starting update process here"; // If localversion and remoteversion are diffrent then let user know the files are out of date and start the updating process..
                GetListOfUpdates(remoteversion);  // Starting the updating process function..     

            }
        }

        private void GetListOfUpdates(string remoteversion)
        {

            //WebClient webClient = new WebClient();
            //webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            //webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            //webClient.DownloadFileAsync(new Uri(remoteversion), @"v1.0.0.1.exe");

            string url = "http://localhost/update/v1.0.0.1.exe";
            WebClient downloader = new WebClient();
            downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
            downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
            downloader.DownloadFileAsync(new Uri(url), "temp.exe");



        }


        void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {

            label1.Text = e.BytesReceived + " " + e.ProgressPercentage;
        }
        void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            //if (e.Error != null)
            //    MessageBox.Show(e.Error.Message);
            //else
            //    MessageBox.Show("Completed!!!");
        }


    }
}

ありがとう

4

1 に答える 1

2

SOへようこそ!

私はプログラミングが初めてで、これは私が考えることができる唯一の種類のアプリであり、学習に取り組むことができます. ありがとう

あなたがどれだけ新しいかにもよりますが、少し簡単なものから始めることをお勧めします. それ以外の場合は、まず実際にフローチャートを作成することをお勧めします。あなたのロジックは少しずれているように見えます。このシステムを作成しながら設計しようとしているように見えますが、これは決してやりたくないことです。

これには、自分で作成できるものよりも優れた信頼性の高いシステムを提供するソリューションがたくさんありますが、この種のプロジェクトの教育的価値は理解できます。まさにその理由で、最近自分の「自動更新/ランチャー」を作成しました。これは、無料の Web サーバー上で自分自身と数​​人の友人が唯一のユーザーであるにもかかわらず、かなりうまく機能します。

これが私が作成したフローチャートです。

ここに画像の説明を入力 大: http://i.imgur.com/qS1U8.png

これは実際には私の小さなプロジェクトの 2 回目の反復であり、最初の反復はそれほど圧倒されず、まれな状況ではやや悲惨ですが、良い学習体験です。これには、更新中にユーザーにメッセージを表示するなどのことを定義できる間抜けなコマンド ファイルもあります。

ひどく乱雑なコードを見ても構わない場合は、ここのコード リポジトリを参照してください。ただし、ドキュメント化されておらず、実際には使用されていないものの、ソース管理から削除されていない部分もあります。それを使用するサンプルアプリケーションはこちらですソース、これも乱雑です)。

恥知らずなセルフプラグのように見えて申し訳ありませんが、私はあなたの質問に直接答えることはできません.かなり楽しいプロジェクト。

于 2012-08-11T00:01:56.937 に答える