Browse Source

调整更新为完全插件模式

yuzhengyang 8 years ago
parent
commit
68e37ed864
41 changed files with 2673 additions and 302 deletions
  1. 3 3
      Fork.Net/Oreo.VersionBuilder/App.config
  2. 3 1
      Fork.Net/Oreo.VersionBuilder/Oreo.VersionBuilder.csproj
  3. 25 33
      Fork.Net/Oreo.VersionBuilder/Properties/Resources.Designer.cs
  4. 13 17
      Fork.Net/Oreo.VersionBuilder/Properties/Settings.Designer.cs
  5. 3 3
      Fork.Net/Oreo.VersionUpdate/App.config
  6. 0 1
      Fork.Net/Oreo.VersionUpdate/Commons/P.cs
  7. 5 7
      Fork.Net/Oreo.VersionUpdate/Commons/R.cs
  8. 4 0
      Fork.Net/Oreo.VersionUpdate/FodyWeavers.xml
  9. 148 0
      Fork.Net/Oreo.VersionUpdate/Helpers/DataHelper.cs
  10. 36 0
      Fork.Net/Oreo.VersionUpdate/Helpers/FileHelper.cs
  11. BIN
      Fork.Net/Oreo.VersionUpdate/Images/Icons/app.ico
  12. 1 0
      Fork.Net/Oreo.VersionUpdate/Models/PluginModel.cs
  13. 19 0
      Fork.Net/Oreo.VersionUpdate/Models/VersionModel.cs
  14. 32 2
      Fork.Net/Oreo.VersionUpdate/Oreo.VersionUpdate.csproj
  15. 10 5
      Fork.Net/Oreo.VersionUpdate/Program.cs
  16. 25 33
      Fork.Net/Oreo.VersionUpdate/Properties/Resources.Designer.cs
  17. 13 17
      Fork.Net/Oreo.VersionUpdate/Properties/Settings.Designer.cs
  18. 2 0
      Fork.Net/Oreo.VersionUpdate/Views/MainForm.Designer.cs
  19. 136 180
      Fork.Net/Oreo.VersionUpdate/Views/MainForm.cs
  20. 2005 0
      Fork.Net/Oreo.VersionUpdate/Views/MainForm.resx
  21. 5 0
      Fork.Net/Oreo.VersionUpdate/packages.config
  22. 12 0
      Fork.Net/Y.Utils/IOUtils/TxtUtils/XmlTool.cs
  23. 24 0
      Fork.Net/Y.Utils/WindowsUtils/ProcessUtils/ProcessTool.cs
  24. 1 0
      Fork.Net/Y.Utils/Y.Utils.csproj
  25. BIN
      Fork.Net/packages/Costura.Fody.1.6.0/Costura.Fody.1.6.0.nupkg
  26. BIN
      Fork.Net/packages/Costura.Fody.1.6.0/Costura.Fody.dll
  27. BIN
      Fork.Net/packages/Costura.Fody.1.6.0/Costura.Tasks.dll
  28. BIN
      Fork.Net/packages/Costura.Fody.1.6.0/lib/dotnet/Costura.dll
  29. BIN
      Fork.Net/packages/Costura.Fody.1.6.0/lib/portable-net+sl+win+wpa+wp/Costura.dll
  30. 94 0
      Fork.Net/packages/Costura.Fody.1.6.0/tools/install.ps1
  31. 47 0
      Fork.Net/packages/Costura.Fody.1.6.0/tools/uninstall.ps1
  32. 4 0
      Fork.Net/packages/Fody.2.0.0/Content/FodyWeavers.xml
  33. BIN
      Fork.Net/packages/Fody.2.0.0/Fody.2.0.0.nupkg
  34. BIN
      Fork.Net/packages/Fody.2.0.0/Fody.dll
  35. BIN
      Fork.Net/packages/Fody.2.0.0/FodyCommon.dll
  36. BIN
      Fork.Net/packages/Fody.2.0.0/FodyIsolated.dll
  37. BIN
      Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Mdb.dll
  38. BIN
      Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Pdb.dll
  39. BIN
      Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Rocks.dll
  40. BIN
      Fork.Net/packages/Fody.2.0.0/Mono.Cecil.dll
  41. 3 0
      Fork.Net/packages/Fody.2.0.0/Tools/install.ps1

+ 3 - 3
Fork.Net/Oreo.VersionBuilder/App.config

@@ -1,6 +1,6 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     </startup>
-</configuration>
+</configuration>

+ 3 - 1
Fork.Net/Oreo.VersionBuilder/Oreo.VersionBuilder.csproj

@@ -9,9 +9,10 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Oreo.VersionBuilder</RootNamespace>
     <AssemblyName>Oreo.VersionBuilder</AssemblyName>
-    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -74,6 +75,7 @@
     <Compile Include="Properties\Resources.Designer.cs">
       <AutoGen>True</AutoGen>
       <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
     </Compile>
     <EmbeddedResource Include="Views\MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>

+ 25 - 33
Fork.Net/Oreo.VersionBuilder/Properties/Resources.Designer.cs

@@ -1,69 +1,61 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     此代码由工具生成。
-//     运行时版本: 4.0.30319.42000
+//     运行时版本:4.0.30319.42000
 //
