Exemple #1
0
        private void btnCheckValue_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var fullPath = openFileDialog1.FileName;
                var text     = System.IO.File.ReadAllText(fullPath, Encoding.ASCII);

                var hash   = new HashHandler();
                var result = hash.ConvertFromHash(text);
                MessageBox.Show("Start : " + result.Start.ToString("dd.MM.yyyy") + " - End : " + result.End.ToString("dd.MM.yyyy HH.mm.ss"));
            }
        }
Exemple #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!local)
            {
                try
                {
                    var files   = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.ins");
                    var authDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Auth");
                    var hash    = new HashHandler();
                    if (files == null || files.Length == 0)
                    {
                        // Check PC name in other directory
                        var di = new DirectoryInfo(authDir);
                        if (!di.Exists)
                        {
                            MessageBox.Show("No license file was provided.");
                            ShutDownForm();
                        }
                        else
                        {
                            var dirFiles = Directory.GetFiles(authDir, "*.ins");
                            if (dirFiles == null)
                            {
                                MessageBox.Show("No license file was provided.");
                                ShutDownForm();
                            }
                            else if (dirFiles.Length == 1)
                            {
                                var text       = System.IO.File.ReadAllText(dirFiles[0], Encoding.ASCII);
                                var licensedPC = hash.Decode(text);
                                if (string.IsNullOrEmpty(licensedPC))
                                {
                                    MessageBox.Show("Empty license file.");
                                    ShutDownForm();
                                }
                                else if (!Environment.MachineName.Equals(licensedPC))
                                {
                                    MessageBox.Show("Application was licensed for other PC...WTF, bro?");
                                    ShutDownForm();
                                }
                            }
                            else if (dirFiles.Length > 1)
                            {
                                MessageBox.Show("More than 1 license file exists...WTF?");
                                ShutDownForm();
                            }
                        }
                    }
                    else if (files.Length == 1)
                    {
                        var text = System.IO.File.ReadAllText(files[0], Encoding.ASCII);

                        var result = hash.ConvertFromHash(text);
                        var now    = DateTime.Now;
                        if (result == null)
                        {
                            MessageBox.Show("Broken activation file.");
                            ShutDownForm();
                        }
                        else if (now < result.Start || now > result.End)
                        {
                            MessageBox.Show("You can activate app in this interval of dates only: " + result.Start.ToString("dd.MM.yyyy HH.mm.ss") + " - " + result.End.ToString("dd.MM.yyyy HH.mm.ss"));
                            ShutDownForm();
                        }
                        else
                        {
                            // App may be activated
                            var di = new DirectoryInfo(authDir);
                            if (!di.Exists)
                            {
                                di.Create();
                            }
                            else
                            {
                                var dirFiles = di.GetFiles();
                                for (int i = 0; i < dirFiles.Length; i++)
                                {
                                    var f = new FileInfo(dirFiles[i].FullName);
                                    f.Delete();
                                }
                            }

                            var fi           = new FileInfo(files[0]);
                            var stringToSave = hash.Encode(Environment.MachineName);
                            File.WriteAllText(Path.Combine(authDir, fi.Name), stringToSave, Encoding.ASCII);
                            File.Delete(files[0]);
                            AppShortcutToDesktop("Numerology");
                            MessageBox.Show("Successfully activated for : " + Environment.MachineName);
                        }
                    }
                    else if (files.Length > 1)
                    {
                        MessageBox.Show("There are more than 1 .ins file in start directory.");
                        ShutDownForm();
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Error, while authentication check: " + exc.Message);
                    ShutDownForm();
                }
                this.Text = "Нумерология (licensed for: " + Environment.MachineName + ").";
            }
            else
            {
                // For Yana only
                this.Text = "Нумерология (private version).";
            }

            if (!isAuthProblem)
            {
                InitUI();
                numerologyObject = InitNumerologyObject();

                var customersFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CUSTOMER_FOLDER_NAME);
                if (!Directory.Exists(customersFolderPath))
                {
                    Directory.CreateDirectory(customersFolderPath);
                }
            }
        }