예제 #1
0
        public Plugin_Download_Data(JSONNode info)
        {
            json = info;

            Author      = TryGet("author");
            Name        = TryGet("name");
            Description = TryGet("description");
            URL         = TryGet("url");

            string method = TryGet("update_method");

            if (method != null)
            {
                Updater = Updater_Base.Get_Instance((UPDATER_TYPE)Enum.Parse(typeof(UPDATER_TYPE), method, true));
            }
        }
예제 #2
0
        IEnumerator Start_Update()
        {
            foreach (UpdateFile file in Files)
            {
                byte[]      buf  = null;
                IEnumerator iter = Updater_Base.GetAsync(file.URL, null, (float read, float total) => {
                    if (updatesView != null)
                    {
                        var prog = (updatesView[file.FILE] as uiListItem_Progress);
                        if (prog != null)
                        {
                            prog.Value = ((float)read / (float)total);
                        }
                    }
                });
                while (iter.MoveNext())
                {
                    yield return(null);
                }

                if (iter.Current == null)
                {
                    continue;                      // go to the next file
                }
                buf = iter.Current as byte[];
                if (buf == null || buf.Length <= 0)
                {
                    continue;                      // go to the next file
                }
                string filename = file.LOCAL_PATH; // String.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Path.GetFileName(url));
                string new_file = String.Format("{0}.tmp", filename);
                string old_file = String.Format("{0}.old", filename);

                File.WriteAllBytes(new_file, buf);
                if (File.Exists(old_file))
                {
                    File.Delete(old_file);
                }
                File.Replace(new_file, filename, old_file);
            }
            // We have to restart the game for this to take effect.
            Loader.Restart_App();
            yield break;
        }
예제 #3
0
        /// <summary>
        /// Updates the isURLmissing parameter.
        /// If the URL returns 404 or the connection is broken, it's missing. Else, we suppose it's fine.
        /// This should or can be used along with web async instance's isURLcheckingCompleted parameter
        /// inside a IEnumerator method capable of yield return for it, although it's mostly for clarity.
        /// Here's an usage example:
        ///
        /// WebAsync webAsync = new WebAsync(); StartCoroutine( webAsync.CheckForMissingURL(url) );
        /// while (! webAsync.isURLcheckingCompleted) yield return null;
        /// bool result = webAsync.isURLmissing;
        ///
        /// </summary>
        /// <param name='url'>
        /// A fully formated URL.
        /// </param>
        public IEnumerator CheckForMissingURL(string url)
        {
            isURLcheckingCompleted = false;
            isURLmissing           = false;

            //Uri httpSite = new Uri(url);

            WebRequest webRequest = Updater_Base.CreateRequest(url);

            //WebRequest webRequest = WebRequest.Create(httpSite);

            // We need no more than HTTP's head
            webRequest.Method = "HEAD";

            // Get the request's reponse
            requestState = null;

            // Manually iterate IEnumerator, because Unity can't do it (and this does not inherit StartCoroutine from MonoBehaviour)
            IEnumerator e = GetResponse(webRequest);

            while (e.MoveNext())
            {
                yield return(e.Current);
            }
            while (!isResponseCompleted)
            {
                yield return(null);                         // this while is just to be sure and clear
            }
            // Deal up with the results
            if (requestState.errorMessage != null)
            {
                if (requestState.errorMessage.Contains("404") || requestState.errorMessage.Contains("NameResolutionFailure"))
                {
                    isURLmissing = true;
                }
                else
                {
                    Debug.LogError("[WebAsync] Error trying to verify if URL '" + url + "' exists: " + requestState.errorMessage);
                }
            }

            isURLcheckingCompleted = true;
        }