mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
Merge pull request #219 from Cyberboss/ReinitStatic
Adds a function to recreate static directories
This commit is contained in:
@@ -9,14 +9,14 @@ namespace TGCommandLine
|
||||
public AdminCommand()
|
||||
{
|
||||
Keyword = "admin";
|
||||
Children = new Command[] { new AdminViewGroupCommand(), new AdminSetGroupCommand(), new AdminClearGroupCommand(), new AdminViewPortCommand(), new AdminSetPortCommand(), new AdminMoveServerCommand() };
|
||||
Children = new Command[] { new AdminViewGroupCommand(), new AdminSetGroupCommand(), new AdminClearGroupCommand(), new AdminViewPortCommand(), new AdminSetPortCommand(), new AdminMoveServerCommand(), new AdminRecreateStaticCommand() };
|
||||
}
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Manage server service authentication";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AdminMoveServerCommand : Command
|
||||
{
|
||||
public AdminMoveServerCommand()
|
||||
@@ -42,6 +42,25 @@ namespace TGCommandLine
|
||||
return "Move the server installation (BYOND, Repo, Game) to a new location. Nothing else may be running for this task to complete";
|
||||
}
|
||||
}
|
||||
class AdminRecreateStaticCommand : Command
|
||||
{
|
||||
public AdminRecreateStaticCommand()
|
||||
{
|
||||
Keyword = "recreate-static-directory";
|
||||
}
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return "Backup the current static directory and repopulate it from the TGS3.json in the repository";
|
||||
}
|
||||
}
|
||||
|
||||
class AdminSetPortCommand : Command
|
||||
{
|
||||
|
||||
Generated
+13
@@ -154,6 +154,7 @@
|
||||
this.StaticFileCreateButton = new System.Windows.Forms.Button();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.StaticFileListBox = new System.Windows.Forms.ListBox();
|
||||
this.RecreateStaticButton = new System.Windows.Forms.Button();
|
||||
this.ChatPanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ChatPortSelector)).BeginInit();
|
||||
this.ChatProviderSelectorPanel.SuspendLayout();
|
||||
@@ -1611,6 +1612,7 @@
|
||||
// StaticPanel
|
||||
//
|
||||
this.StaticPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34)))));
|
||||
this.StaticPanel.Controls.Add(this.RecreateStaticButton);
|
||||
this.StaticPanel.Controls.Add(this.StaticFileDownloadButton);
|
||||
this.StaticPanel.Controls.Add(this.StaticFilesRefreshButton);
|
||||
this.StaticPanel.Controls.Add(this.StaticFileUploadButton);
|
||||
@@ -1725,6 +1727,16 @@
|
||||
this.StaticFileListBox.TabIndex = 0;
|
||||
this.StaticFileListBox.SelectedIndexChanged += new System.EventHandler(this.StaticFileListBox_SelectedIndexChanged);
|
||||
//
|
||||
// RecreateStaticButton
|
||||
//
|
||||
this.RecreateStaticButton.Location = new System.Drawing.Point(471, 6);
|
||||
this.RecreateStaticButton.Name = "RecreateStaticButton";
|
||||
this.RecreateStaticButton.Size = new System.Drawing.Size(144, 22);
|
||||
this.RecreateStaticButton.TabIndex = 33;
|
||||
this.RecreateStaticButton.Text = "Recreate Static Directory";
|
||||
this.RecreateStaticButton.UseVisualStyleBackColor = true;
|
||||
this.RecreateStaticButton.Click += new System.EventHandler(this.RecreateStaticButton_Click);
|
||||
//
|
||||
// Main
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -1887,5 +1899,6 @@
|
||||
private System.Windows.Forms.Button TGSJsonUpdate;
|
||||
private System.Windows.Forms.Button BYONDRefreshButton;
|
||||
private System.Windows.Forms.Button ServerPageRefreshButton;
|
||||
private System.Windows.Forms.Button RecreateStaticButton;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,16 @@ namespace TGControlPanel
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CheckAdminWithWarning()
|
||||
{
|
||||
if (!Server.AuthenticateAdmin())
|
||||
{
|
||||
MessageBox.Show("Only system administrators may use this command!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ServiceDisconnectException(Exception e)
|
||||
{
|
||||
MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString());
|
||||
|
||||
@@ -21,10 +21,14 @@ namespace TGControlPanel
|
||||
string updateError;
|
||||
bool updatingFields = false;
|
||||
|
||||
string DDStatusString = null;
|
||||
void InitServerPage()
|
||||
{
|
||||
LoadServerPage();
|
||||
if (!Server.AuthenticateAdmin())
|
||||
{
|
||||
ServerPathTextbox.Enabled = false;
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
}
|
||||
FullUpdateWorker.RunWorkerCompleted += FullUpdateWorker_RunWorkerCompleted;
|
||||
ServerPathTextbox.LostFocus += ServerPathTextbox_LostFocus;
|
||||
ServerPathTextbox.KeyDown += ServerPathTextbox_KeyDown;
|
||||
@@ -77,9 +81,10 @@ namespace TGControlPanel
|
||||
|
||||
void UpdateServerPath()
|
||||
{
|
||||
if (!Server.AuthenticateAdmin())
|
||||
if (!Program.CheckAdminWithWarning())
|
||||
{
|
||||
MessageBox.Show("Only system administrators may move the server installation");
|
||||
ServerPathTextbox.Enabled = false;
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
return;
|
||||
}
|
||||
if (updatingFields || ServerPathTextbox.Text.Trim() == Server.GetComponent<ITGConfig>().ServerDirectory())
|
||||
@@ -87,6 +92,13 @@ namespace TGControlPanel
|
||||
var DialogResult = MessageBox.Show("This will move the entire server installation.", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult != DialogResult.Yes)
|
||||
return;
|
||||
|
||||
if (!Program.CheckAdminWithWarning())
|
||||
{
|
||||
ServerPathTextbox.Enabled = false;
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
return;
|
||||
}
|
||||
MessageBox.Show(Server.GetComponent<ITGAdministration>().MoveServer(ServerPathTextbox.Text) ?? "Success!");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace TGControlPanel
|
||||
|
||||
void InitStaticPage()
|
||||
{
|
||||
if(!Server.AuthenticateAdmin())
|
||||
RecreateStaticButton.Visible = false;
|
||||
BuildFileList();
|
||||
}
|
||||
|
||||
@@ -317,5 +319,25 @@ namespace TGControlPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RecreateStaticButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Program.CheckAdminWithWarning())
|
||||
{
|
||||
RecreateStaticButton.Visible = false;
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("This will rename the current static directory to a backup and recreate it. Continue?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
return;
|
||||
if (!Program.CheckAdminWithWarning())
|
||||
{
|
||||
RecreateStaticButton.Visible = false;
|
||||
return;
|
||||
}
|
||||
var res = Server.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
BuildFileList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,5 +239,44 @@ namespace TGServerService
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
public string RecreateStaticFolder()
|
||||
{
|
||||
if (!Monitor.TryEnter(RepoLock))
|
||||
return "Repo locked!";
|
||||
try
|
||||
{
|
||||
if (!Monitor.TryEnter(watchdogLock))
|
||||
return "Watchdog locked!";
|
||||
try
|
||||
{
|
||||
if (!Monitor.TryEnter(configLock))
|
||||
return "Static dir locked!";
|
||||
try
|
||||
{
|
||||
if (currentStatus != TGDreamDaemonStatus.Offline)
|
||||
return "Watchdog running!";
|
||||
BackupAndDeleteStaticDirectory();
|
||||
InitialConfigureRepository();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(configLock);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(watchdogLock);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return e.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(RepoLock);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,22 +249,7 @@ namespace TGServerService
|
||||
DeletePRList();
|
||||
lock (configLock)
|
||||
{
|
||||
if (Directory.Exists(StaticDirs))
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
string path = Path.GetDirectoryName(StaticBackupDir);
|
||||
string newFullPath = StaticBackupDir;
|
||||
|
||||
while (File.Exists(newFullPath) || Directory.Exists(newFullPath))
|
||||
{
|
||||
string tempDirName = string.Format("{0}({1})", StaticBackupDir, count++);
|
||||
newFullPath = Path.Combine(path, tempDirName);
|
||||
}
|
||||
|
||||
Program.CopyDirectory(StaticDirs, newFullPath);
|
||||
}
|
||||
Program.DeleteDirectory(StaticDirs);
|
||||
BackupAndDeleteStaticDirectory();
|
||||
}
|
||||
|
||||
var Opts = new CloneOptions()
|
||||
@@ -309,6 +294,26 @@ namespace TGServerService
|
||||
}
|
||||
}
|
||||
|
||||
void BackupAndDeleteStaticDirectory()
|
||||
{
|
||||
if (Directory.Exists(StaticDirs))
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
string path = Path.GetDirectoryName(StaticBackupDir);
|
||||
string newFullPath = StaticBackupDir;
|
||||
|
||||
while (File.Exists(newFullPath) || Directory.Exists(newFullPath))
|
||||
{
|
||||
string tempDirName = string.Format("{0}({1})", StaticBackupDir, count++);
|
||||
newFullPath = Path.Combine(path, tempDirName);
|
||||
}
|
||||
|
||||
Program.CopyDirectory(StaticDirs, newFullPath);
|
||||
}
|
||||
Program.DeleteDirectory(StaticDirs);
|
||||
}
|
||||
|
||||
public string UpdateTGS3Json()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -46,5 +46,12 @@ namespace TGServiceInterface
|
||||
/// <returns>null on success, error message on failure</returns>
|
||||
[OperationContract]
|
||||
string MoveServer(string new_location);
|
||||
|
||||
/// <summary>
|
||||
/// Renames the current static folder to a backup name and recreates is from the current repo using TGS3.json
|
||||
/// </summary>
|
||||
/// <returns>null on success, error message on failure</returns>
|
||||
[OperationContract]
|
||||
string RecreateStaticFolder();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user