Beispiel #1
0
        private static void CaptureUnzipFileRequest(RequestWrapper request)
        {
            var    req  = request.Request as C2S_UnzipFileRequest;
            string path = null;

            if (req == null || !FileManager.FileExists(req.S64Sha256, out path) || !request.Connection.Authorized(DfsPermissions.UnzipFile))
            {
                request.TrySendResponse(new S2C_UnzipFileResult(null, false, false), out _);
                return;
            }


            FileStream fs;

            try
            {
                fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
            }
            catch
            {
                request.TrySendResponse(new S2C_UnzipFileResult(null, false, false), out _);
                return;
            }
            UnzipQueue.Enqueue(new UnzipFileItem {
                FileStream = fs, Request = request
            },
                               CryptoHelper.BuildDiscriminatorFromS64(req.S64Sha256));
        }
Beispiel #2
0
        private static void CaptureDownloadFileReady(RequestWrapper request)
        {
            var connection = request.Connection;
            var payload    = request.Request as C2S_DownloadFileReady;

            if (payload == null || !connection.Authorized(DfsPermissions.DownloadFile))
            {
                request.TrySendResponse(S2C_DownloadFileResult.Failed, out _);
                return;
            }
            var fileId = connection.Data.Get <string>($"F_{payload?.BufferId}", null);

            if (fileId == null)
            {
                request.TrySendResponse(S2C_DownloadFileResult.Failed, out _);
                return;
            }
            connection.Data[$"F_{payload.BufferId}"] = null;
            var path = PathHelper.MapLocal(fileId, Config.Dfs.Path);

            SendQueue.Enqueue(new SendFileItem
            {
                FileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete),
                Request    = request,
                BufferId   = payload.BufferId
            }, (int)connection.Identifier + payload.BufferId);
        }