Skip to content

Commit 0c58275

Browse files
committed
reduce warnings
1 parent 1820d90 commit 0c58275

File tree

9 files changed

+36
-26
lines changed

9 files changed

+36
-26
lines changed

SourceServerManager/Converters/BoolToColorConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SourceServerManager.Converters;
77

88
public class BoolToColorConverter : IValueConverter
99
{
10-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1111
{
1212
if (value is bool isOnline)
1313
{
@@ -17,7 +17,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1717
return new SolidColorBrush(Colors.Gray);
1818
}
1919

20-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
2121
{
2222
throw new NotImplementedException();
2323
}

SourceServerManager/Converters/BoolToStatusConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SourceServerManager.Converters;
66

77
public class BoolToStatusConverter : IValueConverter
88
{
9-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
9+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1010
{
1111
if (value is bool isOnline)
1212
{
@@ -16,7 +16,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1616
return "Unknown";
1717
}
1818

19-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
2020
{
2121
throw new NotImplementedException();
2222
}

SourceServerManager/Converters/EnumToIntConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace SourceServerManager.Converters;
66

77
public class EnumToIntConverter : IValueConverter
88
{
9-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
9+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1010
{
1111
if (value is Enum)
1212
return (int)value;
1313
return 0;
1414
}
1515

16-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
16+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
1717
{
1818
if (value is int intValue && targetType.IsEnum)
1919
return Enum.ToObject(targetType, intValue);
20-
return Enum.GetValues(targetType).GetValue(0);
20+
return Enum.GetValues(targetType).GetValue(0) ?? 0;
2121
}
2222
}

SourceServerManager/Models/ServerConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ public class ServerConfig : INotifyPropertyChanged
2323
private string _currentMap = string.Empty;
2424
private string _serverHostname = string.Empty;
2525

26-
public event PropertyChangedEventHandler PropertyChanged;
26+
public event PropertyChangedEventHandler? PropertyChanged;
2727

2828
public enum FileTransferProtocol
2929
{
3030
FTP,
3131
SFTP
3232
}
3333

34-
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
34+
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
3535
{
3636
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
3737
}
3838

39-
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
39+
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
4040
{
4141
if (Equals(field, value)) return false;
4242
field = value;

SourceServerManager/Services/ServerConfigurationService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ServerConfigurationService
1313
private readonly string _configFilePath;
1414
private readonly JsonSerializerOptions _jsonOptions;
1515

16-
public ServerConfigurationService(string configFilePath = null)
16+
public ServerConfigurationService(string? configFilePath = null)
1717
{
1818
// Use default path if none specified
1919
_configFilePath = configFilePath ?? Path.Combine(
@@ -23,7 +23,11 @@ public ServerConfigurationService(string configFilePath = null)
2323
);
2424

2525
// Create directory if it doesn't exist
26-
Directory.CreateDirectory(Path.GetDirectoryName(_configFilePath));
26+
var configDir = Path.GetDirectoryName(_configFilePath);
27+
if (!string.IsNullOrEmpty(configDir))
28+
{
29+
Directory.CreateDirectory(configDir);
30+
}
2731

2832
// Configure JSON serialization options
2933
_jsonOptions = new JsonSerializerOptions

SourceServerManager/Services/ServerStatusService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task UpdateServerInfoAsync(ServerConfig server)
6161
}
6262

6363
// Try to get server info
64-
InfoResponse serverInfo = null;
64+
InfoResponse? serverInfo = null;
6565

6666
try
6767
{

SourceServerManager/SourceServerManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9+
<NoWarn>$(NoWarn);CA1416</NoWarn>
910
</PropertyGroup>
1011

1112
<ItemGroup>

SourceServerManager/ViewModels/MainWindowViewModel.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class MainWindowViewModel : ViewModelBase
1818
private readonly RconService _rconService;
1919
private readonly FtpService _ftpService;
2020
private readonly SftpService _sftpService;
21-
private FilesService _filesService;
21+
private FilesService? _filesService;
2222
private readonly ServerConfigurationService _configService;
2323
private readonly ServerStatusService _statusService;
2424
private readonly CommandHistoryService _commandHistoryService;
2525
private readonly Timer _statusUpdateTimer;
26-
private ServerConfig _serverBeingEdited;
26+
private ServerConfig? _serverBeingEdited;
2727
private readonly Timer _statusClearTimer;
2828
private readonly object _statusLock = new();
2929

@@ -71,8 +71,8 @@ public string RemoteBrowsePath
7171
set => this.RaiseAndSetIfChanged(ref _remoteBrowsePath, value);
7272
}
7373

74-
private ServerConfig _selectedServer;
75-
public ServerConfig SelectedServer
74+
private ServerConfig? _selectedServer;
75+
public ServerConfig? SelectedServer
7676
{
7777
get => _selectedServer;
7878
set => this.RaiseAndSetIfChanged(ref _selectedServer, value);
@@ -199,7 +199,7 @@ private async Task<string> ListDirectoryWithCorrectServiceAsync(ServerConfig ser
199199
}
200200
}
201201

202-
private void ClearStatusCallback(object state)
202+
private void ClearStatusCallback(object? state)
203203
{
204204
Dispatcher.UIThread.Post(() =>
205205
{
@@ -323,13 +323,16 @@ private void SaveServerEdit()
323323
// Exit edit mode
324324
IsEditingServer = false;
325325

326-
UpdateStatus($"Server configuration saved: {SelectedServer.DisplayName}");
326+
UpdateStatus($"Server configuration saved: {SelectedServer?.DisplayName ?? "Unknown"}");
327327

328328
// Save the configuration
329329
Task.Run(SaveConfigAsync);
330330

331331
// Try to update server status
332-
Task.Run(async () => await _statusService.UpdateServerInfoAsync(SelectedServer));
332+
if (SelectedServer != null)
333+
{
334+
Task.Run(async () => await _statusService.UpdateServerInfoAsync(SelectedServer));
335+
}
333336
}
334337

335338
private void CancelEdit()

SourceServerManager/Views/MainWindow.axaml.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace SourceServerManager.Views;
1010

1111
public partial class MainWindow : Window
1212
{
13-
private TextBox _rconConsoleTextBox;
14-
private TextBox _ftpConsoleTextBox;
13+
private TextBox? _rconConsoleTextBox;
14+
private TextBox? _ftpConsoleTextBox;
1515
private string _lastRconConsoleText = string.Empty;
1616
private string _lastFtpConsoleText = string.Empty;
1717

@@ -33,19 +33,21 @@ private void MainWindow_Opened(object? sender, EventArgs e)
3333
}
3434
}
3535

36-
private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
36+
private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
3737
{
3838
if (e.PropertyName == nameof(MainWindowViewModel.RconConsoleOutput))
3939
{
40-
ScrollToEnd(_rconConsoleTextBox, ((MainWindowViewModel)DataContext).RconConsoleOutput);
40+
if (DataContext is MainWindowViewModel vm)
41+
ScrollToEnd(_rconConsoleTextBox, vm.RconConsoleOutput);
4142
}
4243
else if (e.PropertyName == nameof(MainWindowViewModel.FtpConsoleOutput))
4344
{
44-
ScrollToEnd(_ftpConsoleTextBox, ((MainWindowViewModel)DataContext).FtpConsoleOutput);
45+
if (DataContext is MainWindowViewModel vm)
46+
ScrollToEnd(_ftpConsoleTextBox, vm.FtpConsoleOutput);
4547
}
4648
}
4749

48-
private void ScrollToEnd(TextBox textBox, string text)
50+
private void ScrollToEnd(TextBox? textBox, string text)
4951
{
5052
Dispatcher.UIThread.Post(() =>
5153
{

0 commit comments

Comments
 (0)