-//     对此文件的更改可能导致不正确的行为,如果
-//     重新生成代码,则所做更改将丢失。
+//     对此文件的更改可能导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Oreo.VersionBuilder.Properties
-{
-
-
+namespace Oreo.VersionBuilder.Properties {
+    using System;
+    
+    
     /// <summary>
-    ///   强类型资源类,用于查找本地化字符串等。
+    ///   一个强类型资源类,用于查找本地化字符串等。
     /// </summary>
     // 此类是由 StronglyTypedResourceBuilder
     // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
-    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
     // (以 /str 作为命令选项),或重新生成 VS 项目。
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    internal class Resources
-    {
-
+    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()
-        {
+        internal Resources() {
         }
-
+        
         /// <summary>
-        ///   返回此类使用的缓存 ResourceManager 实例。
+        ///   返回此类使用的缓存 ResourceManager 实例。
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Resources.ResourceManager ResourceManager
-        {
-            get
-            {
-                if ((resourceMan == null))
-                {
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Oreo.VersionBuilder.Properties.Resources", typeof(Resources).Assembly);
                     resourceMan = temp;
                 }
                 return resourceMan;
             }
         }
-
+        
         /// <summary>
-        ///   覆盖当前线程的 CurrentUICulture 属性
-        ///   使用此强类型的资源类的资源查找
+        ///   使用此强类型资源类,为所有资源查找
+        ///   重写当前线程的 CurrentUICulture 属性
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Globalization.CultureInfo Culture
-        {
-            get
-            {
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
                 return resourceCulture;
             }
-            set
-            {
+            set {
                 resourceCulture = value;
             }
         }

+ 13 - 17
Fork.Net/Oreo.VersionBuilder/Properties/Settings.Designer.cs

@@ -1,28 +1,24 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
 //
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Oreo.VersionBuilder.Properties
-{
-
-
+namespace Oreo.VersionBuilder.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
-    {
-
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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
-            {
+        
+        public static Settings Default {
+            get {
                 return defaultInstance;
             }
         }

+ 3 - 3
Fork.Net/Oreo.VersionUpdate/App.config

@@ -1,6 +1,6 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     </startup>
-</configuration>
+</configuration>

+ 0 - 1
Fork.Net/Oreo.VersionUpdate/Commons/P.cs

@@ -18,7 +18,6 @@ namespace Oreo.VersionUpdate.Commons
         }
         static void InitSettings()
         {
-            IniTool.GetStringValue(R.Files.Settings, "Version", "Number", R.Settings.Version.Number);
             R.LogLevel = (LogLevel)IniTool.GetIntValue(R.Files.Settings, "Log", "Level");
         }
         static void InitLog()

+ 5 - 7
Fork.Net/Oreo.VersionUpdate/Commons/R.cs

@@ -22,20 +22,18 @@ namespace Oreo.VersionUpdate.Commons
         public static class Paths
         {
             public static string App = AppDomain.CurrentDomain.BaseDirectory;
-            public static string Temp = App + "Temp\\";
+            public static string ProjectRoot = AppDomain.CurrentDomain.BaseDirectory;
+            public static string Temp = ProjectRoot + "Temp\\";
         }
         public static class Files
         {
             public static string App = Application.ExecutablePath;
-            public static string Settings = Paths.App + "\\upd.ini";
-            public static string Whatsnew = Paths.App + "\\Whatsnew.txt";
+            public static string Settings = Paths.ProjectRoot + "\\upd.ini";
+            public static string Whatsnew = Paths.ProjectRoot + "\\Whatsnew.txt";
+            public static string Plugins = "";
         }
         public static class Settings
         {
-            public static class Version
-            {
-                public static string Number = "0.0.0.0";
-            }
             public static class FTP
             {
                 public static string Address = "192.168.3.56";

+ 4 - 0
Fork.Net/Oreo.VersionUpdate/FodyWeavers.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Weavers>
+  <Costura />
+</Weavers>

+ 148 - 0
Fork.Net/Oreo.VersionUpdate/Helpers/DataHelper.cs

@@ -0,0 +1,148 @@
+using Oreo.VersionUpdate.Commons;
+using Oreo.VersionUpdate.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+using Y.Utils.DataUtils.Collections;
+using Y.Utils.DataUtils.JsonUtils;
+using Y.Utils.IOUtils.TxtUtils;
+using Y.Utils.WindowsUtils.InfoUtils;
+
+namespace Oreo.VersionUpdate.Helpers
+{
+    public class DataHelper
+    {
+        /// <summary>
+        /// 获取要更新的插件列表
+        /// </summary>
+        /// <returns></returns>
+        public static List<PluginModel> GetPluginList()
+        {
+            #region 读取本地插件列表
+            List<PluginModel> localPluginList = new List<PluginModel>();
+            try
+            {
+                XElement xe = XElement.Load(R.Files.Plugins);
+                IEnumerable<XElement> elements = xe.Elements("Item");
+                if (ListTool.HasElements(elements))
+                {
+                    foreach (var ele in elements)
+                    {
+                        PluginModel plug = new PluginModel()
+                        {
+                            Name = ele.Attribute("Name").Value,
+                            Entry = ele.Attribute("Entry").Value,
+                            Version = ele.Attribute("Version").Value
+                        };
+                        localPluginList.Add(plug);
+                    }
+                }
+            }
+            catch (Exception e) { }
+            #endregion
+            #region 读取服务器插件列表
+            List<PluginModel> serverPluginList = new List<PluginModel>()
+            {
+                new PluginModel() { Name="yo",Version=Guid.NewGuid().ToString(),Entry="C:\\aa"},
+                new PluginModel() { Name="yooo2",Version=Guid.NewGuid().ToString(),Entry="C:\\ab"}
+            };
+            #endregion
+            #region 整理需要更新的插件列表
+            List<PluginModel> rs = new List<PluginModel>();
+            if (ListTool.HasElements(serverPluginList))
+            {
+                serverPluginList.ForEach(p =>
+                {
+                    var tmp = localPluginList.FirstOrDefault(x => x.Name == p.Name);
+                    if (tmp == null)
+                    {
+                        //如果服务器有的插件,本地没有,则添加至需要更新的列表
+                        rs.Add(p);
+                    }
+                    else
+                    {
+                        if (tmp.Version != p.Version)
+                        {
+                            //如果服务器插件版本和本机插件版本不同,则添加至需要更新列表
+                            rs.Add(p);
+                        }
+                    }
+                });
+            }
+            #endregion
+            return rs;
+        }
+        /// <summary>
+        /// 联网获取插件的最新版本
+        /// </summary>
+        /// <param name="pm"></param>
+        /// <returns></returns>
+        public static VersionModel GetPluginNewVersion(PluginModel pm)
+        {
+            VersionModel rs = JsonTool.ToObjFromFile<VersionModel>(@"D:\CoCo\GitHub\Fork\Fork.Net\Oreo.VersionBuilder\bin\Debug\VersionFile\0527112916.version");
+            return rs;
+        }
+        /// <summary>
+        /// 写入 Whatsnew
+        /// </summary>
+        /// <param name="vm"></param>
+        public static void UpdateWhatsnew(VersionModel vm)
+        {
+            TxtTool.Append(R.Files.Whatsnew, string.Format("{0} {1} {2}",
+            vm.CodeName, vm.VersionNumber, (vm.PluginName == "" ? "" : "For:" + vm.PluginName)));
+            TxtTool.Append(R.Files.Whatsnew, vm.VersionDesc);
+            TxtTool.Append(R.Files.Whatsnew, new string('=', 50));
+        }
+        /// <summary>
+        /// 写入更新配置文件
+        /// </summary>
+        /// <param name="vm"></param>
+        public static void UpdatePluginConfig(VersionModel vm)
+        {
+            if (!string.IsNullOrWhiteSpace(vm.PluginName) && !string.IsNullOrWhiteSpace(vm.PluginEntry))
+            {
+                //插入更新的插件配置
+                XElement insertXE = XElement.Load(R.Files.Plugins);
+                XElement record = new XElement("Item", new XAttribute("Name", vm.PluginName), new XAttribute("Entry", vm.PluginEntry), new XAttribute("Version", vm.VersionNumber));
+                insertXE.Add(record);
+                insertXE.Save(R.Files.Plugins);
+                //删除老版本插件配置
+                XElement deleteXE = XElement.Load(R.Files.Plugins);
+                IEnumerable<XElement> elements = from ele in deleteXE.Elements("book")
+                                                 where (string)ele.Attribute("ISBN") == id
+                                                 select ele;
+                {
+                    if (elements.Count() > 0)
+                        elements.First().Remove();
+                }
+                deleteXE.Save(R.Files.Plugins);
+            }
+        }
+        /// <summary>
+        /// 更新注册表项
+        /// </summary>
+        /// <param name="vm"></param>
+        private static void UpdateRegister(List<VersionRegister> vr)
+        {
+            if (ListTool.HasElements(vr))
+            {
+                foreach (var r in vr)
+                {
+                    if (r.IsClean)
+                    {
+                        //删除该注册表项
+                        RegisterTool.DeleteValue(r.Key, r.Name);
+                    }
+                    else
+                    {
+                        //添加或修改该注册表项
+                        RegisterTool.SetValue(r.Key, r.Name, r.Value);
+                    }
+                }
+            }
+        }
+    }
+}

+ 36 - 0
Fork.Net/Oreo.VersionUpdate/Helpers/FileHelper.cs

@@ -0,0 +1,36 @@
+using Oreo.VersionUpdate.Commons;
+using Oreo.VersionUpdate.Models;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Y.Utils.IOUtils.PathUtils;
+using Y.Utils.IOUtils.TxtUtils;
+
+namespace Oreo.VersionUpdate.Helpers
+{
+    public class FileHelper
+    {
+        public static void Clean(VersionModel vm)
+        {
+            //清理临时文件夹
+            if (Directory.Exists(R.Paths.Temp))
+            {
+                try { Directory.Delete(R.Paths.Temp, true); } catch { }
+            }
+            //清理指定文件
+            var cleanFile = vm.FileList.Where(x => x.IsClean == true);
+            foreach (var file in cleanFile)
+            {
+                string fff = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : R.Paths.ProjectRoot + file.LocalFile;
+                if (File.Exists(fff))
+                {
+                    try { File.Delete(fff); } catch { }
+                }
+            }
+        }
+     
+    }
+}

BIN
Fork.Net/Oreo.VersionUpdate/Images/Icons/app.ico


+ 1 - 0
Fork.Net/Oreo.VersionUpdate/Models/PluginModel.cs

@@ -10,5 +10,6 @@ namespace Oreo.VersionUpdate.Models
     {
         public string Name { get; set; }
         public string Version { get; set; }
+        public string Entry { get; set; }
     }
 }

+ 19 - 0
Fork.Net/Oreo.VersionUpdate/Models/VersionModel.cs

@@ -68,4 +68,23 @@ namespace Oreo.VersionUpdate.Models
         /// </summary>
         public bool IsClean { get; set; }
     }
+    public class VersionRegister
+    {
+        /// <summary>
+        /// 注册表键(路径)
+        /// </summary>
+        public string Key { get; set; }
+        /// <summary>
+        /// 注册表项(名称)
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 注册表值
+        /// </summary>
+        public string Value { get; set; }
+        /// <summary>
+        /// 是否清理该项
+        /// </summary>
+        public bool IsClean { get; set; }
+    }
 }

+ 32 - 2
Fork.Net/Oreo.VersionUpdate/Oreo.VersionUpdate.csproj

@@ -9,9 +9,12 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Oreo.VersionUpdate</RootNamespace>
     <AssemblyName>Oreo.VersionUpdate</AssemblyName>
-    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -21,7 +24,7 @@
     <OutputPath>bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
+    <WarningLevel>3</WarningLevel>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,7 +35,14 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup>
+    <ApplicationIcon>Images\Icons\app.ico</ApplicationIcon>
+  </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Costura, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\Costura.Fody.1.6.0\lib\dotnet\Costura.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
     <Reference Include="Newtonsoft.Json">
       <HintPath>..\Dlls\Fork.Net\Newtonsoft.Json.dll</HintPath>
     </Reference>
@@ -54,6 +64,8 @@
   <ItemGroup>
     <Compile Include="Commons\P.cs" />
     <Compile Include="Commons\R.cs" />
+    <Compile Include="Helpers\DataHelper.cs" />
+    <Compile Include="Helpers\FileHelper.cs" />
     <Compile Include="Models\PluginModel.cs" />
     <Compile Include="Models\VersionModel.cs" />
     <Compile Include="Program.cs" />
@@ -72,10 +84,12 @@
     <Compile Include="Properties\Resources.Designer.cs">
       <AutoGen>True</AutoGen>
       <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
     </Compile>
     <EmbeddedResource Include="Views\MainForm.resx">
       <DependentUpon>MainForm.cs</DependentUpon>
     </EmbeddedResource>
+    <None Include="packages.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -95,7 +109,23 @@
       <Name>Y.Utils</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="FodyWeavers.xml" />
+    <Content Include="Images\Icons\app.ico" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Images\Backgrounds\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="..\packages\Fody.2.0.0\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.0\build\dotnet\Fody.targets'))" />
+    <Error Condition="!Exists('..\packages\Costura.Fody.1.6.0\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.6.0\build\dotnet\Costura.Fody.targets'))" />
+  </Target>
+  <Import Project="..\packages\Costura.Fody.1.6.0\build\dotnet\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.6.0\build\dotnet\Costura.Fody.targets')" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">

+ 10 - 5
Fork.Net/Oreo.VersionUpdate/Program.cs

@@ -14,12 +14,17 @@ namespace Oreo.VersionUpdate
         /// 应用程序的主入口点。
         /// </summary>
         [STAThread]
-        static void Main()
+        static void Main(string[] args)
         {
-            P.Init();
-            Application.EnableVisualStyles();
-            Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new MainForm());
+            if (args != null && args.Length == 2)
+            {
+                R.Paths.ProjectRoot = args[0];
+                R.Files.Plugins = args[1];
+                P.Init();
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                Application.Run(new MainForm());
+            }
         }
     }
 }

+ 25 - 33
Fork.Net/Oreo.VersionUpdate/Properties/Resources.Designer.cs

@@ -1,69 +1,61 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     此代码由工具生成。
-//     运行时版本: 4.0.30319.42000
+//     运行时版本:4.0.30319.42000
 //
-//     对此文件的更改可能导致不正确的行为,如果
-//     重新生成代码,则所做更改将丢失。
+//     对此文件的更改可能导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Oreo.VersionUpdate.Properties
-{
-
-
+namespace Oreo.VersionUpdate.Properties {
+    using System;
+    
+    
     /// <summary>
-    ///   强类型资源类,用于查找本地化字符串等。
+    ///   一个强类型资源类,用于查找本地化字符串等。
     /// </summary>
     // 此类是由 StronglyTypedResourceBuilder
     // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
-    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
     // (以 /str 作为命令选项),或重新生成 VS 项目。
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    internal class Resources
-    {
-
+    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()
-        {
+        internal Resources() {
         }
-
+        
         /// <summary>
-        ///   返回此类使用的缓存 ResourceManager 实例。
+        ///   返回此类使用的缓存 ResourceManager 实例。
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Resources.ResourceManager ResourceManager
-        {
-            get
-            {
-                if ((resourceMan == null))
-                {
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Oreo.VersionUpdate.Properties.Resources", typeof(Resources).Assembly);
                     resourceMan = temp;
                 }
                 return resourceMan;
             }
         }
-
+        
         /// <summary>
-        ///   覆盖当前线程的 CurrentUICulture 属性
-        ///   使用此强类型的资源类的资源查找
+        ///   使用此强类型资源类,为所有资源查找
+        ///   重写当前线程的 CurrentUICulture 属性
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Globalization.CultureInfo Culture
-        {
-            get
-            {
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
                 return resourceCulture;
             }
-            set
-            {
+            set {
                 resourceCulture = value;
             }
         }

+ 13 - 17
Fork.Net/Oreo.VersionUpdate/Properties/Settings.Designer.cs

@@ -1,28 +1,24 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
 //
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Oreo.VersionUpdate.Properties
-{
-
-
+namespace Oreo.VersionUpdate.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
-    {
-
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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
-            {
+        
+        public static Settings Default {
+            get {
                 return defaultInstance;
             }
         }

+ 2 - 0
Fork.Net/Oreo.VersionUpdate/Views/MainForm.Designer.cs

@@ -28,6 +28,7 @@
         /// </summary>
         private void InitializeComponent()
         {
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
             this.label2 = new System.Windows.Forms.Label();
             this.label3 = new System.Windows.Forms.Label();
             this.LbVersionNumber = new System.Windows.Forms.Label();
@@ -136,6 +137,7 @@
             this.Controls.Add(this.label3);
             this.Controls.Add(this.label2);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
             this.MaximizeBox = false;
             this.MinimizeBox = false;
             this.Name = "MainForm";

+ 136 - 180
Fork.Net/Oreo.VersionUpdate/Views/MainForm.cs

@@ -1,4 +1,5 @@
 using Oreo.VersionUpdate.Commons;
+using Oreo.VersionUpdate.Helpers;
 using Oreo.VersionUpdate.Models;
 using System;
 using System.Collections.Generic;
@@ -27,7 +28,8 @@ namespace Oreo.VersionUpdate.Views
 
         string VersionNumber = "";
         string VersionDesc = "";
-        string TempFile = "Temp";
+        string DownTemp = "DownTemp";
+        string BackupTemp = "BackupTemp";
 
         public MainForm()
         {
@@ -41,129 +43,81 @@ namespace Oreo.VersionUpdate.Views
         {
             Task.Factory.StartNew(() =>
             {
-                //读取标准更新最新版本号 获取需要标准更新的配置
-                StartUpdateStandard();
-
-                //使用本地插件名称和版本号 获取需要更新插件的配置
-                StartUpdatePlugin();
-            });
-        }
-        private void StartUpdateStandard()
-        {
-            R.Log.i("读取本地标准更新版本号");
-            string versionNumber = GetStandardVersionNumber();
-            R.Log.i("读取当前标准版本 " + versionNumber + ",准备请求服务器新版本");
-            VersionModel standardNewVersion = GetStandardNewVersion(versionNumber);
-            if (standardNewVersion != null)
-            {
-                R.Log.i("有新的更新,版本号 " + standardNewVersion.VersionNumber);
-                bool flag = Update(standardNewVersion);
-                if (flag)
-                {
-                    R.Log.i(versionNumber + " 更新成功,当前版本" + standardNewVersion.VersionNumber);
-                }
-                else
-                {
-                    R.Log.w(versionNumber + " 更新失败");
-                }
-            }
-            else
-            {
-                R.Log.i("当前标准版本为最新,不需要更新");
-            }
-        }
-        private void StartUpdatePlugin()
-        {
-            R.Log.i("读取本地插件列表(名称、版本号)");
-            List<PluginModel> pluginList = GetPluginList();
-            if (ListTool.HasElements(pluginList))
-            {
-                R.Log.i("共读取到 " + pluginList.Count + " 个插件");
-                pluginList.ForEach(x =>
+                R.Log.i("读取要更新的插件列表");
+                List<PluginModel> pluginList = DataHelper.GetPluginList();
+                if (ListTool.HasElements(pluginList))
                 {
-                    R.Log.i("请求 " + x.Name + " / " + x.Version + " 插件的更新");
-                    VersionModel pluginNewVersion = GetPluginNewVersion(x);
-                    if (pluginNewVersion != null)
+                    R.Log.i("共读取到 " + pluginList.Count + " 个插件");
+                    pluginList.ForEach(x =>
                     {
-                        R.Log.i(x.Name + " / " + x.Version + " 插件有新版本 " + pluginNewVersion.VersionNumber + " 需要更新,准备更新");
-                        bool flag = Update(pluginNewVersion);
-                        if (flag)
+                        R.Log.i("请求 " + x.Name + " / " + x.Version + " 插件的更新");
+                        VersionModel pluginNewVersion = DataHelper.GetPluginNewVersion(x);
+                        if (pluginNewVersion != null)
                         {
-                            R.Log.i(x.Name + " 更新成功,当前版本" + pluginNewVersion.VersionNumber);
+                            R.Log.i("准备更新 " + x.Name);
+                            BeforeUpdate(pluginNewVersion);//更新前操作
+                            bool flag = Update(pluginNewVersion);
+                            AfterUpdate(pluginNewVersion);//更新后操作
+                            if (flag)
+                            {
+                                R.Log.i(x.Name + " 更新成功,当前版本" + pluginNewVersion.VersionNumber);
+                            }
+                            else
+                            {
+                                R.Log.w(x.Name + " 更新失败");
+                            }
                         }
                         else
                         {
-                            R.Log.w(x.Name + " 更新失败");
+                            R.Log.i("更新配置请求失败,跳过当前更新");
                         }
-                    }
-                    else
-                    {
-                        R.Log.i("当前插件版本为最新版本,不需要更新");
-                    }
-                });
-            }
-            else
-            {
-                R.Log.w("本地插件列表为空");
-            }
-            R.Log.i("本地插件更新操作结束");
-        }
-        #region 读取本地数据操作
-        private List<PluginModel> GetPluginList()
-        {
-            List<PluginModel> rs = null;
-            return rs;
-        }
-        private string GetStandardVersionNumber()
-        {
-            string rs = R.Settings.Version.Number;
-            return rs;
-        }
-        #endregion
-        #region 读取网络数据操作
-        private VersionModel GetStandardNewVersion(string vn)
-        {
-            VersionModel rs = JsonTool.ToObjFromFile<VersionModel>(@"D:\CoCo\GitHub\Fork\Fork.Net\Oreo.VersionBuilder\bin\Debug\VersionFile\0527112916.version");
-            return rs;
-        }
-        private VersionModel GetPluginNewVersion(PluginModel pm)
-        {
-            VersionModel rs = JsonTool.ToObjFromFile<VersionModel>(@"D:\CoCo\GitHub\Fork\Fork.Net\Oreo.VersionBuilder\bin\Debug\VersionFile\0527112916.version");
-            return rs;
+                    });
+                }
+                else
+                {
+                    R.Log.w("更新插件列表为空");
+                }
+                R.Log.i("本地插件更新操作结束");
+            });
         }
-        #endregion
+
         #region 更新操作
+        /// <summary>
+        /// 更新的完整流程
+        /// </summary>
+        /// <param name="vm"></param>
+        /// <returns></returns>
         private bool Update(VersionModel vm)
         {
             VersionNumber = vm.VersionNumber;
             VersionDesc = vm.VersionDesc;
-            TempFile = Guid.NewGuid().ToString();
-            if (DirTool.Create(R.Paths.Temp + TempFile))
+            DownTemp = Guid.NewGuid().ToString();
+            BackupTemp = Guid.NewGuid().ToString();
+            if (DirTool.Create(R.Paths.Temp + DownTemp))
             {
-                R.Log.i("创建临时存放文件目录 " + R.Paths.Temp + TempFile);
+                R.Log.i("创建临时下载目录 " + R.Paths.Temp + DownTemp);
+                R.Log.i("创建临时备份目录 " + R.Paths.Temp + BackupTemp);
 
                 R.Log.i("将版本信息显示到 UI");
                 UILoadVersion(vm);
-                UpdateBefore(vm);
 
                 if (UpdateDownload(vm))
                 {
-                    R.Log.i("文件已下载成功");
-                    if (UpdateInstead(vm))
+                    R.Log.i("文件已全部下载成功");
+                    if (UpdateInsteadAndBackup(vm))
                     {
                         R.Log.i("文件已替换,准备执行清理任务");
-                        UpdateClean(vm);
-
-
-                        R.Log.i("配置文件信息更新完毕,准备写入新版本配置和描述信息");
-                        UpdateConfig(vm);
-                        UpdateWhatsnew(vm);
-                        UpdateAfter(vm);
+                        FileHelper.Clean(vm);
+                        R.Log.i("准备更新配置信息");
+                        DataHelper.UpdatePluginConfig(vm);
+                        DataHelper.UpdateWhatsnew(vm);
+                        UIUpdateDetail("添加新版本特性说明 Whatsnew.txt");
                         return true;
                     }
                     else
                     {
-                        R.Log.w("文件替换失败,当前更新失败");
+                        UpdateRollback(vm);
+                        R.Log.w("文件替换失败,当前更新失败,准备回滚备份的文件");
                     }
                 }
                 else
@@ -173,29 +127,34 @@ namespace Oreo.VersionUpdate.Views
             }
             else
             {
-                R.Log.i("创建临时存放文件目录 " + R.Paths.Temp + TempFile + " 失败,中止更新");
+                R.Log.i("创建临时存放文件目录 " + R.Paths.Temp + DownTemp + " 失败,中止更新");
             }
             return false;
         }
-        private void UpdateBefore(VersionModel vm)
+        /// <summary>
+        /// 更新前操作(启动或关闭进程)
+        /// </summary>
+        /// <param name="vm"></param>
+        private void BeforeUpdate(VersionModel vm)
         {
-            if (ListTool.HasElements(vm.BeforeUpdateKillProcess))
-            {
-                foreach (var p in vm.BeforeUpdateKillProcess)
-                {
-                    if (!string.IsNullOrWhiteSpace(p))
-                        ProcessTool.KillProcess(p);
-                }
-            }
-            if (ListTool.HasElements(vm.BeforeUpdateStartProcess))
-            {
-                foreach (var p in vm.BeforeUpdateStartProcess)
-                {
-                    if (!string.IsNullOrWhiteSpace(p))
-                        ProcessTool.StartProcess(p);
-                }
-            }
+            ProcessTool.Kills(vm.BeforeUpdateKillProcess);
+            ProcessTool.Starts(vm.BeforeUpdateStartProcess);
         }
+        /// <summary>
+        /// 更新后操作(启动或关闭进程)
+        /// </summary>
+        /// <param name="vm"></param>
+        private void AfterUpdate(VersionModel vm)
+        {
+            ProcessTool.Kills(vm.AfterUpdateKillProcess);
+            ProcessTool.Starts(vm.AfterUpdateStartProcess);
+            UIUpdateDetail("当前更新完成");
+        }
+        /// <summary>
+        /// 下载要更新的文件
+        /// </summary>
+        /// <param name="vm"></param>
+        /// <returns></returns>
         private bool UpdateDownload(VersionModel vm)
         {
             FileCodeTool fcode = new FileCodeTool();
@@ -206,8 +165,8 @@ namespace Oreo.VersionUpdate.Views
                 {
                     R.Log.v("当前处理文件:" + file.ServerFile);
                     string serverFile = DirTool.Combine(vm.ServerPath, file.ServerFile);
-                    string tempFile = DirTool.Combine(R.Paths.Temp, TempFile, file.ServerFile);//下载到目标位置(带文件名)
-                    string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.App, file.LocalFile);//旧文件位置
+                    string tempFile = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile);//下载到目标位置(带文件名)
+                    string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile);//旧文件位置
                     if (fcode.GetMD5(localFile) != file.FileMD5)
                     {
                         UIUpdateDetail("准备下载:" + Path.GetFileName(file.ServerFile));
@@ -230,20 +189,38 @@ namespace Oreo.VersionUpdate.Views
             }
             return false;
         }
-        private bool UpdateInstead(VersionModel vm)
+        /// <summary>
+        /// 备份并替换文件
+        /// </summary>
+        /// <param name="vm"></param>
+        /// <returns></returns>
+        private bool UpdateInsteadAndBackup(VersionModel vm)
         {
             var insteadFile = vm.FileList.Where(x => x.IsClean == false);
             foreach (var file in insteadFile)
             {
-                string tempFile = DirTool.Combine(R.Paths.Temp, TempFile, file.ServerFile);//下载到目标位置(带文件名)
-                string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.App, file.LocalFile);//旧文件位置
+                string tempDown = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile);//下载到目标位置(带文件名)
+                string tempBack = DirTool.Combine(R.Paths.Temp, BackupTemp, file.ServerFile);//备份到目标位置(带文件名)
+                string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile);//旧文件位置
 
-                if (File.Exists(tempFile))
+                //备份文件
+                if (File.Exists(localFile) && File.Exists(tempDown))
+                {
+                    try
+                    {
+                        DirTool.Create(DirTool.GetFilePath(tempBack));
+                        File.Copy(localFile, tempBack, true);
+                        UIUpdateDetail("正在备份:" + tempBack);
+                    }
+                    catch (Exception e) { }
+                }
+                //替换文件
+                if (File.Exists(tempDown))
                 {
                     try
                     {
                         DirTool.Create(DirTool.GetFilePath(localFile));
-                        File.Copy(tempFile, localFile, true);
+                        File.Copy(tempDown, localFile, true);
                         UIUpdateDetail("正在更新:" + file.LocalFile);
                     }
                     catch (Exception e)
@@ -251,73 +228,41 @@ namespace Oreo.VersionUpdate.Views
                         return false;
                     }
                 }
+
             }
             return true;
         }
-        private void UpdateClean(VersionModel vm)
-        {
-            //清理临时文件夹
-            if (Directory.Exists(R.Paths.Temp))
-            {
-                try { Directory.Delete(R.Paths.Temp, true); } catch { }
-                UIUpdateDetail("正在清理临时文件夹:Temp");
-            }
-            //清理指定文件
-            var cleanFile = vm.FileList.Where(x => x.IsClean == true);
-            foreach (var file in cleanFile)
-            {
-                string fff = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : R.Paths.App + file.LocalFile;
-                if (File.Exists(fff))
-                {
-                    try { File.Delete(fff); } catch { }
-                    UIUpdateDetail("正在清理指定位置文件:" + fff);
-                }
-            }
-        }
-        private void UpdateConfig(VersionModel vm)
-        {
-            if (string.IsNullOrWhiteSpace(vm.PluginName) || string.IsNullOrWhiteSpace(vm.PluginEntry))
-            {
-                //标准版本更改设置
-                IniTool.WriteValue(R.Files.Settings, "Version", "Number", vm.VersionNumber);
-                UIUpdateDetail("修改主版本号:" + vm.VersionNumber);
-            }
-            else
-            {
-                //插件版本更改设置
-                UIUpdateDetail("修改插件版本号:" + vm.PluginName + " " + vm.VersionNumber);
-            }
-        }
-        private void UpdateWhatsnew(VersionModel vm)
-        {
-            TxtTool.Append(R.Files.Whatsnew, string.Format("{0} {1} {2}",
-                    vm.CodeName, vm.VersionNumber, (vm.PluginName == "" ? "" : "For:" + vm.PluginName)));
-            TxtTool.Append(R.Files.Whatsnew, vm.VersionDesc);
-            TxtTool.Append(R.Files.Whatsnew, new string('=', 50));
-            UIUpdateDetail("添加新版本特性说明 Whatsnew.txt");
-        }
-        private void UpdateAfter(VersionModel vm)
+        /// <summary>
+        /// 更新回滚
+        /// </summary>
+        /// <param name="vm"></param>
+        private void UpdateRollback(VersionModel vm)
         {
-            if (ListTool.HasElements(vm.AfterUpdateKillProcess))
+            var backFile = vm.FileList.Where(x => x.IsClean == false);
+            foreach (var file in backFile)
             {
-                foreach (var p in vm.AfterUpdateKillProcess)
-                {
-                    if (!string.IsNullOrWhiteSpace(p))
-                        ProcessTool.KillProcess(p);
-                }
-            }
-            if (ListTool.HasElements(vm.AfterUpdateStartProcess))
-            {
-                foreach (var p in vm.AfterUpdateStartProcess)
+                string tempBack = DirTool.Combine(R.Paths.Temp, BackupTemp, file.ServerFile);//备份到目标位置(带文件名)
+                string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile);//旧文件位置
+
+                //还原备份文件
+                if (File.Exists(tempBack))
                 {
-                    if (!string.IsNullOrWhiteSpace(p))
-                        ProcessTool.StartProcess(p);
+                    try
+                    {
+                        DirTool.Create(DirTool.GetFilePath(localFile));
+                        File.Copy(tempBack, localFile, true);
+                        UIUpdateDetail("正在还原备份文件:" + file.LocalFile);
+                    }
+                    catch (Exception e) { }
                 }
             }
-            UIUpdateDetail("当前更新完成");
         }
         #endregion
         #region UI操作
+        /// <summary>
+        /// 显示更新详情
+        /// </summary>
+        /// <param name="s"></param>
         void UIUpdateDetail(string s)
         {
             Invoke(new Action(() =>
@@ -326,6 +271,10 @@ namespace Oreo.VersionUpdate.Views
             }));
             Thread.Sleep(DETAIL_SHOWTIME);
         }
+        /// <summary>
+        /// 读取当前要更新的信息
+        /// </summary>
+        /// <param name="vm"></param>
         void UILoadVersion(VersionModel vm)
         {
             Invoke(new Action(() =>
@@ -335,6 +284,9 @@ namespace Oreo.VersionUpdate.Views
                 LbUpdateDetail.Text = "配置已加载,准备更新……";
             }));
         }
