Skip to content

Commit 5637788

Browse files
authored
Merge pull request #82 from Gml-Launcher/develop
Update to v1.0.7
2 parents 5e75b6e + cedf818 commit 5637788

35 files changed

+1040
-69
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
url = https://github.com/Gml-Launcher/CmlLib.Core.Installer.NeoForge
1313
[submodule "src/Modrinth.Api"]
1414
path = src/Modrinth.Api
15-
url = https://github.com/GamerVII-NET/Modrinth.Api.git
15+
url = git@github.com:Gml-Launcher/Modrinth.Api.git

Gml.Core.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{FC610D
4343
EndProject
4444
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{08346264-61DD-450B-93E9-F85E84E5C8F9}"
4545
EndProject
46-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gml.Core.Sample.Console", "Gml.Core.Sample.Console\Gml.Core.Sample.Console.csproj", "{5D78A096-9F97-4596-AA2C-74B7230A435D}"
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gml.Core.Sample.Console", "src\Gml.Core.Sample.Console\Gml.Core.Sample.Console.csproj", "{62B4117D-94E6-433E-B76C-38A79E788180}"
4747
EndProject
4848
Global
4949
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -91,10 +91,10 @@ Global
9191
{073FBC05-E8F1-480C-8799-0F31B038B6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
9292
{073FBC05-E8F1-480C-8799-0F31B038B6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
9393
{073FBC05-E8F1-480C-8799-0F31B038B6E7}.Release|Any CPU.Build.0 = Release|Any CPU
94-
{5D78A096-9F97-4596-AA2C-74B7230A435D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
95-
{5D78A096-9F97-4596-AA2C-74B7230A435D}.Debug|Any CPU.Build.0 = Debug|Any CPU
96-
{5D78A096-9F97-4596-AA2C-74B7230A435D}.Release|Any CPU.ActiveCfg = Release|Any CPU
97-
{5D78A096-9F97-4596-AA2C-74B7230A435D}.Release|Any CPU.Build.0 = Release|Any CPU
94+
{62B4117D-94E6-433E-B76C-38A79E788180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
95+
{62B4117D-94E6-433E-B76C-38A79E788180}.Debug|Any CPU.Build.0 = Debug|Any CPU
96+
{62B4117D-94E6-433E-B76C-38A79E788180}.Release|Any CPU.ActiveCfg = Release|Any CPU
97+
{62B4117D-94E6-433E-B76C-38A79E788180}.Release|Any CPU.Build.0 = Release|Any CPU
9898
EndGlobalSection
9999
GlobalSection(NestedProjects) = preSolution
100100
{F437E3A7-05A0-481F-88F2-5769F116A39F} = {89C1B6A5-3BEE-45EE-9CB2-BFB6E095DE0B}
@@ -111,6 +111,6 @@ Global
111111
{3426695D-144A-4055-AC70-ED29B8180217} = {7A24CB48-82C7-4F8D-9511-DF69E8F8A342}
112112
{FC610D36-F382-4BFA-A865-A70F18EFD771} = {0A839A5D-6C25-49CA-BCB1-FE261FC828E5}
113113
{FEBB9BAD-A445-4965-927C-3DED320900BD} = {FC610D36-F382-4BFA-A865-A70F18EFD771}
114-
{5D78A096-9F97-4596-AA2C-74B7230A435D} = {08346264-61DD-450B-93E9-F85E84E5C8F9}
114+
{62B4117D-94E6-433E-B76C-38A79E788180} = {08346264-61DD-450B-93E9-F85E84E5C8F9}
115115
EndGlobalSection
116116
EndGlobal

src/Gml.Core.Interfaces/Enums/AuthType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public enum AuthType
1010
UnicoreCMS = 5,
1111
CustomEndpoint = 6,
1212
NamelessMC = 7,
13-
WebMCR = 8,
13+
WebMCRReloaded = 8,
14+
WordPress = 9,
1415
}

Gml.Core.Sample.Console/Gml.Core.Sample.Console.csproj renamed to src/Gml.Core.Sample.Console/Gml.Core.Sample.Console.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<ProjectReference Include="..\src\Gml.Core.Interfaces\Gml.Core.Interfaces.csproj" />
12-
<ProjectReference Include="..\src\Gml.Core\Gml.Core.csproj" />
13-
<ProjectReference Include="..\tests\GmlCore.Tests\GmlCore.Tests.csproj" />
11+
<ProjectReference Include="..\..\tests\GmlCore.Tests\GmlCore.Tests.csproj" />
12+
<ProjectReference Include="..\Gml.Core.Interfaces\Gml.Core.Interfaces.csproj" />
13+
<ProjectReference Include="..\Gml.Core\Gml.Core.csproj" />
1414
</ItemGroup>
1515

1616
</Project>
File renamed without changes.

src/Gml.Core/Core/Helpers/Profiles/ProfileProcedures.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public async Task AddProfile(IGameProfile? profile)
122122
};
123123
await AddProfile(profile);
124124

125+
await AddFileToWhiteList(profile, [
126+
new LocalFileInfo(Path.Combine("clients", profile.Name, "options.txt")),
127+
]);
128+
125129
await AddFolderToWhiteList(profile, [
126130
new LocalFolderInfo("saves"),
127131
new LocalFolderInfo("logs"),
@@ -659,6 +663,16 @@ public Task AddFileToWhiteList(IGameProfile profile, IFileInfo file)
659663
return SaveProfiles();
660664
}
661665

666+
public Task AddFileToWhiteList(IGameProfile profile, IEnumerable<IFileInfo> files)
667+
{
668+
foreach (var file in files)
669+
{
670+
AddWhiteListFileIfNotExists(profile, file);
671+
}
672+
673+
return SaveProfiles();
674+
}
675+
662676
private static void AddWhiteListFileIfNotExists(IGameProfile profile, IFileInfo file)
663677
{
664678
profile.FileWhiteList ??= [];

src/Gml.Core/Core/Integrations/ServicesIntegrationProcedures.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public Task<IEnumerable<IAuthServiceInfo>> GetAuthServices()
4343
new AuthServiceInfo("UnicoreCMS", AuthType.UnicoreCMS),
4444
new AuthServiceInfo("CustomEndpoint", AuthType.CustomEndpoint),
4545
new AuthServiceInfo("NamelessMC", AuthType.NamelessMC),
46-
new AuthServiceInfo("WebMCR", AuthType.WebMCR)
46+
new AuthServiceInfo("WebMCR Reloaded", AuthType.WebMCRReloaded),
47+
new AuthServiceInfo("WordPress ", AuthType.WordPress)
4748
}.AsEnumerable());
4849
}
4950

src/Gml.Core/Core/Launcher/StartupOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class StartupOptions : IStartupOptions
1111
ScreenHeight = 500,
1212
ScreenWidth = 500,
1313
MaximumRamMb = 1024,
14-
MinimumRamMb = 1024,
14+
MinimumRamMb = 512,
1515
OsName = "windows",
1616
OsArch = "64"
1717
};

src/Gml.Core/Models/System/LocalFileInfo.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using GmlCore.Interfaces.System;
23

34
namespace Gml.Models.System;
@@ -10,6 +11,17 @@ public class LocalFileInfo : IFileInfo
1011
public string Hash { get; set; }
1112
public string FullPath { get; set; }
1213

14+
public LocalFileInfo()
15+
{
16+
17+
}
18+
19+
public LocalFileInfo(string directory)
20+
{
21+
Directory = directory;
22+
Name = Path.GetFileName(directory);
23+
}
24+
1325
public override string ToString()
1426
{
1527
return Directory;

src/Modrinth.Api/README.md

Lines changed: 117 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,162 @@
1-
Modrinth.Api
2-
=======
1+
![Frame 39267](https://github.com/user-attachments/assets/dea7368e-c80c-4399-a4cf-94791b9e067a)
32

4-
## How to use Modrinth.Api in your project
3+
# Modrinth.Api
54

6-
To use the `Modrinth.Api` in your project, follow these steps:
5+
A robust and easy-to-use C# library for interacting with the Modrinth API, enabling developers to search, filter, and download mods and projects effortlessly.
76

8-
### Step 1: Import the necessary namespaces
7+
## Table of Contents
8+
- [Features](#features)
9+
- [Installation](#installation)
10+
- [Usage](#usage)
11+
- [Initializing the API](#initializing-the-api)
12+
- [Searching for Projects](#searching-for-projects)
13+
- [Retrieving and Downloading Mods](#retrieving-and-downloading-mods)
14+
- [Examples](#examples)
15+
- [Contributing](#contributing)
16+
- [License](#license)
17+
18+
## Features
19+
- **Search and Filter**: Query Modrinth projects and mods with customizable filters (e.g., categories, versions, or search terms).
20+
- **Download Mods**: Download specific mod versions along with their dependencies.
21+
- **Asynchronous Operations**: Fully async/await compatible for efficient API calls.
22+
- **Type-Safe Models**: Strongly-typed DTOs for seamless integration with Modrinth's API responses.
23+
24+
## Installation
25+
1. Add the `Modrinth.Api` NuGet package to your project:
26+
```bash
27+
dotnet add package Modrinth.Api
28+
```
29+
2. Ensure your project targets .NET Framework or .NET Core compatible with the library.
30+
31+
## Usage
32+
33+
### Initializing the API
34+
To start using the `Modrinth.Api`, import the required namespaces and create an instance of `ModrinthApi`.
935

1036
```csharp
1137
using Modrinth.Api;
1238
using Modrinth.Api.Core.Filter;
1339
using Modrinth.Api.Core.Projects;
1440
using Modrinth.Api.Models.Dto;
1541
using Modrinth.Api.Models.Projects;
16-
```
1742

18-
### Step 2: Create an instance of ModrinthApi
19-
20-
```csharp
2143
namespace YourNamespace
2244
{
23-
ModrinthApi api = new ModrinthApi();
45+
public class Program
46+
{
47+
private readonly ModrinthApi _api = new ModrinthApi();
48+
}
2449
}
2550
```
2651

27-
## How to Get a List of Projects
28-
29-
To retrieve a list of projects from Modrinth using the `Modrinth.Api`, follow these steps:
30-
31-
### Step 1: Set Up Project Filter
52+
### Searching for Projects
53+
Retrieve a list of projects by applying filters such as search queries, categories, or Minecraft versions.
3254

3355
```csharp
34-
35-
var projectFilter = new ProjectFilter()
56+
var projectFilter = new ProjectFilter
3657
{
37-
Query = "your_search_query",
38-
Limit = 50, // Set the number of projects to retrieve
58+
Query = "fabric",
59+
Limit = 50,
3960
Index = FaceIndexEnum.Follows,
4061
Offset = 0
4162
};
4263

64+
// Add facets for finer control
4365
projectFilter.AddFacet(ProjectFilterTypes.Category, "forge", LogicalOperator.Or);
44-
projectFilter.AddFacet(ProjectFilterTypes.Version, "1.16.5", LogicalOperator.Or);
45-
46-
```
66+
projectFilter.AddFacet(ProjectFilterTypes.Version, "1.20.1", LogicalOperator.Or);
4767

48-
### Step 2: Retrieve Projects List
49-
50-
```csharp
68+
// Fetch projects
5169
var projects = await _api.Projects.FindAsync<SearchProjectResultDto>(projectFilter, CancellationToken.None);
70+
foreach (var project in projects.Hits)
71+
{
72+
Console.WriteLine($"Project: {project.Title} (ID: {project.ProjectId})");
73+
}
5274
```
53-
This code snippet demonstrates how to set up a project filter and retrieve a list of projects based on your search criteria. Adjust the filter parameters according to your specific requirements.
54-
55-
## How to Get a List of Mods and Download a Version with Dependencies
56-
57-
To interact with Modrinth and retrieve a list of mods while also downloading a specific version with all dependencies, follow these steps:
5875

59-
### Step 1: Set Up Mod Filter
60-
61-
Before fetching the list of mods or downloading a version, you can set up a filter to narrow down the results. For example, you can filter mods by name, category, version, etc.
76+
### Retrieving and Downloading Mods
77+
Search for mods and download specific versions, including their dependencies, to a designated folder.
6278

6379
```csharp
64-
var modFilter = new ProjectModFilter()
80+
var modFilter = new ProjectModFilter
6581
{
66-
Query = "your_search_query",
67-
Limit = 50, // Set the number of mods to retrieve
82+
Query = "sodium",
83+
Limit = 50,
6884
Index = FaceIndexEnum.Follows,
6985
Offset = 0
7086
};
7187

72-
// Add facets to filter mods further (optional)
73-
modFilter.AddFacet(ProjectFilterTypes.Category, "forge", LogicalOperator.Or);
74-
modFilter.AddFacet(ProjectFilterTypes.Version, "1.16.5", LogicalOperator.Or);
88+
// Add facets to narrow down results
89+
modFilter.AddFacet(ProjectFilterTypes.Category, "optimization", LogicalOperator.Or);
90+
modFilter.AddFacet(ProjectFilterTypes.Version, "1.20.1", LogicalOperator.Or);
7591

76-
```
92+
// Retrieve mod project
93+
var modProject = await _api.Mods.FindAsync<ModProject>("sodium", CancellationToken.None);
94+
if (modProject == null) return;
7795

78-
### Step 2: Download a Mod Version with Dependencies
96+
// Get all versions
97+
var versions = await modProject.GetVersionsAsync(CancellationToken.None);
98+
var latestVersion = versions.MaxBy(v => v.DatePublished);
7999

80-
```csharp
81-
// Retrieve the ModProject instance for the mod
82-
var modProject = await _api.Mods.FindAsync<ModProject?>(ProjectId, CancellationToken.None);
100+
if (latestVersion != null)
101+
{
102+
var downloadFolder = Path.Combine(Environment.CurrentDirectory, "mods");
103+
await _api.Mods.DownloadAsync(downloadFolder, latestVersion, true, CancellationToken.None);
104+
Console.WriteLine($"Downloaded {latestVersion.Name} to {downloadFolder}");
105+
}
106+
```
83107

84-
// Retrieve all versions for the mod
85-
var versions = await modProject?.GetVersionsAsync(CancellationToken.None)!;
108+
## Examples
109+
Here’s a complete example combining project search and mod download:
86110

87-
// Assuming you want to download the latest version
88-
var latestVersion = versions.MaxBy(c => c.DatePublished);
111+
```csharp
112+
using Modrinth.Api;
113+
using Modrinth.Api.Core.Filter;
114+
using Modrinth.Api.Core.Projects;
115+
using Modrinth.Api.Models.Dto;
89116

90-
if (latestVersion != null)
117+
namespace ModrinthExample
91118
{
92-
// Set up the folder where you want to download the mod
93-
var folder = Path.Combine(Environment.CurrentDirectory, "mods");
94-
95-
// Download the mod with all dependencies
96-
await _api.Mods.DownloadAsync(folder, latestVersion, true, CancellationToken.None);
119+
public class Program
120+
{
121+
public static async Task Main()
122+
{
123+
var api = new ModrinthApi();
124+
125+
// Search for projects
126+
var filter = new ProjectFilter
127+
{
128+
Query = "adventure",
129+
Limit = 10
130+
};
131+
var projects = await api.Projects.FindAsync<SearchProjectResultDto>(filter, CancellationToken.None);
132+
Console.WriteLine($"Found {projects.Hits.Count} projects.");
133+
134+
// Download a mod
135+
var mod = await api.Mods.FindAsync<ModProject>("fabric-api", CancellationToken.None);
136+
if (mod != null)
137+
{
138+
var versions = await mod.GetVersionsAsync(CancellationToken.None);
139+
var latest = versions.MaxBy(v => v.DatePublished);
140+
if (latest != null)
141+
{
142+
await api.Mods.DownloadAsync("mods", latest, true, CancellationToken.None);
143+
Console.WriteLine("Downloaded Fabric API.");
144+
}
145+
}
146+
}
147+
}
97148
}
98149
```
99150

100-
This code snippet demonstrates how to set up a mod filter, retrieve a list of mods, and download a specific version with all dependencies. Customize the search query, filter options, and version selection according to your project's requirements.
151+
## Contributing
152+
Contributions are welcome! To contribute:
153+
1. Fork the repository.
154+
2. Create a feature branch (`git checkout -b feature/YourFeature`).
155+
3. Commit your changes (`git commit -m 'Add YourFeature'`).
156+
4. Push to the branch (`git push origin feature/YourFeature`).
157+
5. Open a Pull Request.
158+
159+
Please ensure your code follows the project's coding standards and includes appropriate tests.
160+
161+
## License
162+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)