/
Radiator
/
VesAKAutoUpdate
Обзор
Документация
Войти
/
Radiator
/
VesAKAutoUpdate
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Form1.cs
688 строк
29 KB
Radiator
Create: Program.cs, Upd.cs, Инструкция автоапдейт.odt, Form1.cs
15 июн 2026, 11:29
Верифицирован
15 июн 2026, 11:29
c1bb6d4
Код
Авторство
О чём код?
using System; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; public class Form1 : Form { public delegate void MyMainThreadProc(); private string MApp1CStart; public MyMainThreadProc MyDynamicDelegate; private IContainer components; private Button VesAutoUpdate; private GroupBox groupBox1; private Label label1; private Button App1CStartChooseFile; private TextBox App1CStart; private FolderBrowserDialog MyfolderBrowser; private OpenFileDialog MyOpenFile; private TextBox Path1CBase; private Label label2; private Label label3; private Button Path1CBaseChooseFolder; private TextBox Password1C; private Label label4; private TextBox Login1C; public Label label5; private Button SaveConfigButt; private Button DumpPathChooseFolder; private TextBox FNameDump; private TextBox PathDump; private Label label7; private Label label6; private CheckBox checkBox1; private Label label8; private System.Windows.Forms.Label labelClusterServer; private System.Windows.Forms.TextBox ClusterServer; private System.Windows.Forms.Label labelIBName; private System.Windows.Forms.TextBox IBName; private System.Windows.Forms.Label labelClusterAdminLogin; private System.Windows.Forms.TextBox ClusterAdminLogin; private System.Windows.Forms.Label labelClusterAdminPwd; private CheckBox IB_ServerType; private Label label9; private System.Windows.Forms.TextBox ClusterAdminPwd; private async void Update1CBase_Click(object sender, EventArgs e) { // Блокируем кнопку для предотвращения повторного нажатия VesAutoUpdate.Enabled = false; label5.Text = "Обновление началось. Ожидайте..."; var updater = new Upd(); try { // Передаем ТОЛЬКО метод для обновления статуса на форме. // Логирование Upd теперь делает сам. await updater.RunUpdateAsync( status => label5.Text = status ); } catch (Exception ex) { // Этот блок скорее всего не сработает, так как исключения уже пойманы в Upd, // но он полезен для отлова непредвиденных ошибок. label5.Text = "Непредвиденная ошибка: " + ex.Message; } finally { // Гарантированно разблокируем кнопку в конце VesAutoUpdate.Enabled = true; } } private void MyLog(string LogText) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown StreamWriter val = new StreamWriter("VesAKAutoupdate.log", true, Encoding.Default); try { ((TextWriter)val).WriteLine(global::System.DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss") + " " + LogText); ((TextWriter)val).Dispose(); } finally { ((global::System.IDisposable)val)?.Dispose(); } } public Form1(string[] args) { bool flag = false; MyLog("Приложение запущено"); if (args.Length != 0) { for (int i = 0; i < args.Length; i++) { if (args[i] == "/AkAdminStart") { flag = true; break; } } } InitializeComponent(); if (!flag) { ((Control)groupBox1).Visible = false; ((Control)this).Height = 135; } else { LoadConfigToForm(); } } private void Form1_Load(object sender, EventArgs e) { } private void App1CStartChooseFile_Click(object sender, EventArgs e) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 if ((int)((CommonDialog)MyOpenFile).ShowDialog() == 1) { ((Control)App1CStart).Text = ((FileDialog)MyOpenFile).FileName; } } private void Path1CBaseChooseFolder_Click(object sender, EventArgs e) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 if ((int)((CommonDialog)MyfolderBrowser).ShowDialog() == 1) { ((Control)Path1CBase).Text = MyfolderBrowser.SelectedPath; } } private void SaveConfig() { string userCreds = "Логин:" + Login1C.Text + "Пароль:" + Password1C.Text; string encodedUserCreds = Convert.ToBase64String(Encoding.GetEncoding(855).GetBytes(userCreds)); string clusterCreds = "Логин:" + ClusterAdminLogin.Text + "Пароль:" + ClusterAdminPwd.Text; string encodedClusterCreds = Convert.ToBase64String(Encoding.GetEncoding(855).GetBytes(clusterCreds)); StreamWriter val = new StreamWriter("VesAKAutoUpdate.cfg", false, Encoding.GetEncoding(855)); try { ((TextWriter)val).WriteLine(App1CStart.Text); ((TextWriter)val).WriteLine(Path1CBase.Text); ((TextWriter)val).WriteLine(encodedUserCreds); ((TextWriter)val).WriteLine(PathDump.Text); ((TextWriter)val).WriteLine(FNameDump.Text); ((TextWriter)val).WriteLine(checkBox1.Checked.ToString()); ((TextWriter)val).WriteLine(IB_ServerType.Checked.ToString()); ((TextWriter)val).WriteLine(ClusterServer.Text); ((TextWriter)val).WriteLine(IBName.Text); ((TextWriter)val).WriteLine(encodedClusterCreds); } finally { ((global::System.IDisposable)val)?.Dispose(); } } private void LoadConfigToForm() { // Файл может отсутствовать, если запуск без /AkAdminStart или первый запуск if (!File.Exists("VesAKAutoUpdate.cfg")) { return; } try { // Используем using для автоматического закрытия StreamReader using (StreamReader val = new StreamReader("VesAKAutoUpdate.cfg", Encoding.GetEncoding(855))) { // 1. Читаем базовые параметры и сразу присваиваем их элементам управления ((Control)App1CStart).Text = val.ReadLine(); ((Control)Path1CBase).Text = val.ReadLine(); // 2. Читаем и декодируем учетные данные пользователя ИБ string encodedUserCreds = val.ReadLine(); if (!string.IsNullOrEmpty(encodedUserCreds)) { byte[] userData = Convert.FromBase64String(encodedUserCreds); string decodedUserCreds = Encoding.GetEncoding(855).GetString(userData); // Извлекаем логин и пароль из строки "Логин:xxxПароль:yyy" ((Control)Login1C).Text = decodedUserCreds.Substring( decodedUserCreds.IndexOf("Логин:") + 6, decodedUserCreds.IndexOf("Пароль:") - decodedUserCreds.IndexOf("Логин:") - 6); ((Control)Password1C).Text = decodedUserCreds.Substring(decodedUserCreds.IndexOf("Пароль:") + 7); } // 3. Читаем остальные параметры ((Control)PathDump).Text = val.ReadLine(); ((Control)FNameDump).Text = val.ReadLine(); // Флаг сжатия (с проверкой на конец файла) if (!val.EndOfStream) { bool.TryParse(val.ReadLine(), out bool compressionResult); checkBox1.Checked = compressionResult; } else { return; } // Флаг типа базы (с проверкой на конец файла) if (!val.EndOfStream) { bool.TryParse(val.ReadLine(), out bool serverTypeResult); IB_ServerType.Checked = serverTypeResult; } else { return; } // 4. Читаем параметры кластера ((Control)ClusterServer).Text = val.ReadLine(); ((Control)IBName).Text = val.ReadLine(); // 5. Читаем и декодируем учетные данные администратора кластера string encodedClusterCreds = val.ReadLine(); if (!string.IsNullOrEmpty(encodedClusterCreds)) { byte[] clusterData = Convert.FromBase64String(encodedClusterCreds); string decodedClusterCreds = Encoding.GetEncoding(855).GetString(clusterData); ((Control)ClusterAdminLogin).Text = decodedClusterCreds.Substring( decodedClusterCreds.IndexOf("Логин:") + 6, decodedClusterCreds.IndexOf("Пароль:") - decodedClusterCreds.IndexOf("Логин:") - 6); ((Control)ClusterAdminPwd).Text = decodedClusterCreds.Substring(decodedClusterCreds.IndexOf("Пароль:") + 7); } } } catch (Exception ex) { MyLog("Ошибка чтения конфигурации в форму"); MyLog(ex.Message); } } private void SaveConfigButt_Click(object sender, EventArgs e) { try { SaveConfig(); } catch (global::System.Exception ex) { MyLog("Ошибка записи конфигурации"); MyLog(ex.Message); } } private void DumpPathChooseFolder_Click(object sender, EventArgs e) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 if ((int)((CommonDialog)MyfolderBrowser).ShowDialog() == 1) { ((Control)PathDump).Text = MyfolderBrowser.SelectedPath; } } private void App1CStart_TextChanged(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { } protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } // ПРАВИЛЬНО: Вызов реализации Dispose у базового класса Form base.Dispose(disposing); } private void InitializeComponent() { this.VesAutoUpdate = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.label8 = new System.Windows.Forms.Label(); this.DumpPathChooseFolder = new System.Windows.Forms.Button(); this.FNameDump = new System.Windows.Forms.TextBox(); this.PathDump = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.SaveConfigButt = new System.Windows.Forms.Button(); this.Path1CBaseChooseFolder = new System.Windows.Forms.Button(); this.Password1C = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.Login1C = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.Path1CBase = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.App1CStartChooseFile = new System.Windows.Forms.Button(); this.App1CStart = new System.Windows.Forms.TextBox(); this.ClusterAdminPwd = new System.Windows.Forms.TextBox(); this.labelClusterAdminPwd = new System.Windows.Forms.Label(); this.ClusterAdminLogin = new System.Windows.Forms.TextBox(); this.labelClusterAdminLogin = new System.Windows.Forms.Label(); this.IBName = new System.Windows.Forms.TextBox(); this.labelIBName = new System.Windows.Forms.Label(); this.ClusterServer = new System.Windows.Forms.TextBox(); this.labelClusterServer = new System.Windows.Forms.Label(); this.MyfolderBrowser = new System.Windows.Forms.FolderBrowserDialog(); this.MyOpenFile = new System.Windows.Forms.OpenFileDialog(); this.label5 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.IB_ServerType = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // VesAutoUpdate // this.VesAutoUpdate.Location = new System.Drawing.Point(12, 12); this.VesAutoUpdate.Name = "VesAutoUpdate"; this.VesAutoUpdate.Size = new System.Drawing.Size(169, 23); this.VesAutoUpdate.TabIndex = 0; this.VesAutoUpdate.Text = "Обновить конфигурацию"; this.VesAutoUpdate.UseVisualStyleBackColor = true; this.VesAutoUpdate.Click += new System.EventHandler(this.Update1CBase_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.IB_ServerType); this.groupBox1.Controls.Add(this.label9); this.groupBox1.Controls.Add(this.checkBox1); this.groupBox1.Controls.Add(this.label8); this.groupBox1.Controls.Add(this.DumpPathChooseFolder); this.groupBox1.Controls.Add(this.FNameDump); this.groupBox1.Controls.Add(this.PathDump); this.groupBox1.Controls.Add(this.label7); this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.SaveConfigButt); this.groupBox1.Controls.Add(this.Path1CBaseChooseFolder); this.groupBox1.Controls.Add(this.Password1C); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.Login1C); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.Path1CBase); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.App1CStartChooseFile); this.groupBox1.Controls.Add(this.App1CStart); this.groupBox1.Controls.Add(this.ClusterAdminPwd); this.groupBox1.Controls.Add(this.labelClusterAdminPwd); this.groupBox1.Controls.Add(this.ClusterAdminLogin); this.groupBox1.Controls.Add(this.labelClusterAdminLogin); this.groupBox1.Controls.Add(this.IBName); this.groupBox1.Controls.Add(this.labelIBName); this.groupBox1.Controls.Add(this.ClusterServer); this.groupBox1.Controls.Add(this.labelClusterServer); this.groupBox1.Location = new System.Drawing.Point(12, 90); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(754, 434); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "Настройки"; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(133, 362); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(15, 14); this.checkBox1.TabIndex = 18; this.checkBox1.UseVisualStyleBackColor = true; this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); // // label8 // this.label8.AutoSize = true; this.label8.Location = new System.Drawing.Point(21, 363); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(106, 13); this.label8.TabIndex = 17; this.label8.Text = "Сжать таблицы ИБ:"; // // DumpPathChooseFolder // this.DumpPathChooseFolder.Location = new System.Drawing.Point(706, 168); this.DumpPathChooseFolder.Name = "DumpPathChooseFolder"; this.DumpPathChooseFolder.Size = new System.Drawing.Size(36, 29); this.DumpPathChooseFolder.TabIndex = 16; this.DumpPathChooseFolder.Text = "..."; this.DumpPathChooseFolder.UseVisualStyleBackColor = true; this.DumpPathChooseFolder.Click += new System.EventHandler(this.DumpPathChooseFolder_Click); // // FNameDump // this.FNameDump.Location = new System.Drawing.Point(171, 210); this.FNameDump.Name = "FNameDump"; this.FNameDump.Size = new System.Drawing.Size(529, 20); this.FNameDump.TabIndex = 15; // // PathDump // this.PathDump.Location = new System.Drawing.Point(171, 173); this.PathDump.Name = "PathDump"; this.PathDump.Size = new System.Drawing.Size(529, 20); this.PathDump.TabIndex = 14; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(6, 213); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(157, 13); this.label7.TabIndex = 13; this.label7.Text = "Имя файла резервной копии:"; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(6, 176); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(133, 13); this.label6.TabIndex = 12; this.label6.Text = "Путь к резервной копии:"; // // SaveConfigButt // this.SaveConfigButt.Location = new System.Drawing.Point(9, 392); this.SaveConfigButt.Name = "SaveConfigButt"; this.SaveConfigButt.Size = new System.Drawing.Size(733, 23); this.SaveConfigButt.TabIndex = 11; this.SaveConfigButt.Text = "Сохранить"; this.SaveConfigButt.UseVisualStyleBackColor = true; this.SaveConfigButt.Click += new System.EventHandler(this.SaveConfigButt_Click); // // Path1CBaseChooseFolder // this.Path1CBaseChooseFolder.Location = new System.Drawing.Point(706, 56); this.Path1CBaseChooseFolder.Name = "Path1CBaseChooseFolder"; this.Path1CBaseChooseFolder.Size = new System.Drawing.Size(36, 29); this.Path1CBaseChooseFolder.TabIndex = 10; this.Path1CBaseChooseFolder.Text = "..."; this.Path1CBaseChooseFolder.UseVisualStyleBackColor = true; this.Path1CBaseChooseFolder.Click += new System.EventHandler(this.Path1CBaseChooseFolder_Click); // // Password1C // this.Password1C.Location = new System.Drawing.Point(171, 136); this.Password1C.Name = "Password1C"; this.Password1C.PasswordChar = '*'; this.Password1C.Size = new System.Drawing.Size(529, 20); this.Password1C.TabIndex = 9; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(6, 139); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(48, 13); this.label4.TabIndex = 8; this.label4.Text = "Пароль:"; // // Login1C // this.Login1C.Location = new System.Drawing.Point(171, 98); this.Login1C.Name = "Login1C"; this.Login1C.Size = new System.Drawing.Size(529, 20); this.Login1C.TabIndex = 7; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(6, 101); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(106, 13); this.label3.TabIndex = 2; this.label3.Text = "Имя пользователя:"; // // Path1CBase // this.Path1CBase.Location = new System.Drawing.Point(171, 61); this.Path1CBase.Name = "Path1CBase"; this.Path1CBase.Size = new System.Drawing.Size(529, 20); this.Path1CBase.TabIndex = 6; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(6, 64); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(86, 13); this.label2.TabIndex = 5; this.label2.Text = "Путь к базе 1С:"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(6, 27); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(90, 13); this.label1.TabIndex = 4; this.label1.Text = "Приложение 1С:"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.Click += new System.EventHandler(this.label1_Click); // // App1CStartChooseFile // this.App1CStartChooseFile.Location = new System.Drawing.Point(706, 19); this.App1CStartChooseFile.Name = "App1CStartChooseFile"; this.App1CStartChooseFile.Size = new System.Drawing.Size(36, 29); this.App1CStartChooseFile.TabIndex = 3; this.App1CStartChooseFile.Text = "..."; this.App1CStartChooseFile.UseVisualStyleBackColor = true; this.App1CStartChooseFile.Click += new System.EventHandler(this.App1CStartChooseFile_Click); // // App1CStart // this.App1CStart.Location = new System.Drawing.Point(171, 24); this.App1CStart.Name = "App1CStart"; this.App1CStart.Size = new System.Drawing.Size(529, 20); this.App1CStart.TabIndex = 2; this.App1CStart.TextChanged += new System.EventHandler(this.App1CStart_TextChanged); // // ClusterAdminPwd // this.ClusterAdminPwd.Location = new System.Drawing.Point(171, 315); this.ClusterAdminPwd.Name = "ClusterAdminPwd"; this.ClusterAdminPwd.PasswordChar = '*'; this.ClusterAdminPwd.Size = new System.Drawing.Size(529, 20); this.ClusterAdminPwd.TabIndex = 27; // // labelClusterAdminPwd // this.labelClusterAdminPwd.AutoSize = true; this.labelClusterAdminPwd.Location = new System.Drawing.Point(6, 315); this.labelClusterAdminPwd.Name = "labelClusterAdminPwd"; this.labelClusterAdminPwd.Size = new System.Drawing.Size(139, 13); this.labelClusterAdminPwd.TabIndex = 26; this.labelClusterAdminPwd.Text = "Пароль админа кластера:"; // // ClusterAdminLogin // this.ClusterAdminLogin.Location = new System.Drawing.Point(171, 290); this.ClusterAdminLogin.Name = "ClusterAdminLogin"; this.ClusterAdminLogin.Size = new System.Drawing.Size(529, 20); this.ClusterAdminLogin.TabIndex = 25; // // labelClusterAdminLogin // this.labelClusterAdminLogin.AutoSize = true; this.labelClusterAdminLogin.Location = new System.Drawing.Point(6, 290); this.labelClusterAdminLogin.Name = "labelClusterAdminLogin"; this.labelClusterAdminLogin.Size = new System.Drawing.Size(132, 13); this.labelClusterAdminLogin.TabIndex = 24; this.labelClusterAdminLogin.Text = "Логин админа кластера:"; // // IBName // this.IBName.Location = new System.Drawing.Point(171, 265); this.IBName.Name = "IBName"; this.IBName.Size = new System.Drawing.Size(529, 20); this.IBName.TabIndex = 23; // // labelIBName // this.labelIBName.AutoSize = true; this.labelIBName.Location = new System.Drawing.Point(6, 265); this.labelIBName.Name = "labelIBName"; this.labelIBName.Size = new System.Drawing.Size(121, 13); this.labelIBName.TabIndex = 22; this.labelIBName.Text = "Имя базы на сервере:"; // // ClusterServer // this.ClusterServer.Location = new System.Drawing.Point(171, 240); this.ClusterServer.Name = "ClusterServer"; this.ClusterServer.Size = new System.Drawing.Size(529, 20); this.ClusterServer.TabIndex = 21; // // labelClusterServer // this.labelClusterServer.AutoSize = true; this.labelClusterServer.Location = new System.Drawing.Point(6, 240); this.labelClusterServer.Name = "labelClusterServer"; this.labelClusterServer.Size = new System.Drawing.Size(63, 13); this.labelClusterServer.TabIndex = 20; this.labelClusterServer.Text = "Сервер 1С:"; // // MyOpenFile // this.MyOpenFile.FileName = "openFileDialog1"; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(204))); this.label5.Location = new System.Drawing.Point(16, 50); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(378, 20); this.label5.TabIndex = 2; this.label5.Text = "Нажмите кнопку \"Обновить конфигурацию\""; // // label9 // this.label9.AutoSize = true; this.label9.Location = new System.Drawing.Point(168, 362); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(100, 13); this.label9.TabIndex = 28; this.label9.Text = "Это серверная ИБ"; // // IB_ServerType // this.IB_ServerType.AutoSize = true; this.IB_ServerType.Location = new System.Drawing.Point(274, 361); this.IB_ServerType.Name = "IB_ServerType"; this.IB_ServerType.Size = new System.Drawing.Size(15, 14); this.IB_ServerType.TabIndex = 29; this.IB_ServerType.UseVisualStyleBackColor = true; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(778, 536); this.Controls.Add(this.label5); this.Controls.Add(this.groupBox1); this.Controls.Add(this.VesAutoUpdate); this.Name = "Form1"; this.Text = "Обновление конфигурации \"Весовая Агрокомплекса им. Ткачева\""; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } }