mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Feature handle ipc config changes (#1349)
* Handle changes to IPC.config * Only restart ArchiKestrel instead of ASF as a whole * Fix autocomplete mistake https://www.youtube.com/watch?v=s1BDBT9LQJg * Rename methods as requested and Handle multiple write events correctly * Revert requested changes
This commit is contained in:
committed by
Łukasz Domeradzki
parent
ba30ac8e85
commit
4cf66478cb
@@ -374,6 +374,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
switch (extension) {
|
||||
case SharedInfo.ConfigExtension:
|
||||
case SharedInfo.IPCConfigExtension:
|
||||
await OnChangedConfigFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
@@ -411,6 +412,69 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
string extension = Path.GetExtension(name);
|
||||
|
||||
switch (extension) {
|
||||
case SharedInfo.IPCConfigExtension:
|
||||
await OnCreatedConfigFile(name).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
case SharedInfo.ConfigExtension:
|
||||
await OnCreatedJsonFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task OnCreatedFile(string name, string fullPath) {
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(fullPath)) {
|
||||
ArchiLogger.LogNullError(nameof(name) + " || " + nameof(fullPath));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string extension = Path.GetExtension(name);
|
||||
|
||||
switch (extension) {
|
||||
case SharedInfo.ConfigExtension:
|
||||
await OnCreatedConfigFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
|
||||
case SharedInfo.KeysExtension:
|
||||
await OnCreatedKeysFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task OnCreatedConfigFile(string name) {
|
||||
if (string.IsNullOrEmpty(name)) {
|
||||
ArchiLogger.LogNullError(nameof(name));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name.Equals(SharedInfo.IPCConfigFile) || (GlobalConfig?.IPC != true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await CanHandleWriteEvent(name).ConfigureAwait(false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArchiLogger.LogGenericInfo(Strings.IPCConfigChanged);
|
||||
await ArchiKestrel.Stop().ConfigureAwait(false);
|
||||
await ArchiKestrel.Start().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task OnCreatedJsonFile(string name, string fullPath) {
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(fullPath)) {
|
||||
ArchiLogger.LogNullError(nameof(name) + " || " + nameof(fullPath));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string botName = Path.GetFileNameWithoutExtension(name);
|
||||
|
||||
if (string.IsNullOrEmpty(botName) || (botName[0] == '.')) {
|
||||
@@ -443,27 +507,6 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task OnCreatedFile(string name, string fullPath) {
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(fullPath)) {
|
||||
ArchiLogger.LogNullError(nameof(name) + " || " + nameof(fullPath));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string extension = Path.GetExtension(name);
|
||||
|
||||
switch (extension) {
|
||||
case SharedInfo.ConfigExtension:
|
||||
await OnCreatedConfigFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
case SharedInfo.KeysExtension:
|
||||
await OnCreatedKeysFile(name, fullPath).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task OnCreatedKeysFile(string name, string fullPath) {
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(fullPath)) {
|
||||
ArchiLogger.LogNullError(nameof(name) + " || " + nameof(fullPath));
|
||||
|
||||
@@ -32,8 +32,6 @@ using NLog.Web;
|
||||
|
||||
namespace ArchiSteamFarm.IPC {
|
||||
internal static class ArchiKestrel {
|
||||
private const string ConfigurationFile = nameof(IPC) + ".config";
|
||||
|
||||
internal static HistoryTarget HistoryTarget { get; private set; }
|
||||
internal static string WebsiteDirectory { get; private set; } = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.WebsiteDirectory);
|
||||
|
||||
@@ -78,9 +76,9 @@ namespace ArchiSteamFarm.IPC {
|
||||
builder.ConfigureLogging(logging => logging.SetMinimumLevel(Debugging.IsUserDebugging ? LogLevel.Trace : LogLevel.Warning));
|
||||
|
||||
// Now conditionally initialize settings that are not possible to override
|
||||
if (File.Exists(Path.Combine(absoluteConfigDirectory, ConfigurationFile))) {
|
||||
if (File.Exists(Path.Combine(absoluteConfigDirectory, SharedInfo.IPCConfigFile))) {
|
||||
// Set up custom config to be used
|
||||
builder.UseConfiguration(new ConfigurationBuilder().SetBasePath(absoluteConfigDirectory).AddJsonFile(ConfigurationFile, false, true).Build());
|
||||
builder.UseConfiguration(new ConfigurationBuilder().SetBasePath(absoluteConfigDirectory).AddJsonFile(SharedInfo.IPCConfigFile, false, true).Build());
|
||||
|
||||
// Use custom config for Kestrel and Logging configuration
|
||||
builder.UseKestrel((builderContext, options) => options.Configure(builderContext.Configuration.GetSection("Kestrel")));
|
||||
|
||||
387
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
387
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@@ -734,4 +734,7 @@ StackTrace:
|
||||
<data name="BotGeneratingSteamParentalCode" xml:space="preserve">
|
||||
<value>Generating Steam parental code, this can take a while, consider putting it in the config instead...</value>
|
||||
</data>
|
||||
<data name="IPCConfigChanged" xml:space="preserve">
|
||||
<value>IPC config has been changed!</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -45,6 +45,8 @@ namespace ArchiSteamFarm {
|
||||
internal const string GithubRepo = "JustArchiNET/" + AssemblyName;
|
||||
internal const string GlobalConfigFileName = ASF + ConfigExtension;
|
||||
internal const string GlobalDatabaseFileName = ASF + DatabaseExtension;
|
||||
internal const string IPCConfigExtension = ".config";
|
||||
internal const string IPCConfigFile = nameof(IPC) + IPCConfigExtension;
|
||||
internal const string KeysExtension = ".keys";
|
||||
internal const string KeysUnusedExtension = ".unused";
|
||||
internal const string KeysUsedExtension = ".used";
|
||||
|
||||
Reference in New Issue
Block a user