public MainWindow() { InitializeComponent(); this.Hide(); HandleXnaVersion(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(3,0,0); dispatcherTimer.Start(); InternetConnectionState_e flags = 0; isConnected = InternetGetConnectedState(ref flags, 0); GetVersionOnRegistry(); if (isConnected == false) return; try { AvaliableVersions.Clear(); ftp = new FTP("ftp.ploobs.com.br", "ploobs", "5ruTrus6"); ftp.Connect(); ftp.ChangeDir("/ploobs/Web/Updater"); foreach (String item in ftp.List()) { String[] files = item.Split(' '); String file = files[files.Count() - 1]; AvaliableVersions.Add(file); listBox1.Items.Add(file); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { ftp.Disconnect(); } if (packageName != null) { label2.Content = "CurrentVersion: " + packageName; } if (AvaliableVersions.Count == 0) { button1.IsEnabled = false; button2.IsEnabled = false; } }
/// <summary> /// TICK /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void dispatcherTimer_Tick(object sender, EventArgs e) { try { InternetConnectionState_e flags = 0; isConnected = InternetGetConnectedState(ref flags, 0); if (isConnected == false) return; if (AvaliableVersions.Count == 0) return; String oldLast = AvaliableVersions[AvaliableVersions.Count - 1]; try { ftp = new FTP("ftp.ploobs.com.br", "ploobs", "5ruTrus6"); ftp.Connect(); ftp.ChangeDir("/ploobs/Web/Updater"); System.Collections.ArrayList fileList = ftp.List(); AvaliableVersions.Clear(); listBox1.Items.Clear(); foreach (String item in fileList) { String[] files = item.Split(' '); String file = files[files.Count() - 1]; AvaliableVersions.Add(file); listBox1.Items.Add(file); } } catch (Exception) { ///do not show message box here .... return; } finally { ftp.Disconnect(); } if (oldLast != AvaliableVersions[AvaliableVersions.Count - 1]) { string title = "PloobsUpdates"; string text = "There is a new Version of PloobsEngine Avaliable"; //show balloon with built-in icon this.MyNotifyIcon.ShowBalloonTip(title, text, BalloonIcon.Info); this.MyNotifyIcon.TrayBalloonTipClicked += new RoutedEventHandler(MyNotifyIcon_TrayBalloonTipClicked); } if (AvaliableVersions.Count == 0) { button1.IsEnabled = false; button2.IsEnabled = false; } } catch(Exception) { ///nothing } }
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; }