private void button1_Click(object sender, RoutedEventArgs e) { isDownloading = true; this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Send, (Action)(() => { remove.IsEnabled = false; })); HandleXnaVersion(); if (isConnected == false) { MessageBox.Show("No Internet Connection"); return; } try { String sitem = listBox1.SelectedItem as String; if (String.IsNullOrEmpty(sitem)) { MessageBox.Show("You Must select a version"); this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { remove.IsEnabled = true; })); isDownloading = false; return; } if (sitem != packageName) { if (!String.IsNullOrEmpty(packageName)) { DeleteCurrentEngineVersion(); GetVersionOnRegistry(); if (!String.IsNullOrEmpty(packageName)) { MessageBox.Show("You need to unistall current version to be able to install another"); this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { remove.IsEnabled = true; })); isDownloading = false; return; } } Random rd = new Random(); int rdnum = rd.Next(); button1.IsEnabled = false; progressBar1.Value = 0; label2.Content = "Downloading"; Task.Factory.StartNew(() => { try { FTP ftp = new FTP("ftp.ploobs.com.br", "ploobs", "5ruTrus6"); ftp.Connect(); ftp.ChangeDir("/ploobs/Web/Updater/" + sitem); String temppath = System.IO.Path.GetTempPath() + System.IO.Path.GetRandomFileName(); ftp.OpenDownload("PloobsEngine.rar", temppath, true); while (ftp.DoDownload() != 0) { progressBar1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { progressBar1.Value = 100 * (float)ftp.BytesTotal / (float)ftp.FileSize; })); } label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { label2.Content = "INSTALLING"; })); if(File.Exists(System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe")) { File.Delete(System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe"); } if(Directory.Exists(System.IO.Path.GetTempPath() + "PloobsEngine/")) { Directory.Delete(System.IO.Path.GetTempPath() + "PloobsEngine/", true); } RarArchive.WriteToDirectory(temppath, System.IO.Path.GetTempPath(), NUnrar.Common.ExtractOptions.ExtractFullPath); temppath = System.IO.Path.GetTempPath() + "PloobsEngine//setup.exe"; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = temppath; process.Start(); process.WaitForExit(); packageName = sitem; GetVersionOnRegistry(); label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { label2.Content = "Current Version: " + packageName; })); MySqlCommonConnection.WriteClientToDB(sitem); } catch (Exception ex) { MessageBox.Show(ex.ToString()); label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { label2.Content = "ERROR"; })); } finally { button1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { button1.IsEnabled = true; })); if (packageName != null) { label2.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { label2.Content = "CurrentVersion: " + packageName; })); } } } ); } else { MessageBox.Show("You already have this version installed, Unistall it first clicking on Remove Current Version"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } isDownloading = false; this.remove.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { remove.IsEnabled = true; })); }
public static void DownloadFilesFromFTP() { FTP ftplib = new FTP(); try { Console.WriteLine( "Connecting to \"ftp.khaeros.net\"..." ); ftplib.Connect( "ftp.khaeros.net", "khaeros", "mVJJQLvpR5" ); Console.WriteLine( "Retrieving file log from the database..." ); ftplib.ChangeDir( "public_html/data/pages/database/creatures/" ); } catch( Exception ex ) { Console.WriteLine( ex.Message ); if( mob != null ) { mob.SendMessage( ex.Message ); mob = null; } trd = null; return; } try { int perc = 0; List<string> lines = new List<string>(); List<string> files = new List<string>(); Console.WriteLine( "Received the following log:" ); foreach( string line in ftplib.List() ) { Console.WriteLine( line ); lines.Add( line ); } for( int i = 0; i < lines.Count; i++ ) { if( !lines[i].Contains( ".txt" ) ) { Console.WriteLine( "Skipping line " + i.ToString() + "." ); continue; } Console.WriteLine( "Parsing line " + i.ToString() + "." ); string[] strings = lines[i].Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries ); for( int a = 0; a < strings.Length; a++ ) { if( !String.IsNullOrEmpty( strings[a] ) && strings[a].Contains( ".txt" ) ) files.Add( strings[a] ); } } foreach( string file in files ) { Console.WriteLine( "Attempting to download file: \"" + file + "\"." ); ftplib.OpenDownload( file, FilePath + file, true ); while( ftplib.DoDownload() > 0 ) { perc = (int)( ( ftplib.BytesTotal * 100 ) / ftplib.FileSize ); Console.Write( "\rDownloading: {0}/{1} {2}%", ftplib.BytesTotal, ftplib.FileSize, perc ); Console.Out.Flush(); } if( Misc.CrashGuard.Crashed ) { trd = null; return; } Console.WriteLine( "" ); } } catch( Exception ex ) { Console.WriteLine( "" ); Console.WriteLine( ex.Message ); if( mob != null ) { mob.SendMessage( ex.Message ); mob = null; } trd = null; return; } if( Misc.CrashGuard.Crashed ) { trd = null; return; } LoadCreatureFiles( mob ); if( mob != null ) { mob.SendMessage( "The database was successfully updated." ); mob = null; } Console.WriteLine( "The database was successfully updated." ); trd = null; }