Skip to content

Commit

Permalink
release notes, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Rynchodon committed Oct 29, 2016
1 parent 9cd7433 commit a99b1db
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Injector/ArmsUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void UpdateArms()

if (bestRelease == null)
{
WriteLine("No releases found");
WriteLine("ERROR: No releases found");
return;
}

Expand All @@ -47,7 +47,7 @@ public static void UpdateArms()

if (asset == null)
{
WriteLine("Could not get asset");
WriteLine("ERROR: Could not get asset");
return;
}

Expand Down
66 changes: 47 additions & 19 deletions Injector/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;

namespace Rynchodon
{
Expand All @@ -15,39 +16,66 @@ public static void CreateRelease(string userAgent, string oAuthToken, Release re
request.Method = "POST";
request.Headers.Add("Authorization", "token " + oAuthToken);

release.WriteCreateJson(request.GetRequestStream());
using (Stream requestStream = request.GetRequestStream())
release.WriteCreateJson(requestStream);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Release));
release = (Release)serializer.ReadObject(request.GetResponse().GetResponseStream());
using (WebResponse response = request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
release = (Release)serializer.ReadObject(responseStream);

Console.WriteLine("Release id: " + release.id);

foreach (string asset in assetsPaths)
{
string fileName = Path.GetFileName(asset);
Console.WriteLine("Posting asset: " + fileName);
request = WebRequest.CreateHttp(@"https://uploads.github.com/repos/Rynchodon/ARMS/releases/" + release.id + "/assets?name=" + fileName);
request.UserAgent = userAgent;
request.Method = "POST";
request.ContentType = "application/dll";
request.Headers.Add("Authorization", "token " + oAuthToken);

FileStream fileStream = new FileStream(asset, FileMode.Open);
fileStream.CopyTo(request.GetRequestStream());
request.GetResponse();

Console.WriteLine("Posted: " + fileName);
Console.Write("Posting asset " + fileName + ": ");

using (WebClient client = new WebClient())
{
client.Headers.Add(HttpRequestHeader.UserAgent, userAgent);
client.Headers.Add(HttpRequestHeader.ContentType, "application/dll");
client.Headers.Add(HttpRequestHeader.Authorization, "token " + oAuthToken);

int cursorLeft = Console.CursorLeft, cursorTop = Console.CursorTop;
long lastPercent = -1L;
object locker = new object();
UploadProgressChangedEventHandler handler = (sender, e) => {
long percent = e.BytesSent * 100L / e.TotalBytesToSend;
lock (locker)
{
if (percent == lastPercent)
return;
lastPercent = percent;
Console.SetCursorPosition(cursorLeft, cursorTop);
if (percent < 10)
Console.Write(' ');
if (percent < 100)
Console.Write(' ');
Console.Write(percent);
Console.Write('%');
}
};

client.UploadProgressChanged += handler;
Task uploadTask = client.UploadFileTaskAsync(@"https://uploads.github.com/repos/Rynchodon/ARMS/releases/" + release.id + "/assets?name=" + fileName, asset);
uploadTask.Wait();
uploadTask.Dispose();
}

Console.WriteLine();
}
}

public static Release[] GetReleases(string userAgent)
{
HttpWebRequest request = WebRequest.CreateHttp(@"https://api.github.com/repos/Rynchodon/ARMS/releases");
request.UserAgent = userAgent;
WebResponse response;
response = request.GetResponse();

DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Release[]));
return (Release[])serializer.ReadObject(response.GetResponseStream());
using (WebResponse response = request.GetResponse())
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Release[]));
using (Stream responseStream = response.GetResponseStream())
return (Release[])serializer.ReadObject(responseStream);
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions Injector/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Asset
private class Create
{
[DataMember]
public string tag_name;
public string tag_name, body;
[DataMember]
public bool draft, prerelease;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ public int CompareTo(Release other)

public void WriteCreateJson(Stream writeTo)
{
Create c = new Create() { tag_name = tag_name, draft = draft, prerelease = prerelease };
Create c = new Create() { tag_name = tag_name, body = body, draft = draft, prerelease = prerelease };
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Create));
serializer.WriteObject(writeTo, c);
}
Expand Down

0 comments on commit a99b1db

Please sign in to comment.