+        /// <summary>
+        /// 退出程序
+        /// </summary>
         void UIClose()
         {
             Invoke(new Action(() =>
@@ -343,8 +295,12 @@ namespace Oreo.VersionUpdate.Views
             }));
         }
         #endregion
-
         #region 控件事件
+        /// <summary>
+        /// 点击版本号 显示版本特性
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void LbVersionNumber_Click(object sender, EventArgs e)
         {
             MessageBox.Show(VersionDesc, VersionNumber + " 新特性");

File diff suppressed because it is too large
+ 2005 - 0
Fork.Net/Oreo.VersionUpdate/Views/MainForm.resx


+ 5 - 0
Fork.Net/Oreo.VersionUpdate/packages.config

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Costura.Fody" version="1.6.0" targetFramework="net452" developmentDependency="true" requireReinstallation="true" />
+  <package id="Fody" version="2.0.0" targetFramework="net452" developmentDependency="true" requireReinstallation="true" />
+</packages>

+ 12 - 0
Fork.Net/Y.Utils/IOUtils/TxtUtils/XmlTool.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Y.Utils.IOUtils.TxtUtils
+{
+    public class XmlTool
+    {
+        
+    }
+}

+ 24 - 0
Fork.Net/Y.Utils/WindowsUtils/ProcessUtils/ProcessTool.cs

@@ -7,6 +7,7 @@ using System.Diagnostics;
 using System.Drawing;
 using System.IO;
 using System.Windows.Forms;
+using Y.Utils.DataUtils.Collections;
 
 namespace Y.Utils.WindowsUtils.ProcessUtils
 {
@@ -62,5 +63,28 @@ namespace Y.Utils.WindowsUtils.ProcessUtils
                 }
             }
         }
