您好,登錄后才能下訂單哦!
這篇文章主要講解了“C# WinForm怎么實現自動更新程序”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“C# WinForm怎么實現自動更新程序”吧!
.NET Core 3.1
Visual Studio 2019
//xml文件 <?xml version="1.0" encoding="utf-8" ?> <updateList> <url>http://localhost:5000/api/Update/</url> <files> <file name="1.dll" version="1.0"></file> <file name="1.dll" version="1.1"></file> <file name="AutoUpdate.Test.exe" version="1.1"></file> </files> </updateList>
//Model public class UpdateModel { public string name { get; set; } public string version { get; set; } } public class UpdateModel_Out { public string url { get; set; } public List<UpdateModel> updateList { get; set; } }
//控制器 namespace AutoUpdate.WebApi.Controllers { [Route("api/[controller]/[Action]")] [ApiController] public class UpdateController : ControllerBase { [HttpGet] public JsonResult Index() { return new JsonResult(new { code = 10, msg = "success" }); } [HttpPost] public JsonResult GetUpdateFiles([FromBody] List<UpdateModel> input) { string xmlPath = AppContext.BaseDirectory + "UpdateList.xml"; XDocument xdoc = XDocument.Load(xmlPath); var files = from f in xdoc.Root.Element("files").Elements() select new { name = f.Attribute("name").Value, version = f.Attribute("version").Value }; var url = xdoc.Root.Element("url").Value; List<UpdateModel> updateList = new List<UpdateModel>(); foreach(var file in files) { UpdateModel model = input.Find(s => s.name == file.name); if(model == null || file.version.CompareTo(model.version) > 0) { updateList.Add(new UpdateModel { name = file.name, version = file.version }); } } UpdateModel_Out output = new UpdateModel_Out { url = url, updateList = updateList }; return new JsonResult(output); } [HttpPost] public FileStreamResult DownloadFile([FromBody] UpdateModel input) { string path = AppContext.BaseDirectory + "files\\" + input.name; FileStream fileStream = new FileStream(path, FileMode.Open); return new FileStreamResult(fileStream, "application/octet-stream"); } } }
感謝各位的閱讀,以上就是“C# WinForm怎么實現自動更新程序”的內容了,經過本文的學習后,相信大家對C# WinForm怎么實現自動更新程序這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。