File Manager - Overwrites a different file with same name.

This commit is contained in:
NYAN CAT 2019-06-28 20:43:07 +03:00
parent 7bb9f02b71
commit 85c3f6b674
3 changed files with 11 additions and 8 deletions

View File

@ -26,7 +26,7 @@ namespace Server.Forms
public string FullFileName;
public string ClientFullFileName;
private bool IsUpload = false;
public string DirPath;
public FormDownloadFile()
{
InitializeComponent();

View File

@ -101,7 +101,9 @@ namespace Server.Forms
{
Name = "socketDownload:" + dwid,
Text = "socketDownload:" + Client.ID,
F = F
F = F,
DirPath = FullPath
};
SD.Show();
}

View File

@ -150,15 +150,16 @@ namespace Server.Handle_Packet
FormDownloadFile SD = (FormDownloadFile)Application.OpenForms["socketDownload:" + dwid];
if (SD != null)
{
if (!Directory.Exists(Path.Combine(Application.StartupPath, "ClientsFolder\\" + SD.Text.Replace("socketDownload:", ""))))
if (!Directory.Exists(SD.DirPath))
return;
string filename = Path.Combine(Application.StartupPath, "ClientsFolder\\" + SD.Text.Replace("socketDownload:", "") + "\\" + unpack_msgpack.ForcePathObject("Name").AsString);
if (File.Exists(filename))
string fileName = unpack_msgpack.ForcePathObject("Name").AsString;
string dirPath = SD.DirPath;
if (File.Exists(dirPath + "\\" + fileName))
{
File.Delete(filename);
await Task.Delay(500);
fileName = DateTime.Now.ToString("MM-dd-yyyy HH;mm;ss") + "_" + fileName;
await Task.Delay(100);
}
await Task.Run(() => SaveFileAsync(unpack_msgpack.ForcePathObject("File"), filename));
await Task.Run(() => SaveFileAsync(unpack_msgpack.ForcePathObject("File"), dirPath + "\\" + fileName));
SD.Close();
}
}