Skip to content

Commit

Permalink
Merge pull request #691 from immense/tech/nullable-references
Browse files Browse the repository at this point in the history
Enable nullable references... and other stuff.
  • Loading branch information
bitbound authored Jul 31, 2023
2 parents 7c58b4f + 7a362c9 commit 57b8676
Show file tree
Hide file tree
Showing 200 changed files with 11,478 additions and 3,570 deletions.
2 changes: 2 additions & 0 deletions Agent.Installer.Win/Agent.Installer.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RuntimeIdentifiers>win;win-x64;win10-x64;win-x64;win10-x86;</RuntimeIdentifiers>
Expand Down
13 changes: 6 additions & 7 deletions Agent.Installer.Win/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Windows;

namespace Remotely.Agent.Installer.Win
namespace Remotely.Agent.Installer.Win;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{

}
}
108 changes: 55 additions & 53 deletions Agent.Installer.Win/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,72 @@
using System.Windows.Documents;
using System.Windows.Input;

namespace Remotely.Agent.Installer.Win
namespace Remotely.Agent.Installer.Win;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
if (CommandLineParser.CommandLineArgs.ContainsKey("quiet"))
{
if (CommandLineParser.CommandLineArgs.ContainsKey("quiet"))
{
Hide();
ShowInTaskbar = false;
_ = new MainWindowViewModel().Init();
}
InitializeComponent();
Hide();
ShowInTaskbar = false;
_ = new MainWindowViewModel().Init();
}
InitializeComponent();
}

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}

private async void Window_Loaded(object sender, RoutedEventArgs e)
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
if (DataContext is MainWindowViewModel viewModel)
{
await (DataContext as MainWindowViewModel).Init();
await viewModel.Init();
}
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
}

private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}

private void ShowServerUrlHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"This is the URL of the Remotely server that you're hosting. The device will connect to this URL.",
"Server URL",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void ShowServerUrlHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"This is the URL of the Remotely server that you're hosting. The device will connect to this URL.",
"Server URL",
MessageBoxButton.OK,
MessageBoxImage.Information);
}

