diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 45ad158..1b8b748 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] diff --git a/SurfTimerRPC_Form.Designer.cs b/SurfTimerRPC_Form.Designer.cs index 721b248..88876ca 100644 --- a/SurfTimerRPC_Form.Designer.cs +++ b/SurfTimerRPC_Form.Designer.cs @@ -37,6 +37,8 @@ private void InitializeComponent() this.lbx_modules1 = new System.Windows.Forms.ListBox(); this.lbx_modules2 = new System.Windows.Forms.ListBox(); this.lbx_modules3 = new System.Windows.Forms.ListBox(); + this.lb_cgiConfig = new System.Windows.Forms.Label(); + this.pn_cgiConfigStatus = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // pn_rpcStatus @@ -125,12 +127,33 @@ private void InitializeComponent() this.lbx_modules3.TabIndex = 8; this.lbx_modules3.SelectedIndexChanged += new System.EventHandler(this.lbx_modulesChangeIndex); // + // lb_cgiConfig + // + this.lb_cgiConfig.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lb_cgiConfig.AutoSize = true; + this.lb_cgiConfig.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(229)))), ((int)(((byte)(233)))), ((int)(((byte)(240))))); + this.lb_cgiConfig.Location = new System.Drawing.Point(237, 11); + this.lb_cgiConfig.Name = "lb_cgiConfig"; + this.lb_cgiConfig.Size = new System.Drawing.Size(58, 13); + this.lb_cgiConfig.TabIndex = 10; + this.lb_cgiConfig.Text = "CGI Config"; + // + // pn_cgiConfigStatus + // + this.pn_cgiConfigStatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(46)))), ((int)(((byte)(52)))), ((int)(((byte)(64))))); + this.pn_cgiConfigStatus.Location = new System.Drawing.Point(221, 12); + this.pn_cgiConfigStatus.Name = "pn_cgiConfigStatus"; + this.pn_cgiConfigStatus.Size = new System.Drawing.Size(10, 10); + this.pn_cgiConfigStatus.TabIndex = 9; + // // SurfTimerRPC_Form // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(46)))), ((int)(((byte)(52)))), ((int)(((byte)(64))))); this.ClientSize = new System.Drawing.Size(404, 230); + this.Controls.Add(this.lb_cgiConfig); + this.Controls.Add(this.pn_cgiConfigStatus); this.Controls.Add(this.lbx_modules3); this.Controls.Add(this.lbx_modules2); this.Controls.Add(this.lbx_modules1); @@ -163,6 +186,8 @@ private void InitializeComponent() private System.Windows.Forms.ListBox lbx_modules1; private System.Windows.Forms.ListBox lbx_modules2; private System.Windows.Forms.ListBox lbx_modules3; + private System.Windows.Forms.Label lb_cgiConfig; + private System.Windows.Forms.Panel pn_cgiConfigStatus; } } diff --git a/SurfTimerRPC_Form.cs b/SurfTimerRPC_Form.cs index 041de83..01fc52f 100644 --- a/SurfTimerRPC_Form.cs +++ b/SurfTimerRPC_Form.cs @@ -3,7 +3,11 @@ using surftimer_rpc_gui.Properties; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; +using System.IO; +using System.Linq; +using System.Threading.Tasks; using System.Timers; using System.Windows.Forms; @@ -23,6 +27,10 @@ public partial class SurfTimerRPC_Form : Form private int[,] lbx_moduleSelectedIndexes; + private string cgiConfigPath; + + private bool csgoNotOpenedWarningShowed = false; + public SurfTimerRPC_Form() { InitializeComponent(); @@ -165,6 +173,8 @@ private RichPresence formatRichPresence(string details, string? state, string? l private SurfTimerRPC_Form initializeRPC() { + if (surfTimerRPC_Client == null) return this; + surfTimerRPC_Client.Client.SetPresence(formatRichPresence($"SurfTimer RPC v{GetAssemblyVersion()}", "just started", "logo", null, null, null)); return this; @@ -281,11 +291,68 @@ private SurfTimerRPC_Form updateCGIStatus(bool status) return this; } + private SurfTimerRPC_Form updateCGIConfig() + { +#nullable enable + Process? process = Process.GetProcessesByName("csgo").FirstOrDefault(); + if (process == null) + { + if (!csgoNotOpenedWarningShowed) MessageBox.Show("Please start csgo!"); + csgoNotOpenedWarningShowed = true; + System.Timers.Timer t = new System.Timers.Timer(10000); + t.Elapsed += (Object source, ElapsedEventArgs e) => + { + this.updateCGIConfig(); + }; + t.Start(); + return this; + } +#nullable disable + string path = process.MainModule.FileName; + + this.checkCGIConfig(path); + + + return this; + } + + private SurfTimerRPC_Form checkCGIConfig(string path) + { + + cgiConfigPath = Path.Combine(Path.GetDirectoryName(path), "csgo", "cfg", "gamestate_integration_surf.cfg"); + bool configExists = File.Exists(cgiConfigPath); + updateCGIConfigStatus(configExists); + + if (!configExists) createCGIConfig(); + + return this; + } + + private SurfTimerRPC_Form createCGIConfig() + { + if (cgiConfigPath == null) return this; + + string config = "\"surf\"\n{\n \"uri\" \"http://localhost:23251/\"\n \"timeout\" \"5.0\"\n \"buffer\" \"0.1\"\n \"throttle\" \"0.1\"\n \"heartbeat\" \"0.5\"\n \"data\"\n {\n \"provider\" \"1\"\n \"map\" \"1\"\n \"round\" \"1\"\n \"player_id\" \"1\"\n \"player_state\" \"1\"\n \"player_weapons\" \"1\"\n \"player_match_stats\" \"1\"\n }\n}\n"; + File.WriteAllText(cgiConfigPath, config); + + updateCGIConfig(); + + return this; + } + + private SurfTimerRPC_Form updateCGIConfigStatus(bool status) + { + pn_cgiConfigStatus.BackColor = status ? Color.FromArgb(255, 163, 190, 140) : Color.FromArgb(255, 191, 97, 106); + return this; + } + private SurfTimerRPC_Form initializeFormElements() { this.updateRPCStatus(false) .updateCGIStatus(false) + .updateCGIConfigStatus(false) .updateCGITime() + .updateCGIConfig() ; return this; }