+
+        public static void Starts(string[] files)
+        {
+            if (ListTool.HasElements(files))
+            {
+                foreach (var f in files)
+                {
+                    if (!string.IsNullOrWhiteSpace(f))
+                        StartProcess(f);
+                }
+            }
+        }
+        public static void Kills(string[] pro)
+        {
+            if (ListTool.HasElements(pro))
+            {
+                foreach (var p in pro)
+                {
+                    if (!string.IsNullOrWhiteSpace(p))
+                        KillProcess(p);
+                }
+            }
+        }
     }
 }

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -56,6 +56,7 @@
     <Compile Include="AppUtils\AppUnique.cs" />
     <Compile Include="DataUtils\UnitConvertUtils\ByteConvertUtils.cs" />
     <Compile Include="IOUtils\ImageUtils\IconTool.cs" />
+    <Compile Include="IOUtils\TxtUtils\XmlTool.cs" />
     <Compile Include="NetUtils\NetInfoUtils\NetCardInfoTool.cs" />
     <Compile Include="NetUtils\NetInfoUtils\NetFlowTool.cs" />
     <Compile Include="NetUtils\NetInfoUtils\NetPacketTool.cs" />

BIN
Fork.Net/packages/Costura.Fody.1.6.0/Costura.Fody.1.6.0.nupkg


