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.

98 lines
3.2KB

  1. using GCMM.Properties;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace GCMM
  14. {
  15. partial class MainForm
  16. {
  17. public void UpdateButton(Button button, bool enabled)
  18. {
  19. if (enabled)
  20. {
  21. button.ForeColor = Color.Lime;
  22. button.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 40, 0);
  23. button.FlatAppearance.MouseDownBackColor = Color.Green;
  24. }
  25. else
  26. {
  27. button.ForeColor = Color.Green;
  28. button.FlatAppearance.MouseOverBackColor = Color.Black;
  29. button.FlatAppearance.MouseDownBackColor = Color.Black;
  30. }
  31. }
  32. public string GetGameFolder()
  33. {
  34. string libs;
  35. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  36. libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf";
  37. else
  38. return null;
  39. foreach (var line in File.ReadAllLines(libs).Concat(new[] { @"C:\Program Files (x86)\Steam\" }))
  40. {
  41. var regex = new Regex("\\t\"\\d+\"\\t\\t\"(.+)\"");
  42. var match = regex.Match(line);
  43. if (!match.Success)
  44. continue;
  45. string library = match.Groups[1].Value.Replace("\\\\", "\\");
  46. library += @"\steamapps\common\";
  47. if (File.Exists(library + @"Gamecraft\Gamecraft.exe"))
  48. return library + "Gamecraft";
  49. if (File.Exists(library + @"RobocraftX\Gamecraft.exe"))
  50. return library + "RobocraftX";
  51. }
  52. return libs;
  53. }
  54. public string SelectGameFolder()
  55. {
  56. var ofd = new OpenFileDialog();
  57. ofd.Filter = "Gamecraft executable|Gamecraft.exe";
  58. ofd.Title = "Game location";
  59. ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\";
  60. ofd.CheckFileExists = true;
  61. ofd.ShowDialog();
  62. if (string.IsNullOrWhiteSpace(ofd.FileName))
  63. return null;
  64. return Directory.GetParent(ofd.FileName).FullName;
  65. }
  66. private void CheckStartGame(object sender, EventArgs e)
  67. {
  68. Action act = () =>
  69. {
  70. if ((sender as Process).ExitCode != 0)
  71. {
  72. status.Text = "Status: Patching failed";
  73. return;
  74. }
  75. if (CheckIfPatched() ?? false)
  76. Process.Start("steam://run/1078000/");
  77. };
  78. if (InvokeRequired)
  79. Invoke(act);
  80. }
  81. public WebClient GetClient()
  82. {
  83. var client = new WebClient();
  84. if (!Settings.Default.UseProxy)
  85. client.Proxy = null;
  86. client.Headers.Clear();
  87. client.Headers[HttpRequestHeader.Accept] = "application/json";
  88. client.BaseAddress = "https://git.exmods.org";
  89. return client;
  90. }
  91. }
  92. }