예제 #1
0
        private void PluginUpdate(UpdateArgs args)
        {
            Updates++;
            if(args.Success && String.IsNullOrEmpty(args.Error))
            {
                invoker.SendSuccessMessage(String.Format("{0} was downloaded successfully.", args.Plugin.Name));
            }
            else if(args.Success)
            {
                invoker.SendSuccessMessage(String.Format("{0} was skipped. Reason: {1}", args.Plugin.Name, args.Error));
            }
            else
            {
                invoker.SendSuccessMessage(String.Format("{0} failed to downloaded. Error: {1}", args.Plugin.Name, args.Error));
            }

            if(Updates >= Terraria.ProgramServer.Plugins.Count)
            {
                PluginVersionCheck.PluginUpdate -= PluginUpdate;

                invoker.SendSuccessMessage("All plugins have been downloaded.  Now copying them to the plugin folder...");

                string folder = Path.Combine(TShock.SavePath, "UpdatedPlugins");
                string dest = Path.Combine(TShock.SavePath, "..", "ServerPlugins");

                foreach (string dir in Directory.GetDirectories(folder, "*", System.IO.SearchOption.AllDirectories))
                {
                    string new_folder = dest + dir.Substring(folder.Length);
                    if (!Directory.Exists(new_folder))
                        Directory.CreateDirectory(new_folder);
                }

                foreach (string file_name in Directory.GetFiles(folder, "*.*", System.IO.SearchOption.AllDirectories))
                {
                    TSPlayer.Server.SendSuccessMessage(String.Format("Copied {0}", file_name));
                    File.Copy(file_name, dest + file_name.Substring(folder.Length), true);
                }

                Directory.Delete(folder, true);

                invoker.SendSuccessMessage("All plugins have been processed.  Restart the server to have access to the new plugins.");
            }
        }
예제 #2
0
        public static void CheckPlugin(object p)
        {
            TerrariaPlugin plugin = (TerrariaPlugin)p;
            UpdateArgs args = new UpdateArgs {Plugin = plugin, Success = true, Error = ""};
            List<string> files = new List<string>();

            try
            {
                if (!String.IsNullOrEmpty(plugin.UpdateURL))
                {
                    var request = HttpWebRequest.Create(plugin.UpdateURL);
                    VersionInfo vi;

                    request.Timeout = 5000;
                    using (var response = request.GetResponse())
                    {
                        using (var reader = new StreamReader(response.GetResponseStream()))
                        {
                            vi = JsonConvert.DeserializeObject<VersionInfo>(reader.ReadToEnd());
                        }
                    }

                    System.Version v = System.Version.Parse((vi.version.ToString()));

                    if (!v.Equals(plugin.Version))
                    {
                        DownloadPackage pkg;
                        request = HttpWebRequest.Create(vi.url);

                        request.Timeout = 5000;
                        using (var response = request.GetResponse())
                        {
                            using (var reader = new StreamReader(response.GetResponseStream()))
                            {
                                pkg = JsonConvert.DeserializeObject<DownloadPackage>(reader.ReadToEnd());
                            }
                        }

                        foreach (PluginFile f in pkg.files)
                        {
                            using (WebClient Client = new WebClient())
                            {
                                string dir = Path.Combine(TShock.SavePath, "UpdatedPlugins");
                                if (!Directory.Exists(dir))
                                    Directory.CreateDirectory(dir);

                                Client.DownloadFile(f.url,
                                                    Path.Combine(dir, f.destination));

                                files.Add(Path.Combine(dir, f.destination));
                            }
                        }
                    }
                    else
                    {
                        args.Error = "Plugin is up to date.";
                    }
                }
                else
                {
                    args.Error = "Plugin has no updater recorded.";
                }
            }
            catch(Exception e)
            {
                args.Success = false;
                args.Error = e.Message;
                if(files.Count > 0)
                {
                    foreach(string s in files)
                    {
                        File.Delete(s);
                    }
                }
            }

            OnPluginUpdate(args);
        }
예제 #3
0
        public static void OnPluginUpdate(UpdateArgs args)
        {
            if (PluginUpdate == null)
            {
                return;
            }

            PluginUpdate(args);
        }
예제 #4
0
        public static void CheckPlugin(object p)
        {
            TerrariaPlugin plugin = (TerrariaPlugin)p;
            UpdateArgs     args   = new UpdateArgs {
                Plugin = plugin, Success = true, Error = ""
            };
            List <string> files = new List <string>();

            try
            {
                if (!String.IsNullOrEmpty(plugin.UpdateURL))
                {
                    var         request = HttpWebRequest.Create(plugin.UpdateURL);
                    VersionInfo vi;

                    request.Timeout = 5000;
                    using (var response = request.GetResponse())
                    {
                        using (var reader = new StreamReader(response.GetResponseStream()))
                        {
                            vi = JsonConvert.DeserializeObject <VersionInfo>(reader.ReadToEnd());
                        }
                    }

                    System.Version v = System.Version.Parse((vi.version.ToString()));

                    if (!v.Equals(plugin.Version))
                    {
                        DownloadPackage pkg;
                        request = HttpWebRequest.Create(vi.url);

                        request.Timeout = 5000;
                        using (var response = request.GetResponse())
                        {
                            using (var reader = new StreamReader(response.GetResponseStream()))
                            {
                                pkg = JsonConvert.DeserializeObject <DownloadPackage>(reader.ReadToEnd());
                            }
                        }

                        foreach (PluginFile f in pkg.files)
                        {
                            using (WebClient Client = new WebClient())
                            {
                                string dir = Path.Combine(TShock.SavePath, "UpdatedPlugins");
                                if (!Directory.Exists(dir))
                                {
                                    Directory.CreateDirectory(dir);
                                }

                                Client.DownloadFile(f.url,
                                                    Path.Combine(dir, f.destination));

                                files.Add(Path.Combine(dir, f.destination));
                            }
                        }
                    }
                    else
                    {
                        args.Error = "Plugin is up to date.";
                    }
                }
                else
                {
                    args.Error = "Plugin has no updater recorded.";
                }
            }
            catch (Exception e)
            {
                args.Success = false;
                args.Error   = e.Message;
                if (files.Count > 0)
                {
                    foreach (string s in files)
                    {
                        File.Delete(s);
                    }
                }
            }

            OnPluginUpdate(args);
        }