private Dictionary <int, List <BoardIndex> > topMovableDic; /* コマ移動定義 */ /// <summary> /// クラスのインスタンス化 /// </summary> /// <param name="size"></param> public ShogiBoard(int size, Vector2 boardPos) { boardSize = size; this.boardPos = boardPos; boardInf = new BoardInf[boardSize + 1, boardSize + 1]; for (int i = 0; i <= boardSize; i++) { for (int j = 0; j <= boardSize; j++) { boardInf[i, j] = new BoardInf(); } } //すべてのコマ移動定義を格納する topMovableDic = new Dictionary <int, List <BoardIndex> >(); for (int i = 1; i <= 10; i++) { List <BoardIndex> indexesList = GetMovableIndexDefEachTop(i); topMovableDic.Add(i, indexesList); } }
private void cmdDoSearch_Click(object sender, EventArgs e) { try { string[] saTerm = z.Split(txTerm.Text.ToLower(), "; "); int iChan = cbChan.SelectedIndex; ChanInf thChan = Chans[iChan]; int iBoard = cbBoard.SelectedIndex; BoardInf thBoard = Chans[iChan].bBoards[iBoard]; sFoundWrd = ""; sFoundURL = ""; sFoundCtx = ""; lBoardsChecked = 0; lThreadsChecked = 0; lFound = 0; GUI("Downloading board pages"); string AllURLs = "\n"; Grabber[] WRB = new Grabber[thBoard.b04_sURL_IndexP_C]; for (int a = 0; a < WRB.Length; a++) { string ReqURL = thBoard.b01_sURL_Index; string sURLP_1 = thBoard.b02_sURL_IndexP_1; if (sURLP_1 == "!null~") { sURLP_1 = ""; } string sURLP_2 = thBoard.b03_sURL_IndexP_2; if (sURLP_2 == "!null~") { sURLP_2 = ""; } if (a > 0) { ReqURL = sURLP_1 + a + sURLP_2; } //I don't remember why this is here, and I //can't be arsed to figure it out either. Meh. System.Threading.Thread.Sleep(rnd.Next(10, 50)); WRB[a] = new Grabber(ReqURL); } while (true) { bool bDone = true; for (int a = 0; a < WRB.Length; a++) { if (!WRB[a].done) { bDone = false; } } System.Threading.Thread.Sleep(100); if (bDone) { break; } } GUI("Parsing board pages"); for (int a = 0; a < WRB.Length; a++) { string bHTML = WRB[a].ret; if (WRB[a].ex == Grabber.Ex.NotFound) { throw new Exception("Error 404: File does not exist"); } string sSTmp = ""; sSTmp = thBoard.c01_sS_Threads_1; if (sSTmp != "!null~") { bHTML = bHTML.Substring(bHTML.IndexOf(sSTmp) + sSTmp.Length); } sSTmp = thBoard.c02_sS_Threads_2; if (sSTmp != "!null~") { bHTML = bHTML.Substring(0, bHTML.IndexOf(sSTmp)); } string[] saTURLs = z.Split(bHTML, thBoard.c03_sS_Threads); string[] TURLs = new string[saTURLs.Length - 1]; for (int b = 0; b < TURLs.Length; b++) { TURLs[b] = saTURLs[b + 1]; sSTmp = thBoard.c04_sS_ThreadURL_1; if (sSTmp != "!null~") { TURLs[b] = TURLs[b].Substring(TURLs[b].IndexOf(sSTmp) + sSTmp.Length); } sSTmp = thBoard.c05_sS_ThreadURL_2; if (sSTmp != "!null~") { TURLs[b] = TURLs[b].Substring(0, TURLs[b].IndexOf(sSTmp)); } sSTmp = thBoard.b05_sURL_Thread; if (sSTmp != "!null~") { TURLs[b] = sSTmp + TURLs[b]; } if (!AllURLs.Contains("\n" + TURLs[b] + "\n")) { AllURLs += TURLs[b] + "\n"; } } } GUI("Downloading / parsing threads"); AllURLs = AllURLs.TrimStart('\n'); while (AllURLs != "") { string thURLs = ""; for (int a = 0; a < 10; a++) { if (AllURLs != "") { thURLs += AllURLs.Substring(0, AllURLs.IndexOf("\n")) + "\n"; AllURLs = AllURLs.Substring(AllURLs.IndexOf("\n") + 1); } } string[] saURLs = thURLs.TrimEnd('\n').Split('\n'); Grabber[] WR = new Grabber[saURLs.Length]; for (int b = 0; b < WR.Length; b++) { //See last comment. Also, there's something //strangely familiar with this code... Hurrr System.Threading.Thread.Sleep(rnd.Next(10, 50)); WR[b] = new Grabber(saURLs[b]); } while (true) { bool bDone = true; int olThreadsChecked = 0; for (int b = 0; b < WR.Length; b++) { if (WR[b].done) { olThreadsChecked++; } else { bDone = false; } } lThreadsChecked += olThreadsChecked; GUI(); lThreadsChecked -= olThreadsChecked; System.Threading.Thread.Sleep(100); if (bDone) { break; } } lThreadsChecked += WR.Length; for (int b = 0; b < WR.Length; b++) { string thHTML = WR[b].ret.ToLower(); for (int c = 0; c < saTerm.Length; c++) { if (thHTML.Contains(saTerm[c])) { sFoundWrd += saTerm[c] + "\n"; sFoundURL += WR[b].uri.AbsoluteUri + "\n"; thHTML = thHTML.Replace("\r", "").Replace("\n", "") .Replace("<br />", " .. "); thHTML = System.Text.RegularExpressions.Regex .Replace(thHTML, "<(.|\n)*?>", " - "); int StartOfs = thHTML.IndexOf(saTerm[c]) - 40; if (StartOfs < 0) { StartOfs = 0; } int TotLen = 40 + saTerm[c].Length; if (StartOfs != 0) { TotLen += 40; } if (StartOfs + TotLen > thHTML.Length) { StartOfs = 0; TotLen = thHTML.Length; } sFoundCtx += thHTML.Substring(StartOfs, TotLen) + "\n"; } } } string[] saFound = sFoundURL.TrimEnd('\n').Split('\n'); lFound = saFound.Length; if (saFound[0] == "") { lFound = 0; } lBoardsChecked++; GUI(); } sFoundWrd = sFoundWrd.TrimEnd('\n'); sFoundURL = sFoundURL.TrimEnd('\n'); sFoundCtx = sFoundCtx.TrimEnd('\n'); dtLastSearch = System.DateTime.Now; MessageBox.Show( "Found " + lFound + " instances across " + lThreadsChecked + " threads." + "\r\n\r\n" + "(multiple hits of same word in same threads not counted)"); } catch (Exception ex) { MessageBox.Show("Oh snap, something went wrong." + "\r\n\r\n" + ex.Message); } }