public static async Task <IList <EntryInfo> > GetHistoryEntriesInfo() { Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; IList <string> entriesKey = GetHistory(); IDictionary <string, EntryInfo> oldHistory = new Dictionary <string, EntryInfo>(StringComparer.OrdinalIgnoreCase); if (_chmHistoryFiles != null) { foreach (var x in _chmHistoryFiles.Entries) { oldHistory.Add(x.Key, x); } } else { _chmHistoryFiles = new EntriesInfo(); } List <EntryInfo> newHistory = new List <EntryInfo>(); List <string> invalidEntries = new List <string>(); foreach (var k in entriesKey) { if (oldHistory.ContainsKey(k)) { newHistory.Add(oldHistory[k]); } else if (await ChmFile.ContainsFile(k)) { try { MetaInfo info = await MetaInfo.ReadMetaInfo(k); EntryInfo entry = new EntryInfo(); entry.Key = k; entry.Name = info.GetDisplayName(); if (string.IsNullOrEmpty(entry.Name)) { entry.Name = "未知"; } entry.Image = await Snapshot.LoadSnapshot(k); newHistory.Add(entry); } catch { //Ignore invalidEntries.Add(k); } } else { invalidEntries.Add(k); } } await DeleteFromHistory(invalidEntries); _chmHistoryFiles.Entries = newHistory; return(newHistory); }
public static async Task DeleteFromHistory(string name) { IList <string> historyList = GetHistory(); historyList.Remove(name); await ChmFile.DeleteFile(name); await MetaInfo.DeleteMetaFile(name); await Snapshot.DeleteSnapshotFile(name); SetHistory(historyList); }
public static async Task DeleteFromHistory(IEnumerable <string> keys) { IList <string> historyList = GetHistory(); foreach (string name in keys) { historyList.Remove(name); await ChmFile.DeleteFile(name); await MetaInfo.DeleteMetaFile(name); await Snapshot.DeleteSnapshotFile(name); } SetHistory(historyList); }
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; }