/// <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);
            }
        });
    }
    private async Task InitializeApiAsync()
    {
        try
        {
            var indexApi = new IndexApi();
            var index    = await indexApi.GetIndexAsync();

            var packages = await index.TryGetGameBananaPackageList(GameId);

            if (packages.result)
            {
                _indexPackageProvider = new IndexPackageProvider(packages.list);
                _initializedApi       = true;
            }
        }
        catch (Exception) { /* ignored */ }

        _initializeComplete = true;
    }
Beispiel #3
0
    /// <summary>
    /// Gets an index from local folder, or returns a dummy.
    /// </summary>
    public static async Task <Structures.Index> GetOrCreateLocalIndexAsync(this IndexApi api)
    {
        var uri = new Uri(api.IndexUrl, Routes.Index);

        if (!uri.IsFile)
        {
            throw new ArgumentException("The index API was created with a non-local path.");
        }

        if (!File.Exists(uri.LocalPath))
        {
            return new Structures.Index()
                   {
                       BaseUrl = api.IndexUrl
                   }
        }
        ;

        return(await api.GetIndexAsync());
    }
}
    private async Task InitializeApiAsync(string?appId)
    {
        try
        {
            var indexApi = new IndexApi();
            var index    = await indexApi.GetIndexAsync();

            var packages = await index.TryGetNuGetPackageList(SourceUrl);

            if (packages.result)
            {
                // Filter out by tag if app requested
                if (!string.IsNullOrEmpty(appId))
                {
                    packages.list.Packages = packages.list.Packages.Where(x => x.Tags != null && x.Tags.Contains(appId, StringComparer.OrdinalIgnoreCase)).ToList();
                }

                _indexPackageProvider = new IndexPackageProvider(packages.list);
                _initializedApi       = true;
            }
        }
        catch (Exception) { /* ignored */ }
    }