Ejemplo n.º 1
0
        protected virtual void StartDLJob(FileDownloadInfo info)
        {
            string jobURL = PopDownloadFile();

            if (jobURL == string.Empty)
            {
                lock (DownloadPool)
                    DownloadPool.Remove(info);

                info.Connection.Dispose();
                info = null;
            }
            else
            {
                info.Args.DownloadFileName = jobURL;
                info.Args.Progress         = 0;
                lock (RootDir)
                    info.LocalFile = new FileInfo(Path.Combine(RootDir.FullName, jobURL));
                info.Args.LocalFileName = info.LocalFile.FullName;

                FileDownloadStarted?.Invoke(this, info.Args);

                string uriString = string.Empty;
                lock (UpdateServerURL)
                    uriString = UpdateServerURL + "dl.aspx";

                NameValueCollection data = new NameValueCollection();

                string cryptoFileName = HorizonCrypto.EncryptString(jobURL, CryptoSecret);

                data.Add("Timestamp", HorizonCrypto.TimeStamp());
                data.Add("Data", cryptoFileName);

                info.Connection.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                info.Connection.UploadValuesAsync(new Uri(uriString), "POST", data, info);
            }
        }
Ejemplo n.º 2
0
        private void OK_Click(object sender, EventArgs e)
        {
            if (ProdcutCode.Text == string.Empty)
            {
                DialogResult = DialogResult.Cancel;
            }
            else
            {
                if (!CheckNetwork())
                {
                    MessageBox.Show(this, "An active Internet connection is required for activation", "No Network Connection", MessageBoxButtons.OK);
                    DialogResult = DialogResult.None;
                    return;
                }

                string licenseKey = ProdcutCode.Text.Replace("-", "");

                using (WebClient webClient = new WebClient())
                {
                    string address = "http://updates.starshiphorizons.com/comm/license.aspx";
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    NameValueCollection data = new NameValueCollection();

                    data.Add("Timestamp", HorizonCrypto.TimeStamp());
                    data.Add("Login", "-");
                    data.Add("Key", HorizonCrypto.EncryptString(licenseKey, UpdateManager.CryptoSecret));

                    // show update progress

                    LicenseUpdateProgress p = new LicenseUpdateProgress();
                    p.Show(this);

                    var responce = webClient.UploadValues(address, data);

                    p.Close();

                    if (responce == null || responce.Length == 0)
                    {
                        MessageBox.Show(this, "Validation failed, unable to contact server", "Validation Failed", MessageBoxButtons.OK);
                        DialogResult = DialogResult.None;
                        return;
                    }

                    string results = HorizonCrypto.DecryptString(Encoding.UTF8.GetString(responce), UpdateManager.CryptoSecret);

                    foreach (var part in results.Split("\r\n".ToCharArray()))
                    {
                        if (part.ToUpperInvariant() == "VALID")
                        {
                            LicenseCode  = licenseKey;
                            DialogResult = DialogResult.OK;
                            return;
                        }
                    }

                    MessageBox.Show(this, "Validation failed, unable to contact server", "Validation Failed", MessageBoxButtons.OK);
                    DialogResult = DialogResult.None;
                }
            }
        }
Ejemplo n.º 3
0
        private bool GetRemoteFileList()
        {
            UpdateServerConnectStarted.Invoke(this, EventArgs.Empty);

            NameValueCollection data = new NameValueCollection();
            string encryptedMagic    = HorizonCrypto.EncryptString("", CryptoSecret);

            data.Add("Timestamp", HorizonCrypto.TimeStamp());
            data.Add("TimeDiff", LicenseKeyGUID.ToString());
            data.Add("MacName", Environment.MachineName);
            data.Add("Launcher", VersionToReport);
            data.Add("Data", encryptedMagic);

            using (WebClient webClient = new WebClient())
            {
                try
                {
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    byte[] responce = webClient.UploadValues(UpdateServerURL + "updates.aspx", data);
                    if (responce == null || responce.Length == 0)
                    {
                        SetLastError("GetRemoteFileList failed, server returned no data");
                        UpdateServerConnectFailed?.Invoke(this, EventArgs.Empty);
                        return(false);
                    }
                    string responceText = HorizonCrypto.DecryptString(Encoding.UTF8.GetString(responce), CryptoSecret);

                    foreach (var line in responceText.Split("\r\n".ToCharArray()))
                    {
                        if (line == string.Empty)
                        {
                            continue;
                        }

                        string[] parts = line.Split(":".ToCharArray(), 2);

                        if (parts.Length > 2 || parts[0].ToUpperInvariant() == "TIME")
                        {
                            continue;
                        }

                        string urlPath = parts[1];
                        if (LocalFileMap.ContainsKey(urlPath.ToLowerInvariant()))
                        {
                            continue;
                        }

                        FilesToDownload.Add(urlPath);
                    }

                    UpdateServerConnectCompleted.Invoke(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    SetLastError("GetRemoteFileList failed " + ex.ToString());
                    UpdateServerConnectFailed?.Invoke(this, EventArgs.Empty);
                    return(false);
                }
            }

            return(true);
        }