This commit is contained in:
JustArchi 2017-07-01 04:06:33 +02:00
parent 78bb754a6e
commit f2d527c0ec
8 changed files with 100 additions and 48 deletions

View file

@ -28,9 +28,13 @@ script:
- dotnet restore
- dotnet build -c Release
- dotnet publish -c Release -o out/generic
- echo "generic" > ASF/out/generic/ASF.version
- dotnet publish -c Release -r win-x64 -o out/win-x64
- echo "win-x64" > ASF/out/win-x64/ASF.version
- dotnet publish -c Release -r linux-x64 -o out/linux-x64
- echo "linux-x64" > ASF/out/linux-x64/ASF.version
- dotnet publish -c Release -r osx-x64 -o out/osx-x64
- echo "osx-x64" > ASF/out/osx-x64/ASF.version
# This is our main build matrix
matrix:

View file

@ -26,6 +26,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Threading;
@ -45,32 +46,47 @@ namespace ArchiSteamFarm {
private static FileSystemWatcher FileSystemWatcher;
internal static async Task CheckForUpdate(bool updateOverride = false) {
if (Debugging.IsDebugBuild && !updateOverride) {
if (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None) {
return;
}
string exeFile = Assembly.GetEntryAssembly().Location;
if (string.IsNullOrEmpty(exeFile)) {
ArchiLogger.LogNullError(nameof(exeFile));
string assemblyFile = Assembly.GetEntryAssembly().Location;
if (string.IsNullOrEmpty(assemblyFile)) {
ArchiLogger.LogNullError(nameof(assemblyFile));
return;
}
string oldExeFile = exeFile + ".old";
string oldAssemblyFile = assemblyFile + ".old";
// We booted successfully so we can now remove old exe file
if (File.Exists(oldExeFile)) {
if (File.Exists(oldAssemblyFile)) {
// It's entirely possible that old process is still running, allow at least a second before trying to remove the file
await Task.Delay(1000).ConfigureAwait(false);
try {
File.Delete(oldExeFile);
File.Delete(oldAssemblyFile);
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
ArchiLogger.LogGenericError(string.Format(Strings.ErrorRemovingOldBinary, oldExeFile));
ArchiLogger.LogGenericError(string.Format(Strings.ErrorRemovingOldBinary, oldAssemblyFile));
}
}
if (Program.GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.None) {
if (!File.Exists(SharedInfo.VersionFile)) {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, SharedInfo.VersionFile));
return;
}
string version;
try {
version = await File.ReadAllTextAsync(SharedInfo.VersionFile).ConfigureAwait(false);
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
return;
}
if (string.IsNullOrEmpty(version) || !IsVersionValid(version)) {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, SharedInfo.VersionFile));
return;
}
@ -137,8 +153,8 @@ namespace ArchiSteamFarm {
return;
}
if (File.Exists(oldExeFile)) {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorRemovingOldBinary, oldExeFile));
if (File.Exists(oldAssemblyFile)) {
ArchiLogger.LogGenericError(string.Format(Strings.ErrorRemovingOldBinary, oldAssemblyFile));
return;
}
@ -148,11 +164,11 @@ namespace ArchiSteamFarm {
return;
}
string exeFileName = Path.GetFileName(exeFile);
GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => asset.Name.Equals(exeFileName, StringComparison.OrdinalIgnoreCase));
string targetFile = SharedInfo.ASF + "-" + version + ".zip";
GitHub.ReleaseResponse.Asset binaryAsset = releaseResponse.Assets.FirstOrDefault(asset => asset.Name.Equals(targetFile, StringComparison.OrdinalIgnoreCase));
if (binaryAsset == null) {
ArchiLogger.LogGenericWarning(Strings.ErrorUpdateNoAssetForThisBinary);
ArchiLogger.LogGenericWarning(Strings.ErrorUpdateNoAssetForThisVersion);
return;
}
@ -168,42 +184,27 @@ namespace ArchiSteamFarm {
return;
}
string newExeFile = exeFile + ".new";
// Firstly we create new exec
try {
File.WriteAllBytes(newExeFile, result);
File.Move(assemblyFile, oldAssemblyFile);
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
return;
}
// Now we move current -> old
try {
File.Move(exeFile, oldExeFile);
using (ZipArchive zipArchive = new ZipArchive(new MemoryStream(result))) {
UpdateFromArchive(zipArchive);
}
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
try {
// Cleanup
File.Delete(newExeFile);
} catch {
// Ignored
}
return;
}
// Now we move new -> current
try {
File.Move(newExeFile, exeFile);
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
try {
// Cleanup
File.Move(oldExeFile, exeFile);
File.Delete(newExeFile);
File.Move(oldAssemblyFile, assemblyFile);
} catch {
// Ignored
}
return;
}
@ -272,6 +273,23 @@ namespace ArchiSteamFarm {
Bot.RegisterBot(botName);
}
private static bool IsVersionValid(string version) {
if (string.IsNullOrEmpty(version)) {
ArchiLogger.LogNullError(nameof(version));
return false;
}
switch (version) {
case "generic":
case "win-x64":
case "linux-x64":
case "osx-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));
@ -412,6 +430,30 @@ namespace ArchiSteamFarm {
}
}
private static void UpdateFromArchive(ZipArchive archive) {
if (archive == null) {
ArchiLogger.LogNullError(nameof(archive));
return;
}
string targetDirectory = Directory.GetCurrentDirectory();
foreach (ZipArchiveEntry file in archive.Entries) {
string completeFileName = Path.Combine(targetDirectory, file.FullName);
string directory = Path.GetDirectoryName(completeFileName);
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
if (string.IsNullOrEmpty(file.Name) || file.Name.Equals(SharedInfo.GlobalConfigFileName)) {
continue;
}
file.ExtractToFile(completeFileName, true);
}
}
internal sealed class BotConfigEventArgs : EventArgs {
internal readonly BotConfig BotConfig;

View file

@ -955,11 +955,11 @@ namespace ArchiSteamFarm.Localization {
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Could not proceed with update because there is no asset that relates to currently running binary! Please ensure that your ASF binary is named appropriately!.
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Could not proceed with update because there is no asset that relates to currently running version! Automatic update to that version is not possible..
/// </summary>
internal static string ErrorUpdateNoAssetForThisBinary {
internal static string ErrorUpdateNoAssetForThisVersion {
get {
return ResourceManager.GetString("ErrorUpdateNoAssetForThisBinary", resourceCulture);
return ResourceManager.GetString("ErrorUpdateNoAssetForThisVersion", resourceCulture);
}
}

View file

@ -184,8 +184,8 @@ StackTrace:
<data name="ErrorUpdateCheckFailed" xml:space="preserve">
<value>Could not check latest version!</value>
</data>
<data name="ErrorUpdateNoAssetForThisBinary" xml:space="preserve">
<value>Could not proceed with update because there is no asset that relates to currently running binary! Please ensure that your ASF binary is named appropriately!</value>
<data name="ErrorUpdateNoAssetForThisVersion" xml:space="preserve">
<value>Could not proceed with update because there is no asset that relates to currently running version! Automatic update to that version is not possible.</value>
</data>
<data name="ErrorUpdateNoAssets" xml:space="preserve">
<value>Could not proceed with an update because that version doesn't include any assets!</value>

View file

@ -181,7 +181,10 @@ namespace ArchiSteamFarm {
ParsePostInitArgs(args);
}
await ASF.CheckForUpdate().ConfigureAwait(false);
if (!Debugging.IsDebugBuild) {
await ASF.CheckForUpdate().ConfigureAwait(false);
}
await ASF.InitBots().ConfigureAwait(false);
ASF.InitEvents();
}

View file

@ -30,15 +30,16 @@ namespace ArchiSteamFarm {
internal const ulong ArchiSteamID = 76561198006963719;
internal const string ASF = "ASF";
internal const ulong ASFGroupSteamID = 103582791440160998;
internal const string AssemblyName = "ArchiSteamFarm";
internal const string ConfigDirectory = "config";
internal const string DebugDirectory = "debug";
internal const string GithubReleaseURL = "https://api.github.com/repos/" + GithubRepo + "/releases"; // GitHub API is HTTPS only
internal const string GithubRepo = "JustArchi/ArchiSteamFarm";
internal const string GithubRepo = "JustArchi/" + AssemblyName;
internal const string GlobalConfigFileName = ASF + ".json";
internal const string GlobalDatabaseFileName = ASF + ".db";
internal const string LogFile = "log.txt";
internal const string ServiceName = "ArchiSteamFarm";
internal const string StatisticsServer = "asf.justarchi.net";
internal const string VersionFile = AssemblyName + ".version";
internal static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version;
}

View file

@ -58,7 +58,7 @@ namespace ArchiSteamFarm {
};
// Most web services expect that UserAgent is set, so we declare it globally
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(SharedInfo.ServiceName + "/" + SharedInfo.Version);
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(SharedInfo.AssemblyName + "/" + SharedInfo.Version);
}
internal static void Init() {

View file

@ -26,7 +26,7 @@ after_build:
if ($env:APPVEYOR_REPO_TAG -eq 'true') {
$ZIP_ARGS = '-mx=9', '-md=27', '-mfb=273', '-mmc=1000000000'
$ZIP_ARGS = '-mx=9', '-mfb=257', '-mpass=15'
} else {
$ZIP_ARGS = '-mx=1'
}
@ -39,13 +39,15 @@ after_build:
dotnet publish -c "$env:CONFIGURATION" -r "$RUNTIME" -o "out\$RUNTIME"
}
7z a -bd -tzip -mm=LZMA $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"
Add-Content "out\$RUNTIME\ASF.version" "$RUNTIME"
7z a -bd -tzip -mm=Deflate64 $ZIP_ARGS "ASF\out\ASF-$RUNTIME.zip" "$env:APPVEYOR_BUILD_FOLDER\ASF\out\$RUNTIME\*"
Push-AppveyorArtifact "ASF\out\ASF-$RUNTIME.zip" -FileName "ASF-$RUNTIME.zip" -DeploymentName "ASF-$RUNTIME.zip"
}
deploy:
- provider: GitHub
tag: $(appveyor_repo_tag_name)
release: ArchiSteamFarm V$(appveyor_repo_tag_name)
release: ASF V$(appveyor_repo_tag_name)
description: '**NOTICE:** Pre-releases are experimental versions that often contain unpatched bugs, work-in-progress features or rewritten implementations. If you don''t consider yourself advanced user, please download **[latest stable release](https://github.com/JustArchi/ArchiSteamFarm/releases/latest)** instead. Pre-release versions are dedicated to users who know how to report bugs, deal with issues and give feedback - no technical support will be given. Check out ASF **[release cycle](https://github.com/JustArchi/ArchiSteamFarm/wiki/Release-cycle)** if you''d like to learn more.\n\n---\n\nThis is automated AppVeyor GitHub deployment, human-readable changelog should be available soon. In the meantime please refer to **[GitHub commits](https://github.com/JustArchi/ArchiSteamFarm/commits/$(appveyor_repo_tag_name))**.\n\n---\n\nASF is available for free. If you''re grateful for what we''re doing, please consider donating. Developing ASF requires massive amount of time and knowledge, especially when it comes to Steam (and its problems). Even 1$ is highly appreciated and shows that you care!\n\n [![Patreon support](https://img.shields.io/badge/Patreon-support-yellow.svg)](https://www.patreon.com/JustArchi) [![Paypal.me donate](https://img.shields.io/badge/Paypal.me-donate-yellow.svg)](https://www.paypal.me/JustArchi/1usd) [![Paypal donate](https://img.shields.io/badge/Paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HD2P2P3WGS5Y4) [![Bitcoin donate](https://img.shields.io/badge/Bitcoin-donate-yellow.svg)](https://blockchain.info/payment_request?address=1Archi6M1r5b41Rvn1SY2FfJAzsrEUT7aT) [![Steam donate](https://img.shields.io/badge/Steam-donate-yellow.svg)](https://steamcommunity.com/tradeoffer/new/?partner=46697991&token=0ix2Ruv_)'
auth_token:
secure: QC5gIDMvSpd43EG6qW8d1E3ZHiVU4aR7pbKQonXstjj/JtAABf5S1IbtoY4OsnOR