public FileDiscoveryService(WallpaperManagerContext context) { Context = context; ThemeRepo = new WallpaperThemeRepository(context); DirectoryRepo = new WallpaperDirectoryRepository(context); FileCacheRepo = new FileDiscoveryCacheRepository(context); }
private WallpaperTheme GetTheme(int id) { using (var context = new WallpaperManagerContext()) { var themeRepo = new WallpaperThemeRepository(context); try { return(themeRepo.Find(id)); } catch (Exception) { } } return(null); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; // Setup App Consts SetupAppConsts(); // Migrate and Update the DB using (var db = new WallpaperManagerContext()) { db.Database.Migrate(); } // Register the Background Tasks RegisterBackgroundTasks(); }
public WallpaperManagerViewModelBase() { // Setup the Repos var context = new WallpaperManagerContext(); ThemeRepository = new WallpaperThemeRepository(context); DirectoryRepository = new WallpaperDirectoryRepository(context); AccessTokenRepository = new FileAccessTokenRepository(context); FileDiscoveryCacheRepository = new FileDiscoveryCacheRepository(context); // Setup the AppProducts try { InAppPurchaseManagerBase.AppProductsChanged += InAppPurchaseManager_AppProductsChanged; var product = InAppPurchaseManagerFactory.Create(true).GetAppProductByStoreID("9nzm4xdbvpk0"); ProductAWMPro = product; Debug.WriteLine($"{nameof(WallpaperManagerViewModelBase)} | {ProductAWMPro}"); } catch (Exception) { } }
public async void Run(IBackgroundTaskInstance taskInstance) { Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Run)} - Begun"); // Register the Monitoring Events taskInstance.Canceled += TaskInstance_Canceled; taskInstance.Task.Completed += Task_Completed; taskInstance.Task.Progress += Task_Progress; // If the task is not allowed to run, return early if (!IsTaskAllowedToRun()) { return; } // Otherwise, we jump into File Discovery Process _deferral = taskInstance.GetDeferral(); using (var context = new WallpaperManagerContext()) { var themeRepo = new WallpaperThemeRepository(context); var fileDiscoveryService = new FileDiscoveryService(context); // Preform File Discovery for ALL of the themes //_deferral = taskInstance.GetDeferral(); //await fileDiscoveryService.PreformFileDiscoveryAll(null); //_deferral.Complete(); // Preform File Discovery for the Desktop Wallpaper Theme Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveDesktopThemeSetting)} - Started"); var activeDesktopThemeSetting = new ActiveDesktopThemeSetting(); var activeDesktopThemeSettingValue = activeDesktopThemeSetting.Value; if (activeDesktopThemeSettingValue.HasValue) { var activeWallpaperTheme = themeRepo.Find(activeDesktopThemeSettingValue.Value); await fileDiscoveryService.PreformFileDiscovery(activeWallpaperTheme, null); } Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveDesktopThemeSetting)} - Completed"); // Preform File Discovery for the Lockscreen Theme Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveLockscreenThemeSetting)} - Started"); var activeLockscreenThemeSetting = new ActiveLockscreenThemeSetting(); var activeLockscreenThemeSettingValue = activeLockscreenThemeSetting.Value; if (activeLockscreenThemeSettingValue.HasValue && activeLockscreenThemeSettingValue != activeDesktopThemeSettingValue) { var activeLockscreenTheme = themeRepo.Find(activeLockscreenThemeSettingValue.Value); await fileDiscoveryService.PreformFileDiscovery(activeLockscreenTheme, null); } Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveLockscreenThemeSetting)} - Completed"); } // Update the FileDiscovery Last Run var fileDiscoveryLastRunSetting = new FileDiscoveryLastRunSetting(); fileDiscoveryLastRunSetting.Value = DateTime.UtcNow; // Update the FileDiscovery Background Task Last Run var fileDiscoveryTaskLastRunSetting = new FileDiscoveryTaskLastRunSetting(); fileDiscoveryTaskLastRunSetting.Value = DateTime.UtcNow; Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Run)} - Completed"); _deferral.Complete(); }
public async Task <StorageFile> CreateWindowsTheme(WallpaperTheme theme) { using (var context = new WallpaperManagerContext()) { var fileDiscoveryService = new FileDiscoveryService(context); var fileCache = fileDiscoveryService.GetCache(theme); if (fileCache.Count <= 0) { return(null); } // Build up the file format StringBuilder builder = new StringBuilder(); builder.AppendLine("; Copyright © Killerrin Studios"); builder.AppendLine(); builder.AppendLine("[Theme]"); builder.AppendLine($"DisplayName={theme.Name}"); builder.AppendLine(); builder.AppendLine(@"[Control Panel\Desktop]"); builder.AppendLine($"Wallpaper={theme.FirstImageFromCache}"); builder.AppendLine("; The path to the wallpaper picture can point to a .bmp, .gif, .jpg, .png, or .tif file."); builder.AppendLine("Pattern="); //builder.AppendLine($"MultimonBackgrounds={0}"); //builder.AppendLine($"PicturePosition={4}"); builder.AppendLine($"TileWallpaper={0}"); builder.AppendLine("; 0: The wallpaper picture should not be tiled"); builder.AppendLine("; 1: The wallpaper picture should be tiled "); builder.AppendLine($"WallpaperStyle={10}"); builder.AppendLine("; 0: The image is centered if TileWallpaper = 0 or tiled if TileWallpaper = 1"); builder.AppendLine("; 2: The image is stretched to fill the screen"); builder.AppendLine("; 6: The image is resized to fit the screen while maintaining the aspect ratio. (Windows 7 and later)"); builder.AppendLine("; 10: The image is resized and cropped to fill the screen while maintaining the aspect ratio. (Windows 7 and later)"); builder.AppendLine(); builder.AppendLine("[Slideshow]"); if (theme.WallpaperChangeFrequency.TotalMilliseconds > 0.0) { builder.AppendLine($"Interval={theme.WallpaperChangeFrequency.TotalMilliseconds}"); } else { builder.AppendLine($"Interval={TimeSpan.FromMinutes(5.0).TotalMilliseconds}"); } builder.AppendLine("; Interval is a number that determines how often the background changes. It is measured in milliseconds."); switch (theme.WallpaperSelectionMethod) { case ImageSelectionMethod.Random: case ImageSelectionMethod.Sequential: builder.AppendLine($"Shuffle={(int)theme.WallpaperSelectionMethod}"); break; default: builder.AppendLine($"Shuffle={0}"); break; } builder.AppendLine("; 0: Disabled"); builder.AppendLine("; 1: Enabled"); builder.AppendLine(); builder.AppendLine($"ImagesRootPath={fileCache[0].FolderPath}"); for (int i = 0; i < fileCache.Count; i++) { builder.AppendLine($"Item{i}Path={fileCache[i].FilePath}"); } builder.AppendLine(); builder.AppendLine("[VisualStyles]"); builder.AppendLine($@"Path=%ResourceDir%\Themes\Aero\Aero.msstyles"); builder.AppendLine($"ColorStyle=NormalColor"); builder.AppendLine($"Size=NormalSize"); builder.AppendLine($"AutoColorization=0"); builder.AppendLine($"ColorizationColor=0XC40078D7"); builder.AppendLine(); builder.AppendLine("[boot]"); builder.AppendLine("SCRNSAVE.EXE="); builder.AppendLine(); builder.AppendLine("[MasterThemeSelector]"); builder.AppendLine("MTSM=RJSPBS"); FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; savePicker.FileTypeChoices.Add("Windows Theme File", new List <string>() { ".theme" }); savePicker.SuggestedFileName = $"{theme.Name}"; var file = await savePicker.PickSaveFileAsync(); if (file != null) { CachedFileManager.DeferUpdates(file); await FileIO.WriteTextAsync(file, builder.ToString()); FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); if (status == FileUpdateStatus.Complete || status == FileUpdateStatus.CompleteAndRenamed) { return(file); } } } return(null); }