Beispiel #1
0
 /// <summary>
 /// Logs an exception.
 /// </summary>
 /// <param name="ex">Exception to log.</param>
 /// <param name="customMessage">Message text to log, exception message will be appended.</param>
 public static void Log(this Exception ex, string customMessage = "ERROR: An exception occurred: ")
 {
     ProgramBase.ConsoleWriteColored(ConsoleColor.Red, () =>
     {
         MySandboxGame.Log.WriteLineAndConsole(customMessage + ex.Message);
         MySandboxGame.Log.WriteLineToConsole("Check the log file for details.");
         MySandboxGame.Log.WriteLine(ex.StackTrace);
     });
 }
Beispiel #2
0
 public static void WriteLineError(this MyLog log, string msg)
 {
     ProgramBase.ConsoleWriteColored(ConsoleColor.Red, () =>
                                     log.WriteLineAndConsole(msg));
 }
Beispiel #3
0
 public static void WriteLineWarning(this MyLog log, string msg)
 {
     ProgramBase.ConsoleWriteColored(ConsoleColor.Yellow, () =>
                                     log.WriteLineAndConsole(msg));
 }
Beispiel #4
0
        protected override void AuthenticateWorkshop()
        {
            if (m_useModIO)
            {
                base.AuthenticateWorkshop();

                var config  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var email   = config.AppSettings.Settings["auth-login"]?.Value;
                var token   = config.AppSettings.Settings["auth-token"]?.Value;
                var expires = int.Parse(config.AppSettings.Settings["auth-expires"]?.Value ?? "0");

                if (string.IsNullOrEmpty(email))
                {
                    System.Console.WriteLine(
                        "Authentication to mod.io required." + Environment.NewLine +
                        "This will create an OAuth2 token for your account." + Environment.NewLine +
                        "This is a one-time process, and does NOT require your password." + Environment.NewLine +
                        $"Your email and token will be saved in {config.FilePath}." + Environment.NewLine);
                    ProgramBase.ConsoleWriteColored(ConsoleColor.White,
                                                    "Protect this file." + Environment.NewLine);
                    System.Console.Write("Enter the email associated with your mod.io account: ");
                    email = System.Console.ReadLine();
                }

                if (string.IsNullOrEmpty(token))
                {
                    var clsMyModIo = typeof(VRage.Mod.Io.MyModIoService).Assembly.GetType("VRage.Mod.Io.MyModIo");
                    clsMyModIo.InvokeMember("EmailRequest", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, new object[] { email, (Action <MyGameServiceCallResult>)((r) =>
                        {
                            if (r == MyGameServiceCallResult.OK)
                            {
                                System.Console.WriteLine("Mod.io has sent security code to your email. It expires after 15 minutes.");
                                System.Console.Write("Enter Security code: ");
                                var code = System.Console.ReadLine();

                                clsMyModIo.InvokeMember("EmailExchange", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, new object[] { code, (Action <MyGameServiceCallResult>)((a) =>
                                    {
                                        if (a == MyGameServiceCallResult.OK)
                                        {
                                            System.Console.WriteLine("Authentication successful!");

                                            var accessToken = clsMyModIo.GetField("m_authenticatedToken", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null);
                                            token           = (string)accessToken.GetType().GetField("access_token", BindingFlags.Public | BindingFlags.Instance)?.GetValue(accessToken);
                                            expires         = (int)accessToken.GetType().GetField("date_expires", BindingFlags.Public | BindingFlags.Instance)?.GetValue(accessToken);

                                            config.AppSettings.Settings.Add("auth-login", email);
                                            config.AppSettings.Settings.Add("auth-token", token);
                                            config.AppSettings.Settings.Add("auth-expires", expires.ToString());
                                            config.Save();

                                            MySandboxGame.Log.WriteLineAndConsole($"Your authentication token has been saved in {config.FilePath}. Do not delete or replace this file, or you will need to authenticate again.");
                                            PostAuthentication(token, expires);
                                        }
                                    }) });
                            }
                        }) });
                }
                else
                {
                    PostAuthentication(token, expires);
                }
            }
        }