diff --git a/Client/DownloadManager.cs b/Client/DownloadManager.cs index 319af33..2269863 100644 --- a/Client/DownloadManager.cs +++ b/Client/DownloadManager.cs @@ -45,7 +45,7 @@ namespace CoopClient lock (_streams) { - _streams.Add(id, new FileStream($"{downloadFolder}\\{name}", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)); + _streams.Add(id, new FileStream($"{downloadFolder}\\{name}", FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite)); } } @@ -87,10 +87,11 @@ namespace CoopClient lock (_streams) { - FileStream fs = _streams.ContainsKey(id) ? _streams[id] : null; + FileStream fs = _streams.FirstOrDefault(x => x.Key == id).Value; if (fs == null) { - throw new System.Exception($"Stream for file {id} doesn't found!"); + Logger.Write($"Stream for file {id} not found!", Logger.LogLevel.Server); + return; } fs.Write(data, 0, data.Length); @@ -100,7 +101,8 @@ namespace CoopClient DownloadFile file = _downloadFiles.FirstOrDefault(x => x.FileID == id); if (file == null) { - throw new System.Exception($"File {id} couldn't ne found in list!"); + Logger.Write($"File {id} couldn't be found in the list!", Logger.LogLevel.Server); + return; } file.FileWritten += data.Length; @@ -133,11 +135,11 @@ namespace CoopClient } } - public static void Cleanup() + public static void Cleanup(bool everything) { lock (_streams) lock (_downloadFiles) lock (_filesFinished) { - foreach (var stream in _streams) + foreach (KeyValuePair stream in _streams) { stream.Value.Close(); stream.Value.Dispose(); @@ -147,7 +149,10 @@ namespace CoopClient _filesFinished.Clear(); } - DownloadComplete = false; + if (everything) + { + DownloadComplete = false; + } } } diff --git a/Client/Networking.cs b/Client/Networking.cs index 82d83e2..6079fcf 100644 --- a/Client/Networking.cs +++ b/Client/Networking.cs @@ -133,7 +133,7 @@ namespace CoopClient } break; case NetConnectionStatus.Disconnected: - DownloadManager.Cleanup(); + DownloadManager.Cleanup(true); // Reset all values Latency = 0; @@ -501,6 +501,7 @@ namespace CoopClient Packets.FileTransferComplete packet = new Packets.FileTransferComplete(); packet.NetIncomingMessageToPacket(data); + DownloadManager.Cleanup(false); DownloadManager.DownloadComplete = true; } catch (Exception ex) diff --git a/Server/CoopServer.csproj b/Server/CoopServer.csproj index c6bd777..8fce608 100644 --- a/Server/CoopServer.csproj +++ b/Server/CoopServer.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.47.3.0001 + 1.47.4.0001 1.0.0.0 https://github.com/GTACOOP-R/GTACoop-R diff --git a/Server/DownloadManager.cs b/Server/DownloadManager.cs index 64ef799..3869366 100644 --- a/Server/DownloadManager.cs +++ b/Server/DownloadManager.cs @@ -70,9 +70,11 @@ namespace CoopServer } newFile.FileData.Add(buffer); + Logging.Debug($"[{fileInfo.Name}] {buffer.Length}"); } } + Logging.Debug($"[{fileInfo.Name}] RESULT {newFile.FileData.Count} / {newFile.FileLength}"); _files.Add(newFile); fileCount++; } @@ -238,6 +240,8 @@ namespace CoopServer private void Send(long nethandle, DownloadFile file) { + Logging.Debug($"SEND [{file.FileName}][{_fileDataPosition}/{file.FileData.Count - 1}]"); + NetConnection conn = Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == nethandle); if (conn == null) {