public static async Task <WallpaperModel> EditLocalPack(string sourceFile, string previewPath, WallpaperInfo info, string destDir) { string oldInfoPath = Path.Combine(destDir, "project.json"); var oldInfo = await JsonHelper.JsonDeserializeFromFileAsync <WallpaperInfo>(oldInfoPath); string oldFile = null, oldPreview = null; if (oldInfo != null) { oldFile = Path.Combine(destDir, oldInfo.File); if (oldInfo.Preview != null) { oldPreview = Path.Combine(destDir, oldInfo.Preview ?? ""); } } if (NormalizePath(sourceFile) != NormalizePath(oldFile)) { await Task.Run(() => { File.Delete(oldFile); IOHelper.CopyFileToDir(sourceFile, destDir); }); } info.Preview = Path.GetFileName(previewPath); if (NormalizePath(oldPreview) != NormalizePath(previewPath)) { await Task.Run(() => { File.Delete(oldPreview); IOHelper.CopyFileToDir(previewPath, destDir); }); } await WriteInfo(info, destDir); return(new WallpaperModel() { Path = Path.Combine(destDir, info.File), Info = info }); }
public static async Task <WallpaperModel> CreateLocalPack(string sourceFile, string previewPath, WallpaperInfo info, string destDir) { string oldInfoPath = Path.Combine(sourceFile, "project.json"); if (File.Exists(oldInfoPath)) { var existInfo = await JsonHelper.JsonDeserializeFromFileAsync <WallpaperInfo>(oldInfoPath); info.Description ??= existInfo.Description; info.File ??= existInfo.File; info.Preview ??= existInfo.Preview; info.Tags ??= existInfo.Tags; info.Title ??= existInfo.Title; info.Type ??= existInfo.Type; info.Visibility ??= existInfo.Visibility; await Task.Run(() => { IOHelper.CopyFolder(sourceFile, destDir); }); } else { await Task.Run(() => { IOHelper.CopyFileToDir(sourceFile, destDir); info.Preview = Path.GetFileName(previewPath); IOHelper.CopyFileToDir(previewPath, destDir); }); } await WriteInfo(info, destDir); return(new WallpaperModel() { Path = Path.Combine(destDir, info.File), Info = info }); }