From 5ab7cf5af77339a09cd67a92e4db2e54b2eed039 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Fri, 29 Mar 2019 09:17:16 -0700 Subject: [PATCH] Fixed line endings on sh scripts. Removed test code. Refactored ScreenCaster method. --- Remotely_Agent/Services/Logger.cs | 11 +++- Remotely_Desktop/App.xaml.cs | 1 + Remotely_Desktop/Remotely_Desktop.csproj | 1 - Remotely_Desktop/Services/Logger.cs | 66 ------------------- .../ViewModels/MainWindowViewModel.cs | 3 +- .../Capture/ScreenCaster.cs | 9 ++- Remotely_ScreenCast.Core/Utilities/Logger.cs | 20 +++++- Remotely_ScreenCast.Linux/Program.cs | 3 +- Remotely_ScreenCast.Win/Program.cs | 2 +- Remotely_Server/CurrentVersion.txt | 2 +- Utilities/Remotely_Server_Install.sh | 3 + 11 files changed, 42 insertions(+), 79 deletions(-) delete mode 100644 Remotely_Desktop/Services/Logger.cs diff --git a/Remotely_Agent/Services/Logger.cs b/Remotely_Agent/Services/Logger.cs index 549c0d0c..597b9144 100644 --- a/Remotely_Agent/Services/Logger.cs +++ b/Remotely_Agent/Services/Logger.cs @@ -1,8 +1,10 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -13,7 +15,14 @@ namespace Remotely_Agent.Services public static void Write(string message) { var path = Path.Combine(Path.GetTempPath(), "Remotely_Logs.txt"); - + if (!File.Exists(path)) + { + File.Create(path).Close(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("sudo", $"chmod 666 {path}").WaitForExit(); + } + } var jsoninfo = new { Type = "Info", diff --git a/Remotely_Desktop/App.xaml.cs b/Remotely_Desktop/App.xaml.cs index 445c2c3d..167d1921 100644 --- a/Remotely_Desktop/App.xaml.cs +++ b/Remotely_Desktop/App.xaml.cs @@ -1,5 +1,6 @@ using Remotely_Desktop.Services; using Remotely_Desktop.ViewModels; +using Remotely_ScreenCast.Core.Utilities; using System; using System.Collections.Generic; using System.Configuration; diff --git a/Remotely_Desktop/Remotely_Desktop.csproj b/Remotely_Desktop/Remotely_Desktop.csproj index 442c6c71..c86c4bd0 100644 --- a/Remotely_Desktop/Remotely_Desktop.csproj +++ b/Remotely_Desktop/Remotely_Desktop.csproj @@ -80,7 +80,6 @@ HostNamePrompt.xaml - diff --git a/Remotely_Desktop/Services/Logger.cs b/Remotely_Desktop/Services/Logger.cs deleted file mode 100644 index a79d12de..00000000 --- a/Remotely_Desktop/Services/Logger.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Remotely_Desktop.Services -{ - public static class Logger - { - public static void Write(string message) - { - var path = Path.Combine(Path.GetTempPath(), "Remotely_Logs.txt"); - - var jsoninfo = new - { - Type = "Info", - Timestamp = DateTime.Now.ToString(), - Message = message - }; - if (File.Exists(path)) - { - var fi = new FileInfo(path); - while (fi.Length > 1000000) - { - var content = File.ReadAllLines(path); - File.WriteAllLines(path, content.Skip(10)); - fi = new FileInfo(path); - } - } - File.AppendAllText(path, JsonConvert.SerializeObject(jsoninfo) + Environment.NewLine); - } - - public static void Write(Exception ex) - { - var exception = ex; - var path = Path.Combine(Path.GetTempPath(), "Remotely_Logs.txt"); - - while (exception != null) - { - var jsonError = new - { - Type = "Error", - Timestamp = DateTime.Now.ToString(), - Message = exception?.Message, - Source = exception?.Source, - StackTrace = exception?.StackTrace, - }; - if (File.Exists(path)) - { - var fi = new FileInfo(path); - while (fi.Length > 1000000) - { - var content = File.ReadAllLines(path); - File.WriteAllLines(path, content.Skip(10)); - fi = new FileInfo(path); - } - } - File.AppendAllText(path, JsonConvert.SerializeObject(jsonError) + Environment.NewLine); - exception = exception.InnerException; - } - } - } -} diff --git a/Remotely_Desktop/ViewModels/MainWindowViewModel.cs b/Remotely_Desktop/ViewModels/MainWindowViewModel.cs index f96eb905..aea50e41 100644 --- a/Remotely_Desktop/ViewModels/MainWindowViewModel.cs +++ b/Remotely_Desktop/ViewModels/MainWindowViewModel.cs @@ -3,6 +3,7 @@ using Remotely_Desktop.Services; using Remotely_ScreenCast.Core; using Remotely_ScreenCast.Core.Capture; using Remotely_ScreenCast.Core.Models; +using Remotely_ScreenCast.Core.Utilities; using Remotely_ScreenCast.Win; using Remotely_ScreenCast.Win.Capture; using Remotely_ScreenCast.Win.Input; @@ -177,7 +178,7 @@ namespace Remotely_Desktop.ViewModels capturer = new BitBltCapture(); } await Conductor.OutgoingMessages.SendCursorChange(CursorIconWatcher.GetCurrentCursor(), new List() { viewerAndRequester.Item1 }); - ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, Conductor.OutgoingMessages, capturer, Conductor); + ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, capturer, Conductor); }); } }); diff --git a/Remotely_ScreenCast.Core/Capture/ScreenCaster.cs b/Remotely_ScreenCast.Core/Capture/ScreenCaster.cs index c257804c..6fd28776 100644 --- a/Remotely_ScreenCast.Core/Capture/ScreenCaster.cs +++ b/Remotely_ScreenCast.Core/Capture/ScreenCaster.cs @@ -16,7 +16,6 @@ namespace Remotely_ScreenCast.Core.Capture { public static async void BeginScreenCasting(string viewerID, string requesterName, - OutgoingMessages outgoingMessages, ICapturer capturer, Conductor conductor) { @@ -46,16 +45,16 @@ namespace Remotely_ScreenCast.Core.Capture conductor.ViewerAdded?.Invoke(null, viewer); } - await outgoingMessages.SendScreenCount( + await conductor.OutgoingMessages.SendScreenCount( capturer.SelectedScreen, capturer.GetScreenCount(), viewerID); - await outgoingMessages.SendScreenSize(capturer.CurrentScreenBounds.Width, capturer.CurrentScreenBounds.Height, viewerID); + await conductor.OutgoingMessages.SendScreenSize(capturer.CurrentScreenBounds.Width, capturer.CurrentScreenBounds.Height, viewerID); capturer.ScreenChanged += async (sender, bounds) => { - await outgoingMessages.SendScreenSize(bounds.Width, bounds.Height, viewerID); + await conductor.OutgoingMessages.SendScreenSize(bounds.Width, bounds.Height, viewerID); }; // TODO: SetThradDesktop causes issues with input after switching. @@ -124,7 +123,7 @@ namespace Remotely_ScreenCast.Core.Capture if (encodedImageBytes?.Length > 0) { - await outgoingMessages.SendScreenCapture(encodedImageBytes, viewerID, diffArea.Left, diffArea.Top, diffArea.Width, diffArea.Height, DateTime.UtcNow); + await conductor.OutgoingMessages.SendScreenCapture(encodedImageBytes, viewerID, diffArea.Left, diffArea.Top, diffArea.Width, diffArea.Height, DateTime.UtcNow); viewer.PendingFrames++; } // TODO: Even after disposing of the bitmap, GC doesn't collect in time. Memory usage soars quickly. diff --git a/Remotely_ScreenCast.Core/Utilities/Logger.cs b/Remotely_ScreenCast.Core/Utilities/Logger.cs index 4be74a50..054cf215 100644 --- a/Remotely_ScreenCast.Core/Utilities/Logger.cs +++ b/Remotely_ScreenCast.Core/Utilities/Logger.cs @@ -1,8 +1,10 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -13,7 +15,14 @@ namespace Remotely_ScreenCast.Core.Utilities public static void Write(string message) { var path = Path.Combine(Path.GetTempPath(), "Remotely_Logs.txt"); - + if (!File.Exists(path)) + { + File.Create(path).Close(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("sudo", $"chmod 666 {path}").WaitForExit(); + } + } var jsoninfo = new { Type = "Info", @@ -48,6 +57,15 @@ namespace Remotely_ScreenCast.Core.Utilities var exception = ex; var path = Path.Combine(Path.GetTempPath(), "Remotely_Logs.txt"); + if (!File.Exists(path)) + { + File.Create(path).Close(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("sudo", $"chmod 666 {path}").WaitForExit(); + } + } + while (exception != null) { var jsonError = new diff --git a/Remotely_ScreenCast.Linux/Program.cs b/Remotely_ScreenCast.Linux/Program.cs index ec1bb759..6ad2f7e4 100644 --- a/Remotely_ScreenCast.Linux/Program.cs +++ b/Remotely_ScreenCast.Linux/Program.cs @@ -19,7 +19,6 @@ namespace Remotely_ScreenCast.Linux { try { - ScreenCastInitiated(null, new Tuple("asdf", "asdf")); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Conductor = new Conductor(); Conductor.ProcessArgs(args); @@ -49,7 +48,7 @@ namespace Remotely_ScreenCast.Linux { capturer = new X11Capture(); //await Conductor.OutgoingMessages.SendCursorChange(CursorIconWatcher.GetCurrentCursor(), new List() { viewerAndRequester.Item1 }); - ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, Conductor.OutgoingMessages, capturer, Conductor); + ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, capturer, Conductor); } catch (Exception ex) { diff --git a/Remotely_ScreenCast.Win/Program.cs b/Remotely_ScreenCast.Win/Program.cs index 07203327..45cb3127 100644 --- a/Remotely_ScreenCast.Win/Program.cs +++ b/Remotely_ScreenCast.Win/Program.cs @@ -89,7 +89,7 @@ namespace Remotely_ScreenCast.Win capturer = new BitBltCapture(); } await Conductor.OutgoingMessages.SendCursorChange(CursorIconWatcher.GetCurrentCursor(), new List() { viewerAndRequester.Item1 }); - ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, Conductor.OutgoingMessages, capturer, Conductor); + ScreenCaster.BeginScreenCasting(viewerAndRequester.Item1, viewerAndRequester.Item2, capturer, Conductor); } public static async void CursorIconWatcher_OnChange(object sender, CursorInfo cursor) diff --git a/Remotely_Server/CurrentVersion.txt b/Remotely_Server/CurrentVersion.txt index 53221c22..e0ea3820 100644 --- a/Remotely_Server/CurrentVersion.txt +++ b/Remotely_Server/CurrentVersion.txt @@ -1 +1 @@ -2019.03.28.1441 +2019.03.29.0908 diff --git a/Utilities/Remotely_Server_Install.sh b/Utilities/Remotely_Server_Install.sh index ddb8f74b..0e7c051c 100644 --- a/Utilities/Remotely_Server_Install.sh +++ b/Utilities/Remotely_Server_Install.sh @@ -6,6 +6,8 @@ The output directory is the app root path. This would typically be in /var/www/[ read -p "Enter app root path: " appRoot read -p "Enter server host (e.g. example.com): " serverHost +apt-get install acl + setfacl -R -m u:www-data:rwx $appRoot # Install .NET Core Runtime. @@ -17,6 +19,7 @@ apt-get update apt-get install -y aspnetcore-runtime-2.2 rm packages-microsoft-prod.deb + # Install Nginx apt-get update apt-get install -y nginx