static ImageUtilities() { // Get system DPI Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice; if (m.M11 > 0 && m.M22 > 0) { dpiXFactor = m.M11; dpiYFactor = m.M22; } else { // Sometimes this can return a matrix with 0s. Fall back to assuming normal DPI in this case. Ioc.Get <IAppLogger>().Log("Could not read DPI. Assuming default DPI."); dpiXFactor = 1; dpiYFactor = 1; } }
public static SourceType GetSourceType(string sourcePath) { FileAttributes attributes = File.GetAttributes(sourcePath); if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) { var driveService = Ioc.Get <IDriveService>(); if (driveService.PathIsDrive(sourcePath)) { return(SourceType.Disc); } else { return(SourceType.DiscVideoFolder); } } else { return(SourceType.File); } }
public static void OpenFolderAndSelectItem(string folderPath, string file) { IntPtr nativeFolder; uint psfgaoOut; SHParseDisplayName(folderPath, IntPtr.Zero, out nativeFolder, 0, out psfgaoOut); if (nativeFolder == IntPtr.Zero) { Ioc.Get <ILogger>().LogError($"Could not find folder {folderPath}"); return; } IntPtr nativeFile; SHParseDisplayName(Path.Combine(folderPath, file), IntPtr.Zero, out nativeFile, 0, out psfgaoOut); IntPtr[] fileArray; if (nativeFile == IntPtr.Zero) { Ioc.Get <ILogger>().LogError($"Could not find file {Path.Combine(folderPath, file)}"); fileArray = new IntPtr[0]; } else { fileArray = new IntPtr[] { nativeFile }; } SHOpenFolderAndSelectItems(nativeFolder, (uint)fileArray.Length, fileArray, 0); Marshal.FreeCoTaskMem(nativeFolder); if (nativeFile != IntPtr.Zero) { Marshal.FreeCoTaskMem(nativeFile); } }
public static string GetSourceName(string sourcePath) { switch (GetSourceType(sourcePath)) { case SourceType.DiscVideoFolder: return(GetSourceNameFolder(sourcePath)); case SourceType.Disc: var driveService = Ioc.Get <IDriveService>(); DriveInformation info = driveService.GetDriveInformationFromPath(sourcePath); if (info != null) { return(info.VolumeLabel); } else { return(GetSourceNameFile(sourcePath)); } default: return(GetSourceNameFile(sourcePath)); } }
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(); } }