Fix ProcessStartTime on generic-netf mono

This commit is contained in:
JustArchi
2018-11-09 10:58:05 +01:00
parent 4121768625
commit 7da7d12161
2 changed files with 20 additions and 11 deletions

View File

@@ -20,7 +20,6 @@
// limitations under the License.
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using ArchiSteamFarm.IPC.Requests;
@@ -39,13 +38,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
public ActionResult<GenericResponse<ASFResponse>> ASFGet() {
uint memoryUsage = (uint) GC.GetTotalMemory(false) / 1024;
DateTime processStartTime;
using (Process process = Process.GetCurrentProcess()) {
processStartTime = process.StartTime;
}
ASFResponse result = new ASFResponse(SharedInfo.BuildInfo.Variant, Program.GlobalConfig, memoryUsage, processStartTime, SharedInfo.Version);
ASFResponse result = new ASFResponse(SharedInfo.BuildInfo.Variant, Program.GlobalConfig, memoryUsage, RuntimeCompatibility.ProcessStartTime, SharedInfo.Version);
return Ok(new GenericResponse<ASFResponse>(result));
}

View File

@@ -20,21 +20,37 @@
// limitations under the License.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
#if NETFRAMEWORK
using System.Collections.Generic;
#endif
#if NETFRAMEWORK
using System.Net.WebSockets;
using System.Threading;
#endif
namespace ArchiSteamFarm {
internal static class RuntimeCompatibility {
#if NETFRAMEWORK
private static readonly DateTime SavedProcessStartTime = DateTime.UtcNow;
#endif
internal static bool IsRunningOnMono => Type.GetType("Mono.Runtime") != null;
internal static DateTime ProcessStartTime {
get {
#if NETFRAMEWORK
if (IsRunningOnMono) {
return SavedProcessStartTime;
}
#endif
using (Process process = Process.GetCurrentProcess()) {
return process.StartTime;
}
}
}
#pragma warning disable 1998
internal static class File {
internal static async Task AppendAllTextAsync(string path, string contents) =>