private void button1_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text)) { string[] skey = textBox2.Text.Split('-'); if (skey.Length == 4 && textBox2.Text.Length == 23) { SerialKey key = new SerialKey(); key._BusinessName = textBox1.Text; key._KeyPartA = skey[0]; key._KeyPartB = skey[1]; key._KeyPartC = skey[2]; key._KeyPartD = skey[3]; key._KeyHashCode = textBox3.Text; if (ValidateSerialKey.ValidateSK(key)) { try { string LicenseFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\ExpressTaxi.lic"; string sKey = string.Format("{0}-{1}-{2}-{3}", key._KeyPartA, key._KeyPartB, key._KeyPartC, key._KeyPartD); using (System.IO.StreamWriter file = new System.IO.StreamWriter(LicenseFile)) { file.WriteLine(string.Format("BusinessName:{0}:ExpressTaxi:1.1", key._BusinessName)); file.WriteLine(string.Format("SerialKey:{0}:ExpressTaxi:1.1", sKey)); file.WriteLine(string.Format("ActivationCode:{0}:ExpressTaxi:1.1", key._KeyHashCode)); } Config.ShowInfoMessage("License successfully validated, Please restart ExpressTaxi for it to take effect."); this.Close(); } catch (Exception ex) { log.Error(ex); Config.ShowErrorMessage("Failed to save license file."); } } else { Config.ShowErrorMessage("Validation Failed. The information entered is not valid to activate ExpressTaxi."); } } else { Config.ShowErrorMessage("Invalid Serial Key Entered."); } } else { Config.ShowErrorMessage("The information entered is not valid to activate ExpressTaxi."); } }
private void RibbonWindow_Loaded(object sender, RoutedEventArgs e) { try { RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey(@"Software\Sydea Studios Antigua\ExpressTaxi"); string EulaAccepted = (string)regKeyAppRoot.GetValue("ExpessTaxiEula"); cache.LoadMappingFile(); if (string.IsNullOrEmpty(EulaAccepted) || EulaAccepted != "YES") { EULA dlg = new EULA(); dlg.ShowDialog(); if (dlg.Accepted) { regKeyAppRoot.SetValue("ExpessTaxiEula", "YES"); } else { Application.Current.Shutdown(); return; } } regKeyAppRoot.Close(); Config.LoadCfg(); if (!Config.LoadAppRegInfo()) { Config.ShowErrorMessage("Failed to load license file."); Application.Current.Shutdown(); return; } if (!Config.IsRegistered) { string edt = (string)ValidateSerialKey.HexDecode((string)cache.ExpDateTime); string Valid = (string)ValidateSerialKey.HexDecode((string)cache.ExpTag); DateTime dt = DateTime.Parse(edt); DateTime td = DateTime.Today; TimeSpan ts = td - dt; if (!string.IsNullOrEmpty(Valid)) { if (ts.TotalDays > 30) { //Config.ShowErrorMessage("Error this trial version of ExpressTaxi has expired. Please register the application."); TrialExpired texp = new TrialExpired(); texp.Owner = this; texp.ShowDialog(); Valid = (string)ValidateSerialKey.HexEncode("Expired"); cache.ExpTag = (string)Valid; cache.SaveMapping(); Application.Current.Shutdown(); return; } else if (!Valid.ToUpper().Equals(("Valid").ToUpper())) { //Config.ShowErrorMessage("Error this trial version of ExpressTaxi has expired. Please register the application."); TrialExpired texp = new TrialExpired(); texp.Owner = this; texp.ShowDialog(); Application.Current.Shutdown(); return; } else { this.Title = "Express Taxi (SP4) Trial Version"; } } else { Config.ShowInfoMessage("Installation completion is in progress, you will need to restart ExpressTaxi"); Application.Current.Shutdown(); return; } } conn = new SqlCeConnection(string.Format("Data Source = {0};", Config.sdfFile)); conn.Open(); } catch (SqlCeException ce) { Config.ShowErrorMessage("Failed to establish a connection to the active database."); log.Error(ce); Application.Current.Shutdown(); } catch (System.Exception ex) { Config.ShowErrorMessage("An unexpected Error occurred, cannot start ExpressTaxi."); log.Error(ex); Application.Current.Shutdown(); } }
internal static bool LoadAppRegInfo() { try { string LicenseFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\ExpressTaxi.lic"; string[] LicenseArray = new string[3]; using (StreamReader reader = new StreamReader(LicenseFile)) { string line1 = reader.ReadLine(); string line2 = reader.ReadLine(); string line3 = reader.ReadLine(); string[] tmpArray = line1.Split(':'); if (tmpArray[0] == "BusinessName") { LicenseArray[0] = tmpArray[1]; } else if (tmpArray[0] == "SerialKey") { LicenseArray[1] = tmpArray[1]; } else if (tmpArray[0] == "ActivationCode") { LicenseArray[2] = tmpArray[1]; } tmpArray = line2.Split(':'); if (tmpArray[0] == "BusinessName") { LicenseArray[0] = tmpArray[1]; } else if (tmpArray[0] == "SerialKey") { LicenseArray[1] = tmpArray[1]; } else if (tmpArray[0] == "ActivationCode") { LicenseArray[2] = tmpArray[1]; } tmpArray = line3.Split(':'); if (tmpArray[0] == "BusinessName") { LicenseArray[0] = tmpArray[1]; } else if (tmpArray[0] == "SerialKey") { LicenseArray[1] = tmpArray[1]; } else if (tmpArray[0] == "ActivationCode") { LicenseArray[2] = tmpArray[1]; } string[] sKey = LicenseArray[1].Split('-'); SerialKey key = new SerialKey(); key._BusinessName = LicenseArray[0]; key._KeyHashCode = LicenseArray[2]; key._KeyPartA = sKey[0]; key._KeyPartB = sKey[1]; key._KeyPartC = sKey[2]; key._KeyPartD = sKey[3]; ExpTmsRSet = ValidateSerialKey.ValidateSK(key); return(true); } } catch (Exception ex) { log.Error(ex); } return(false); }