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)
        {
            Wallpaper renderWallpaper = null;

            if (RenderWindow != null)
            {
                Execute.OnUIThread(() =>
                {
                    renderWallpaper = RenderWindow.Wallpaper;
                });
            }

            if (renderWallpaper != null &&
                renderWallpaper.AbsolutePath == 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)
 {
     Execute.OnUIThread(() =>
     {
         _lastwallPaper = RenderWindow?.Wallpaper;
     });
     Show(previewWallpaper);
 }
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 void Preivew(Wallpaper previewWallpaper)
 {
     _isPreviewing = true;
     Execute.OnUIThread(() =>
     {
         _lastwallPaper = _videoRenders[0]?.CurrentPath;
     });
     Show(previewWallpaper, -1);
 }
        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 #8
0
        public static void Show(Wallpaper wallpaper)
        {
            IntPtr handler = IntPtr.Zero;

            Execute.OnUIThread(() =>
            {
                if (RenderWindow == null)
                {
                    RenderWindow = new RenderForm
                    {
                        Wallpaper = wallpaper
                    };
                    RenderWindow.SetAspect(VideoAspect);
                    RenderWindow.Show();
                }
                else
                {
                    try
                    {
                        RenderWindow.Wallpaper = wallpaper;
                        RenderWindow.SetAspect(VideoAspect);

                        //RenderWindow .Visibility = System.Windows.Visibility.Visible;
                        RenderWindow.Visible = true;
                    }
                    catch (Exception)
                    {
                        RenderWindow?.Close();
                        RenderWindow = null;
                        //explorer 崩溃后会触发这个问题

                        RenderWindow = new RenderForm
                        {
                            Wallpaper = wallpaper
                        };
                        RenderWindow.Show();
                    }
                }

                //handler = new WindowInteropHelper(RenderWindow).Handle;
                handler = RenderWindow.Handle;
            });

            //HandlerWallpaper.Show(handler);
            _LWECore.SendToBackground(handler);
        }
 public static void Show(Wallpaper w, int displayMonitor)
 {
     InnerShow(w.AbsolutePath, displayMonitor);
 }