コード例 #1
0
 private void fileSystemWatcherOsuSongFolder_Created(object sender, FileSystemEventArgs e)
 {
     //刷新Beatmaps和SkinFiles列表
     requestRefreshList();
     if (checkBoxAutoBlockup.Checked == true)
     {
         //屏蔽单个歌曲
         List <string> _skinFiles = new List <string>();
         for (int i = 1; i < listViewCustomBlockFiles.Items.Count; i++)
         {
             if (listViewCustomBlockFiles.Items[i].Checked)
             {
                 _skinFiles.Add(listViewCustomBlockFiles.Items[i].Text);
             }
         }
         threadBlockup = new ThreadBlockup(e.FullPath, _skinFiles, Convert.ToInt32(numericUpDownAutoBlockupDelay.Value), checkBoxBlockVideo.Checked, checkBoxBlockStoryboard.Checked, ThreadBlockup.calcBackgroundBlockStyle(comboBoxChangeBackground.SelectedIndex), checkBoxBlockCustomFiles.Checked);
         threadBlockup.Start();
     }
 }
コード例 #2
0
        private void buttonBlockUp_Click(object sender, EventArgs e)
        {
            List <string> _songsFolder      = new List <string>();
            List <string> _customBlockFiles = new List <string>();

            if (MessageBox.Show("您真的要开始屏蔽歌曲吗,这将会花费一些时间,但您可以中断这个操作。\n屏蔽完成后将会\"beep~\"的一声通知您", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
            {
                return;
            }
            //禁用一些控件并显示 线程信息panel
            buttonBlockUp.Enabled             = false;
            checkBoxSuspendOsuProcess.Enabled = false;
            panelBlockUpProgressInfo.Visible  = true;
            buttonAbortBlockup.Enabled        = true;
            buttonAbortBlockup.Focus();
            //过滤选中的Beatmaps和SkinFiles
            for (int i = 1; i < listViewBeatmaps.Items.Count; i++)
            {
                if (listViewBeatmaps.Items[i].Checked)
                {
                    _songsFolder.Add(listViewBeatmaps.Items[i].Text);
                }
            }
            for (int i = 1; i < listViewCustomBlockFiles.Items.Count; i++)
            {
                if (listViewCustomBlockFiles.Items[i].Checked)
                {
                    _customBlockFiles.Add(listViewCustomBlockFiles.Items[i].Text);
                }
            }
            //处理多线程设置
            {
                int _indexOf_songsFolder = 0;//在_songsFolder中的索引
                //第一种计算方法,(任务数 + (线程数 - (任务数 % 线程数))) / 线程数
                //第二种计算方法为下面的代码,目测还没有人在osu!歌曲目录下还有超过 int.MaxValue 数量的歌曲
                int _singleThreadTasks = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(_songsFolder.Count) / Convert.ToDouble(comboBoxThreads.SelectedIndex + 1)));

                threadBlockupStack = new List <ThreadBlockup>();
                for (int i = 1; i <= comboBoxThreads.SelectedIndex + 1; i++)
                {
                    List <string> _songsSingleThread = new List <string>();
                    for (int j = 0; j < _singleThreadTasks; j++)
                    {
                        if (_indexOf_songsFolder <= _songsFolder.Count - 1)
                        {
                            _songsSingleThread.Add(_songsFolder[_indexOf_songsFolder]);
                            _indexOf_songsFolder++;
                        }
                    }
                    if (_songsSingleThread.Count > 0)
                    {
                        threadBlockupStack.Add(new ThreadBlockup("thread:" + i, osuInstalledLocation, _songsSingleThread, _customBlockFiles, checkBoxBlockVideo.Checked, checkBoxBlockStoryboard.Checked, ThreadBlockup.calcBackgroundBlockStyle(comboBoxChangeBackground.SelectedIndex), checkBoxBlockCustomFiles.Checked));
                    }
                }
            }
            //暂停osu!.exe进程后开始屏蔽
            if (checkBoxSuspendOsuProcess.Checked == true)
            {
                OsuHelper.OsuIsSuspend = true;
            }
            //在listViewThreadProgressInfo中创建列表项并启动线程
            listViewThreadProgressInfo.Items.Clear();
            foreach (ThreadBlockup item in threadBlockupStack)
            {
                ListViewItem lvItem = new ListViewItem(item.t.Name);
                lvItem.SubItems.Add(string.Format("0/{0}(0%)", item.TotalBeatmaps));
                listViewThreadProgressInfo.Items.Add(lvItem);
                item.Start();
            }
            //屏蔽选中的歌曲
            timerBlockupProgressWatcher.Enabled = true;
        }