Esempio 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);
    }
    /// <inheritdoc/>
    public void Migrate(PathTuple <ModConfig> mod, PathTuple <ModUserConfig>?userConfig)
    {
        var modDirectory   = Path.GetDirectoryName(mod.Path);
        var nuspecFilePath = Path.Combine(modDirectory !, $"{IO.Utility.IOEx.ForceValidFilePath(mod.Config.ModId)}.nuspec");

        if (File.Exists(nuspecFilePath))
        {
            this.SetConfiguration(mod, new NuGetConfig()
            {
                AllowUpdateFromAnyRepository = true,
                DefaultRepositoryUrls        = new ObservableCollection <StringWrapper>(Singleton <LoaderConfig> .Instance.NuGetFeeds.Select(x => (StringWrapper)(x.URL)))
            });

            mod.Save();
            IOEx.TryDeleteFile(nuspecFilePath);
        }
    }
Esempio n. 3
0
    public void Migrate_MigratesNuSpecIntoMainConfig()
    {
        // Arrange
        var mod            = _testEnvironmoent.TestModConfigATuple;
        var modDirectory   = Path.GetDirectoryName(mod.Path);
        var nuspecFilePath = Path.Combine(modDirectory !, $"{IOEx.ForceValidFilePath(mod.Config.ModId)}.nuspec");

        File.Create(nuspecFilePath).Dispose();

        // Act
        var factory = new NuGetUpdateResolverFactory();

        factory.Migrate(mod, null);
        using var disposalHelper = new RemoveConfiguration <NuGetUpdateResolverFactory.NuGetConfig>(mod, factory);

        // Assert
        Assert.False(File.Exists(nuspecFilePath));
        Assert.True(factory.TryGetConfigurationOrDefault(mod, out var config));
    }
Esempio n. 4
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);
    }
    /// <summary/>
    public PublishModDialogViewModel(PathTuple <ModConfig> modTuple)
    {
        _modTuple    = modTuple;
        PackageName  = IOEx.ForceValidFilePath(_modTuple.Config.ModName.Replace(' ', '_'));
        OutputFolder = Path.Combine(Path.GetTempPath(), $"{IOEx.ForceValidFilePath(_modTuple.Config.ModId)}.Publish");

        // Set default Regexes.
        IgnoreRegexes = new ObservableCollection <StringWrapper>()
        {
            @".*\.json", // Config files
            $"{Regex.Escape($@"{_modTuple.Config.ModId}.nuspec")}"
        };

        IncludeRegexes = new ObservableCollection <StringWrapper>()
        {
            Regex.Escape(ModConfig.ConfigFileName),
            @"\.deps\.json",
            @"\.runtimeconfig\.json",
        };

        // Set notifications
        PropertyChanged += ChangeUiVisbilityOnPropertyChanged;
    }