public static async Task Initlize() { //开机启动 #if UWP AutoStartupHelper.Initlize(AutoStartupType.Store, "LiveWallpaper"); #else AutoStartupHelper.Initlize(AutoStartupType.Win32, "LiveWallpaper"); #endif //多语言 Xaml.CustomMaps.Add(typeof(TaskbarIcon), TaskbarIcon.ToolTipTextProperty); //不能用Environment.CurrentDirectory,开机启动目录会出错 ApptEntryDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string path = Path.Combine(ApptEntryDir, "Res\\Languages"); LanService.Init(new JsonDB(path), true, "zh"); //配置相关 var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); AppDataDir = $"{appData}\\LiveWallpaper"; UWPRealAppDataDir = Path.Combine(ApplicationData.Current.LocalCacheFolder.Path, "Roaming\\LiveWallpaper"); SettingPath = $"{AppDataDir}\\Config\\setting.json"; //LocalWallpaperDir = $"{AppDataDir}\\Wallpapers"; //因为uwp store权限问题所以改为 %userprofile%\videos\LivewallpaperCache //string videoDir = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); //LocalWallpaperDir = $"{videoDir}\\LivewallpaperCache"; AppDataPath = $"{AppDataDir}\\appData.json"; PurchaseDataPath = $"{AppDataDir}\\purchaseData.json"; await CheckDefaultSetting(); //应用程序数据 AppData = await JsonHelper.JsonDeserializeFromFileAsync <AppData>(AppDataPath); if (AppData == null) { AppData = new AppData(); await ApplyAppDataAsync(); } //加载壁纸 await Task.Run(() => { RefreshLocalWallpapers(); //if (AppData.Wallpaper != null) //{ WallpaperManager.MaximizedEvent += WallpaperManager_MaximizedEvent; var current = Wallpapers.FirstOrDefault(m => m.AbsolutePath == AppData.Wallpaper); if (current != null) { WallpaperManager.VideoAspect = Setting.Wallpaper.VideoAspect; WallpaperManager.Show(current); } WallpaperManager.MonitorMaxiemized(true); //} }); }
public static async void InitlizeSetting() { if (SettingInitialized) { return; } //开机启动 AutoStartupHelper.Initlize(AutoStartupType.Store, "LiveWallpaper"); //配置相关 SettingDefaultFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Res\\setting.default.json"); SettingDescFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Res\\setting.desc.json"); var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); AppDataDir = $"{appData}\\LiveWallpaper"; SettingPath = $"{AppDataDir}\\Config\\setting.json"; AppDataPath = $"{AppDataDir}\\appData.json"; PurchaseDataPath = $"{AppDataDir}\\purchaseData.json"; await CheckDefaultSetting(); //应用程序数据 AppData = await JsonHelper.JsonDeserializeFromFileAsync <AppData>(AppDataPath); if (AppData == null) { AppData = new AppData(); await ApplyAppDataAsync(); } Setting = await JsonHelper.JsonDeserializeFromFileAsync <SettingObject>(SettingPath); LocalWallpaperDir = Setting.General.WallpaperSaveDir; SettingInitialized = true; }