public static WallpaperType GetType(Wallpaper w) { if (w == null || w.ProjectInfo == null) { return(WallpaperType.NotSupport); } return(GetType(w.ProjectInfo.Type)); }
public static IEnumerable <Wallpaper> GetWallpapers(string dir) { DirectoryInfo dirInfo = new DirectoryInfo(dir); //test E:\SteamLibrary\steamapps\workshop\content\431960 //foreach (var item in Directory.EnumerateFiles(dir, "project.json", SearchOption.AllDirectories)) foreach (var item in dirInfo.EnumerateFiles("project.json", SearchOption.AllDirectories).OrderByDescending(m => m.CreationTime)) { var info = JsonHelper.JsonDeserializeFromFileAsync <ProjectInfo>(item.FullName).Result; var saveDir = Path.GetDirectoryName(item.FullName); var result = new Wallpaper(info, saveDir); yield return(result); } }
/// <summary> /// 解析壁纸 /// </summary> /// <param name="filePath">壁纸路径</param> /// <remarks>如果目录下没有project.json,则会生成默认对象</remarks> /// <returns></returns> public static Wallpaper ResolveFromFile(string filePath) { Wallpaper result = new Wallpaper() { AbsolutePath = filePath }; string dir = Path.GetDirectoryName(filePath); result.ProjectInfo = GetProjectInfo(dir); if (result.ProjectInfo == null) { result.ProjectInfo = new ProjectInfo(filePath); } return(result); }
public static async Task <bool> Delete(Wallpaper wallpaper) { string dir = Path.GetDirectoryName(wallpaper.AbsolutePath); for (int i = 0; i < 3; i++) { await Task.Delay(1000); try { //尝试删除3次 Directory.Delete(dir, true); return(true); } catch (Exception) { } } return(false); }
public ProjectInfo(string filePath) { File = Path.GetFileName(filePath); Title = Path.GetFileNameWithoutExtension(filePath); Type = Wallpaper.GetWallpaperType(filePath); }
public static async Task <Wallpaper> CreateLocalPack(Wallpaper wallpaper, string destDir) { var tmpResult = await WallpaperManager.CreateLocalPack(wallpaper.AbsolutePath, wallpaper.AbsolutePreviewPath, Convert(wallpaper.ProjectInfo), destDir); return(new Wallpaper(Convert(tmpResult.Info), destDir)); }
public static async Task EditLocakPack(Wallpaper wallpaper, string destDir) { await WallpaperManager.EditLocalPack(wallpaper.AbsolutePath, wallpaper.AbsolutePreviewPath, Convert(wallpaper.ProjectInfo), destDir); }