Get available mods, allow disabling proxy

This commit is contained in:
Norbi Peti 2020-06-16 15:45:04 +02:00
parent eeb4074440
commit 4666757290
7 changed files with 127 additions and 40 deletions

View file

@ -6,6 +6,15 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>

View file

@ -28,25 +28,25 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.ListViewGroup listViewGroup13 = new System.Windows.Forms.ListViewGroup("Installed", System.Windows.Forms.HorizontalAlignment.Center); System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Installed", System.Windows.Forms.HorizontalAlignment.Center);
System.Windows.Forms.ListViewGroup listViewGroup14 = new System.Windows.Forms.ListViewGroup("Available", System.Windows.Forms.HorizontalAlignment.Left); System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Available", System.Windows.Forms.HorizontalAlignment.Center);
System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem(new string[] { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
"Mod", "Mod",
"modtainers",
"1.0", "1.0",
"2020.06.15. 2:01:43", "2020.06.15. 2:01:43"}, -1);
"1.0"}, -1);
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.modlist = new System.Windows.Forms.ListView(); this.modlist = new System.Windows.Forms.ListView();
this.modName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.modName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.modVersion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.modVersion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.modTimestamp = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.modTimestamp = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.latestVersion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.status = new System.Windows.Forms.Label(); this.status = new System.Windows.Forms.Label();
this.installbtn = new System.Windows.Forms.Button(); this.installbtn = new System.Windows.Forms.Button();
this.uninstallbtn = new System.Windows.Forms.Button(); this.uninstallbtn = new System.Windows.Forms.Button();
this.modinfobox = new System.Windows.Forms.TextBox(); this.modinfobox = new System.Windows.Forms.TextBox();
this.playbtn = new System.Windows.Forms.Button(); this.playbtn = new System.Windows.Forms.Button();
this.settingsbtn = new System.Windows.Forms.Button(); this.settingsbtn = new System.Windows.Forms.Button();
this.modAuthor = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout(); this.SuspendLayout();
// //
// modlist // modlist
@ -58,50 +58,47 @@
this.modlist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.modlist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.modlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.modlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.modName, this.modName,
this.modAuthor,
this.modVersion, this.modVersion,
this.modTimestamp, this.modTimestamp});
this.latestVersion});
this.modlist.ForeColor = System.Drawing.Color.Green; this.modlist.ForeColor = System.Drawing.Color.Green;
this.modlist.FullRowSelect = true; this.modlist.FullRowSelect = true;
listViewGroup13.Header = "Installed"; listViewGroup1.Header = "Installed";
listViewGroup13.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; listViewGroup1.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center;
listViewGroup13.Name = "installed"; listViewGroup1.Name = "installed";
listViewGroup14.Header = "Available"; listViewGroup2.Header = "Available";
listViewGroup14.Name = "available"; listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center;
listViewGroup2.Name = "available";
this.modlist.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { this.modlist.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
listViewGroup13, listViewGroup1,
listViewGroup14}); listViewGroup2});
this.modlist.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.modlist.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.modlist.HideSelection = false; this.modlist.HideSelection = false;
listViewItem7.Group = listViewGroup13; listViewItem1.Group = listViewGroup1;
this.modlist.Items.AddRange(new System.Windows.Forms.ListViewItem[] { this.modlist.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem7}); listViewItem1});
this.modlist.Location = new System.Drawing.Point(12, 12); this.modlist.Location = new System.Drawing.Point(12, 12);
this.modlist.Name = "modlist"; this.modlist.Name = "modlist";
this.modlist.Size = new System.Drawing.Size(491, 468); this.modlist.Size = new System.Drawing.Size(491, 468);
this.modlist.TabIndex = 0; this.modlist.TabIndex = 0;
this.modlist.UseCompatibleStateImageBehavior = false; this.modlist.UseCompatibleStateImageBehavior = false;
this.modlist.View = System.Windows.Forms.View.Details; this.modlist.View = System.Windows.Forms.View.Details;
this.modlist.SelectedIndexChanged += new System.EventHandler(this.modlist_SelectedIndexChanged);
// //
// modName // modName
// //
this.modName.Text = "Name"; this.modName.Text = "Name";
this.modName.Width = 203; this.modName.Width = 148;
// //
// modVersion // modVersion
// //
this.modVersion.Text = "Version"; this.modVersion.Text = "Version";
this.modVersion.Width = 65; this.modVersion.Width = 62;
// //
// modTimestamp // modTimestamp
// //
this.modTimestamp.Text = "Last updated"; this.modTimestamp.Text = "Last updated";
this.modTimestamp.Width = 129; this.modTimestamp.Width = 120;
//
// latestVersion
//
this.latestVersion.Text = "Latest";
this.latestVersion.Width = 86;
// //
// status // status
// //
@ -189,6 +186,11 @@
this.settingsbtn.UseVisualStyleBackColor = true; this.settingsbtn.UseVisualStyleBackColor = true;
this.settingsbtn.Click += new System.EventHandler(this.settingsbtn_Click); this.settingsbtn.Click += new System.EventHandler(this.settingsbtn_Click);
// //
// modAuthor
//
this.modAuthor.Text = "Author";
this.modAuthor.Width = 142;
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -218,13 +220,13 @@
private System.Windows.Forms.ColumnHeader modName; private System.Windows.Forms.ColumnHeader modName;
private System.Windows.Forms.ColumnHeader modVersion; private System.Windows.Forms.ColumnHeader modVersion;
private System.Windows.Forms.ColumnHeader modTimestamp; private System.Windows.Forms.ColumnHeader modTimestamp;
private System.Windows.Forms.ColumnHeader latestVersion;
private System.Windows.Forms.Label status; private System.Windows.Forms.Label status;
private System.Windows.Forms.Button installbtn; private System.Windows.Forms.Button installbtn;
private System.Windows.Forms.Button uninstallbtn; private System.Windows.Forms.Button uninstallbtn;
private System.Windows.Forms.TextBox modinfobox; private System.Windows.Forms.TextBox modinfobox;
private System.Windows.Forms.Button playbtn; private System.Windows.Forms.Button playbtn;
private System.Windows.Forms.Button settingsbtn; private System.Windows.Forms.Button settingsbtn;
private System.Windows.Forms.ColumnHeader modAuthor;
} }
} }

