mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-28 15:40:56 +01:00
Merge pull request #489 from tgstation/482-WarnEdit
Adds a warning if control panel data has changed since being edited
This commit is contained in:
@@ -147,7 +147,7 @@ namespace TGS.CommandLine
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = Instance.Config.WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized);
|
||||
var res = Instance.Config.WriteText(parameters[0], File.ReadAllText(parameters[1]), null, out bool unauthorized);
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc("Error: " + res);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using TGS.Interface;
|
||||
using TGS.Interface.Components;
|
||||
|
||||
namespace TGS.ControlPanel
|
||||
@@ -10,6 +9,7 @@ namespace TGS.ControlPanel
|
||||
partial class ControlPanel
|
||||
{
|
||||
IDictionary<int, string> IndexesToPaths = new Dictionary<int, string>();
|
||||
string originalCurrentFileContent;
|
||||
IList<string> EnumeratedPaths = new List<string>() { "" };
|
||||
bool enumerating = false;
|
||||
/// <summary>
|
||||
@@ -147,7 +147,7 @@ namespace TGS.ControlPanel
|
||||
if (error == null)
|
||||
try
|
||||
{
|
||||
error = Instance.Config.WriteText(FileName, fileContents, out bool unauthorized);
|
||||
error = Instance.Config.WriteText(FileName, fileContents, null, out bool unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -237,7 +237,7 @@ namespace TGS.ControlPanel
|
||||
if (resu == DialogResult.Yes)
|
||||
FullFileName = Path.Combine(FullFileName, "__TGS3_CP_DIRECTORY_CREATOR__");
|
||||
var config = Instance.Config;
|
||||
var res = config.WriteText(FullFileName, "", out bool unauthorized);
|
||||
var res = config.WriteText(FullFileName, "", null, out bool unauthorized);
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
if (resu == DialogResult.Yes)
|
||||
@@ -255,7 +255,9 @@ namespace TGS.ControlPanel
|
||||
bool unauthorized;
|
||||
try
|
||||
{
|
||||
res = Instance.Config.WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized);
|
||||
res = Instance.Config.WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, originalCurrentFileContent, out unauthorized);
|
||||
if (res == null)
|
||||
originalCurrentFileContent = StaticFileEditTextbox.Text;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -325,6 +327,7 @@ namespace TGS.ControlPanel
|
||||
else
|
||||
{
|
||||
StaticFileEditTextbox.ReadOnly = false;
|
||||
originalCurrentFileContent = entry;
|
||||
StaticFileEditTextbox.Text = entry.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@ namespace TGS.Interface.Components
|
||||
/// </summary>
|
||||
/// <param name="staticRelativePath">The path from the Static dir. E.g. config/config.txt</param>
|
||||
/// <param name="data">The full text of the config file</param>
|
||||
/// <param name="originalData">The original data that the client knows about. Set to null to skip checks</param>
|
||||
/// <param name="unauthorized">This will be true if error is set to a message that indicates the current user does not have access to the specified file</param>
|
||||
/// <returns>null on success, error message on failure</returns>
|
||||
/// <exception cref="CommunicationException">Along with implied disconnect exceptions, if the file exceeds transfer limits</exception>
|
||||
[OperationContract]
|
||||
string WriteText(string staticRelativePath, string data, out bool unauthorized);
|
||||
string WriteText(string staticRelativePath, string data, string originalData, out bool unauthorized);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the target static file
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace TGS.Server
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string WriteText(string staticRelativePath, string data, out bool unauthorized)
|
||||
public string WriteText(string staticRelativePath, string data, string originalData, out bool unauthorized)
|
||||
{
|
||||
var path = RelativePath(StaticDirs) + '/' + staticRelativePath; //do not use path.combine or it will try and take the root
|
||||
try
|
||||
@@ -129,6 +129,11 @@ namespace TGS.Server
|
||||
|
||||
using (Server.BeginImpersonation())
|
||||
{
|
||||
if (originalData != null && File.ReadAllText(path) != originalData)
|
||||
{
|
||||
unauthorized = false;
|
||||
return "File has changed since being initially read. Please refresh!";
|
||||
}
|
||||
Directory.CreateDirectory(destdir);
|
||||
File.WriteAllText(path, data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user