Skip to content

Commit

Permalink
次スレ検索ロジックの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ggslyman committed Apr 2, 2014
1 parent 0e2f978 commit d2dcb11
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 42 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@

##更新履歴

* 14/04/03 2.0.1 Rev.14
- 次スレ検索ロジックを追加。次スレ検索キーワードが入力されている場合、現在のスレより新しい、指定のキーワードを含むスレを新スレとして開く。

* 14/04/03 2.0.1 Rev.13
- 画像をビューアに表示するURL判別が小文字固定になってたので、大文字小文字を無視して判別するよう修正
- 左のレス一覧を隠すオプションボタンを追加
Expand Down
23 changes: 20 additions & 3 deletions SpeechCast/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 60 additions & 37 deletions SpeechCast/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ private async Task<bool> GetFromURL(bool next)
if (m.Success)
{
rawURL = m.Groups[1].Value + "/bbs/rawmode.cgi" + m.Groups[2];
AddLog("jbbs rawmode: {0}", rawURL);
threadId = m.Groups[5].Value;
AddLog("jbbs rawmode: {0} {1}", rawURL, threadId);
Response.Style = Response.BBSStyle.jbbs;
encodingName = "EUC-JP";

Expand All @@ -383,9 +384,10 @@ private async Task<bool> GetFromURL(bool next)
if (m.Success)
{
rawURL = m.Groups[1].Value + "/" + m.Groups[2].Value + "/dat/" + m.Groups[3].Value + ".dat";
threadId = m.Groups[3].Value;
Response.Style = Response.BBSStyle.yykakiko;

AddLog("yykakiko dat mode: {0}", rawURL);
AddLog("yykakiko dat mode: {0} {1}", rawURL , threadId);

encodingName = "Shift_JIS";
baseURL = string.Format("{0}/{1}/", m.Groups[1], m.Groups[2]);
Expand All @@ -396,9 +398,10 @@ private async Task<bool> GetFromURL(bool next)
if (m.Success)
{
rawURL = m.Groups[1].Value + "/" + m.Groups[2].Value + "/dat/" + m.Groups[3].Value + ".dat";
threadId = m.Groups[3].Value;
Response.Style = Response.BBSStyle.nichan;

AddLog("2ch dat mode: {0}", rawURL);
AddLog("2ch dat mode: {0} {1}", rawURL , threadId);

encodingName = "Shift_JIS";
baseURL = string.Format("{0}/{1}/", m.Groups[1], m.Groups[2]);
Expand Down Expand Up @@ -443,38 +446,37 @@ private async Task<bool> GetFromURL(bool next)
// Webアクセス部分を非同期化するためTask.Runで囲む
await Task.Run(() =>
{
System.Net.HttpWebRequest webReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webReq.KeepAlive = false;
FormMain.UserConfig.SetProxy(webReq);
if (UserConfig.GZipCompressionEnabled && useRangeHeader == false)
{
webReq.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
}
#if DEBUG
//AddLog("datSize={0} lastModifiedTime={1} useRangeHeader={2}",
// datSize, lastModifiedDateTime.ToLongTimeString(), useRangeHeader);
#endif
if (useRangeHeader)
try
{
webReq.AddRange(datSize - 1);
webReq.IfModifiedSince = lastModifiedDateTime;
}
System.Net.HttpWebRequest webReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webReq.KeepAlive = false;
FormMain.UserConfig.SetProxy(webReq);
if (UserConfig.GZipCompressionEnabled && useRangeHeader == false)
{
webReq.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
}
if (useRangeHeader)
{
webReq.AddRange(datSize - 1);
webReq.IfModifiedSince = lastModifiedDateTime;
}
gettingWebTime = System.DateTime.Now; //例外が発生した場合、連続してwebアクセスが起こるのを防ぐ
gettingWebTime = System.DateTime.Now; //例外が発生した場合、連続してwebアクセスが起こるのを防ぐ
stopWatch.Start();
//サーバーからの応答を受信するためのWebResponseを取得
webReq.Timeout = 10000;
webRes = (System.Net.HttpWebResponse)webReq.GetResponse();
stopWatch.Start();
//サーバーからの応答を受信するためのWebResponseを取得
webReq.Timeout = 10000;
webRes = (System.Net.HttpWebResponse)webReq.GetResponse();
lastModifiedDateTime = webRes.LastModified;
responseTime = stopWatch.ElapsedMilliseconds;
//if (useRangeHeader)
//{
// throw (new Exception(" 416 "));
//}
lastModifiedDateTime = webRes.LastModified;
responseTime = stopWatch.ElapsedMilliseconds;
}
catch (System.Net.WebException e)
{
webReqResult = false;
}
});// 非同期処理終了
}
catch (System.Net.WebException e)
Expand Down Expand Up @@ -1295,7 +1297,7 @@ private async void timerWeb_Tick(object sender, EventArgs e)

// レス取得の条件判定
if (
responses.Count <= Response.MaxResponseCount
responses.Count < Response.MaxResponseCount
&& this.endWebRequest
)
{
Expand Down Expand Up @@ -1368,6 +1370,8 @@ private void FormMain_Load(object sender, EventArgs e)
this.splitContainerResCaption.SplitterDistance = 2000;
toolStripButtonAutoScroll.Checked = UserConfig.EnableAutoScroll;
toolStripButtonListToggle.Checked = !UserConfig.ViewResList;
toolStripTextBoxThreadKeyword.Text = UserConfig.ThreadKeyword;

this.viewResList(UserConfig.ViewResList);
}
catch (Exception ex)
Expand Down Expand Up @@ -1439,6 +1443,7 @@ private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
UserConfig.SetFormToRect(ref UserConfig.FormMainRect, this);
UserConfig.SetFormToRect(ref UserConfig.FormCaptionRect, FormCaption.Instance);
UserConfig.URL = toolStripTextBoxURL.Text;
UserConfig.ThreadKeyword = toolStripTextBoxThreadKeyword.Text;
UserConfig.Serialize();
Bookmarks.Serialize();
}
Expand Down Expand Up @@ -1887,6 +1892,7 @@ private void toolStripButtonAutoNextThread_Click(object sender, EventArgs e)
// 「現在の条件+現在のスレより後に立てられたスレに絞り込む」
// 「現在のスレより後に立てられたスレが1件のみであれば数字の一致を確認しない」
// 等を想定。そういえばゴミスレはどうすりゃいいんだ・・・
private string threadId = null;
private int openNextThreadUrl(){
// 最初の数字検索用の正規表現オブジェクト
System.Text.RegularExpressions.Regex r =
Expand All @@ -1896,7 +1902,7 @@ private int openNextThreadUrl(){
// スレタイのレス数の削除用正規表現オブジェクト
System.Text.RegularExpressions.Regex rTitle =
new System.Text.RegularExpressions.Regex(
@"(?<title>\\d+?)\([0-9]+\)",
@"(?<title>\\d+?)\\([0-9]+\\)",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string nextUrl = null;
try
Expand All @@ -1908,7 +1914,7 @@ private int openNextThreadUrl(){
// 現在のスレタイから連番と思われる部分を抽出
System.Text.RegularExpressions.Match m = r.Match(searchTitle);
string nextNumber = null;
AddLog(searchTitle);
// AddLog(searchTitle);
if (m.Success)
{
// 取得した数字をインクリメントして文字列として格納
Expand Down Expand Up @@ -1953,14 +1959,29 @@ private int openNextThreadUrl(){
// スレタイを取得
parseSubject = s.Replace("<>", ",").Split(',');
string searchSubject = zen2han(parseSubject[1]);
string searchThreadid = parseSubject[0].Split('.')[0];
// スレタイの連番部分を取得
System.Text.RegularExpressions.Match m2 = r.Match(searchSubject);
if(m2.Success)
if (
// 指定キーワードを含む、今スレより当たらしいスレが見つかれば
toolStripTextBoxThreadKeyword.Text.Trim().Length > 0
&& searchSubject.IndexOf(toolStripTextBoxThreadKeyword.Text) >= 0
&& Int32.Parse(threadId) < Int32.Parse(searchThreadid)
)
{
// 一致データをメンバ変数に入れてループを抜ける
threadId = null;
nextUrl = parseSubject[0];
threadTitle = parseSubject[1];
break;
}
if (m2.Success)
{
// 連番部分が次スレ連番候補と一致したら
if (m2.Value == nextNumber)
{
// 一致データをメンバ変数に入れてループを抜ける
threadId = null;
nextUrl = parseSubject[0];
threadTitle = parseSubject[1];
break;
Expand All @@ -1969,7 +1990,6 @@ private int openNextThreadUrl(){
}
}
System.Text.RegularExpressions.Match m3 = r.Match(nextUrl);
string threadId = null;
if (m3.Success)
{
//一致した対象が見つかったときキャプチャした部分文字列を表示
Expand All @@ -1984,8 +2004,11 @@ private int openNextThreadUrl(){
// スレタイを更新して、フラグを次スレオープン状態に変更
toolStripTextBoxURL.Text = threadUrl;
rawURL = null;

System.Text.RegularExpressions.Match mtitle = r.Match(parseSubject[1]);
responses.Clear();
oldResCount = 0;
Object[] objArray = new Object[1];
webBrowser.Document.InvokeScript("clearRes", objArray);
System.Text.RegularExpressions.Match mtitle = rTitle.Match(threadTitle);
if (mtitle.Success) threadTitle = mtitle.Groups["title"].Value;
return OpenNextThread;
}
Expand Down
4 changes: 2 additions & 2 deletions SpeechCast/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.13")]
[assembly: AssemblyFileVersion("2.0.1.13")]
[assembly: AssemblyVersion("2.0.1.14")]
[assembly: AssemblyFileVersion("2.0.1.14")]
8 changes: 8 additions & 0 deletions SpeechCast/UseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,16 @@ public void SupplementSettings()
/// </summary>
public int AutoScrollSpeed = 1;

/// <summary>
/// レス一覧の表示非表示フラグ
/// </summary>
public bool ViewResList = true;

/// <summary>
/// 自動次スレ検索時のHIT条件キーワード
/// </summary>
public string ThreadKeyword = "";

/// <summary>
/// 読み上げONOFF
/// </summary>
Expand Down

0 comments on commit d2dcb11

Please sign in to comment.