NetSeal_Helper.NetSeal.LicenseManager.LicenseReader.ReadLocalLicenseV2 C# (CSharp) Method

ReadLocalLicenseV2() private method

Reads a netseal license file from local path
private ReadLocalLicenseV2 ( string netsealId ) : NetSeal_Helper.NetSeal.LicenseManager.LicenseFile
netsealId string NetSeal ID
return NetSeal_Helper.NetSeal.LicenseManager.LicenseFile
        internal LicenseFile ReadLocalLicenseV2(string netsealId)
        {
            var licensePath = Path.Combine(LocalPathV2, $"login_{netsealId}.bin");

            if (!File.Exists(licensePath))
                licensePath = Path.Combine(LocalPath, $"login_{netsealId}.bin");

            var licenseFile = ReadLicenseFromV2(licensePath, netsealId);

            return licenseFile;
        }

Usage Example

Beispiel #1
0
        private void LoadLocalLicensesV2()
        {
            this.ltvLicenses.Items.Clear();

            Logger.LogInformation("Loading local license(s)");

            var licenseReader = new LicenseReader();
            if (!Directory.Exists(licenseReader.LocalPath))
            {
                Logger.LogWarning("No license(s) found");
                return;
            }

            var regex = new Regex(@"^login_([A-F0-9]{8})\.bin$");

            var files = Directory.GetFiles(licenseReader.LocalPath).Where((x) =>
            {
                return regex.IsMatch(Path.GetFileName(x));
            }).ToArray<string>();

            if (Directory.Exists(licenseReader.LocalPathV2))
            {
                var files2 = Directory.GetFiles(licenseReader.LocalPathV2).Where((x) =>
                {
                    return regex.IsMatch(Path.GetFileName(x));
                }).ToArray<string>();

                Array.Resize(ref files, files.Length + files2.Length);
                Array.Copy(files2, 0, files, files.Length - 1, files2.Length);
            }

            var counter = 0;

            foreach (var file in files)
            {
                try
                {
                    var fileName = Path.GetFileName(file);
                    var id = regex.Match(fileName).Groups[1].Value;
                    var programName = IdsDataBase.IDsDataBaseV2[id];

                    if (!string.IsNullOrEmpty(id))
                    {
                        var licenseFile = licenseReader.ReadLocalLicenseV2(id);
                        //Store the license
                        Licenses.Add(licenseFile);

                        programName = !string.IsNullOrEmpty(programName) ? programName : this.txtUnknownProgramName.Text;

                        ltvLicenses.Items.Add(id).SubItems.AddRange(new string[]
                        {
                            programName,
                            licenseFile.GUID,
                            licenseFile.Remember.ToString(),
                            licenseFile.Username,
                            licenseFile.Sha1Password,
                        });
                        counter++;
                    }
                }
                catch
                {
                    continue;
                }
            }
            Logger.LogInformation("Loaded " + counter + " license(s)");
        }