示例#1
0
        public NewDownloadTaskWindow()
        {
            apiHandler = new FunctionAPIHandler(App.config.MainConfig.Download.DownloadSource);
            InitializeComponent();
            versionListDataGrid.ItemsSource = verList;
            ICollectionView vw = CollectionViewSource.GetDefaultView(verList);

            vw.GroupDescriptions.Add(new PropertyGroupDescription("Type"));
            vw.SortDescriptions.Add(new SortDescription("Type", ListSortDirection.Ascending));
        }
        private async Task AppendVersionsDownloadTask(IList list)
        {
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    foreach (JWVersion item in list)
                    {
                        string json = FunctionAPIHandler.HttpGet(apiHandler.DoURLReplace(item.Url));
                        Core.Modules.Version ver = App.handler.JsonToVersion(json);
                        string jsonPath          = App.handler.GetJsonPath(ver.ID);

                        string dir = Path.GetDirectoryName(jsonPath);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        File.WriteAllText(jsonPath, json);

                        List <DownloadTask> tasks = new List <DownloadTask>();

                        tasks.Add(new DownloadTask("资源引导", apiHandler.DoURLReplace(ver.AssetIndex.URL), App.handler.GetAssetsIndexPath(ver.Assets)));

                        tasks.AddRange(Core.Util.GetLost.GetLostDependDownloadTask(App.config.MainConfig.Download.DownloadSource, App.handler, ver));

                        App.downloader.SetDownloadTasks(tasks);
                        App.downloader.StartDownload();
                    }
                }
                catch (WebException ex)
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.ShowMessageAsync("获取版本信息失败", "请检查您的网络是否正常或更改下载源/n原因:" + ex.Message);
                    }));
                }
                catch (Exception ex)
                {
                    AggregateExceptionArgs args = new AggregateExceptionArgs()
                    {
                        AggregateException = new AggregateException(ex)
                    };
                    App.CatchAggregateException(this, args);
                }
            });
        }
示例#3
0
        /// <summary>
        /// 获取丢失的资源文件下载任务
        /// </summary>
        /// <param name="source"></param>
        /// <param name="core"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public static List <DownloadTask> GetLostAssetsDownloadTask(DownloadSource source, LaunchHandler core, Version ver)
        {
            List <DownloadTask> tasks  = new List <DownloadTask>();
            JAssets             assets = null;

            string assetsPath = core.GetAssetsIndexPath(ver.Assets);

            if (!File.Exists(assetsPath))
            {
                if (ver.AssetIndex != null)
                {
                    string jsonUrl    = GetDownloadUrl.DoURLReplace(source, ver.AssetIndex.URL);
                    string assetsJson = FunctionAPIHandler.HttpGet(jsonUrl);
                    assets = core.GetAssetsByJson(assetsJson);
                    tasks.Add(new DownloadTask("资源文件引导", jsonUrl, assetsPath));
                }
                else
                {
                    return(tasks);
                }
            }
            else
            {
                assets = core.GetAssets(ver);
            }
            var lostAssets = GetLostAssets(core, assets);

            foreach (var item in lostAssets)
            {
                DownloadTask task = GetDownloadUrl.GetAssetsDownloadTask(source, item.Value, core);
                if (!tasks.Contains(task))
                {
                    tasks.Add(task);
                }
            }
            return(tasks);
        }
 public NewDownloadTaskWindow()
 {
     apiHandler = new FunctionAPIHandler(App.config.MainConfig.Download.DownloadSource);
     InitializeComponent();
 }