Skip to content

Commit

Permalink
earlier check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rynchodon committed Jan 22, 2017
1 parent 6d6b447 commit bbde263
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Injector/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.2.0")]
[assembly: AssemblyVersion("0.5.2.1")]
38 changes: 28 additions & 10 deletions Loader/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,12 @@ public bool PublishRelease(CreateRelease create, params string[] assetsPaths)
if (!File.Exists(path))
throw new ArgumentException("File does not exist: " + path);

// check for extant release
Release[] releases = GetReleases();
if (releases == null)
string fail;
if (!CanCreateRelease(create.version, out fail))
{
Logger.WriteLine("Failed to download releases");
Logger.WriteLine(fail);
return false;
}
foreach (Release rel in releases)
if (rel.version.CompareTo(create.version) == 0)
{
Logger.WriteLine("Release exists: " + create.version);
return false;
}

// release needs to be draft while it is being created, in case of failure
bool draft = create.draft;
Expand Down Expand Up @@ -128,6 +121,31 @@ public bool PublishRelease(CreateRelease create, params string[] assetsPaths)
return true;
}

/// <summary>
/// Checks if a release with a specified version can be created.
/// </summary>
/// <param name="version">A version that might be in use.</param>
/// <param name="reason">In the event of failure, the reason for the failure.</param>
public bool CanCreateRelease(Version version, out string reason)
{
Release[] releases = GetReleases();
if (releases == null)
{
reason = "Failed to download releases";
return false;
}

foreach (Release release in releases)
if (release.version.CompareTo(version) == 0)
{
reason = "Release exists: " + version;
return false;
}

reason = null;
return true;
}

/// <summary>
/// Edit information about a release.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions Loader/ReleaseCreater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public static void Publish(ModVersion modVersion, string directory, string oAuth
using (XmlDictionaryWriter writer = JsonReaderWriterFactory.CreateJsonWriter(new FileStream(releaseFile, FileMode.CreateNew), Encoding.UTF8, true, true))
serializer.WriteObject(writer, input);

string fail;
if (!client.CanCreateRelease(modVersion.version, out fail))
{
Console.WriteLine(fail);
return;
}

while (true)
{
Process edit = Process.Start(releaseFile);
Expand Down

0 comments on commit bbde263

Please sign in to comment.