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 FullFileName;
public string ClientFullFileName; public string ClientFullFileName;
private bool IsUpload = false; private bool IsUpload = false;
public string DirPath;
public FormDownloadFile() public FormDownloadFile()
{ {
InitializeComponent(); InitializeComponent();

View File

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

View File

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