Exemplo n.º 1
0
 public void DownloadRemoteFile(string url, string destination)
 {
     try
     {
         using (WebClient wc = new WebClientWithTimeout())
         {
             wc.Proxy = null;
             wc.DownloadFileCompleted += (s, e) =>
             {
                 Console.Write("100%");
                 Console.WriteLine();
                 Utils.Log($"Downloaded {url} to {destination}");
                 counter = 0;
             };
             wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
             Stream stream = wc.OpenRead(url);
             // Size manipulations
             string size;
             long   bytes = Convert.ToInt64(wc.ResponseHeaders["Content-Length"]);
             double mb    = Math.Round((bytes / 1024f) / 1024f, 2);
             if (mb <= 0.00f)
             {
                 size = Math.Round((bytes / 1024f), 2).ToString() + "KB";
             }
             else
             {
                 size = mb.ToString() + "MB";
             }
             stream.Close();
             Utils.Log($"Downloading {Path.GetFileName(destination)}: {size}...");
             wc.DownloadFileTaskAsync(new Uri(url), destination).Wait();
             wc.Dispose();
         }
     }
     catch (WebException we)
     {
         Utils.Log(we.Message, Utils.MsgType.error);
     }
 }
Exemplo n.º 2
0
Arquivo: Form11.cs Projeto: ging/AARS
        private void check_updates()
        {
            String current_ver = btn_update.Text;

            btn_update.Refresh();

            new System.Threading.Thread(() =>
            {
                System.Threading.Thread.CurrentThread.IsBackground = true;

                try
                {
                    WebClient client         = new WebClientWithTimeout();
                    String lang_check_update = "";
                    if (language == "es")
                    {
                        lang_check_update = "https://raw.githubusercontent.com/ging/AARS/main/current_plato_saga_es.txt";
                    }
                    if (language == "en")
                    {
                        lang_check_update = "https://raw.githubusercontent.com/ging/AARS/main/current_plato_saga_en.txt";
                    }
                    Stream stream       = client.OpenRead(lang_check_update);
                    StreamReader reader = new StreamReader(stream);
                    String content      = reader.ReadToEnd();
                    content1            = content;
                }
                catch (Exception excpt)
                {
                    try
                    {
                        this.Invoke(new MethodInvoker(delegate
                        {
                            this.Enabled = false;
                        }));
                    } catch { }

                    if (language == "es")
                    {
                        MessageBox.Show("Hubo un error al conectar al servidor de actualizaciones." + Environment.NewLine + Environment.NewLine + excpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (language == "en")
                    {
                        MessageBox.Show("An error occurred conecting to update service." + Environment.NewLine + Environment.NewLine + excpt.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    btn_update.Invoke(new MethodInvoker(delegate
                    {
                        btn_update.Text = current_ver;
                    }));
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.Enabled = true;
                        this.Activate();
                    }));
                    return;
                }

                try
                {
                    if (Convert.ToInt16(content1.Replace(".", String.Empty).Substring(0, 3)) > Convert.ToInt16(Application.ProductVersion.Replace(".", String.Empty)))
                    {
                        DialogResult a = DialogResult.None;

                        this.Invoke(new MethodInvoker(delegate
                        {
                            this.Enabled = false;
                        }));

                        if (language == "es")
                        {
                            a = MessageBox.Show("Una nueva versión está disponible: " + content1.Substring(0, 5) + Environment.NewLine + content1.Substring(6, content1.Length - 6) + Environment.NewLine + Environment.NewLine + "¿Desea descargarla?", "Nueva versión disponible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        }
                        if (language == "en")
                        {
                            a = MessageBox.Show("A new version was found : " + content1.Substring(0, 5) + Environment.NewLine + content1.Substring(6, content1.Length - 6) + Environment.NewLine + Environment.NewLine + "Do you want to download it?", "New version found", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        }

                        if (a == DialogResult.Yes)
                        {
                            update_now = true;
                            this.Invoke(new MethodInvoker(delegate
                            {
                                this.Enabled = true;
                                this.Close();
                            }));
                        }
                        else
                        {
                            this.Invoke(new MethodInvoker(delegate
                            {
                                this.Enabled = true;
                            }));
                        }
                    }
                    else
                    {
                        if (language == "es")
                        {
                            MessageBox.Show("Está usando la versión más reciente.");
                        }
                        if (language == "en")
                        {
                            MessageBox.Show("You are using the latest version.");
                        }
                    }
                }
                catch {
                    if (language == "es")
                    {
                        MessageBox.Show("Ocurrió un error al buscar actualizaciones.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (language == "en")
                    {
                        MessageBox.Show("An error ocurred while obtaining updates.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    this.Invoke(new MethodInvoker(delegate
                    {
                        this.Enabled = true;
                        this.Activate();
                    }));
                }
            }).Start();
        }
Exemplo n.º 3
0
        private void trySettings()
        {
            if (!m_SettingsDone && m_SettingsAggregator != null)
            {
                m_SettingsDone = true;

                m_Logger.Log(@"settings applied to Shell Window", Category.Debug, Priority.Medium);



                bool clickOnce = ApplicationDeployment.IsNetworkDeployed;
                if (!clickOnce && Settings.Default.EnableVersionChecking)
                {
                    string thisVersion = ApplicationConstants.GetVersion();

                    string url       = "http://data.daisy.org/projects/tobi/install/net-4/Tobi_NET4.application";
                    var    webClient = new WebClientWithTimeout {
                        UseDefaultCredentials = true, Timeout = 5 * 1000
                    };                                                                                             // 5 seconds
                    StreamReader streamReader = null;
                    try
                    {
                        streamReader = new StreamReader(webClient.OpenRead(url), Encoding.UTF8);
                        string xmlStr = streamReader.ReadToEnd();
                        //m_Logger.Log(str, Category.Info, Priority.High);

                        if (!string.IsNullOrEmpty(xmlStr))
                        {
                            int i = xmlStr.IndexOf(" version=", 20);
                            if (i > 0)
                            {
                                int k = i + 10;
                                int j = xmlStr.IndexOf("\"", k);
                                if (j > 0 && j > i)
                                {
                                    string latestVersion = xmlStr.Substring(k, j - k);

                                    int lastestVersionNumber = parseVersionNumber(latestVersion);
                                    int thisVersionNumber    = parseVersionNumber(thisVersion);

                                    if (lastestVersionNumber > thisVersionNumber &&
                                        Settings.Default.UpdateRejected != latestVersion)
                                    {
                                        bool update = askUserAppUpdate(thisVersion, latestVersion);
                                        if (update)
                                        {
                                            ExecuteShellProcess("http://daisy.org/tobi");
                                        }
                                        else
                                        {
                                            Settings.Default.UpdateRejected = latestVersion;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        m_Logger.Log(@"Problem checking Tobi latest version? " + ex.Message, Category.Exception, Priority.High);
                        //ExceptionHandler.LogException(ex);
#if DEBUG
                        Debugger.Break();
#endif // DEBUG
                    }
                    finally
                    {
                        if (streamReader != null)
                        {
                            streamReader.Close();
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void usageReport(IShellView shellView)
        {
            string uid = "";

            if (!Tobi.Settings.Default.EnableAnonymousUsageReport_UserConfirm)
            {
                Tobi.Settings.Default.EnableAnonymousUsageReport             = false; // reset
                Tobi.Settings.Default.EnableAnonymousUsageReport_UserConfirm = true;

                string defaultSettingValue = (string)Settings.Default.Properties["UserId"].DefaultValue;
                string settingValue        = Tobi.Settings.Default.UserId;
                if (!String.IsNullOrEmpty(settingValue))
                {
                    settingValue = settingValue.Trim();
                    if (settingValue.Equals(defaultSettingValue, StringComparison.OrdinalIgnoreCase))
                    {
                        settingValue = ""; // can be null also
                    }
                }

                // NEED USER CONFIRM (explicit consent, opt-in)
                if (true) // String.IsNullOrEmpty(settingValue) || settingValue.Equals(defaultSettingValue))
                {
                    // Settings.Default.UserId_DoNotAskAgain ? "" :
                    String userid = askUserId(shellView, Tobi_Lang.UserId_title, Tobi_Lang.UserId_message, Tobi_Lang.UserId_details, Tobi_Lang.UserId_consent, settingValue);
                    if (!String.IsNullOrEmpty(userid))
                    {
                        userid = userid.Trim();
                    }
                    if (String.IsNullOrEmpty(userid))
                    {
                        Tobi.Settings.Default.UserId = defaultSettingValue;
                        uid = "";
                    }
                    else
                    {
                        Tobi.Settings.Default.UserId = userid;
                        uid = userid;
                        if (userid.Equals(defaultSettingValue, StringComparison.OrdinalIgnoreCase))
                        {
                            uid = "";
                        }
                    }
                }
            }

            //http://blogs.msdn.com/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx

            string url = ApplicationConstants.TOBI_ANON_USAGE_URI;

            url += "?version=" + Uri.EscapeDataString(ApplicationConstants.APP_VERSION);
            url += "&clickonce=" + (ApplicationDeployment.IsNetworkDeployed ? "true" :
                                    (Debugger.IsAttached ? "VS" : "false"));
            url += "&datetime=" + Uri.EscapeDataString(DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss_K", CultureInfo.InvariantCulture));
            url += "&datetimeutc=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd_HH:mm:ss_K", CultureInfo.InvariantCulture));
            url += "&os=" + Uri.EscapeDataString(ApplicationConstants.OS_INFORMATION);
            url += "&lang=" + Thread.CurrentThread.CurrentUICulture;
            url += "&userid=" + Uri.EscapeDataString(uid);

            // THIS BREAKS PRIVACY, so we don't
            //string ipAddress = "";
            //IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
            //IPAddress[] ipAddresses = ipHostEntry.AddressList;
            //for (int i = 0; i < ipAddresses.Length; i++)
            //{
            //    if (ipAddresses[i].AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
            //    {
            //        if (!IPAddress.IsLoopback(ipAddresses[i]))
            //        {
            //            ipAddress += string.Format("_{0}", ipAddresses[i]);
            //        }
            //    }
            //    else
            //    {
            //        ipAddress += string.Format("__{0}", ipAddresses[i]);
            //    }
            //}
            //if (!string.IsNullOrEmpty(ipAddress))
            //{
            //    url += "&localip=" + Uri.EscapeDataString(ipAddress);
            //}

            if (Settings.Default.EnableAnonymousUsageReport && Settings.Default.EnableAnonymousUsageReport_UserConfirm)
            {
                var webClient = new WebClientWithTimeout {
                    UseDefaultCredentials = true, Timeout = 5 * 1000
                };                                                                                             // 5 seconds
                StreamReader streamReader = null;
                try
                {
                    streamReader = new StreamReader(webClient.OpenRead(url), Encoding.UTF8);
                    string str = streamReader.ReadToEnd();
                    m_Logger.Log(str, Category.Info, Priority.High);
                }
                catch (Exception ex)
                {
                    m_Logger.Log(@"Can't query Tobi anonymous usage logger !", Category.Exception, Priority.High);
                    ExceptionHandler.LogException(ex);
                    //#if DEBUG
                    //                Debugger.Break();
                    //#endif // DEBUG
                }
                finally
                {
                    if (streamReader != null)
                    {
                        streamReader.Close();
                    }
                }
            }
            else
            {
                m_Logger.Log(@"Tobi anonymous usage logger has been DISABLED by user.", Category.Warn, Priority.High);
            }
        }