using Oxide.Core; using System.IO; using Oxide.Core.Libraries.Covalence; using System; using UnityEngine.Networking; using System.Collections; namespace Oxide.Plugins { [Info("WGet", "done6666", "1.0.1")] class WGet : CovalencePlugin { #region globals private static string rootDirectory = Interface.Oxide.RootDirectory; #endregion #region commands [Command("wget")] private void WgetCommand(IPlayer player, string command, string[] args) { if (player.Id != "server_console") return; switch (args.Length) { case 0: Puts("Expecting URL and PATH"); return; case 1: Puts("Expecting PATH"); return; } var url = args[0]; var path = args[1]; if (!validateURL(url)) { Puts("url must be in url format"); return; } ServerMgr.Instance.StartCoroutine(Download(url, path)); } #endregion #region handlers public IEnumerator Download(string url, string path) { Puts("Downloading started."); UnityWebRequest www = UnityWebRequest.Get(url); www.downloadHandler = new DownloadHandlerBuffer(); yield return www.SendWebRequest(); if (www.downloadHandler is DownloadHandlerFile downloadHandlerFile && downloadHandlerFile.data == null) { PrintWarning("Download handler not set up correctly. Check the path and file permissions."); www.Dispose(); yield break; } if (www.result != UnityWebRequest.Result.Success) { PrintWarning($"Failed to download from {url}. Reason: {www.error}"); } else { File.WriteAllBytes(withRoot(path), www.downloadHandler.data); Puts("Download completed!"); } www.Dispose(); } #endregion #region validation static bool validateURL(string url) { return url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase); } static string withRoot(string path) { return rootDirectory + path; } #endregion } }