Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #266 from RPMTW/fix/modrinth
Browse files Browse the repository at this point in the history
fix: download mods on Modrinth
  • Loading branch information
SiongSng authored Jul 4, 2022
2 parents 7376768 + e804192 commit 33b9f6e
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 220 deletions.
2 changes: 1 addition & 1 deletion lib/account/microsoft_account_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:oauth2/oauth2.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/model/account/Account.dart';
import 'package:rpmlauncher/model/account/MicrosoftEntitlements.dart';
import 'package:rpmlauncher/util/data.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/account/mojang_account_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';

import 'package:dio/dio.dart';
import 'package:http/http.dart' as http;
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/util/data.dart';
import 'package:rpmlauncher/util/I18n.dart';
// ignore: depend_on_referenced_packages
Expand Down
21 changes: 0 additions & 21 deletions lib/launcher/APIs.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/launcher/Fabric/FabricAPI.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:dio/dio.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/model/Game/FabricInstallerVersion.dart';
import 'package:rpmlauncher/util/RPMHttpClient.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/launcher/Fabric/FabricServer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/launcher/Fabric/FabricAPI.dart';
import 'package:rpmlauncher/launcher/GameRepository.dart';
import 'package:rpmlauncher/launcher/MinecraftServer.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/launcher/Forge/ForgeAPI.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:rpmlauncher/launcher/GameRepository.dart';
import 'package:archive/archive.dart';
import 'package:http/http.dart';
import 'package:path/path.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/mod/mod_loader.dart';
import 'package:rpmlauncher/model/Game/Libraries.dart';
import 'package:rpmlauncher/model/Game/MinecraftSide.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/launcher/Forge/ForgeClient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:rpmlauncher/util/I18n.dart';
import 'package:rpmlauncher/widget/dialog/UnSupportedForgeVersion.dart';
import 'package:rpmlauncher/widget/rpmtw_design/OkClose.dart';

import '../APIs.dart';
import '../apis.dart';
import '../MinecraftClient.dart';
import 'ForgeInstallProfile.dart';
import 'Processors.dart';
Expand Down
21 changes: 21 additions & 0 deletions lib/launcher/apis.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
String mojangMetaAPI = 'https://launchermeta.mojang.com/mc/game';
String fabricApi = 'https://meta.fabricmc.net/v2';
String forgeFilesAPI = 'https://files.minecraftforge.net';
String forgeFilesMainAPI =
'https://files.minecraftforge.net/net/minecraftforge/forge';
String forgeLatestVersionAPI = '$forgeFilesMainAPI/promotions_slim.json';
String forgeMavenUrl = 'https://maven.minecraftforge.net';
String forgeMavenMainUrl =
'https://maven.minecraftforge.net/net/minecraftforge/forge';
String mojangJavaRuntimeAPI =
'https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json';
String mojangAuthAPI = 'https://authserver.mojang.com';
String microsoftProfileAPI =
'https://api.minecraftservices.com/minecraft/profile';
String modrinthAPI = 'https://api.modrinth.com/v2';
String ftbModPackAPI = 'https://api.modpacks.ch/public';
String minecraftNewsRSS =
'https://www.minecraft.net/en-us/feeds/community-content/rss';
String recommendedModpack =
'https://github.com/RPMTW/RPMTW-website-data/raw/main/data/RPMLauncher/recommend-modpack.json';
String paperApi = 'https://papermc.io/api/v2';
2 changes: 1 addition & 1 deletion lib/mod/FTB/Handler.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/util/I18n.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
Expand Down
79 changes: 0 additions & 79 deletions lib/mod/ModrinthHandler.dart

This file was deleted.

78 changes: 78 additions & 0 deletions lib/mod/modrinth_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:dio/dio.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/util/I18n.dart';
import 'package:flutter/material.dart';
import 'package:rpmlauncher/util/RPMHttpClient.dart';

