예제 #1
0
        private static bool InternetConnetction()
        {
            InternetConnectionState_e cs = new InternetConnectionState_e();

            InternetGetConnectedState(ref cs, 0);

            bool[] IC = new bool[]
            {
                (cs & InternetConnectionState_e.INTERNET_CONNECTION_LAN) == InternetConnectionState_e.INTERNET_CONNECTION_LAN,
                (cs & InternetConnectionState_e.INTERNET_CONNECTION_MODEM) == InternetConnectionState_e.INTERNET_CONNECTION_MODEM,
                (cs & InternetConnectionState_e.INTERNET_CONNECTION_PROXY) == InternetConnectionState_e.INTERNET_CONNECTION_PROXY
            };
            IPStatus?status = null;

            if (IC[0] || IC[1] || IC[2])
            {
                Ping ping = new Ping();
                for (byte i = 0; i < 4; i++)
                {
                    try { status = ping.Send("8.8.8.8").Status; }
                    catch { }
                    if (status == IPStatus.Success)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        public static bool IsInternet()
        {
            InternetConnectionState_e flags = 0;
            bool isConnected = InternetGetConnectedState(ref flags, 0);

            return(flags != InternetConnectionState_e.INTERNET_CONNECTION_OFFLINE);
        }
        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 extern static bool InternetGetConnectedState(ref InternetConnectionState_e lpdwFlags, int dwReserved);
예제 #5
0
        public static bool IsConnectedToInternet()
        {
            InternetConnectionState_e flags = 0;

            return(InternetGetConnectedState(ref flags, 0));
        }
예제 #6
0
 private extern static bool InternetGetConnectedState(ref InternetConnectionState_e lpdwFlags, int dwReserved);
        /// <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
            }
        }