示例#1
0
    /// <summary>
    /// Returns an individual application profile.
    /// </summary>
    public async Task <AppItem> GetApplicationAsync(IndexAppEntry appEntry)
    {
        if (string.IsNullOrEmpty(appEntry.FilePath))
        {
            throw new ArgumentException($"({nameof(appEntry.FilePath)}) was null or empty.");
        }

        var uri     = new Uri(IndexUrl, Routes.GetApplicationPath(appEntry.FilePath));
        var appItem = await DownloadAndDeserialize <AppItem>(uri);

        if (appItem == null)
        {
            throw new Exception("Failed to download package index entry.");
        }

        return(appItem);
    }
示例#2
0
    /// <summary>
    /// Builds a game index given a source folder and outputs it to a given directory.
    /// </summary>
    /// <param name="folder">Folder containing the root of the repository, corresponding to root folder of <see cref="Routes"/>.</param>
    /// <param name="outputFolder">Folder where to place the output result.</param>
    /// <returns>A copy of the newly created index.</returns>
    public static Index Build(string folder, string outputFolder)
    {
        folder       = Path.GetFullPath(folder);
        outputFolder = Path.GetFullPath(outputFolder);
        Directory.CreateDirectory(outputFolder);

        var applicationFolder = Path.Combine(folder, Routes.Application);
        var files             = Directory.GetFiles(applicationFolder, $"*{Routes.FileExtension}", SearchOption.AllDirectories);
        var result            = new Index();

        foreach (var file in files)
        {
            var appItem = JsonSerializer.Deserialize <AppItem>(File.ReadAllBytes(file));
            if (appItem == null || string.IsNullOrEmpty(appItem.AppId) || string.IsNullOrEmpty(appItem.Hash))
            {
                continue;
            }

            // Make Index Entry
            var relativePath = IO.GetRelativePath(file, applicationFolder);
            var indexEntry   = new IndexAppEntry()
            {
                AppName  = appItem.AppName,
                FilePath = $"{relativePath}{Routes.CompressionExtension}"
            };

            GetOrCreateValue(result.IdToApps, appItem.AppId).Add(indexEntry);
            GetOrCreateValue(result.HashToAppDictionary, appItem.Hash).Add(indexEntry);

            // Write new File Out
            var newAppItemBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(appItem)); // Because user made JSON is readable, not indented.
            var newFilePath     = Path.Combine(outputFolder, Routes.Application, indexEntry.FilePath);
            Directory.CreateDirectory(Path.GetDirectoryName(newFilePath) !);
            File.WriteAllBytes(newFilePath, Compression.Compress(newAppItemBytes));
        }

        var indexBytes = Compression.Compress(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(result)));

        File.WriteAllBytes(Path.Combine(outputFolder, Routes.Index), indexBytes);

        return(result);
    }
 /// <summary/>
 public SelectAddedGameDialogViewModel(List <IndexAppEntry> applications)
 {
     Entries       = applications;
     SelectedEntry = Entries[0];
 }