Esempio n. 1
0
        /// <summary>
        ///   Resets the application options
        /// </summary>
        /// <param name="hard">Removes everything under the application directory</param>
        internal static void Reset(bool hard = false)
        {
            var nodes = new List <string> {
                Path.Combine(FsManager.GetSafePath(), Options.OptionsFileName)
            };

            if (hard)
            {
                Log.WriteLine(LogLevel.Warning, "performing hard reset!");
                nodes.AddRange(new[] { FsManager.LogsPath, FsManager.PluginPath, FsManager.TemporaryPath }
                               .Select(FsManager.GetSafePath));
            }

            Log.WriteLine(LogLevel.Verbose, $"deleting nodes: {String.Join("; ", nodes)}");
            Exit(0, false);
            Process.Start(Assembly.GetExecutingAssembly().Location,
                          $"--kill {Process.GetCurrentProcess().Id} --rmnodes \"{String.Join("\" \"", nodes)}\"");
            Environment.Exit(0);
        }
        private static void Main(string[] args)
        {
#if DEBUG
            // black magic - tracks unmanaged D2D/D3D objects and prints out unreleased resources at exit
            Configuration.EnableObjectTracking = true;
            ObjectTracker.StackTraceProvider   = () => Environment.StackTrace;
#endif

            HandleCommandLineArgs(args);

            // is another instance of the application currently running?
            // TODO: allow multiple instances with a key switch (i.e. Shift)
            if (Mutex.TryOpenExisting(SingleInstanceMutexName, out Mutex _))
            {
                Environment.Exit(1);
            }

            // create a mutex that will prevent multiple instances of the application to be run
            SingleInstanceMutex = new Mutex(true, SingleInstanceMutexName);

            // Windows Forms setup
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

#if !DEBUG
            System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
            System.Windows.Forms.Application.ThreadException
                += (s, e) => {
                Log.Error("unhandled exception: ${e.Exception}");
                Restart(e.Exception.HResult);
                };
#endif

            // initialize file system manager and log file stream
            Log       = new Logger();
            FsManager = new FsManager();

            try {
                // create/open log file stream
                loggerStream = new FileStream(Path.Combine(FsManager.GetSafePath(FsManager.LogsPath),
                                                           DateTime.UtcNow.ToString("yy.MM.dd") + ".log"),
                                              FileMode.Append);
                Log.Streams.Add(loggerStream);
            } catch (Exception exception) {
                Log.Warn($"could not open logger stream: {exception}");
            }

            // write version info to log
            Log.Info(
                $"{System.Windows.Forms.Application.ProductName} {Version} ({(Environment.Is64BitProcess ? 64 : 32)}-bit)");
            Log.Info($"{Environment.OSVersion} ({(Environment.Is64BitOperatingSystem ? 64 : 32)}-bit)");

            // initialize main components
            Options          = Options.Load() ?? new Options();
            ExtensionManager = new ExtensionManager();

            EnforceIntegratedGraphics();
            InitialSetup();

            TrayIcon      = new TrayIcon();
            UpdateManager = new UpdateManager();

            // global hook behaviours
            DesktopKeyboardHook = new DesktopKeyboardHook();
            DesktopMouseHook    = new DesktopMouseHook();

            // HUD manager depends on the hooks
            HudManager = new HudManager();
            DesktopKeyboardHook.RequestLock();

            // release the mutex when the application is terminated
            System.Windows.Forms.Application.ApplicationExit += (s, e) => {
                lock (SingleInstanceMutex) {
                    SingleInstanceMutex.ReleaseMutex();
                }
            };

            new Workflow {
                Codec    = (typeof(HevcMediaFoundationVideoCodec).FullName, null),
                Handlers = new (string, object)[] { (typeof(FileHandler).FullName, null) },