ArchiSteamFarm/ConfigGenerator/GlobalConfig.cs

224 lines
7.7 KiB
C#
Raw Normal View History

2016-03-20 04:27:30 +00:00
/*
_ _ _ ____ _ _____
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
2017-01-02 19:05:21 +00:00
Copyright 2015-2017 Łukasz "JustArchi" Domeradzki
2016-03-20 04:27:30 +00: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 04:32:42 +00:00
using System.Diagnostics.CodeAnalysis;
2016-03-20 04:27:30 +00:00
using System.IO;
using System.Net.Sockets;
using ConfigGenerator.Localization;
using Newtonsoft.Json;
2016-03-20 04:27:30 +00:00
namespace ConfigGenerator {
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
2016-03-20 05:41:12 +00:00
internal sealed class GlobalConfig : ASFConfig {
private const byte DefaultConnectionTimeout = 60;
private const byte DefaultFarmingDelay = 15;
private const byte DefaultMaxFarmingTime = 10;
2016-03-26 21:51:19 +00:00
private const ProtocolType DefaultSteamProtocol = ProtocolType.Tcp;
private const ushort DefaultWCFPort = 1242;
2016-03-23 12:39:56 +00:00
2016-03-20 04:27:30 +00:00
// This is hardcoded blacklist which should not be possible to change
2016-12-15 02:38:16 +00:00
private static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 267420, 303700, 335590, 368020, 425280, 480730, 566020 };
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Updates")]
2016-04-06 14:37:45 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public bool AutoRestart { get; set; } = true;
2016-04-06 14:37:45 +00:00
[LocalizedCategory("Updates")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public bool AutoUpdates { get; set; } = true;
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
public List<uint> Blacklist { get; set; } = new List<uint>(GlobalBlacklist);
2016-04-18 16:38:48 +00:00
[LocalizedCategory("Debugging")]
[JsonProperty(Required = Required.DisallowNull)]
public byte ConnectionTimeout { get; set; } = DefaultConnectionTimeout;
2017-01-08 04:32:59 +00:00
[JsonProperty]
public string CurrentCulture { get; set; } = null;
[LocalizedCategory("Debugging")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public bool Debug { get; set; } = false;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte FarmingDelay { get; set; } = DefaultFarmingDelay;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte GiftsLimiterDelay { get; set; } = 1;
[LocalizedCategory("Advanced")]
[JsonProperty(Required = Required.DisallowNull)]
public bool Headless { get; set; } = false;
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte IdleFarmingPeriod { get; set; } = 3;
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte InventoryLimiterDelay { get; set; } = 3;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte LoginLimiterDelay { get; set; } = 10;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Performance")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte MaxFarmingTime { get; set; } = DefaultMaxFarmingTime;
2016-03-20 04:27:30 +00:00
2016-06-24 20:26:52 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public byte MaxTradeHoldDuration { get; set; } = 15;
2016-06-24 20:26:52 +00:00
[LocalizedCategory("Performance")]
[JsonProperty(Required = Required.DisallowNull)]
public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.MaxPerformance;
2016-06-26 23:45:41 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public bool Statistics { get; set; } = true;
2016-06-26 23:45:41 +00:00
[LocalizedCategory("Access")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamOwnerID { get; set; } = 0;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Advanced")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
public ProtocolType SteamProtocol { get; set; } = DefaultSteamProtocol;
[LocalizedCategory("Updates")]
[JsonProperty(Required = Required.DisallowNull)]
public EUpdateChannel UpdateChannel { get; set; } = EUpdateChannel.Stable;
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Access")]
2016-03-23 12:39:56 +00:00
[JsonProperty]
2016-12-16 13:20:32 +00:00
public string WCFHost { get; set; } = "127.0.0.1";
2016-03-20 04:27:30 +00:00
[LocalizedCategory("Access")]
2016-03-20 04:27:30 +00:00
[JsonProperty(Required = Required.DisallowNull)]
2016-03-23 12:39:56 +00:00
public ushort WCFPort { get; set; } = DefaultWCFPort;
2016-03-20 04:27:30 +00:00
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private GlobalConfig() { }
2016-03-20 04:27:30 +00:00
private GlobalConfig(string filePath) : base(filePath) {
if (string.IsNullOrEmpty(filePath)) {
throw new ArgumentNullException(nameof(filePath));
}
Save();
}
2016-03-20 04:27:30 +00:00
internal static GlobalConfig Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) {
2016-05-29 23:57:06 +00:00
Logging.LogNullError(nameof(filePath));
2016-03-20 04:27:30 +00:00
return null;
}
if (!File.Exists(filePath)) {
return new GlobalConfig(filePath);
}
GlobalConfig globalConfig;
2016-05-29 23:57:06 +00:00
2016-03-20 04:27:30 +00:00
try {
globalConfig = JsonConvert.DeserializeObject<GlobalConfig>(File.ReadAllText(filePath));
} catch (Exception e) {
Logging.LogGenericException(e);
2016-03-23 12:42:16 +00:00
return new GlobalConfig(filePath);
2016-03-20 04:27:30 +00:00
}
2016-03-28 11:11:02 +00:00
if (globalConfig == null) {
return new GlobalConfig(filePath);
}
2016-03-23 17:38:19 +00:00
globalConfig.FilePath = filePath;
globalConfig.ValidateAndFix();
return globalConfig;
}
2016-03-23 17:38:19 +00:00
internal override void ValidateAndFix() {
base.ValidateAndFix();
if (ConnectionTimeout == 0) {
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(ConnectionTimeout), ConnectionTimeout));
ConnectionTimeout = DefaultConnectionTimeout;
Save();
Logging.LogGenericWarning(string.Format(CGStrings.WarningConfigPropertyModified, nameof(ConnectionTimeout), ConnectionTimeout));
2016-03-23 12:39:56 +00: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 12:39:56 +00:00
}
if (MaxFarmingTime == 0) {
Logging.LogGenericWarning(string.Format(CGStrings.ErrorConfigPropertyInvalid, nameof(MaxFarmingTime), MaxFarmingTime));
MaxFarmingTime = DefaultMaxFarmingTime;
Save();
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 12:39:56 +00:00
}
if (WCFPort != 0) {
return;
}
2016-05-13 04:32:42 +00: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 04:27:30 +00:00
}
internal enum EOptimizationMode : byte {
MaxPerformance,
MinMemoryUsage
}
internal enum EUpdateChannel : byte {
None,
Stable,
Experimental
2016-03-20 04:27:30 +00:00
}
}
}