BIN
Fork.Net/packages/Costura.Fody.1.6.0/Costura.Fody.dll


BIN
Fork.Net/packages/Costura.Fody.1.6.0/Costura.Tasks.dll


BIN
Fork.Net/packages/Costura.Fody.1.6.0/lib/dotnet/Costura.dll


BIN
Fork.Net/packages/Costura.Fody.1.6.0/lib/portable-net+sl+win+wpa+wp/Costura.dll


+ 94 - 0
Fork.Net/packages/Costura.Fody.1.6.0/tools/install.ps1

@@ -0,0 +1,94 @@
+param($installPath, $toolsPath, $package, $project)
+
+
+function RemoveForceProjectLevelHack($project)
+{
+    Write-Host "RemoveForceProjectLevelHack"
+	Foreach ($item in $project.ProjectItems)
+	{
+		if ($item.Name -eq "Fody_ToBeDeleted.txt")
+		{
+			$item.Delete()
+		}
+	}
+}
+
+function FlushVariables()
+{
+    Write-Host "Flushing environment variables"
+    $env:FodyLastProjectPath = ""
+    $env:FodyLastWeaverName = ""
+    $env:FodyLastXmlContents = ""
+}
+
+function Update-FodyConfig($addinName, $project)
+{
+	Write-Host "Update-FodyConfig"
+    $fodyWeaversPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($project.FullName), "FodyWeavers.xml")
+
+	$FodyLastProjectPath = $env:FodyLastProjectPath
+	$FodyLastWeaverName = $env:FodyLastWeaverName
+	$FodyLastXmlContents = $env:FodyLastXmlContents
+
+	if (
+		($FodyLastProjectPath -eq $project.FullName) -and
+		($FodyLastWeaverName -eq $addinName))
+	{
+        Write-Host "Upgrade detected. Restoring content for $addinName"
+		[System.IO.File]::WriteAllText($fodyWeaversPath, $FodyLastXmlContents)
+        FlushVariables
+		return
+	}
+
+    FlushVariables
+
+    $xml = [xml](get-content $fodyWeaversPath)
+
+    $weavers = $xml["Weavers"]
+    $node = $weavers.SelectSingleNode($addinName)
+
+    if (-not $node)
+    {
+        Write-Host "Appending node"
+        $newNode = $xml.CreateElement($addinName)
+        $weavers.AppendChild($newNode)
+    }
+
+    $xml.Save($fodyWeaversPath)
+}
+
+function Fix-ReferencesCopyLocal($package, $project)
+{
+    Write-Host "Fix-ReferencesCopyLocal $($package.Id)"
+    $asms = $package.AssemblyReferences | %{$_.Name}
+
+    foreach ($reference in $project.Object.References)
+    {
+        if ($asms -contains $reference.Name + ".dll")
+        {
+            if($reference.CopyLocal -eq $true)
+            {
+                $reference.CopyLocal = $false;
+            }
+        }
+    }
+}
+
+function UnlockWeaversXml($project)
+{
+    $fodyWeaversProjectItem = $project.ProjectItems.Item("FodyWeavers.xml");
+    if ($fodyWeaversProjectItem)
+    {
+        $fodyWeaversProjectItem.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}")
+        $fodyWeaversProjectItem.Save()
+		$fodyWeaversProjectItem.Document.Close()
+    }
+}
+
+UnlockWeaversXml($project)
+
+RemoveForceProjectLevelHack $project
+
+Update-FodyConfig $package.Id.Replace(".Fody", "") $project
+
+Fix-ReferencesCopyLocal $package $project

