Skip to content

Commit b9a3c89

Browse files
committed
Clean warnings
1 parent 5b0567d commit b9a3c89

File tree

8 files changed

+82
-36
lines changed

8 files changed

+82
-36
lines changed

Keys/KeyForm.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void LoadConent(bool force = false)
134134

135135
protected void OnCreatePublicKeyButtonClick(object? sender, EventArgs e)
136136
{
137-
if (Key == null)
137+
if (Key == null || Key.Filename == null)
138138
{
139139
MessageBox.Show("Ключ не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
140140
return;
@@ -147,7 +147,7 @@ protected void OnCreatePublicKeyButtonClick(object? sender, EventArgs e)
147147
}
148148
protected void OnRemoveKeyButtonClick(object? sender, EventArgs e)
149149
{
150-
if (Key == null)
150+
if (Key == null || Key.Filename == null)
151151
{
152152
MessageBox.Show("Ключ не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
153153
return;
@@ -170,6 +170,11 @@ protected void OnContentTableCellDoubleClick(object? sender, DataGridViewCellEve
170170
string? name = ContentTable.Rows[e.RowIndex].Cells[0].Value.ToString();
171171
string? value = ContentTable.Rows[e.RowIndex].Cells[1].Value.ToString();
172172

173+
if (string.IsNullOrWhiteSpace(value))
174+
{
175+
return;
176+
}
177+
173178
try
174179
{
175180
Clipboard.SetText(value);

Keys/KeyObject.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace RishWinTools.Keys
99
{
1010
public class KeyObject
1111
{
12-
public string Filename;
13-
public string Path;
14-
public string PublicKey;
15-
public string PublicKeyPath;
16-
public string ServerCommand;
12+
public string? Filename;
13+
public string? Path;
14+
public string? PublicKey;
15+
public string? PublicKeyPath;
16+
public string? ServerCommand;
1717
public bool KeyExist = false;
1818

19-
public KeyObject(string fileName = null)
19+
public KeyObject(string? fileName = null)
2020
{
2121
Path = "";
2222
if (fileName == null)

Keys/KeysTab.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected void OnCreateButtonClick(object? sender, EventArgs e)
168168
protected void OnInsertButtonClick(object? sender, EventArgs e)
169169
{
170170
using (InsertKeyForm insertKeyForm = new InsertKeyForm())
171-
{
171+
{
172172
if (insertKeyForm.ShowDialog(this) == DialogResult.OK)
173173
{
174174
LoadConent(true);
@@ -206,7 +206,11 @@ protected void OnContentTableCellDoubleClick(object? sender, DataGridViewCellEve
206206
return;
207207
}
208208

209-
string keyName = ContentTable.Rows[e.RowIndex].Cells[0].Value.ToString();
209+
string? keyName = ContentTable.Rows[e.RowIndex].Cells[0].Value.ToString();
210+
if (keyName == null || String.IsNullOrEmpty(keyName))
211+
{
212+
return;
213+
}
210214

211215
using (KeyForm keyForm = new KeyForm(keyName))
212216
{

Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ namespace RishWinTools
22
{
33
internal static class Program
44
{
5-
public static string SSHFolderPath { get; private set; }
5+
public static string SSHFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh");
66

77
[STAThread]
88
static void Main()
9-
{
10-
SSHFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh");
9+
{
1110
ApplicationConfiguration.Initialize();
1211
Application.Run(new MainForm());
1312
}

Servers/CreateServerForm.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public partial class CreateServerForm : System.Windows.Forms.Form
2323
public string UserValue => UserInput.Text;
2424
private Label KeyLabel;
2525
private ComboBox KeyInput;
26-
public string KeyValue
26+
public string? KeyValue
2727
{
2828
get
2929
{
@@ -120,12 +120,15 @@ public CreateServerForm()
120120
foreach (var item in items)
121121
{
122122
KeyObject key = item.Value as KeyObject;
123-
KeyInput.Items.Add(new KeyValuePair<string, string>(key.Filename, key.Filename));
123+
if (key != null && key.Filename != null)
124+
{
125+
KeyInput.Items.Add(new KeyValuePair<string, string>(key.Filename, key.Filename));
126+
}
124127
}
125128
KeyInput.SelectedIndex = 0;
126129
KeyInput.GotFocus += (sender, e) =>
127130
{
128-
ComboBox comboBox = sender as ComboBox;
131+
ComboBox? comboBox = sender as ComboBox;
129132
if (comboBox != null)
130133
{
131134
comboBox.DroppedDown = true;
@@ -141,7 +144,7 @@ public CreateServerForm()
141144
CreateButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
142145
CreateButton.Location = new Point(10, KeyInput.Bottom + 10);
143146
CreateButton.UseVisualStyleBackColor = true;
144-
CreateButton.Click += new EventHandler(OnCreateButtonClick);
147+
CreateButton.Click += OnCreateButtonClick;
145148
Controls.Add(CreateButton);
146149

147150
// Layout
@@ -157,7 +160,7 @@ public CreateServerForm()
157160
ClientSize = new Size(ClientSize.Width, FormHeight + 20);
158161
}
159162

160-
protected void OnCreateButtonClick(object sender, EventArgs e)
163+
protected void OnCreateButtonClick(object? sender, EventArgs e)
161164
{
162165

163166
string hostValue = HostValue.Trim();
@@ -181,12 +184,12 @@ protected void OnCreateButtonClick(object sender, EventArgs e)
181184
return;
182185
}
183186

184-
string keyValue = KeyValue.Trim();
187+
string keyValue = (KeyValue != null) ? KeyValue.Trim() : "";
185188
if (string.IsNullOrWhiteSpace(keyValue))
186189
{
187190
MessageBox.Show("Пожалуйста Выберите ключ", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
188191
return;
189-
}
192+
}
190193

191194
if (keyValue == "rwt_generete")
192195
{
@@ -202,7 +205,16 @@ protected void OnCreateButtonClick(object sender, EventArgs e)
202205
key = new KeyObject(newKeyName);
203206
}
204207

205-
keyValue = key.Filename;
208+
if (key.Filename != null)
209+
{
210+
keyValue = key.Filename;
211+
}
212+
}
213+
214+
if (keyValue == null)
215+
{
216+
MessageBox.Show("Пожалуйста Выберите ключ", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
217+
return;
206218
}
207219

208220
if (ServersManager.CreateServer(hostValue, hostnameValue, userValue, keyValue))

Servers/ServerForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected void LoadConent(bool force = false)
147147

148148
protected void OnConnectServerButtonClick(object? sender, EventArgs e)
149149
{
150-
if (Server == null)
150+
if (Server == null || Server.Host == null)
151151
{
152152
MessageBox.Show("Сервер не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
153153
return;
@@ -157,7 +157,7 @@ protected void OnConnectServerButtonClick(object? sender, EventArgs e)
157157

158158
protected void OnRemoveServerButtonClick(object? sender, EventArgs e)
159159
{
160-
if (Server == null)
160+
if (Server == null || Server.Host == null)
161161
{
162162
MessageBox.Show("Сервер не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
163163
return;

Servers/ServerObject.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace RishWinTools.Servers
1010
{
1111
public class ServerObject
1212
{
13-
public string Host;
14-
public string Hostname;
15-
public string User;
16-
public string KeyName;
17-
public string PublicKey;
13+
public string? Host;
14+
public string? Hostname;
15+
public string? User;
16+
public string? KeyName;
17+
public string? PublicKey;
1818
public Dictionary<string, string> Additions = new Dictionary<string, string>();
1919
public KeyObject Key = new KeyObject();
2020

Servers/ServersManager.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public static Dictionary<string, ServerObject> GetServers(bool forse = false)
4949
public static bool CreateServer(string host, string hostname, string user, string key)
5050
{
5151
GetServers(true);
52+
if (Servers == null)
53+
{
54+
return false;
55+
}
56+
5257
if (Servers.ContainsKey(host))
5358
{
5459
MessageBox.Show("Сервер уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -84,13 +89,21 @@ public static bool RemoveServer(string host)
8489
MessageBox.Show("Сервер удален", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
8590
return true;
8691
}
92+
8793
ServerObject server = new ServerObject(host);
88-
if (Servers != null && !Servers.ContainsKey(server.Host))
94+
if (server.Host == null)
95+
{
96+
MessageBox.Show("Сервер не существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
97+
return false;
98+
}
99+
100+
if (Servers.ContainsKey(server.Host))
89101
{
90102
MessageBox.Show("Сервер не существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
91103

92104
return false;
93105
}
106+
94107
Servers.Remove(server.Host);
95108
if (PullServersToFile())
96109
{
@@ -107,6 +120,11 @@ public static bool RemoveServer(string host)
107120

108121
public static void SetServer(ServerObject server)
109122
{
123+
if (server.Host == null)
124+
{
125+
return;
126+
}
127+
110128
if (Servers == null)
111129
{
112130
Servers = new Dictionary<string, ServerObject>();
@@ -120,14 +138,22 @@ public static bool PullServersToFile()
120138
bool backup = false;
121139
try
122140
{
141+
if (Servers == null)
142+
{
143+
GetServers();
144+
}
145+
123146
List<string> result = new List<string>();
124-
SortedDictionary<string, ServerObject> sortedServers = new SortedDictionary<string, ServerObject>(Servers);
125-
foreach (var item in sortedServers)
147+
if (Servers != null)
126148
{
127-
ServerObject server = item.Value as ServerObject;
128-
if (server != null)
149+
SortedDictionary<string, ServerObject> sortedServers = new SortedDictionary<string, ServerObject>(Servers);
150+
foreach (var item in sortedServers)
129151
{
130-
result.Add(server.ToConfigFileSting());
152+
ServerObject server = item.Value as ServerObject;
153+
if (server != null)
154+
{
155+
result.Add(server.ToConfigFileSting());
156+
}
131157
}
132158
}
133159

@@ -160,7 +186,7 @@ public static bool PullServersToFile()
160186
File.Copy(ConfigBacPath, ConfigPath, true);
161187
backupRestore = 1;
162188
}
163-
catch (Exception backupEx)
189+
catch
164190
{
165191
backupRestore = -1;
166192
}
@@ -186,7 +212,7 @@ public static void ConnectToServer(string host, string? user = null)
186212
sshCommand = $"ssh {user}@{host}";
187213
}
188214

189-
string workingDirectory = Environment.GetEnvironmentVariable("USERPROFILE");
215+
string? workingDirectory = Environment.GetEnvironmentVariable("USERPROFILE");
190216
string commandToShow = $"echo '{workingDirectory}^>{sshCommand}'";
191217

192218
try

0 commit comments

Comments
 (0)