using BeWoLauncher.Extensions; using BeWoLauncher.ServiceProxy; using BS.SharedLauncher; using BS.SharedLauncher.DataContract; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace BeWoLauncher { public class FileEventArgs : EventArgs { public object File { get; set; } //public FileToDo ToDo { get; set; } } public static class UpdateFileManager { public static event EventHandler DownloadFileEventHandler; public static event EventHandler ApplyFileEventHandler; //public static BeWoProgramPackageDC UpdateData { get; set; } static UpdateFileManager() { } //public static BeWoProgramPackageDC GetLastUpdate() //{ // var last = new BeWoProgramPackageDC(); // last.Files = UpdatePathManager.GetApplyDirInfo().GetFiles().Select(file => new BeWoProgramFileDC(file)).ToList(); // return last; //} //public static void DownloadUpdateSync() //{ // var last = GetLastUpdate(); // UpdateData = LauncherServiceFacade.DoLauncherServiceSync(x => x.Update(last)); // foreach (var file in UpdateData.Files) // { // switch (file.ToDo) // { // //case FileToDo.Update: // //case FileToDo.Add: // // using (var fs = new FileStream(Path.Combine(UpdatePathManager.GetDownloadPath(), file.FileName), FileMode.Create, FileAccess.Write)) // // { // // fs.Write(file.FileData, 0, file.FileData.Length); // // } // // file.FileData = null; // // break; // //case FileToDo.Remove: // // break; // //case FileToDo.Nuthing: // // break; // } // DownloadFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file }); // } //} public static async Task DownloadUpdateAsync() { throw new NotImplementedException("#98341345"); //var last = GetLastUpdate(); //UpdateData = LauncherServiceFacade.DoLauncherServiceSync(x => x.Update(last)); //foreach (var file in UpdateData.Files) //{ // switch (file.ToDo) // { // case FileToDo.Update: // case FileToDo.Add: // using (var fs = new FileStream(Path.Combine(GetDownloadPath(), file.FileName), FileMode.Create, FileAccess.Write)) // { // fs.Write(file.FileData, 0, file.FileData.Length); // } // file.FileData = null; // break; // case FileToDo.Remove: // break; // case FileToDo.Nuthing: // break; // } // DownloadFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file }); //} } //public static async Task ApplyUpdate() //{ // foreach (var file in UpdateData.Files) // { // switch (file.ToDo) // { // case FileToDo.Update: // case FileToDo.Add: // var source = Path.Combine(UpdatePathManager.GetDownloadPath(), file.FileName); // var dest = Path.Combine(UpdatePathManager.GetApplyPath(), file.FileName); // File.Delete(dest); // File.Copy(source, dest); // break; // case FileToDo.Remove: // File.Delete(Path.Combine(UpdatePathManager.GetApplyPath(), file.FileName)); // break; // case FileToDo.Nuthing: // break; // } // await showDelay(50); // ApplyFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file }); // } //} private static async Task showDelay(int millisec) { if (true) await Task.Delay(millisec); } } }