private void ExecutablePathBox_TextChanged(object sender, EventArgs e) { // Если путь к файлу .exe не пустой if (!string.IsNullOrWhiteSpace(this.ExecutablePathBox.Text)) { // Выводим версию .Net файла this.VersionNet.Text = $"NetFramework: {CheckFramework.Version(this.ExecutablePathBox.Text)}"; // Если строка совпадает с N/A if (this.VersionNet.Text.Contains("N/A")) { // Выводим ошибку пользователю MusicPlay.Inizialize(Resources.Error_Build); this.ExecutablePathBox.Clear(); this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Supports only .Net binary files", Color.LightBlue, 3000); this.AddingLibrary.Enabled = false; // Блокируем кнопку добавления библиотек .dll } else { // разблокируем элементы кнопок this.AddingLibrary.Enabled = true; // Добавление библиотек .dll this.CompileBuild.Enabled = true; // Перепаковка ( слияние библиотек ) } } else { // Очищяем версию .Net Framework this.VersionNet.Text = ""; // Блокируем элементы кнопко this.AddingLibrary.Enabled = false; // Добавление библиотек .dll this.CompileBuild.Enabled = false; // Перепаковка ( слияние библиотек ) } }
private void AddingExecutable_Click(object sender, EventArgs e) { // Убираем фокус с кнопки NativeMethods.SetFocus(IntPtr.Zero); this.LogoText.Focus(); using var ofd = new OpenFileDialog { Title = "Select the file you want to add .dll libraries", Filter = "Executable file|*.exe", AutoUpgradeEnabled = true, CheckFileExists = true, Multiselect = false, RestoreDirectory = true }; if (ofd.ShowDialog() == DialogResult.OK) { this.ExecutablePathBox.Text = ofd.FileName; this.RepackLogBox.Clear(); } else { StatusMessage.Location = new Point(17, 273); ControlActive.CheckMessage(StatusMessage, "No file selected", Color.LightBlue, 3000); this.ExecutablePathBox.Clear(); } }
private void LibraryPathBox_DragDrop(object sender, DragEventArgs e) { // Если путь к файлу .exe не пустой if (!string.IsNullOrWhiteSpace(this.ExecutablePathBox.Text)) { // Принимаем файл(ы) string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // Проходимся в цикле foreach (string file in files) { // Проверяем расширения файла if (files[0].EndsWith(".dll")) { // Получаем версию NetFramework бибиотеки string FrameVerDllInfo = CheckFramework.Version(files[0]); // Получаем версию NetFramework бинарника string FrameVerExeInfo = CheckFramework.Version(this.ExecutablePathBox.Text); // Если версия не совпадает с N/A if (!FrameVerDllInfo.Contains("N/A")) { // Если нет совпадений файлов из ListBox'a if (!this.LibraryPathBox.Items.Contains(file)) { // Если версии .dll совпадает с .exe if (FrameVerExeInfo.Equals(FrameVerDllInfo, StringComparison.OrdinalIgnoreCase)) { this.LibraryPathBox.Items.Add(file); // Добавляем файл в список ListBox this.TextPathLibrary.Text = $"Path to .dll file(s): {LibraryPathBox.Items.Count}"; // Добавляем счётчик } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, ".NetFramework version does not match file", Color.LightBlue, 3000); } } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Such file is already in the list", Color.LightBlue, 3000); } } else { this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Supports only .Net library files", Color.LightBlue, 3000); } } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Supports only .dll files", Color.LightBlue, 3000); } } } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Fill in the first input field .exe path", Color.LightBlue, 3000); } }
private void AddingLibrary_Click(object sender, EventArgs e) { // Убираем фокус с кнопки NativeMethods.SetFocus(IntPtr.Zero); this.LogoText.Focus(); using var ofd = new OpenFileDialog { Title = "Select the .dll file(s) you want to add", Filter = "Library file|*.dll", AutoUpgradeEnabled = true, CheckFileExists = true, Multiselect = true, RestoreDirectory = true }; if (ofd.ShowDialog() == DialogResult.OK) { foreach (string multi in ofd.FileNames) { string FrameVerDllInfo = CheckFramework.Version(multi); // Получаем версию NetFramework бибиотеки string FrameVerExeInfo = CheckFramework.Version(this.ExecutablePathBox.Text); // Получаем версию NetFramework бинарника if (!FrameVerDllInfo.Contains("N/A")) // Если нет совпадений с N/A { if (!this.LibraryPathBox.Items.Contains(multi)) // Если нет совпадающий файлов в списке { if (FrameVerExeInfo.Equals(FrameVerDllInfo, StringComparison.OrdinalIgnoreCase)) // Если версии .dll совпадает с .exe { this.LibraryPathBox.Items.Add(multi); // Добавляем файл в ListBox this.TextPathLibrary.Text = $"Path to .dll file(s): {LibraryPathBox.Items.Count}"; // Добавляем счётчик } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, ".NetFramework version does not match .exe file", Color.LightBlue, 3000); } } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Such file is already in the list", Color.LightBlue, 3000); } } else { this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Supports only .Net library files", Color.LightBlue, 3000); } } } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "No file selected", Color.LightBlue, 3000); } }
private void ClearLog_Click(object sender, EventArgs e) { // Убираем фокус с кнопки NativeMethods.SetFocus(IntPtr.Zero); this.LogoText.Focus(); // Если логированный список не пустой if (!string.IsNullOrWhiteSpace(this.RepackLogBox.Text)) { this.RepackLogBox.Clear(); // Очищяем } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "There is nothing in the logger.", Color.LightBlue, 3000); } }
private void SelectDelete_Click(object sender, EventArgs e) { // Убираем фокус с кнопки NativeMethods.SetFocus(IntPtr.Zero); this.LogoText.Focus(); // Если если какой-то элемент в списке if (this.LibraryPathBox.SelectedIndex != -1) { this.LibraryPathBox.Items.RemoveAt(this.LibraryPathBox.SelectedIndex); // Удаляем выбранный элемент this.TextPathLibrary.Text = $"Path to .dll file(s): {LibraryPathBox.Items.Count}"; // Добавляем счётчик } else { StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Select an item from the list to remove.", Color.LightBlue, 3000); } }
/// <summary> /// Метод для проверки библиотек на наличие .NetFramework'a /// </summary> /// <returns>true/false</returns> private bool CheckLibrary() { // Проходимся по списку .dll из ListBox'a foreach (var libs in this.LibraryPathBox.Items) { bool result = CheckNative.IsReflection((string)libs); if (result) { return(true); } else { this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, $"The library {this.LibraryPathBox.Items.IndexOf(result)} is not .Net", Color.LightBlue, 3000); return(false); } } return(false); }
private async void CompileBuild_Click(object sender, EventArgs e) { // Убираем фокус с кнопки NativeMethods.SetFocus(IntPtr.Zero); this.LogoText.Focus(); // Если путь к файлу .exe не пустой if (!string.IsNullOrWhiteSpace(this.ExecutablePathBox.Text)) { // Если в списке ListBox есть .dll файлы if (this.LibraryPathBox.Items.Count > 0) { // Проверяем на корректность библиотек if (CheckLibrary()) { // Очищяем логгер this.RepackLogBox.Clear(); // Проверяем файл ILRepacke'a в папке %AppData% if (!File.Exists(GlobalPath.ILPath)) { try { // Если файла нету, то сохраняем его в папку %AppData% из ресурсов. File.WriteAllBytes(GlobalPath.ILPath, Resources.ilrepack); } catch { } } // Выполняем слияние библиотек с файлом в асинхронном режиме var action = new Action <string>((s) => this.RepackLogBox.Text += $"{s}{Environment.NewLine}"); foreach (string item in await RepackRun.GetCMDOutputAsync(Script()).ConfigureAwait(false)) { this.RepackLogBox.Invoke(action, item); } // Если в логгере находим строку Finished - что значит "закончено" if (this.RepackLogBox.Text.Contains("Finished")) { // Уведомляем пользователя что всё прошло успешно MusicPlay.Inizialize(Resources.GoodBuild); this.StatusMessage.Location = new Point(128, 244); ControlActive.CheckMessage(this.StatusMessage, "Libraries have been successfully added to the assembly!", Color.LightBlue, 3000); DeleteILPack(); } else { // Иначе выводим ошибку MusicPlay.Inizialize(Resources.Error_Build); this.StatusMessage.Location = new Point(128, 244); ControlActive.CheckMessage(this.StatusMessage, "Error adding libraries!", Color.LightBlue, 3000); } } } else { this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Add the .dll file to the field", Color.LightBlue, 3000); } } else { this.StatusMessage.Location = new Point(7, 273); ControlActive.CheckMessage(StatusMessage, "Add the .exe file to the field", Color.LightBlue, 3000); } }