Ejemplo n.º 1
0
        private void FormMain_Shown(object sender, EventArgs e)
        {
            // globalny obiekt licencji aplikacji
            Global.License = LicenseHandler.ReadLicense(out LicenseStatus licStatus, out string validationMsg);

            switch (licStatus)
            {
            case LicenseStatus.Undefined:           //  jeżeli nie ma plik z licencją

                using (FormLicense frm = new FormLicense())
                {
                    frm.ShowDialog(this);
                }

                Application.Exit();

                break;

            case LicenseStatus.Valid:           //  jeżeli licencja jest poprawna

                // wpisz nazwę właściciela licencji do tytułu okna
                Text = $@"ScanHelper 2.0 - {Global.License.LicenseOwner.Split('\n').First()}";

                // wpisz rodzaj licencji do pola statusu
                statusStripLicense.Text = $@"Licencja typu: '{Global.License.Type}', ważna do: {Global.License.LicenseEnd}";

                break;

            default:            //  jeżeli licencja jest niepoprawna

                MessageBox.Show(validationMsg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();

                break;
            }
        }
Ejemplo n.º 2
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            string        msg    = string.Empty;
            LicenseStatus status = LicenseStatus.Undefined;

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                assembly.GetManifestResourceStream("ScanHelper.LicenseVerify.cer")?.CopyTo(memoryStream);

                _certPublicKeyData = memoryStream.ToArray();
            }

            if (File.Exists("license.lic"))
            {
                _license = (MyLicense)LicenseHandler.ReadLicense(typeof(MyLicense), File.ReadAllText("license.lic"), _certPublicKeyData, out status, out msg);
            }
            else
            {
                FormLicense frm = new FormLicense();
                frm.ShowDialog(this);
            }

            switch (status)
            {
            case LicenseStatus.Undefined:

                MessageBox.Show(@"By używać tej aplikacji musisz posiadać aktualną licencję", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                break;

            case LicenseStatus.Invalid:
            case LicenseStatus.Cracked:
            case LicenseStatus.Expired:

                MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                break;

            case LicenseStatus.Valid:

                string licenseOwner = _license?.LicenseOwner;

                statusStripLicense.Text = $"Licencja: {_license?.Type}. Licencja ważna do: {_license?.LicenseEnd}";

                Text = Application.ProductName + ' ' + Application.ProductVersion + @" - " + licenseOwner?.Split('\n').First();

                Location = new Point(Convert.ToInt32(Functions.IniParser.ReadIni("FormMain", "X")), Convert.ToInt32(Functions.IniParser.ReadIni("FormMain", "Y")));

                using (FileStream stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"ScanHelper.jpg", FileMode.Open, FileAccess.Read))
                {
                    _activeImage = Image.FromStream(stream);
                }

                pictureBoxView.Image    = ImageZoom(_activeImage, 0);
                pictureBoxView.Left     = 0;
                pictureBoxView.Top      = 0;
                pictureBoxView.Location = new Point((panelView.ClientSize.Width / 2) - (pictureBoxView.Image.Width / 2), (panelView.ClientSize.Height / 2) - (pictureBoxView.Height / 2));

                trackBarZoom.Value = 0;

                _zoom = 0;


                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }