Пример #1
0
        public OnlineAssetsControl(MainWindow main, BoxartControl boxart, BackgroundControl background, IconBannerControl iconBanner, ScreenshotsControl screenshots)
        {
            InitializeComponent();
            XboxAssetDownloader.StatusChanged += StatusChanged;
            _main                   = main;
            _boxart                 = boxart;
            _background             = background;
            _iconBanner             = iconBanner;
            _screenshots            = screenshots;
            SourceBox.SelectedIndex = 0;

            #region Xbox.com Locale worker

            var bw = new BackgroundWorker();
            bw.DoWork             += LocaleWorkerDoWork;
            bw.RunWorkerCompleted += (sender, args) => {
                LocaleBox.ItemsSource = _locales;
                SourceBox.Items.Add("Xbox 360 Marketplace");
                var index = 0;
                for (var i = 0; i < _locales.Length; i++)
                {
                    if (!_locales[i].Locale.Equals("en-us", StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    index = i;
                    break;
                }
                LocaleBox.SelectedIndex = index;
            };
            bw.RunWorkerAsync();

            #endregion

            #region Unity Worker

            _unityWorker.DoWork += (o, args) => {
                try {
                    _unityResult = XboxUnity.GetUnityCoverInfo(args.Argument.ToString());
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "Finished fetching asset information..."));
                    args.Result = true;
                }
                catch (Exception ex) {
                    MainWindow.SaveError(ex);
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "An error has occured, check error.log for more information..."));
                    args.Result = false;
                }
            };
            _unityWorker.RunWorkerCompleted += (o, args) => {
                if ((bool)args.Result)
                {
                    ResultBox.ItemsSource  = _unityResult;
                    SearchResultCount.Text = _unityResult.Length.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    ResultBox.ItemsSource  = null;
                    SearchResultCount.Text = "0";
                }
            };

            #endregion

            #region Xbox.com Worker

            _xboxWorker.DoWork += (sender, args) => {
                try {
                    _xboxResult = _keywords == null
                                                            ? _xboxAssetDownloader.GetTitleInfo(_titleId, args.Argument as XboxLocale)
                                                            : _xboxAssetDownloader.GetTitleInfo(_keywords, args.Argument as XboxLocale);

                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "Finished fetching asset information..."));
                    args.Result = true;
                }
                catch (Exception ex) {
                    MainWindow.SaveError(ex);
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "An error has occured. See the log for more details about this error."));
                    args.Result = false;
                }
            };
            _xboxWorker.RunWorkerCompleted += (sender, args) => {
                if ((bool)args.Result)
                {
                    var disp = new List <XboxTitleInfo.XboxAssetInfo>();
                    foreach (var info in _xboxResult)
                    {
                        disp.AddRange(info.AssetsInfo);
                    }
                    ResultBox.ItemsSource  = disp;
                    SearchResultCount.Text = disp.Count.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    ResultBox.ItemsSource  = null;
                    SearchResultCount.Text = "0";
                }
            };

            #endregion

            #region Cover Menu

            _coverMenu = new UIElement[] {
                new MenuItem {
                    Header = "Save Cover Art to File"
                },
                new MenuItem {
                    Header = "Set as Cover Art"
                }
            };
            ((MenuItem)_coverMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Choose Location to Save Cover Art Image", "cover.png");
            ((MenuItem)_coverMenu[1]).Click += (sender, args) => _boxart.Load(_img);

            #endregion

            #region Icon Menu

            _iconMenu = new UIElement[] {
                new MenuItem {
                    Header = "Save Icon to File"
                },
                new MenuItem {
                    Header = "Set as Icon"
                }
            };
            ((MenuItem)_iconMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Choose Location to Save Icon Image", "icon.png");
            ((MenuItem)_iconMenu[1]).Click += (sender, args) => _iconBanner.Load(_img, true);

            #endregion

            #region Banner Menu

            _bannerMenu = new UIElement[] {
                new MenuItem {
                    Header = "Save Banner to File"
                },
                new MenuItem {
                    Header = "Set as Banner"
                }
            };
            ((MenuItem)_bannerMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Choose Location to Save Banner Image", "banner.png");
            ((MenuItem)_bannerMenu[1]).Click += (sender, args) => _iconBanner.Load(_img, false);

            #endregion

            #region Background Menu

            _backgroundMenu = new UIElement[] {
                new MenuItem {
                    Header = "Save Background to File"
                },
                new MenuItem {
                    Header = "Set as Background"
                }
            };
            ((MenuItem)_backgroundMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Choose Location to Save Background Image", "background.png");
            ((MenuItem)_backgroundMenu[1]).Click += (sender, args) => _background.Load(_img);

            #endregion

            #region Screenshots Menu

            _screenshotsMenu = new UIElement[] {
                new MenuItem {
                    Header = "Save Screenshot to File"
                },
                new MenuItem {
                    Header = "Replace Current Screenshot"
                },
                new MenuItem {
                    Header = "Add Screenshot"
                }
            };
            ((MenuItem)_screenshotsMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Choose Location to Save Screenshot Image", "screenshot.png");
            ((MenuItem)_screenshotsMenu[1]).Click += (sender, args) => _screenshots.Load(_img, true);
            ((MenuItem)_screenshotsMenu[2]).Click += (sender, args) => _screenshots.Load(_img, false);

            #endregion
        }
        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;
            }
            var bw = new BackgroundWorker();

            bw.DoWork += (sender, args) => {
                try {
                    switch (task)
                    {
                    case Task.GetBoxart:
                        _buffer = asset.GetBoxart();
                        break;

                    case Task.GetBackground:
                        _buffer = asset.GetBackground();
                        break;

                    case Task.GetIconBanner:
                        _buffer = asset.GetIconBanner();
                        break;

                    case Task.GetScreenshots:
                        _buffer = asset.GetScreenshots();
                        break;

                    case Task.SetBoxart:
                        asset.SaveAsBoxart(_buffer);
                        break;

                    case Task.SetBackground:
                        asset.SaveAsBackground(_buffer);
                        break;

                    case Task.SetIconBanner:
                        asset.SaveAsIconBanner(_buffer);
                        break;

                    case Task.SetScreenshots:
                        asset.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();
        }
        public OnlineAssetsControl(MainWindow main, BoxartControl boxart, BackgroundControl background, IconBannerControl iconBanner, ScreenshotsControl screenshots)
        {
            InitializeComponent();
            XboxAssetDownloader.StatusChanged += StatusChanged;
            _main = main;
            _boxart = boxart;
            _background = background;
            _iconBanner = iconBanner;
            _screenshots = screenshots;
            SourceBox.SelectedIndex = Settings.Default.OnlineSourceIndex;

            #region Xbox.com Locale worker

            var bw = new BackgroundWorker();
            bw.DoWork += LocaleWorkerDoWork;
            bw.RunWorkerCompleted += (sender, args) => {
                LocaleBox.ItemsSource = _locales;
                SourceBox.Items.Add("Xbox.com");
                var index = 0;
                for(var i = 0;i < _locales.Length;i++) {
                    if(!_locales[i].Locale.Equals("en-us", StringComparison.CurrentCultureIgnoreCase))
                        continue;
                    index = i;
                    break;
                    }

                if(Settings.Default.LocaleMarketIndex == -99) {
                    Settings.Default.LocaleMarketIndex = index;
                    Settings.Default.LocaleMarketName = "en-us";
                    }

                LocaleBox.SelectedIndex = Settings.Default.LocaleMarketIndex;
                Settings.Default.Save();
            };
            bw.RunWorkerAsync();

            #endregion

            #region Unity Worker

            _unityWorker.DoWork += (o, args) => {
                try {
                    _unityResult = XboxUnity.GetUnityCoverInfo(args.Argument.ToString());
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "Finished downloading asset information..."));
                    args.Result = true;
                    }
                catch(Exception ex) {
                    MainWindow.SaveError(ex);
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "An error has occured, check error.log for more information..."));
                    args.Result = false;
                    }
            };
            _unityWorker.RunWorkerCompleted += (o, args) => {
                if((bool)args.Result) {
                    ResultBox.ItemsSource = _unityResult;
                    SearchResultCount.Text = _unityResult.Length.ToString(CultureInfo.InvariantCulture);
                    }
                else {
                    ResultBox.ItemsSource = null;
                    SearchResultCount.Text = "0";
                    }
            };

            #endregion

            #region Xbox.com Worker

            _xboxWorker.DoWork += (sender, args) => {
                try {
                    _xboxResult = _keywords == null
                                      ? _xboxAssetDownloader.GetTitleInfo(_titleId, args.Argument as XboxLocale)
                                      : _xboxAssetDownloader.GetTitleInfo(_keywords, args.Argument as XboxLocale);
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "Finished downloading asset information..."));
                    args.Result = true;
                    }
                catch(Exception ex) {
                    MainWindow.SaveError(ex);
                    Dispatcher.Invoke(new Action(() => StatusMessage.Text = "An error has occured, check error.log for more information..."));
                    args.Result = false;
                    }
            };
            _xboxWorker.RunWorkerCompleted += (sender, args) => {
                if((bool)args.Result) {
                    var disp = new List<XboxTitleInfo.XboxAssetInfo>();
                    foreach(var info in _xboxResult)
                        disp.AddRange(info.AssetsInfo);
                    ResultBox.ItemsSource = disp;
                    SearchResultCount.Text = disp.Count.ToString(CultureInfo.InvariantCulture);
                    }
                else {
                    ResultBox.ItemsSource = null;
                    SearchResultCount.Text = "0";
                    }
            };

            #endregion

            #region Cover Menu

            _coverMenu = new UIElement[] {
                                             new MenuItem {
                                                              Header = "Save cover to file"
                                                          },
                                             new MenuItem {
                                                              Header = "Set as cover"
                                                          }
                                         };
            ((MenuItem)_coverMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Select where to save the cover", "cover.png");
            ((MenuItem)_coverMenu[1]).Click += (sender, args) => _boxart.Load(_img);

            #endregion

            #region Icon Menu

            _iconMenu = new UIElement[] {
                                            new MenuItem {
                                                             Header = "Save icon to file"
                                                         },
                                            new MenuItem {
                                                             Header = "Set as icon"
                                                         }
                                        };
            ((MenuItem)_iconMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Select where to save the icon", "icon.png");
            ((MenuItem)_iconMenu[1]).Click += (sender, args) => _iconBanner.Load(_img, true);

            #endregion

            #region Banner Menu

            _bannerMenu = new UIElement[] {
                                              new MenuItem {
                                                               Header = "Save banner to file"
                                                           },
                                              new MenuItem {
                                                               Header = "Set as banner"
                                                           }
                                          };
            ((MenuItem)_bannerMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Select where to save the banner", "banner.png");
            ((MenuItem)_bannerMenu[1]).Click += (sender, args) => _iconBanner.Load(_img, false);

            #endregion

            #region Background Menu

            _backgroundMenu = new UIElement[] {
                                                  new MenuItem {
                                                                   Header = "Save background to file"
                                                               },
                                                  new MenuItem {
                                                                   Header = "Set as background"
                                                               }
                                              };
            ((MenuItem)_backgroundMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Select where to save the background", "background.png");
            ((MenuItem)_backgroundMenu[1]).Click += (sender, args) => _background.Load(_img);

            #endregion

            #region Screenshots Menu

            _screenshotsMenu = new UIElement[] {
                                                   new MenuItem {
                                                                    Header = "Save screenshot to file"
                                                                },
                                                   new MenuItem {
                                                                    Header = "Replace current screenshot"
                                                                },
                                                   new MenuItem {
                                                                    Header = "Add new screenshot"
                                                                }
                                               };
            ((MenuItem)_screenshotsMenu[0]).Click += (sender, args) => MainWindow.SaveToFile(_img, "Select where to save the screenshot", "screenshot.png");
            ((MenuItem)_screenshotsMenu[1]).Click += (sender, args) => _screenshots.Load(_img, true);
            ((MenuItem)_screenshotsMenu[2]).Click += (sender, args) => _screenshots.Load(_img, false);

            #endregion
        }