From d5c16168e8b6b25a308e51a0dd01537d8f897b06 Mon Sep 17 00:00:00 2001 From: GeraltSnow Date: Mon, 11 Feb 2019 02:26:00 +0800 Subject: [PATCH] Ver 1.4 --- .../LicDataDecoder/Form1.Designer.cs | 2 +- LicDataDecoder/LicDataDecoder/Form1.cs | 147 +++++++++++------- .../LicDataDecoder/Form2.Designer.cs | 18 +-- 3 files changed, 98 insertions(+), 69 deletions(-) diff --git a/LicDataDecoder/LicDataDecoder/Form1.Designer.cs b/LicDataDecoder/LicDataDecoder/Form1.Designer.cs index 1933549..7fdb115 100644 --- a/LicDataDecoder/LicDataDecoder/Form1.Designer.cs +++ b/LicDataDecoder/LicDataDecoder/Form1.Designer.cs @@ -151,7 +151,7 @@ this.MainMenuStrip = this.menuStrip1; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "LicData Decoder 1.3"; + this.Text = "LicData Decoder 1.4"; this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); diff --git a/LicDataDecoder/LicDataDecoder/Form1.cs b/LicDataDecoder/LicDataDecoder/Form1.cs index 3659a26..8a8b50d 100644 --- a/LicDataDecoder/LicDataDecoder/Form1.cs +++ b/LicDataDecoder/LicDataDecoder/Form1.cs @@ -11,10 +11,9 @@ namespace LicDataDecoder { public partial class Form1 : Form { - //Наличие необходимых компонентов в системе - bool JRE = false; - bool RING = false; - bool LICENSE = false; + //Версии необходимых компонентов в системе + string JRE = ""; + string RING = ""; string path; //путь к файлу string fileName; //имя файла @@ -25,8 +24,8 @@ namespace LicDataDecoder InitializeComponent(); this.Width = 500; - button1.Enabled = true; - //checkAbilityAcync(); + + checkAbilityAcync(); } private async void button1_Click(object sender, EventArgs e) @@ -34,6 +33,8 @@ namespace LicDataDecoder if (openFileDialog1.ShowDialog() == DialogResult.Cancel) return; textBox1.Text = openFileDialog1.FileName; textBox2.Text = "Подождите..."; + textBox3.Text = "Параметры компьютера, получившего лицензию. Не все из них являются ключевыми."; + textBox4.Text = "Здесь будет выведена информация о параметрах текущего компьютера"; try { @@ -54,6 +55,7 @@ namespace LicDataDecoder catch { textBox2.Text = "Выбранный файл не является лицензией или поврежден."; + File.Delete(folderName + "\\" + fileName); } } @@ -62,6 +64,14 @@ namespace LicDataDecoder path = textBox1.Text; fileName = path.Substring(path.LastIndexOf(@"\") + 1, path.Length - path.LastIndexOf('\\') - 1); folderName = path.Substring(0, path.Length - fileName.Length - 1); + + string tempFolder = System.IO.Path.GetTempPath() + "LicDataDecoder"; + Directory.CreateDirectory(tempFolder); + folderName = tempFolder; + File.Copy(path, tempFolder+"\\"+fileName, true); + + //У текущей версии Ring есть баг - если в папке с указанной лицензией находится сломанная лицензия, то она зачем-то выводит пытается просканировать и её. + //Во избежание этого реализовал копирование текущего файла лицензии во временный каталог с последующим удалением. } private string[] decodeLicenceFile() @@ -104,10 +114,10 @@ namespace LicDataDecoder string HWConfig = debugMessages[1].Substring(0, debugMessages[1].IndexOf("\r\n\r\n")); results[2] = "Параметры этого компьютера, которые могли бы записаться в лицензию" + System.Environment.NewLine + System.Environment.NewLine + HWConfig; - - } + File.Delete(folderName + "\\" + fileName); + return results; @@ -131,7 +141,7 @@ namespace LicDataDecoder debugInfo = reader.ReadToEnd(); return debugInfo; - } + } //получить полную конфигурацию компьютера private string getLicName() { @@ -244,94 +254,109 @@ namespace LicDataDecoder private async void checkAbilityAcync() { - textBox2.Text += Environment.NewLine + Environment.NewLine + "Выполняется проверка возможности декодирования лицензий..."; + bool READY = true; - JRE = await Task.Factory.StartNew( + textBox2.Text += Environment.NewLine + Environment.NewLine + "Выполняется проверка возможности декодирования лицензий..." + Environment.NewLine + Environment.NewLine; + + JRE = await Task.Factory.StartNew( () => checkJRE(), TaskCreationOptions.LongRunning); - RING = await Task.Factory.StartNew( + RING = await Task.Factory.StartNew( () => checkRING(), TaskCreationOptions.LongRunning); - LICENSE = await Task.Factory.StartNew( - () => checkLICENSE(), - TaskCreationOptions.LongRunning); + switch (JRE) + { + case "0": + textBox2.Text += "В системе отсутствует JRE. Для работы необходима версия JRE не ниже 161. Скачать: https://www.oracle.com/technetwork/java/javase/downloads/index.html"; + READY &= false; + break; + case "error": + textBox2.Text += "Неозможно определить версию JRE!"; + READY &= false; + break; + default: + textBox2.Text += "Версия JRE: " + JRE; + if (Int32.Parse(JRE.Substring(6, 3)) < 161) + { + textBox2.Text += Environment.NewLine + "Для работы необходима версия JRE не ниже 161. Скачать: https://www.oracle.com/technetwork/java/javase/downloads/index.html"; + READY &= false; + } + break; + } - if (!JRE) textBox2.Text += Environment.NewLine + Environment.NewLine + "В системе отсутствует JRE. \nСкачать: https://www.oracle.com/technetwork/java/javase/downloads/index.html"; - if (!RING) textBox2.Text += Environment.NewLine + Environment.NewLine + "В системе отсутствует утилита RING. Утилита поставляется в комплекте с дистрибутивом технологической платформы в папке \"license-tools\". Запустите файл 1ce-installer.cmd с правами администратора для установки."; - if (!LICENSE) textBox2.Text += Environment.NewLine + Environment.NewLine + "В системе отсутствует модуль LICENSE. Модуль поставляется в комплекте с дистрибутивом технологической платформы в папке \"license-tools\". Запустите файл 1ce-installer.cmd с правами администратора для установки."; + textBox2.Text += Environment.NewLine + Environment.NewLine; - if (JRE & RING & LICENSE) + switch (RING) { - textBox2.Text += Environment.NewLine + "Программа готова к работе!"; + case "0": + textBox2.Text += "В системе отсутствует RING. Для работы необходима версия RING не ниже 0.11.5-3. Утилита поставляется в комплекте с дистрибутивом технологической платформы 8.3.14.1565 в папке \"license-tools\". Запустите файл 1ce-installer.cmd с правами администратора для установки."; + READY &= false; + break; + case "error": + textBox2.Text += "Неозможно определить версию RING!"; + READY &= false; + break; + default: + textBox2.Text += "Версия RING: " + RING; + if (Int32.Parse(RING.Substring(5, 1)) < 5 & Int32.Parse(RING.Substring(2, 2)) < 12) + { + textBox2.Text += Environment.NewLine + "Для работы необходима версия RING не ниже 0.11.5-3. Утилита поставляется в комплекте с дистрибутивом технологической платформы 8.3.14.1565 в папке \"license-tools\". Удалите старые версии Ring и License и запустите файл 1ce-installer.cmd с правами администратора для установки."; + READY &= false; + } + break; + } + + if (READY) + { + textBox2.Text += Environment.NewLine + Environment.NewLine + "Программа готова к работе!"; button1.Enabled = true; } } - private bool checkJRE() - { - - try - { - Process process = new Process(); - process.StartInfo.FileName = "java"; - process.StartInfo.RedirectStandardError = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.Start(); - return true; - - //StreamReader reader = process.StandardError; - //string output = reader.ReadToEnd(); - //return output == ""; - - // java дублирует информацию из стандартного потока вывода в стандартный поток ошибок, поэтому он никогда не будет пустым. - - } - catch (Exception e) - { - return false; - } - - } - - private bool checkRING() + private string checkJRE() { try { Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; - process.StartInfo.Arguments = "/C ring"; + process.StartInfo.Arguments = "/C java -version"; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); - + StreamReader reader = process.StandardError; string output = reader.ReadToEnd(); + if (!output.Contains("\"java\"")) + { + return output.Substring(output.IndexOf("\"") + 1, 9); + } + else return "0"; - return output == ""; + //Передаю огненный привет разработчикам java, которые посчитали хорошей идеей выводить информацию + //в стандартный поток ошибок вместо стандартного потока вывода } catch (Exception e) { - return false; + return "error"; } } - private bool checkLICENSE() + private string checkRING() { try { - if (!RING) return false; + if (checkJRE()=="0") return "error"; Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; - process.StartInfo.Arguments = "/C ring license"; + process.StartInfo.Arguments = "/C ring --version"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; @@ -339,15 +364,19 @@ namespace LicDataDecoder StreamReader reader = process.StandardOutput; string output = reader.ReadToEnd(); - - return (!output.Contains("ERROR")); + if (!output.Contains("\"ring\"") && output!="") + { + return output.Replace("\r\n", ""); + } + else return "0"; } catch (Exception e) { - return false; + return "error"; } - } + + } private void checkBox1_CheckedChanged(object sender, EventArgs e) { diff --git a/LicDataDecoder/LicDataDecoder/Form2.Designer.cs b/LicDataDecoder/LicDataDecoder/Form2.Designer.cs index 5e30920..c7540e9 100644 --- a/LicDataDecoder/LicDataDecoder/Form2.Designer.cs +++ b/LicDataDecoder/LicDataDecoder/Form2.Designer.cs @@ -66,7 +66,7 @@ this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(21))))); - this.label3.Location = new System.Drawing.Point(197, 0); + this.label3.Location = new System.Drawing.Point(238, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(133, 30); this.label3.TabIndex = 2; @@ -77,30 +77,30 @@ this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(21))))); - this.label4.Location = new System.Drawing.Point(197, 30); + this.label4.Location = new System.Drawing.Point(238, 30); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(177, 30); + this.label4.Size = new System.Drawing.Size(131, 60); this.label4.TabIndex = 3; - this.label4.Text = "JRE, Ring, License"; + this.label4.Text = "JRE 161 \r\nRing 0.11.5.1"; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Segoe UI", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.label5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(52)))), ((int)(((byte)(152)))), ((int)(((byte)(21))))); - this.label5.Location = new System.Drawing.Point(26, 167); + this.label5.Location = new System.Drawing.Point(40, 174); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(329, 30); this.label5.TabIndex = 4; - this.label5.Text = "Версия 1.3©2019 Влад Москалёв"; + this.label5.Text = "Версия 1.4©2019 Влад Москалёв"; this.label5.Click += new System.EventHandler(this.label5_Click); // // pictureBox1 // this.pictureBox1.Image = global::LicDataDecoder.Properties.Resources.LOGO; - this.pictureBox1.Location = new System.Drawing.Point(41, 73); + this.pictureBox1.Location = new System.Drawing.Point(63, 93); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(314, 78); + this.pictureBox1.Size = new System.Drawing.Size(283, 78); this.pictureBox1.TabIndex = 5; this.pictureBox1.TabStop = false; // @@ -108,7 +108,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(377, 206); + this.ClientSize = new System.Drawing.Size(407, 210); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label5); this.Controls.Add(this.label4);