Example #1
0
        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);
        }
Example #2
0
 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;
 }