Ejemplo n.º 1
0
        private void DoPartialRead(string cleanUrl, ResourceRequestUIGT request,
                                   ResourceResponseUIGT response)
        {
            string rangeValue = request.GetHeader("Range");
            Match  match      = m_RangeRequestValue.Match(rangeValue);

            if (!match.Success)
            {
                response.SignalFailure();
                return;
            }

            long fileSize = new FileInfo(cleanUrl).Length;

            long   startByte     = long.Parse(match.Groups ["From"].Value);
            string endByteString = match.Groups ["To"].Value;
            long   endByte       = fileSize - 1;

            if (string.IsNullOrEmpty(endByteString))
            {
                // Clamp to a maximum chunk size
                const long MaxPartialReadSize = 16 * 1024 * 1024;
                if (endByte - startByte > MaxPartialReadSize)
                {
                    endByte = startByte + MaxPartialReadSize;
                }
            }
            else
            {
                endByte = long.Parse(endByteString);
            }

            // Clamp to int.MaxValue since that's the type BinaryReader
            // allows us to read; if it could read more bytes, then we would
            // clamp the size to uint.MaxValue since ResourceResponse.GetBuffer
            // expects an uint value.
            long bufferSize = Math.Min((long)int.MaxValue,
                                       endByte - startByte + 1);

            byte[] bytes = new byte[bufferSize];
            using (BinaryReader reader = new BinaryReader(
                       new FileStream(cleanUrl, FileMode.Open)))
            {
                reader.BaseStream.Seek(startByte, SeekOrigin.Begin);
                reader.Read(bytes, 0, (int)bufferSize);
            }

            // Set required response headers
            response.SetStatus(206);
            response.SetExpectedLength(fileSize);
            response.SetResponseHeader("Accept-Ranges", "bytes");
            response.SetResponseHeader("Content-Range", "bytes " + startByte +
                                       "-" + endByte + "/" + fileSize);
            response.SetResponseHeader("Content-Length",
                                       bufferSize.ToString());

            response.ReceiveData(bytes, bytes.LongLength);

            response.SignalSuccess();
        }
Ejemplo n.º 2
0
        public override void OnResourceRead(ResourceRequestUIGT request,
                                            ResourceResponseUIGT response)
        {
            if (m_UISystem == null)
            {
                m_UISystem = CoherentUIGTSystem.CurrentUISystem;
            }

            string url      = request.GetURL();
            string cleanUrl = GetFilepath(url);

            if (IsImageRequest(url) && url.StartsWith("coui://" + PRELOADEDIMAGES_PATH))
            {
                var    asUri         = new Uri(url);
                string fileExtension = url.Substring(url.LastIndexOf('.'));
                string texturePath   = url.Replace(asUri.Scheme + "://", "").Replace(fileExtension, "");;
                if (LoadPreloadedImage(texturePath, ref response))
                {
                    response.SignalSuccess();
                }
                else
                {
                    response.SignalFailure();
                }
                response.Release();
                return;
            }
            else if (m_UISystem.LiveGameViewComponents.ContainsKey(url))
            {
                if (LoadLiveViewFromComponent(url, ref response))
                {
                    response.SignalSuccess();
                }
                else
                {
                    response.SignalFailure();
                }
                response.Release();
                return;
            }

            if (!File.Exists(cleanUrl))
            {
                Debug.LogError("[Coherent GT] File not found for " + url);
                response.SignalFailure();
                response.Release();
                return;
            }

            if (request.GetHeaderIndex("Range") < 0)
            {
                DoCompleteRead(cleanUrl, request, response);
            }
            else
            {
                DoPartialRead(cleanUrl, request, response);
            }
            response.Release();
        }
Ejemplo n.º 3
0
        private void DoCompleteRead(string cleanUrl,
                                    ResourceRequestUIGT request, ResourceResponseUIGT response)
        {
            // TODO: Handle exception & notify response -
            // maybe handle it in the calling method
            byte[] bytes = File.ReadAllBytes(cleanUrl);

            response.SetStatus(200);
            response.SetExpectedLength(bytes.LongLength);
            response.ReceiveData(bytes, bytes.LongLength);
            response.SignalSuccess();
        }
Ejemplo n.º 4
0
        public override void OnResourceRead(ResourceRequestUIGT request,
                                            ResourceResponseUIGT response)
        {
            if (m_ViewComponent != null)
            {
                string url   = request.GetURL();
                var    asUri = new Uri(url);
                if (asUri.Scheme == "coui" && !url.EndsWith(".renderTexture"))
                {
                    string uiresources  = PlayerPrefs.GetString("CoherentGT:UIResources");
                    string resourcePath = asUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
                    string path         = "Assets/" + uiresources + "/" + resourcePath;
                    m_ViewComponent.m_ResourcesInUse.Add(path);
                }
            }

            m_Handler.OnResourceRead(request, response);
        }