Ejemplo n.º 1
0
 protected virtual bool SyncSource(SourcePath target, byte[] data)
 {
     return(SyncSource(new SourcePath[] { target }, data));
 }
Ejemplo n.º 2
0
        //todo: this needs to run on separate thread probably
        private bool TryLoadSource(SourcePath p)
        {
            try
            {
                WWWForm post    = null;
                WWW     request = null;

                try
                {
                    if (!p.isLocal)
                    {
                        if (p.hasPostData)
                        {
                            post = new WWWForm();
                            foreach (var field in p.getPostData())
                            {
                                post.AddField(field.Key, field.Value);
                            }
                        }

                        //l.w("(MSF)...isLocal == FALSE");

                        if (post != null)
                        {
                            //l.w("(MSF)...hasPost == TRUE. Making GET request");
                            request = new WWW(p.path, post);
                        }
                        else
                        {
                            //l.w("(MSF)...hasPost == FALSE. Making POST request");
                            request = new WWW(p.path);
                        }

                        //w.InitWWW(url, null, new string[] { "Request-Encoding: utf-8" });
                        while (request.isDone == false)
                        {
                            Thread.Sleep(100);
                        }

                        //l.w("(MSF)...source response recieved");

                        //l.w("(MSF)Content-Length: " + request.responseHeaders["Content-Length"]);
                        //l.w("(MSF)Content-length: " + request.responseHeaders["Content-length"]);
                        //l.w("(MSF)content-length: " + request.responseHeaders["content-length"]);
                        file = request.bytes;
                        RecieveTryLoadSource(request);
                        //l.w("...MSF loaded and parsed");
                        return(true);
                    }
                    else
                    {
                        //l.w("(MSF)...isLocal == TRUE");
                        if (File.Exists(p.path))
                        {
                            file = File.ReadAllBytes(p.path);
                            using (FileStream src = File.OpenRead(p.path))
                            {
                                RecieveTryLoadSource(src);
                            }

                            //l.w("...MSF loaded and parsed from " + p.path);
                        }

                        bytes = file;
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("(MFS)Failed. Error: " + e.ToString());
                }
            }
            catch (Exception e)
            {
                //todo: log the exception somewhere useful
                Debug.Log(e.ToString());
                return(false);
            }

            return(false);
        }