예제 #1
0
        private void CheckScriptUpdate()
        {
            DateTime now = DateTime.UtcNow;
            var      updatedScriptData = false;
            var      toUpdate          = new List <UserScript>();
            var      toUpdateTo        = new List <ScriptWithContent>();

            foreach (UserScript s in AllScripts)
            {
                if (!Userscript.UpdateDisabledScripts && !s.Enabled)
                {
                    continue;
                }

                if (!String.IsNullOrWhiteSpace(s.UpdateUrl) && s.InstallDate < now - TimeSpan.FromDays(7))
                {
                    try
                    {
                        var content = ScriptDownloader.DownloadDefendencies(s.UpdateUrl); //SendWebRequest(s.UpdateUrl);
                        if (content == String.Empty)                                      // Request failed, try again later
                        {
                            continue;
                        }
                        var newScript = ParseUserScript.Parse(content, false);

                        if (newScript.Version != s.Version)
                        {
                            var scriptContents = new ScriptWithContent(newScript)
                            {
                                Content = content
                            };
                            toUpdate.Add(s);
                            toUpdateTo.Add(scriptContents);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.w("Script update check failed for: " + s.Name, ex);
                    }
                    s.InstallDate     = now;
                    updatedScriptData = true;
                }
            }

            if (updatedScriptData)
            {
                Save();
            }

            if (toUpdate.Count > 0)
            {
                AskUpdateScriptsAsync(toUpdate, toUpdateTo);
            }
        }
예제 #2
0
        public void InstallScript(string url, string code)
        {
            var x    = ParseUserScript.Parse(code, false);
            var name = Utils.GetFileNameFromUrl(url);

            Utils.WriteFileAsync(ScriptPath + name, code);
            x.Path = ScriptPath + name;
            if (x.Name == String.Empty)
            {
                x.Name = "Userscript from " + url;
            }
            if (String.IsNullOrWhiteSpace(x.UpdateUrl))
            {
                x.UpdateUrl = url;
            }
            AddScript(x);
        }