View file

@ -42,6 +42,7 @@ namespace GCMM
} }
CheckIfPatched(); CheckIfPatched();
GetInstalledMods(); GetInstalledMods();
GetAvailableMods();
} }
public void UpdateButton(Button button, bool enabled) public void UpdateButton(Button button, bool enabled)
@ -104,7 +105,9 @@ namespace GCMM
{ {
var an = AssemblyName.GetAssemblyName(mod); var an = AssemblyName.GetAssemblyName(mod);
if (an.Name == "0Harmony") continue; if (an.Name == "0Harmony") continue;
modlist.Items.Add(new ListViewItem(new[] { an.Name, an.Version.ToString(), File.GetLastWriteTime(mod).ToString(), "" }, modlist.Groups["installed"])); var item = new ListViewItem(new[] { an.Name, "", an.Version.ToString(), File.GetLastWriteTime(mod).ToString() }, modlist.Groups["installed"]);
item.Name = an.Name;
modlist.Items.Add(item);
} }
catch (BadImageFormatException) catch (BadImageFormatException)
{ //Not a .NET assembly { //Not a .NET assembly
@ -116,10 +119,10 @@ namespace GCMM
{ {
if (!File.Exists(Settings.Default.GamePath + @"\IPA.exe")) if (!File.Exists(Settings.Default.GamePath + @"\IPA.exe"))
{ {
status.Text = "Status: Patcher missing\nInstalling a mod downloads it"; status.Text = "Status: Patcher missing\nClicking Play will install it";
return null; return null;
} }
string nopatch = "Status: Unpatched\nClick play"; string nopatch = "Status: Unpatched\nClicking Play patches it";
if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft")) if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft"))
{ {
status.Text = nopatch; status.Text = nopatch;
@ -132,8 +135,8 @@ namespace GCMM
return false; return false;
} }
if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll") if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll")
> //If the file was updated at least a minute after patching > //If the file was updated at least 2 minutes after patching
Directory.GetLastWriteTime(backup).AddMinutes(1)) Directory.GetLastWriteTime(backup).AddMinutes(2))
{ {
status.Text = nopatch; status.Text = nopatch;
return false; return false;
@ -153,18 +156,15 @@ namespace GCMM
if (MessageBox.Show("The patcher (GCIPA) is not found. It will be downloaded from https://git.exmods.org/modtainers/GCIPA/releases and ran to patch the game.", "Patcher download needed", MessageBoxButtons.OKCancel) if (MessageBox.Show("The patcher (GCIPA) is not found. It will be downloaded from https://git.exmods.org/modtainers/GCIPA/releases and ran to patch the game.", "Patcher download needed", MessageBoxButtons.OKCancel)
== DialogResult.Cancel) == DialogResult.Cancel)
return; return;
string releases = "https://git.exmods.org/api/v1/repos/modtainers/GCIPA/releases"; string releases = "/api/v1/repos/modtainers/GCIPA/releases";
string url; string url;
this.status.Text = "Status: Patching..."; this.status.Text = "Status: Patching...";
await Task.Run(() => using (WebClient client = await GetClient())
{ {
using (WebClient client = new WebClient()) url = JArray.Parse(await client.DownloadStringTaskAsync(releases)).First["assets"].First["browser_download_url"].ToString();
{ await client.DownloadFileTaskAsync(url, "IPA.zip");
url = JArray.Parse(client.DownloadString(releases)).First["assets"].First["browser_download_url"].ToString(); ZipFile.ExtractToDirectory("IPA.zip", Settings.Default.GamePath);
client.DownloadFile(url, "IPA.zip"); }
ZipFile.ExtractToDirectory("IPA.zip", Settings.Default.GamePath);
}
});
} }
bool? status = CheckIfPatched(); bool? status = CheckIfPatched();
if (!status.HasValue) //Make sure it actually worked if (!status.HasValue) //Make sure it actually worked
@ -210,6 +210,46 @@ namespace GCMM
Invoke(act); Invoke(act);
} }
public async void GetAvailableMods()
{
string reposURL = "/api/v1/repos/search?sort=updated&order=desc";
using (var client = await GetClient())
{
var obj = JObject.Parse(await client.DownloadStringTaskAsync(reposURL));
if (!(bool)obj["ok"]) return;
foreach (var repo in obj["data"])
{
string name = repo["name"].ToString();
if (modlist.Items.ContainsKey(name))
{
var item = modlist.Items[name];
var si = item.SubItems;
si[1] = new ListViewItem.ListViewSubItem(item, repo["owner"]["username"].ToString());
}
else
{
var item = new ListViewItem(new[] { name, repo["owner"]["username"].ToString(), "", ((DateTime)repo["updated_at"]).ToString() }, modlist.Groups["available"]);
item.Name = name;
modlist.Items.Add(item);
}
}
}
}
public async Task<WebClient> GetClient()
{
var client = new WebClient();
if (!Settings.Default.UseProxy)
client.Proxy = null;
client.Headers.Clear();
client.Headers[HttpRequestHeader.Accept] = "application/json";
/*client.Headers[HttpRequestHeader.Host] = "git.exmods.org";
var addr = (await Dns.GetHostAddressesAsync("git.exmods.org")).Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First();
client.BaseAddress = "https://" + addr;*/
client.BaseAddress = "https://git.exmods.org";
return client;
}
private void playbtn_Click(object sender, EventArgs e) private void playbtn_Click(object sender, EventArgs e)
{ {
if (playbtn.ForeColor == Color.Green) return; //Disabled if (playbtn.ForeColor == Color.Green) return; //Disabled
@ -222,5 +262,10 @@ namespace GCMM
var sf = new SettingsForm(); var sf = new SettingsForm();
sf.ShowDialog(this); sf.ShowDialog(this);
} }
private void modlist_SelectedIndexChanged(object sender, EventArgs e)
{
}
} }
} }

