Skip to content

Commit

Permalink
added check for cgi config file
Browse files Browse the repository at this point in the history
version bump to 1.0.1.0
  • Loading branch information
13ace37 committed Jun 9, 2023
1 parent f53e487 commit 8264502
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
25 changes: 25 additions & 0 deletions SurfTimerRPC_Form.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions SurfTimerRPC_Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8264502

Please sign in to comment.