コード例 #1
0
        //decrypt and save file
        private void button_save_Click(object sender, EventArgs e)
        {
            if (!File.Exists(textBox_path.Text))
            {
                MessageBox.Show("Input file \"" + textBox_path.Text + "\" does not exist.");
                return;
            }


            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Thread t = new Thread(() =>
                {
                    //disable contols
                    foreach (Control control in Controls)
                    {
                        Invoke(new Action(() => control.Enabled = false));
                    }

                    byte[] data = BCAT.DecryptBCAT(File.ReadAllBytes(textBox_path.Text), ulong.Parse(textBox_tid.Text, NumberStyles.HexNumber), textBox_pass.Text);

                    File.WriteAllBytes(saveFileDialog1.FileName, data);
                    SystemSounds.Asterisk.Play();

                    Invoke(new Action(() => this.Close()));
                });
                t.IsBackground = true;
                t.Start();
            }
        }
コード例 #2
0
        private void DownloadAll(bool decrypt, string tid, string pass)
        {
            FolderSelectDialog fbox = new FolderSelectDialog();

            if (fbox.ShowDialog() == DialogResult.OK)
            {
                string rootPath = $@"{fbox.SelectedPath}\{DataList.topic_id}\";

                //create folder if doesn't exist
                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }

                Thread t = new Thread(() =>
                {
                    Invoke(new Action(() => {
                        foreach (Control c in Controls)
                        {
                            c.Enabled = false;
                        }
                    }));

                    foreach (var dir in DataList.directories)
                    {
                        string dirPath = $@"{rootPath}\{dir.name}\";

                        //create folder if doesn't exist
                        if (!Directory.Exists(dirPath))
                        {
                            Directory.CreateDirectory(dirPath);
                        }

                        foreach (var file in dir.data_list)
                        {
                            string filePath = dirPath + file.filename;
                            byte[] data     = (decrypt)
                                ? BCAT.GetDecBcat(file.url, BCAT.Module.nnBcat, ulong.Parse(tid, NumberStyles.HexNumber), pass)
                                : BCAT.GetRawBcat(file.url, BCAT.Module.nnBcat);

                            File.WriteAllBytes(filePath, data);
                        }
                    }

                    Invoke(new Action(() => {
                        foreach (Control c in Controls)
                        {
                            c.Enabled = true;
                        }
                    }));

                    SystemSounds.Asterisk.Play();
                });
                t.IsBackground = true;
                t.Start();
            }
        }
コード例 #3
0
        public static List <NewsData> RefreshNews(string TopicID, ProgressBar pb, Label lbl)
        {
            string listPath = $"{NEWS_CACHE_PATH}/{TopicID}";

            if (!Directory.Exists(listPath))
            {
                Directory.CreateDirectory(listPath);
            }

            byte[] b = BCAT.GetRawBcatNewsList(TopicID);
            File.WriteAllBytes(listPath + ".bin", b);
            var news = MsgPack.Deserialize <BcatNews>(b);

            pb.Invoke(new Action(() => {
                pb.Value   = 0;
                pb.Maximum = news.directories[0].data_list.Count;
            }));

            List <NewsData> newsdata = new List <NewsData>();
            int             c        = 0;

            foreach (var item in news.directories[0].data_list)
            {
                pb.Invoke(new Action(() => pb.Value  = c));
                lbl.Invoke(new Action(() => lbl.Text = $"Processing... {c}/{pb.Maximum} (New ID : {item.news_id:X8})"));

                foreach (var lang in item.languages)
                {
                    if (lang.language == Program.Config.Lang)
                    {
                        string path = $"{listPath}/{item.news_id:X8}";

                        if (!File.Exists(path))
                        {
                            b = BCAT.GetRawNewsData(lang.url);
                            File.WriteAllBytes(path, b);
                        }
                        else
                        {
                            b = File.ReadAllBytes(path);
                        }

                        newsdata.Add(MsgPack.Deserialize <NewsData>(b));
                    }
                }
                c++;
            }

            newsdata.Sort(delegate(NewsData d1, NewsData d2) { return(d2.published_at.CompareTo(d1.published_at)); });

            return(newsdata);
        }
