C # Prepare an online Upgrade Program,
// This Is A webserviceprivate AppUpdate. updateServ UpdateSvr; private void button#click (object sender, System. eventArgs e) {if (LinkWebServices () = true) {this. label1.Text = "connect to the server ....... PASS "; if (CheckVer () = true) {this. label2.Text = "check the latest version and download ....... PASS ";} else {this. label2.Text = "check the latest version and download ....... FAIL ";}} else {this. label1.Text = "connect to the server ....... FAIL ";}}// this is used to establish a connection with the upgrade server private bool LinkWebServices () {Try {UpdateSvr = new UpdateServ (); return true;} catch {return false ;}// call webservice to check whether the latest version of private bool CheckVer () exists () {string path = Application. startupPath; try {VersionCheck (path); return true;} catch (Exception ex) {MessageBox. show (ex. toString (); return false ;}} private void VersionCheck (string desPath) {try {# region viewing files and directories if (! DesPath. EndsWith (@ "\") desPath + = @ "\"; if (! System. IO. directory. exists (desPath) {System. IO. directory. createDirectory (desPath);} string tempPath = desPath + @ "tempDesPathCache \"; if (System. IO. directory. exists (tempPath) {System. IO. directory. delete (tempPath, true); System. IO. directory. createDirectory (tempPath);} else System. IO. directory. createDirectory (tempPath); if (! System. IO. file. exists (desPath + "UpdateConfig. xml ") {System. xml. xmlDocument updateConfig = new System. xml. xmlDocument (); updateConfig. loadXml (@ "<root> </root>"); updateConfig. save (desPath + "UpdateConfig. xml ") ;}# endregion System. xml. xmlDocument serverXmlDoc = UpdateSvr. appUpdateVertion (); System. xml. xmlDocument localXmlDoc = new System. xml. xmlDocument (); localXmlDoc. load (desPath + "UpdateConfig. Xml "); bool newVersionExist = false; bool moduleExist = false; System. xml. xmlNode serverNode0 = serverXmlDoc. childNodes [0]; System. xml. xmlNode localNode0 = localXmlDoc. childNodes [0]; foreach (System. xml. xmlNode serverNode in serverNode0) {moduleExist = false; foreach (System. xml. xmlNode localNode in localNode0) {// find the corresponding module if (localNode. childNodes [0]. innerText = serverNode. childNodes [0]. innerText ){ ModuleExist = true; // judge if (localNode. childNodes [1]. innerText. compareTo (serverNode. childNodes [1]. innerText) <0) {newVersionExist = true; if (System. configuration. configurationSettings. appSettings ["NetStyle"]. toString () = "internet") {DownloadFile (serverNode. childNodes [2]. innerText, tempPath + serverNode. childNodes [0]. innerText);} else {DownloadFile (serverNode. childNodes [3]. innerText, tempPath + ServerNode. childNodes [0]. innerText) ;}} break ;}// the module if (false = moduleExist) {if (System. configuration. configurationSettings. appSettings ["NetStyle"]. toString () = "internet") {DownloadFile (serverNode. childNodes [2]. innerText, tempPath + serverNode. childNodes [0]. innerText);} else {DownloadFile (serverNode. childNodes [3]. innerText, tempPath + serverNode. childNodes [0]. innerText) ;}}// write new UpdateConfig. replace if (newVersionExist) {serverXmlDoc. save (tempPath + "UpdateConfig. xml "); if (DialogResult. yes = MessageBox. show ("Is there a new version, update? "," Prompt ", MessageBoxButtons. yesNo) {string [] dirs = System. IO. directory. getFiles (tempPath ,"*. * "); string fileName; foreach (string dir in dirs) {fileName = (dir. split (Convert. toChar (@ "\") [dir. split (Convert. toChar (@"\")). length-1]); if (System. IO. file. exists (desPath + fileName) {// TODO: supports backing up previous versions of System. IO. file. delete (desPath + fileName);} // TODO: if the System is running, you must stop the System. diagnostics. process System. IO. file. move (dir, desPath + fileName);} MessageBox. show ("upgrade completed");} else {// TODO: You can prompt for a new update.} catch (Exception ex) {throw new Exception ("upgrade failed because: "+ ex. message, ex) ;}/// download the latest file private void DownloadFile (string source, string fileName) {try {System. net. webClient myWebClient = new System. net. webClient (); myWebClient. downloadFile (source, fileName);} catch (Exception ex) {throw new Exception ("Download failed because:" + ex. message, ex );}}
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.