Skip to content

Commit 9d7daca

Browse files
committed
Cleanup code
1 parent 37533e8 commit 9d7daca

File tree

9 files changed

+22
-35
lines changed

9 files changed

+22
-35
lines changed

Core.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Nfu.Models;
22
using Nfu.Properties;
33
using System;
4-
using System.Collections.Specialized;
54
using System.Diagnostics;
65
using System.Drawing;
76
using System.IO;

Cp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void ButtonSave(object sender, EventArgs e)
8787
if (checkBoxStartWindows.Checked)
8888
{
8989
_autoStartKey.SetValue(Settings.Default.RunKey,
90-
string.Format("\"{0}\" {1}", Application.ExecutablePath, "minimized"));
90+
$"\"{Application.ExecutablePath}\" {"minimized"}");
9191
}
9292
else
9393
{

Misc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected override void WndProc(ref Message m)
6666
{
6767
if (m.Msg == 0x0312 && m.WParam.ToInt32() == WParam)
6868
{
69-
if (HotKeyPass != null) HotKeyPass.Invoke();
69+
HotKeyPass?.Invoke();
7070
}
7171

7272
base.WndProc(ref m);
@@ -117,7 +117,7 @@ public static void HandleError(Exception err, string name, bool show = true, Eve
117117
{
118118
if (Settings.Default.Debug)
119119
{
120-
EventLog.WriteEntry(Resources.AppName, string.Format("[{0}]: {1}\n\n{2}", name, err.Message, err.StackTrace), type);
120+
EventLog.WriteEntry(Resources.AppName, $"[{name}]: {err.Message}\n\n{err.StackTrace}", type);
121121
}
122122
}
123123
catch

Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ static void Main(string[] args)
9090

9191
FormCore.Setup();
9292

93-
if (Settings.Default.FirstRun) FormCore.Load += (sender, e) =>
93+
if (Settings.Default.FirstRun)
94+
{
95+
FormCore.Load += (sender, e) =>
9496
{
9597
FormCp.ShowDialog();
9698
};
99+
}
97100

98101
if (args.Any(a => a == "minimized"))
99102
{

Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following

Snipper.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,8 @@ private Snipper()
9494
/// </summary>
9595
private void ScreenIndexChanged(object sender, EventArgs e)
9696
{
97-
if (_comboBoxScreen.SelectedIndex == 0)
98-
{
99-
_rectangle = SystemInformation.VirtualScreen;
100-
}
101-
else
102-
{
103-
_rectangle = Screen.AllScreens[_comboBoxScreen.SelectedIndex - 1].Bounds;
104-
}
97+
_rectangle = _comboBoxScreen.SelectedIndex == 0 ?
98+
SystemInformation.VirtualScreen : Screen.AllScreens[_comboBoxScreen.SelectedIndex - 1].Bounds;
10599

106100
Size = _rectangle.Size;
107101
Location = _rectangle.Location;

Tests/FileTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using System.Collections.Generic;
43
using Nfu.Models;
54
using System.IO;

Tests/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following

Uploader.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Renci.SshNet;
44
using Renci.SshNet.Sftp;
55
using System;
6-
using System.Collections.Generic;
76
using System.ComponentModel;
87
using System.Drawing;
98
using System.IO;
@@ -115,7 +114,7 @@ static void UploadWorkerHandler(object sender, DoWorkEventArgs a)
115114
_currentStatus = Resources.ZippingDirectory;
116115
UploadWorker.ReportProgress(0);
117116

118-
var zipFileName = string.Format("{0}.zip", file.FileName);
117+
var zipFileName = $"{file.FileName}.zip";
119118
var zipFile = new UploadFile(FileState.Temporary, "zip");
120119
if (zipFile.Path == null)
121120
{
@@ -238,11 +237,11 @@ static bool UploadFtp(UploadFile file)
238237

239238
if (!string.IsNullOrEmpty(Settings.Default.Directory))
240239
{
241-
ftpRequest = (FtpWebRequest)WebRequest.Create(string.Format("ftp://{0}:{1}/{2}/{3}", Settings.Default.Host, Settings.Default.Port, Settings.Default.Directory, file.FileName));
240+
ftpRequest = (FtpWebRequest)WebRequest.Create($"ftp://{Settings.Default.Host}:{Settings.Default.Port}/{Settings.Default.Directory}/{file.FileName}");
242241
}
243242
else
244243
{
245-
ftpRequest = (FtpWebRequest)WebRequest.Create(string.Format("ftp://{0}:{1}/{2}", Settings.Default.Host, Settings.Default.Port, file.FileName));
244+
ftpRequest = (FtpWebRequest)WebRequest.Create($"ftp://{Settings.Default.Host}:{Settings.Default.Port}/{file.FileName}");
246245
}
247246

248247
if (Settings.Default.TransferType == (int)TransferType.FtpsExplicit)
@@ -291,26 +290,19 @@ static bool UploadSftp(UploadFile file)
291290
{
292291
try
293292
{
294-
SftpClient client;
295-
296-
if (Settings.Default.TransferType == (int)TransferType.SftpKeys)
297-
{
298-
client = new SftpClient(Settings.Default.Host, Settings.Default.Port, Settings.Default.Username, new PrivateKeyFile(Misc.Decrypt(Settings.Default.Password)));
299-
}
300-
else
301-
{
302-
client = new SftpClient(Settings.Default.Host, Settings.Default.Port, Settings.Default.Username, Misc.Decrypt(Settings.Default.Password));
303-
}
293+
var client = Settings.Default.TransferType == (int)TransferType.SftpKeys ?
294+
new SftpClient(Settings.Default.Host, Settings.Default.Port, Settings.Default.Username, new PrivateKeyFile(Misc.Decrypt(Settings.Default.Password))) :
295+
new SftpClient(Settings.Default.Host, Settings.Default.Port, Settings.Default.Username, Misc.Decrypt(Settings.Default.Password));
304296

305297
using (var inputStream = new FileStream(file.Path, FileMode.Open))
306-
using (SftpClient outputStream = client)
298+
using (var outputStream = client)
307299
{
308300
outputStream.Connect();
309301

310302
if (!string.IsNullOrEmpty(Settings.Default.Directory)) outputStream.ChangeDirectory(Settings.Default.Directory);
311303

312-
IAsyncResult async = outputStream.BeginUploadFile(inputStream, file.FileName);
313-
SftpUploadAsyncResult sftpAsync = async as SftpUploadAsyncResult;
304+
var async = outputStream.BeginUploadFile(inputStream, file.FileName);
305+
var sftpAsync = async as SftpUploadAsyncResult;
314306

315307
while (sftpAsync != null && !sftpAsync.IsCompleted)
316308
{
@@ -348,7 +340,9 @@ static bool UploadCifs(UploadFile file)
348340
Misc.LogonUser(Settings.Default.Username, Resources.AppName, Misc.Decrypt(Settings.Default.Password), 9, 0, ref token);
349341
var identity = new WindowsIdentity(token);
350342

351-
var destPath = (!string.IsNullOrEmpty(Settings.Default.Directory)) ? string.Format(@"\\{0}\{1}\{2}", Settings.Default.Host, Settings.Default.Directory, file.FileName) : string.Format(@"\\{0}\{1}", Settings.Default.Host, file.FileName);
343+
var destPath = (!string.IsNullOrEmpty(Settings.Default.Directory)) ?
344+
$@"\\{Settings.Default.Host}\{Settings.Default.Directory}\{file.FileName}" :
345+
$@"\\{Settings.Default.Host}\{file.FileName}";
352346

353347
using (identity.Impersonate())
354348
using (var inputStream = new FileStream(file.Path, FileMode.Open, FileAccess.Read))

0 commit comments

Comments
 (0)