Esempio n. 1
0
        private void unzipHandler(IRequest request, IResponse response)
        {
            if (EnableCrossDomain)
            {
                enableCrossDomain(response);
            }

            if (request.QueryString == null)
            {
                response.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            var type = request.QueryString.Get("type");
            var path = request.QueryString.Get("path");

            if (type == null || path == null)
            {
                response.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }


            var dirType = 0;
            var pathStr = UnescapeDataString(path.Value);

            if (!int.TryParse(type.Value, out dirType))
            {
                response.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            if (!canEdit((EDirType)dirType))
            {
                response.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            var dir      = getDir((EDirType)dirType);
            var fullname = dir + pathStr;

            if (!File.Exists(fullname))
            {
                response.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }
            var baseDir = Path.GetDirectoryName(pathStr);

            if (baseDir == null)
            {
                baseDir = "/";
            }

            var zip = new Zipper();

            zip.UnzipFile(fullname, dir + baseDir);

            var info = getInfo((EDirType)dirType, baseDir);

            sendData(response, info);
        }