|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.IO; |
| 5 | +using System.Reflection; |
| 6 | + |
| 7 | +namespace Upgrade |
| 8 | +{ |
| 9 | + class Program |
| 10 | + { |
| 11 | + static string _appDir = ""; |
| 12 | + static string _upgDir = ""; |
| 13 | + static string _slash = Path.DirectorySeparatorChar.ToString(); |
| 14 | + static List<string> _items; |
| 15 | + |
| 16 | + static void Main(string[] args) |
| 17 | + { |
| 18 | + _appDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); |
| 19 | + _upgDir = $"{_appDir}{_slash}upgrade"; |
| 20 | + _items = new List<string>(); |
| 21 | + |
| 22 | + _items.Add($"STARTING UPGRADE IN: {_appDir}"); |
| 23 | + |
| 24 | + // wait for web app to stop |
| 25 | + System.Threading.Thread.Sleep(3000); |
| 26 | + |
| 27 | + var files = Directory.GetFiles(_appDir); |
| 28 | + |
| 29 | + foreach (var file in GetCoreFiles()) |
| 30 | + { |
| 31 | + ReplaceFile(file); |
| 32 | + } |
| 33 | + |
| 34 | + ReplaceFolder($"wwwroot{_slash}admin"); |
| 35 | + ReplaceFolder($"wwwroot{_slash}lib"); |
| 36 | + |
| 37 | + using (StreamWriter writer = new StreamWriter("upgrade.log")) |
| 38 | + { |
| 39 | + foreach (var item in _items) |
| 40 | + { |
| 41 | + writer.WriteLine(item); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + Process p = new Process(); |
| 46 | + p.StartInfo.FileName = "dotnet"; |
| 47 | + p.StartInfo.Arguments = "App.dll"; |
| 48 | + p.StartInfo.UseShellExecute = false; |
| 49 | + p.StartInfo.CreateNoWindow = false; |
| 50 | + p.Start(); |
| 51 | + } |
| 52 | + |
| 53 | + static void ReplaceFile(string file) |
| 54 | + { |
| 55 | + string oldFile = $"{_appDir}{_slash}{file}"; |
| 56 | + string newFile = $"{_upgDir}{_slash}{file}"; |
| 57 | + try |
| 58 | + { |
| 59 | + if (File.Exists(oldFile)) |
| 60 | + File.Delete(oldFile); |
| 61 | + |
| 62 | + File.Copy(newFile, oldFile); |
| 63 | + _items.Add($"Replacing {oldFile} with {newFile}"); |
| 64 | + } |
| 65 | + catch (Exception fe) |
| 66 | + { |
| 67 | + _items.Add($"Error replacing {oldFile}: {fe.Message}"); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + static void ReplaceFolder(string folder) |
| 72 | + { |
| 73 | + string oldFolder = $"{_appDir}{_slash}{folder}"; |
| 74 | + string newFolder = $"{_upgDir}{_slash}{folder}"; |
| 75 | + try |
| 76 | + { |
| 77 | + if (Directory.Exists(oldFolder)) |
| 78 | + Directory.Delete(oldFolder, true); |
| 79 | + |
| 80 | + Directory.Move(newFolder, oldFolder); |
| 81 | + _items.Add($"Replacing {oldFolder} with {newFolder}"); |
| 82 | + } |
| 83 | + catch (Exception fe) |
| 84 | + { |
| 85 | + _items.Add($"Error replacing {oldFolder}: {fe.Message}"); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + static string NameFromPath(string path) |
| 90 | + { |
| 91 | + int x = path.LastIndexOf(_slash); |
| 92 | + string name = path.Substring(x); |
| 93 | + return name; |
| 94 | + } |
| 95 | + |
| 96 | + static List<string> GetCoreFiles() |
| 97 | + { |
| 98 | + return new List<string> |
| 99 | + { |
| 100 | + "App.deps.json", |
| 101 | + "App.dll", |
| 102 | + "App.pdb", |
| 103 | + "App.PrecompiledViews.dll", |
| 104 | + "App.PrecompiledViews.pdb", |
| 105 | + "App.runtimeconfig.json", |
| 106 | + "Common.dll", |
| 107 | + "Core.dll", |
| 108 | + "Core.pdb", |
| 109 | + "HtmlAgilityPack.dll", |
| 110 | + "Markdig.dll", |
| 111 | + "Microsoft.Data.Sqlite.dll", |
| 112 | + "Microsoft.EntityFrameworkCore.Sqlite.dll", |
| 113 | + "Microsoft.SyndicationFeed.ReaderWriter.dll", |
| 114 | + "ReverseMarkdown.dll", |
| 115 | + "Serilog.dll", |
| 116 | + "Serilog.Extensions.Logging.dll", |
| 117 | + "Serilog.Sinks.File.dll", |
| 118 | + "Serilog.Sinks.RollingFile.dll", |
| 119 | + "SQLitePCLRaw.batteries_green.dll", |
| 120 | + "SQLitePCLRaw.batteries_v2.dll", |
| 121 | + "SQLitePCLRaw.core.dll", |
| 122 | + "SQLitePCLRaw.provider.e_sqlite3.dll", |
| 123 | + "System.Xml.XPath.XmlDocument.dll" |
| 124 | + }; |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments