From f07d9002dd219f5563edca6f4741e00aeb2d427f Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Mon, 18 Mar 2019 21:07:15 -0700 Subject: [PATCH] Linux updater (again). --- Remotely_Agent/Services/Updater.cs | 19 ++----- .../Services/RemoteControlSessionRecorder.cs | 56 +++++++++++-------- .../wwwroot/Downloads/CurrentAgentVersion.txt | 2 +- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Remotely_Agent/Services/Updater.cs b/Remotely_Agent/Services/Updater.cs index 2159075b..d12e11a9 100644 --- a/Remotely_Agent/Services/Updater.cs +++ b/Remotely_Agent/Services/Updater.cs @@ -62,18 +62,7 @@ namespace Remotely_Agent.Services if (OSUtils.IsWindows) { ZipFile.ExtractToDirectory(tempFile, tempFolder, true); - } - else if (OSUtils.IsLinux) - { - Process.Start("sudo", "apt-get install unzip").WaitForExit(); - Process.Start("sudo", $"unzip -o {tempFile} -d {tempFolder}").WaitForExit(); - Process.Start("sudo", $"chmod -R 777 {tempFolder}").WaitForExit(); - Process.Start("sudo", $"chmod +x {Path.Combine(Path.GetTempPath(), "Remotely_Update", "Remotely_Agent")}").WaitForExit(); - } - - Logger.Write($"Service Updater: Launching extracted process to perform update."); - if (OSUtils.IsWindows) - { + Logger.Write($"Service Updater: Launching extracted process to perform update."); var psi = new ProcessStartInfo() { FileName = Path.Combine(Path.GetTempPath(), "Remotely_Update", OSUtils.ClientExecutableFileName), @@ -84,7 +73,11 @@ namespace Remotely_Agent.Services } else if (OSUtils.IsLinux) { - Process.Start("sudo", $"{Path.Combine(Path.GetTempPath(), "Remotely_Update", "Remotely_Agent")} -update true & disown"); + Process.Start("sudo", "apt-get install unzip").WaitForExit(); + Process.Start("sudo", $"unzip -o {tempFile} -d /usr/local/bin/Remotely/").WaitForExit(); + Process.Start("sudo", "chmod +x /usr/local/bin/Remotely/Remotely_Agent").WaitForExit(); + Logger.Write($"Service Updater: Update complete. Restarting service."); + Process.Start("sudo", "systemctl restart remotely-agent"); } } } diff --git a/Remotely_Server/Services/RemoteControlSessionRecorder.cs b/Remotely_Server/Services/RemoteControlSessionRecorder.cs index 0b5441a6..e6d449f8 100644 --- a/Remotely_Server/Services/RemoteControlSessionRecorder.cs +++ b/Remotely_Server/Services/RemoteControlSessionRecorder.cs @@ -44,38 +44,48 @@ namespace Remotely_Server.Services internal void StartProcessing() { - while (FrameQueue.Count > 0) + try { - if (FrameQueue.TryDequeue(out var frame)) + while (FrameQueue.Count > 0) { - if (!CumulativeFrames.ContainsKey(frame.ViewerID)) + if (FrameQueue.TryDequeue(out var frame)) { - CumulativeFrames[frame.ViewerID] = new Bitmap(frame.Width, frame.Height); - } - - var saveDir = Directory.CreateDirectory(GetSaveFolder(frame)); - - var saveFile = Path.Combine( - saveDir.FullName, - $"frame-{(Directory.GetFiles(saveDir.FullName).Length + 1).ToString()}.jpg"); - - var bitmap = CumulativeFrames[frame.ViewerID] as Bitmap; - using (var graphics = Graphics.FromImage(bitmap)) - { - using (var ms = new MemoryStream(frame.FrameBytes)) + if (!CumulativeFrames.ContainsKey(frame.ViewerID)) { - using (var saveImage = Image.FromStream(ms)) + CumulativeFrames[frame.ViewerID] = new Bitmap(frame.Width, frame.Height); + } + + var saveDir = Directory.CreateDirectory(GetSaveFolder(frame)); + + var saveFile = Path.Combine( + saveDir.FullName, + $"frame-{(Directory.GetFiles(saveDir.FullName).Length + 1).ToString()}.jpg"); + + var bitmap = CumulativeFrames[frame.ViewerID] as Bitmap; + using (var graphics = Graphics.FromImage(bitmap)) + { + using (var ms = new MemoryStream(frame.FrameBytes)) { - graphics.DrawImage(saveImage, frame.Left, frame.Top); + using (var saveImage = Image.FromStream(ms)) + { + graphics.DrawImage(saveImage, frame.Left, frame.Top); + } } } + bitmap.Save(saveFile, ImageFormat.Jpeg); } - bitmap.Save(saveFile, ImageFormat.Jpeg); } } - lock (LockObject) + catch(Exception ex) { - IsProcessing = false; + DataService.WriteEvent(ex); + } + finally + { + lock (LockObject) + { + IsProcessing = false; + } } } @@ -98,8 +108,8 @@ namespace Remotely_Server.Services HostingEnv.ContentRootPath, "Recordings", DateTime.Now.Year.ToString().PadLeft(4, '0'), - DateTime.Now.Month.ToString().PadLeft(2, '0')), - viewerID, + DateTime.Now.Month.ToString().PadLeft(2, '0')), + viewerID, SearchOption.AllDirectories); foreach (var dir in recordingDirs) diff --git a/Remotely_Server/wwwroot/Downloads/CurrentAgentVersion.txt b/Remotely_Server/wwwroot/Downloads/CurrentAgentVersion.txt index 8d1fb540..af09d738 100644 --- a/Remotely_Server/wwwroot/Downloads/CurrentAgentVersion.txt +++ b/Remotely_Server/wwwroot/Downloads/CurrentAgentVersion.txt @@ -1 +1 @@ -2019.03.18.1822 +2019.03.18.2104