コード例 #1
0
        public LocalAssetsControl(MainWindow main, BoxartControl boxart, BackgroundControl background, IconBannerControl iconBanner, ScreenshotsControl screenshots)
        {
            InitializeComponent();
            _main = main;
            _boxart = boxart;
            _background = background;
            _iconBanner = iconBanner;
            _screenshots = screenshots;

            FtpAssetsBox.ItemsSource = _assetsList;

            onlyNewSync.IsChecked = Settings.Default.OnlyNew;
            sliderScreens.Value = Settings.Default.NumScreens;

            #region Xbox.com Worker

            _xboxWorker.WorkerReportsProgress = true;
            _xboxWorker.WorkerSupportsCancellation = true;

            var xboxMarketDataResult = new ConcurrentBag<XboxTitleInfo>();
            var omitedTitles = new ConcurrentBag<AuroraDbManager.ContentItem>();

            _xboxWorker.DoWork += (sender, args) => {

                var bgWork = sender as BackgroundWorker;

                try {

                    if(_assetsList.Count ==0) {
                        Dispatcher.Invoke(new Action(() => Status.Text = "No games..."));
                        return;
                        }

                    xboxMarketDataResult = new ConcurrentBag<XboxTitleInfo>();
                    omitedTitles = new ConcurrentBag<AuroraDbManager.ContentItem>();
                    XboxLocale loc = args.Argument as XboxLocale;

                    var _assetsToGo = _assetsList.Where(p => p.TitleIdNumber > 0);

                    Dispatcher.Invoke(new Action(() => _main.busyProgress.Visibility = Visibility.Visible));
                    Dispatcher.Invoke(new Action(() => _main.busyProgress.Text= "0 / " + _assetsToGo.Count()));

                    var maxScreens = Settings.Default.NumScreens;

                    int progressCount = 0;
                    Object progressLock = new Object();

                    Ts.Parallel.ForEach(_assetsToGo, (contentItem) => {

                        if(bgWork.CancellationPending) {
                            args.Cancel = true;
                            }

                        XboxTitleInfo _titleResult = _xboxAssetDownloader.GetTitleInfoSingle(contentItem.TitleIdNumber, loc);

                        if(_titleResult.AssetsInfo!= null) {

                            var unityCovers = XboxUnity.GetUnityCoverInfo(contentItem.TitleId);

                            if(unityCovers.Count() > 0) {
                                var cover = unityCovers.FirstOrDefault(p => p._unityResponse.Official == true);
                                if(cover!= null) {
                                    _titleResult.CoverAsset = cover;
                                    }
                                }

                            xboxMarketDataResult.Add(_titleResult);
                            }
                        else {
                            omitedTitles.Add(contentItem);
                            }

                        lock (progressLock) {
                            bgWork.ReportProgress(1, (++progressCount) + " / " + _assetsToGo.Count());
                            }
                    });

                    progressCount = 0;

                    Ts.Parallel.ForEach(xboxMarketDataResult, (titleItem) => {
                        AuroraDbManager.ContentItem contentItem = _assetsToGo.FirstOrDefault(p => p.TitleId == titleItem.TitleId);
                        if(contentItem!= null) {

                            lock (progressLock) {
                                bgWork.ReportProgress(1, (++progressCount) + " / " + xboxMarketDataResult.Count);
                                }

                            var itemWrap = new ContentItemLocal(contentItem);

                            if(titleItem.CoverAsset!= null) {

                                var assetFileC = new AuroraAsset.AssetFile();

                                assetFileC.SetBoxart(titleItem.CoverAsset.GetCover(), true);

                                itemWrap.SaveAsBoxart(assetFileC.FileData);

                                assetFileC.Dispose();
                                }

                            int screenCount = 0;

                            Ts.Parallel.ForEach(titleItem.AssetsInfo, (assetInfo) => {

                                if(!assetInfo.HaveAsset) {

                                    if(assetInfo.AssetType == XboxTitleInfo.XboxAssetType.Screenshot && screenCount >= maxScreens) {
                                        return;
                                        }
                                    var XboxAsset = assetInfo.GetAsset();
                                    var assetFile = new AuroraAsset.AssetFile();

                                    switch(assetInfo.AssetType) {
                                        case XboxTitleInfo.XboxAssetType.Icon:
                                        assetFile.SetIcon(XboxAsset.Image, true);
                                        itemWrap.SaveAsIconBanner(assetFile.FileData);
                                        break;
                                        case XboxTitleInfo.XboxAssetType.Banner:
                                        assetFile.SetBanner(XboxAsset.Image, true);
                                        itemWrap.SaveAsIconBanner(assetFile.FileData);
                                        break;
                                        case XboxTitleInfo.XboxAssetType.Background:
                                        assetFile.SetBackground(XboxAsset.Image, true);
                                        itemWrap.SaveAsBackground(assetFile.FileData);
                                        break;
                                        case XboxTitleInfo.XboxAssetType.Screenshot:
                                        // _screenshots.Load(XboxAsset.Image, false);
                                        // itemWrap.SaveAsScreenshots(assetFile.FileData);
                                        screenCount++;
                                        break;
                                        default:
                                        break;
                                        }
                                    //  XboxAsset.Dispose();
                                    assetFile.Dispose();

                                    }

                                GC.Collect();

                            });

                            }
                        titleItem.Dispose();
                    });

                    Dispatcher.Invoke(new Action(() => Status.Text = "Finished downloading asset information..."));

                    }
                catch(Exception ex) {
                    MainWindow.SaveError(ex);
                    Dispatcher.Invoke(new Action(() => Status.Text = "An error has occured, check error.log for more information..."));
                    }
            };
            _xboxWorker.RunWorkerCompleted += (sender, args) => {

                _main.busyProgress.Visibility = Visibility.Collapsed;
                _main.BusyIndicator.Visibility = Visibility.Collapsed;
                syncDb.IsEnabled = true;

                if(omitedTitles.Count >0) {

                    var logPath = Path.GetTempPath() + Path.DirectorySeparatorChar + "omittedTitlesLog.log";

                    string logcontent = "";
                    foreach(var item in omitedTitles) {
                        logcontent += "Title name: " + item.TitleName + @"

            TitleID: " + item.TitleId + @"

            Title int: " + item.TitleIdNumber + @"

            MediaID: " + item.MediaId + @"
            -----------------------------------------------

            ";
                        }

                    File.WriteAllText(logPath, logcontent);

                    var msgresult = MessageBox.Show("Omitted titles " + omitedTitles.Count + @"

            Show log?", "Action", MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.Cancel);

                    if(msgresult == MessageBoxResult.OK) {
                        try {
                            Process.Start(logPath);
                            }
                        catch {

                            }
                        }

                    }
                // var disp = new List<XboxTitleInfo.XboxAssetInfo>();

            };

            _xboxWorker.ProgressChanged+=_xboxWorker_ProgressChanged;

            #endregion
        }
コード例 #2
0
        private void ProcessAsset(Task task, bool shouldHideWhenDone = true)
        {
            _isError = false;
            AuroraDbManager.ContentItem asset = null;
            Dispatcher.InvokeIfRequired(() => asset = FtpAssetsBox.SelectedItem as AuroraDbManager.ContentItem, DispatcherPriority.Normal);
            if(asset == null)
                return;

            ContentItemLocal assetWrapper = new ContentItemLocal(asset);

            var bw = new BackgroundWorker();
            bw.DoWork += (sender, args) => {
                try {
                    switch(task) {
                        case Task.GetBoxart:
                        _buffer = assetWrapper.GetBoxart();
                        break;
                        case Task.GetBackground:
                        _buffer = assetWrapper.GetBackground();
                        break;
                        case Task.GetIconBanner:
                        _buffer = assetWrapper.GetIconBanner();
                        break;
                        case Task.GetScreenshots:
                        _buffer = assetWrapper.GetScreenshots();
                        break;
                        case Task.SetBoxart:
                        assetWrapper.SaveAsBoxart(_buffer);
                        break;
                        case Task.SetBackground:
                        assetWrapper.SaveAsBackground(_buffer);
                        break;
                        case Task.SetIconBanner:
                        assetWrapper.SaveAsIconBanner(_buffer);
                        break;
                        case Task.SetScreenshots:
                        assetWrapper.SaveAsScreenshots(_buffer);
                        break;
                        }
                    args.Result = true;
                    }
                catch(Exception ex) {
                    MainWindow.SaveError(ex);
                    args.Result = false;
                    }
            };
            bw.RunWorkerCompleted += (sender, args) => {
                if(shouldHideWhenDone)
                    Dispatcher.InvokeIfRequired(() => _main.BusyIndicator.Visibility = Visibility.Collapsed, DispatcherPriority.Normal);
                var isGet = true;
                if((bool)args.Result) {
                    if(_buffer.Length > 0) {
                        var aurora = new AuroraAsset.AssetFile(_buffer);
                        switch(task) {
                            case Task.GetBoxart:
                            _boxart.Load(aurora);
                            Dispatcher.InvokeIfRequired(() => _main.BoxartTab.IsSelected = true, DispatcherPriority.Normal);
                            break;
                            case Task.GetBackground:
                            _background.Load(aurora);
                            Dispatcher.InvokeIfRequired(() => _main.BackgroundTab.IsSelected = true, DispatcherPriority.Normal);
                            break;
                            case Task.GetIconBanner:
                            _iconBanner.Load(aurora);
                            Dispatcher.InvokeIfRequired(() => _main.IconBannerTab.IsSelected = true, DispatcherPriority.Normal);
                            break;
                            case Task.GetScreenshots:
                            _screenshots.Load(aurora);
                            Dispatcher.InvokeIfRequired(() => _main.ScreenshotsTab.IsSelected = true, DispatcherPriority.Normal);
                            break;
                            default:
                            isGet = false;
                            break;
                            }
                        }
                    if(shouldHideWhenDone && isGet)
                        Dispatcher.InvokeIfRequired(() => Status.Text = "Finished grabbing assets from FTP", DispatcherPriority.Normal);
                    else if(shouldHideWhenDone)
                        Dispatcher.InvokeIfRequired(() => Status.Text = "Finished saving assets to FTP", DispatcherPriority.Normal);
                    }
                else {
                    switch(task) {
                        case Task.GetBoxart:
                        case Task.GetBackground:
                        case Task.GetIconBanner:
                        case Task.GetScreenshots:
                        break;
                        default:
                        isGet = false;
                        break;
                        }
                    if(isGet)
                        Dispatcher.InvokeIfRequired(() => Status.Text = "Failed getting asset data... See error.log for more information...", DispatcherPriority.Normal);
                    else
                        Dispatcher.InvokeIfRequired(() => Status.Text = "Failed saving asset data... See error.log for more information...", DispatcherPriority.Normal);
                    _isError = true;
                    }
                _isBusy = false;
            };
            Dispatcher.InvokeIfRequired(() => _main.BusyIndicator.Visibility = Visibility.Visible, DispatcherPriority.Normal);
            _isBusy = true;
            bw.RunWorkerAsync();
        }