コード例 #1
0
 public async Task SwitchToVersion(ByondVersion version)
 {
     if (version.Equals(getVersion()))
     {
         logger.LogInformation($"Server is on {version.Major}.{version.Minor} version. No switch is needed.");
         return;
     }
     if (!Directory.Exists(GetByondDirectoryPath(version)))
     {
         logger.LogInformation($"Version {version.Major}.{version.Minor} is not installed. Downloading and installing...");
         await DownloadByond(version);
     }
     if (!getVersion(GetByondDirectoryPath(version)).Equals(version))
     {
         throw new Exception($"Byond version '{version.Major}.{version.Minor}' data mismatches folder name or ByondVersion data. Please manually remove this version.");
     }
     if (Directory.Exists(GetByondDirectoryPath()))
     {
         Directory.Delete(GetByondDirectoryPath());
     }
     FileSystemHelper.CreateRelativeSymbolicLink(GetByondDirectoryPath(version), GetByondDirectoryPath(), Emet.FileSystems.FileType.Directory);
     if (!version.Equals(getVersion()))
     {
         throw new Exception($"Byond version switch failed.");
     }
 }
コード例 #2
0
 public async Task DownloadByond(ByondVersion version)
 {
     using (var response = await httpclient.SendAsync(new HttpRequestMessage(HttpMethod.Get, GetDownloadUrl(version))))
         using (var stream = await response.Content.ReadAsStreamAsync())
             using (var archive = new ZipArchive(stream, ZipArchiveMode.Read))
                 archive.ExtractToDirectory(GetByondDirectoryPath(version), true);
     using (var versionData = File.Create(GetByondDirectoryPath(version, "version.dat")))
         version.WriteTo(versionData);
 }
コード例 #3
0
        /// <inheritdoc />
        public string GetVersion(ByondVersion type)
        {
            try
            {
                lock (ByondLock)
                {
                    if (type == ByondVersion.Latest)
                    {
                        //get the latest version from the website
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ByondLatestURL);
                        var            results = new List <string>();
                        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        {
                            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            {
                                string html = reader.ReadToEnd();

                                Regex           regex   = new Regex("\\\"([^\"]*)\\\"");
                                MatchCollection matches = regex.Matches(html);
                                foreach (Match match in matches)
                                {
                                    if (match.Success && match.Value.Contains("_byond.exe"))
                                    {
                                        results.Add(match.Value.Replace("\"", "").Replace("_byond.exe", ""));
                                    }
                                }
                            }
                        }
                        results.Sort();
                        results.Reverse();
                        return(results.Count > 0 ? results[0] : null);
                    }
                    else
                    {
                        string DirToUse = RelativePath(type == ByondVersion.Staged ? StagingDirectoryInner : ByondDirectory);
                        if (Directory.Exists(DirToUse))
                        {
                            string file = DirToUse + VersionFile;
                            if (File.Exists(file))
                            {
                                return(File.ReadAllText(file));
                            }
                        }
                    }
                    return(null);
                }
            }
            catch (Exception e)
            {
                return("Error: " + e.ToString());
            }
        }
コード例 #4
0
        public async override Task <InstanceStatus> GetStatus(EmptyRequest request, ServerCallContext context)
        {
            switch (request.Auth.Token)
            {
            case "IB":
                var version = new ByondVersion()
                {
                    Major = 512, Minor = 1469
                };
                var byond = serviceProvider.GetRequiredService <ByondService>();
                await byond.SwitchToVersion(version);

                return(new InstanceStatus
                {
                    Message = $"Installed {version}"
                });

            default:
                return(new InstanceStatus
                {
                    Message = $"YOU:{request.Auth.Token}:WE:{DateTime.Now.ToString()}"
                });
            }
        }
コード例 #5
0
 public string GetByondDirectoryPath(ByondVersion version, params string[] extraPaths) => FileSystemHelper.GetPath(globalConfig, extraPaths, config["Dir"], getByondVersionDirectoryName(version));
コード例 #6
0
 private static string getByondVersionDirectoryName(ByondVersion version) => $"{version.Major}.{version.Minor}";
コード例 #7
0
 public static string GetDownloadUrl(ByondVersion version) => GetDownloadUrl(version.Major, version.Minor);