public static Wallpaper CreateLocalPack(Wallpaper wallpaper, string destDir)
        {
            var    currentDir      = Path.GetDirectoryName(wallpaper.AbsolutePath);
            string projectInfoPath = Path.Combine(currentDir, "project.json");

            if (File.Exists(projectInfoPath))
            {
                //有详细信息,全拷。兼容wallpaper engine
                CopyFolder(new DirectoryInfo(currentDir), new DirectoryInfo(destDir));
            }
            else
            {
                CopyFileToDir(wallpaper.AbsolutePath, destDir);
            }

            string preview = "preview.jpg";

            wallpaper.ProjectInfo.Preview = preview;
            CopyFileToDir(wallpaper.AbsolutePreviewPath, destDir, preview);


            string jsonPath = Path.Combine(destDir, "project.json");

            JsonHelper.JsonSerialize(wallpaper.ProjectInfo, jsonPath);

            Wallpaper result = new Wallpaper(wallpaper.ProjectInfo, destDir);

            return(result);
        }
        public static async Task <bool> Delete(Wallpaper wallpaper)
        {
            string renderWallpaper = null;

            if (_videoRenders != null)
            {
                Execute.OnUIThread(() =>
                {
                    renderWallpaper = _videoRenders[0].CurrentPath;
                });
            }

            if (renderWallpaper != null &&
                renderWallpaper == wallpaper.AbsolutePath)
            {
                Close();
            }
            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);
        }
Example #3
0
 public static void Preivew(Wallpaper previewWallpaper)
 {
     _isPreviewing = true;
     Execute.OnUIThread(() =>
     {
         _lastwallPaper = _videoRenders[0]?.CurrentPath;
     });
     Show(previewWallpaper, -1);
 }
Example #4
0
        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);
        }
Example #7
0
 public static void Show(Wallpaper w, int displayMonitor)
 {
     InnerShow(w.AbsolutePath, displayMonitor);
 }