(acf0cb343) Fixes to EnableWorkShopItem: - Don't allow enabling if the item is not compatible with the user's version of Barotrauma or if it's a core package that's missing some required files. - Don't allow enabling if the item external files referenced in the content package are not found (e.g. if a mod uses vanilla files but the vanilla files aren't found).
This commit is contained in:
@@ -583,6 +583,23 @@ namespace Barotrauma.Steam
|
||||
ContentPackage contentPackage = new ContentPackage(metaDataFilePath);
|
||||
string newContentPackagePath = GetWorkshopItemContentPackagePath(contentPackage);
|
||||
|
||||
if (!contentPackage.IsCompatible())
|
||||
{
|
||||
errorMsg = TextManager.Get(contentPackage.GameVersion <= new Version(0, 0, 0, 0) ? "IncompatibleContentPackageUnknownVersion" : "IncompatibleContentPackage")
|
||||
.Replace("[packagename]", contentPackage.Name)
|
||||
.Replace("[packageversion]", contentPackage.GameVersion.ToString())
|
||||
.Replace("[gameversion]", GameMain.Version.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (contentPackage.CorePackage && !contentPackage.ContainsRequiredCorePackageFiles(out List<ContentType> missingContentTypes))
|
||||
{
|
||||
errorMsg = TextManager.Get("ContentPackageMissingCoreFiles")
|
||||
.Replace("[packagename]", contentPackage.Name)
|
||||
.Replace("[missingfiletypes]", string.Join(", ", missingContentTypes));
|
||||
return false;
|
||||
}
|
||||
|
||||
var allPackageFiles = Directory.GetFiles(item.Directory.FullName, "*", SearchOption.AllDirectories);
|
||||
List<string> nonContentFiles = new List<string>();
|
||||
foreach (string file in allPackageFiles)
|
||||
@@ -599,8 +616,6 @@ namespace Barotrauma.Steam
|
||||
|
||||
if (!allowFileOverwrite)
|
||||
{
|
||||
// TODO: If you create a new mod via the workshop interface and enable it, it will show the error msg, but still allows you to enable the content.
|
||||
|
||||
if (File.Exists(newContentPackagePath) && !CheckFileEquality(newContentPackagePath, metaDataFilePath))
|
||||
{
|
||||
errorMsg = TextManager.Get("WorkshopErrorOverwriteOnEnable")
|
||||
@@ -629,12 +644,41 @@ namespace Barotrauma.Steam
|
||||
foreach (ContentFile contentFile in contentPackage.Files)
|
||||
{
|
||||
string sourceFile = Path.Combine(item.Directory.FullName, contentFile.Path);
|
||||
if (!File.Exists(sourceFile)) { continue; }
|
||||
|
||||
//path not allowed -> the content file must be a reference to an external file (such as some vanilla file outside the Mods folder)
|
||||
if (!ContentPackage.IsModFilePathAllowed(contentFile))
|
||||
{
|
||||
DebugConsole.ThrowError(TextManager.Get("WorkshopErrorIllegalPathOnEnable").Replace("[filename]", contentFile.Path));
|
||||
//the content package is trying to copy a file to a prohibited path, which is not allowed
|
||||
if (File.Exists(sourceFile))
|
||||
{
|
||||
errorMsg = TextManager.Get("WorkshopErrorIllegalPathOnEnable").Replace("[filename]", contentFile.Path);
|
||||
return false;
|
||||
}
|
||||
//not trying to copy anything, so this is a reference to an external file
|
||||
//if the external file doesn't exist, we cannot enable the package
|
||||
else if (!File.Exists(contentFile.Path))
|
||||
{
|
||||
//TODO: add the error message to localization
|
||||
errorMsg = TextManager.Get("WorkshopErrorEnableFailed").Replace("[itemname]", item.Title) + " {File \"" + contentFile.Path + "\" not found.}";
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (!File.Exists(sourceFile))
|
||||
{
|
||||
if (File.Exists(contentFile.Path))
|
||||
{
|
||||
//the file is already present in the game folder, all good
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//file not present in either the mod or the game folder -> cannot enable the package
|
||||
//TODO: add the error message to localization
|
||||
errorMsg = TextManager.Get("WorkshopErrorEnableFailed").Replace("[itemname]", item.Title) + " {File \"" + contentFile.Path + "\" not found.}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//make sure the destination directory exists
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(contentFile.Path));
|
||||
@@ -656,7 +700,7 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorMsg = TextManager.Get("WorkshopErrorEnableFailed").Replace("[itemname]", item.Title) + " " + e.Message;
|
||||
errorMsg = TextManager.Get("WorkshopErrorEnableFailed").Replace("[itemname]", item.Title) + " {" + e.Message + "}";
|
||||
DebugConsole.NewMessage(errorMsg, Microsoft.Xna.Framework.Color.Red);
|
||||
return false;
|
||||
}
|
||||
@@ -827,7 +871,7 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
foreach (ContentFile contentFile in contentPackage.Files)
|
||||
{
|
||||
if (!File.Exists(contentFile.Path)) return false;
|
||||
if (!File.Exists(contentFile.Path)) { return false; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user