public override string ToParseable() { return(string.Format("{0},{1},{2},{3},{4},{5}", Command.Replace(",", "%comma;"), Arguments.Replace(",", "%comma;"), WorkingDirectory.Replace(",", "%comma;"), ErrorDialog, WindowStyle, RunOnRelease)); }
private void SetupSerilog() { LoggerConfiguration loggerConfiguration; try { var loggingPath = Path.Combine(WorkingDirectory, "logging.yaml"); if (!File.Exists(loggingPath)) { // First run, logging.yaml doesn't exist yet. // We can't wait for auto-copy from the assembly as it would be too late. using var stream = typeof(AsyncHelper).Assembly.GetManifestResourceStream("OpenMod.Core.logging.yaml"); using var reader = new StreamReader( stream ?? throw new MissingManifestResourceException( "Couldn't find resource: OpenMod.Core.logging.yaml")); var fileContent = reader.ReadToEnd(); File.WriteAllText(loggingPath, fileContent); } var configuration = new ConfigurationBuilder() .SetBasePath(WorkingDirectory) .AddYamlFileEx(s => { s.Path = "logging.yaml"; s.Optional = false; s.Variables = new Dictionary <string, string> { { "workingDirectory", WorkingDirectory.Replace(@"\", @"/") }, { "date", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") } }; s.ResolveFileProvider(); }) .AddEnvironmentVariables() .Build(); loggerConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(configuration); } catch (Exception ex) { var previousColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Failed to setup Serilog; logging will not work correctly."); Console.WriteLine("Setting up console only logging as workaround."); Console.WriteLine("Please fix your logging.yaml file or delete it to restore the default one."); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ForegroundColor = previousColor; loggerConfiguration = new LoggerConfiguration() .WriteTo.Async(c => c.Console()); } var serilogLogger = Log.Logger = loggerConfiguration.CreateLogger(); m_LoggerFactory = new SerilogLoggerFactory(serilogLogger); m_Logger = m_LoggerFactory.CreateLogger <Runtime>(); }
public override void Run(List <Variable> variableList) { foreach (var variable in variableList) { FilePath = FilePath.Replace("@(" + variable.Name + ")", variable.Value); WorkingDirectory = WorkingDirectory.Replace("@(" + variable.Name + ")", variable.Value); } FilePath = Environment.ExpandEnvironmentVariables(FilePath); WorkingDirectory = Environment.ExpandEnvironmentVariables(WorkingDirectory); Console.Write($"Open app {new FileInfo(FilePath).Name} ... "); var newName = FilePath; Process process = new Process(); if (AsFile.Value) { newName = FilePath.Replace(".as", ".app"); process.StartInfo.WorkingDirectory = WorkingDirectory; process.StartInfo.FileName = @$ "/bin/bash"; process.StartInfo.Arguments = $@"-c ""mv {FilePath} {newName}"""; process.StartInfo.Verb = "runas"; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception($@"Converting as file to app failed."); } } process.StartInfo.WorkingDirectory = WorkingDirectory; process.StartInfo.FileName = @$ "/bin/bash"; process.StartInfo.Arguments = $@"-c ""xattr -cr {newName}"""; process.StartInfo.Verb = "runas"; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception($@"Converting as file to app failed."); } var addComand = "-W"; if (!Wait.Value) { addComand = ""; } process.StartInfo.Arguments = $@"-c ""open {addComand} {newName}"""; process.StartInfo.Verb = "runas"; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception($@"open app failed."); } Console.WriteLine("Done"); }
private void SetupSerilog(bool loadFromFile) { #if DEBUG Serilog.Debugging.SelfLog.Enable(s => { Console.WriteLine(s); Debugger.Break(); }); #endif LoggerConfiguration?loggerConfiguration = null; LoggerConfiguration CreateDefaultLoggerConfiguration() { const string c_DefaultConsoleLogTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}][{SourceContext}] {Message:lj}{NewLine}{Exception}"; const string c_DefaultFileLogTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}][{SourceContext}] {Message:lj}{NewLine}{Exception}"; m_DateLogger ??= DateTime.Now; var logFilePath = $"{WorkingDirectory}/logs/openmod-{m_DateLogger:yyyy-MM-dd-HH-mm-ss}.log" .Replace(@"\", "/"); return(new LoggerConfiguration() .WriteTo.Async(c => c.Console(LogEventLevel.Information, c_DefaultConsoleLogTemplate)) .WriteTo.Async(c => c.File(logFilePath, LogEventLevel.Information, outputTemplate: c_DefaultFileLogTemplate))); } if (loadFromFile) { try { Log.CloseAndFlush(); var loggingPath = Path.Combine(WorkingDirectory, "logging.yaml"); if (!File.Exists(loggingPath)) { // First run, logging.yaml doesn't exist yet. // We can't wait for auto-copy from the assembly as it would be too late. using var stream = typeof(AsyncHelper).Assembly.GetManifestResourceStream("OpenMod.Core.logging.yaml"); using var reader = new StreamReader( stream ?? throw new MissingManifestResourceException( "Couldn't find resource: OpenMod.Core.logging.yaml")); var fileContent = reader.ReadToEnd(); File.WriteAllText(loggingPath, fileContent); } m_DateLogger ??= DateTime.Now; var configuration = new ConfigurationBuilder() .SetBasePath(WorkingDirectory) .AddYamlFileEx(s => { s.Path = "logging.yaml"; s.Optional = false; s.Variables = new Dictionary <string, string> { { "workingDirectory", WorkingDirectory.Replace(@"\", "/") }, { "date", m_DateLogger.Value.ToString("yyyy-MM-dd-HH-mm-ss") } }; s.ResolveFileProvider(); }) .AddEnvironmentVariables() .Build(); loggerConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(configuration); } catch (Exception ex) { var previousColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Failed to setup Serilog; logging will not work correctly."); Console.WriteLine("Setting up console only logging as workaround."); Console.WriteLine("Please fix your logging.yaml file or delete it to restore the default one."); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ForegroundColor = previousColor; } } loggerConfiguration ??= CreateDefaultLoggerConfiguration(); var serilogLogger = Log.Logger = loggerConfiguration.CreateLogger(); m_LoggerFactory = new SerilogLoggerFactory(serilogLogger); m_Logger = m_LoggerFactory.CreateLogger <Runtime>(); }