2015-05-16 01:15:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using xServer.Core.Packets.ClientPackets;
|
|
|
|
|
using xServer.Forms;
|
|
|
|
|
using xServer.Settings;
|
|
|
|
|
|
|
|
|
|
namespace xServer.Core.Commands
|
|
|
|
|
{
|
|
|
|
|
/* THIS PARTIAL CLASS SHOULD CONTAIN METHODS THAT MANIPULATE THE SYSTEM (drives, directories, files, etc.). */
|
|
|
|
|
public static partial class CommandHandler
|
|
|
|
|
{
|
|
|
|
|
public static void HandleDrivesResponse(Client client, DrivesResponse packet)
|
|
|
|
|
{
|
2015-06-02 22:06:16 +00:00
|
|
|
|
if (client.Value.FrmFm == null || packet.Drives == null)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
client.Value.FrmFm.AddDrives(packet.Drives);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleDirectoryResponse(Client client, DirectoryResponse packet)
|
|
|
|
|
{
|
|
|
|
|
if (client.Value.FrmFm == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
client.Value.FrmFm.ClearFileBrowser();
|
2015-05-16 01:15:44 +00:00
|
|
|
|
|
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
ListViewItem lviBack = new ListViewItem(new string[] { "..", "", "Directory" })
|
|
|
|
|
{
|
|
|
|
|
Tag = "dir",
|
|
|
|
|
ImageIndex = 0
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
client.Value.FrmFm.AddItemToFileBrowser(lviBack);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
|
2015-06-02 22:06:16 +00:00
|
|
|
|
if (packet.Folders != null && packet.Folders.Length != 0)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < packet.Folders.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (packet.Folders[i] != DELIMITER)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem lvi = new ListViewItem(new string[] { packet.Folders[i], "", "Directory" })
|
|
|
|
|
{
|
|
|
|
|
Tag = "dir",
|
|
|
|
|
ImageIndex = 1
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
if (client.Value.FrmFm == null)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
break;
|
2015-05-29 21:35:11 +00:00
|
|
|
|
|
|
|
|
|
client.Value.FrmFm.AddItemToFileBrowser(lvi);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 22:06:16 +00:00
|
|
|
|
if (packet.Files != null && packet.Files.Length != 0)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < packet.Files.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (packet.Files[i] != DELIMITER)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem lvi =
|
2015-05-19 20:17:03 +00:00
|
|
|
|
new ListViewItem(new string[] { packet.Files[i], Helper.Helper.GetDataSize(packet.FilesSize[i]), "File" })
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
|
|
|
|
Tag = "file",
|
|
|
|
|
ImageIndex = Helper.Helper.GetFileIcon(Path.GetExtension(packet.Files[i]))
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
if (client.Value.FrmFm == null)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
break;
|
2015-05-29 21:35:11 +00:00
|
|
|
|
|
|
|
|
|
client.Value.FrmFm.AddItemToFileBrowser(lvi);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.Value.LastDirectorySeen = true;
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleGetSystemInfoResponse(Client client, GetSystemInfoResponse packet)
|
|
|
|
|
{
|
2015-06-02 22:06:16 +00:00
|
|
|
|
if (packet.SystemInfos == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-05-16 01:15:44 +00:00
|
|
|
|
if (XMLSettings.ShowToolTip)
|
|
|
|
|
{
|
2015-05-29 21:34:57 +00:00
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < packet.SystemInfos.Length; i += 2)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
2015-05-29 21:34:57 +00:00
|
|
|
|
if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
2015-05-29 21:34:57 +00:00
|
|
|
|
builder.AppendFormat("{0}: {1}\r\n", packet.SystemInfos[i], packet.SystemInfos[i + 1]);
|
|
|
|
|
}
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
2015-05-29 21:34:57 +00:00
|
|
|
|
|
|
|
|
|
FrmMain.Instance.SetToolTipText(client, builder.ToString());
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (client.Value.FrmSi == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ListViewItem[] lviCollection = new ListViewItem[packet.SystemInfos.Length / 2];
|
|
|
|
|
for (int i = 0, j = 0; i < packet.SystemInfos.Length; i += 2, j++)
|
|
|
|
|
{
|
|
|
|
|
if (packet.SystemInfos[i] != null && packet.SystemInfos[i + 1] != null)
|
|
|
|
|
{
|
|
|
|
|
lviCollection[j] = new ListViewItem(new string[] { packet.SystemInfos[i], packet.SystemInfos[i + 1] });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 21:35:11 +00:00
|
|
|
|
if (client.Value.FrmSi != null)
|
|
|
|
|
client.Value.FrmSi.AddItems(lviCollection);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleGetStartupItemsResponse(Client client, GetStartupItemsResponse packet)
|
|
|
|
|
{
|
2015-06-02 17:19:35 +00:00
|
|
|
|
if (client.Value.FrmStm == null || packet.StartupItems == null)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-06-03 13:18:37 +00:00
|
|
|
|
foreach (var item in packet.StartupItems)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
2015-05-29 21:35:11 +00:00
|
|
|
|
if (client.Value.FrmStm == null) return;
|
|
|
|
|
|
2015-06-03 13:18:37 +00:00
|
|
|
|
int type;
|
2015-06-04 18:09:19 +00:00
|
|
|
|
if (!int.TryParse(item.Substring(0, 1), out type)) continue;
|
2015-06-03 13:18:37 +00:00
|
|
|
|
|
|
|
|
|
string preparedItem = item.Remove(0, 1);
|
|
|
|
|
var temp = preparedItem.Split(new string[] { "||" }, StringSplitOptions.None);
|
2015-05-29 21:35:11 +00:00
|
|
|
|
var l = new ListViewItem(temp)
|
2015-05-16 01:15:44 +00:00
|
|
|
|
{
|
2015-06-03 13:18:37 +00:00
|
|
|
|
Group = client.Value.FrmStm.GetGroup(type),
|
|
|
|
|
Tag = type
|
2015-05-29 21:35:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (l.Group == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
client.Value.FrmStm.AddAutostartItemToListview(l);
|
2015-05-16 01:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|