コード例 #4
0
        //download/parse bcat
        private void button_getList_Click(object sender, EventArgs e)
        {
            if (button_getList.Text == "Get List")
            {
                try
                {
                    ListCache = BCAT.GetRawBcatList(ulong.Parse(textBox_tid.Text, NumberStyles.HexNumber), textBox_pass.Text);
                    DataList  = MsgPack.Deserialize <BcatList>(ListCache);

                    treeView1.Nodes.Clear();

                    var rootnode = treeView1.Nodes.Add(DataList.topic_id);
                    rootnode.SelectedImageIndex = 0;
                    rootnode.ImageIndex         = 0;
                    tabControl1.SelectedIndex   = 0;

                    foreach (var dir in DataList.directories)
                    {
                        var dirnode = rootnode.Nodes.Add(dir.name);
                        dirnode.SelectedImageIndex = 0;
                        dirnode.ImageIndex         = 0;
                        foreach (var file in dir.data_list)
                        {
                            var filenode = dirnode.Nodes.Add(file.filename);
                            filenode.SelectedImageIndex = 1;
                            filenode.ImageIndex         = 1;
                        }
                    }

                    SystemSounds.Asterisk.Play();
                    textBox_tid.Enabled   = false;
                    textBox_pass.Enabled  = false;
                    button_select.Enabled = false;
                    button_getList.Text   = "New";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                treeView1.Nodes.Clear();
                tabControl1.SelectedIndex = 0;
                textBox_tid.Enabled       = true;
                textBox_pass.Enabled      = true;
                button_select.Enabled     = true;
                button_getList.Text       = "Get List";
            }
        }
コード例 #5
0
        public Form1()
        {
            InitializeComponent();

            //hackjob
            tabControl1.Location   = new Point(tabControl1.Location.X, tabControl1.Location.Y + tabControl1.ItemSize.Height);
            tabControl1.ItemSize   = new Size(0, 1);
            tabControl1.SizeMode   = TabSizeMode.Fixed;
            tabControl1.Appearance = TabAppearance.FlatButtons;

            Updater.GetUpdate();

            SetCurrentTopic(BCAT.GetBcatTopic(CurrentTopicId));
        }
コード例 #6
0
        //lang
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <int> indices = new List <int>();

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                {
                    indices.Add(i);
                }
            }

            textBox_queryString.Text = BCAT.MakeQueryString(comboBox1.SelectedIndex, indices);
        }
コード例 #7
0
        private void DownloadFile(bool decrypt, TreeNode node, string tid, string pass)
        {
            var dir  = DataList.directories[node.Parent.Index];
            var file = dir.data_list[node.Index];

            saveFileDialog1.FileName = file.filename;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Thread t = new Thread(() =>
                {
                    Invoke(new Action(() => {
                        foreach (Control c in Controls)
                        {
                            c.Enabled = false;
                        }
                    }));

                    byte[] data = (decrypt)
                        ? BCAT.GetDecBcat(file.url, BCAT.Module.nnBcat, ulong.Parse(tid, NumberStyles.HexNumber), pass)
                        : BCAT.GetRawBcat(file.url, BCAT.Module.nnBcat);

                    File.WriteAllBytes(saveFileDialog1.FileName, data);

                    Invoke(new Action(() => {
                        foreach (Control c in Controls)
                        {
                            c.Enabled = true;
                        }
                    }));

                    SystemSounds.Asterisk.Play();
                });
                t.IsBackground = true;
                t.Start();
            }
        }
コード例 #8
0
        private void button_save_Click(object sender, EventArgs e)
        {
            if (!File.Exists(textBox_path.Text) && !CalledWithBuffer)
            {
                MessageBox.Show("Input file \"" + textBox_path.Text + "\" does not exist.");
                return;
            }

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Thread t = new Thread(() =>
                {
                    //disable contols
                    foreach (Control control in Controls)
                    {
                        Invoke(new Action(() => control.Enabled = false));
                    }

                    byte[] data = (CalledWithBuffer)
                    ? RawBuffer
                    : File.ReadAllBytes(textBox_path.Text);

                    byte crypto = 0, hashType = 0;
                    Invoke(new Action(() => crypto   = (byte)(comboBox_crypto.SelectedIndex + 1)));
                    Invoke(new Action(() => hashType = (byte)comboBox_sha.SelectedIndex));
                    byte[] enc = BCAT.EncryptBCAT(data, ulong.Parse(textBox_tid.Text, NumberStyles.HexNumber), textBox_pass.Text, hashType, crypto, Signature);

                    File.WriteAllBytes(saveFileDialog1.FileName, enc);
                    SystemSounds.Asterisk.Play();

                    Invoke(new Action(() => this.Close()));
                });
                t.IsBackground = true;
                t.Start();
            }
        }
コード例 #9
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);
        }