Skip to content

Commit 2c478a8

Browse files
committed
update MForge to ForgeInstaller
1 parent 741293a commit 2c478a8

File tree

10 files changed

+302
-268
lines changed

10 files changed

+302
-268
lines changed

en/SUMMARY.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,4 @@
6767
* [Home](installer.forge/README.md)
6868
* [Supported Versions](installer.forge/supported-versions.md)
6969
* [Getting Started](installer.forge/getting-started.md)
70-
* [MForge](installer.forge/mforge.md)
71-
* [ForgeVersionLoader](installer.forge/forgeversionloader.md)
70+
* [ForgeInstaller](installer.forge/forgeinstaller.md)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# ForgeInstaller
2+
3+
ForgeInstaller provides functionality to download and install Forge versions for Minecraft.
4+
5+
## Initializing the Installer
6+
7+
```csharp
8+
var path = new MinecraftPath();
9+
var launcher = new MinecraftLauncher(path);
10+
var forgeInstaller = new ForgeInstaller(launcher);
11+
```
12+
13+
Optionally, you can configure the HttpClient used to access the Forge website by using `new ForgeInstaller(launcher, new HttpClient())`.
14+
15+
## Listing Available Versions
16+
17+
```csharp
18+
var versions = await forgeInstaller.GetForgeVersions("1.20.1");
19+
foreach (var version in versions)
20+
{
21+
Console.WriteLine();
22+
Console.WriteLine("MinecraftVersion: " + version.MinecraftVersionName);
23+
Console.WriteLine("ForgeVersion: " + version.ForgeVersionName);
24+
Console.WriteLine("Time: " + version.Time);
25+
Console.WriteLine("IsLatestVersion: " + version.IsLatestVersion);
26+
Console.WriteLine("IsRecommendedVersion: " + version.IsRecommendedVersion);
27+
28+
var installerFile = version.GetInstallerFile();
29+
if (installerFile != null)
30+
{
31+
Console.WriteLine("Type: " + installerFile.Type);
32+
Console.WriteLine("DirectUrl: " + installerFile.DirectUrl);
33+
Console.WriteLine("AdUrl: " + installerFile.AdUrl);
34+
Console.WriteLine("MD5: " + installerFile.MD5);
35+
Console.WriteLine("SHA1: " + installerFile.SHA1);
36+
}
37+
}
38+
```
39+
40+
This retrieves all available Forge versions that can be installed for the specified Minecraft version.
41+
42+
## Installation
43+
44+
### Installing the Best Version
45+
46+
```csharp
47+
var installedVersionName = await forgeInstaller.Install("1.20.1", new ForgeInstallOptions());
48+
```
49+
50+
This finds and installs the most appropriate Forge version available for Minecraft 1.20.1.
51+
52+
The appropriate version is selected using the following priority rules:
53+
54+
1. First version with the 'Recommended Version' flag
55+
2. First version with the 'Latest Version' flag
56+
3. The topmost version in the version list
57+
58+
### Installing a Specific Version
59+
60+
```csharp
61+
var installedVersionName = await forgeInstaller.Install("1.20.1", "47.1.0", new ForgeInstallOptions());
62+
```
63+
64+
This installs Forge version 47.1.0 for Minecraft 1.20.1.
65+
66+
### Installing the Latest Version
67+
68+
```csharp
69+
var versions = await forgeInstaller.GetForgeVersions("1.20.1");
70+
var latestVersion = versions.First(v => v.IsLatestVersion);
71+
var installedVersionName = await forgeInstaller.Install(latestVersion, new ForgeInstallOptions());
72+
```
73+
74+
This finds and installs the latest Forge version available for Minecraft 1.20.1.
75+
76+
## Installation Options
77+
78+
To use features like installation progress display and cancellation, configure the appropriate values in `ForgeInstallOptions`.
79+
80+
```csharp
81+
var installOptions = new ForgeInstallOptions
82+
{
83+
FileProgress = new Progress<InstallerProgressChangedEventArgs>(e =>
84+
Console.WriteLine($"[{e.EventType}][{e.ProgressedTasks}/{e.TotalTasks}] {e.Name}")),
85+
ByteProgress = new Progress<ByteProgress>(e =>
86+
Console.WriteLine(e.ToRatio() * 100 + "%")),
87+
InstallerOutput = new Progress<string>(e =>
88+
Console.WriteLine(e)),
89+
CancellationToken = CancellationToken.None,
90+
91+
JavaPath = "java.exe",
92+
SkipIfAlreadyInstalled = true,
93+
};
94+
var installedVersionName = await forgeInstaller.Install("1.20.1", installOptions);
95+
```
96+
97+
- **FileProgress** and **ByteProgress**: Report file download progress. See [Event Handling](../cmllib.core/getting-started/Handling-Events.md) for more details.
98+
- **InstallerOutput**: Reports logs output from the installer's console.
99+
- **CancellationToken**: Allows you to cancel the installation process.
100+
- **JavaPath**: Sets the path to the Java runtime used to execute the installer. The default value is `null`, which automatically determines the Java runtime path.
101+
- **SkipIfAlreadyInstalled**: When set to `true`, skips installation if the target version is already installed. The default value is `true`.
102+
103+
## Important Note About Complete Installation
104+
105+
`forgeInstaller.Install` does not fully install the Forge version. The version still needs additional files such as sound assets, Java runtime, and vanilla version files. Therefore, you should always call `launcher.InstallAsync` before launching the game.
106+
107+
```csharp
108+
// Install Forge
109+
var versionName = await forgeInstaller.Install("1.20.1", new ForgeInstallOptions());
110+
111+
// Install remaining dependencies (sound assets, Java runtime, vanilla version)
112+
await launcher.InstallAsync(versionName);
113+
114+
// Launch the game
115+
var process = await launcher.BuildProcessAsync(versionName, new MLaunchOption
116+
{
117+
MaximumRamMb = 1024,
118+
Session = MSession.CreateOfflineSession("Gamer123"),
119+
});
120+
process.Start();
121+
```
122+
123+
## About Ads
124+
125+
`ForgeInstaller` will display an ad page after a successful installation. The official Forge installer shows the following message:
126+
127+
```
128+
Please do not automate the download and installation of Forge.
129+
Our efforts are supported by ads from the download page.
130+
If you MUST automate this, please consider supporting the project through https://www.patreon.com/LexManos
131+
```
132+
133+
If you want to disable this behavior, you can modify the [ForgeInstaller source code](https://github.com/CmlLib/CmlLib.Core.Installer.Forge/blob/main/CmlLib.Core.Installer.Forge/ForgeInstaller.cs) yourself.

en/installer.forge/forgeversionloader.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

en/installer.forge/getting-started.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Install
44

5-
Install nuget package [CmlLib.Core.Installer.Forge](https://www.nuget.org/packages/CmlLib.Core.Installer.Forge).
5+
Install nuget package [CmlLib.Core.Installer.Forge](https://www.nuget.org/packages/CmlLib.Core.Installer.Forge)
66

77
## Example
88

@@ -15,39 +15,30 @@ using CmlLib.Core.ProcessBuilder;
1515

1616
var path = new MinecraftPath(); // use default directory
1717
var launcher = new MinecraftLauncher(path);
18+
var forgeInstaller = new ForgeInstaller(launcher);
1819

19-
// show launch progress to console
20-
var fileProgress = new SyncProgress<InstallerProgressChangedEventArgs>(e =>
21-
Console.WriteLine($"[{e.EventType}][{e.ProgressedTasks}/{e.TotalTasks}] {e.Name}"));
22-
var byteProgress = new SyncProgress<ByteProgress>(e =>
23-
Console.WriteLine(e.ToRatio() * 100 + "%"));
24-
var installerOutput = new SyncProgress<string>(e =>
25-
Console.WriteLine(e));
26-
27-
//Initialize variables with the Minecraft version and the Forge version
28-
var mcVersion = "1.20.1";
29-
var forgeVersion = "47.2.32";
30-
31-
//Initialize MForge
32-
var forge = new ForgeInstaller(launcher);
20+
var fileProgress = new Progress<InstallerProgressChangedEventArgs>(e =>
21+
Console.WriteLine($"[{e.EventType}][{e.ProgressedTasks}/{e.TotalTasks}] {e.Name}"));
22+
var byteProgress = new Progress<ByteProgress>(e =>
23+
Console.WriteLine(e.ToRatio() * 100 + "%"));
3324

34-
var version_name = await forge.Install(mcVersion, forgeVersion, new ForgeInstallOptions
25+
// install forge
26+
// show launch progress to console
27+
var versionName = await forgeInstaller.Install("1.20.1", new ForgeInstallOptions
3528
{
3629
FileProgress = fileProgress,
3730
ByteProgress = byteProgress,
38-
InstallerOutput = installerOutput,
31+
InstallerOutput = new Progress<string>(e =>
32+
Console.WriteLine(e)),
3933
});
40-
//var version_name = await forge.Install(mcVersion); // install the recommended forge version for mcVersion
41-
//OR var version_name = forge.Install(mcVersion, forgeVersion).GetAwaiter().GetResult();
4234

43-
//Start Minecraft
44-
var launchOption = new MLaunchOption
35+
// ForgeInstaller does not fully install the version, you still need to call InstallAsync
36+
await launcher.InstallAsync(versionName, fileProgress, byteProgress);
37+
var process = await launcher.BuildProcessAsync(versionName, new MLaunchOption
4538
{
4639
MaximumRamMb = 1024,
4740
Session = MSession.CreateOfflineSession("Gamer123"),
48-
};
49-
50-
var process = await launcher.InstallAndBuildProcessAsync(version_name, launchOption);
41+
});
5142

5243
// print game logs
5344
var processUtil = new ProcessWrapper(process);

en/installer.forge/mforge.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

ko/SUMMARY.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,5 @@
6767
* [](installer.forge/README.md)
6868
* [지원되는 버전](installer.forge/supported-versions.md)
6969
* [시작하기](installer.forge/getting-started.md)
70-
* [MForge](installer.forge/mforge.md)
71-
* [ForgeVersionLoader](installer.forge/forgeversionloader.md)
70+
* [ForgeInstaller](installer.forge/forgeinstaller.md)
7271
* [[AD] 커스텀 런처 주문제작](ad.md)

0 commit comments

Comments
 (0)