mirror of https://github.com/quasar/Quasar.git
Added enum for dirs and files in File Manager
This commit is contained in:
parent
fcf50ca639
commit
b46b57e602
|
@ -41,5 +41,11 @@ namespace xClient.Core.Commands
|
|||
Restart,
|
||||
Standby
|
||||
}
|
||||
public enum PathType
|
||||
{
|
||||
File,
|
||||
Directory,
|
||||
Back
|
||||
}
|
||||
}
|
||||
}
|
|
@ -103,10 +103,15 @@ namespace xClient.Core.Commands
|
|||
{
|
||||
try
|
||||
{
|
||||
if (command.IsDirectory)
|
||||
Directory.Delete(command.Path, true);
|
||||
else
|
||||
File.Delete(command.Path);
|
||||
switch (command.PathType)
|
||||
{
|
||||
case PathType.Directory:
|
||||
Directory.Delete(command.Path, true);
|
||||
break;
|
||||
case PathType.File:
|
||||
File.Delete(command.Path);
|
||||
break;
|
||||
}
|
||||
|
||||
HandleGetDirectory(new Packets.ServerPackets.GetDirectory(Path.GetDirectoryName(command.Path)), client);
|
||||
}
|
||||
|
@ -119,10 +124,15 @@ namespace xClient.Core.Commands
|
|||
{
|
||||
try
|
||||
{
|
||||
if (command.IsDirectory)
|
||||
Directory.Move(command.Path, command.NewPath);
|
||||
else
|
||||
File.Move(command.Path, command.NewPath);
|
||||
switch (command.PathType)
|
||||
{
|
||||
case PathType.Directory:
|
||||
Directory.Move(command.Path, command.NewPath);
|
||||
break;
|
||||
case PathType.File:
|
||||
File.Move(command.Path, command.NewPath);
|
||||
break;
|
||||
}
|
||||
|
||||
HandleGetDirectory(new Packets.ServerPackets.GetDirectory(Path.GetDirectoryName(command.NewPath)), client);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ProtoBuf;
|
||||
using xClient.Core.Networking;
|
||||
using PathType = xClient.Core.Commands.CommandHandler.PathType;
|
||||
|
||||
namespace xClient.Core.Packets.ServerPackets
|
||||
{
|
||||
|
@ -10,16 +11,16 @@ namespace xClient.Core.Packets.ServerPackets
|
|||
public string Path { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public bool IsDirectory { get; set; }
|
||||
public PathType PathType { get; set; }
|
||||
|
||||
public DoPathDelete()
|
||||
{
|
||||
}
|
||||
|
||||
public DoPathDelete(string path, bool isdirectory)
|
||||
public DoPathDelete(string path, PathType pathtype)
|
||||
{
|
||||
this.Path = path;
|
||||
this.IsDirectory = isdirectory;
|
||||
this.PathType = pathtype;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ProtoBuf;
|
||||
using xClient.Core.Networking;
|
||||
using PathType = xClient.Core.Commands.CommandHandler.PathType;
|
||||
|
||||
namespace xClient.Core.Packets.ServerPackets
|
||||
{
|
||||
|
@ -13,17 +14,17 @@ namespace xClient.Core.Packets.ServerPackets
|
|||
public string NewPath { get; set; }
|
||||
|
||||
[ProtoMember(3)]
|
||||
public bool IsDirectory { get; set; }
|
||||
public PathType PathType { get; set; }
|
||||
|
||||
public DoPathRename()
|
||||
{
|
||||
}
|
||||
|
||||
public DoPathRename(string path, string newpath, bool isdirectory)
|
||||
public DoPathRename(string path, string newpath, PathType pathtype)
|
||||
{
|
||||
this.Path = path;
|
||||
this.NewPath = newpath;
|
||||
this.IsDirectory = isdirectory;
|
||||
this.PathType = pathtype;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -20,5 +20,11 @@ namespace xServer.Core.Commands
|
|||
Restart,
|
||||
Standby
|
||||
}
|
||||
public enum PathType
|
||||
{
|
||||
File,
|
||||
Directory,
|
||||
Back
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,9 +30,9 @@ namespace xServer.Core.Commands
|
|||
|
||||
new Thread(() =>
|
||||
{
|
||||
ListViewItem lviBack = new ListViewItem(new string[] { "..", "", "Directory" })
|
||||
ListViewItem lviBack = new ListViewItem(new string[] { "..", "", "" })
|
||||
{
|
||||
Tag = "dir",
|
||||
Tag = PathType.Back,
|
||||
ImageIndex = 0
|
||||
};
|
||||
|
||||
|
@ -44,9 +44,9 @@ namespace xServer.Core.Commands
|
|||
{
|
||||
if (packet.Folders[i] != DELIMITER)
|
||||
{
|
||||
ListViewItem lvi = new ListViewItem(new string[] { packet.Folders[i], "", "Directory" })
|
||||
ListViewItem lvi = new ListViewItem(new string[] { packet.Folders[i], "", PathType.Directory.ToString() })
|
||||
{
|
||||
Tag = "dir",
|
||||
Tag = PathType.Directory,
|
||||
ImageIndex = 1
|
||||
};
|
||||
|
||||
|
@ -65,9 +65,9 @@ namespace xServer.Core.Commands
|
|||
if (packet.Files[i] != DELIMITER)
|
||||
{
|
||||
ListViewItem lvi =
|
||||
new ListViewItem(new string[] { packet.Files[i], Helper.Helper.GetDataSize(packet.FilesSize[i]), "File" })
|
||||
new ListViewItem(new string[] { packet.Files[i], Helper.Helper.GetDataSize(packet.FilesSize[i]), PathType.File.ToString() })
|
||||
{
|
||||
Tag = "file",
|
||||
Tag = PathType.File,
|
||||
ImageIndex = Helper.Helper.GetFileIcon(Path.GetExtension(packet.Files[i]))
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ProtoBuf;
|
||||
using xServer.Core.Networking;
|
||||
using PathType = xServer.Core.Commands.CommandHandler.PathType;
|
||||
|
||||
namespace xServer.Core.Packets.ServerPackets
|
||||
{
|
||||
|
@ -10,16 +11,16 @@ namespace xServer.Core.Packets.ServerPackets
|
|||
public string Path { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public bool IsDirectory { get; set; }
|
||||
public PathType PathType { get; set; }
|
||||
|
||||
public DoPathDelete()
|
||||
{
|
||||
}
|
||||
|
||||
public DoPathDelete(string path, bool isdirectory)
|
||||
public DoPathDelete(string path, PathType pathtype)
|
||||
{
|
||||
this.Path = path;
|
||||
this.IsDirectory = isdirectory;
|
||||
this.PathType = pathtype;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using ProtoBuf;
|
||||
using xServer.Core.Networking;
|
||||
using PathType = xServer.Core.Commands.CommandHandler.PathType;
|
||||
|
||||
namespace xServer.Core.Packets.ServerPackets
|
||||
{
|
||||
|
@ -13,17 +14,17 @@ namespace xServer.Core.Packets.ServerPackets
|
|||
public string NewPath { get; set; }
|
||||
|
||||
[ProtoMember(3)]
|
||||
public bool IsDirectory { get; set; }
|
||||
public PathType PathType { get; set; }
|
||||
|
||||
public DoPathRename()
|
||||
{
|
||||
}
|
||||
|
||||
public DoPathRename(string path, string newpath, bool isdirectory)
|
||||
public DoPathRename(string path, string newpath, PathType pathtype)
|
||||
{
|
||||
this.Path = path;
|
||||
this.NewPath = newpath;
|
||||
this.IsDirectory = isdirectory;
|
||||
this.PathType = pathtype;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -7,6 +7,7 @@ using xServer.Core.Commands;
|
|||
using xServer.Core.Helper;
|
||||
using xServer.Core.Misc;
|
||||
using xServer.Core.Networking;
|
||||
using PathType = xServer.Core.Commands.CommandHandler.PathType;
|
||||
|
||||
namespace xServer.Forms
|
||||
{
|
||||
|
@ -64,31 +65,26 @@ namespace xServer.Forms
|
|||
|
||||
private void lstDirectory_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if (_connectClient != null)
|
||||
if (_connectClient != null && _connectClient.Value != null && lstDirectory.SelectedItems.Count > 0)
|
||||
{
|
||||
if (lstDirectory.SelectedItems.Count != 0)
|
||||
PathType type = (PathType) lstDirectory.SelectedItems[0].Tag;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
if (lstDirectory.SelectedItems[0].Tag.ToString() == "dir" && _connectClient.Value != null)
|
||||
{
|
||||
if (lstDirectory.SelectedItems[0].SubItems[0].Text == "..")
|
||||
{
|
||||
_currentDir = Path.GetFullPath(Path.Combine(_currentDir, @"..\"));
|
||||
case PathType.Back:
|
||||
if (!_connectClient.Value.LastDirectorySeen) return;
|
||||
|
||||
new Core.Packets.ServerPackets.GetDirectory(_currentDir).Execute(_connectClient);
|
||||
_connectClient.Value.LastDirectorySeen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_connectClient.Value.LastDirectorySeen)
|
||||
{
|
||||
_currentDir = GetAbsolutePath(lstDirectory.SelectedItems[0].SubItems[0].Text);
|
||||
_currentDir = Path.GetFullPath(Path.Combine(_currentDir, @"..\"));
|
||||
break;
|
||||
case PathType.Directory:
|
||||
if (!_connectClient.Value.LastDirectorySeen) return;
|
||||
|
||||
new Core.Packets.ServerPackets.GetDirectory(_currentDir).Execute(_connectClient);
|
||||
_connectClient.Value.LastDirectorySeen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentDir = GetAbsolutePath(lstDirectory.SelectedItems[0].SubItems[0].Text);
|
||||
break;
|
||||
}
|
||||
|
||||
new Core.Packets.ServerPackets.GetDirectory(_currentDir).Execute(_connectClient);
|
||||
_connectClient.Value.LastDirectorySeen = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +92,9 @@ namespace xServer.Forms
|
|||
{
|
||||
foreach (ListViewItem files in lstDirectory.SelectedItems)
|
||||
{
|
||||
if (files.Tag.ToString() == "file")
|
||||
PathType type = (PathType)files.Tag;
|
||||
|
||||
if (type == PathType.File)
|
||||
{
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
|
||||
|
@ -121,7 +119,9 @@ namespace xServer.Forms
|
|||
{
|
||||
foreach (ListViewItem files in lstDirectory.SelectedItems)
|
||||
{
|
||||
if (files.Tag.ToString() == "file")
|
||||
PathType type = (PathType) files.Tag;
|
||||
|
||||
if (type == PathType.File)
|
||||
{
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
|
||||
|
@ -135,19 +135,23 @@ namespace xServer.Forms
|
|||
{
|
||||
foreach (ListViewItem files in lstDirectory.SelectedItems)
|
||||
{
|
||||
if (files.SubItems[0].Text != "..")
|
||||
PathType type = (PathType)files.Tag;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
string newName = files.SubItems[0].Text;
|
||||
bool isDir = files.Tag.ToString() == "dir";
|
||||
case PathType.Directory:
|
||||
case PathType.File:
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
string newName = files.SubItems[0].Text;
|
||||
|
||||
if (InputBox.Show("New name", "Enter new name:", ref newName) == DialogResult.OK)
|
||||
{
|
||||
newName = GetAbsolutePath(newName);
|
||||
if (InputBox.Show("New name", "Enter new name:", ref newName) == DialogResult.OK)
|
||||
{
|
||||
newName = GetAbsolutePath(newName);
|
||||
|
||||
if (_connectClient != null)
|
||||
new Core.Packets.ServerPackets.DoPathRename(path, newName, isDir).Execute(_connectClient);
|
||||
}
|
||||
if (_connectClient != null)
|
||||
new Core.Packets.ServerPackets.DoPathRename(path, newName, type).Execute(_connectClient);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,19 +160,22 @@ namespace xServer.Forms
|
|||
{
|
||||
foreach (ListViewItem files in lstDirectory.SelectedItems)
|
||||
{
|
||||
if (files.SubItems[0].Text != "..")
|
||||
{
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
bool isDir = files.Tag.ToString() == "dir";
|
||||
string text = string.Format("Are you sure you want to delete this {0}",
|
||||
(isDir) ? "directory?" : "file?");
|
||||
PathType type = (PathType)files.Tag;
|
||||
|
||||
if (MessageBox.Show(text, "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
|
||||
DialogResult.Yes)
|
||||
{
|
||||
if (_connectClient != null)
|
||||
new Core.Packets.ServerPackets.DoPathDelete(path, isDir).Execute(_connectClient);
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case PathType.Directory:
|
||||
case PathType.File:
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
string text = string.Format("Are you sure you want to delete this {0}?", type);
|
||||
|
||||
if (MessageBox.Show(text, "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
|
||||
DialogResult.Yes)
|
||||
{
|
||||
if (_connectClient != null)
|
||||
new Core.Packets.ServerPackets.DoPathDelete(path, type).Execute(_connectClient);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +184,9 @@ namespace xServer.Forms
|
|||
{
|
||||
foreach (ListViewItem files in lstDirectory.SelectedItems)
|
||||
{
|
||||
if (files.Tag.ToString() == "file")
|
||||
PathType type = (PathType)files.Tag;
|
||||
|
||||
if (type == PathType.File)
|
||||
{
|
||||
string path = GetAbsolutePath(files.SubItems[0].Text);
|
||||
|
||||
|
@ -211,7 +220,9 @@ namespace xServer.Forms
|
|||
if (lstDirectory.SelectedItems.Count == 1)
|
||||
{
|
||||
var item = lstDirectory.SelectedItems[0];
|
||||
if (item.SubItems[0].Text != ".." && item.Tag.ToString() == "dir")
|
||||
PathType type = (PathType)item.Tag;
|
||||
|
||||
if (type == PathType.Directory)
|
||||
{
|
||||
path = GetAbsolutePath(item.SubItems[0].Text);
|
||||
}
|
||||
|
@ -320,7 +331,7 @@ namespace xServer.Forms
|
|||
}
|
||||
}
|
||||
|
||||
public int GetTransferIndex(string ID)
|
||||
public int GetTransferIndex(string id)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
|
@ -328,7 +339,7 @@ namespace xServer.Forms
|
|||
{
|
||||
lstTransfers.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
foreach (ListViewItem lvi in lstTransfers.Items.Cast<ListViewItem>().Where(lvi => lvi != null && ID == lvi.SubItems[0].Text))
|
||||
foreach (ListViewItem lvi in lstTransfers.Items.Cast<ListViewItem>().Where(lvi => lvi != null && id == lvi.SubItems[0].Text))
|
||||
{
|
||||
index = lvi.Index;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue