Merge pull request #421 from stevenh/simple-fixes

Adds -logformat & -logclear command line options
This commit is contained in:
Steven Hartland 2012-03-01 02:18:29 -08:00
commit 5c380f0f6e

View file

@ -40,6 +40,9 @@ namespace TShockAPI
[APIVersion(1, 11)] [APIVersion(1, 11)]
public class TShock : TerrariaPlugin public class TShock : TerrariaPlugin
{ {
private const string LogFormatDefault = "yyyyMMddHHmmss";
private static string LogFormat = LogFormatDefault;
private static bool LogClear = false;
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
public static readonly string VersionCodename = "Squashing bugs, and adding suggestions"; public static readonly string VersionCodename = "Squashing bugs, and adding suggestions";
@ -112,10 +115,20 @@ namespace TShockAPI
Directory.CreateDirectory(SavePath); Directory.CreateDirectory(SavePath);
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
string logFilename;
try
{
logFilename = Path.Combine(SavePath, now.ToString(LogFormat)+".log");
}
catch(Exception)
{
// Problem with the log format use the default
logFilename = Path.Combine(SavePath, now.ToString(LogFormatDefault) + ".log");
}
#if DEBUG #if DEBUG
Log.Initialize(Path.Combine(SavePath, now.ToString("yyyyMMddHHmmss")+".log"), LogLevel.All, false); Log.Initialize(logFilename, LogLevel.All, false);
#else #else
Log.Initialize(Path.Combine(SavePath, now.ToString("yyyyMMddHHmmss")+".log"), LogLevel.All & ~LogLevel.Debug, false); Log.Initialize(logFilename, LogLevel.All & ~LogLevel.Debug, LogClear);
#endif #endif
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
@ -332,30 +345,41 @@ namespace TShockAPI
private void HandleCommandLine(string[] parms) private void HandleCommandLine(string[] parms)
{ {
string path;
for (int i = 0; i < parms.Length; i++) for (int i = 0; i < parms.Length; i++)
{ {
if (parms[i].ToLower() == "-configpath") switch(parms[i].ToLower())
{ {
var path = parms[++i]; case "-configpath":
path = parms[++i];
if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1) if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1)
{ {
SavePath = path; SavePath = path;
Log.ConsoleInfo("Config path has been set to " + path); Log.ConsoleInfo("Config path has been set to " + path);
} }
} break;
if (parms[i].ToLower() == "-worldpath")
{ case "-worldpath":
var path = parms[++i]; path = parms[++i];
if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1) if (path.IndexOfAny(Path.GetInvalidPathChars()) == -1)
{ {
Main.WorldPath = path; Main.WorldPath = path;
Log.ConsoleInfo("World path has been set to " + path); Log.ConsoleInfo("World path has been set to " + path);
} }
} break;
if (parms[i].ToLower() == "-dump")
{ case "-dump":
ConfigFile.DumpDescriptions(); ConfigFile.DumpDescriptions();
Permissions.DumpDescriptions(); Permissions.DumpDescriptions();
break;
case "-logformat":
LogFormat = parms[++i];
break;
case "-logclear":
bool.TryParse(parms[++i], out LogClear);
break;
} }
} }
} }