summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-08 02:22:12 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-08 02:22:12 -0400
commit0e5982bf9c21acd0429f05a0a608303f72b7b470 (patch)
treef0c73ed27a2edcc7a370059d5c176a72aac2a214
parentca58da37cd8cd9818b71a2b67b5186e7ab81a73c (diff)
downloadSMAPI-0e5982bf9c21acd0429f05a0a608303f72b7b470.tar.gz
SMAPI-0e5982bf9c21acd0429f05a0a608303f72b7b470.tar.bz2
SMAPI-0e5982bf9c21acd0429f05a0a608303f72b7b470.zip
escape invalid characters in release zip paths
-rw-r--r--src/SMAPI.ModBuildConfig/Tasks/CreateModReleaseZip.cs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/SMAPI.ModBuildConfig/Tasks/CreateModReleaseZip.cs b/src/SMAPI.ModBuildConfig/Tasks/CreateModReleaseZip.cs
index 26f2ed44..dd89d6b8 100644
--- a/src/SMAPI.ModBuildConfig/Tasks/CreateModReleaseZip.cs
+++ b/src/SMAPI.ModBuildConfig/Tasks/CreateModReleaseZip.cs
@@ -45,18 +45,17 @@ namespace StardewModdingAPI.ModBuildConfig.Tasks
{
try
{
- // create output path if needed
- Directory.CreateDirectory(this.OutputFolderPath);
-
- // get zip filename
- string fileName = $"{this.ModName}-{this.GetManifestVersion()}.zip";
+ // get names
+ string zipName = this.EscapeInvalidFilenameCharacters($"{this.ModName}-{this.GetManifestVersion()}.zip");
+ string folderName = this.EscapeInvalidFilenameCharacters(this.ModName);
+ string zipPath = Path.Combine(this.OutputFolderPath, zipName);
// clear old zip file if present
- string zipPath = Path.Combine(this.OutputFolderPath, fileName);
if (File.Exists(zipPath))
File.Delete(zipPath);
// create zip file
+ Directory.CreateDirectory(this.OutputFolderPath);
using (Stream zipStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write))
using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
{
@@ -64,7 +63,7 @@ namespace StardewModdingAPI.ModBuildConfig.Tasks
{
// get file info
string filePath = file.ItemSpec;
- string entryName = this.ModName + '/' + file.GetMetadata("RecursiveDir") + file.GetMetadata("Filename") + file.GetMetadata("Extension");
+ string entryName = folderName + '/' + file.GetMetadata("RecursiveDir") + file.GetMetadata("Filename") + file.GetMetadata("Extension");
if (new FileInfo(filePath).Directory.Name.Equals("i18n", StringComparison.InvariantCultureIgnoreCase))
entryName = Path.Combine("i18n", entryName);
@@ -138,5 +137,14 @@ namespace StardewModdingAPI.ModBuildConfig.Tasks
IDictionary<string, object> data = (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
return MakeCaseInsensitive(data);
}
+
+ /// <summary>Get a copy of a filename with all invalid filename characters substituted.</summary>
+ /// <param name="name">The filename.</param>
+ private string EscapeInvalidFilenameCharacters(string name)
+ {
+ foreach (char invalidChar in Path.GetInvalidFileNameChars())
+ name = name.Replace(invalidChar, '.');
+ return name;
+ }
}
}