コード例 #1
0
ファイル: App.xaml.cs プロジェクト: mmalewski/VidCoder
        protected override void OnStartup(StartupEventArgs e)
        {
#if !DEBUG
            this.DispatcherUnhandledException += this.OnDispatcherUnhandledException;
#endif
            base.OnStartup(e);

            OperatingSystem OS = Environment.OSVersion;
            if (OS.Version.Major <= 5)
            {
                MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
                MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
                this.Shutdown();
                return;
            }

#if PSEUDOLOCALIZER_ENABLED
            Delay.PseudoLocalizer.Enable(typeof(CommonRes));
            Delay.PseudoLocalizer.Enable(typeof(MainRes));
            Delay.PseudoLocalizer.Enable(typeof(EnumsRes));
            Delay.PseudoLocalizer.Enable(typeof(EncodingRes));
            Delay.PseudoLocalizer.Enable(typeof(OptionsRes));
            Delay.PseudoLocalizer.Enable(typeof(PreviewRes));
            Delay.PseudoLocalizer.Enable(typeof(LogRes));
            Delay.PseudoLocalizer.Enable(typeof(SubtitleRes));
            Delay.PseudoLocalizer.Enable(typeof(QueueTitlesRes));
            Delay.PseudoLocalizer.Enable(typeof(ChapterMarkersRes));
            Delay.PseudoLocalizer.Enable(typeof(MiscRes));
#endif

            JsonSettings.SetDefaultSerializationSettings();

            // Takes about 50ms
            Config.EnsureInitialized(Database.Connection);

            var interfaceLanguageCode = Config.InterfaceLanguageCode;
            if (!string.IsNullOrWhiteSpace(interfaceLanguageCode))
            {
                var cultureInfo = new CultureInfo(interfaceLanguageCode);
                Thread.CurrentThread.CurrentCulture       = cultureInfo;
                Thread.CurrentThread.CurrentUICulture     = cultureInfo;
                CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
                CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
            }

            if (Config.UseCustomPreviewFolder && FileUtilities.HasWriteAccessOnFolder(Config.PreviewOutputFolder))
            {
                Environment.SetEnvironmentVariable("TMP", Config.PreviewOutputFolder, EnvironmentVariableTarget.Process);
                FileUtilities.OverrideTempFolder = true;
                FileUtilities.TempFolderOverride = Config.PreviewOutputFolder;
            }

            var updater = Ioc.Get <IUpdater>();
            updater.HandlePendingUpdate();

            try
            {
                // Check if we're a secondary instance
                IsPrimaryInstance = mutex.WaitOne(TimeSpan.Zero, true);
            }
            catch (AbandonedMutexException)
            {
            }

            this.GlobalInitialize();

            var mainVM = new MainViewModel();
            Ioc.Get <IWindowManager>().OpenWindow(mainVM);
            mainVM.OnLoaded();

            if (e.Args.Length > 0)
            {
                mainVM.HandlePaths(new List <string> {
                    e.Args[0]
                });
            }

            if (!Utilities.IsPortable && IsPrimaryInstance)
            {
                AutomationHost.StartListening();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ncxj/VidCoder
        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 2)
                {
                    PrintUsage();
                    return;
                }

                int parentProcId;
                if (!int.TryParse(args[0], out parentProcId))
                {
                    PrintUsage();
                    return;
                }

                JsonSettings.SetDefaultSerializationSettings();

                PipeName = args[1];

                parentCheckTimer           = new System.Timers.Timer();
                parentCheckTimer.Interval  = ParentCheckInterval;
                parentCheckTimer.AutoReset = true;
                parentCheckTimer.Elapsed  += (o, e) =>
                {
                    try
                    {
                        if (!ProcessExists(parentProcId))
                        {
                            // If we couldn't stop the process, just wait until next tick. May have not started yet or may
                            // already be in the process of closing.
                            if (HandBrakeWorker.CurrentWorker != null && HandBrakeWorker.CurrentWorker.StopEncodeIfPossible())
                            {
                                // If we are able to stop the encode, we will do so. Cleanup should
                                // happen with the encode complete callback.
                                Console.WriteLine("Parent no longer exists, stopping encode.");
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        WorkerErrorLogger.LogError("Exception in parentCheckTimer.Elapsed: " + exception.ToString(), isError: true);
                        throw;
                    }
                };

                parentCheckTimer.Start();

                ServiceHost host = null;
                try
                {
                    host = new ServiceHost(typeof(HandBrakeWorker));

                    host.AddServiceEndpoint(
                        typeof(IHandBrakeWorker),
                        new NetNamedPipeBinding(),
                        "net.pipe://localhost/" + PipeName);

                    host.Open();

                    encodeComplete = new ManualResetEventSlim(false);
                    Console.WriteLine("Service state is " + host.State + " on pipe " + PipeName);
                    encodeComplete.Wait();

                    host.Close();
                }
                catch (CommunicationException exception)
                {
                    WorkerErrorLogger.LogError("Exception when trying to establish pipe service: " + exception, isError: true);
                    if (host != null)
                    {
                        host.Abort();
                    }
                }
                catch (TimeoutException exception)
                {
                    WorkerErrorLogger.LogError("Exception when trying to establish pipe service: " + exception, isError: true);
                    if (host != null)
                    {
                        host.Abort();
                    }
                }
                catch (Exception)
                {
                    if (host != null)
                    {
                        host.Abort();
                    }

                    throw;
                }
            }
            catch (Exception exception)
            {
                WorkerErrorLogger.LogError("Exception in Main: " + exception, isError: true);
                throw;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: tyronebj/VidCoder
        static async Task Main(string[] args)
        {
            try
            {
                ////Debugger.Launch();

                if (args.Length < 3)
                {
                    PrintUsage();
                    return;
                }

                int parentProcId;
                if (!int.TryParse(args[0], out parentProcId))
                {
                    PrintUsage();
                    return;
                }

                JsonSettings.SetDefaultSerializationSettings();

                PipeName = args[1];

                var action = (HandBrakeWorkerAction)Enum.Parse(typeof(HandBrakeWorkerAction), args[2]);

                parentCheckTimer           = new System.Timers.Timer();
                parentCheckTimer.Interval  = ParentCheckInterval;
                parentCheckTimer.AutoReset = true;
                parentCheckTimer.Elapsed  += (o, e) =>
                {
                    try
                    {
                        if (!ProcessExists(parentProcId))
                        {
                            if (action == HandBrakeWorkerAction.Encode && HandBrakeEncodeWorker.CurrentWorker != null && HandBrakeEncodeWorker.CurrentWorker.StopEncodeIfPossible())
                            {
                                // If we are able to stop the encode, we will do so. Cleanup should
                                // happen with the encode complete callback.
                                Console.WriteLine("Parent no longer exists, stopping encode.");
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        WorkerErrorLogger.LogError("Exception in parentCheckTimer. Elapsed: " + exception.ToString(), isError: true);
                        throw;
                    }
                };

                parentCheckTimer.Start();

                StartService(action);

                encodeComplete = new SemaphoreSlim(0, 1);
                await encodeComplete.WaitAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                WorkerErrorLogger.LogError("Exception in Main: " + exception, isError: true);
                throw;
            }
        }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: tyronebj/VidCoder
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Contains("-ToastActivated"))
            {
                return;
            }

            if (!Debugger.IsAttached)
            {
                this.DispatcherUnhandledException += this.OnDispatcherUnhandledException;
            }

            OperatingSystem OS = Environment.OSVersion;

            if (OS.Version.Major <= 5)
            {
                MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
                MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
                this.Shutdown();
                return;
            }

#if PSEUDOLOCALIZER_ENABLED
            Delay.PseudoLocalizer.Enable(typeof(CommonRes));
            Delay.PseudoLocalizer.Enable(typeof(MainRes));
            Delay.PseudoLocalizer.Enable(typeof(EnumsRes));
            Delay.PseudoLocalizer.Enable(typeof(EncodingRes));
            Delay.PseudoLocalizer.Enable(typeof(OptionsRes));
            Delay.PseudoLocalizer.Enable(typeof(PreviewRes));
            Delay.PseudoLocalizer.Enable(typeof(LogRes));
            Delay.PseudoLocalizer.Enable(typeof(SubtitleRes));
            Delay.PseudoLocalizer.Enable(typeof(QueueTitlesRes));
            Delay.PseudoLocalizer.Enable(typeof(ChapterMarkersRes));
            Delay.PseudoLocalizer.Enable(typeof(MiscRes));
#endif

            JsonSettings.SetDefaultSerializationSettings();

            Ioc.SetUp();

            try
            {
                Database.Initialize();
            }
            catch (Exception)
            {
                Environment.Exit(0);
            }

            Config.EnsureInitialized(Database.Connection);

            var interfaceLanguageCode = Config.InterfaceLanguageCode;
            if (!string.IsNullOrWhiteSpace(interfaceLanguageCode))
            {
                var cultureInfo = new CultureInfo(interfaceLanguageCode);
                Thread.CurrentThread.CurrentCulture       = cultureInfo;
                Thread.CurrentThread.CurrentUICulture     = cultureInfo;
                CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
                CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
            }

            Stopwatch sw = Stopwatch.StartNew();

            if (Config.UseCustomPreviewFolder && FileUtilities.HasWriteAccessOnFolder(Config.PreviewOutputFolder))
            {
                Environment.SetEnvironmentVariable("TMP", Config.PreviewOutputFolder, EnvironmentVariableTarget.Process);
                FileUtilities.OverrideTempFolder = true;
                FileUtilities.TempFolderOverride = Config.PreviewOutputFolder;
            }

            var updater = StaticResolver.Resolve <IUpdater>();

            sw.Stop();
            System.Diagnostics.Debug.WriteLine("Startup time: " + sw.Elapsed);

            updater.HandlePendingUpdate();

            try
            {
                // Check if we're a secondary instance
                IsPrimaryInstance = mutex.WaitOne(TimeSpan.Zero, true);
            }
            catch (AbandonedMutexException)
            {
            }

            this.GlobalInitialize();

            this.appThemeService = StaticResolver.Resolve <IAppThemeService>();
            this.appThemeService.AppThemeObservable.Subscribe(appTheme =>
            {
                if (appTheme != this.currentTheme)
                {
                    this.currentTheme = appTheme;
                    this.ChangeTheme(new Uri($"/Themes/{appTheme}.xaml", UriKind.Relative));

                    bool isDark = appTheme == AppTheme.Dark;

                    string fluentTheme = isDark ? "Dark" : "Light";
                    ThemeManager.ChangeTheme(this, fluentTheme + ".Cobalt");

                    Color ribbonTextColor = isDark ? Colors.White : Colors.Black;
                    this.Resources["Fluent.Ribbon.Brushes.LabelTextBrush"] = new SolidColorBrush(ribbonTextColor);
                }
            });

            var mainVM = new MainViewModel();
            StaticResolver.Resolve <IWindowManager>().OpenWindow(mainVM);
            mainVM.OnLoaded();

            if (e.Args.Length > 0)
            {
                mainVM.HandlePaths(new List <string> {
                    e.Args[0]
                });
            }

            if (!Utilities.IsPortable && IsPrimaryInstance)
            {
                AutomationHost.StartListening();
            }

            base.OnStartup(e);
        }