Skip to content

Commit 199f76e

Browse files
Add zip artifact support for mods
1 parent 26c7269 commit 199f76e

4 files changed

Lines changed: 355 additions & 71 deletions

File tree

Natives/installer/modpack/CurseForgeAPI.m

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define kCurseForgeGameIDMinecraft 432
99
#define kCurseForgeClassIDModpack 4471
1010
#define kCurseForgeClassIDMod 6
11+
#define kCurseForgeClassIDResourcePack 12
12+
#define kCurseForgeClassIDShader 6552
1113
#define kCurseForgePageSize 50
1214
#define kCurseForgeModLoaderForge 1
1315
#define kCurseForgeModLoaderFabric 4
@@ -113,6 +115,19 @@ - (NSArray *)normalizedCurseForgeDependencies:(NSArray *)dependencies {
113115
return result;
114116
}
115117

118+
- (NSString *)installDirectoryForProject:(NSDictionary *)project {
119+
NSInteger classID = [project[@"classId"] respondsToSelector:@selector(integerValue)] ? [project[@"classId"] integerValue] : kCurseForgeClassIDMod;
120+
NSDictionary *links = [project[@"links"] isKindOfClass:NSDictionary.class] ? project[@"links"] : nil;
121+
NSString *websiteURL = [links[@"websiteUrl"] isKindOfClass:NSString.class] ? [links[@"websiteUrl"] lowercaseString] : @"";
122+
if (classID == kCurseForgeClassIDResourcePack || [websiteURL containsString:@"/texture-packs/"]) {
123+
return @"resourcepacks";
124+
}
125+
if (classID == kCurseForgeClassIDShader || [websiteURL containsString:@"/shaders/"]) {
126+
return @"shaderpacks";
127+
}
128+
return @"mods";
129+
}
130+
116131
- (NSDictionary *)modManagerRecordForFile:(NSDictionary *)file projectID:(NSNumber *)projectID fileName:(NSString *)fileName projectCache:(NSMutableDictionary *)projectCache {
117132
NSDictionary *project = [self projectInfoForProjectID:projectID cache:projectCache];
118133
NSDictionary *logo = [project[@"logo"] isKindOfClass:NSDictionary.class] ? project[@"logo"] : nil;
@@ -136,6 +151,8 @@ - (NSDictionary *)modManagerRecordForFile:(NSDictionary *)file projectID:(NSNumb
136151
@"gameVersion": [self minecraftVersionForFile:file],
137152
@"dependencies": [self normalizedCurseForgeDependencies:([file[@"dependencies"] isKindOfClass:NSArray.class] ? file[@"dependencies"] : @[])],
138153
@"dependencyMetadataCheckedAt": @([[NSDate date] timeIntervalSince1970]),
154+
@"artifactType": @"mod",
155+
@"installDirectory": @"mods",
139156
@"enabled": @YES
140157
};
141158
}
@@ -215,7 +232,14 @@ - (NSString *)manualDownloadPageURLForFile:(NSDictionary *)file projectID:(NSNum
215232
NSString *slug = project[@"slug"];
216233
if ([slug isKindOfClass:NSString.class] && slug.length > 0) {
217234
NSInteger classID = [project[@"classId"] respondsToSelector:@selector(integerValue)] ? [project[@"classId"] integerValue] : kCurseForgeClassIDMod;
218-
NSString *section = classID == kCurseForgeClassIDModpack ? @"modpacks" : @"mc-mods";
235+
NSString *section = @"mc-mods";
236+
if (classID == kCurseForgeClassIDModpack) {
237+
section = @"modpacks";
238+
} else if (classID == kCurseForgeClassIDResourcePack) {
239+
section = @"texture-packs";
240+
} else if (classID == kCurseForgeClassIDShader) {
241+
section = @"shaders";
242+
}
219243
return [NSString stringWithFormat:@"https://www.curseforge.com/minecraft/%@/%@/download/%@", section, slug, fileID];
220244
}
221245

@@ -368,7 +392,8 @@ - (NSMutableArray *)searchModWithFilters:(NSDictionary<NSString *, NSString *> *
368392
@"id": modID,
369393
@"title": title,
370394
@"description": description,
371-
@"imageUrl": imageUrl
395+
@"imageUrl": imageUrl,
396+
@"classId": mod[@"classId"] ?: @0
372397
}.mutableCopy];
373398
}
374399

@@ -574,7 +599,9 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
574599
return;
575600
}
576601

