Skip to content

Commit

Permalink
Fix options being ignored on already uploaded mods
Browse files Browse the repository at this point in the history
Fix issue with various options, such as visibility, being ignored if the mod was already on the workshop, preventing them from being changed. Add a few more descriptive messages to the help and when an error occurs. Perform reflection even if dry-run, so it can be debugged.
  • Loading branch information
Gwindalmir committed Apr 3, 2019
1 parent 2222333 commit 6f960c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion WorkshopToolCommon/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public static class Constants
#else
public const string SEWT_Prefix = "[_MEWT_]";
#endif
public const string ERROR_Reflection = "WARNING: Could not reflect '{0}', some functions may not work";
public const string ERROR_Reflection = "WARNING: Could not reflect '{0}', some functions may not work. Has the game updated?";
}
}
2 changes: 1 addition & 1 deletion WorkshopToolCommon/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class Options
[Option('f', "force", DefaultValue = false, HelpText = "Force operation. USE WITH CAUTION! (not valid everywhere)")]
public bool Force { get; set; }

[OptionArray('m', "mods", HelpText = "List of directories of mods to upload; or Workshop ID of mods to download (when in download mode)")]
[OptionArray('m', "mods", HelpText = "List of directories of mods to upload; or Workshop ID of mods to download (when in download mode). Use quotes if spaces.")]
public string[] ModPaths { get; set; }

[OptionArray('b', "blueprints", HelpText = "List of directories of blueprints to upload; or Workshop ID of blueprints to download (when in download mode)")]
Expand Down
52 changes: 28 additions & 24 deletions WorkshopToolCommon/Uploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ class Uploader : IMod
public Uploader(WorkshopType type, string path, string[] tags = null, string[] ignoredExtensions = null, bool compile = false, bool dryrun = false, bool development = false, MyPublishedFileVisibility? visibility = null, bool force = false, string previewFilename = null)
{
m_modPath = path;
m_modId = MyWorkshop.GetWorkshopIdFromLocalMod(m_modPath);

// Fill defaults before assigning user-defined ones
FillPropertiesFromPublished();

m_compile = compile;
m_dryrun = dryrun;
m_visibility = visibility;
m_title = Path.GetFileName(path);
m_modId = MyWorkshop.GetWorkshopIdFromLocalMod(m_modPath);
m_type = type;
m_isDev = development;
m_force = force;
Expand Down Expand Up @@ -131,18 +135,15 @@ private void SetupReflection()
}
}

if (!m_dryrun)
{
var publishMethod = typeof(MyWorkshop).GetMethod("PublishItemBlocking", BindingFlags.Static | BindingFlags.NonPublic);
MyDebug.AssertDebug(publishMethod != null);
var publishMethod = typeof(MyWorkshop).GetMethod("PublishItemBlocking", BindingFlags.Static | BindingFlags.NonPublic);
MyDebug.AssertDebug(publishMethod != null);

if (publishMethod != null)
_publishMethod = Delegate.CreateDelegate(typeof(PublishItemBlocking), publishMethod, false) as PublishItemBlocking;
if (publishMethod != null)
_publishMethod = Delegate.CreateDelegate(typeof(PublishItemBlocking), publishMethod, false) as PublishItemBlocking;

if (_publishMethod == null)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "PublishItemBlocking"));
}
if (_publishMethod == null)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "PublishItemBlocking"));
}
}

Expand Down Expand Up @@ -274,8 +275,7 @@ public bool Publish()
}
else
{
if(FillPropertiesFromPublished())
MySandboxGame.Log.WriteLineAndConsole(string.Format("Updating {0}: {1}; {2}", m_type.ToString(), m_modId, m_title));
MySandboxGame.Log.WriteLineAndConsole(string.Format("Updating {0}: {1}; {2}", m_type.ToString(), m_modId, m_title));
}

// Process Tags
Expand Down Expand Up @@ -330,21 +330,26 @@ bool FillPropertiesFromPublished()
#endif
{
if (results.Count > 0)
{
m_title = results[0].Title;

// Check if the mod owner in the sbmi matches steam owner
var owner = results[0].OwnerId;
// Check if the mod owner in the sbmi matches steam owner
var owner = results[0].OwnerId;

if(m_visibility == null)
m_visibility = results[0].Visibility;
if (m_visibility == null)
m_visibility = results[0].Visibility;

MyDebug.AssertDebug(owner == MySteam.UserId);
if (owner != MySteam.UserId)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("Owner mismatch! Mod owner: {0}; Current user: {1}", owner, MySteam.UserId));
MySandboxGame.Log.WriteLineAndConsole("Upload/Publish FAILED!");
return false;

MyDebug.AssertDebug(owner == MySteam.UserId);
if (owner != MySteam.UserId)
{
MySandboxGame.Log.WriteLineAndConsole(string.Format("Owner mismatch! Mod owner: {0}; Current user: {1}", owner, MySteam.UserId));
MySandboxGame.Log.WriteLineAndConsole("Upload/Publish FAILED!");
return false;
}
return true;
}
return false;
}
return true;
}
Expand Down Expand Up @@ -498,7 +503,6 @@ string[] GetTags()
public bool UpdatePreviewFileOrTags()
{
ProcessTags();
FillPropertiesFromPublished();

var publisher = MySteam.CreateWorkshopPublisher();
publisher.Id = ModId;
Expand Down

0 comments on commit 6f960c5

Please sign in to comment.