(ffa166343) Workshop fixes: - Refresh content package file in the staging folder when adding/removing files, not just when publishing. - Allow multiselecting files in the "add files" dialog. - Fixed autoupdating workshop files not working because Workshop.GetItem doesn't query the time the item was modified. - Some extra exception handling.

This commit is contained in:
Joonas Rikkonen
2019-06-11 21:45:01 +03:00
parent a4875cfeb3
commit 7dfa6e89fe
3 changed files with 65 additions and 22 deletions
@@ -594,8 +594,15 @@ namespace Barotrauma.Steam
} }
SaveUtil.ClearFolder(WorkshopItemStagingFolder); SaveUtil.ClearFolder(WorkshopItemStagingFolder);
Directory.Delete(WorkshopItemStagingFolder);
File.Delete(PreviewImageName); File.Delete(PreviewImageName);
try
{
Directory.Delete(WorkshopItemStagingFolder);
}
catch (Exception e)
{
DebugConsole.ThrowError("Failed to delete Workshop item staging folder.", e);
}
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
@@ -927,28 +934,50 @@ namespace Barotrauma.Steam
{ {
if (instance == null || !instance.isInitialized) { return false; } if (instance == null || !instance.isInitialized) { return false; }
bool itemsUpdated = false; bool? itemsUpdated = null;
foreach (ulong subscribedItemId in instance.client.Workshop.GetSubscribedItemIds()) bool timedOut = false;
var query = instance.client.Workshop.CreateQuery();
query.FileId = new List<ulong>(instance.client.Workshop.GetSubscribedItemIds());
query.UploaderAppId = AppID;
query.Run();
query.OnResult = (Workshop.Query q) =>
{ {
//TODO: fix this, GetItem doesn't query item.Modified if (timedOut) { return; }
var item = instance.client.Workshop.GetItem(subscribedItemId); itemsUpdated = false;
if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item)) foreach (var item in q.Items)
{ {
if (!UpdateWorkshopItem(item, out string errorMsg)) if (item.Installed && CheckWorkshopItemEnabled(item) && !CheckWorkshopItemUpToDate(item))
{ {
DebugConsole.ThrowError(errorMsg); if (!UpdateWorkshopItem(item, out string errorMsg))
new GUIMessageBox( {
TextManager.Get("Error"), DebugConsole.ThrowError(errorMsg);
TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg })); new GUIMessageBox(
} TextManager.Get("Error"),
else TextManager.GetWithVariables("WorkshopItemUpdateFailed", new string[2] { "[itemname]", "[errormessage]" }, new string[2] { item.Title, errorMsg }));
{ }
new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title)); else
itemsUpdated = true; {
new GUIMessageBox("", TextManager.GetWithVariable("WorkshopItemUpdated", "[itemname]", item.Title));
itemsUpdated = true;
}
} }
} }
};
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
while (!itemsUpdated.HasValue)
{
if (DateTime.Now > timeOut)
{
itemsUpdated = false;
timedOut = true;
break;
}
instance.client.Update();
System.Threading.Thread.Sleep(10);
} }
return itemsUpdated;
return itemsUpdated.Value;
} }
public static bool UpdateWorkshopItem(Workshop.Item item, out string errorMsg) public static bool UpdateWorkshopItem(Workshop.Item item, out string errorMsg)
@@ -1081,6 +1081,7 @@ namespace Barotrauma
{ {
InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder), InitialDirectory = Path.GetFullPath(SteamManager.WorkshopItemStagingFolder),
Title = TextManager.Get("workshopitemaddfiles"), Title = TextManager.Get("workshopitemaddfiles"),
Multiselect = true
}; };
if (ofd.ShowDialog() == DialogResult.OK) if (ofd.ShowDialog() == DialogResult.OK)
{ {
@@ -1228,7 +1229,7 @@ namespace Barotrauma
private void OnAddFilesSelected(string[] fileNames) private void OnAddFilesSelected(string[] fileNames)
{ {
if (fileNames == null) { return; } if (fileNames == null) { return; }
for(int i = 0; i < fileNames.Length; i++) for (int i = 0; i < fileNames.Length; i++)
{ {
string file = fileNames[i]; string file = fileNames[i];
if (string.IsNullOrEmpty(file)) { continue; } if (string.IsNullOrEmpty(file)) { continue; }
@@ -1258,6 +1259,7 @@ namespace Barotrauma
itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None); itemContentPackage.AddFile(filePathRelativeToStagingFolder, ContentType.None);
} }
} }
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
} }
@@ -1331,6 +1333,7 @@ namespace Barotrauma
OnClicked = (btn, userdata) => OnClicked = (btn, userdata) =>
{ {
itemContentPackage.RemoveFile(contentFile); itemContentPackage.RemoveFile(contentFile);
itemContentPackage.Save(itemContentPackage.Path);
RefreshCreateItemFileList(); RefreshCreateItemFileList();
return true; return true;
} }
@@ -378,8 +378,6 @@ namespace Barotrauma
Thread.Sleep(250); Thread.Sleep(250);
} }
} }
return true; return true;
} }
@@ -470,7 +468,20 @@ namespace Barotrauma
foreach (DirectoryInfo di in dir.GetDirectories()) foreach (DirectoryInfo di in dir.GetDirectories())
{ {
ClearFolder(di.FullName, ignoredFileNames); ClearFolder(di.FullName, ignoredFileNames);
di.Delete(); int maxRetries = 4;
for (int i = 0; i <= maxRetries; i++)
{
try
{
di.Delete();
break;
}
catch (IOException)
{
if (i >= maxRetries) { throw; }
Thread.Sleep(250);
}
}
} }
} }
} }