diff --git a/TGS.CommandLine/ConfigCommands.cs b/TGS.CommandLine/ConfigCommands.cs index c047d6c3dd..77c47bfaf9 100644 --- a/TGS.CommandLine/ConfigCommands.cs +++ b/TGS.CommandLine/ConfigCommands.cs @@ -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); diff --git a/TGS.ControlPanel/ControlPanel/StaticPage.cs b/TGS.ControlPanel/ControlPanel/StaticPage.cs index 2ef85aeea6..8fef139bc2 100644 --- a/TGS.ControlPanel/ControlPanel/StaticPage.cs +++ b/TGS.ControlPanel/ControlPanel/StaticPage.cs @@ -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 IndexesToPaths = new Dictionary(); + string originalCurrentFileContent; IList EnumeratedPaths = new List() { "" }; bool enumerating = false; /// @@ -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); } } diff --git a/TGS.Interface/Components/Config.cs b/TGS.Interface/Components/Config.cs index 5b33051d0d..2e9409228e 100644 --- a/TGS.Interface/Components/Config.cs +++ b/TGS.Interface/Components/Config.cs @@ -39,11 +39,12 @@ namespace TGS.Interface.Components /// /// The path from the Static dir. E.g. config/config.txt /// The full text of the config file + /// The original data that the client knows about. Set to null to skip checks /// This will be true if error is set to a message that indicates the current user does not have access to the specified file /// null on success, error message on failure /// Along with implied disconnect exceptions, if the file exceeds transfer limits [OperationContract] - string WriteText(string staticRelativePath, string data, out bool unauthorized); + string WriteText(string staticRelativePath, string data, string originalData, out bool unauthorized); /// /// Deletes the target static file diff --git a/TGS.Server/Instance/Config.cs b/TGS.Server/Instance/Config.cs index 788e271241..5eda46466e 100644 --- a/TGS.Server/Instance/Config.cs +++ b/TGS.Server/Instance/Config.cs @@ -99,7 +99,7 @@ namespace TGS.Server } /// - 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); }