mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Introduce UpdatePeriod
Direct AutoUpdates replacement, also get rid of ArchiSteamFarm.version, since I'm pretty sure it can be done at compile time instead.
This commit is contained in:
19
.travis.yml
19
.travis.yml
@@ -23,7 +23,7 @@ env:
|
||||
- CONFIGURATION: Release
|
||||
- DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
- RUNTIMES="generic win-x64 linux-x64 linux-arm osx-x64" # https://github.com/travis-ci/travis-ci/issues/1444
|
||||
- VARIANTS="generic win-x64 linux-x64 linux-arm osx-x64" # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in ASF.cs!
|
||||
|
||||
before_script:
|
||||
- |
|
||||
@@ -43,21 +43,22 @@ script:
|
||||
dotnet test ArchiSteamFarm.Tests -c "$CONFIGURATION" -o 'out/source' --no-build --no-restore
|
||||
|
||||
publish() {
|
||||
if [ "$1" = 'generic' ]; then
|
||||
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo /p:LinkDuringPublish=false
|
||||
else
|
||||
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" -r "$1" --no-restore /nologo
|
||||
fi
|
||||
local variantProperty="${1//-/_}"
|
||||
variantProperty="ASF_VARIANT_${variantProperty^^}=1"
|
||||
|
||||
echo "$1" > "ArchiSteamFarm/out/${1}/ArchiSteamFarm.version"
|
||||
if [ "$1" = 'generic' ]; then
|
||||
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo "/p:$variantProperty" /p:LinkDuringPublish=false
|
||||
else
|
||||
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" -r "$1" --no-restore /nologo "/p:$variantProperty"
|
||||
fi
|
||||
|
||||
if [ -d "ArchiSteamFarm/scripts/${1}" ]; then
|
||||
cp "ArchiSteamFarm/scripts/${1}/"* "ArchiSteamFarm/out/${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
for RUNTIME in $RUNTIMES; do
|
||||
publish "$RUNTIME" &
|
||||
for variant in $VARIANTS; do
|
||||
publish "$variant" &
|
||||
done
|
||||
wait
|
||||
|
||||
|
||||
@@ -33,8 +33,21 @@ using ArchiSteamFarm.Localization;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class ASF {
|
||||
private const byte AutoUpdatePeriodInHours = 24;
|
||||
private const string DefaultVersion = "source"; // Default entry of ArchiSteamFarm.version
|
||||
private const string SourceVariant = "source";
|
||||
|
||||
#if ASF_VARIANT_GENERIC
|
||||
private const string Variant = "generic";
|
||||
#elif ASF_VARIANT_LINUX_ARM
|
||||
private const string Variant = "linux-arm";
|
||||
#elif ASF_VARIANT_LINUX_X64
|
||||
private const string Variant = "linux-x64";
|
||||
#elif ASF_VARIANT_OSX_X64
|
||||
private const string Variant = "osx-x64";
|
||||
#elif ASF_VARIANT_WIN_X64
|
||||
private const string Variant = "win-x64";
|
||||
#else
|
||||
private const string Variant = SourceVariant;
|
||||
#endif
|
||||
|
||||
internal static readonly ArchiLogger ArchiLogger = new ArchiLogger(SharedInfo.ASF);
|
||||
|
||||
@@ -44,50 +57,12 @@ namespace ArchiSteamFarm {
|
||||
private static FileSystemWatcher FileSystemWatcher;
|
||||
|
||||
internal static async Task<Version> CheckAndUpdateProgram(bool updateOverride = false) {
|
||||
if (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None) {
|
||||
if (Variant.Equals(SourceVariant) || (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
string assemblyFile = Assembly.GetEntryAssembly().Location;
|
||||
if (string.IsNullOrEmpty(assemblyFile)) {
|
||||
ArchiLogger.LogNullError(nameof(assemblyFile));
|
||||
return null;
|
||||
}
|
||||
|
||||
string targetDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
string versionFile = Path.Combine(targetDirectory, SharedInfo.VersionFile);
|
||||
|
||||
if (!File.Exists(versionFile)) {
|
||||
ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, versionFile));
|
||||
return null;
|
||||
}
|
||||
|
||||
string version;
|
||||
|
||||
try {
|
||||
version = await File.ReadAllTextAsync(versionFile).ConfigureAwait(false);
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, versionFile));
|
||||
return null;
|
||||
}
|
||||
|
||||
version = version.TrimEnd();
|
||||
if (string.IsNullOrEmpty(version) || !IsValidVersion(version)) {
|
||||
ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, versionFile));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (version.Equals(DefaultVersion)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((AutoUpdatesTimer == null) && Program.GlobalConfig.AutoUpdates) {
|
||||
TimeSpan autoUpdatePeriod = TimeSpan.FromHours(AutoUpdatePeriodInHours);
|
||||
if ((AutoUpdatesTimer == null) && (Program.GlobalConfig.UpdatePeriod > 0)) {
|
||||
TimeSpan autoUpdatePeriod = TimeSpan.FromHours(Program.GlobalConfig.UpdatePeriod);
|
||||
|
||||
AutoUpdatesTimer = new Timer(
|
||||
async e => await CheckAndUpdateProgram().ConfigureAwait(false),
|
||||
@@ -101,6 +76,8 @@ namespace ArchiSteamFarm {
|
||||
|
||||
ArchiLogger.LogGenericInfo(Strings.UpdateCheckingNewVersion);
|
||||
|
||||
string targetDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
||||
// Cleanup from previous update - update directory for old in-use runtime files
|
||||
string backupDirectory = Path.Combine(targetDirectory, SharedInfo.UpdateDirectory);
|
||||
if (Directory.Exists(backupDirectory)) {
|
||||
@@ -164,7 +141,7 @@ namespace ArchiSteamFarm {
|
||||
return SharedInfo.Version;
|
||||
}
|
||||
|
||||
if (!updateOverride && !Program.GlobalConfig.AutoUpdates) {
|
||||
if (!updateOverride && (Program.GlobalConfig.UpdatePeriod == 0)) {
|
||||
ArchiLogger.LogGenericInfo(Strings.UpdateNewVersionAvailable);
|
||||
await Task.Delay(5000).ConfigureAwait(false);
|
||||
return null;
|
||||
@@ -176,7 +153,7 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
string targetFile = SharedInfo.ASF + "-" + version + ".zip";
|
||||
const string targetFile = SharedInfo.ASF + "-" + Variant + ".zip";
|
||||
GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => asset.Name.Equals(targetFile, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (binaryAsset == null) {
|
||||
@@ -205,7 +182,7 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (IsUnixVersion(version)) {
|
||||
if (IsUnixVariant(Variant)) {
|
||||
string executable = Path.Combine(targetDirectory, SharedInfo.AssemblyName);
|
||||
if (File.Exists(executable)) {
|
||||
OS.UnixSetFileAccessExecutable(executable);
|
||||
@@ -269,13 +246,13 @@ namespace ArchiSteamFarm {
|
||||
await Bot.RegisterBot(botName).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static bool IsUnixVersion(string version) {
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
ArchiLogger.LogNullError(nameof(version));
|
||||
private static bool IsUnixVariant(string variant) {
|
||||
if (string.IsNullOrEmpty(variant)) {
|
||||
ArchiLogger.LogNullError(nameof(variant));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (version) {
|
||||
switch (variant) {
|
||||
case "linux-arm":
|
||||
case "linux-x64":
|
||||
case "osx-x64":
|
||||
@@ -305,25 +282,6 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsValidVersion(string version) {
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
ArchiLogger.LogNullError(nameof(version));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (version) {
|
||||
case DefaultVersion:
|
||||
case "generic":
|
||||
case "linux-arm":
|
||||
case "linux-x64":
|
||||
case "osx-x64":
|
||||
case "win-x64":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static async void OnChanged(object sender, FileSystemEventArgs e) {
|
||||
if ((sender == null) || (e == null)) {
|
||||
ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e));
|
||||
|
||||
@@ -63,9 +63,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ArchiSteamFarm.version">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Changelog.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
source
|
||||
@@ -41,9 +41,6 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool AutoRestart = true;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool AutoUpdates = true;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte BackgroundGCPeriod;
|
||||
|
||||
@@ -101,6 +98,9 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly EUpdateChannel UpdateChannel = EUpdateChannel.Stable;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte UpdatePeriod = 24;
|
||||
|
||||
[JsonProperty]
|
||||
internal string IPCHost { get; set; } = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace ArchiSteamFarm {
|
||||
internal const string LogFile = "log.txt";
|
||||
internal const string StatisticsServer = "asf.justarchi.net";
|
||||
internal const string UpdateDirectory = "_old";
|
||||
internal const string VersionFile = AssemblyName + ".version";
|
||||
|
||||
internal static Guid ModuleVersion => Assembly.GetEntryAssembly().ManifestModule.ModuleVersionId;
|
||||
internal static Version Version => Assembly.GetEntryAssembly().GetName().Version;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"AutoRestart": true,
|
||||
"AutoUpdates": true,
|
||||
"BackgroundGCPeriod": 0,
|
||||
"Blacklist": [],
|
||||
"ConnectionTimeout": 60,
|
||||
@@ -20,5 +19,6 @@
|
||||
"Statistics": true,
|
||||
"SteamOwnerID": 0,
|
||||
"SteamProtocols": 1,
|
||||
"UpdateChannel": 1
|
||||
"UpdateChannel": 1,
|
||||
"UpdatePeriod": 24
|
||||
}
|
||||
41
appveyor.yml
41
appveyor.yml
@@ -12,7 +12,7 @@ clone_depth: 10
|
||||
environment:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
RUNTIMES: generic win-x64 linux-x64 linux-arm osx-x64
|
||||
VARIANTS: generic win-x64 linux-x64 linux-arm osx-x64 # NOTE: When modifying variants, don't forget to update ASF_VARIANT definitions in ASF.cs!
|
||||
matrix:
|
||||
fast_finish: true
|
||||
before_build:
|
||||
@@ -57,7 +57,7 @@ after_test:
|
||||
|
||||
|
||||
$PublishBlock = {
|
||||
param($RUNTIME)
|
||||
param($Variant)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
@@ -65,44 +65,43 @@ after_test:
|
||||
|
||||
Set-Location -Path "$env:APPVEYOR_BUILD_FOLDER"
|
||||
|
||||
if ($RUNTIME -eq 'generic') {
|
||||
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" --no-restore /nologo /p:LinkDuringPublish=false
|
||||
$variantProperty = 'ASF_VARIANT_' + $Variant.Replace('-', '_').ToUpperInvariant() + '=1'
|
||||
|
||||
if ($Variant -eq 'generic') {
|
||||
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$Variant" --no-restore /nologo "/p:$variantProperty" /p:LinkDuringPublish=false
|
||||
} else {
|
||||
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" -r "$RUNTIME" --no-restore /nologo
|
||||
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$Variant" -r "$Variant" --no-restore /nologo "/p:$variantProperty"
|
||||
}
|
||||
|
||||
# Update ArchiSteamFarm.version from "source" variant into the one we've just built
|
||||
Set-Content -Path "ArchiSteamFarm\out\$RUNTIME\ArchiSteamFarm.version" -Value "$RUNTIME"
|
||||
|
||||
# If we include any helper scripts for this variant, copy them to output directory
|
||||
if (Test-Path -Path "ArchiSteamFarm\scripts\$RUNTIME" -PathType Container) {
|
||||
Copy-Item "ArchiSteamFarm\scripts\$RUNTIME\*" -Destination "ArchiSteamFarm\out\$RUNTIME"
|
||||
if (Test-Path -Path "ArchiSteamFarm\scripts\$Variant" -PathType Container) {
|
||||
Copy-Item "ArchiSteamFarm\scripts\$Variant\*" -Destination "ArchiSteamFarm\out\$Variant"
|
||||
}
|
||||
|
||||
# Until https://github.com/dotnet/cli/issues/3267 happens, we'll hack dotnet binary icon on Windows and include .ico file on other platforms
|
||||
if (Test-Path -Path "ArchiSteamFarm\out\$RUNTIME\ArchiSteamFarm.exe" -PathType Leaf) {
|
||||
tools\rcedit\rcedit-x64.exe "ArchiSteamFarm\out\$RUNTIME\ArchiSteamFarm.exe" --set-icon 'resources\ASF.ico'
|
||||
if (Test-Path -Path "ArchiSteamFarm\out\$Variant\ArchiSteamFarm.exe" -PathType Leaf) {
|
||||
tools\rcedit\rcedit-x64.exe "ArchiSteamFarm\out\$Variant\ArchiSteamFarm.exe" --set-icon 'resources\ASF.ico'
|
||||
} else {
|
||||
Copy-Item 'resources\ASF.ico' -Destination "ArchiSteamFarm\out\$RUNTIME\ArchiSteamFarm.ico"
|
||||
Copy-Item 'resources\ASF.ico' -Destination "ArchiSteamFarm\out\$Variant\ArchiSteamFarm.ico"
|
||||
}
|
||||
|
||||
if ($env:APPVEYOR_REPO_TAG -eq 'true') {
|
||||
# Update link in Changelog.html accordingly
|
||||
if (Test-Path -Path "ArchiSteamFarm\out\$RUNTIME\Changelog.html" -PathType Leaf) {
|
||||
(Get-Content -Path "ArchiSteamFarm\out\$RUNTIME\Changelog.html").Replace('ArchiSteamFarm/commits/master', "ArchiSteamFarm/releases/tag/$env:APPVEYOR_REPO_TAG_NAME") | Set-Content -Path "ArchiSteamFarm\out\$RUNTIME\Changelog.html"
|
||||
if (Test-Path -Path "ArchiSteamFarm\out\$Variant\Changelog.html" -PathType Leaf) {
|
||||
(Get-Content -Path "ArchiSteamFarm\out\$Variant\Changelog.html").Replace('ArchiSteamFarm/commits/master', "ArchiSteamFarm/releases/tag/$env:APPVEYOR_REPO_TAG_NAME") | Set-Content -Path "ArchiSteamFarm\out\$Variant\Changelog.html"
|
||||
}
|
||||
|
||||
$ZIP_ARGS = '-mx=9', '-mfb=257', '-mpass=15'
|
||||
$zipArgs = '-mx=9', '-mfb=257', '-mpass=15'
|
||||
} else {
|
||||
$ZIP_ARGS = '-mx=1'
|
||||
$zipArgs = '-mx=1'
|
||||
}
|
||||
|
||||
7z a -bd -tzip -mm=Deflate64 $ZIP_ARGS "ArchiSteamFarm\out\ASF-$RUNTIME.zip" "$env:APPVEYOR_BUILD_FOLDER\ArchiSteamFarm\out\$RUNTIME\*"
|
||||
Push-AppveyorArtifact "ArchiSteamFarm\out\ASF-$RUNTIME.zip" -FileName "ASF-$RUNTIME.zip" -DeploymentName "ASF-$RUNTIME.zip"
|
||||
7z a -bd -tzip -mm=Deflate64 $zipArgs "ArchiSteamFarm\out\ASF-$Variant.zip" "$env:APPVEYOR_BUILD_FOLDER\ArchiSteamFarm\out\$Variant\*"
|
||||
Push-AppveyorArtifact "ArchiSteamFarm\out\ASF-$Variant.zip" -FileName "ASF-$Variant.zip" -DeploymentName "ASF-$Variant.zip"
|
||||
}
|
||||
|
||||
foreach ($RUNTIME in $env:RUNTIMES.Split([char[]] $null, [System.StringSplitOptions]::RemoveEmptyEntries)) {
|
||||
Start-Job -Name "$RUNTIME" -ScriptBlock $PublishBlock -ArgumentList "$RUNTIME"
|
||||
foreach ($variant in $env:VARIANTS.Split([char[]] $null, [System.StringSplitOptions]::RemoveEmptyEntries)) {
|
||||
Start-Job -Name "$variant" -ScriptBlock $PublishBlock -ArgumentList "$variant"
|
||||
}
|
||||
|
||||
Get-Job | Receive-Job -AutoRemoveJob -Wait
|
||||
|
||||
Reference in New Issue
Block a user