From 4666757290934206fd685165fc819ad4cde189c6 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 16 Jun 2020 15:45:04 +0200 Subject: [PATCH] Get available mods, allow disabling proxy --- GCMM/GCMM.csproj | 9 ++++ GCMM/MainForm.Designer.cs | 54 ++++++++++---------- GCMM/MainForm.cs | 73 ++++++++++++++++++++++------ GCMM/Properties/Settings.Designer.cs | 12 +++++ GCMM/Properties/Settings.settings | 3 ++ GCMM/SettingsForm.Designer.cs | 13 +++++ GCMM/SettingsForm.cs | 3 ++ 7 files changed, 127 insertions(+), 40 deletions(-) diff --git a/GCMM/GCMM.csproj b/GCMM/GCMM.csproj index c4f3c1f..ec9ebe6 100644 --- a/GCMM/GCMM.csproj +++ b/GCMM/GCMM.csproj @@ -6,6 +6,15 @@ true + + + AnyCPU + + + + AnyCPU + + diff --git a/GCMM/MainForm.Designer.cs b/GCMM/MainForm.Designer.cs index 612bcee..b9e4d73 100644 --- a/GCMM/MainForm.Designer.cs +++ b/GCMM/MainForm.Designer.cs @@ -28,25 +28,25 @@ /// private void InitializeComponent() { - System.Windows.Forms.ListViewGroup listViewGroup13 = 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.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem(new string[] { + System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Installed", System.Windows.Forms.HorizontalAlignment.Center); + System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Available", System.Windows.Forms.HorizontalAlignment.Center); + System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "Mod", + "modtainers", "1.0", - "2020.06.15. 2:01:43", - "1.0"}, -1); + "2020.06.15. 2:01:43"}, -1); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.modlist = new System.Windows.Forms.ListView(); this.modName = ((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.latestVersion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.status = new System.Windows.Forms.Label(); this.installbtn = new System.Windows.Forms.Button(); this.uninstallbtn = new System.Windows.Forms.Button(); this.modinfobox = new System.Windows.Forms.TextBox(); this.playbtn = 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(); // // modlist @@ -58,50 +58,47 @@ this.modlist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.modlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.modName, + this.modAuthor, this.modVersion, - this.modTimestamp, - this.latestVersion}); + this.modTimestamp}); this.modlist.ForeColor = System.Drawing.Color.Green; this.modlist.FullRowSelect = true; - listViewGroup13.Header = "Installed"; - listViewGroup13.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; - listViewGroup13.Name = "installed"; - listViewGroup14.Header = "Available"; - listViewGroup14.Name = "available"; + listViewGroup1.Header = "Installed"; + listViewGroup1.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; + listViewGroup1.Name = "installed"; + listViewGroup2.Header = "Available"; + listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; + listViewGroup2.Name = "available"; this.modlist.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { - listViewGroup13, - listViewGroup14}); + listViewGroup1, + listViewGroup2}); this.modlist.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.modlist.HideSelection = false; - listViewItem7.Group = listViewGroup13; + listViewItem1.Group = listViewGroup1; this.modlist.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem7}); + listViewItem1}); this.modlist.Location = new System.Drawing.Point(12, 12); this.modlist.Name = "modlist"; this.modlist.Size = new System.Drawing.Size(491, 468); this.modlist.TabIndex = 0; this.modlist.UseCompatibleStateImageBehavior = false; this.modlist.View = System.Windows.Forms.View.Details; + this.modlist.SelectedIndexChanged += new System.EventHandler(this.modlist_SelectedIndexChanged); // // modName // this.modName.Text = "Name"; - this.modName.Width = 203; + this.modName.Width = 148; // // modVersion // this.modVersion.Text = "Version"; - this.modVersion.Width = 65; + this.modVersion.Width = 62; // // modTimestamp // this.modTimestamp.Text = "Last updated"; - this.modTimestamp.Width = 129; - // - // latestVersion - // - this.latestVersion.Text = "Latest"; - this.latestVersion.Width = 86; + this.modTimestamp.Width = 120; // // status // @@ -189,6 +186,11 @@ this.settingsbtn.UseVisualStyleBackColor = true; this.settingsbtn.Click += new System.EventHandler(this.settingsbtn_Click); // + // modAuthor + // + this.modAuthor.Text = "Author"; + this.modAuthor.Width = 142; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -218,13 +220,13 @@ private System.Windows.Forms.ColumnHeader modName; private System.Windows.Forms.ColumnHeader modVersion; private System.Windows.Forms.ColumnHeader modTimestamp; - private System.Windows.Forms.ColumnHeader latestVersion; private System.Windows.Forms.Label status; private System.Windows.Forms.Button installbtn; private System.Windows.Forms.Button uninstallbtn; private System.Windows.Forms.TextBox modinfobox; private System.Windows.Forms.Button playbtn; private System.Windows.Forms.Button settingsbtn; + private System.Windows.Forms.ColumnHeader modAuthor; } } diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index ed98267..ffe08c1 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -42,6 +42,7 @@ namespace GCMM } CheckIfPatched(); GetInstalledMods(); + GetAvailableMods(); } public void UpdateButton(Button button, bool enabled) @@ -104,7 +105,9 @@ namespace GCMM { var an = AssemblyName.GetAssemblyName(mod); 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) { //Not a .NET assembly @@ -116,10 +119,10 @@ namespace GCMM { 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; } - string nopatch = "Status: Unpatched\nClick play"; + string nopatch = "Status: Unpatched\nClicking Play patches it"; if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft")) { status.Text = nopatch; @@ -132,8 +135,8 @@ namespace GCMM return false; } if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll") - > //If the file was updated at least a minute after patching - Directory.GetLastWriteTime(backup).AddMinutes(1)) + > //If the file was updated at least 2 minutes after patching + Directory.GetLastWriteTime(backup).AddMinutes(2)) { status.Text = nopatch; 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) == DialogResult.Cancel) return; - string releases = "https://git.exmods.org/api/v1/repos/modtainers/GCIPA/releases"; + string releases = "/api/v1/repos/modtainers/GCIPA/releases"; string url; this.status.Text = "Status: Patching..."; - await Task.Run(() => + using (WebClient client = await GetClient()) { - using (WebClient client = new WebClient()) - { - url = JArray.Parse(client.DownloadString(releases)).First["assets"].First["browser_download_url"].ToString(); - client.DownloadFile(url, "IPA.zip"); - ZipFile.ExtractToDirectory("IPA.zip", Settings.Default.GamePath); - } - }); + url = JArray.Parse(await client.DownloadStringTaskAsync(releases)).First["assets"].First["browser_download_url"].ToString(); + await client.DownloadFileTaskAsync(url, "IPA.zip"); + ZipFile.ExtractToDirectory("IPA.zip", Settings.Default.GamePath); + } } bool? status = CheckIfPatched(); if (!status.HasValue) //Make sure it actually worked @@ -210,6 +210,46 @@ namespace GCMM 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 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) { if (playbtn.ForeColor == Color.Green) return; //Disabled @@ -222,5 +262,10 @@ namespace GCMM var sf = new SettingsForm(); sf.ShowDialog(this); } + + private void modlist_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/GCMM/Properties/Settings.Designer.cs b/GCMM/Properties/Settings.Designer.cs index 2348c7a..a3582b4 100644 --- a/GCMM/Properties/Settings.Designer.cs +++ b/GCMM/Properties/Settings.Designer.cs @@ -46,5 +46,17 @@ namespace GCMM.Properties { 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; + } + } } } diff --git a/GCMM/Properties/Settings.settings b/GCMM/Properties/Settings.settings index a196f44..9f011ed 100644 --- a/GCMM/Properties/Settings.settings +++ b/GCMM/Properties/Settings.settings @@ -8,5 +8,8 @@ + + False + \ No newline at end of file diff --git a/GCMM/SettingsForm.Designer.cs b/GCMM/SettingsForm.Designer.cs index 24a8397..6438564 100644 --- a/GCMM/SettingsForm.Designer.cs +++ b/GCMM/SettingsForm.Designer.cs @@ -34,6 +34,7 @@ this.browsebtn = new System.Windows.Forms.Button(); this.savebtn = new System.Windows.Forms.Button(); this.cancelbtn = new System.Windows.Forms.Button(); + this.useProxy = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // label1 @@ -92,6 +93,16 @@ this.cancelbtn.UseVisualStyleBackColor = true; 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 // this.AcceptButton = this.savebtn; @@ -100,6 +111,7 @@ this.BackColor = System.Drawing.Color.Black; this.CancelButton = this.cancelbtn; this.ClientSize = new System.Drawing.Size(439, 109); + this.Controls.Add(this.useProxy); this.Controls.Add(this.cancelbtn); this.Controls.Add(this.savebtn); this.Controls.Add(this.browsebtn); @@ -128,6 +140,7 @@ private System.Windows.Forms.Button browsebtn; private System.Windows.Forms.Button savebtn; private System.Windows.Forms.Button cancelbtn; + private System.Windows.Forms.CheckBox useProxy; } } diff --git a/GCMM/SettingsForm.cs b/GCMM/SettingsForm.cs index c32d968..4e76ea3 100644 --- a/GCMM/SettingsForm.cs +++ b/GCMM/SettingsForm.cs @@ -24,6 +24,7 @@ namespace GCMM private void Form1_Load(object sender, EventArgs e) { gamelocation.Text = Settings.Default.GamePath; + useProxy.Checked = Settings.Default.UseProxy; mainForm = Owner as MainForm; } @@ -35,6 +36,8 @@ namespace GCMM private void savebtn_Click(object sender, EventArgs e) { Settings.Default.GamePath = gamelocation.Text; + Settings.Default.UseProxy = useProxy.Checked; + Settings.Default.Save(); Close(); }