Ejemplo n.º 1
0
        public async Task <Process> Install()
        {
            string version = await GetRemoteBuild();

            if (version == null)
            {
                return(null);
            }
            string tarName = $"vs_server_{version}.tar.gz";
            string address = $"https://cdn.vintagestory.at/gamefiles/stable/{tarName}";
            string tarPath = ServerPath.GetServersServerFiles(_serverData.ServerID, tarName);

            // Download vs_server_{version}.tar.gz from https://cdn.vintagestory.at/gamefiles/stable/
            using (WebClient webClient = new WebClient())
            {
                try { await webClient.DownloadFileTaskAsync(address, tarPath); }
                catch
                {
                    Error = $"Fail to download {tarName}";
                    return(null);
                }
            }

            // Extract vs_server_{version}.tar.gz
            if (!await FileManagement.ExtractTarGZ(tarPath, Directory.GetParent(tarPath).FullName))
            {
                Error = $"Fail to extract {tarName}";
                return(null);
            }

            // Delete vs_server_{version}.tar.gz, leave it if fail to delete
            await FileManagement.DeleteAsync(tarPath);

            return(null);
        }
Ejemplo n.º 2
0
        public string GetLocalBuild(string serverId, string appId)
        {
            string manifestFile = $"appmanifest_{appId}.acf";
            string manifestPath = Path.Combine(ServerPath.GetServersServerFiles(serverId), "steamapps", manifestFile);

            if (!File.Exists(manifestPath))
            {
                Error = $"{manifestFile} is missing.";
                return(string.Empty);
            }

            string text;

            try
            {
                text = File.ReadAllText(manifestPath);
            }
            catch (Exception e)
            {
                Error = $"Fail to get local build {e.Message}";
                return(string.Empty);
            }

            Regex regex   = new Regex("\"buildid\".{1,}\"(.*?)\"");
            var   matches = regex.Matches(text);

            if (matches.Count != 1 || matches[0].Groups.Count != 2)
            {
                Error = $"Fail to get local build";
                return(string.Empty);
            }

            return(matches[0].Groups[1].Value);
        }
Ejemplo n.º 3
0
        public async Task <Process> Install(string serverId, string modName, string appId, bool validate = true, bool loginAnonymous = true)
        {
            SetParameter(ServerPath.GetServersServerFiles(serverId), modName, appId, validate, loginAnonymous);
            Process p = await Run();

            SendEnterPreventFreeze(p);
            return(p);
        }
Ejemplo n.º 4
0
        public async void CreateServerCFG()
        {
            //Download serverconfig.json
            var replaceValues = new List <(string, string)>()
            {
                ("{{ServerName}}", _serverData.ServerName),
                ("{{Port}}", _serverData.ServerPort),
                ("{{MaxClients}}", _serverData.ServerMaxPlayer)
            };

            await Github.DownloadGameServerConfig(ServerPath.GetServersServerFiles(_serverData.ServerID, "data", "serverconfig.json"), FullName, replaceValues);
        }
Ejemplo n.º 5
0
        public string GetLocalBuild()
        {
            // Get local version in VintageStoryServer.exe
            string exePath = ServerPath.GetServersServerFiles(_serverData.ServerID, StartPath);

            if (!File.Exists(exePath))
            {
                Error = $"{StartPath} is missing.";
                return(string.Empty);
            }

            return(FileVersionInfo.GetVersionInfo(exePath).ProductVersion); // return "1.12.14"
        }
Ejemplo n.º 6
0
        // New
        public static async Task <(Process, string)> UpdateEx(string serverId, string appId, bool validate = true, bool loginAnonymous = true, string modName = null, string custom = null, bool embedConsole = true)
        {
            string param = GetParameter(ServerPath.GetServersServerFiles(serverId), appId, validate, loginAnonymous, modName, custom);

            if (param == null)
            {
                return(null, "Steam account not set up");
            }

            string exePath = Path.Combine(_installPath, _exeFile);

            if (!File.Exists(exePath) && !await Download())
            {
                return(null, "Unable to download steamcmd");
            }

            var p = new Process
            {
                StartInfo =
                {
                    WorkingDirectory = _installPath,
                    FileName         = exePath,
                    Arguments        = param,
                    WindowStyle      = ProcessWindowStyle.Minimized,
                    UseShellExecute  = false
                },
                EnableRaisingEvents = true
            };

            if (embedConsole)
            {
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.StandardOutputEncoding = Encoding.UTF8;
                p.StartInfo.StandardErrorEncoding  = Encoding.UTF8;
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
                var serverConsole = new ServerConsole(serverId);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
                return(p, null);
            }

            p.Start();
            return(p, null);
        }
Ejemplo n.º 7
0
        public async Task <Process> Start()
        {
            string exePath = ServerPath.GetServersServerFiles(_serverData.ServerID, StartPath);

            if (!File.Exists(exePath))
            {
                Error = $"{Path.GetFileName(exePath)} not found ({exePath})";
                return(null);
            }

            Process p = new Process
            {
                StartInfo =
                {
                    WorkingDirectory = Directory.GetParent(exePath).FullName,
                    FileName         = exePath,
                    Arguments        = _serverData.ServerParam,
                    WindowStyle      = ProcessWindowStyle.Minimized,
                    UseShellExecute  = false
                },
                EnableRaisingEvents = true
            };

            if (AllowsEmbedConsole)
            {
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
                var serverConsole = new ServerConsole(_serverData.ServerID);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
                return(p);
            }

            p.Start();
            return(p);
        }
Ejemplo n.º 8
0
        public bool IsInstallValid()
        {
            string exePath = ServerPath.GetServersServerFiles(_serverData.ServerID, StartPath);

            return(File.Exists(exePath));
        }
Ejemplo n.º 9
0
        public async Task <Process> Update()
        {
            // Backup the data folder
            string dataPath   = ServerPath.GetServersServerFiles(_serverData.ServerID, "data");
            string tempPath   = ServerPath.GetServers(_serverData.ServerID, "__temp");
            bool   needBackup = Directory.Exists(dataPath);

            if (needBackup)
            {
                if (Directory.Exists(tempPath))
                {
                    if (!await DirectoryManagement.DeleteAsync(tempPath, true))
                    {
                        Error = "Fail to delete the temp folder";
                        return(null);
                    }
                }

                if (!await Task.Run(() =>
                {
                    try
                    {
                        Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(dataPath, tempPath);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Error = e.Message;
                        return(false);
                    }
                }))
                {
                    return(null);
                }
            }

            // Delete the serverfiles folder
            if (!await DirectoryManagement.DeleteAsync(ServerPath.GetServersServerFiles(_serverData.ServerID), true))
            {
                Error = "Fail to delete the serverfiles";
                return(null);
            }

            // Recreate the serverfiles folder
            Directory.CreateDirectory(ServerPath.GetServersServerFiles(_serverData.ServerID));

            if (needBackup)
            {
                // Restore the data folder
                if (!await Task.Run(() =>
                {
                    try
                    {
                        Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(tempPath, dataPath);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Error = e.Message;
                        return(false);
                    }
                }))
                {
                    return(null);
                }

                await DirectoryManagement.DeleteAsync(tempPath, true);
            }

            // Update the server by install again
            await Install();

            // Return is valid
            if (IsInstallValid())
            {
                return(null);
            }

            Error = "Update fail";
            return(null);
        }