Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Documentation/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# System-Wide Configuration

This directory contains an example `config.json` file that can be placed in the application installation directory to override user settings for all users on a machine.

## Usage

1. Copy the example configuration file to the NETworkManager installation directory (where `NETworkManager.exe` is located)
2. Rename `config.json.example` to `config.json`
3. Edit the settings as needed
4. Restart NETworkManager

## Configuration Options

### Update_DisableUpdateCheck

When set to `true`, disables the automatic update check at startup for all users.

**Example:**
```json
{
"Update_DisableUpdateCheck": true
}
```

This is useful for enterprise deployments where you want to:
- Control software updates centrally
- Prevent users from being prompted about updates
- Disable update checks on multiple machines without user intervention

## File Location

The `config.json` file should be placed in:
- **Installed version**: `C:\Program Files\NETworkManager\` (or your custom installation path)
- **Portable version**: Same directory as `NETworkManager.exe`

## Notes

- System-wide configuration takes precedence over user settings
- If the file doesn't exist or contains invalid JSON, it will be ignored and default user settings will apply
- Changes to `config.json` require restarting the application to take effect
- The file is optional - if not present, user settings will be used as normal
3 changes: 3 additions & 0 deletions Documentation/config/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Update_DisableUpdateCheck": true
}
17 changes: 17 additions & 0 deletions Source/NETworkManager.Settings/PolicyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;

namespace NETworkManager.Settings;

/// <summary>
/// Class that represents system-wide policies that override user settings.
/// This configuration is loaded from a config.json file in the application directory.
/// </summary>
public class PolicyInfo
{
/// <summary>
/// Disable update check for all users. When set to true, the application will not check for updates at startup.
/// This overrides the user's "Update_CheckForUpdatesAtStartup" setting.
/// </summary>
[JsonPropertyName("Update_DisableUpdateCheck")]
public bool? Update_DisableUpdateCheck { get; set; }
}
95 changes: 95 additions & 0 deletions Source/NETworkManager.Settings/PolicyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using log4net;
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace NETworkManager.Settings;

/// <summary>
/// Manager for system-wide policies that are loaded from a config.json file
/// in the application directory. These policies override user settings.
/// </summary>
public static class PolicyManager
{
#region Variables

/// <summary>
/// Logger for logging.
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(PolicyManager));

/// <summary>
/// Config file name.
/// </summary>
private static string ConfigFileName => "config.json";

/// <summary>
/// System-wide policies that are currently loaded.
/// </summary>
public static PolicyInfo Current { get; private set; }

/// <summary>
/// JSON serializer options for consistent serialization/deserialization.
/// </summary>
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true,
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverter() }
};

#endregion

#region Methods

/// <summary>
/// Method to get the config file path in the application directory.
/// </summary>
/// <returns>Config file path.</returns>
private static string GetConfigFilePath()
{
return Path.Combine(AssemblyManager.Current.Location, ConfigFileName);
}

/// <summary>
/// Method to load the system-wide policies from config.json file in the application directory.
/// </summary>
public static void Load()
{
var filePath = GetConfigFilePath();

// Check if config file exists
if (File.Exists(filePath))
{
try
{
Log.Info($"Loading system-wide policies from: {filePath}");

var jsonString = File.ReadAllText(filePath);
Current = JsonSerializer.Deserialize<PolicyInfo>(jsonString, JsonOptions);

Log.Info("System-wide policies loaded successfully.");

// Log enabled settings
if (Current.Update_DisableUpdateCheck.HasValue)
{
Log.Info($"System-wide policy - Update_DisableUpdateCheck: {Current.Update_DisableUpdateCheck.Value}");
}
}
catch (Exception ex)
{
Log.Error($"Failed to load system-wide policies from: {filePath}", ex);
Current = new PolicyInfo();
}
}
else
{
Log.Debug($"No system-wide policy file found at: {filePath}");
Current = new PolicyInfo();
}
}

#endregion
}
22 changes: 22 additions & 0 deletions Source/NETworkManager.Settings/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public static class SettingsManager
/// </summary>
public static bool HotKeysChanged { get; set; }

/// <summary>
/// Gets whether update check should be performed at startup.
/// This respects the system-wide policies (config.json) which take precedence over user settings.
/// </summary>
public static bool ShouldCheckForUpdatesAtStartup
{
get
{
// System-wide policy takes precedence - if it explicitly disables updates, honor it
if (PolicyManager.Current?.Update_DisableUpdateCheck == true)
{
return false;
}

// Otherwise, use the user's setting
return Current.Update_CheckForUpdatesAtStartup;
}
}

/// <summary>
/// JSON serializer options for consistent serialization/deserialization.
/// </summary>
Expand Down Expand Up @@ -152,6 +171,9 @@ public static void Initialize()
/// </summary>
public static void Load()
{
// Load system-wide policies first (from app directory)
PolicyManager.Load();

var filePath = GetSettingsFilePath();
var legacyFilePath = GetLegacySettingsFilePath();

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ private void Load()
NetworkChange.NetworkAddressChanged += (_, _) => OnNetworkHasChanged();

// Search for updates...
if (SettingsManager.Current.Update_CheckForUpdatesAtStartup)
if (SettingsManager.ShouldCheckForUpdatesAtStartup)
CheckForUpdates();
}

Expand Down