Exemplo n.º 1
0
    /// <summary>
    /// Finds all mods in <paramref name="tempExtractDir"/> and copies them to appropriate subfolders in <paramref name="packageFolder"/>.
    /// </summary>
    /// <returns>Path to last folder copied.</returns>
    public static string CopyPackagesFromExtractFolderToTargetDir(string packageFolder, string tempExtractDir, CancellationToken token)
    {
        var configs = ConfigReader <ModConfig> .ReadConfigurations(tempExtractDir, ModConfig.ConfigFileName, token, int.MaxValue, 0);

        var returnResult = "";

        foreach (var config in configs)
        {
            string configId        = config.Config.ModId;
            string configDirectory = Path.GetDirectoryName(config.Path) !;
            returnResult = Path.Combine(packageFolder, IO.Utility.IOEx.ForceValidFilePath(configId));
            IOEx.MoveDirectory(configDirectory, returnResult);
        }

        return(returnResult);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Extracts the content files of the NuGet package to a specified directory.
    /// </summary>
    /// <param name="stream">Stream containing the NuGet package.</param>
    /// <param name="targetDirectory">The directory to extract the package content to.</param>
    /// <param name="token">A cancellation token to allow cancellation of the task.</param>
    public static void ExtractPackage(Stream stream, string targetDirectory, CancellationToken token = default)
    {
        PackageReaderBase packageReader = new PackageArchiveReader(stream);
        var items         = packageReader.GetFiles();
        var tempDirectory = $"{Path.GetTempPath()}\\{packageReader.NuspecReader.GetId()}";

        // Remove all items ending with a front or backslash (directories)
        items = items.Where(x => !(x.EndsWith("\\") || x.EndsWith("/")));

        if (Directory.Exists(tempDirectory))
        {
            Directory.Delete(tempDirectory, true);
        }

        packageReader.CopyFiles(tempDirectory, items, ExtractFile, new NullLogger(), token);

        var fullTargetDirectory = Path.GetFullPath(targetDirectory);

        IOEx.MoveDirectory(tempDirectory, fullTargetDirectory);
    }