mirror of https://github.com/quasar/Quasar.git
Improved check for illegal chars in path
This commit is contained in:
parent
90f30caafb
commit
836b77d13e
|
@ -30,13 +30,10 @@ namespace xServer.Core.Commands
|
||||||
client.Value.PCName = packet.PCName;
|
client.Value.PCName = packet.PCName;
|
||||||
|
|
||||||
string userAtPc = string.Format("{0}@{1}", client.Value.Username, client.Value.PCName);
|
string userAtPc = string.Format("{0}@{1}", client.Value.Username, client.Value.PCName);
|
||||||
char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
|
|
||||||
bool containsIllegalChar = userAtPc.Count(c => illegal.Contains(c)) > 0;
|
|
||||||
|
|
||||||
if (!containsIllegalChar)
|
client.Value.DownloadDirectory = (!Helper.Helper.CheckPathForIllegalChars(userAtPc)) ?
|
||||||
client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + userAtPc + "\\");
|
Path.Combine(Application.StartupPath, "Clients\\" + userAtPc + "\\") :
|
||||||
else
|
Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\");
|
||||||
client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\");
|
|
||||||
|
|
||||||
if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id))
|
if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id))
|
||||||
FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now);
|
FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace xServer.Core.Helper
|
namespace xServer.Core.Helper
|
||||||
|
@ -8,6 +10,12 @@ namespace xServer.Core.Helper
|
||||||
private const string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
private const string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
private static readonly Random _rnd = new Random(Environment.TickCount);
|
private static readonly Random _rnd = new Random(Environment.TickCount);
|
||||||
private static readonly string[] _sizes = {"B", "KB", "MB", "GB"};
|
private static readonly string[] _sizes = {"B", "KB", "MB", "GB"};
|
||||||
|
private static readonly char[] _illegalChars = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
|
||||||
|
|
||||||
|
public static bool CheckPathForIllegalChars(string path)
|
||||||
|
{
|
||||||
|
return path.Any(c => _illegalChars.Contains(c));
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetRandomFilename(int length, string extension)
|
public static string GetRandomFilename(int length, string extension)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using xServer.Core.Helper;
|
||||||
using xServer.Core.Misc;
|
using xServer.Core.Misc;
|
||||||
|
|
||||||
namespace xServer.Forms
|
namespace xServer.Forms
|
||||||
|
@ -52,16 +53,14 @@ namespace xServer.Forms
|
||||||
|
|
||||||
private void txtName_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtName_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars());
|
e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) &&
|
||||||
if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar))
|
!char.IsControl(e.KeyChar));
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void txtPath_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtPath_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars());
|
e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) &&
|
||||||
if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar))
|
!char.IsControl(e.KeyChar));
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -130,8 +130,7 @@ namespace xServer.Forms
|
||||||
|
|
||||||
private void txtPort_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtPort_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
|
e.Handled = (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar));
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void txtDelay_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtDelay_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
|
@ -141,16 +140,14 @@ namespace xServer.Forms
|
||||||
|
|
||||||
private void txtInstallname_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtInstallname_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
|
e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) &&
|
||||||
|
!char.IsControl(e.KeyChar));
|
||||||
e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void txtInstallsub_KeyPress(object sender, KeyPressEventArgs e)
|
private void txtInstallsub_KeyPress(object sender, KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
|
e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) &&
|
||||||
|
!char.IsControl(e.KeyChar));
|
||||||
e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnMutex_Click(object sender, EventArgs e)
|
private void btnMutex_Click(object sender, EventArgs e)
|
||||||
|
|
Loading…
Reference in New Issue