Ejemplo n.º 1
0
 internal static bool CheckForLicense(string product, string path, ref string productCode)
 {
     LastError = string.Empty;
     try
     {
         if (File.Exists(path))
         {
             string str1     = HorizonCrypto.DecryptString(Encoding.Default.GetString(File.ReadAllBytes(path)), "a1783!b1971|c2005");
             char[] chArray1 = new char[1] {
                 '|'
             };
             foreach (string str2 in str1.Split(chArray1))
             {
                 char[] chArray2 = new char[1] {
                     ','
                 };
                 string[] strArray = str2.Split(chArray2);
                 if (strArray.Length > 1)
                 {
                     if (strArray[0] == "MAC" && strArray[1] != Environment.MachineName)
                     {
                         LastError = "This license was validated on another machine.";
                         return(false);
                     }
                     if (strArray[0] == "Path" && strArray[1] != path)
                     {
                         LastError = "This license file has been copied or moved.";
                         return(false);
                     }
                     if (strArray[0] == product)
                     {
                         productCode = strArray[1];
                         Guid guid = new Guid(strArray[1]);
                         return(true);
                     }
                 }
             }
         }
         else
         {
             LastError = "CheckForLicense: License File Missing";
             return(false);
         }
     }
     catch (Exception ex)
     {
         LastError = "CheckForLicense: " + ex.Message;
         return(false);
     }
     return(false);
 }
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);
        }