7
7
using System . Text . RegularExpressions ;
8
8
using Microsoft . Build . Framework ;
9
9
using Microsoft . Build . Utilities ;
10
- using Newtonsoft . Json ;
11
10
using StardewModdingAPI . ModBuildConfig . Framework ;
12
- using StardewModdingAPI . Toolkit . Framework ;
13
- using StardewModdingAPI . Toolkit . Serialization ;
14
- using StardewModdingAPI . Toolkit . Serialization . Models ;
15
11
using StardewModdingAPI . Toolkit . Utilities ;
16
12
17
13
namespace StardewModdingAPI . ModBuildConfig ;
@@ -34,6 +30,10 @@ public class DeployModTask : Task
34
30
[ Required ]
35
31
public string ModZipPath { get ; set ; }
36
32
33
+ /// <summary>The version number for the project assembly.</summary>
34
+ [ Required ]
35
+ public string ProjectVersion { get ; set ; }
36
+
37
37
/// <summary>The folder containing the project files.</summary>
38
38
[ Required ]
39
39
public string ProjectDir { get ; set ; }
@@ -87,33 +87,12 @@ public override bool Execute()
87
87
if ( ! this . EnableModDeploy && ! this . EnableModZip )
88
88
return true ;
89
89
90
- // validate the manifest file
91
- IManifest manifest ;
90
+ // read & validate manifest
91
+ string manifestPath = Path . Combine ( this . ProjectDir , BundleFile . ManifestFileName ) ;
92
+ if ( ! ManifestHelper . TryLoadManifest ( manifestPath , this . ProjectVersion , out IManifest manifest , out string overrideManifestJson , out string error ) )
92
93
{
93
- try
94
- {
95
- string manifestPath = Path . Combine ( this . ProjectDir , "manifest.json" ) ;
96
- if ( ! new JsonHelper ( ) . ReadJsonFileIfExists ( manifestPath , out Manifest rawManifest ) )
97
- {
98
- this . Log . LogError ( "[mod build package] The mod's manifest.json file doesn't exist." ) ;
99
- return false ;
100
- }
101
- manifest = rawManifest ;
102
- }
103
- catch ( JsonReaderException ex )
104
- {
105
- // log the inner exception, otherwise the message will be generic
106
- Exception exToShow = ex . InnerException ?? ex ;
107
- this . Log . LogError ( $ "[mod build package] The mod's manifest.json file isn't valid JSON: { exToShow . Message } ") ;
108
- return false ;
109
- }
110
-
111
- // validate manifest fields
112
- if ( ! ManifestValidator . TryValidateFields ( manifest , out string error ) )
113
- {
114
- this . Log . LogError ( $ "[mod build package] The mod's manifest.json file is invalid: { error } ") ;
115
- return false ;
116
- }
94
+ this . Log . LogError ( $ "[mod build package] The mod's { BundleFile . ManifestFileName } is invalid: { error } ") ;
95
+ return false ;
117
96
}
118
97
119
98
// deploy files
@@ -128,7 +107,7 @@ public override bool Execute()
128
107
129
108
var modPackages = new Dictionary < string , IModFileManager >
130
109
{
131
- [ this . ModFolderName ] = new MainModFileManager ( this . ProjectDir , this . TargetDir , ignoreFilePaths , ignoreFilePatterns , bundleAssemblyTypes , this . ModDllName , validateRequiredModFiles : this . EnableModDeploy || this . EnableModZip )
110
+ [ this . ModFolderName ] = new MainModFileManager ( this . ProjectDir , this . TargetDir , ignoreFilePaths , ignoreFilePatterns , bundleAssemblyTypes , this . ModDllName , overrideManifestJson , validateRequiredModFiles : this . EnableModDeploy || this . EnableModZip )
132
111
} ;
133
112
134
113
if ( this . ContentPacks != null )
@@ -158,7 +137,7 @@ public override bool Execute()
158
137
this . Log . LogMessage ( MessageImportance . High , $ "[mod build package] Bundling content pack: { folderName } v{ version } at { contentPath } .") ;
159
138
modPackages . Add (
160
139
folderName ,
161
- new ContentPackFileManager ( this . ProjectDir , contentPath , version , ignoreFilePaths , ignoreFilePatterns , validateManifest )
140
+ new ContentPackFileManager ( this . ProjectDir , contentPath , this . ProjectVersion , version , ignoreFilePaths , ignoreFilePatterns , validateManifest )
162
141
) ;
163
142
}
164
143
}
@@ -299,21 +278,17 @@ private IEnumerable<string> GetCustomIgnoreFilePaths(string pattern)
299
278
/// <param name="outputPath">The folder path to create with the mod files.</param>
300
279
private void CreateModFolder ( IDictionary < string , IModFileManager > modPackages , string outputPath )
301
280
{
302
- foreach ( var mod in modPackages )
281
+ foreach ( var pair in modPackages )
303
282
{
304
- string relativePath = modPackages . Count == 1
305
- ? outputPath
306
- : Path . Combine ( outputPath , this . EscapeInvalidFilenameCharacters ( mod . Key ) ) ;
307
-
308
- foreach ( var file in mod . Value . GetFiles ( ) )
309
- {
310
- string fromPath = file . Value . FullName ;
311
- string toPath = Path . Combine ( relativePath , file . Key ) ;
283
+ string folderName = pair . Key ;
284
+ IModFileManager fileManager = pair . Value ;
312
285
313
- Directory . CreateDirectory ( Path . GetDirectoryName ( toPath ) ! ) ;
286
+ string folderPath = modPackages . Count == 1
287
+ ? outputPath
288
+ : Path . Combine ( outputPath , this . EscapeInvalidFilenameCharacters ( folderName ) ) ;
314
289
315
- File . Copy ( fromPath , toPath , overwrite : true ) ;
316
- }
290
+ foreach ( BundleFile from in fileManager . GetFiles ( ) )
291
+ from . CopyToFolder ( folderPath ) ;
317
292
}
318
293
}
319
294
@@ -330,21 +305,19 @@ private void CreateReleaseZip(IDictionary<string, IModFileManager> modPackages,
330
305
foreach ( var mod in modPackages )
331
306
{
332
307
string modFolder = this . EscapeInvalidFilenameCharacters ( mod . Key ) ;
333
- foreach ( var file in mod . Value . GetFiles ( ) )
308
+ foreach ( BundleFile from in mod . Value . GetFiles ( ) )
334
309
{
335
- string relativePath = file . Key ;
310
+ string relativePath = from . RelativePath ;
311
+
336
312
if ( relativePath . Contains ( '\\ ' ) )
337
313
relativePath = string . Join ( "/" , PathUtilities . GetSegments ( relativePath ) ) ; // zip files use forward slashes regardless of OS
338
314
339
- FileInfo fileInfo = file . Value ;
340
-
341
315
string archivePath = modPackages . Count == 1
342
316
? $ "{ modFolder } /{ relativePath } "
343
317
: $ "{ this . ModFolderName } /{ modFolder } /{ relativePath } ";
344
318
345
- using Stream fileStream = new FileStream ( fileInfo . FullName , FileMode . Open , FileAccess . Read ) ;
346
319
using Stream fileStreamInZip = archive . CreateEntry ( archivePath ) . Open ( ) ;
347
- fileStream . CopyTo ( fileStreamInZip ) ;
320
+ from . CopyToStream ( fileStreamInZip ) ;
348
321
}
349
322
}
350
323
}
0 commit comments