/// <summary>
    /// Executes the task asynchronously.
    /// </summary>
    /// <returns></returns>
    public async Task ExecuteAsync()
    {
        var config = _application.Config;

        await using var fileStream = new FileStream(ApplicationConfig.GetAbsoluteAppLocation(_application), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 524288);
        var indexApi = new IndexApi();
        var index    = await indexApi.GetIndexAsync();

        var hash         = Hashing.ToString(await Hashing.FromStreamAsync(fileStream));
        var applications = index.FindApplication(hash, config.AppId, out bool hashMatches);

        await await ActionWrappers.ExecuteWithApplicationDispatcherAsync(async() =>
        {
            if (applications.Count == 1 && hashMatches)
            {
                ApplyIndexEntry(await indexApi.GetApplicationAsync(applications[0]), _application, hash);
            }
            else if (applications.Count >= 1)
            {
                // Select application.
                var viewModel = new SelectAddedGameDialogViewModel(applications);
                var result    = Actions.ShowSelectAddedGameDialog(viewModel);
                if (result == null)
                {
                    return;
                }

                ApplyIndexEntry(await indexApi.GetApplicationAsync(result), _application, hash);
            }
        });
    }
 public SelectAddedGameDialog(SelectAddedGameDialogViewModel viewModel)
 {
     InitializeComponent();
     ViewModel = viewModel;
 }
Exemplo n.º 3
0
    private static IndexAppEntry?ShowSelectAddedGameDialog(SelectAddedGameDialogViewModel viewmodel)
    {
        var result = ShowDialogAndGetResult(new SelectAddedGameDialog(viewmodel));

        return(result ? viewmodel.SelectedEntry : null);
    }