+ 47 - 0
Fork.Net/packages/Costura.Fody.1.6.0/tools/uninstall.ps1

@@ -0,0 +1,47 @@
+param($installPath, $toolsPath, $package, $project)
+
+
+function Update-FodyConfig($addinName, $project)
+{
+    $fodyWeaversPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($project.FullName), "FodyWeavers.xml")
+
+    if (!(Test-Path ($fodyWeaversPath)))
+    {
+        return
+    }
+
+    Write-Host "Caching variables for possible update"
+	$env:FodyLastProjectPath = $project.FullName
+	$env:FodyLastWeaverName = $addinName
+	$env:FodyLastXmlContents = [IO.File]::ReadAllText($fodyWeaversPath)
+
+
+    $xml = [xml](get-content $fodyWeaversPath)
+
+    $weavers = $xml["Weavers"]
+    $node = $weavers.SelectSingleNode($addinName)
+
+    if ($node)
+    {
+        Write-Host "Removing node from FodyWeavers.xml"
+        $weavers.RemoveChild($node)
+    }
+
+    $xml.Save($fodyWeaversPath)
+}
+
+
+function UnlockWeaversXml($project)
+{
+    $fodyWeaversProjectItem = $project.ProjectItems.Item("FodyWeavers.xml");
+    if ($fodyWeaversProjectItem)
+    {
+        $fodyWeaversProjectItem.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}")
+        $fodyWeaversProjectItem.Save()
+		$fodyWeaversProjectItem.Document.Close()
+    }
+}
+
+UnlockWeaversXml($project)
+
+Update-FodyConfig $package.Id.Replace(".Fody", "") $project

+ 4 - 0
Fork.Net/packages/Fody.2.0.0/Content/FodyWeavers.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<Weavers>
+  
+</Weavers>

BIN
Fork.Net/packages/Fody.2.0.0/Fody.2.0.0.nupkg


BIN
Fork.Net/packages/Fody.2.0.0/Fody.dll


BIN
Fork.Net/packages/Fody.2.0.0/FodyCommon.dll


BIN
Fork.Net/packages/Fody.2.0.0/FodyIsolated.dll


BIN
Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Mdb.dll


BIN
Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Pdb.dll


BIN
Fork.Net/packages/Fody.2.0.0/Mono.Cecil.Rocks.dll


BIN
Fork.Net/packages/Fody.2.0.0/Mono.Cecil.dll


+ 3 - 0
Fork.Net/packages/Fody.2.0.0/Tools/install.ps1

@@ -0,0 +1,3 @@
+param($installPath, $toolsPath, $package, $project)
+$item = $project.ProjectItems | where-object {$_.Name -eq "FodyWeavers.xml"} 
+$item.Properties.Item("BuildAction").Value = [int]0