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;
            }
   
        }
        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; }));            
        }
Example #3
0
        void UploadFiles()
        {
            FTP ftplib = new FTP();

            try
            {
                // there are server, user and password properties
                // that can be set within the ftplib object as well
                // those properties are actually set when
                // you call the Connect(server, user, pass) function
                String host = Settings.Default.Host;
                ftplib.Connect("ftp." + host,
                               Settings.Default.Username,
                               Settings.Default.Password);

                InputBoxDialog inputBox = new InputBoxDialog();
                inputBox.FormPrompt = "FTP Directory";
                inputBox.FormCaption = "FTP Directory";
                inputBox.DefaultValue = Settings.Default.DefaultDir;
                inputBox.ShowDialog();
                String directory = inputBox.InputResponse;
                inputBox.Close();

                if (directory == "" || directory == null)
                    Application.Exit();


                // Populate clipboard
                String clipboard = "";
                foreach (String filename in resizedPictureFiles)
                {
                    FileInfo fileInfo = new FileInfo(filename);
                    clipboard += "http://" + host + "/" + directory + fileInfo.Name + "\r\n";
                }
                Clipboard.SetDataObject(clipboard, true);

                try
                {
                    ftplib.ChangeDir(directory);
                }
                catch (Exception)
                {
                    // Directory probably didn't exist. Create it.
                    ftplib.MakeDir(directory,true);
                }


                // open the file with resume support if it already exists, the last 
                // peram should be false for no resume
                foreach (String filename in resizedPictureFiles)
                {
                    FileInfo fileInfo = new FileInfo(filename);
                    ftplib.OpenUpload(fileInfo.FullName, fileInfo.Name);
                    while (ftplib.DoUpload() > 0)
                    {
                        //perc = (int)((ftplib.BytesTotal * 100) / ftplib.FileSize);
                        //Console.Write("\rDownloading: {0}/{1} {2}%",
                        //  ftplib.BytesTotal, ftplib.FileSize, perc);
                        //Console.Out.Flush();
                    }
                    //Console.WriteLine("");
                }

                MessageBox.Show("Upload Complete!");

                Application.Exit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <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;
        }