static void Main(string[] args) { SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); var applicationPath = Assembly.GetEntryAssembly().Location; var options = new StartupOptions(Environment.GetCommandLineArgs()); // Allow this to be specified on the command line. var customProgramDataPath = options.GetOption("-programdata"); var appFolderPath = Path.GetDirectoryName(applicationPath); var appPaths = CreateApplicationPaths(appFolderPath, customProgramDataPath); var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Info); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; StartApplication(appPaths, logManager, options); NSApplication.Init(); NSApplication.Main(args); }
private static bool CheckInjectedStatus(Process process) { var log = SimpleLogManager.GetLogger(typeof(Program), "CheckInjectedStatus"); var containsFile = false; process.Refresh(); foreach (ProcessModule module in process.Modules) { if (module.FileName.Contains("HawkeyeInjector")) { containsFile = true; break; } } if (containsFile) { log.Info( $"Successfully injected Hawkeye for process {process.ProcessName} (PID = {process.Id})"); } else { log.Error($"Failed to inject for process {process.ProcessName} (PID = {process.Id})"); } return(containsFile); }
static void Main(string[] args) { OutputType output = (OutputType)getOutputType(); LogManager logManager = SimpleLogManager.getLogManager(output); Console.WriteLine("---START---"); logManager.Log(LogType.INFO, "------------------------A aplicação foi inicializada!------------------------"); logManager.Log(LogType.INFO, $"Tipo de log escolhido - {output}"); logManager.Log(LogType.WARNING, "Gerando um log de Warning"); logManager.Log(LogType.ERROR, "Um erro desconhecido ocorreu no fluxo de execução do programa!"); logManager.Log(LogType.INFO, "------------------------ Fim da Execução! ------------------------"); Console.WriteLine("---END---"); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var logManager = new SimpleLogManager(); using (var gip = new GraphicsInfrastructureProvider(logManager.GetLogger("DXGI"))) { gip.Detect(); } ////using (var detector = new MainDetector(logManager.GetLogger("Dxva"))) ////{ //// detector.DoCodecs(); ////} }
private static void Main(string[] args) { var log = SimpleLogManager.GetLogger(typeof(Program), "Main"); log.Info(string.Format("Command line: {0} {1}", Process.GetCurrentProcess().ProcessName, string.Join(" ", args))); InjectorParameters parameters = null; try { parameters = new InjectorParameters(args); } catch (Exception ex) { log.Error(string.Format( "Wrong command-line arguments: {0}.\r\n{1}", ex.Message, ex)); return; } try { Injector.Launch(parameters); // Make sure we were injected; it not, retry with the main window handle. var process = GetProcessFromWindowHandle(parameters.WindowHandle); if (process != null && !CheckInjectedStatus(process) && process.MainWindowHandle != parameters.WindowHandle) { log.Debug("Could not inject with current handle... retrying with MainWindowHandle"); parameters.WindowHandle = process.MainWindowHandle; Injector.Launch(parameters); CheckInjectedStatus(process); } } catch (Exception ex) { log.Error(string.Format( "There was an error during the injection process: {0}.\r\n{1}", ex.Message, ex)); return; } log.Debug(new string('-', 120)); }
private static Process GetProcessFromWindowHandle(IntPtr windowHandle) { var log = SimpleLogManager.GetLogger(typeof(Program), "GetProcessFromWindowHandle"); IntPtr processId = IntPtr.Zero; GetWindowThreadProcessId(windowHandle, out processId); if (processId == IntPtr.Zero) { log.Error($"could not get process for window handle {windowHandle}"); return(null); } var process = Process.GetProcessById(processId.ToInt32()); if (process == null) { log.Error($"could not get process for PID = {processId}"); return(null); } return(process); }
public static void Main(string[] args) { var applicationPath = Assembly.GetEntryAssembly().Location; SetSqliteProvider(); var options = new StartupOptions(Environment.GetCommandLineArgs()); // Allow this to be specified on the command line. var customProgramDataPath = options.GetOption("-programdata"); var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); _appPaths = appPaths; using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) { _logManager = logManager; var task = logManager.ReloadLogger(LogSeverity.Debug, CancellationToken.None); Task.WaitAll(task); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; RunApplication(appPaths, logManager, options); _logger.Info("Disposing app host"); if (_restartOnShutdown) { StartNewInstance(options); } } }
public static void Main(string[] args) { var applicationPath = Assembly.GetEntryAssembly().Location; var appFolderPath = Path.GetDirectoryName(applicationPath); SetSqliteProvider(); var options = new StartupOptions(Environment.GetCommandLineArgs()); // Allow this to be specified on the command line. var customProgramDataPath = options.GetOption("-programdata"); var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath); var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Info); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; try { RunApplication(appPaths, logManager, options); } finally { logger.Info("Shutting down"); _appHost.Dispose(); } }
public static void Main() { var options = new StartupOptions(Environment.GetCommandLineArgs()); IsRunningAsService = options.ContainsOption("-service"); var currentProcess = Process.GetCurrentProcess(); ApplicationPath = currentProcess.MainModule.FileName; var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86"); var success = SetDllDirectory(architecturePath); SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); _appPaths = appPaths; using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server")) { _logManager = logManager; logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); // Uninstall directly if (options.ContainsOption("-uninstallservice")) { logger.Info("Performing service uninstallation"); UninstallService(ApplicationPath, logger); return; } // Restart with admin rights, then uninstall if (options.ContainsOption("-uninstallserviceasadmin")) { logger.Info("Performing service uninstallation"); RunServiceUninstallation(ApplicationPath); return; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (IsAlreadyRunning(ApplicationPath, currentProcess)) { logger.Info("Shutting down because another instance of Emby Server is already running."); return; } if (PerformUpdateIfNeeded(appPaths, logger)) { logger.Info("Exiting to perform application update."); return; } RunApplication(appPaths, logManager, IsRunningAsService, options); logger.Info("Shutdown complete"); if (_restartOnShutdown) { logger.Info("Starting new server process"); var restartCommandLine = GetRestartCommandLine(); Process.Start(restartCommandLine.Item1, restartCommandLine.Item2); } } }
static void Main() { ApplicationPath = Assembly.GetEntryAssembly().Location; var environmentInfo = GetEnvironmentInfo(); var appPaths = new ApplicationPaths(GetProgramDataPath(ApplicationPath), ApplicationPath); _appPaths = appPaths; using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "theater")) { _logManager = logManager; logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); logger.Info("Application path: {0}", ApplicationPath); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Mutex credit: https://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c/229567 // unique id for global mutex - Global prefix means it is global to the machine string mutexId = string.Format("Global\\{{{0}}}", "EmbyTheater"); // Need a place to store a return value in Mutex() constructor call bool createdNew; // edited by MasonGZhwiti to prevent race condition on security settings via VanNguyen using (var mutex = new Mutex(false, mutexId, out createdNew)) { // edited by acidzombie24 var hasHandle = false; try { // note, you may want to time out here instead of waiting forever // edited by acidzombie24 hasHandle = mutex.WaitOne(5000, false); if (hasHandle == false) { logger.Info("Exiting because another instance is already running."); return; } } catch (AbandonedMutexException) { // Log the fact that the mutex was abandoned in another process, // it will still get acquired hasHandle = true; logger.Info("Mutex was abandoned in another process."); } using (new MutexHandle(mutex, hasHandle, _logger)) { if (PerformUpdateIfNeeded(appPaths, environmentInfo, logger)) { logger.Info("Exiting to perform application update."); return; } RunApplication(appPaths, logManager, environmentInfo, new StartupOptions(Environment.GetCommandLineArgs())); } } logger.Info("Shutdown complete"); if (_restartOnShutdown) { // This is artificial, but add some delay to ensure sockets are released. var delay = environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows ? 5000 : 60000; var task = Task.Delay(delay); Task.WaitAll(task); logger.Info("Starting new server process"); var restartCommandLine = GetRestartCommandLine(); Process.Start(restartCommandLine.Item1, restartCommandLine.Item2); } } }