(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -736,14 +736,14 @@ namespace Barotrauma.Steam
/// <summary>
/// Creates a copy of the specified workshop item in the staging folder and an editor that can be used to edit and update the item
/// </summary>
public static void CreateWorkshopItemStaging(Workshop.Item existingItem, out Workshop.Editor itemEditor, out ContentPackage contentPackage)
public static bool CreateWorkshopItemStaging(Workshop.Item existingItem, out Workshop.Editor itemEditor, out ContentPackage contentPackage)
{
if (!existingItem.Installed)
{
itemEditor = null;
contentPackage = null;
DebugConsole.ThrowError("Cannot edit the workshop item \"" + existingItem.Title + "\" because it has not been installed.");
return;
return false;
}
itemEditor = instance.client.Workshop.EditItem(existingItem.Id);
@@ -763,7 +763,7 @@ namespace Barotrauma.Steam
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { existingItem.Title, errorMsg }));
itemEditor = null;
contentPackage = null;
return;
return false;
}
}
@@ -773,7 +773,7 @@ namespace Barotrauma.Steam
if (contentPackage == null && tempContentPackage.GameVersion <= new Version(0, 9, 1, 0))
{
//try finding the content package in the lega
//try finding the content package from the non-legacy path
installedContentPackagePath = Path.GetFullPath(GetWorkshopItemContentPackagePath(tempContentPackage, legacy: false));
contentPackage = ContentPackage.List.Find(cp => Path.GetFullPath(cp.Path) == installedContentPackagePath);
}
@@ -792,8 +792,11 @@ namespace Barotrauma.Steam
contentPackage.Path = newPath;
itemEditor.Folder = newDir;
if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); }
if (File.Exists(newPath)) { File.Delete(newPath); }
File.Move(installedContentPackagePath, newPath);
if (Path.GetFullPath(newPath) != installedContentPackagePath)
{
if (File.Exists(newPath)) { File.Delete(newPath); }
File.Move(installedContentPackagePath, newPath);
}
//move all files inside the Mods folder
foreach (ContentFile cf in contentPackage.Files)
{
@@ -815,7 +818,7 @@ namespace Barotrauma.Steam
string errorMsg = TextManager.GetWithVariable("WorkshopErrorOnEnable", "[itemname]", TextManager.EnsureUTF8(existingItem.Title));
new GUIMessageBox(TextManager.Get("Error"), errorMsg);
DebugConsole.ThrowError(errorMsg, e);
return;
return false;
}
}
@@ -846,6 +849,7 @@ namespace Barotrauma.Steam
GameAnalyticsManager.AddErrorEventOnce("SteamManager.CreateWorkshopItemStaging:WriteAllBytesFailed" + previewImagePath,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg + "\n" + e.Message);
}
return true;
}
public static void StartPublishItem(ContentPackage contentPackage, Workshop.Editor item)
@@ -865,11 +869,9 @@ namespace Barotrauma.Steam
contentPackage.GameVersion = GameMain.Version;
contentPackage.Save(contentPackage.Path);
if (File.Exists(PreviewImageName)) { File.Delete(PreviewImageName); }
//move the preview image out of the staging folder, it does not need to be included in the folder sent to Workshop
File.Move(Path.GetFullPath(Path.Combine(item.Folder, PreviewImageName)), PreviewImageName);
item.PreviewImage = Path.GetFullPath(PreviewImageName);
string previewImagePath = Path.GetFullPath(Path.Combine(item.Folder, PreviewImageName));
item.PreviewImage = File.Exists(previewImagePath) ? previewImagePath : null;
CoroutineManager.StartCoroutine(PublishItem(item));
}
@@ -904,7 +906,7 @@ namespace Barotrauma.Steam
/// <summary>
/// Enables a workshop item by moving it to the game folder.
/// </summary>
public static bool EnableWorkShopItem(Workshop.Item item, bool allowFileOverwrite, out string errorMsg)
public static bool EnableWorkShopItem(Workshop.Item item, bool allowFileOverwrite, out string errorMsg, bool selectContentPackage = true)
{
if (!item.Installed)
{
@@ -959,19 +961,24 @@ namespace Barotrauma.Steam
}
newPackage.Save(newContentPackagePath);
ContentPackage.List.Add(newPackage);
if (newPackage.CorePackage)
if (selectContentPackage)
{
//if enabling a core package, disable all other core packages
GameMain.Config.SelectedContentPackages.RemoveWhere(cp => cp.CorePackage);
if (newPackage.CorePackage)
{
//if enabling a core package, disable all other core packages
GameMain.Config.SelectedContentPackages.RemoveAll(cp => cp.CorePackage);
}
GameMain.Config.SelectContentPackage(newPackage);
GameMain.Config.SaveNewPlayerConfig();
foreach (ContentFile cf in newPackage.Files)
{
if (cf.Type == ContentType.Submarine)
{
Submarine.RefreshSavedSub(cf.Path);
}
}
}
GameMain.Config.SelectedContentPackages.Add(newPackage);
GameMain.Config.SaveNewPlayerConfig();
if (newPackage.Files.Any(f => f.Type == ContentType.Submarine))
{
Submarine.RefreshSavedSubs();
}
errorMsg = "";
return true;
}
@@ -1166,7 +1173,8 @@ namespace Barotrauma.Steam
}
ContentPackage.List.RemoveAll(cp => System.IO.Path.GetFullPath(cp.Path) == System.IO.Path.GetFullPath(installedContentPackagePath));
GameMain.Config.SelectedContentPackages.RemoveWhere(cp => !ContentPackage.List.Contains(cp));
GameMain.Config.SelectedContentPackages.RemoveAll(cp => !ContentPackage.List.Contains(cp));
ContentPackage.SortContentPackages();
GameMain.Config.SaveNewPlayerConfig();
}
catch (Exception e)
@@ -1218,7 +1226,7 @@ namespace Barotrauma.Steam
{
metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
}
catch (ArgumentException e)
catch (ArgumentException)
{
string errorMessage = "Metadata file for the Workshop item \"" + item.Title +
"\" not found. Could not combine path (" + (item.Directory.FullName ?? "directory name empty") + ").";
@@ -1255,7 +1263,7 @@ namespace Barotrauma.Steam
public static bool CheckWorkshopItemUpToDate(Workshop.Item item)
{
if (!item.Installed) return false;
if (!item.Installed) { return false; }
string metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
if (!File.Exists(metaDataPath))
@@ -1274,6 +1282,22 @@ namespace Barotrauma.Steam
return item.Modified <= myPackage.InstallTime.Value;
}
public static bool CheckWorkshopItemSelected(Workshop.Item item)
{
if (!item.Installed) { return false; }
string metaDataPath = Path.Combine(item.Directory.FullName, MetadataFileName);
if (!File.Exists(metaDataPath))
{
DebugConsole.ThrowError("Metadata file for the Workshop item \"" + item.Title + "\" not found. The file may be corrupted.");
return false;
}
ContentPackage steamPackage = new ContentPackage(metaDataPath);
return GameMain.Config.SelectedContentPackages.Any(cp => cp.Name == steamPackage.Name);
}
public static bool AutoUpdateWorkshopItems()
{
if (instance == null || !instance.isInitialized) { return false; }
@@ -1290,8 +1314,9 @@ namespace Barotrauma.Steam
itemsUpdated = false;
foreach (var item in q.Items)
{
if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item))
try
{
if (!item.Installed || !CheckWorkshopItemEnabled(item) || CheckWorkshopItemUpToDate(item)) { continue; }
if (!UpdateWorkshopItem(item, out string errorMsg))
{
DebugConsole.ThrowError(errorMsg);
@@ -1305,6 +1330,16 @@ namespace Barotrauma.Steam
itemsUpdated = true;
}
}
catch (Exception e)
{
new GUIMessageBox(
TextManager.Get("Error"),
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, e.Message + ", " + e.TargetSite }));
GameAnalyticsManager.AddErrorEventOnce(
"SteamManager.AutoUpdateWorkshopItems:" + e.Message,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Failed to autoupdate workshop item \"" + item.Title + "\". " + e.Message + "\n" + e.StackTrace);
}
}
};
@@ -1328,8 +1363,9 @@ namespace Barotrauma.Steam
{
errorMsg = "";
if (!item.Installed) { return false; }
bool wasSelected = CheckWorkshopItemSelected(item);
if (!DisableWorkShopItem(item, out errorMsg)) { return false; }
if (!EnableWorkShopItem(item, allowFileOverwrite: false, errorMsg: out errorMsg)) { return false; }
if (!EnableWorkShopItem(item, allowFileOverwrite: false, errorMsg: out errorMsg, selectContentPackage: wasSelected)) { return false; }
return true;
}