Techblox Mod Manager / Launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.9KB

  1. using GCMM.Properties;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Reflection;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace GCMM
  16. {
  17. public partial class MainForm : Form
  18. {
  19. public MainForm()
  20. {
  21. InitializeComponent();
  22. }
  23. private Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
  24. private void Form1_Load(object sender, EventArgs e)
  25. {
  26. modlist.Items.Clear();
  27. UpdateButton(installbtn, false);
  28. modinfobox.Text = "";
  29. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  30. {
  31. Settings.Default.GamePath = GetGameFolder();
  32. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  33. Settings.Default.GamePath = SelectGameFolder();
  34. else
  35. MessageBox.Show("Found game at " + Settings.Default.GamePath);
  36. Settings.Default.Save();
  37. }
  38. if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  39. {
  40. status.Text = "Status: Game not found";
  41. return;
  42. }
  43. CheckIfPatched();
  44. GetInstalledMods();
  45. GetAvailableMods();
  46. }
  47. private void playbtn_Click(object sender, EventArgs e)
  48. {
  49. if (playbtn.ForeColor == Color.Green) return; //Disabled
  50. if (!BeginWork()) return;
  51. PatchGame();
  52. EndWork();
  53. }
  54. private void settingsbtn_Click(object sender, EventArgs e)
  55. {
  56. if (settingsbtn.ForeColor == Color.Green) return; //Disabled
  57. var sf = new SettingsForm();
  58. sf.ShowDialog(this);
  59. }
  60. private void modlist_SelectedIndexChanged(object sender, EventArgs e)
  61. {
  62. if (working) return;
  63. switch (modlist.SelectedItems.Count)
  64. {
  65. case 0:
  66. modinfobox.Text = "";
  67. UpdateButton(installbtn, false);
  68. UpdateButton(uninstallbtn, false);
  69. break;
  70. case 1:
  71. default:
  72. installbtn.Text = "Install mod";
  73. UpdateButton(installbtn, false);
  74. UpdateButton(uninstallbtn, false);
  75. foreach (ListViewItem item in modlist.SelectedItems)
  76. {
  77. var mod = mods[item.Name];
  78. if (modlist.SelectedItems.Count == 1)
  79. modinfobox.Text = mod.Description?.Replace("\n", Environment.NewLine);
  80. else
  81. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  82. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  83. {
  84. UpdateButton(installbtn, true);
  85. if (mod.Version != null)
  86. installbtn.Text = "Update mod";
  87. else
  88. installbtn.Text = "Install mod";
  89. }
  90. if (mod.Version != null)
  91. UpdateButton(uninstallbtn, true);
  92. }
  93. break;
  94. }
  95. }
  96. private async void installbtn_Click(object sender, EventArgs e)
  97. {
  98. if (installbtn.ForeColor == Color.Green) return; //Disabled
  99. if (!BeginWork()) return;
  100. foreach (ListViewItem item in modlist.SelectedItems)
  101. {
  102. if (item.Group.Name == "installed") continue;
  103. await InstallMod(mods[item.Name]);
  104. }
  105. EndWork();
  106. }
  107. }
  108. }