Readded Program.cs Logging commands but with Obsolete attribute

This commit is contained in:
ClxS 2016-03-06 15:54:09 +00:00
parent ff96bba617
commit 55b5770718
1 changed files with 97 additions and 35 deletions

View File

@ -72,7 +72,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex); StardewModdingAPI.Log.Error("Could not create a missing ModPath: " + ModPath + "\n\n" + ex);
} }
} }
//Same for content //Same for content
@ -85,7 +85,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex); StardewModdingAPI.Log.Error("Could not create a missing ModContentPath: " + ModContentPath + "\n\n" + ex);
} }
} }
//And then make sure we have an errorlog dir //And then make sure we have an errorlog dir
@ -96,15 +96,15 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex); StardewModdingAPI.Log.Error("Could not create the missing ErrorLogs path: " + LogPath + "\n\n" + ex);
} }
Log.Info("Initializing SDV Assembly..."); StardewModdingAPI.Log.Info("Initializing SDV Assembly...");
if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe")) if (!File.Exists(ExecutionPath + "\\Stardew Valley.exe"))
{ {
//If the api isn't next to SDV.exe then terminate. Though it'll crash before we even get here w/o sdv.exe. Perplexing. //If the api isn't next to SDV.exe then terminate. Though it'll crash before we even get here w/o sdv.exe. Perplexing.
Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe"); StardewModdingAPI.Log.Error("Could not find: " + ExecutionPath + "\\Stardew Valley.exe");
Log.Error("The API will now terminate."); StardewModdingAPI.Log.Error("The API will now terminate.");
Console.ReadKey(); Console.ReadKey();
Environment.Exit(-4); Environment.Exit(-4);
} }
@ -120,14 +120,14 @@ namespace StardewModdingAPI
{ {
foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll"))
{ {
Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s); StardewModdingAPI.Log.Success(ConsoleColor.Green, "Found Stardew Injector DLL: " + s);
try try
{ {
Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs
if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0)
{ {
Log.Success("Loading Injector DLL..."); StardewModdingAPI.Log.Success("Loading Injector DLL...");
TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod));
Mod m = (Mod)mod.CreateInstance(tar.ToString()); Mod m = (Mod)mod.CreateInstance(tar.ToString());
Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description);
@ -137,12 +137,12 @@ namespace StardewModdingAPI
} }
else else
{ {
Log.Error("Invalid Mod DLL"); StardewModdingAPI.Log.Error("Invalid Mod DLL");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
} }
} }
} }
@ -188,12 +188,12 @@ namespace StardewModdingAPI
#endregion #endregion
//Change the game's version //Change the game's version
Log.Info("Injecting New SDV Version..."); StardewModdingAPI.Log.Info("Injecting New SDV Version...");
Game1.version += "-Z_MODDED | SMAPI " + Version; Game1.version += "-Z_MODDED | SMAPI " + Version;
//Create the thread for the game to run in. //Create the thread for the game to run in.
gameThread = new Thread(RunGame); gameThread = new Thread(RunGame);
Log.Info("Starting SDV..."); StardewModdingAPI.Log.Info("Starting SDV...");
gameThread.Start(); gameThread.Start();
//I forget. //I forget.
@ -205,10 +205,10 @@ namespace StardewModdingAPI
} }
//SDV is running //SDV is running
Log.Comment("SDV Loaded Into Memory"); StardewModdingAPI.Log.Comment("SDV Loaded Into Memory");
//Create definition to listen for input //Create definition to listen for input
Log.Verbose("Initializing Console Input Thread..."); StardewModdingAPI.Log.Verbose("Initializing Console Input Thread...");
consoleInputThread = new Thread(ConsoleInputThread); consoleInputThread = new Thread(ConsoleInputThread);
//The only command in the API (at least it should be, for now)\ //The only command in the API (at least it should be, for now)\
@ -228,7 +228,7 @@ namespace StardewModdingAPI
#endif #endif
//Do tweaks using winforms invoke because I'm lazy //Do tweaks using winforms invoke because I'm lazy
Log.Verbose("Applying Final SDV Tweaks..."); StardewModdingAPI.Log.Verbose("Applying Final SDV Tweaks...");
StardewInvoke(() => StardewInvoke(() =>
{ {
gamePtr.IsMouseVisible = false; gamePtr.IsMouseVisible = false;
@ -237,10 +237,10 @@ namespace StardewModdingAPI
}); });
//Game's in memory now, send the event //Game's in memory now, send the event
Log.Verbose("Game Loaded"); StardewModdingAPI.Log.Verbose("Game Loaded");
Events.GameEvents.InvokeGameLoaded(); Events.GameEvents.InvokeGameLoaded();
Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help <cmd>' for a command's usage"); StardewModdingAPI.Log.Comment(ConsoleColor.Cyan, "Type 'help' for help, or 'help <cmd>' for a command's usage");
//Begin listening to input //Begin listening to input
consoleInputThread.Start(); consoleInputThread.Start();
@ -255,8 +255,8 @@ namespace StardewModdingAPI
if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running) if (consoleInputThread != null && consoleInputThread.ThreadState == ThreadState.Running)
consoleInputThread.Abort(); consoleInputThread.Abort();
Log.Verbose("Game Execution Finished"); StardewModdingAPI.Log.Verbose("Game Execution Finished");
Log.Verbose("Shutting Down..."); StardewModdingAPI.Log.Verbose("Shutting Down...");
Thread.Sleep(100); Thread.Sleep(100);
/* /*
int time = 0; int time = 0;
@ -282,14 +282,14 @@ namespace StardewModdingAPI
public static void RunGame() public static void RunGame()
{ {
Application.ThreadException += Log.Application_ThreadException; Application.ThreadException += StardewModdingAPI.Log.Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += Log.CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += StardewModdingAPI.Log.CurrentDomain_UnhandledException;
try try
{ {
gamePtr = new SGame(); gamePtr = new SGame();
Log.Verbose("Patching SDV Graphics Profile..."); StardewModdingAPI.Log.Verbose("Patching SDV Graphics Profile...");
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
LoadMods(); LoadMods();
@ -319,7 +319,7 @@ namespace StardewModdingAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Game failed to start: " + ex); StardewModdingAPI.Log.Error("Game failed to start: " + ex);
} }
} }
@ -338,7 +338,7 @@ namespace StardewModdingAPI
public static void LoadMods() public static void LoadMods()
{ {
Log.Verbose("LOADING MODS"); StardewModdingAPI.Log.Verbose("LOADING MODS");
int loadedMods = 0; int loadedMods = 0;
foreach (string ModPath in ModPaths) foreach (string ModPath in ModPaths)
{ {
@ -346,14 +346,14 @@ namespace StardewModdingAPI
{ {
if (s.Contains("StardewInjector")) if (s.Contains("StardewInjector"))
continue; continue;
Log.Success("Found DLL: " + s); StardewModdingAPI.Log.Success("Found DLL: " + s);
try try
{ {
Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs
if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0)
{ {
Log.Verbose("Loading Mod DLL..."); StardewModdingAPI.Log.Verbose("Loading Mod DLL...");
TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod));
Mod m = (Mod)mod.CreateInstance(tar.ToString()); Mod m = (Mod)mod.CreateInstance(tar.ToString());
Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); Console.WriteLine("LOADED MOD: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description);
@ -362,16 +362,16 @@ namespace StardewModdingAPI
} }
else else
{ {
Log.Error("Invalid Mod DLL"); StardewModdingAPI.Log.Error("Invalid Mod DLL");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s); StardewModdingAPI.Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, s);
} }
} }
} }
Log.Success("LOADED {0} MODS", loadedMods); StardewModdingAPI.Log.Success("LOADED {0} MODS", loadedMods);
} }
public static void ConsoleInputThread() public static void ConsoleInputThread()
@ -386,7 +386,7 @@ namespace StardewModdingAPI
static void Events_LoadContent(object o, EventArgs e) static void Events_LoadContent(object o, EventArgs e)
{ {
Log.Info("Initializing Debug Assets..."); StardewModdingAPI.Log.Info("Initializing Debug Assets...");
DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); DebugPixel = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);
DebugPixel.SetData(new Color[] { Color.White }); DebugPixel.SetData(new Color[] { Color.White });
@ -422,7 +422,7 @@ namespace StardewModdingAPI
static void Events_MenuChanged(IClickableMenu newMenu) static void Events_MenuChanged(IClickableMenu newMenu)
{ {
Log.Verbose("NEW MENU: " + newMenu.GetType()); StardewModdingAPI.Log.Verbose("NEW MENU: " + newMenu.GetType());
if (newMenu is GameMenu) if (newMenu is GameMenu)
{ {
Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu); Game1.activeClickableMenu = SGameMenu.ConstructFromBaseClass(Game1.activeClickableMenu as GameMenu);
@ -461,17 +461,79 @@ namespace StardewModdingAPI
{ {
Command fnd = Command.FindCommand(e.Command.CalledArgs[0]); Command fnd = Command.FindCommand(e.Command.CalledArgs[0]);
if (fnd == null) if (fnd == null)
Log.Error("The command specified could not be found"); StardewModdingAPI.Log.Error("The command specified could not be found");
else else
{ {
if (fnd.CommandArgs.Length > 0) if (fnd.CommandArgs.Length > 0)
Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular()); StardewModdingAPI.Log.Info("{0}: {1} - {2}", fnd.CommandName, fnd.CommandDesc, fnd.CommandArgs.ToSingular());
else else
Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc); StardewModdingAPI.Log.Info("{0}: {1}", fnd.CommandName, fnd.CommandDesc);
} }
} }
else else
Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular()); StardewModdingAPI.Log.Info("Commands: " + Command.RegisteredCommands.Select(x => x.CommandName).ToSingular());
} }
#region Logging
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void Log(object o, params object[] format)
{
StardewModdingAPI.Log.Info(o, format);
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogColour(ConsoleColor c, object o, params object[] format)
{
StardewModdingAPI.Log.Info(o, format);
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogInfo(object o, params object[] format)
{
StardewModdingAPI.Log.Info(o, format);
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogError(object o, params object[] format)
{
StardewModdingAPI.Log.Error(o, format);
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogDebug(object o, params object[] format)
{
StardewModdingAPI.Log.Debug(o, format);
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogValueNotSpecified()
{
StardewModdingAPI.Log.Error("<value> must be specified");
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogObjectValueNotSpecified()
{
StardewModdingAPI.Log.Error("<object> and <value> must be specified");
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogValueInvalid()
{
StardewModdingAPI.Log.Error("<value> is invalid");
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogObjectInvalid()
{
StardewModdingAPI.Log.Error("<object> is invalid");
}
[Obsolete("This method is obsolete and will be removed in v0.39, please use the appropriate methods in the Log class")]
public static void LogValueNotInt32()
{
StardewModdingAPI.Log.Error("<value> must be a whole number (Int32)");
}
#endregion
} }
} }