diff --git a/PEIS.sln b/PEIS.sln index a4a7550..29b146e 100644 --- a/PEIS.sln +++ b/PEIS.sln @@ -15,14 +15,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DicomTool", "DicomTool\Dico EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWindowsFormsApp", "..\..\..\Test\TestWindowsFormsApp\TestWindowsFormsApp.csproj", "{BAC2778E-8EDF-435A-BC81-7C8D1F027572}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Update", "..\..\..\Update\Update.csproj", "{8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scale", "Scale\Scale.csproj", "{F13021FD-372E-4D3C-8982-6FE5102AF45A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{37E64FF5-7C4B-4DC7-BFA9-2529CF95BEE3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWinFormApp", "..\..\..\Test\TestWinFormApp\TestWinFormApp.csproj", "{4A92A40D-1C15-471C-AA42-80732E925904}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Update", "Update\Update.csproj", "{8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,14 +71,6 @@ Global {BAC2778E-8EDF-435A-BC81-7C8D1F027572}.Release|Any CPU.Build.0 = Release|Any CPU {BAC2778E-8EDF-435A-BC81-7C8D1F027572}.Release|x86.ActiveCfg = Release|Any CPU {BAC2778E-8EDF-435A-BC81-7C8D1F027572}.Release|x86.Build.0 = Release|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|x86.ActiveCfg = Debug|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|x86.Build.0 = Debug|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|Any CPU.Build.0 = Release|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|x86.ActiveCfg = Release|Any CPU - {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|x86.Build.0 = Release|Any CPU {F13021FD-372E-4D3C-8982-6FE5102AF45A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F13021FD-372E-4D3C-8982-6FE5102AF45A}.Debug|Any CPU.Build.0 = Debug|Any CPU {F13021FD-372E-4D3C-8982-6FE5102AF45A}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -103,10 +95,21 @@ Global {4A92A40D-1C15-471C-AA42-80732E925904}.Release|Any CPU.Build.0 = Release|Any CPU {4A92A40D-1C15-471C-AA42-80732E925904}.Release|x86.ActiveCfg = Release|Any CPU {4A92A40D-1C15-471C-AA42-80732E925904}.Release|x86.Build.0 = Release|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|x86.ActiveCfg = Debug|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Debug|x86.Build.0 = Debug|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|Any CPU.Build.0 = Release|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|x86.ActiveCfg = Release|Any CPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5} = {AB0394FA-735E-4213-9ACE-31C02F698FA7} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {56DA78F6-DED1-4B17-AE1F-7DCF4A666388} EndGlobalSection diff --git a/README.md b/README.md index fd18dc8..fb4a670 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PEIS 新体检系统 -!!! SVN 和 main分支保持同步 !!! +!!! SVN 和 main分支保持同步 !!!\ 通用功能同步提交到main分支,特殊定制功能提交到各自医院分支。 ## 分支 @@ -14,3 +14,4 @@ - PEIS 体检系统程序 - DicomTool PACS图片同步工具,Dicom文件转图片; - Scale 身高体重/血压仪联机程序; +- Update 体检系统自动更新程序 diff --git a/Update/Form1.Designer.cs b/Update/Form1.Designer.cs new file mode 100644 index 0000000..58abf3e --- /dev/null +++ b/Update/Form1.Designer.cs @@ -0,0 +1,79 @@ +namespace Update +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.lblTips = new System.Windows.Forms.Label(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // lblTips + // + this.lblTips.AutoSize = true; + this.lblTips.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.lblTips.Location = new System.Drawing.Point(93, 55); + this.lblTips.Name = "lblTips"; + this.lblTips.Size = new System.Drawing.Size(74, 20); + this.lblTips.TabIndex = 4; + this.lblTips.Text = "正在更新···"; + this.lblTips.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // pictureBox1 + // + this.pictureBox1.Image = global::Update.Properties.Resources.update; + this.pictureBox1.InitialImage = null; + this.pictureBox1.Location = new System.Drawing.Point(12, 40); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(50, 50); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 5; + this.pictureBox1.TabStop = false; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(304, 141); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.lblTips); + this.Name = "Form1"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "体检系统更新"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Label lblTips; + private System.Windows.Forms.PictureBox pictureBox1; + } +} + diff --git a/Update/Form1.cs b/Update/Form1.cs new file mode 100644 index 0000000..14cd307 --- /dev/null +++ b/Update/Form1.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading; +using System.Windows.Forms; + +namespace Update +{ + public partial class Form1 : Form + { + // 当前程序目录 **/Update/ + private static string CurrentPath = Application.StartupPath; + + public Form1() + { + InitializeComponent(); + TopMost = true; + MaximizeBox = false; + ControlBox = true; + ControlBox = false; + + try + { + // 体检系统 + var program = "PEIS.exe"; + // 解压文件目录 **/Update/Unzip/ + var unZipPath = Path.Combine(CurrentPath, "UnZip"); + // 检查程序是否正在运行 + var processes = Process.GetProcessesByName(program); + if (processes.Length > 0) + { + // 关闭程序 + foreach (var process in processes) + { + process.Kill(); + process.WaitForExit(); // 等待程序退出 + Console.WriteLine($@"Closed existing instance of {program}"); + } + // 等待1秒 + Thread.Sleep(1000); + } + lblTips.Text = @"正在更新……"; + // 删除文件夹 + DelDirectory(); + // 解压路径是否存在 + if (Directory.Exists(unZipPath)) + { + // 获取解压文件下的第一个文件夹,避免 **/Update/UnZip/PEIS.exe || **/Update/UnZip/XxDirectory/PEIS.exe + var temp = Directory.GetDirectories(unZipPath, "*", SearchOption.AllDirectories).ToList() + ?.FirstOrDefault(); + if (File.Exists(Path.Combine(unZipPath, program))) + { + CopyFilesRecursively(unZipPath, Path.GetDirectoryName(CurrentPath)); + var sourceFilePath = Path.Combine(unZipPath, "PEIS.exe.config"); + var targetFilePath = Path.Combine(Path.GetDirectoryName(CurrentPath), "PEIS.exe.config"); + // 复制并替换指定文件 PEIS.exe.config + File.Copy(sourceFilePath, targetFilePath, true); + //删除压缩目录 + //Directory.Delete(unZipPath, true); + lblTips.Text = (@"更新完成,请重新启动!"); + //Process.Start(programPath); + } + else if (File.Exists(Path.Combine(temp, program))) + { + CopyFilesRecursively(temp, Path.GetDirectoryName(CurrentPath)); + var sourceFilePath = Path.Combine(temp, "PEIS.exe.config"); + var targetFilePath = Path.Combine(Path.GetDirectoryName(CurrentPath), "PEIS.exe.config"); + // 复制并替换指定文件 + File.Copy(sourceFilePath, targetFilePath, true); + lblTips.Text = (@"更新完成,请重新启动!"); + } + else + { + lblTips.Text = (@"未找到更新程序!"); + } + } + else + { + lblTips.Text = (@"未找到更新文件!"); + } + //Process.GetCurrentProcess().Kill(); + } + catch (Exception e) + { + lblTips.Text = (e.Message); + //Process.GetCurrentProcess().Kill(); + } + finally + { + ControlBox = true; + } + } + + /// + /// 文件复制替换 + /// + /// 原位置 + /// 目标位置 + private static void CopyFilesRecursively(string sourcePath, string targetPath) + { + //现在创建所有目录 + foreach (var dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) + { + if (dirPath == CurrentPath) continue; + if (dirPath.Contains("Update")) continue; + var dir = dirPath.Replace(sourcePath, targetPath); + Directory.CreateDirectory(dir); + } + //复制所有文件并替换所有同名文件 + foreach (var newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) + { + //File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true); + var newFilePath = newPath.Replace(sourcePath, targetPath); + var targetDirectory = Path.GetDirectoryName(newFilePath); + + if (newPath.Contains("Update.exe")) continue; + if (newFilePath.Contains("Update.exe")) continue; + // 如果目标文件夹不存在,则创建 + if (!Directory.Exists(targetDirectory)) + { + Directory.CreateDirectory(targetDirectory); + } + + File.Copy(newPath, newFilePath, true); + } + } + + + private static void DelDirectory() + { + var list = new List() + { + "de", + "es", + "ja", + "ru", + "nl", + "x64", + "x86", + }; + list.ForEach(item => + { + var path = Path.Combine( Path.GetDirectoryName(CurrentPath), item); + DeleteDirectory(path); + }); + } + + static void DeleteDirectory(string targetDir) + { + if (Directory.Exists(targetDir)) + { + string[] files = Directory.GetFiles(targetDir); + foreach (string file in files) + { + File.Delete(file); + } + string[] subDirs = Directory.GetDirectories(targetDir); + foreach (string subDir in subDirs) + { + DeleteDirectory(subDir); + } + Directory.Delete(targetDir); + } + } + } +} \ No newline at end of file diff --git a/Update/Form1.resx b/Update/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Update/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Update/Program.cs b/Update/Program.cs new file mode 100644 index 0000000..a64f644 --- /dev/null +++ b/Update/Program.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Windows.Forms; + +namespace Update +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + var program = "PEIS.exe"; + + // 检查程序是否正在运行 + Process[] processes = Process.GetProcessesByName(program); + + if (processes.Length > 0) + { + // 关闭程序 + foreach (var process in processes) + { + process.Kill(); + process.WaitForExit(); // 等待程序退出 + Console.WriteLine($@"Closed existing instance of {program}"); + } + + // 等待2秒 + Thread.Sleep(1000); + } + Application.Run(new Form1()); + } + } +} diff --git a/Update/Properties/AssemblyInfo.cs b/Update/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9d2771d --- /dev/null +++ b/Update/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Update")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Update")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("8894c92c-210d-459c-b5cd-7a6d2ab4cbe5")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Update/Properties/Resources.Designer.cs b/Update/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9156364 --- /dev/null +++ b/Update/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace Update.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Update.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap update { + get { + object obj = ResourceManager.GetObject("update", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Update/Properties/Resources.resx b/Update/Properties/Resources.resx new file mode 100644 index 0000000..3aa7d5a --- /dev/null +++ b/Update/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\update.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Update/Properties/Settings.Designer.cs b/Update/Properties/Settings.Designer.cs new file mode 100644 index 0000000..37ea7c8 --- /dev/null +++ b/Update/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Update.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Update/Properties/Settings.settings b/Update/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Update/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Update/Update.csproj b/Update/Update.csproj new file mode 100644 index 0000000..7726f31 --- /dev/null +++ b/Update/Update.csproj @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + {8894C92C-210D-459C-B5CD-7A6D2AB4CBE5} + WinExe + Update + Update + v4.0 + 512 + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + False + .NET Framework 3.5 SP1 + false + + + + + Always + + + + \ No newline at end of file diff --git a/Update/packages.config b/Update/packages.config new file mode 100644 index 0000000..362fa35 --- /dev/null +++ b/Update/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Update/update.png b/Update/update.png new file mode 100644 index 0000000..96948ce Binary files /dev/null and b/Update/update.png differ