View file

@ -46,5 +46,17 @@ namespace GCMM.Properties {
this["WinePath"] = value; this["WinePath"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool UseProxy {
get {
return ((bool)(this["UseProxy"]));
}
set {
this["UseProxy"] = value;
}
}
} }
} }

View file

@ -8,5 +8,8 @@
<Setting Name="WinePath" Type="System.String" Scope="User"> <Setting Name="WinePath" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="UseProxy" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View file

@ -34,6 +34,7 @@
this.browsebtn = new System.Windows.Forms.Button(); this.browsebtn = new System.Windows.Forms.Button();
this.savebtn = new System.Windows.Forms.Button(); this.savebtn = new System.Windows.Forms.Button();
this.cancelbtn = new System.Windows.Forms.Button(); this.cancelbtn = new System.Windows.Forms.Button();
this.useProxy = new System.Windows.Forms.CheckBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
@ -92,6 +93,16 @@
this.cancelbtn.UseVisualStyleBackColor = true; this.cancelbtn.UseVisualStyleBackColor = true;
this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click); this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click);
// //
// useProxy
//
this.useProxy.AutoSize = true;
this.useProxy.Location = new System.Drawing.Point(12, 49);
this.useProxy.Name = "useProxy";
this.useProxy.Size = new System.Drawing.Size(147, 17);
this.useProxy.TabIndex = 5;
this.useProxy.Text = "Use system proxy settings";
this.useProxy.UseVisualStyleBackColor = true;
//
// SettingsForm // SettingsForm
// //
this.AcceptButton = this.savebtn; this.AcceptButton = this.savebtn;
@ -100,6 +111,7 @@
this.BackColor = System.Drawing.Color.Black; this.BackColor = System.Drawing.Color.Black;
this.CancelButton = this.cancelbtn; this.CancelButton = this.cancelbtn;
this.ClientSize = new System.Drawing.Size(439, 109); this.ClientSize = new System.Drawing.Size(439, 109);
this.Controls.Add(this.useProxy);
this.Controls.Add(this.cancelbtn); this.Controls.Add(this.cancelbtn);
this.Controls.Add(this.savebtn); this.Controls.Add(this.savebtn);
this.Controls.Add(this.browsebtn); this.Controls.Add(this.browsebtn);
@ -128,6 +140,7 @@
private System.Windows.Forms.Button browsebtn; private System.Windows.Forms.Button browsebtn;
private System.Windows.Forms.Button savebtn; private System.Windows.Forms.Button savebtn;
private System.Windows.Forms.Button cancelbtn; private System.Windows.Forms.Button cancelbtn;
private System.Windows.Forms.CheckBox useProxy;
} }
} }

View file

@ -24,6 +24,7 @@ namespace GCMM
private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
{ {
gamelocation.Text = Settings.Default.GamePath; gamelocation.Text = Settings.Default.GamePath;
useProxy.Checked = Settings.Default.UseProxy;
mainForm = Owner as MainForm; mainForm = Owner as MainForm;
} }
@ -35,6 +36,8 @@ namespace GCMM
private void savebtn_Click(object sender, EventArgs e) private void savebtn_Click(object sender, EventArgs e)
{ {
Settings.Default.GamePath = gamelocation.Text; Settings.Default.GamePath = gamelocation.Text;
Settings.Default.UseProxy = useProxy.Checked;
Settings.Default.Save();
Close(); Close();
} }