diff --git a/.gitignore b/.gitignore index 44aa595..41fa271 100644 --- a/.gitignore +++ b/.gitignore @@ -399,4 +399,5 @@ FodyWeavers.xsd *.sln.iml # Releases Temporary Dir -releases/ \ No newline at end of file +releases/ +msou/ \ No newline at end of file diff --git a/MSOUI.sln.DotSettings b/MSOUI.sln.DotSettings new file mode 100644 index 0000000..0bcf654 --- /dev/null +++ b/MSOUI.sln.DotSettings @@ -0,0 +1,5 @@ + + True + True + True + True \ No newline at end of file diff --git a/msou_installer/Enums/EBits.cs b/msou_installer/Enums/EBits.cs deleted file mode 100644 index 1977492..0000000 --- a/msou_installer/Enums/EBits.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace msoui.Enums; - -/// -/// Перечисление разрядности -/// -public enum EBits -{ - /// - /// 32-разрядная версия - /// - Bit32 = 0, - - /// - /// 64-разрядная версия - /// - Bit64 = 1 -} diff --git a/msou_installer/Forms/InstallForm.Designer.cs b/msou_installer/Forms/InstallForm.Designer.cs index e36dcac..bcb6b2f 100644 --- a/msou_installer/Forms/InstallForm.Designer.cs +++ b/msou_installer/Forms/InstallForm.Designer.cs @@ -46,7 +46,7 @@ partial class InstallForm this.actionPanel.Location = new System.Drawing.Point(0, 0); this.actionPanel.Name = "actionPanel"; this.actionPanel.Padding = new System.Windows.Forms.Padding(10); - this.actionPanel.Size = new System.Drawing.Size(496, 91); + this.actionPanel.Size = new System.Drawing.Size(738, 91); this.actionPanel.TabIndex = 5; // // progressBar @@ -54,7 +54,7 @@ partial class InstallForm this.progressBar.Dock = System.Windows.Forms.DockStyle.Fill; this.progressBar.Location = new System.Drawing.Point(10, 59); this.progressBar.Name = "progressBar"; - this.progressBar.Size = new System.Drawing.Size(476, 22); + this.progressBar.Size = new System.Drawing.Size(718, 22); this.progressBar.TabIndex = 1; // // statusLabel @@ -62,7 +62,7 @@ partial class InstallForm this.statusLabel.Dock = System.Windows.Forms.DockStyle.Top; this.statusLabel.Location = new System.Drawing.Point(10, 10); this.statusLabel.Name = "statusLabel"; - this.statusLabel.Size = new System.Drawing.Size(476, 49); + this.statusLabel.Size = new System.Drawing.Size(718, 49); this.statusLabel.TabIndex = 0; this.statusLabel.Text = "&Начинаю установку..."; // @@ -74,7 +74,7 @@ partial class InstallForm this.logList.Location = new System.Drawing.Point(0, 0); this.logList.Margin = new System.Windows.Forms.Padding(10); this.logList.Name = "logList"; - this.logList.Size = new System.Drawing.Size(496, 313); + this.logList.Size = new System.Drawing.Size(738, 442); this.logList.TabIndex = 4; // // process @@ -97,7 +97,7 @@ partial class InstallForm // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 21F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(496, 313); + this.ClientSize = new System.Drawing.Size(738, 442); this.ControlBox = false; this.Controls.Add(this.actionPanel); this.Controls.Add(this.logList); @@ -106,6 +106,7 @@ partial class InstallForm this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "InstallForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Установка обновлений"; this.Load += new System.EventHandler(this.InstallForm_Load); this.actionPanel.ResumeLayout(false); diff --git a/msou_installer/Forms/InstallForm.cs b/msou_installer/Forms/InstallForm.cs index f3534a8..8625620 100644 --- a/msou_installer/Forms/InstallForm.cs +++ b/msou_installer/Forms/InstallForm.cs @@ -1,28 +1,36 @@ -namespace msoui.Forms; -public partial class InstallForm: Form +using msoui.Models; + +namespace msoui.Forms; + +public partial class InstallForm : Form { - public InstallForm (List fileList, string extractDir) + public InstallForm(InstallModel model) { - FileList = fileList; - ExtractDir = extractDir; + Model = model; InitializeComponent(); } - public List FileList { get; set; } - - public string ExtractDir { get; set; } + public InstallModel Model { get; set; } private void LogIt(string message) { logList.Items.Add(message); + Application.DoEvents(); } - private void LogIt (string message, params object?[] args) + private void LogIt(string message, params object?[] args) { logList.Items.Add(string.Format(message, args)); + Application.DoEvents(); } - public void StartProcess (string fileName) + private void AddStatus(string message, params object?[] args) + { + statusLabel.Text = string.Format(message, args); + Application.DoEvents(); + } + + public void StartProcess(string fileName) { process.StartInfo.FileName = fileName; process.StartInfo.Arguments = "/q /norestart"; @@ -34,42 +42,69 @@ public partial class InstallForm: Form } - public void InstallUpdates () + public void InstallUpdates() { + //Сообщение о начале установки LogIt("Начинаю установку..."); - int updatesCount = FileList.Count; + //Высчитываю максимальное число программ + int updatesCount = Model.FileList.Count; + //Вывожу сообщение о количестве элементов LogIt("Выбрано {0} обновлений для установки...", updatesCount); + AddStatus("Выбрано {0} обновлений для установки...", updatesCount); + //Счётчик int count = 0; - foreach (string? file in FileList) + //Устанавливаю индикатор прогресса + progressBar.Maximum = updatesCount; + progressBar.Value = 0; + + //Запускаю программы установки + foreach (string? file in Model.FileList) { + //Добавляю статусное сообщение + AddStatus("Устанавливается обновление: {0}", file); + + //Прибавляю счётчик count++; - decimal percentDone = Math.Round((decimal)count / updatesCount * 100); + //Считаю процент выполненного + decimal percentDone = Math.Round((decimal) count / updatesCount * 100); + //Заношу в лог информацию об устанавливаемом файле LogIt(@"Устанавливается файл {0} [{1} из {2}, {3}%]...", file, count, updatesCount, percentDone); - StartProcess($"{ExtractDir}{file}"); + + //Запускаю файл установки + StartProcess($"{Model.FromDir}{file}"); + Application.DoEvents(); + + //Увеличиваю прогресс + progressBar.Value++; + Application.DoEvents(); + + //Вывожу сообщение об установке LogIt(@"Файл {0} установлен!", file); } + //Вывожу сообщение об окончании установки MessageBox.Show(@"Набор обновлений успешно установлен!", @"Установка завершена", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + //Закрываю окно DialogResult = DialogResult.OK; } - private void startTimer_Tick (object sender, EventArgs e) + private void startTimer_Tick(object sender, EventArgs e) { startTimer.Enabled = false; InstallUpdates(); } - private void InstallForm_Load (object sender, EventArgs e) + private void InstallForm_Load(object sender, EventArgs e) { startTimer.Enabled = true; } -} +} \ No newline at end of file diff --git a/msou_installer/Forms/MainForm.Designer.cs b/msou_installer/Forms/MainForm.Designer.cs index 181409e..9052a15 100644 --- a/msou_installer/Forms/MainForm.Designer.cs +++ b/msou_installer/Forms/MainForm.Designer.cs @@ -30,52 +30,35 @@ sealed partial class MainForm { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.contentPanel = new System.Windows.Forms.Panel(); - this.viewButton = new System.Windows.Forms.Button(); this.bitsSelector64 = new System.Windows.Forms.RadioButton(); this.bitsSelector32 = new System.Windows.Forms.RadioButton(); - this.dataFileSelector = new System.Windows.Forms.TextBox(); this.bitsSelectorLabel = new System.Windows.Forms.Label(); - this.dataFileLabel = new System.Windows.Forms.Label(); this.titleLabel = new System.Windows.Forms.Label(); this.buttonsPanel = new System.Windows.Forms.Panel(); this.exitButton = new System.Windows.Forms.Button(); this.installButton = new System.Windows.Forms.Button(); - this.dataFileDialog = new System.Windows.Forms.OpenFileDialog(); this.contentPanel.SuspendLayout(); this.buttonsPanel.SuspendLayout(); this.SuspendLayout(); // // contentPanel // - this.contentPanel.Controls.Add(this.viewButton); this.contentPanel.Controls.Add(this.bitsSelector64); this.contentPanel.Controls.Add(this.bitsSelector32); - this.contentPanel.Controls.Add(this.dataFileSelector); this.contentPanel.Controls.Add(this.bitsSelectorLabel); - this.contentPanel.Controls.Add(this.dataFileLabel); this.contentPanel.Controls.Add(this.titleLabel); this.contentPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.contentPanel.Location = new System.Drawing.Point(0, 0); this.contentPanel.Name = "contentPanel"; - this.contentPanel.Size = new System.Drawing.Size(684, 275); + this.contentPanel.Size = new System.Drawing.Size(684, 207); this.contentPanel.TabIndex = 0; // - // viewButton - // - this.viewButton.Location = new System.Drawing.Point(574, 59); - this.viewButton.Name = "viewButton"; - this.viewButton.Size = new System.Drawing.Size(96, 29); - this.viewButton.TabIndex = 6; - this.viewButton.Text = "&Обзор"; - this.viewButton.UseVisualStyleBackColor = true; - this.viewButton.Click += new System.EventHandler(this.viewButton_Click); - // // bitsSelector64 // this.bitsSelector64.AutoSize = true; this.bitsSelector64.Cursor = System.Windows.Forms.Cursors.Hand; this.bitsSelector64.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.bitsSelector64.Location = new System.Drawing.Point(32, 173); + this.bitsSelector64.Location = new System.Drawing.Point(40, 109); this.bitsSelector64.Name = "bitsSelector64"; this.bitsSelector64.Size = new System.Drawing.Size(179, 25); this.bitsSelector64.TabIndex = 5; @@ -88,7 +71,7 @@ sealed partial class MainForm this.bitsSelector32.Checked = true; this.bitsSelector32.Cursor = System.Windows.Forms.Cursors.Hand; this.bitsSelector32.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.bitsSelector32.Location = new System.Drawing.Point(32, 142); + this.bitsSelector32.Location = new System.Drawing.Point(40, 78); this.bitsSelector32.Name = "bitsSelector32"; this.bitsSelector32.Size = new System.Drawing.Size(179, 25); this.bitsSelector32.TabIndex = 4; @@ -96,32 +79,15 @@ sealed partial class MainForm this.bitsSelector32.Text = "&32-разрядная версия"; this.bitsSelector32.UseVisualStyleBackColor = true; // - // dataFileSelector - // - this.dataFileSelector.Location = new System.Drawing.Point(12, 59); - this.dataFileSelector.Name = "dataFileSelector"; - this.dataFileSelector.Size = new System.Drawing.Size(556, 29); - this.dataFileSelector.TabIndex = 3; - // // bitsSelectorLabel // this.bitsSelectorLabel.AutoSize = true; - this.bitsSelectorLabel.Location = new System.Drawing.Point(12, 107); + this.bitsSelectorLabel.Location = new System.Drawing.Point(12, 45); this.bitsSelectorLabel.Name = "bitsSelectorLabel"; this.bitsSelectorLabel.Size = new System.Drawing.Size(454, 21); this.bitsSelectorLabel.TabIndex = 2; this.bitsSelectorLabel.Text = "&Выберете разрядность установленной версии MS Office 2016:"; // - // dataFileLabel - // - this.dataFileLabel.AutoSize = true; - this.dataFileLabel.Location = new System.Drawing.Point(12, 35); - this.dataFileLabel.Name = "dataFileLabel"; - this.dataFileLabel.Size = new System.Drawing.Size(270, 21); - this.dataFileLabel.TabIndex = 1; - this.dataFileLabel.Text = "&Выберете файл данных обновлений:"; - this.dataFileLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; - // // titleLabel // this.titleLabel.Dock = System.Windows.Forms.DockStyle.Top; @@ -138,7 +104,7 @@ sealed partial class MainForm this.buttonsPanel.Controls.Add(this.exitButton); this.buttonsPanel.Controls.Add(this.installButton); this.buttonsPanel.Dock = System.Windows.Forms.DockStyle.Bottom; - this.buttonsPanel.Location = new System.Drawing.Point(0, 214); + this.buttonsPanel.Location = new System.Drawing.Point(0, 146); this.buttonsPanel.Name = "buttonsPanel"; this.buttonsPanel.Size = new System.Drawing.Size(684, 61); this.buttonsPanel.TabIndex = 1; @@ -163,17 +129,11 @@ sealed partial class MainForm this.installButton.UseVisualStyleBackColor = true; this.installButton.Click += new System.EventHandler(this.installButton_Click); // - // dataFileDialog - // - this.dataFileDialog.DefaultExt = "data"; - this.dataFileDialog.Filter = "Файл данных обновлений|*.data"; - this.dataFileDialog.Title = "Выберете файл данных обновлений"; - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 21F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(684, 275); + this.ClientSize = new System.Drawing.Size(684, 207); this.ControlBox = false; this.Controls.Add(this.buttonsPanel); this.Controls.Add(this.contentPanel); @@ -186,7 +146,6 @@ sealed partial class MainForm this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Установка обновлений для Microsoft Office 2016"; - this.Load += new System.EventHandler(this.StartForm_Load); this.contentPanel.ResumeLayout(false); this.contentPanel.PerformLayout(); this.buttonsPanel.ResumeLayout(false); @@ -198,14 +157,10 @@ sealed partial class MainForm private Panel contentPanel; private Panel buttonsPanel; - private Button viewButton; private RadioButton bitsSelector64; private RadioButton bitsSelector32; - private TextBox dataFileSelector; private Label bitsSelectorLabel; - private Label dataFileLabel; private Label titleLabel; private Button exitButton; private Button installButton; - private OpenFileDialog dataFileDialog; } \ No newline at end of file diff --git a/msou_installer/Forms/MainForm.cs b/msou_installer/Forms/MainForm.cs index b3cc801..e5b6382 100644 --- a/msou_installer/Forms/MainForm.cs +++ b/msou_installer/Forms/MainForm.cs @@ -1,57 +1,47 @@ -using anbs_cp; - -using msoui.Enums; using msoui.Models; namespace msoui.Forms; -public sealed partial class MainForm: Form + +public sealed partial class MainForm : Form { - public MainForm () + public MainForm() { - TempWorkDir = $@"{LikeDelphi.IncludeTrailingBackslash(Path.GetTempPath())}msoui\"; + TempWorkDir = @".\msou\"; InitializeComponent(); } public string TempWorkDir { get; set; } - private void viewButton_Click (object sender, EventArgs e) - { - if (dataFileDialog.ShowDialog() == DialogResult.OK) - dataFileSelector.Text = dataFileDialog.FileName; - } - - private void exitButton_Click (object sender, EventArgs e) + private void exitButton_Click(object sender, EventArgs e) { Application.Exit(); } - private void installButton_Click (object sender, EventArgs e) + private void installButton_Click(object sender, EventArgs e) { - // - if (string.IsNullOrWhiteSpace(dataFileSelector.Text) || !File.Exists(dataFileSelector.Text)) - { - MessageBox.Show($@" {dataFileSelector.Text} !", @"!", MessageBoxButtons.OK, MessageBoxIcon.Error); + // tmp + string oldTempWorkDir = TempWorkDir; - return; - } + // tmp + TempWorkDir = bitsSelector64.Checked ? $@"{TempWorkDir}x64\" : $@"{TempWorkDir}x32\"; // - UnPackModel model = new(dataFileSelector.Text, bitsSelector64.Checked ? EBits.Bit64 : EBits.Bit32, TempWorkDir); + ScanDirModel scanModel = new("*.exe", TempWorkDir, false); // - UnPackForm unPackFrm = new(model); + ScanDirForm scanDirFrm = new(scanModel); // - unPackFrm.ShowDialog(); - - // - - List updatesList = unPackFrm.FileList; + scanDirFrm.ShowDialog(); // - unPackFrm.Dispose(); + scanDirFrm.Dispose(); + + // + ListModel updateListModel = new(scanDirFrm.Model.FoundList); // - UpdatesListForm updatesListForm = new(updatesList); + UpdatesListForm updatesListForm = new(updateListModel); // DialogResult ulDialogResult = updatesListForm.ShowDialog(); @@ -59,16 +49,19 @@ public sealed partial class MainForm: Form // -- if (ulDialogResult == DialogResult.Cancel) { - // - CleanThis(updatesList); + // + TempWorkDir = oldTempWorkDir; return; } // updatesListForm.Dispose(); + // + InstallModel installModel = new(updateListModel.OutList, TempWorkDir); + // - InstallForm installForm = new (updatesList, TempWorkDir); + InstallForm installForm = new(installModel); // installForm.ShowDialog(); @@ -76,28 +69,7 @@ public sealed partial class MainForm: Form // installForm.Dispose(); - // - CleanThis(updatesList); + // tmp + TempWorkDir = oldTempWorkDir; } - - private void StartForm_Load (object sender, EventArgs e) - { - if (!string.IsNullOrWhiteSpace(dataFileSelector.Text) || !File.Exists(dataFileSelector.Text)) - return; - - string dataFileSeek = $"{Application.StartupPath}\\msou.data"; - - if (File.Exists(dataFileSeek)) - dataFileSelector.Text = dataFileSeek; - } - - private void CleanThis(List fileList) - { - // - foreach (string file in fileList) - File.Delete(file); - - // - Directory.Delete(TempWorkDir, true); - } -} +} \ No newline at end of file diff --git a/msou_installer/Forms/MainForm.resx b/msou_installer/Forms/MainForm.resx index 122bed5..8d25c03 100644 --- a/msou_installer/Forms/MainForm.resx +++ b/msou_installer/Forms/MainForm.resx @@ -57,9 +57,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - diff --git a/msou_installer/Forms/UnPackForm.Designer.cs b/msou_installer/Forms/ScanDirForm.Designer.cs similarity index 70% rename from msou_installer/Forms/UnPackForm.Designer.cs rename to msou_installer/Forms/ScanDirForm.Designer.cs index 98f2c90..ffba5e8 100644 --- a/msou_installer/Forms/UnPackForm.Designer.cs +++ b/msou_installer/Forms/ScanDirForm.Designer.cs @@ -1,6 +1,6 @@ namespace msoui.Forms; -sealed partial class UnPackForm +sealed partial class ScanDirForm { /// /// Required designer variable. @@ -29,24 +29,24 @@ sealed partial class UnPackForm private void InitializeComponent () { this.components = new System.ComponentModel.Container(); - this.waitLabel = new System.Windows.Forms.Label(); + this.statusLabel = new System.Windows.Forms.Label(); this.progressBar = new System.Windows.Forms.ProgressBar(); this.startTimer = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // - // waitLabel + // statusLabel // - this.waitLabel.AccessibleRole = System.Windows.Forms.AccessibleRole.Indicator; - this.waitLabel.AutoEllipsis = true; - this.waitLabel.Dock = System.Windows.Forms.DockStyle.Top; - this.waitLabel.Location = new System.Drawing.Point(0, 0); - this.waitLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.waitLabel.Name = "waitLabel"; - this.waitLabel.Size = new System.Drawing.Size(530, 45); - this.waitLabel.TabIndex = 0; - this.waitLabel.Text = "&Открытие файла данных..."; - this.waitLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.waitLabel.UseCompatibleTextRendering = true; + this.statusLabel.AccessibleRole = System.Windows.Forms.AccessibleRole.Indicator; + this.statusLabel.AutoEllipsis = true; + this.statusLabel.Dock = System.Windows.Forms.DockStyle.Top; + this.statusLabel.Location = new System.Drawing.Point(0, 0); + this.statusLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.statusLabel.Name = "statusLabel"; + this.statusLabel.Size = new System.Drawing.Size(530, 45); + this.statusLabel.TabIndex = 0; + this.statusLabel.Text = "&Пожалуйста, подождите. Идёт поиск файлов."; + this.statusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.statusLabel.UseCompatibleTextRendering = true; // // progressBar // @@ -63,22 +63,22 @@ sealed partial class UnPackForm this.startTimer.Interval = 1000; this.startTimer.Tick += new System.EventHandler(this.startTimer_Tick); // - // UnPackForm + // ScanDirForm // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 21F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(530, 65); this.ControlBox = false; this.Controls.Add(this.progressBar); - this.Controls.Add(this.waitLabel); + this.Controls.Add(this.statusLabel); this.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.Margin = new System.Windows.Forms.Padding(4); this.MaximizeBox = false; - this.Name = "UnPackForm"; + this.Name = "ScanDirForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Пожалуйста, подождите. Идёт распаковка файла данных обновлений..."; + this.Text = "Поиск файлов"; this.Load += new System.EventHandler(this.UnPackForm_Load); this.ResumeLayout(false); @@ -86,7 +86,7 @@ sealed partial class UnPackForm #endregion - private Label waitLabel; + private Label statusLabel; private ProgressBar progressBar; private System.Windows.Forms.Timer startTimer; } \ No newline at end of file diff --git a/msou_installer/Forms/ScanDirForm.cs b/msou_installer/Forms/ScanDirForm.cs new file mode 100644 index 0000000..6e42610 --- /dev/null +++ b/msou_installer/Forms/ScanDirForm.cs @@ -0,0 +1,69 @@ +using msoui.Models; + +namespace msoui.Forms; + +public sealed partial class ScanDirForm : Form +{ + private const string SearchFile = "&Пожалуйста, подождите. Идёт поиск файлов. Найдено: {0} файлов..."; + + public ScanDirForm(ScanDirModel model) + { + Model = model; + InitializeComponent(); + } + + public ScanDirModel Model { get; set; } + + private void AddStatus(string message, params object[] args) + { + statusLabel.Text = string.Format(message, args); + Application.DoEvents(); + } + + public void ScanForFiles() + { + //Счётчик найденных + int foundsCount = 0; + + //Добавляю статусное сообщение + AddStatus(SearchFile, foundsCount); + + //Осуществляю подсчёт файлов + foreach (string file in Directory.EnumerateFiles(Model.SearchDir, Model.Mask, + Model.ScanSubDirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) + { + try + { + //Получаю информацию о файле + FileInfo info = new(file); + + //Добавляю имя файла в список + Model.FoundList.Add(info.Name); + + //Увеличиваю число найденных + foundsCount++; + + //Добавляю статус + AddStatus(SearchFile, foundsCount); + } + catch + { + // ignored + } + } + + //Выхожу из формы + DialogResult = DialogResult.OK; + } + + private void startTimer_Tick(object sender, EventArgs e) + { + startTimer.Enabled = false; + ScanForFiles(); + } + + private void UnPackForm_Load(object sender, EventArgs e) + { + startTimer.Enabled = true; + } +} \ No newline at end of file diff --git a/msou_installer/Forms/UnPackForm.resx b/msou_installer/Forms/ScanDirForm.resx similarity index 100% rename from msou_installer/Forms/UnPackForm.resx rename to msou_installer/Forms/ScanDirForm.resx diff --git a/msou_installer/Forms/UnPackForm.cs b/msou_installer/Forms/UnPackForm.cs deleted file mode 100644 index 1e28e0b..0000000 --- a/msou_installer/Forms/UnPackForm.cs +++ /dev/null @@ -1,105 +0,0 @@ -using msoui.Enums; -using msoui.Models; - -using SevenZipExtractor; - -namespace msoui.Forms; -public sealed partial class UnPackForm: Form -{ - public UnPackForm (UnPackModel model) - { - Model = model; - FileList = new(); - InitializeComponent(); - } - - private const string MessageUnPackFile = "Распаковывается файл {0}..."; - - public UnPackModel Model { get; set; } - - public List FileList { get; set; } - - - private void UnPackThis() - { - //Создаю папку - Directory.CreateDirectory(Model.UnPackDir); - - //Папка, которая отсеивается - string unFolderName = Model.Bits == EBits.Bit32 ? "x64" : "x32"; - - //Открываю архив - using ArchiveFile archiveFile = new(Model.DataFile); - - //Создаю список на извлечение - List extractList = new(); - - //Обхожу список и отсеиваю ненужные - foreach (Entry entry in archiveFile.Entries) - { - //Если папка - if (entry.IsFolder) - { - //то проверяем нужную разрядность - if (entry.FileName != unFolderName) - //если да, то добавляем в список для извлечения - extractList.Add(entry); - } - else - { - //если это файл, то проверяем на нахождение в нужной папке - if (entry.FileName[..3] == unFolderName) - continue; - - //и добавляем в список, если нужной - extractList.Add(entry); - } - } - - //Устанавливаю максимальное значение индикатора прогресса - progressBar.Maximum = extractList.Count; - - //Извлекаю архив - foreach (Entry entry in extractList) - { - //Формирую имя файла назначения - string unPackFileName; - try - { - unPackFileName = entry.FileName[4..]; - } - catch (Exception) - { - unPackFileName = "UnNamed"; - } - - //Вывожу сообщение - waitLabel.Text = string.Format(MessageUnPackFile, unPackFileName); - Application.DoEvents(); - - //Распаковываю файл - entry.Extract($@"{Model.UnPackDir}{unPackFileName}"); - - //Добавляю в список файлов - if (File.Exists($@"{Model.UnPackDir}{unPackFileName}")) - FileList.Add(unPackFileName); - - //Добавляю деление в индикатор прогресса - progressBar.Value++; - } - - //Выхожу - DialogResult = DialogResult.OK; - } - - private void startTimer_Tick (object sender, EventArgs e) - { - startTimer.Enabled = false; - UnPackThis(); - } - - private void UnPackForm_Load (object sender, EventArgs e) - { - startTimer.Enabled = true; - } -} diff --git a/msou_installer/Forms/UpdatesListForm.cs b/msou_installer/Forms/UpdatesListForm.cs index da58c33..db305b4 100644 --- a/msou_installer/Forms/UpdatesListForm.cs +++ b/msou_installer/Forms/UpdatesListForm.cs @@ -1,48 +1,53 @@ -namespace msoui.Forms; -public sealed partial class UpdatesListForm: Form +using msoui.Models; + +namespace msoui.Forms; + +public sealed partial class UpdatesListForm : Form { - public UpdatesListForm (List updatesList) + private const string SelectionStatusLabel = "{0} выбрано из {1}"; + + public UpdatesListForm(ListModel model) { - UpdatesList = updatesList; + Model = model; InitializeComponent(); } - public List UpdatesList { get; set; } + public ListModel Model { get; set; } - private const string SelectionStatusLabel = "{0} выбрано из {1}"; - - private void selectAllButton_Click (object sender, EventArgs e) + private void selectAllButton_Click(object sender, EventArgs e) { for (int index = 0; index < updatesListBox.Items.Count; index++) updatesListBox.SetItemCheckState(index, CheckState.Checked); } - private void UpdatesListForm_Load (object sender, EventArgs e) + private void UpdatesListForm_Load(object sender, EventArgs e) { updatesListBox.Items.Clear(); - foreach (string item in UpdatesList) + foreach (string item in Model.InList) updatesListBox.Items.Add(item, CheckState.Checked); } - private void checkedUpdateTimer_Tick (object sender, EventArgs e) + private void checkedUpdateTimer_Tick(object sender, EventArgs e) { - selectionStatus.Text = string.Format(SelectionStatusLabel, updatesListBox.CheckedItems.Count, updatesListBox.Items.Count); + selectionStatus.Text = string.Format(SelectionStatusLabel, updatesListBox.CheckedItems.Count, + updatesListBox.Items.Count); } - private void installButton_Click (object sender, EventArgs e) + private void installButton_Click(object sender, EventArgs e) { - UpdatesList.Clear(); + Model.OutList.Clear(); - foreach (object checkedItem in updatesListBox.CheckedItems) - { - if (checkedItem.ToString() != null) - UpdatesList.Add(checkedItem.ToString()!); - } + foreach (object checkedItem in updatesListBox.CheckedItems.Cast() + .Where(static checkedItem => checkedItem.ToString() != null)) + // ReSharper disable once NullableWarningSuppressionIsUsed + Model.OutList.Add(checkedItem.ToString()!); + + DialogResult = DialogResult.OK; } - private void cancelButton_Click (object sender, EventArgs e) + private void cancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; } -} +} \ No newline at end of file diff --git a/msou_installer/Models/InstallModel.cs b/msou_installer/Models/InstallModel.cs new file mode 100644 index 0000000..60a090b --- /dev/null +++ b/msou_installer/Models/InstallModel.cs @@ -0,0 +1,23 @@ +namespace msoui.Models; + +/// +/// Модель для установки +/// +public class InstallModel +{ + public InstallModel(List fileList, string fromDir) + { + FileList = fileList; + FromDir = fromDir; + } + + /// + /// Каталог с файлами + /// + public string FromDir { get; set; } + + /// + /// Список файлов + /// + public List FileList { get; set; } +} \ No newline at end of file diff --git a/msou_installer/Models/ListModel.cs b/msou_installer/Models/ListModel.cs new file mode 100644 index 0000000..dc45b16 --- /dev/null +++ b/msou_installer/Models/ListModel.cs @@ -0,0 +1,23 @@ +namespace msoui.Models; + +/// +/// Модель для списка +/// +public class ListModel +{ + public ListModel(List inList) + { + InList = inList; + OutList = new List(); + } + + /// + /// Входящий список файлов + /// + public List InList { get; set; } + + /// + /// Исходящий список файлов + /// + public List OutList { get; set; } +} \ No newline at end of file diff --git a/msou_installer/Models/ScanDirModel.cs b/msou_installer/Models/ScanDirModel.cs new file mode 100644 index 0000000..294c774 --- /dev/null +++ b/msou_installer/Models/ScanDirModel.cs @@ -0,0 +1,35 @@ +namespace msoui.Models; + +/// +/// Модель для сканирования +/// +public class ScanDirModel +{ + public ScanDirModel(string mask, string searchDir, bool scanSubDirs) + { + Mask = mask; + SearchDir = searchDir; + ScanSubDirs = scanSubDirs; + FoundList = new List(); + } + + /// + /// Маска для поиска + /// + public string Mask { get; set; } + + /// + /// Каталог поиска + /// + public string SearchDir { get; set; } + + /// + /// Сканировать поддиректории + /// + public bool ScanSubDirs { get; set; } + + /// + /// Список найденных файлов + /// + public List FoundList { get; set; } +} \ No newline at end of file diff --git a/msou_installer/Models/UnPackModel.cs b/msou_installer/Models/UnPackModel.cs deleted file mode 100644 index a73ba7d..0000000 --- a/msou_installer/Models/UnPackModel.cs +++ /dev/null @@ -1,38 +0,0 @@ -using msoui.Enums; - -namespace msoui.Models; - -/// -/// Модель для распаковки -/// -public class UnPackModel -{ - public UnPackModel(string dataFile, EBits bits, string unPackDir) - { - DataFile = dataFile; - Bits = bits; - UnPackDir = unPackDir; - } - - public UnPackModel () - { - DataFile = ""; - Bits = EBits.Bit32; - UnPackDir = @".\"; - } - - /// - /// Файл-данных обновлений - /// - public string DataFile { get; set; } - - /// - /// Разрядность MS Office 2016 - /// - public EBits Bits { get; set; } - - /// - /// Каталог распаковки - /// - public string UnPackDir { get; set; } -} \ No newline at end of file diff --git a/msou_installer/Program.cs b/msou_installer/Program.cs index cb558be..1f0681f 100644 --- a/msou_installer/Program.cs +++ b/msou_installer/Program.cs @@ -5,10 +5,10 @@ namespace msoui; internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] - static void Main () + private static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. diff --git a/msou_installer/app.manifest b/msou_installer/app.manifest new file mode 100644 index 0000000..9cdf7e9 --- /dev/null +++ b/msou_installer/app.manifest @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msou_installer/arrow-down-square.ico b/msou_installer/app_icon.ico similarity index 100% rename from msou_installer/arrow-down-square.ico rename to msou_installer/app_icon.ico diff --git a/msou_installer/msou_installer.csproj b/msou_installer/msou_installer.csproj index ac5494b..2f4a076 100644 --- a/msou_installer/msou_installer.csproj +++ b/msou_installer/msou_installer.csproj @@ -8,16 +8,16 @@ enable msoui msoui.Program - arrow-down-square.ico + app_icon.ico + app.manifest - + - \ No newline at end of file diff --git a/msou_installer/msou_installer.csproj.DotSettings b/msou_installer/msou_installer.csproj.DotSettings new file mode 100644 index 0000000..2a71c6e --- /dev/null +++ b/msou_installer/msou_installer.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file