c# - Check if File exists and download -


i'm trying make "file-updater" when program opens, detects if exists folder called "mods", corresponding files , sizes (in bytes). works! have label informs file downloading , it's showing last message "actualizacion finalizada.ya puedes jugar!" instead of "descargando " + armorsts", "descargando " + treecpt" , blablabla. ,how can inform label file i'm downloading right , file updated? if need see messages in english, let me know.

string armorsts = "[1.7.10]armorstatushud-client-1.28.jar"; string treecpt = "[1.7.10]treecapitator-universal-2.0.4.jar"; string advsolar = "advancedsolarpanel-1.7.10-3.5.1.jar";  private void form1_load(object sender, eventargs e) {     string path = @"c:\users\" + system.environment.username + "\\appdata\\roaming\\.minecraft\\mods\\";     if (!directory.exists(path)) /* si no existe, entonces... */     {         messagebox.show("la carpeta .minecraft (" + path + ") no se encuentra. por favor instale minecraft.",         "error al encontrar el directorio",         messageboxbuttons.ok,         messageboxicon.exclamation);         /* busquemos el directorio entonces... */         dialogresult result = folderbrowserdialog1.showdialog();         if (result == dialogresult.ok)         {             string[] files = directory.getfiles(folderbrowserdialog1.selectedpath);         }         /* si cancelamos entonces cerramos el programa */         else         {             application.exit();         }     }     /* si la carpeta existe, entonces... */     else {         /* si el mod esta, entonces... */         fileinfo mod_1 = new fileinfo(path + armorsts);         /* checkeamos si pesa igual */         if (file.exists(path + armorsts) && mod_1.length == 27281)          {             label1.text = armorsts + " - actualizado";             goto siguiente_1;         }         else         {             /* si el mod no esta o pesa diferente, entonces */             label1.text = "descargando " + armorsts;             /* descargar en %appdata%/.minecraft/mods */             webclient webclient = new webclient();             webclient.downloadfilecompleted += new asynccompletedeventhandler(completed);             webclient.downloadprogresschanged += new downloadprogresschangedeventhandler(progresschanged);             webclient.downloadfileasync(new uri("http://xipher.16mb.com/jallencraft/mods_actualizados/" + armorsts), path + armorsts);             goto siguiente_1;         } siguiente_1 :         fileinfo mod_2 = new fileinfo(path + treecpt);         if (file.exists(path + treecpt) && mod_2.length == 94792)         {             label1.text = treecpt + " - actualizado";             goto siguiente_2;         }         else         {             label1.text = "descargando " + treecpt;             /* descargar en %appdata%/.minecraft/mods */             webclient webclient = new webclient();             webclient.downloadfilecompleted += new asynccompletedeventhandler(completed);             webclient.downloadprogresschanged += new downloadprogresschangedeventhandler(progresschanged);             webclient.downloadfileasync(new uri("http://xipher.16mb.com/jallencraft/mods_actualizados/" + treecpt), path + treecpt);             goto siguiente_2;         } siguiente_2:          fileinfo mod_3 = new fileinfo(path + advsolar);         if (file.exists(path + advsolar) && mod_3.length == 305645)         {             label1.text = advsolar + " - actualizado";             goto siguiente_3;         }         else         {             label1.text = "descargando " + advsolar;             /* descargar en %appdata%/.minecraft/mods */             webclient webclient = new webclient();             webclient.downloadfilecompleted += new asynccompletedeventhandler(completed);             webclient.downloadprogresschanged += new downloadprogresschangedeventhandler(progresschanged);             webclient.downloadfileasync(new uri("http://xipher.16mb.com/jallencraft/mods_actualizados/" + advsolar), path + advsolar);             goto siguiente_3;         } /*         ...         ... , on , on , on ...         ...         */ siguiente_23:         fileinfo mod_24 = new fileinfo(path + witchery);         if (file.exists(path + witchery) && mod_24.length == 7009956)         {             label1.text = witchery + " - actualizado";             thread.sleep(1000);             actualizacionfinalizada();         }         else         {             label1.text = "descargando " + witchery;             /* descargar en %appdata%/.minecraft/mods */             webclient webclient = new webclient();             webclient.downloadfilecompleted += new asynccompletedeventhandler(completed);             webclient.downloadprogresschanged += new downloadprogresschangedeventhandler(progresschanged);             webclient.downloadfileasync(new uri("http://xipher.16mb.com/jallencraft/mods_actualizados/" + witchery), path + witchery);             actualizacionfinalizada();         } }   private void progresschanged(object sender, downloadprogresschangedeventargs e) {     colorprogressbar1.value = e.progresspercentage; }  private void completed(object sender, asynccompletedeventargs e) {     actualizando();     label1.text = "actualizado"; }  private void actualizacionfinalizada() {     actualizando();     label1.text = "actualizacion finalizada. ya puedes jugar!"; } 

i'm learning c# independently , know not correct way (repeating same code little modifications) if there's best way in simplifying code or best performance grateful!

this cuts basic principle of winforms. there 1 thread updating user interface. when set properties on controls change appearance, causes paint event fire on thread. changes won't visible until return program control thread.

what want here fix problem move of form_load code backgroundworker control. control exists explicitly provide place long-running methods otherwise block user interface thread.

also: goto? really?


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -