@@ -102,24 +102,25 @@ func runInstaller(installerPath string, loader string) error {
102102 return nil
103103}
104104
105+ // 下载文件的函数
105106func downloadFile (url , filePath string ) error {
106- if err := os .MkdirAll (filepath .Dir (filePath ), os .ModePerm ); err != nil {
107- return fmt .Errorf ("无法创建目录 %s: %v" , filepath .Dir (filePath ), err )
108- }
109107 resp , err := http .Get (url )
110108 if err != nil {
111109 return fmt .Errorf ("无法下载文件: %v" , err )
112110 }
113111 defer resp .Body .Close ()
112+
114113 file , err := os .Create (filePath )
115114 if err != nil {
116115 return fmt .Errorf ("无法创建文件: %v" , err )
117116 }
118117 defer file .Close ()
118+
119119 _ , err = io .Copy (file , resp .Body )
120120 if err != nil {
121121 return fmt .Errorf ("无法写入文件: %v" , err )
122122 }
123+
123124 return nil
124125}
125126
@@ -197,7 +198,16 @@ func downloadLibraries(versionInfo VersionInfo, librariesDir string, maxConnecti
197198 continue
198199 }
199200
200- url := strings .Replace (lib .Downloads .Artifact .URL , "https://maven.minecraftforge.net/" , "https://bmclapi2.bangbang93.com/maven/" , 1 )
201+ url := lib .Downloads .Artifact .URL
202+ url = strings .Replace (url , "https://maven.minecraftforge.net/" , "https://bmclapi2.bangbang93.com/maven/" , 1 )
203+ url = strings .Replace (url , "https://maven.fabricmc.net/" , "https://bmclapi2.bangbang93.com/maven/" , 1 )
204+ url = strings .Replace (url , "https://maven.neoforged.net/releases/" , "https://bmclapi2.bangbang93.com/maven/" , 1 )
205+ url = strings .Replace (url , "https://libraries.minecraft.net/" , "https://bmclapi2.bangbang93.com/maven/" , 1 )
206+
207+ if url == "" {
208+ fmt .Printf ("警告: 处理后 URL 仍为空,跳过库 %s\n " , lib .Name )
209+ continue
210+ }
201211 filePath := filepath .Join (librariesDir , lib .Downloads .Artifact .Path )
202212
203213 wg .Add (1 )
@@ -216,6 +226,9 @@ func downloadLibraries(versionInfo VersionInfo, librariesDir string, maxConnecti
216226 os .Remove (filePath )
217227 }
218228 }
229+ if err := os .MkdirAll (filepath .Dir (filePath ), os .ModePerm ); err != nil {
230+ fmt .Printf ("无法创建目录: %v\n " , err )
231+ }
219232 fmt .Println ("正在下载:" , url )
220233 if err := downloadFile (url , filePath ); err != nil {
221234 fmt .Printf ("下载失败 %s (%s): %v\n " , lib .Name , url , err )
0 commit comments