更新程序设置

时间:2008-10-29 13:57:19

标签: c# installation

我没有制作设置的经验,但我已经准备好了我的但现在我需要帮助,因为当我创建一个新版本时,我希望用户双击快捷方式,如果有的话,它会进行更新。< / p>

该应用程序位于c#

你可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

这是我如何实现我之前写的更新程序。

首先,您从服务器上获取一个ini文件。此文件将包含有关最新版本以及安装文件所在位置的信息。获取该文件并不太难。

                WebClient wc = new WebClient();
                wc.DownloadFile(UrlOfIniContainingLatestVersion, PlacetoSaveIniFile);

我还设置了从本地ini文件中读取信息以确定最新版本。更好的方法是直接读取文件版本,但我没有代码可以做到这一点。

接下来,我们进行一项非常简单的检查,看看两个版本如何比较和下载更新。

            if (LatestVersion > CurrentVersion)
            {
                //Download update.
            }

下载更新就像下载原始版本一样简单。您只需更改两个参数即可。

wc.DownloadFile(UrlOfLatestSetupFile, PlaceToSaveSetupFile);

现在您已经下载了文件,只需运行安装程序即可。

System.Diagnostics.Start(PathOfDownloadedSetupFile);

如果您不确定如何阅读ini文件,我在CodeProject上找到了以下课程

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Ini
{
    /// <summary>
    /// Create a New INI file to store or load data
    /// </summary>
    public class IniFile
    {
        public string path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section,
            string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section,
                 string key, string def, StringBuilder retVal,
            int size, string filePath);

        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <PARAM name="INIPath"></PARAM>
        public IniFile(string INIPath)
        {
            path = INIPath;
        }

        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// Section name
        /// <PARAM name="Key"></PARAM>
        /// Key Name
        /// <PARAM name="Value"></PARAM>
        /// Value Name
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }

        /// <summary>
        /// Read Data Value From the Ini File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// <PARAM name="Key"></PARAM>
        /// <PARAM name="Path"></PARAM>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp,
                                            255, this.path);
            return temp.ToString();

        }
    }
}

答案 1 :(得分:0)

听起来您可以使用ClickOnce