Esempio n. 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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void LoadTopcisInfo(ChmFile chmFile)
        {
            SelectedIndex        = -1;
            OutlineSelectedIndex = -1;
            Topics        = new List <TopicInfo>();
            OutlineTopics = new List <TopicInfo>();

            if (chmFile == null || !chmFile.HasOutline)
            {
                return;
            }
            _maxLevel = 0;
            IList <TopicInfo>     entries     = new List <TopicInfo>();
            Dictionary <int, int> levelCounts = new Dictionary <int, int>();

            for (int i = 0; i < chmFile.Chm.Contents.Count; ++i)
            {
                int level = chmFile.Chm.Contents[i].Level;
                _maxLevel = Math.Max(_maxLevel, level);
                if (!levelCounts.ContainsKey(level))
                {
                    levelCounts[level] = 1;
                }
                else
                {
                    levelCounts[level]++;
                }
                entries.Add(new TopicInfo(chmFile, i));
            }
            Topics       = entries;
            _outineLevel = GetOutlineLevel(levelCounts, _maxLevel);

            if (_outineLevel >= 0)
            {
                OutlineTopics = _entries.Where(x => x.Level <= _outineLevel).Select(x => new TopicInfo(chmFile, x.TopicId)).ToList();
                if (OutlineTopics.Count <= 1)
                {
                    _outineLevel  = -1;
                    OutlineTopics = new List <TopicInfo>();
                }
            }
            else
            {
                OutlineTopics = new List <TopicInfo>();
            }
        }
Esempio n. 5
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;
 }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 public TopicInfo(ChmFile chmFile, int topicId)
 {
     chmWeak_   = new WeakReference <ChmFile>(chmFile);
     IsSelected = false;
     TopicId    = topicId;
 }