private void ShowOrganizationIdHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"This is your organization ID on the Remotely server. Since Remotely supports multi-tenancy, " +
"this ID needs to be provided to determine who should have access."
+ Environment.NewLine + Environment.NewLine +
"You can find this ID on the Organization tab on the web app.",
"Organization ID",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void ShowSupportShortcutHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show("If selected, the installer will create a desktop shortcut to the Get Support page for this device.",
"Support Shortcut",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void ShowOrganizationIdHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"This is your organization ID on the Remotely server. Since Remotely supports multi-tenancy, " +
"this ID needs to be provided to determine who should have access."
+ Environment.NewLine + Environment.NewLine +
"You can find this ID on the Organization tab on the web app.",
"Organization ID",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void ShowSupportShortcutHelp(object sender, RoutedEventArgs e)
{
MessageBox.Show("If selected, the installer will create a desktop shortcut to the Get Support page for this device.",
"Support Shortcut",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
}
35 changes: 15 additions & 20 deletions Agent.Installer.Win/Models/BrandingInfo.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#nullable enable

namespace Remotely.Agent.Installer.Win.Models
namespace Remotely.Agent.Installer.Win.Models;

public class BrandingInfo
{
public class BrandingInfo
{
public string Product { get; set; } = "Remotely";
public string Product { get; set; } = "Remotely";

public string Icon { get; set; }
public string? Icon { get; set; }

public byte TitleForegroundRed { get; set; } = 29;
public byte TitleForegroundRed { get; set; } = 29;

public byte TitleForegroundGreen { get; set; } = 144;
public byte TitleForegroundGreen { get; set; } = 144;

public byte TitleForegroundBlue { get; set; } = 241;
public byte TitleForegroundBlue { get; set; } = 241;

public byte TitleBackgroundRed { get; set; } = 70;
public byte TitleBackgroundRed { get; set; } = 70;

public byte TitleBackgroundGreen { get; set; } = 70;
public byte TitleBackgroundGreen { get; set; } = 70;

public byte TitleBackgroundBlue { get; set; } = 70;
public byte TitleBackgroundBlue { get; set; } = 70;

public byte ButtonForegroundRed { get; set; } = 255;
public byte ButtonForegroundRed { get; set; } = 255;

public byte ButtonForegroundGreen { get; set; } = 255;
public byte ButtonForegroundGreen { get; set; } = 255;

public byte ButtonForegroundBlue { get; set; } = 255;
}
public byte ButtonForegroundBlue { get; set; } = 255;
}
42 changes: 18 additions & 24 deletions Agent.Installer.Win/Models/EmbeddedServerData.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Remotely.Agent.Installer.Models
namespace Remotely.Agent.Installer.Models;

[DataContract]
public class EmbeddedServerData
{
[DataContract]
public class EmbeddedServerData
{
/// <summary>
/// Parameterless constructor for JsonSerializer.
/// </summary>
public EmbeddedServerData() { }
/// <summary>
/// Parameterless constructor for JsonSerializer.
/// </summary>
public EmbeddedServerData() { }

public EmbeddedServerData(Uri serverUrl, string organizationId)
{
ServerUrl = serverUrl;
OrganizationId = organizationId;
}
public EmbeddedServerData(Uri serverUrl, string organizationId)
{
ServerUrl = serverUrl;
OrganizationId = organizationId;
}

public static EmbeddedServerData Empty { get; } = new EmbeddedServerData();
public static EmbeddedServerData Empty { get; } = new EmbeddedServerData();

[DataMember]
public string OrganizationId { get; set; } = string.Empty;
[DataMember]
public string OrganizationId { get; set; } = string.Empty;

[DataMember]
public Uri ServerUrl { get; set; }
}
[DataMember]
public Uri ServerUrl { get; set; }
}
93 changes: 46 additions & 47 deletions Agent.Installer.Win/Services/EmbeddedServerDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,75 @@
using Remotely.Agent.Installer.Win.Utilities;
using Remotely.Shared;

namespace Remotely.Agent.Installer.Win.Services
namespace Remotely.Agent.Installer.Win.Services;

internal class EmbeddedServerDataReader
{
internal class EmbeddedServerDataReader
{
private readonly JavaScriptSerializer _serializer = new JavaScriptSerializer();
private readonly JavaScriptSerializer _serializer = new JavaScriptSerializer();

public Task<EmbeddedServerData> TryGetEmbeddedData(string filePath)
public Task<EmbeddedServerData> TryGetEmbeddedData(string filePath)
{
try
{
try
if (!File.Exists(filePath))
{
if (!File.Exists(filePath))
throw new Exception($"File path does not exist: {filePath}");
}

using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature);
if (result == -1)
{
throw new Exception($"File path does not exist: {filePath}");
throw new Exception("Signature not found in file buffer.");
}

using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
Logger.Write($"Found data signature at index {result}.");

fs.Seek(result + AppConstants.EmbeddedImmySignature.Length, SeekOrigin.Begin);
using (var reader = new BinaryReader(fs, Encoding.UTF8))
{
var result = SearchBuffer(fs, AppConstants.EmbeddedImmySignature);
if (result == -1)
{
throw new Exception("Signature not found in file buffer.");
}
var serializedData = reader.ReadString();

Logger.Write($"Found data signature at index {result}.");
Logger.Write($"Extracted embedded data from EXE: {serializedData}");

fs.Seek(result + AppConstants.EmbeddedImmySignature.Length, SeekOrigin.Begin);
using (var reader = new BinaryReader(fs, Encoding.UTF8))
var embeddedData = _serializer.Deserialize<EmbeddedServerData>(serializedData);
if (embeddedData != null)
{
var serializedData = reader.ReadString();

Logger.Write($"Extracted embedded data from EXE: {serializedData}");

var embeddedData = _serializer.Deserialize<EmbeddedServerData>(serializedData);
if (embeddedData != null)
{
return Task.FromResult(embeddedData);
}
return Task.FromResult(embeddedData);
}
}
}
catch (Exception ex)
{
Logger.Write(ex);
}
return Task.FromResult(EmbeddedServerData.Empty);
}
catch (Exception ex)
{
Logger.Write(ex);
}
return Task.FromResult(EmbeddedServerData.Empty);
}

private long SearchBuffer(FileStream fileStream, byte[] matchPattern)
private long SearchBuffer(FileStream fileStream, byte[] matchPattern)
{
var matchSize = matchPattern.Length;
var limit = fileStream.Length - matchSize;

for (var i = 0; i <= limit; i++)
{
var matchSize = matchPattern.Length;
var limit = fileStream.Length - matchSize;
var k = 0;

for (var i = 0; i <= limit; i++)
for (; k < matchSize; k++)
{
var k = 0;

for (; k < matchSize; k++)
if (matchPattern[k] != fileStream.ReadByte())
{
if (matchPattern[k] != fileStream.ReadByte())
{
break;
}
break;
}
}

if (k == matchSize)
{
return fileStream.Position - matchSize;
}
if (k == matchSize)
{
return fileStream.Position - matchSize;
}
return -1;
}
return -1;
}
}
Loading

0 comments on commit 57b8676

Please sign in to comment.