Exemple #1
0
        public void Update()
        {
            if (!IsUpdateAvailable())
            {
                throw new LauncherException("no update is available");
            }

            using (var mutex = new WurmAssistantMutex())
            {
                mutex.Enter(1000, "You must close Wurm Assistant before running update");
                var newFileZipped = WebApiClientSpellbook.GetFileFromWebApi(
                    AppContext.WebApiBasePath,
                    string.Format("{0}/{1}", AppContext.ProjectName, buildType),
                    TimeSpan.FromSeconds(15),
                    BasePath);

                using (var extractor = new SevenZipExtractor(newFileZipped.FullName))
                {
                    extractor.ExtractArchive(BasePath);
                }

                Thread.Sleep(1000);

                var cleaner = new DirCleaner(BasePath);
                cleaner.Cleanup();
            }
        }
 public async Task UninstallAsync()
 {
     using (new WurmAssistantGateway(AppContext.WaGatewayErrorMessage))
     {
         await Task.Factory.StartNew(() =>
         {
             var cleaner = new DirCleaner(BasePath);
             cleaner.WipeDir();
         });
     }
 }
        public async Task UpdateAsync()
        {
            StatusReset();
            UpdateRunning = true;
            UpdateStatus = "starting update";

            var updateIsReallyAvailable = await IsUpdateAvailableAsync();
            if (!updateIsReallyAvailable)
            {
                // this should never happen under normal circumstances
                UpdateStatus = "no update available!";
                throw new LauncherException("no update available");
            }

            using (new WurmAssistantGateway(AppContext.WaGatewayErrorMessage))
            {
                // clean up the dir before trying the update
                updateStatus = "preparing for update";
                await TaskEx.Run(() =>
                {
                    var cleaner = new DirCleaner(BasePath);
                    cleaner.Cleanup();
                });

                updateStatus = "downloading";
                ProgressIndeterminate = false;
                var newFileZipped = await WebApiEx.GetFileFromWebApiAsync(
                    AppContext.WebApiBasePath,
                    string.Format("ProjectApi/{0}/{1}", AppContext.ProjectName, BuildType),
                    TimeSpan.FromSeconds(15),
                    Path.Combine(BasePath, Guid.NewGuid().ToString() + ".zip"),
                    (sender, args) =>
                    {
                        var prog = ((double)args.BytesReceived) / ((double)args.TotalBytesToReceive);
                        prog *= 1000;
                        var intProg = (int)prog;
                        UpdateProgress = intProg;
                    });
                ProgressIndeterminate = true;
                UpdateStatus = "extracting";
                await TaskEx.Run(() =>
                {
                    using (var extractor = new SevenZipExtractor(newFileZipped.FullName))
                    {
                        extractor.ExtractArchive(BasePath);
                    }
                });
                UpdateStatus = "cleaning up";
                await TaskEx.Delay(TimeSpan.FromSeconds(1));

                await TaskEx.Run(() =>
                {
                    var cleaner = new DirCleaner(BasePath);
                    cleaner.Cleanup();
                });
                UpdateStatus = "done";

                await TaskEx.Delay(TimeSpan.FromSeconds(3));
                UpdateRunning = false;
            }
        }