Exemplo n.º 1
0
 public static NewsData GetNewsData(string url)
 {
     return(MsgPack.Deserialize <NewsData>(GetRawNewsData(url)));
 }
Exemplo n.º 2
0
 public static List <BcatChannel> GetNewsCatalog()
 {
     return(MsgPack.Deserialize <List <BcatChannel> >(GetRawNewsCatalog()));
 }
Exemplo n.º 3
0
 public static TopicDetail GetTopicDetail(string TopicID)
 {
     return(MsgPack.Deserialize <TopicDetail>(GetRawTopicDetail(TopicID)));
 }
Exemplo n.º 4
0
 public static BcatNews GetBcatNewsList(string topicID)
 {
     return(MsgPack.Deserialize <BcatNews>(GetRawBcatNewsList(topicID)));
 }
Exemplo n.º 5
0
 public static BcatList GetBcatList(ulong TitleID, string pass)
 {
     return(MsgPack.Deserialize <BcatList>(GetRawBcatList(TitleID, pass)));
 }
Exemplo n.º 6
0
        public static List <BcatTopic> RefreshCatalog(ProgressBar pb, Label lbl)
        {
            string catalogPath = $"{CATALOG_CACHE_PATH}.bin";

            byte[]             rawCatalog = BCAT.GetRawNewsCatalog();
            List <BcatChannel> catalog    = MsgPack.Deserialize <List <BcatChannel> >(rawCatalog);

            List <BcatChannel> cached = (File.Exists(catalogPath))
                ? MsgPack.Deserialize <List <BcatChannel> >(File.ReadAllBytes(catalogPath))
                : null;

            pb.Invoke(new Action(() => {
                pb.Value   = 0;
                pb.Maximum = catalog.Count;
            }));

            List <BcatTopic> topics = new List <BcatTopic>();

            for (int i = 0; i < catalog.Count; i++)
            {
                lbl.Invoke(new Action(() => lbl.Text = $"Processing... {i}/{catalog.Count} ({catalog[i].topic_id})"));
                pb.Invoke(new Action(() => pb.Value  = i));

                string dir        = $"{CATALOG_CACHE_PATH}/{catalog[i].topic_id}";
                string iconPath   = $"{dir}/icon.jpg";
                string detailPath = $"{dir}/detail.bin";

                bool redownload = true;

                if (cached != null)
                {
                    foreach (var item in cached)
                    {
                        if (item.topic_id == catalog[i].topic_id)
                        {
                            redownload = !(item.Equals(catalog[i]) && File.Exists(iconPath) && File.Exists(detailPath));
                            break;
                        }
                    }
                }

                if (redownload)
                {
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    File.WriteAllBytes(iconPath, BCAT.GetRawTopicIcon(catalog[i].topic_id));
                    File.WriteAllBytes(detailPath, BCAT.GetRawTopicDetail(catalog[i].topic_id));
                }

                BcatTopic t = new BcatTopic()
                {
                    Icon    = Utils.GetBitmap(File.ReadAllBytes(iconPath)),
                    Details = MsgPack.Deserialize <TopicDetail>(File.ReadAllBytes(detailPath))
                };
                topics.Add(t);
            }

            //if (cached == null)
            File.WriteAllBytes(catalogPath, rawCatalog);

            lbl.Invoke(new Action(() => lbl.Text = "..."));
            pb.Invoke(new Action(() => pb.Value  = 0));


            topics = topics.OrderBy(item => item.Details.important).ThenBy(item => item.Details.last_posted_at).Reverse().ToList();

            return(topics);
        }