public async Task CreateThumbnailFile(Func<IRandomAccessStream, Task> create) { if (await Snapshot.CreateSnapshot(Key, create)) { HasThumbnail = true; FileHistory.UpdateImage(Key); } }
public static async Task<ChmFile> OpenLocalChmFile(string key) { try { Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; ChmFile ret = new ChmFile(); ret.Key = key; var file = await localFolder.GetFileAsync(key + ChmFileExtension); ret.Chm = await LoadChm(file.Path, true); ret.ChmMeta = await MetaInfo.ReadMetaInfo(key); ret.HasThumbnail = await Snapshot.HasSnapshot(key); if (ret.Chm.Title != null) { ret.ChmMeta.SetDisplayName(ret.Chm.Title); } //try //{ // Windows.UI.Xaml.Media.Imaging.BitmapImage image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); // using (var fileStream = await (await folder.GetFileAsync("0.png")).OpenReadAsync()) // { // await image.SetSourceAsync(fileStream); // } //} //catch //{ // ret.HasThumbnail = false; //} if (!ret.ChmMeta.ContainsLast()) { await ret.SetCurrent(ret.Chm.Home); //await ret.ChmMeta.SaveMetaInfo(key); } else { await ret.SetCurrent(ret.ChmMeta.GetLast()); } FileHistory.UpdateHistoryWhenOpenFile(ret.Key); return ret; } catch { } await FileHistory.DeleteFromHistory(key); return null; }
public static async Task<string> SetupChmFileFromOneDrive(LiveConnectClient client, IProgress<LiveOperationProgress> progressHandler, System.Threading.CancellationToken ctoken, string id, string name, string path) { ChmFile ret = new ChmFile(); ret.Key = Guid.NewGuid().ToString("N"); ret.HasThumbnail = false; Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.CreateFileAsync(ret.Key + ChmFileExtension, CreationCollisionOption.ReplaceExisting); LiveDownloadOperationResult result = await client.BackgroundDownloadAsync(id + "/content", file, ctoken, progressHandler); try { ret.Chm = await LoadChm(file.Path, false); MetaInfo meta = new MetaInfo(); meta.SetOriginalPath(path); if (ret.Chm.Title != null) { meta.SetDisplayName(ret.Chm.Title); } else { meta.SetDisplayName(System.IO.Path.GetFileNameWithoutExtension(name)); } ret.ChmMeta = meta; await ret.Save(); FileHistory.AddToHistory(ret.Key); } catch { ret.Chm = null; } if (ret.Chm == null) { await MetaInfo.DeleteMetaFile(ret.Key); await DeleteFile(ret.Key); return null; } return ret.Key; }
public static async Task<string> SetupChmFileFromPhone(IStorageFile storageFile) { ChmFile ret = new ChmFile(); Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; ret.Key = Guid.NewGuid().ToString("N"); ret.HasThumbnail = false; var file = await storageFile.CopyAsync(localFolder, ret.Key + ChmFileExtension); try { ret.Chm = await LoadChm(file.Path, false); MetaInfo meta = new MetaInfo(); meta.SetOriginalPath(storageFile.Path); if (ret.Chm.Title != null) { meta.SetDisplayName(ret.Chm.Title); } else { meta.SetDisplayName(System.IO.Path.GetFileNameWithoutExtension(storageFile.Name)); } ret.ChmMeta = meta; await ret.Save(); FileHistory.AddToHistory(ret.Key); } catch { ret.Chm = null; } if (ret.Chm == null) { await MetaInfo.DeleteMetaFile(ret.Key); await DeleteFile(ret.Key); return null; } return ret.Key; }