├── .gitignore ├── LICENSE ├── README.md └── src ├── AutoUpgrade.sln ├── ComponentInfo.cs ├── Demo.Client ├── Demo.Client.csproj ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Demo.Updater ├── Demo.Updater.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Zl.AutoUpgrade.Core ├── AutoUpdater.cs ├── Exceptions.cs ├── IUpgradeService.cs ├── LogHelper.cs ├── Properties │ └── AssemblyInfo.cs ├── UpgradeCmdArg.cs ├── UpgradeConfig.cs ├── UpgradeService.cs ├── UpgradeStatus.cs ├── Zl.AutoUpgrade.Core.csproj ├── Zl.AutoUpgrade.Core.nuspec └── packages.config ├── Zl.AutoUpgrade.Shared ├── VersionService.cs ├── XmlSerializer.cs ├── Zl.AutoUpgrade.Shared.projitems └── Zl.AutoUpgrade.Shared.shproj └── Zl.AutoUpgrade.VersionInfoBuilder ├── FodyWeavers.xml ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── Zl.AutoUpgrade.VersionInfoBuilder.csproj ├── app.ico └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 ZengLong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoUpgrade [![Build status](https://ci.appveyor.com/api/projects/status/sfg236a8bp7kj2ns/branch/master?svg=true)](https://ci.appveyor.com/project/zenglong/autoupgrade/branch/master) [![NuGet](https://img.shields.io/nuget/v/Zl.AutoUpgrade.Core.svg)](https://www.nuget.org/packages/Zl.AutoUpgrade.Core) 2 | AutoUpgrade 是一个非常简单、轻量级的自动升级组件,以Ftp Server作为升级服务器,可自动升级托管的用户软件。 3 | AutoUpgrade 是用C#语言开发,基于 .Net Framework4.0 实现的,支持 Windows xp sp3 及以上版本的Windows系统。 4 | 5 | ## 组件组成 6 | AutoUpgrade 组件包含两个子组件。 7 | 8 | 子组件 | 对应的.Net项目 | 编译输出 | 说明 9 | ---------|----------|---------|--------- 10 | 升级组件 | Zl.AutoUpgrade.Core | Zl.AutoUpgrade.Core.dll | 升级功能类库,供升级程序调用来完成升级任务。 11 | 版本信息生成工具 | Zl.AutoUpgrade.VersionInfoBuilder | VersionInfoBuilder.exe | 命令行工具,用于给升级补丁文件生成可被升级组件识别的补丁版本信息,只有包含该工具生成的版本信息文件的升级补丁包才可被升级组件下载升级。 12 | 13 | ## 开发说明 14 | 要集成AutoUpgrade需要基于`Zl.AutoUpgrade.Core`实现一个升级程序,用户软件需与升级程序相互配合功能完成用户软件升级。 15 | 一般我们需要在用户软件启动时自动检测补丁及尝试升级,我们可以在用户软件启动时先启动升级程序尝试升级,升级程序升级结束后再重新启动用户软件。 16 | ### 1. 创建升级程序项目 17 | 首先,需要创建一个exe项目作为升级程序项目,该项目通过调用升级组件实现升级控制逻辑,该项目需要引用`Zl.AutoUpgrade.Core`,而不应该依赖任何用户软件项目(用户软件自身功能的相关项目),以免升级时会因正在运行而无法覆盖更新。 18 | 源码中`Demo.Updater`项目为升级程序示例项目,其中包含了升级进度监听和提示功能。 19 | 如下为比较简单的参考实现: 20 | ``` CSharp 21 | [STAThread] 22 | public static void Main(string[] args) 23 | { 24 | //如果已有升级程序正在运行则退出,避免多个进程同时升级 25 | if (AutoUpdater.IsUpdaterRunning()) 26 | { 27 | return; 28 | } 29 | //等待小会,避免用户软件尚未关闭而无法覆盖升级 30 | Thread.Sleep(1000); 31 | IUpgradeService upgradeService; 32 | //获取升级服务,该种方式的服务获取仅针对由用户软件内通过AutoUpdater.TryUpgrade启动的升级程序有效 33 | if (AutoUpdater.TryResolveUpgradeService(out upgradeService)) 34 | { 35 | //尝试升级 36 | upgradeService.TryUpgradeNow(); 37 | } 38 | //尝试升级结束,重新启动托管的用户软件 39 | AutoUpdater.RunManagedExe(); 40 | } 41 | ``` 42 | ### 2. 用户软件启动时自动升级 43 | 一般我们会在用户软件启动时进行一次自动升级,在用户软件的入口项目增加`Zl.AutoUpgrade.Core`引用,在入口的其实代码中调用尝试升级。 44 | 源码中`Demo.Client`项目为升级程序示例项目。 45 | 如下为参考实现: 46 | ``` CSharp 47 | [STAThread] 48 | public static void Main(string[] args) 49 | { 50 | try 51 | { 52 | var upgradeStatus = AutoUpdater.TryUpgrade(new UpgradeConfig() 53 | { 54 | FtpHost = "127.0.0.1", //ftp server 地址 55 | FtpUser = "zl",// ftp 用户名 56 | FtpPassword = "temp",// ftp 密码 57 | FtpOverTLS = true //是否基于TLS连接 58 | }, typeof(Demo.Updater.MainWindow).Assembly //升级程序exe位置或所在的程序集 59 | ); 60 | switch (upgradeStatus) 61 | { 62 | case UpgradeStatus.Started: 63 | case UpgradeStatus.Upgrading: 64 | //升级程序已启动,待升级程序升级结束后会再次启动当前exe,这里直接先结束当前exe 65 | return; 66 | case UpgradeStatus.NoNewVersion: 67 | MessageBox.Show("没有新版不需要升级,可继续运行了!"); 68 | break; 69 | case UpgradeStatus.Ended: 70 | MessageBox.Show("升级过程已结束,可继续运行了!"); 71 | break; 72 | default: 73 | break; 74 | } 75 | } 76 | catch (Exception exc) 77 | { 78 | MessageBox.Show("启动升级程序时遇到错误,跳过本次升级,继续运行!"); 79 | } 80 | //继续用户软件代码 81 | } 82 | ``` 83 | 84 | ## 升级补丁发布说明 85 | 升级补丁是只指某一新版本相对上一版本需要更新的或需要增加的程序文件和资源文件的集合。将升级补丁的所有文件放入升级服务器(ftp server)中即可发布。 86 | ### 1. 自动升级服务器搭建 87 | 自动升级功能将ftp服务器作为自动升级服务器,需搭建一个或使用已有的ftp server用于存储托管软件的升级补丁,作为升级组件的升级补丁包源。 88 | 创建一个只读ftp账号,后续如果有升级补丁,将补丁文件及`VersionInfoBuilder.exe`生成的版本信息文件放置在该ftp账根目录中即完成了补丁发布。 89 | 90 | ### 2. 生成版本信息文件 91 | 升级补丁文件必须通过`VersionInfoBuilder.exe`工具生成对应的版本信息文件后才可被升级组件正常升级。 92 | `VersionInfoBuilder.exe`是一个命令行工具,最简单生成版本信息文件的方式是直接将VersionInfoBuilder.exe放入升级补丁文件所在文件夹,双击运行VersionInfoBuilder.exe即可自动生成。 93 | VersionInfoBuilder.exe包含的参数如下: 94 | 95 | 参数 | 说明 96 | ------- | ------- 97 | [/TargetFolder\|/T] | 要生成版本文件的目标文件夹,生成版本文件后的文件夹才可作为升级包供升级 98 | [/SecretKey\|/S] | 版本信息秘钥,客户端只有与本生成器使用的秘钥一致时才可正常升级本生成器生成的版本升级包 99 | [/Ignore\|/I] | 目标文件夹中要忽略的文件,多个用空格间隔 100 | [/Help\|/H] | 查看帮助 101 | 102 | 也可在命令行中运行`VersionInfoBuilder.exe /H`查看参数帮助。 103 | **注意:不应该将`Zl.AutoUpgrade.Core.dll`和自建的升级程序项目作为升级补丁的一部分,否则会因这两个dll被升级过程运行时依赖而导致总是无法被覆盖升级,从而导致升级失败。** 104 | -------------------------------------------------------------------------------- /src/AutoUpgrade.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2006 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zl.AutoUpgrade.Core", "Zl.AutoUpgrade.Core\Zl.AutoUpgrade.Core.csproj", "{A58CBF69-20A5-4C92-B47C-5C28C3E736F5}" 7 | EndProject 8 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Zl.AutoUpgrade.Shared", "Zl.AutoUpgrade.Shared\Zl.AutoUpgrade.Shared.shproj", "{1618087A-3CB4-45FA-84FF-1EA8B16BF7B6}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1.Common", "1.Common", "{35C59932-3931-403D-AABA-80D81FD22FB0}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.ForClient", "2.ForClient", "{77BA2A67-E3EC-4EAF-9C79-1874E4DF2F7A}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.ForServer", "3.ForServer", "{DEAF28E9-C2E3-4FA3-ABFA-5846B64B3D63}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zl.AutoUpgrade.VersionInfoBuilder", "Zl.AutoUpgrade.VersionInfoBuilder\Zl.AutoUpgrade.VersionInfoBuilder.csproj", "{BF0BC324-A831-4316-A64A-F05BC2346C4A}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4.Demo", "4.Demo", "{5BF4FD96-9033-41C8-B98B-561957F10789}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo.Updater", "Demo.Updater\Demo.Updater.csproj", "{9E4104B6-64D3-4606-9A27-EF66F4F66580}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo.Client", "Demo.Client\Demo.Client.csproj", "{D69BCB79-8AF8-4FF2-B036-04F1AFB65054}" 23 | EndProject 24 | Global 25 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 26 | Zl.AutoUpgrade.Shared\Zl.AutoUpgrade.Shared.projitems*{1618087a-3cb4-45fa-84ff-1ea8b16bf7b6}*SharedItemsImports = 13 27 | Zl.AutoUpgrade.Shared\Zl.AutoUpgrade.Shared.projitems*{a58cbf69-20a5-4c92-b47c-5c28c3e736f5}*SharedItemsImports = 4 28 | Zl.AutoUpgrade.Shared\Zl.AutoUpgrade.Shared.projitems*{bf0bc324-a831-4316-a64a-f05bc2346c4a}*SharedItemsImports = 4 29 | EndGlobalSection 30 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 31 | Debug|Any CPU = Debug|Any CPU 32 | Release|Any CPU = Release|Any CPU 33 | EndGlobalSection 34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 35 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {BF0BC324-A831-4316-A64A-F05BC2346C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {BF0BC324-A831-4316-A64A-F05BC2346C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {BF0BC324-A831-4316-A64A-F05BC2346C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {BF0BC324-A831-4316-A64A-F05BC2346C4A}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {9E4104B6-64D3-4606-9A27-EF66F4F66580}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {9E4104B6-64D3-4606-9A27-EF66F4F66580}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {9E4104B6-64D3-4606-9A27-EF66F4F66580}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {9E4104B6-64D3-4606-9A27-EF66F4F66580}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | GlobalSection(NestedProjects) = preSolution 56 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5} = {77BA2A67-E3EC-4EAF-9C79-1874E4DF2F7A} 57 | {1618087A-3CB4-45FA-84FF-1EA8B16BF7B6} = {35C59932-3931-403D-AABA-80D81FD22FB0} 58 | {BF0BC324-A831-4316-A64A-F05BC2346C4A} = {DEAF28E9-C2E3-4FA3-ABFA-5846B64B3D63} 59 | {9E4104B6-64D3-4606-9A27-EF66F4F66580} = {5BF4FD96-9033-41C8-B98B-561957F10789} 60 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054} = {5BF4FD96-9033-41C8-B98B-561957F10789} 61 | EndGlobalSection 62 | GlobalSection(ExtensibilityGlobals) = postSolution 63 | SolutionGuid = {0F8E21A1-252B-45D5-8FF7-55487E849BC8} 64 | EndGlobalSection 65 | EndGlobal 66 | -------------------------------------------------------------------------------- /src/ComponentInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | 4 | [assembly: AssemblyCompany("ZengLong")] 5 | [assembly: AssemblyProduct("AutoUpgrade")] 6 | [assembly: AssemblyCopyright("Copyright © 2017 ZengLong")] 7 | [assembly: AssemblyTrademark("Zl")] 8 | [assembly: AssemblyCulture("")] 9 | 10 | // 程序集的版本信息由下列四个值组成: 11 | // 12 | // 主版本 13 | // 次版本 14 | // 生成号 15 | // 修订号 16 | // 17 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 18 | // 方法是按如下所示使用“*”: : 19 | // [assembly: AssemblyVersion("1.0.*")] 20 | [assembly: AssemblyVersion("1.1.0.0")] 21 | [assembly: AssemblyFileVersion("1.1.0.0")] 22 | -------------------------------------------------------------------------------- /src/Demo.Client/Demo.Client.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D69BCB79-8AF8-4FF2-B036-04F1AFB65054} 8 | WinExe 9 | Demo.Client 10 | Demo.Client 11 | v4.0 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | Demo.Client.Program 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 4.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Code 57 | 58 | 59 | True 60 | True 61 | Resources.resx 62 | 63 | 64 | True 65 | Settings.settings 66 | True 67 | 68 | 69 | ResXFileCodeGenerator 70 | Resources.Designer.cs 71 | 72 | 73 | SettingsSingleFileGenerator 74 | Settings.Designer.cs 75 | 76 | 77 | 78 | 79 | {9e4104b6-64d3-4606-9a27-ef66f4f66580} 80 | Demo.Updater 81 | 82 | 83 | {A58CBF69-20A5-4C92-B47C-5C28C3E736F5} 84 | Zl.AutoUpgrade.Core 85 | 86 | 87 | 88 | 89 | $(ProjectDir)..\Zl.AutoUpgrade.VersionInfoBuilder\$(OutDir)VersionInfoBuilder.exe /t $(TargetDir) /i Demo.Updater 90 | 91 | -------------------------------------------------------------------------------- /src/Demo.Client/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using Zl.AutoUpgrade.Core; 11 | 12 | namespace Demo.Client 13 | { 14 | class Program 15 | { 16 | [STAThread] 17 | public static void Main(string[] args) 18 | { 19 | try 20 | { 21 | var upgradeStatus = AutoUpdater.TryUpgrade(new UpgradeConfig() 22 | { 23 | FtpHost = "127.0.0.1", //ftp server 地址 24 | FtpUser = "zl",// ftp 用户名 25 | FtpPassword = "temp",// ftp 密码 26 | FtpOverTLS = true //是否基于TLS连接 27 | }, typeof(Demo.Updater.MainWindow).Assembly //升级程序exe位置或所在的程序集 28 | ); 29 | switch (upgradeStatus) 30 | { 31 | case UpgradeStatus.Started: 32 | case UpgradeStatus.Upgrading: 33 | //升级程序已启动,待升级程序升级结束后会再次启动当前exe,这里直接先结束当前exe 34 | return; 35 | case UpgradeStatus.NoNewVersion: 36 | MessageBox.Show("没有新版不需要升级,可继续运行了!"); 37 | break; 38 | case UpgradeStatus.Ended: 39 | MessageBox.Show("升级过程已结束,可继续运行了!"); 40 | break; 41 | default: 42 | break; 43 | } 44 | } 45 | catch (Exception exc) 46 | { 47 | MessageBox.Show("启动升级程序时遇到错误,跳过本次升级,继续运行!"); 48 | } 49 | //继续用户软件代码 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Demo.Client/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("Demo.Client")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("Demo.Client")] 15 | [assembly: AssemblyCopyright("Copyright © 2017")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 52 | // 方法是按如下所示使用“*”: : 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /src/Demo.Client/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Demo.Client.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Demo.Client.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Demo.Client/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /src/Demo.Client/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Demo.Client.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Demo.Client/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Demo.Updater/Demo.Updater.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9E4104B6-64D3-4606-9A27-EF66F4F66580} 8 | WinExe 9 | Demo.Updater 10 | Demo.Updater 11 | v4.0 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | Demo.Updater.Program 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 4.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | MSBuild:Compile 56 | Designer 57 | 58 | 59 | MainWindow.xaml 60 | Code 61 | 62 | 63 | 64 | 65 | 66 | Code 67 | 68 | 69 | True 70 | True 71 | Resources.resx 72 | 73 | 74 | True 75 | Settings.settings 76 | True 77 | 78 | 79 | ResXFileCodeGenerator 80 | Resources.Designer.cs 81 | 82 | 83 | SettingsSingleFileGenerator 84 | Settings.Designer.cs 85 | 86 | 87 | 88 | 89 | {a58cbf69-20a5-4c92-b47c-5c28c3e736f5} 90 | Zl.AutoUpgrade.Core 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/Demo.Updater/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 |