class ModrinthHandler {
static Future<List<dynamic>> getModList(String versionID, String loader,
TextEditingController search, List beforeModList, int index, sort) async {
String searchFilter = '';
if (search.text.isNotEmpty) {
searchFilter = '&query=${search.text}';
}
List modList = beforeModList;
Response response = await RPMHttpClient().get(
'$modrinthAPI/search?facets=[["versions:$versionID"],["categories:$loader"],["project_type:mod"]]$searchFilter&offset=${20 * index}&limit=20&index=$sort');
Map body = RPMHttpClient.json(response);
modList.addAll(body['hits']);
return modList;
}

static Future<List<dynamic>> getModFilesInfo(
modrinthID, versionID, loader) async {
Response response =
await RPMHttpClient().get('$modrinthAPI/project/$modrinthID/version');
late List<dynamic> filesInfo = [];

List<Map> modVersions = RPMHttpClient.json(response).cast<Map>();
modVersions.forEach((versions) {
if (versions['game_versions'].any((element) => element == versionID) &&
versions['loaders'].any((element) => element == loader)) {
filesInfo.add(versions);
}
});
return filesInfo;
}

static Text parseReleaseType(String releaseType) {
late Text releaseTypeString;
if (releaseType == 'release') {
releaseTypeString = Text(I18n.format('edit.instance.mods.release'),
style: const TextStyle(color: Colors.lightGreen));
} else if (releaseType == 'beta') {
releaseTypeString = Text(I18n.format('edit.instance.mods.beta'),
style: const TextStyle(color: Colors.lightBlue));
} else if (releaseType == 'alpha') {
releaseTypeString = Text(I18n.format('edit.instance.mods.alpha'),
style: const TextStyle(color: Colors.red));
}
return releaseTypeString;
}

static Text parseSide(String sideString, String side, Map data) {
Text parse(sideName, type) {
late final Text sideText;
if (type == 'required') {
sideText = Text(
sideName + I18n.format('edit.instance.mods.side.required'),
style: const TextStyle(color: Colors.red),
);
} else if (type == 'optional') {
sideText = Text(
sideName + I18n.format('edit.instance.mods.side.optional'),
style: const TextStyle(color: Colors.lightGreenAccent),
);
} else if (type == 'unsupported') {
sideText = Text(
sideName + I18n.format('edit.instance.mods.side.unsupported'),
style: const TextStyle(color: Colors.grey),
);
}

return sideText;
}

return parse(sideString, data[side]);
}
}
2 changes: 1 addition & 1 deletion lib/model/Game/MinecraftNews.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:collection';

import 'package:dio/dio.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/util/RPMHttpClient.dart';
import 'package:xml/xml.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/model/Game/MinecraftVersion.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:dio/dio.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:rpmlauncher/launcher/APIs.dart';
import 'package:rpmlauncher/launcher/apis.dart';
import 'package:rpmlauncher/mod/mod_loader.dart';
import 'package:rpmlauncher/model/Game/MinecraftMeta.dart';
import 'package:rpmlauncher/util/RPMHttpClient.dart';
Expand Down
9 changes: 4 additions & 5 deletions lib/pages/curseforge_addon_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _CurseForgeAddonPageState extends State<CurseForgeAddonPage> {
if ((scrollController.position.maxScrollExtent -
scrollController.position.pixels) <
50) {
//如果快要滑動到底部
// if scroll to bottom
index += 20;
setState(() {});
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class _CurseForgeAddonPageState extends State<CurseForgeAddonPage> {
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(I18n.format('edit.instance.mods.sort')),
I18nText('edit.instance.mods.sort'),
DropdownButton<CurseForgeSortField>(
value: sortItem,
onChanged: (CurseForgeSortField? newValue) {
Expand All @@ -90,9 +90,8 @@ class _CurseForgeAddonPageState extends State<CurseForgeAddonPage> {
(CurseForgeSortField value) {
return DropdownMenuItem<CurseForgeSortField>(
value: value,
child: Text(
I18n.format(
'edit.instance.mods.sort.curseforge.${value.name}'),
child: I18nText(
'edit.instance.mods.sort.curseforge.${value.name}',
textAlign: TextAlign.center,
),
);
Expand Down
Loading

0 comments on commit 33b9f6e

Please sign in to comment.