Skip to content

Commit

Permalink
Changed compiler updates, polished UI
Browse files Browse the repository at this point in the history
  • Loading branch information
djoslin0 committed Feb 10, 2022
1 parent c61a643 commit 3e7abb4
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 125 deletions.
8 changes: 3 additions & 5 deletions coop-compiler/BuildUtil.cs
Expand Up @@ -258,13 +258,11 @@ public async Task<bool> BuildAsync()
if (!cmdlineUtil.isUpdatedCompiler)
{
SetStage("checking compiler version");
string verUrl = RepoUtil.versionUrl;
string verPath = downloadsDir + @"\version.txt";
await DownloadAsync(verUrl, verPath);
if (!MiscUtil.VersionCheck(verPath))
string remoteVersion = await RestUtil.GetSloppyAsync(RepoUtil.releaseApiUrl, "tag_name");
if (remoteVersion != null && !MiscUtil.VersionCheck(remoteVersion))
{
SetStage("downloading new compiler version");
string compilerUrl = RepoUtil.compilerUrl;
string compilerUrl = RepoUtil.releaseExeUrl;
string compilerPath = coopCompilerNewPath;
await DownloadAndExecuteNewCompiler(cmdlineUtil.currentExePath, compilerUrl, compilerPath);
logUtil.EndThread();
Expand Down
267 changes: 154 additions & 113 deletions coop-compiler/Form1.Designer.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion coop-compiler/Form1.cs
Expand Up @@ -39,7 +39,7 @@ private void ShowPanel(Panel panel)
}
}

private void Form1_Load(object sender, EventArgs e)
private async void Form1_Load(object sender, EventArgs e)
{
ShowPanel(null);
logUtil = new LogUtil(this, this.rtbOutput, this.customProgressBar1);
Expand Down
3 changes: 1 addition & 2 deletions coop-compiler/MiscUtil.cs
Expand Up @@ -38,9 +38,8 @@ public static bool ValidRom(string path)
return (sha.ToLower() == shaUsRom.ToLower());
}

public static bool VersionCheck(string path)
public static bool VersionCheck(string remoteVersion)
{
string remoteVersion = File.ReadAllText(path).Trim();
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return remoteVersion == version;
}
Expand Down
5 changes: 2 additions & 3 deletions coop-compiler/RepoUtil.cs
Expand Up @@ -43,8 +43,7 @@ public string ExtractedFolder()
public static string intelHdFix32 = "https://github.com/coop-compiler/coop-compiler/raw/32-bit/intel-hd/opengl32.dll";
public static string intelHdFix64 = "https://github.com/coop-compiler/coop-compiler/raw/64-bit/intel-hd/opengl32.dll";

public static string compilerUrl = "https://github.com/coop-compiler/coop-compiler/raw/master/exe/coop-compiler.exe";
public static string versionUrl = "https://github.com/coop-compiler/coop-compiler/raw/master/exe/version.txt";

public static string releaseApiUrl = "https://api.github.com/repos/coop-compiler/coop-compiler/releases/latest";
public static string releaseExeUrl = "https://github.com/coop-compiler/coop-compiler/releases/latest/download/coop-compiler.exe";
}
}
55 changes: 55 additions & 0 deletions coop-compiler/RestUtil.cs
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace coop_builder
{
public static class RestUtil
{
public static async Task<string> GetAsync(string url)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; AcmeInc/1.0)");

// HTTP GET
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
return result;
}
}

return null;
}

public static string SloppyExtract(string json, string field)
{
json = json.Replace(" ", "");

string fieldJson = "\"" + field + "\":";
if (!json.Contains(fieldJson)) { return null; }

string after = json.Split(new string[] { fieldJson }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
string[] valueSplit = after.Split('"');
if (valueSplit.Count() < 2) { return null; }

return valueSplit[1];
}

public static async Task<string> GetSloppyAsync(string url, string parameter)
{
string jsonString = await GetAsync(url);
if (jsonString == null) { return null; }

return SloppyExtract(jsonString, parameter);
}
}
}
1 change: 1 addition & 0 deletions coop-compiler/coop-compiler.csproj
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<Reference Include="System.Management" />
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file removed exe/coop-compiler.exe
Binary file not shown.
1 change: 0 additions & 1 deletion exe/version.txt

This file was deleted.

0 comments on commit 3e7abb4

Please sign in to comment.