2008-10-29 57 views
1

我沒有製作設置的經驗,但我都準備好了,但現在我需要幫助,因爲當我創建一個新版本時,我希望用戶雙擊快捷方式,如果有更新是任何。更新程序設置

該應用程序在c#

你能幫忙嗎?

+0

您是否將您的安裝設置爲MSI? – EBGreen 2008-10-29 14:01:24

回答

1

以下是我如何實現我之前編寫的更新程序。

首先,您從服務器上獲取ini文件。該文件將包含有關最新版本的信息以及安裝文件的位置。獲取該文件並不難。

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

我還設置了從本地ini文件讀取信息以確定最新版本。這樣做的更好方法是直接讀取文件版本,但我沒有代碼來執行該操作。

接下來我們做一個非常簡單的檢查,看看這兩個版本如何比較和下載更新。

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

下載更新與下載原始ini一樣簡單。您只需更改更改這兩個參數。

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(); 

     } 
    } 
}