2016-03-20 05:27:30 +01:00
|
|
|
|
/*
|
|
|
|
|
|
_ _ _ ____ _ _____
|
|
|
|
|
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
|
|
|
|
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
|
|
|
|
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
|
|
|
|
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
|
|
|
|
|
|
2017-01-02 20:05:21 +01:00
|
|
|
|
Copyright 2015-2017 Łukasz "JustArchi" Domeradzki
|
2016-03-20 05:27:30 +01:00
|
|
|
|
Contact: JustArchi@JustArchi.net
|
|
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-13 06:32:42 +02:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Net.Sockets;
|
2017-01-08 15:09:30 +01:00
|
|
|
|
using ConfigGenerator.Localization;
|
2016-11-24 07:32:16 +01:00
|
|
|
|
using Newtonsoft.Json;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
|
|
|
|
|
namespace ConfigGenerator {
|
2016-06-09 01:15:48 +02:00
|
|
|
|
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
|
|
|
|
|
|
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
|
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
2016-03-20 06:41:12 +01:00
|
|
|
|
internal sealed class GlobalConfig : ASFConfig {
|
2017-01-22 20:10:28 +01:00
|
|
|
|
private const byte DefaultConnectionTimeout = 60;
|
2016-06-09 01:15:48 +02:00
|
|
|
|
private const byte DefaultFarmingDelay = 15;
|
2016-11-24 07:32:16 +01:00
|
|
|
|
private const byte DefaultMaxFarmingTime = 10;
|
2016-03-26 22:51:19 +01:00
|
|
|
|
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
|
2016-11-24 07:32:16 +01:00
|
|
|
|
private const ushort DefaultWCFPort = 1242;
|
2016-03-23 13:39:56 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Updates")]
|
2016-04-06 16:37:45 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public bool AutoRestart { get; set; } = true;
|
2016-04-06 16:37:45 +02:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Updates")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public bool AutoUpdates { get; set; } = true;
|
|
|
|
|
|
|
2017-02-27 19:59:52 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public List<uint> Blacklist { get; set; } = new List<uint>();
|
2016-04-18 18:38:48 +02:00
|
|
|
|
|
2017-01-22 20:10:28 +01:00
|
|
|
|
[LocalizedCategory("Debugging")]
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public byte ConnectionTimeout { get; set; } = DefaultConnectionTimeout;
|
|
|
|
|
|
|
2017-01-08 05:32:59 +01:00
|
|
|
|
[JsonProperty]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
public string CurrentCulture { get; set; }
|
2017-01-08 05:32:59 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Debugging")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
public bool Debug { get; set; }
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public byte FarmingDelay { get; set; } = DefaultFarmingDelay;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public byte GiftsLimiterDelay { get; set; } = 1;
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Advanced")]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
public bool Headless { get; set; }
|
2016-11-24 07:32:16 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public byte IdleFarmingPeriod { get; set; } = 3;
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public byte InventoryLimiterDelay { get; set; } = 3;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-06-23 16:00:15 +02:00
|
|
|
|
public byte LoginLimiterDelay { get; set; } = 10;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public byte MaxFarmingTime { get; set; } = DefaultMaxFarmingTime;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2016-06-24 22:26:52 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public byte MaxTradeHoldDuration { get; set; } = 15;
|
2016-06-24 22:26:52 +02:00
|
|
|
|
|
2017-01-30 22:17:25 +01:00
|
|
|
|
[LocalizedCategory("Performance")]
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-01-30 22:42:05 +01:00
|
|
|
|
public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.MaxPerformance;
|
2017-01-30 22:17:25 +01:00
|
|
|
|
|
2016-06-27 01:45:41 +02:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public bool Statistics { get; set; } = true;
|
2016-06-27 01:45:41 +02:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Access")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2017-04-05 14:30:14 +02:00
|
|
|
|
public ulong SteamOwnerID { get; set; }
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Advanced")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
public ProtocolType SteamProtocol { get; set; } = DefaultSteamProtocol;
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Updates")]
|
2016-11-24 07:32:16 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public EUpdateChannel UpdateChannel { get; set; } = EUpdateChannel.Stable;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-02-03 09:59:02 +01:00
|
|
|
|
[LocalizedCategory("Access")]
|
|
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
|
|
|
|
|
public EWCFBinding WCFBinding { get; set; } = EWCFBinding.NetTcp;
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Access")]
|
2016-03-23 13:39:56 +01:00
|
|
|
|
[JsonProperty]
|
2016-12-16 14:20:32 +01:00
|
|
|
|
public string WCFHost { get; set; } = "127.0.0.1";
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
[LocalizedCategory("Access")]
|
2016-03-20 05:27:30 +01:00
|
|
|
|
[JsonProperty(Required = Required.DisallowNull)]
|
2016-03-23 13:39:56 +01:00
|
|
|
|
public ushort WCFPort { get; set; } = DefaultWCFPort;
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
|
|
|
|
|
private GlobalConfig() { }
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
private GlobalConfig(string filePath) : base(filePath) {
|
|
|
|
|
|
if (string.IsNullOrEmpty(filePath)) {
|
|
|
|
|
|
throw new ArgumentNullException(nameof(filePath));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Save();
|
|
|
|
|
|
}
|
2016-03-20 05:27:30 +01:00
|
|
|
|
|
|
|
|
|
|
internal static GlobalConfig Load(string filePath) {
|
|
|
|
|
|
if (string.IsNullOrEmpty(filePath)) {
|
2016-05-30 01:57:06 +02:00
|
|
|
|
Logging.LogNullError(nameof(filePath));
|
2016-03-20 05:27:30 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filePath)) {
|
|
|
|
|
|
return new GlobalConfig(filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GlobalConfig globalConfig;
|
2016-05-30 01:57:06 +02:00
|
|
|
|
|
2016-03-20 05:27:30 +01:00
|
|
|
|
try {
|
|
|
|
|
|
globalConfig = JsonConvert.DeserializeObject<GlobalConfig>(File.ReadAllText(filePath));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
Logging.LogGenericException(e);
|
2016-03-23 13:42:16 +01:00
|
|
|
|
return new GlobalConfig(filePath);
|
2016-03-20 05:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-28 13:11:02 +02:00
|
|
|
|
if (globalConfig == null) {
|
|
|
|
|
|
return new GlobalConfig(filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-23 18:38:19 +01:00
|
|
|
|
globalConfig.FilePath = filePath;
|
2017-01-08 15:09:30 +01:00
|
|
|
|
globalConfig.ValidateAndFix();
|
|
|
|
|
|
return globalConfig;
|
|
|
|
|
|
}
|
2016-03-23 18:38:19 +01:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
internal override void ValidateAndFix() {
|
|
|
|
|
|
base.ValidateAndFix();
|
|
|
|
|
|
|
2017-01-22 20:10:28 +01:00
|
|
|
|
if (ConnectionTimeout == 0) {
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(ConnectionTimeout), ConnectionTimeout));
|
|
|
|
|
|
ConnectionTimeout = DefaultConnectionTimeout;
|
2017-01-08 15:09:30 +01:00
|
|
|
|
Save();
|
2017-01-22 20:10:28 +01:00
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(ConnectionTimeout), ConnectionTimeout));
|
2016-03-23 13:39:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
if (FarmingDelay == 0) {
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(FarmingDelay), FarmingDelay));
|
|
|
|
|
|
FarmingDelay = DefaultFarmingDelay;
|
|
|
|
|
|
Save();
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(FarmingDelay), FarmingDelay));
|
2016-03-23 13:39:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-22 20:10:28 +01:00
|
|
|
|
if (MaxFarmingTime == 0) {
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(MaxFarmingTime), MaxFarmingTime));
|
|
|
|
|
|
MaxFarmingTime = DefaultMaxFarmingTime;
|
2017-01-08 15:09:30 +01:00
|
|
|
|
Save();
|
2017-01-22 20:10:28 +01:00
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(MaxFarmingTime), MaxFarmingTime));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (SteamProtocol) {
|
|
|
|
|
|
case ProtocolType.Tcp:
|
|
|
|
|
|
case ProtocolType.Udp:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(SteamProtocol), SteamProtocol));
|
|
|
|
|
|
SteamProtocol = DefaultSteamProtocol;
|
|
|
|
|
|
Save();
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(SteamProtocol), SteamProtocol));
|
|
|
|
|
|
break;
|
2016-03-23 13:39:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
if (WCFPort != 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-05-13 06:32:42 +02:00
|
|
|
|
|
2017-01-08 15:09:30 +01:00
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(WCFPort), WCFPort));
|
|
|
|
|
|
WCFPort = DefaultWCFPort;
|
|
|
|
|
|
Save();
|
|
|
|
|
|
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(WCFPort), WCFPort));
|
2016-03-20 05:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-30 22:17:25 +01:00
|
|
|
|
internal enum EOptimizationMode : byte {
|
|
|
|
|
|
MaxPerformance,
|
|
|
|
|
|
MinMemoryUsage
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-24 07:32:16 +01:00
|
|
|
|
internal enum EUpdateChannel : byte {
|
|
|
|
|
|
None,
|
|
|
|
|
|
Stable,
|
|
|
|
|
|
Experimental
|
2016-03-20 05:27:30 +01:00
|
|
|
|
}
|
2017-02-03 09:56:18 +01:00
|
|
|
|
|
2017-02-03 09:59:02 +01:00
|
|
|
|
internal enum EWCFBinding : byte {
|
2017-02-03 09:56:18 +01:00
|
|
|
|
NetTcp,
|
|
|
|
|
|
BasicHttp,
|
|
|
|
|
|
WSHttp
|
|
|
|
|
|
}
|
2016-03-20 05:27:30 +01:00
|
|
|
|
}
|
2016-11-24 07:32:16 +01:00
|
|
|
|
}
|