From 61b9b8779e4a697c375af4731cb76bb351ea2526 Mon Sep 17 00:00:00 2001 From: Maverick Motherfucker Date: Sat, 4 Jun 2011 11:14:39 -0700 Subject: [PATCH] Made groups.txt and users.txt auto appear in save folder --- TShockAPI/FileTools.cs | 19 ++++- TShockAPI/Resources.Designer.cs | 94 +++++++++++++++++++++++ TShockAPI/Resources.resx | 127 ++++++++++++++++++++++++++++++++ TShockAPI/TShockAPI.csproj | 17 +++++ TShockAPI/Tools.cs | 3 +- 5 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 TShockAPI/Resources.Designer.cs create mode 100644 TShockAPI/Resources.resx diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs index 89608f91..7ee5cb11 100644 --- a/TShockAPI/FileTools.cs +++ b/TShockAPI/FileTools.cs @@ -2,6 +2,7 @@ using System.IO; using Terraria; using System.Web; +using System.Runtime.InteropServices; namespace TShockAPI { @@ -49,6 +50,7 @@ namespace TShockAPI tw.WriteLine("[" + Main.player[ply].name + "] [" + Tools.GetRealIP(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint.ToString()) + "]"); tw.Close(); } + /// /// Writes an error message to errors.txt /// @@ -69,6 +71,7 @@ namespace TShockAPI tw.Close(); } } + /// /// Sets up the configuration file for all variables, and creates any missing files. /// @@ -89,8 +92,20 @@ namespace TShockAPI if (!System.IO.File.Exists(SaveDir + "admins.txt")) { FileTools.CreateFile(SaveDir + "admins.txt"); } if (!System.IO.File.Exists(SaveDir + "grief.txt")) { FileTools.CreateFile(SaveDir + "grief.txt"); } if (!System.IO.File.Exists(SaveDir + "whitelist.txt")) { FileTools.CreateFile(SaveDir + "whitelist.txt"); } - if (!System.IO.File.Exists(SaveDir + "groups.txt")) { FileTools.CreateFile(SaveDir + "groups.txt"); } - if (!System.IO.File.Exists(SaveDir + "users.txt")) { FileTools.CreateFile(SaveDir + "users.txt"); } + if (!System.IO.File.Exists(SaveDir + "groups.txt")) + { + FileTools.CreateFile(SaveDir + "groups.txt"); + StreamWriter sw = new StreamWriter(SaveDir + "groups.txt"); + sw.Write(Resources.groups); + sw.Close(); + } + if (!System.IO.File.Exists(SaveDir + "users.txt")) + { + FileTools.CreateFile(SaveDir + "users.txt"); + StreamWriter sw = new StreamWriter(SaveDir + "users.txt"); + sw.Write(Resources.users); + sw.Close(); + } ConfigurationManager.WriteJsonConfiguration(); ConfigurationManager.ReadJsonConfiguration(); Netplay.serverPort = ConfigurationManager.serverPort; diff --git a/TShockAPI/Resources.Designer.cs b/TShockAPI/Resources.Designer.cs new file mode 100644 index 00000000..3f35d45d --- /dev/null +++ b/TShockAPI/Resources.Designer.cs @@ -0,0 +1,94 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TShockAPI { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TShockAPI.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to #Format + ///#name parent permisson1 permission2 permissionN + ///#if there is no parent, put null instead + ///#groups inherit permissions from their parents + ///#put a ! before a permission to negate it + ///#Do not remove the group default + ///#Do not name a group SuperAdmin, that is hard-coded into the code, it grants total permissions + ///#ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP + /// + ///#currently avaliable permissions: kick ban ignorecheatdetection power cfg causeevents spawnboss tp spawnmob cheat kill pvpfun + /// [rest of string was truncated]";. + /// + internal static string groups { + get { + return ResourceManager.GetString("groups", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to #format + ///#ip group + ///#see groups.txt for a list of groups + ///127.0.0.1 superadmin. + /// + internal static string users { + get { + return ResourceManager.GetString("users", resourceCulture); + } + } + } +} diff --git a/TShockAPI/Resources.resx b/TShockAPI/Resources.resx new file mode 100644 index 00000000..6808b1f7 --- /dev/null +++ b/TShockAPI/Resources.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + config\groups.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + config\users.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + \ No newline at end of file diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index d2813301..260d2c98 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -60,11 +60,28 @@ + + True + True + Resources.resx + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index a4cc44d8..1ed867f4 100644 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -379,6 +379,7 @@ namespace TShockAPI } groups.Add(group); } + sr.Close(); } /// @@ -439,7 +440,7 @@ namespace TShockAPI return GetGroup(args[1]); } } - + sr.Close(); return GetGroup("default"); }