577-
[NSFileManager.defaultManager removeItemAtPath:[destPath stringByAppendingPathComponent:@"mods"] error:nil];
602+
for (NSString *managedDirectory in @[@"mods", @"resourcepacks", @"shaderpacks"]) {
603+
[NSFileManager.defaultManager removeItemAtPath:[destPath stringByAppendingPathComponent:managedDirectory] error:nil];
604+
}
578605

579606
NSMutableArray *manualDownloads = [NSMutableArray new];
580607
NSMutableArray *modManagerRecords = [NSMutableArray new];
@@ -600,14 +627,18 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
600627
return;
601628
}
602629

603-
NSString *relativePath = [@"mods" stringByAppendingPathComponent:fileName];
630+
NSDictionary *project = [self projectInfoForProjectID:projectID cache:projectCache];
631+
NSString *installDirectory = [self installDirectoryForProject:project];
632+
NSString *relativePath = [installDirectory stringByAppendingPathComponent:fileName];
604633
NSString *path = [destPath stringByAppendingPathComponent:relativePath];
605634
NSUInteger size = [file[@"fileLength"] respondsToSelector:@selector(unsignedLongLongValue)] ? [file[@"fileLength"] unsignedLongLongValue] : 0;
606635
if (size == 0) {
607636
size = [file[@"fileSizeOnDisk"] respondsToSelector:@selector(unsignedLongLongValue)] ? [file[@"fileSizeOnDisk"] unsignedLongLongValue] : 0;
608637
}
609638
NSString *sha = [self sha1HashForFile:file];
610-
[modManagerRecords addObject:[self modManagerRecordForFile:file projectID:projectID fileName:fileName projectCache:projectCache]];
639+
if ([installDirectory isEqualToString:@"mods"]) {
640+
[modManagerRecords addObject:[self modManagerRecordForFile:file projectID:projectID fileName:fileName projectCache:projectCache]];
641+
}
611642
NSString *url = [self downloadURLForFile:file projectID:projectID];
612643
if (url.length == 0) {
613644
NSString *manualURL = [self manualDownloadPageURLForFile:file projectID:projectID cache:projectCache];

Natives/installer/modpack/ModrinthAPI.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ - (NSMutableArray *)searchModWithFilters:(NSDictionary<NSString *, NSString *> *
6565
@"id": projectID,
6666
@"title": title,
6767
@"description": description,
68-
@"imageUrl": imageUrl
68+
@"imageUrl": imageUrl,
69+
@"projectType": hit[@"project_type"] ?: @""
6970
}.mutableCopy];
7071
}
7172
NSUInteger totalHits = [response[@"total_hits"] respondsToSelector:@selector(unsignedLongValue)] ? [response[@"total_hits"] unsignedLongValue] : result.count;
@@ -197,7 +198,9 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
197198
return;
198199
}
199200

200-
[NSFileManager.defaultManager removeItemAtPath:[destPath stringByAppendingPathComponent:@"mods"] error:nil];
201+
for (NSString *managedDirectory in @[@"mods", @"resourcepacks", @"shaderpacks"]) {
202+
[NSFileManager.defaultManager removeItemAtPath:[destPath stringByAppendingPathComponent:managedDirectory] error:nil];
203+
}
201204

202205
NSMutableArray *modManagerRecords = [NSMutableArray new];
203206
for (NSDictionary *indexFile in indexFiles) {
@@ -228,14 +231,18 @@ - (void)downloader:(MinecraftResourceDownloadTask *)downloader submitDownloadTas
228231
sha = nil;
229232
}
230233
NSString *fileName = relativePath.lastPathComponent;
231-
if ([relativePath hasPrefix:@"mods/"] && [fileName.lowercaseString hasSuffix:@".jar"]) {
234+
NSString *lowerFileName = fileName.lowercaseString;
235+
if ([relativePath hasPrefix:@"mods/"] &&
236+
([lowerFileName hasSuffix:@".jar"] || [lowerFileName hasSuffix:@".zip"])) {
232237
NSString *source = [self modManagerSourceForDownloadURLs:downloads];
233238
[modManagerRecords addObject:@{
234239
@"source": source,
235240
@"fileName": fileName,
236241
@"downloadUrl": url,
237242
@"sha1": sha ?: @"",
238243
@"size": [indexFile[@"fileSize"] respondsToSelector:@selector(unsignedLongLongValue)] ? indexFile[@"fileSize"] : @0,
244+
@"artifactType": @"mod",
245+
@"installDirectory": @"mods",
239246
@"enabled": @YES
240247
}];
241248
}

0 commit comments

Comments
 (0)