Skip to content

Commit 5d671c3

Browse files
author
th3c120w
committed
Add default settings and server presentation flag
1 parent 5d4941c commit 5d671c3

File tree

3 files changed

+60
-45
lines changed

3 files changed

+60
-45
lines changed

RustBindFixer/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Text.RegularExpressions;
67
using System.Threading;
78

@@ -11,13 +12,13 @@ internal class Program
1112
{
1213
private static void Main ( string[] args )
1314
{
14-
var servers = Settings.Instance.Servers;
15+
var servers = Settings.Instance.Servers.Where ( x => x.PresentInServerList ).ToList ( );
1516

16-
for ( var i = 0; i < servers.Count; ++i )
17-
Console.WriteLine ( $"[{(i + 1)}] - {servers[i]}" );
17+
for ( var i = 0; i < servers.Count; ++i ) Console.WriteLine ( $"[{i + 1}] - {servers[i]}" );
1818

19-
Console.Write ( $"\nConnect to server [1 - { servers.Count }]: " );
19+
Console.Write ( $"\nConnect to server [1 - {servers.Count}]: " );
2020
var selectedServer = Convert.ToInt32 ( Console.ReadLine ( ) );
21+
2122
if ( selectedServer >= 0 && selectedServer <= servers.Count )
2223
servers[selectedServer - 1].Connect ( );
2324

RustBindFixer/Server.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Server
99
public string Ip { get; set; }
1010
public string Name { get; set; }
1111

12+
public bool PresentInServerList { get; set; } = true;
13+
1214
public void Connect ( )
1315
{
1416
if ( string.IsNullOrEmpty ( Ip ) )

RustBindFixer/Settings.cs

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,57 @@
44

55
namespace RustBindFixer
66
{
7-
public class Settings
8-
{
9-
private static readonly object LoadLock;
10-
11-
public static Settings Instance { get; private set; }
12-
13-
private const string SETTINGSFILE = "Settings.json";
14-
15-
#region Properties
16-
17-
public string KeysConfigPath { get; set; }
18-
19-
public string LaunchParameters { get; set; }
20-
21-
public List<Server> Servers { get; set; }
22-
23-
#endregion Properties
24-
25-
static Settings ( )
26-
{
27-
LoadLock = new object ( );
28-
Instance = new Settings ( );
29-
Load ( );
30-
Save ( );
31-
}
32-
33-
public static void Save ( )
34-
{
35-
lock ( LoadLock )
36-
File.WriteAllText ( SETTINGSFILE, JsonConvert.SerializeObject ( Instance, Newtonsoft.Json.Formatting.Indented ) );
37-
}
38-
39-
public static void Load ( )
40-
{
41-
lock ( LoadLock )
42-
{
43-
if ( File.Exists ( SETTINGSFILE ) )
44-
Instance = JsonConvert.DeserializeObject<Settings> ( File.ReadAllText ( SETTINGSFILE ) );
45-
}
46-
}
47-
}
7+
public class Settings
8+
{
9+
private const string SETTINGSFILE = "Settings.json";
10+
private static readonly object LoadLock;
11+
12+
public static Settings Instance { get; private set; }
13+
14+
static Settings ( )
15+
{
16+
LoadLock = new object ( );
17+
Instance = new Settings ( );
18+
Load ( );
19+
Save ( );
20+
}
21+
22+
public static void Save ( )
23+
{
24+
lock ( LoadLock )
25+
File.WriteAllText ( SETTINGSFILE, JsonConvert.SerializeObject ( Instance, Formatting.Indented ) );
26+
}
27+
28+
public static void Load ( )
29+
{
30+
lock ( LoadLock )
31+
{
32+
if ( File.Exists ( SETTINGSFILE ) )
33+
{
34+
var settings = new JsonSerializerSettings {ObjectCreationHandling = ObjectCreationHandling.Replace};
35+
Instance = JsonConvert.DeserializeObject<Settings> ( File.ReadAllText ( SETTINGSFILE ), settings );
36+
}
37+
}
38+
}
39+
40+
#region Properties
41+
42+
public string KeysConfigPath { get; set; } =
43+
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Rust\\cfg\\keys.cfg";
44+
45+
public string LaunchParameters { get; set; } = "-high -malloc=system -nolog";
46+
47+
public List<Server> Servers { get; set; } = new List<Server>
48+
{
49+
new Server
50+
{
51+
Name = "Example name",
52+
Ip = "xxx.xxx.xxx.xxx:00000",
53+
Description = "Example description",
54+
PresentInServerList = false
55+
}
56+
};
57+
58+
#endregion Properties
59+
}
4860
}

0 commit comments

Comments
 (0)