| 1 |
unit NicoVitanD_pas; |
| 2 |
// 2014/02/20 ファイルフォーマットを UTF-8 に変更 |
| 3 |
|
| 4 |
interface |
| 5 |
|
| 6 |
uses |
| 7 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 8 |
Dialogs, ComCtrls, TabNotBk, Grids, {Outline,} StdCtrls, FileCtrl, DBGrids, |
| 9 |
dblookup, Menus, ExtCtrls, IniFiles, xmldom, XMLIntf, msxmldom, XMLDoc, |
| 10 |
ExtDlgs, |
| 11 |
{$IFDEF DEBUG} |
| 12 |
MMSystem, // 処理に掛かった時間を計測する |
| 13 |
{$ENDIF} |
| 14 |
RegularExpressions, |
| 15 |
HTTPApp, |
| 16 |
SHELLAPI, |
| 17 |
CommCtrl ; |
| 18 |
const |
| 19 |
TAGLIST = 15; |
| 20 |
|
| 21 |
type |
| 22 |
TCommentData = record |
| 23 |
CommentNum : Integer; // { TODO add 2014/10/29: UserID → UserName(コテハン) に変換する関数を作る } |
| 24 |
UserName, Comment, CommentTime, ElapsedTime, Premium : string; |
| 25 |
end; |
| 26 |
TCommentDataArray = array of TCommentData; // 動的配列宣言 |
| 27 |
|
| 28 |
TLiveData = record // 2014年11月6日 設定途中 |
| 29 |
// IsLiveStatus[0:削除済 1:放送前 2:放送中 3:タイムシフト期間中 4:タイムシフト無し 5:タイムシフト期間後 6:存在していない未来のLvID] |
| 30 |
LiveAudience, LiveComment, IsLiveStatus : Integer; |
| 31 |
StartTime, OpenTime, LiveOwner, LiveTitle, LiveMemo, LiveID : string; |
| 32 |
LiveTags : array[1..TAGLIST] of string; |
| 33 |
end; |
| 34 |
|
| 35 |
TCommunityData = record |
| 36 |
CommunityAudience, CommunityLevel, CommunityMember, |
| 37 |
CommunityName, CommunityMemo, CommunityID, CommunityOwnerName, CommunityOpenDay : string; // CommunityIDはチャンネルとコミュニティを格納する |
| 38 |
IsCommunityMember, CommunityStatus, IsCommunityGetInfo : Boolean; // CommunityStatus[0:closed 1:open] |
| 39 |
CommunityTags : array[1..TAGLIST] of string; |
| 40 |
end; |
| 41 |
|
| 42 |
TUserData = record |
| 43 |
// IsUserGetInfo[0:取得できなかった 1:取得できた] 0の場合削除ユーザーなどの場合指定する。 |
| 44 |
// UserIsDead[0:個人非公開 1:公開] |
| 45 |
IsUserGetInfo, UserIsDead : Boolean; |
| 46 |
UserBirthday : Int64; |
| 47 |
UserName, UserID, UserLocation, UserSex, UserMemo : string; |
| 48 |
UserStamp, UserNicorare, UserFav : Integer; |
| 49 |
// UserSex [0:非公開 1:男性 2:女性] |
| 50 |
end; |
| 51 |
|
| 52 |
TStatusArray = array [0..20] of Int64; |
| 53 |
|
| 54 |
TForm1 = class(TForm) |
| 55 |
MainMenu1: TMainMenu; |
| 56 |
File2: TMenuItem; |
| 57 |
New2: TMenuItem; |
| 58 |
LogOpen: TMenuItem; |
| 59 |
Save2: TMenuItem; |
| 60 |
SaveAs2: TMenuItem; |
| 61 |
Print2: TMenuItem; |
| 62 |
PrintSetup2: TMenuItem; |
| 63 |
Exit2: TMenuItem; |
| 64 |
N6: TMenuItem; |
| 65 |
N7: TMenuItem; |
| 66 |
Edit2: TMenuItem; |
| 67 |
Undo1: TMenuItem; |
| 68 |
Copy2: TMenuItem; |
| 69 |
Paste2: TMenuItem; |
| 70 |
PasteSpecial2: TMenuItem; |
| 71 |
Find2: TMenuItem; |
| 72 |
GoTo2: TMenuItem; |
| 73 |
Links2: TMenuItem; |
| 74 |
Object2: TMenuItem; |
| 75 |
N8: TMenuItem; |
| 76 |
N9: TMenuItem; |
| 77 |
N10: TMenuItem; |
| 78 |
Window2: TMenuItem; |
| 79 |
NewWindow2: TMenuItem; |
| 80 |
Tile2: TMenuItem; |
| 81 |
Cascade2: TMenuItem; |
| 82 |
ArrangeAll2: TMenuItem; |
| 83 |
Hide2: TMenuItem; |
| 84 |
TopShow: TMenuItem; |
| 85 |
N11: TMenuItem; |
| 86 |
Help1: TMenuItem; |
| 87 |
Contents1: TMenuItem; |
| 88 |
Commands1: TMenuItem; |
| 89 |
About1: TMenuItem; |
| 90 |
N1: TMenuItem; |
| 91 |
MenuLogin: TMenuItem; |
| 92 |
ListView1: TListView; |
| 93 |
MenuComment: TMenuItem; |
| 94 |
NameID1: TMenuItem; |
| 95 |
CommentPanel: TPanel; |
| 96 |
CommentEdit: TEdit; |
| 97 |
CommentSendbtn: TButton; |
| 98 |
MenuSetting: TMenuItem; |
| 99 |
N2: TMenuItem; |
| 100 |
WindowSizeTop: TMenuItem; |
| 101 |
N800x600: TMenuItem; |
| 102 |
N1024x768: TMenuItem; |
| 103 |
N1200x800: TMenuItem; |
| 104 |
XMLDocument1: TXMLDocument; |
| 105 |
OpenTextFileDialog1: TOpenTextFileDialog; |
| 106 |
SaveTextFileDialog1: TSaveTextFileDialog; |
| 107 |
PopupMenu1: TPopupMenu; |
| 108 |
N3: TMenuItem; |
| 109 |
ProgramInfo: TMenuItem; |
| 110 |
StatusBar: TStatusBar; |
| 111 |
a1: TMenuItem; |
| 112 |
b1: TMenuItem; |
| 113 |
procedure Exit2Click(Sender: TObject); |
| 114 |
procedure Contents1Click(Sender: TObject); |
| 115 |
procedure NameID1Click(Sender: TObject); |
| 116 |
procedure Print2Click(Sender: TObject); |
| 117 |
procedure PrintSetup2Click(Sender: TObject); |
| 118 |
procedure MenuLoginClick(Sender: TObject); |
| 119 |
procedure MenuCommentClick(Sender: TObject); |
| 120 |
procedure CommentSendbtnClick(Sender: TObject); |
| 121 |
procedure CommentEditClick(Sender: TObject); |
| 122 |
procedure MenuSettingClick(Sender: TObject); |
| 123 |
procedure FormCreate(Sender: TObject); |
| 124 |
procedure FormDestroy(Sender: TObject); |
| 125 |
procedure N800x600Click(Sender: TObject); |
| 126 |
procedure N1024x768Click(Sender: TObject); |
| 127 |
procedure N1200x800Click(Sender: TObject); |
| 128 |
procedure LogOpenClick(Sender: TObject); |
| 129 |
procedure SaveAs2Click(Sender: TObject); |
| 130 |
procedure XmlFileCheckEncoding(FileName:string); |
| 131 |
procedure XMLRaedVirtualView(FileName:string; Encoding: TEncoding); |
| 132 |
procedure ListView1SelectItem(Sender: TObject; Item: TListItem; |
| 133 |
Selected: Boolean); |
| 134 |
procedure AddNGComment2(CommentDateArrayIndex: Integer); |
| 135 |
procedure ProgramInfoClick(Sender: TObject); |
| 136 |
procedure ListView1CustomDrawSubItem(Sender: TCustomListView; |
| 137 |
Item: TListItem; SubItem: Integer; State: TCustomDrawState; |
| 138 |
var DefaultDraw: Boolean); |
| 139 |
procedure ListView1AdvancedCustomDrawSubItem(Sender: TCustomListView; |
| 140 |
Item: TListItem; SubItem: Integer; State: TCustomDrawState; |
| 141 |
Stage: TCustomDrawStage; var DefaultDraw: Boolean); |
| 142 |
procedure ListView1CustomDrawItem(Sender: TCustomListView; |
| 143 |
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); |
| 144 |
function CommentURLDecode(Str:string):string; |
| 145 |
function CommentBackStagePass(Str:string):string; // Add: 2013/07/27 |
| 146 |
procedure TopShowClick(Sender: TObject); |
| 147 |
procedure SetLVItemFont(ACustomListView: TCustomListView; AListItem: TListItem); |
| 148 |
function PrepareComments(rawComment: string): string; |
| 149 |
procedure CommentEditChange(Sender: TObject); |
| 150 |
procedure kakorokuDataEdit(kakorokuData:TStringlist); |
| 151 |
procedure SetProgramInfoDlg(Sender: TObject); |
| 152 |
procedure ListView1Data(Sender: TObject; Item: TListItem); |
| 153 |
procedure ResetProgramInfoDlgData(Sender: TObject); |
| 154 |
procedure SetStatusBar(StatusArray: TStatusArray); |
| 155 |
procedure ListView1Click(Sender: TObject); |
| 156 |
|
| 157 |
private |
| 158 |
FCommentData: TCommentDataArray; |
| 159 |
FLiveData: TLiveData; |
| 160 |
FUserData: TUserData; |
| 161 |
{ Private 宣言 } |
| 162 |
procedure WindowResize(x, y:integer); // ウィンドウサイズ変更 |
| 163 |
|
| 164 |
//WM_DROPFILESを受け取るイベントハンドラの宣言 ドラッグアンドドロップ用 |
| 165 |
procedure WMDropFiles(var msg: TWMDROPFILES); message WM_DROPFILES; // 2014/05/25 参照コード変更 |
| 166 |
public |
| 167 |
{ Public 宣言 } |
| 168 |
FCommunityData: TCommunityData; |
| 169 |
end; |
| 170 |
|
| 171 |
var |
| 172 |
Form1: TForm1; |
| 173 |
kakorokuData: TStringlist; |
| 174 |
CommentDateArrayIndex: Integer; |
| 175 |
implementation |
| 176 |
|
| 177 |
uses |
| 178 |
NicoVitanD_Login, |
| 179 |
NicoVitanD_setting, |
| 180 |
ProgramInfoTabDlg, |
| 181 |
NicoVitanD_Functions, NicoVitanD_StatusBar, EncodeDetect; |
| 182 |
|
| 183 |
{$R *.dfm} |
| 184 |
|
| 185 |
procedure TForm1.AddNGComment2(CommentDateArrayIndex: Integer); |
| 186 |
begin |
| 187 |
FCommentData[CommentDateArrayIndex].UserName := ' '; |
| 188 |
FCommentData[CommentDateArrayIndex].CommentNum := CommentDateArrayIndex + 1 ; |
| 189 |
FCommentData[CommentDateArrayIndex].Comment := IntToStr(CommentDateArrayIndex + 1) + '番目のコメントは NGコメントです。'; |
| 190 |
FCommentData[CommentDateArrayIndex].CommentTime:= UnixTimeToDatetimeStr(0); |
| 191 |
FCommentData[CommentDateArrayIndex].ElapsedTime:= UnixTimeToDatetimeStr(0); |
| 192 |
FCommentData[CommentDateArrayIndex].Premium := '100'; |
| 193 |
end; |
| 194 |
|
| 195 |
procedure TForm1.CommentSendbtnClick(Sender: TObject); |
| 196 |
begin |
| 197 |
CommentPanel.Visible := False; |
| 198 |
end; |
| 199 |
|
| 200 |
function TForm1.CommentBackStagePass(Str: string): string; |
| 201 |
begin |
| 202 |
(* 書式:/press show 色 コメント 名前 色も返して色を付ける? |
| 203 |
色 |
| 204 |
white : clWhite |
| 205 |
red : clRed |
| 206 |
pink : clWebPink |
| 207 |
orange : clWebOrange |
| 208 |
green : clGreen |
| 209 |
cyan : clWebCyan |
| 210 |
blue : clBlue |
| 211 |
purple : clPurple |
| 212 |
black : clBlack |
| 213 |
niconicowhite : clWhite? |
| 214 |
*) |
| 215 |
if TRegEx.IsMatch(Str, '/press show ') then |
| 216 |
Result:= TRegEx.Replace(Str, '^/press show ', 'BSP: ') |
| 217 |
else |
| 218 |
Result := Str; |
| 219 |
end; |
| 220 |
|
| 221 |
procedure TForm1.CommentEditChange(Sender: TObject); |
| 222 |
begin |
| 223 |
// CommentEdit.Alignment := taCenter; |
| 224 |
end; |
| 225 |
|
| 226 |
procedure TForm1.CommentEditClick(Sender: TObject); |
| 227 |
begin |
| 228 |
// CommentEdit.Alignment := taLeftJustify; |
| 229 |
end; |
| 230 |
|
| 231 |
function TForm1.CommentURLDecode(Str: string): string; |
| 232 |
begin |
| 233 |
if TRegEx.IsMatch(Str, '^/play case') then |
| 234 |
Result:= HTTPDecode(Str) |
| 235 |
else |
| 236 |
Result := Str; |
| 237 |
end; |
| 238 |
|
| 239 |
procedure TForm1.Contents1Click(Sender: TObject); |
| 240 |
begin |
| 241 |
// function FileOpen(const FileName: string; fmOpenRead: LongWord): Integer; |
| 242 |
end; |
| 243 |
|
| 244 |
procedure TForm1.SetProgramInfoDlg(Sender: TObject); // 途中 |
| 245 |
begin |
| 246 |
ProgramInfoDlg.LiveStartTimeLabel.Caption := ProgramInfoDlg.LiveStartTimeLabel.Caption + FLiveData.StartTime; |
| 247 |
ProgramInfoDlg.LiveTitleLE.Text := ProgramInfoDlg.LiveTitleLE.Text + FLiveData.LiveTitle; |
| 248 |
ProgramInfoDlg.LiveOwnerLabel.Caption := ProgramInfoDlg.LiveOwnerLabel.Caption + FLiveData.LiveOwner; |
| 249 |
ProgramInfoDlg.SetLiveURL(FLiveData.LiveID); |
| 250 |
ProgramInfoDlg.LiveMemo.Text := FLiveData.LiveMemo; |
| 251 |
if FLiveData.LiveComment = -1 then |
| 252 |
begin |
| 253 |
FLiveData.LiveComment := 0; |
| 254 |
ProgramInfoDlg.LiveCommentLabel.Caption := ProgramInfoDlg.LiveCommentLabel.Caption + IntToStr(FLiveData.LiveComment); |
| 255 |
end |
| 256 |
else |
| 257 |
ProgramInfoDlg.LiveCommentLabel.Caption := ProgramInfoDlg.LiveCommentLabel.Caption + IntToStr(FLiveData.LiveComment); |
| 258 |
|
| 259 |
ProgramInfoDlg.CommunityIDLabel.Caption := ProgramInfoDlg.SetCommunityIdURL(FCommunityData.CommunityID); |
| 260 |
ProgramInfoDlg.CommunityOpenDayLabel.Caption := ProgramInfoDlg.CommunityOpenDayLabel.Caption + FCommunityData.CommunityOpenDay; |
| 261 |
ProgramInfoDlg.CommunityNameLabel.Caption := ProgramInfoDlg.CommunityNameLabel.Caption + FCommunityData.CommunityName; |
| 262 |
ProgramInfoDlg.CommunityLevelLabel.Caption := ProgramInfoDlg.CommunityLevelLabel.Caption + FCommunityData.CommunityLevel; |
| 263 |
ProgramInfoDlg.CommunityAudienceLabel.Caption:= ProgramInfoDlg.CommunityAudienceLabel.Caption + FCommunityData.CommunityAudience; |
| 264 |
ProgramInfoDlg.CommunityMemberLabel.Caption := ProgramInfoDlg.CommunityMemberLabel.Caption + FCommunityData.CommunityMember; |
| 265 |
ProgramInfoDlg.CommunityOwnerNameLabel.Caption := ProgramInfoDlg.CommunityOwnerNameLabel.Caption + FCommunityData.CommunityOwnerName; |
| 266 |
ProgramInfoDlg.UserNameLabel.Caption := ProgramInfoDlg.UserNameLabel.Caption + FLiveData.LiveOwner; |
| 267 |
end; |
| 268 |
|
| 269 |
procedure TForm1.Exit2Click(Sender: TObject); // 終了処理 |
| 270 |
begin |
| 271 |
Close; |
| 272 |
end; |
| 273 |
|
| 274 |
procedure TForm1.FormCreate(Sender: TObject); // NicoVitanD の開始処理 or 初期化 |
| 275 |
var |
| 276 |
Ini: TIniFile; |
| 277 |
WRect: TRect; |
| 278 |
encodings : TStrings; |
| 279 |
begin |
| 280 |
|
| 281 |
// 表示位置をiniファイルから読み込む |
| 282 |
SystemParametersInfo(SPI_GETWORKAREA, 0, @WRect, 0); |
| 283 |
Ini := TInifile.Create(ChangeFileExt( |
| 284 |
Application.ExeName, '.ini')); |
| 285 |
try |
| 286 |
Top := Ini.ReadInteger('Form', 'Top', WRect.Top); |
| 287 |
Left := Ini.ReadInteger('Form', 'Left', WRect.Left); |
| 288 |
Width := Ini.ReadInteger('Form', 'WindowWidth', Width); |
| 289 |
Height := Ini.ReadInteger('Form','WindowHeight', Height); |
| 290 |
|
| 291 |
if Left > WRect.Right - 100 then Left := WRect.Left; // モニタの解像度が変わっても |
| 292 |
if Left < WRect.Left then Left := WRect.Left; // 大丈夫にする処理(4行) |
| 293 |
if Top < WRect.Top then Top := WRect.Top; |
| 294 |
if Top > WRect.Bottom - 100 then Top := WRect.Top; |
| 295 |
finally |
| 296 |
Ini.Free; |
| 297 |
end; |
| 298 |
|
| 299 |
// http://docwiki.embarcadero.com/CodeExamples/XE4/en/TOpenTextFileDialog_%28Delphi%29 |
| 300 |
TOpenTextFileDialog.Create(Self); |
| 301 |
TSaveTextFileDialog.Create(Self); |
| 302 |
|
| 303 |
// Create a new string list that holds encoding info. |
| 304 |
encodings := TStringList.Create; |
| 305 |
|
| 306 |
OpenTextFileDialog1.Encodings.Clear; |
| 307 |
// Add some encodings to the list. |
| 308 |
encodings.AddObject('UTF8', TEncoding.GetEncoding(65001)); // BOM なしにする |
| 309 |
encodings.AddObject('ANSI', TEncoding.Default); |
| 310 |
encodings.AddObject('ASCII', TEncoding.ASCII); |
| 311 |
|
| 312 |
OpenTextFileDialog1.Encodings.Assign(encodings); |
| 313 |
SaveTextFileDialog1.Encodings.Assign(encodings); |
| 314 |
|
| 315 |
// SaveTextFileDialog1.Filter := 'Text files (*.txt)|*.TXT|XML files (*.xml)|*.XML|Any file (*.*)|*.*'; |
| 316 |
SaveTextFileDialog1.Filter := 'XML files (*.xml)|*.XML|Any file (*.*)|*.*'; |
| 317 |
|
| 318 |
// http://docwiki.embarcadero.com/CodeExamples/XE4/en/TOpenTextFileDialog_%28Delphi%29 |
| 319 |
|
| 320 |
Save2.Enabled := False; { TODO -cメニュー : 名前を付けて保存してから有効にする。 } |
| 321 |
Links2.Enabled := False; { TODO -cメニュー : 表示したリスト内にURLの正規表現に一致したら有効にする。 } |
| 322 |
|
| 323 |
//ドラッグの受入れを許可する |
| 324 |
DragAcceptFiles(Handle, true); |
| 325 |
ResetStatusBar(Self); |
| 326 |
encodings.Free; |
| 327 |
end; |
| 328 |
|
| 329 |
procedure TForm1.FormDestroy(Sender: TObject); // NicoVitanD の終了処理 |
| 330 |
var |
| 331 |
Ini : TIniFile; |
| 332 |
begin |
| 333 |
|
| 334 |
// NicoVitanD の本体の位置をiniファイルに記録 |
| 335 |
Ini := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')); |
| 336 |
|
| 337 |
try |
| 338 |
Ini.WriteInteger('Form', 'Top', Top); |
| 339 |
Ini.WriteInteger('Form', 'Left', Left); |
| 340 |
Ini.WriteInteger('Form', 'WindowWidth', Width); |
| 341 |
Ini.WriteInteger('Form', 'WindowHeight', Height); |
| 342 |
finally |
| 343 |
Ini.Free; |
| 344 |
end; |
| 345 |
//// 割り当てたコンソールを開放 |
| 346 |
// FreeConsole; |
| 347 |
end; |
| 348 |
|
| 349 |
|
| 350 |
procedure TForm1.kakorokuDataEdit(kakorokuData: TStringlist); |
| 351 |
var |
| 352 |
StartTime, LiveTitle, URLnum, LiveOwner, ComName, Explanation : string; |
| 353 |
coNum: string; |
| 354 |
kakorokuArray :TStatusArray; |
| 355 |
begin |
| 356 |
StartTime := kakorokuData.Strings[2]; |
| 357 |
LiveTitle := kakorokuData.Strings[4]; |
| 358 |
Explanation := kakorokuData.Strings[5]; |
| 359 |
LiveOwner := kakorokuData.Strings[6]; |
| 360 |
ComName := kakorokuData.Strings[7]; |
| 361 |
|
| 362 |
(* 対象の文字列があるか確認しながら加工 *) |
| 363 |
if TRegEx.IsMatch(StartTime, '放送開始時間') then |
| 364 |
begin |
| 365 |
StartTime := TRegEx.Replace(StartTime, '^\[放送開始時間\] ', ''); |
| 366 |
end; |
| 367 |
|
| 368 |
// タイトル と 放送URL |
| 369 |
if TRegEx.IsMatch(LiveTitle, 'タイトル') then |
| 370 |
begin |
| 371 |
LiveTitle := TRegEx.Replace(LiveTitle, '^\[タイトル\] ', ''); |
| 372 |
|
| 373 |
if TRegEx.IsMatch(LiveTitle, '\(lv\d+\)$|\(co\d+\)$') then // lv番号 or co番号 があるか? |
| 374 |
begin |
| 375 |
URLnum := TRegEx.Replace(LiveTitle, '^.+\(', ''); |
| 376 |
URLnum := TRegEx.Replace(URLnum, '\)$', ''); |
| 377 |
|
| 378 |
if TRegEx.IsMatch(URLnum, 'co') then |
| 379 |
kakorokuArray[10] := StrToInt64( TRegEx.Replace(URLnum, 'co', '') ) |
| 380 |
else |
| 381 |
kakorokuArray[0] := StrToInt64( TRegEx.Replace(URLnum, 'lv', '') ); |
| 382 |
|
| 383 |
LiveTitle := TRegEx.Replace(LiveTitle, '\(lv\d+\)$|\(co\d+\)$', ''); |
| 384 |
end; |
| 385 |
end; |
| 386 |
|
| 387 |
// 放送説明文 |
| 388 |
if TRegEx.IsMatch(Explanation, '説明') then |
| 389 |
begin |
| 390 |
Explanation := TRegEx.Replace(Explanation, '^\[説明\] ', ''); |
| 391 |
end; |
| 392 |
|
| 393 |
// 放送主 |
| 394 |
if TRegEx.IsMatch(LiveOwner, '放送者') then |
| 395 |
begin |
| 396 |
LiveOwner := TRegEx.Replace(LiveOwner, '^\[放送者\] ', ''); |
| 397 |
end; |
| 398 |
|
| 399 |
// コミュニティ名 |
| 400 |
if TRegEx.IsMatch(ComName, 'コミュニティ名') then |
| 401 |
begin |
| 402 |
ComName := TRegEx.Replace(ComName, '\[コミュニティ名\] ', ''); // ゲーム作り隊@ゲームフェス3受賞おめ(co1969367) |
| 403 |
|
| 404 |
if TRegEx.IsMatch(ComName, '\(co\d+\)$|\(ch\d+\)$|\(official\)$') then // co番号 or ch番号があるか? |
| 405 |
begin |
| 406 |
coNum := TRegEx.Replace(ComName, '^.+\(', ''); |
| 407 |
coNum := TRegEx.Replace(coNum, '\)$', ''); |
| 408 |
|
| 409 |
ComName := TRegEx.Replace(ComName, '\(co\d+\)$|\(ch\d+\)$|\(official\)$', ''); |
| 410 |
|
| 411 |
if coNum = 'official' then kakorokuArray[2] := 1 // ステータスバー 公式|チャンネル|ユーザー |
| 412 |
else |
| 413 |
begin |
| 414 |
if TRegEx.IsMatch(coNum, 'ch\d+') then kakorokuArray[2] := 2 |
| 415 |
else |
| 416 |
if TRegEx.IsMatch(coNum, 'co\d+') then kakorokuArray[2] := 3 |
| 417 |
end; |
| 418 |
end; |
| 419 |
end; |
| 420 |
|
| 421 |
ResetProgramInfoDlgData(Self); // Reset関数でFCommentData/FCommunityData/FUserDataのデータを一旦無くす処理 |
| 422 |
(* 流し込み *) |
| 423 |
FLiveData.StartTime := StartTime; |
| 424 |
FLiveData.LiveTitle := LiveTitle; |
| 425 |
FLiveData.LiveOwner := LiveOwner; |
| 426 |
FLiveData.LiveID := URLnum; |
| 427 |
FLiveData.LiveMemo := Explanation; |
| 428 |
FCommunityData.CommunityID := coNum; |
| 429 |
FCommunityData.CommunityName := ComName; |
| 430 |
FUserData.UserName := LiveOwner; |
| 431 |
|
| 432 |
SetProgramInfoDlg(Self); |
| 433 |
|
| 434 |
kakorokuArray[1] := 4; |
| 435 |
SetStatusBar(kakorokuArray); |
| 436 |
end; |
| 437 |
|
| 438 |
procedure TForm1.MenuLoginClick(Sender: TObject); |
| 439 |
begin |
| 440 |
LoginForm.show; |
| 441 |
end; |
| 442 |
|
| 443 |
procedure TForm1.MenuSettingClick(Sender: TObject); |
| 444 |
begin |
| 445 |
SettingForm.ShowModal; |
| 446 |
end; |
| 447 |
|
| 448 |
procedure TForm1.MenuCommentClick(Sender: TObject); |
| 449 |
begin |
| 450 |
CommentEdit.Text := ''; |
| 451 |
CommentPanel.Visible := True; |
| 452 |
CommentEdit.SetFocus; // Add: 2013/07/27 |
| 453 |
end; |
| 454 |
|
| 455 |
procedure TForm1.WindowResize(x, y:integer); // ウィンドウサイズ変更 |
| 456 |
begin |
| 457 |
Form1.Width := x; |
| 458 |
Form1.Height := y; |
| 459 |
|
| 460 |
{ TODO : Add: 2013/09/20 |
| 461 |
NicoVitanDがあるモニターのウィンドウサイズをモニタ解像度の縦半分で横幅目一杯にする設定を追加するのは面白いかな? |
| 462 |
NicoVitanDがあるモニターのウィンドウサイズを取得してそれ1つだけMainMenuに追加するのは面倒臭そうだけども。 |
| 463 |
↓↓↓↓↓↓↓↓↓↓ |
| 464 |
Delphiでディスプレイの解像度を取得するには? | 山本隆の開発日誌 |
| 465 |
→ http://www.gesource.jp/weblog/?p=6093 } |
| 466 |
|
| 467 |
end; |
| 468 |
|
| 469 |
procedure TForm1.WMDropFiles(var msg: TWMDROPFILES); // ドラッグアンドドロップ |
| 470 |
// http://www.watercolor-city.net/ct_delphi/delphi_memo/dm_002.htm |
| 471 |
var |
| 472 |
i,XMLfiles, notXMLfiles, Count: Integer; |
| 473 |
FileName: array [0..255] of Char; |
| 474 |
{ TODO : |
| 475 |
複数ファイルをD&Dされたら、 |
| 476 |
→1.XMLファイルのみの場合:その都度自プログラムを起動させる。 |
| 477 |
→2.XMLファイルが1つもない場合:スルーした数を表示する。 |
| 478 |
→3.XMLファイルと他のファイルが混ざっている場合:1.と2.をやる。 } |
| 479 |
begin |
| 480 |
XMLfiles := 0; |
| 481 |
notXMLfiles := 0; |
| 482 |
Count:= DragQueryFile(Msg.Drop, Cardinal(-1), nil, 0); |
| 483 |
for i:= 0 to Count - 1 do |
| 484 |
begin |
| 485 |
DragQueryFile(Msg.Drop, i, FileName, SizeOf(FileName)-1); |
| 486 |
|
| 487 |
if WideCompareText(ExtractFileExt(Filename), '.xml') = 0 then // 大文字小文字区別なく拡張子を比較 |
| 488 |
begin |
| 489 |
ProgramInfoDlg.ReSetting(Self); |
| 490 |
XmlFileCheckEncoding(FileName); |
| 491 |
Inc(XMLfiles); |
| 492 |
end |
| 493 |
else |
| 494 |
begin |
| 495 |
Showmessage('XMLファイルじゃないよ'); |
| 496 |
Inc(notXMLfiles); |
| 497 |
end; |
| 498 |
end; |
| 499 |
DragFinish(Msg.Drop); |
| 500 |
// http://www.watercolor-city.net/ct_delphi/delphi_memo/dm_002.htm |
| 501 |
end; |
| 502 |
|
| 503 |
procedure TForm1.XmlFileCheckEncoding(FileName: string); |
| 504 |
// 参照:http://www.watercolor-city.net/ct_delphi/delphi_tiburon/doc_thirdparty/tp_ed_sample.htm |
| 505 |
var |
| 506 |
Enc : TEncoding; |
| 507 |
FS: TFileStream; |
| 508 |
function GetEncodingInstance(ENC: Integer): TEncoding; |
| 509 |
begin |
| 510 |
//判定結果に応じたTEncodingインスタンスの生成 |
| 511 |
case ENC of |
| 512 |
ENC_SJIS: Result := TMBCSEncoding.Create(932); |
| 513 |
ENC_EUC: Result := TMBCSEncoding.Create(20932); |
| 514 |
ENC_JIS: Result := TMBCSEncoding.Create(50220); |
| 515 |
ENC_UTF16LE: Result := TUnicodeEncoding.Create; |
| 516 |
ENC_UTF16BE: Result := TBigEndianUnicodeEncoding.Create; |
| 517 |
ENC_UTF8: Result := TMBCSEncoding.Create(65001); |
| 518 |
ENC_UTF8BOM: Result := TUTF8Encoding.Create; |
| 519 |
// ENC_UTF32LE: Result := TUCS4Encoding.Create;//要UCS4Encodingユニット |
| 520 |
// ENC_UTF32BE: Result := TUCS4Encoding.Create(True);//要UCS4Encodingユニット |
| 521 |
else Result := TMBCSEncoding.Create(0); |
| 522 |
end; |
| 523 |
end; |
| 524 |
begin |
| 525 |
// todo add : 2014/02/20 |
| 526 |
// done 2015/02/08 |
| 527 |
// ファイルパスをもらって |
| 528 |
// 文字エンコーディングを返す。 |
| 529 |
FS := TFileStream.Create(Filename, fmOpenRead); |
| 530 |
try |
| 531 |
ENC:= GetEncodingInstance (CheckEncoding(FS)); |
| 532 |
finally |
| 533 |
FS.Free; // Free し忘れるとファイルを二重に開くことになって処理が途中で終わってしまう。 |
| 534 |
|
| 535 |
try |
| 536 |
XMLRaedVirtualView(Filename,ENC); |
| 537 |
finally |
| 538 |
ENC.Free; |
| 539 |
end; |
| 540 |
end; |
| 541 |
end; |
| 542 |
|
| 543 |
procedure TForm1.XMLRaedVirtualView(FileName: string; Encoding: TEncoding); |
| 544 |
const |
| 545 |
NodeNum : string = 'no'; |
| 546 |
NodeDate : string = 'date'; |
| 547 |
NodeUser : string = 'user_id'; |
| 548 |
label |
| 549 |
Official, NoComments; |
| 550 |
var |
| 551 |
i, NumTemp, LastNum, CommentNo: Integer; |
| 552 |
EncIndex: Integer; |
| 553 |
FileStrings: TStringList; |
| 554 |
t: Cardinal; // 実行時間計測 |
| 555 |
|
| 556 |
XML_Doc: IXMLDocument; |
| 557 |
packetNode: IXMLNodeList; |
| 558 |
UserId, Comment, ElapsedTime, Premium: string; |
| 559 |
CommentTime, StartTime : Int64; |
| 560 |
NCVdataArray: TStatusArray; |
| 561 |
FileNameStr: string; |
| 562 |
LiveNumbers: TMatchCollection; |
| 563 |
SortList : TStringList; |
| 564 |
procedure SetCommentData(i:Integer); |
| 565 |
begin |
| 566 |
UserId := packetNode[i].Attributes[NodeUser]; |
| 567 |
Comment := packetNode[i].ChildNodes.Nodes[0].NodeValue; |
| 568 |
CommentTime := StrToInt64( packetNode[i].Attributes[NodeDate]); |
| 569 |
ElapsedTime := UnixTimeToElapsedTimeStr(0,CommentTime); |
| 570 |
if packetNode[i].HasAttribute('premium') then |
| 571 |
Premium := packetNode[i].Attributes['premium'] |
| 572 |
else |
| 573 |
Premium := ''; |
| 574 |
|
| 575 |
Comment := PrepareComments(Comment); |
| 576 |
FCommentData[CommentDateArrayIndex].CommentNum := CommentNo; |
| 577 |
FCommentData[CommentDateArrayIndex].UserName := UserId; |
| 578 |
FCommentData[CommentDateArrayIndex].Comment := Comment; |
| 579 |
FCommentData[CommentDateArrayIndex].CommentTime := UnixTimeToDatetimeStr(CommentTime); |
| 580 |
FCommentData[CommentDateArrayIndex].ElapsedTime := ElapsedTime; |
| 581 |
FCommentData[CommentDateArrayIndex].Premium := Premium; |
| 582 |
end; |
| 583 |
|
| 584 |
begin |
| 585 |
if ListView1.GetCount > 0 then |
| 586 |
begin |
| 587 |
ListView1.Clear; |
| 588 |
// ToDo: 新たにファイルを開いたときに書き換わらなかったら |
| 589 |
// 「FCommentData」のメモリ上のデータを解放する |
| 590 |
end; |
| 591 |
FileStrings := TStringList.Create; |
| 592 |
|
| 593 |
if FileExists(Filename) then |
| 594 |
begin |
| 595 |
form1.Caption := Filename + ' - NicoVitanD'; |
| 596 |
{$IFDEF DEBUG} |
| 597 |
timeBeginPeriod(1); t := timeGetTime; |
| 598 |
form1.Caption := 'NicoVitanD-Test - ' + Filename; |
| 599 |
{$ENDIF} |
| 600 |
//display the contents in a memo based on the selected encoding |
| 601 |
FileStrings.LoadFromFile(Filename, Encoding); |
| 602 |
XML_Doc := LoadXMLDocument(FileName); |
| 603 |
|
| 604 |
packetNode := XML_Doc.DocumentElement.ChildNodes; |
| 605 |
if packetNode.Count > 0 then |
| 606 |
begin |
| 607 |
// 初期化処理 |
| 608 |
ResetProgramInfoDlgData(Self); |
| 609 |
ResetStatusBar(Self); |
| 610 |
i := 0; LastNum := 0; NumTemp := 0; CommentDateArrayIndex := 0; |
| 611 |
|
| 612 |
if packetNode[0].NodeName = 'chat' then |
| 613 |
begin |
| 614 |
if packetNode[0].HasAttribute(NodeNum) then |
| 615 |
begin |
| 616 |
if (packetNode.First.Attributes[NodeUser] = 'kakoroku') then |
| 617 |
{ ニコ生のタイムシフト番組保存ソフトの |
| 618 |
kakorokuRecorder の設定 - オプション - 一般タブの「コメントの最初に放送の情報を書き込む」に |
| 619 |
チェックボックスがONの場合への対応 |
| 620 |
書かれた情報を ProgramInfoTabDlg.pas に流し込む。 |
| 621 |
} |
| 622 |
begin |
| 623 |
kakorokuData := TStringlist.Create; |
| 624 |
kakorokuData.Text := packetNode.First.NodeValue; |
| 625 |
kakorokuDataEdit(kakorokuData); |
| 626 |
kakorokuData.Free; |
| 627 |
Inc(i); |
| 628 |
if packetNode.Count > 1 then |
| 629 |
begin |
| 630 |
if not packetNode[1].HasAttribute(NodeNum) then |
| 631 |
begin |
| 632 |
Inc(NumTemp); |
| 633 |
Goto Official; // 公式放送用の処理へ |
| 634 |
end; |
| 635 |
LastNum := packetNode.Last.Attributes[NodeNum]; |
| 636 |
SetLength(FCommentData, LastNum ); // 動的配列(FCommentData)の上限数設定 |
| 637 |
end |
| 638 |
else |
| 639 |
begin |
| 640 |
Goto NoComments; // コメントなし放送=LastNumなど変数の値が不正になるのでNoCommentsに飛ばす |
| 641 |
end |
| 642 |
end |
| 643 |
else |
| 644 |
begin |
| 645 |
LastNum := packetNode.Last.Attributes[NodeNum]; |
| 646 |
SetLength(FCommentData, LastNum ); // 動的配列(FCommentData)の上限数設定 |
| 647 |
end; |
| 648 |
|
| 649 |
CommentNo := StrToInt( packetNode[0].Attributes[NodeNum] ); |
| 650 |
|
| 651 |
// <chat /> の1stに no="1" がないXMLファイル対策 |
| 652 |
// XMLファイルの冒頭が NG コメントで番号が飛んでいる対策 |
| 653 |
while CommentDateArrayIndex < CommentNo -1 do |
| 654 |
begin |
| 655 |
AddNGComment2(CommentDateArrayIndex); |
| 656 |
Inc(CommentDateArrayIndex); |
| 657 |
end; |
| 658 |
|
| 659 |
repeat |
| 660 |
begin |
| 661 |
CommentNo := StrToInt( packetNode[i].Attributes[NodeNum] ); |
| 662 |
if CommentNo = CommentDateArrayIndex + 1 then |
| 663 |
begin // CommentNo に問題の無い場合 |
| 664 |
NumTemp := CommentNo; // エラー処理用 |
| 665 |
SetCommentData(i); |
| 666 |
|
| 667 |
Inc(i); |
| 668 |
Inc(CommentDateArrayIndex); |
| 669 |
|
| 670 |
CommentCounter(CommentDateArrayIndex, LastNum); |
| 671 |
end |
| 672 |
else // CommentNo に問題がある場合 |
| 673 |
begin |
| 674 |
if CommentNo <= NumTemp then // 重複している行分:CommentNoが1つ前と比べて減った場合の処理 |
| 675 |
begin |
| 676 |
repeat |
| 677 |
inc(i); |
| 678 |
CommentNo := StrToInt( packetNode[i].Attributes[NodeNum] ); |
| 679 |
until CommentNo > NumTemp; |
| 680 |
end |
| 681 |
else |
| 682 |
while CommentDateArrayIndex < CommentNo -1 do // コメントが飛んでいるのがみつかったらNGコメントにする。 |
| 683 |
begin |
| 684 |
AddNGComment2(CommentDateArrayIndex); |
| 685 |
Inc(CommentDateArrayIndex); |
| 686 |
end; |
| 687 |
end; |
| 688 |
end; |
| 689 |
until ( CommentNo = LastNum ) or |
| 690 |
(CommentDateArrayIndex > packetNode.Count * 3); // 無限ループ対策 NGコメントが一般コメントの 2倍を超える時点でおかしい放送 |
| 691 |
|
| 692 |
// 最後のコメントの1つ前がNGだった場合にコメントが空になる対策。 |
| 693 |
if CommentDateArrayIndex <> LastNum then |
| 694 |
begin |
| 695 |
SetCommentData(i); |
| 696 |
FCommentData[CommentDateArrayIndex].CommentNum := CommentDateArrayIndex +1; |
| 697 |
Inc(CommentDateArrayIndex); // 総コメント数として |
| 698 |
end; |
| 699 |
ProgramInfoDlg.LiveCommentLabel.Caption := ProgramInfoDlg.LiveCommentLabel.Caption + IntToStr(CommentDateArrayIndex); // 総コメント数表示 |
| 700 |
end |
| 701 |
else // 公式放送対応 |
| 702 |
Official: |
| 703 |
begin |
| 704 |
LastNum := packetNode.Count; |
| 705 |
SetLength(FCommentData, LastNum); // 動的配列(FCommentData)の上限数設定 |
| 706 |
for I := NumTemp to packetNode.Count - 1 do |
| 707 |
begin |
| 708 |
// 公式の場合 NodeNum がないっぽいのでCommentNo を「i」で代用 |
| 709 |
SetCommentData(i); |
| 710 |
FCommentData[CommentDateArrayIndex].CommentNum := CommentDateArrayIndex +1; |
| 711 |
Inc(CommentDateArrayIndex); |
| 712 |
|
| 713 |
CommentCounter(CommentDateArrayIndex, LastNum); |
| 714 |
end; |
| 715 |
ProgramInfoDlg.LiveCommentLabel.Caption := ProgramInfoDlg.LiveCommentLabel.Caption + IntToStr(CommentDateArrayIndex); // 総コメント数表示 |
| 716 |
end; |
| 717 |
end |
| 718 |
else if packetNode[7].NodeName = 'LiveCommentDataArray' then // NCV の過去ログの読み込み処理 |
| 719 |
begin |
| 720 |
// 放送情報取得 // ToDo : データがあるかチェックするようにする |
| 721 |
LastNum := packetNode[7].ChildNodes.Count; |
| 722 |
|
| 723 |
if packetNode[5].ChildNodes[0].ChildNodes[6].HasChildNodes then |
| 724 |
begin |
| 725 |
StartTime := StrToInt64( packetNode[5].ChildNodes[0].ChildNodes[6].NodeValue); |
| 726 |
FLiveData.StartTime := UnixTimeToDatetimeStr(StartTime); |
| 727 |
end; |
| 728 |
if packetNode[5].ChildNodes[0].ChildNodes[5].HasChildNodes then |
| 729 |
begin |
| 730 |
FLiveData.OpenTime := UnixTimeToDatetimeStr( StrToInt64( packetNode[5].ChildNodes[0].ChildNodes[5].NodeValue)); |
| 731 |
end; |
| 732 |
if packetNode[1].HasChildNodes then |
| 733 |
begin |
| 734 |
FLiveData.LiveID := 'lv' + packetNode[1].NodeValue; |
| 735 |
NCVdataArray[0] := packetNode[1].NodeValue; |
| 736 |
end; |
| 737 |
if packetNode[4].ChildNodes[0].HasChildNodes then |
| 738 |
FLiveData.LiveTitle := packetNode[4].ChildNodes[0].NodeValue; |
| 739 |
if packetNode[4].ChildNodes[1].HasChildNodes then |
| 740 |
FLiveData.LiveOwner := packetNode[4].ChildNodes[1].NodeValue; |
| 741 |
if packetNode[4].ChildNodes[4].ChildNodes[0].HasChildNodes then |
| 742 |
FLiveData.LiveAudience := packetNode[4].ChildNodes[4].ChildNodes[0].NodeValue; |
| 743 |
if LastNum = 0 then |
| 744 |
FLiveData.LiveComment := 0 |
| 745 |
else |
| 746 |
begin |
| 747 |
FLiveData.LiveComment := LastNum; |
| 748 |
NCVdataArray[3] := LastNum; |
| 749 |
end; |
| 750 |
|
| 751 |
// コミュニティ情報 |
| 752 |
if packetNode[4].ChildNodes[3].HasChildNodes then |
| 753 |
FCommunityData.CommunityAudience := packetNode[4].ChildNodes[3].NodeValue; |
| 754 |
if packetNode[4].ChildNodes[4].ChildNodes[1].HasChildNodes then |
| 755 |
FCommunityData.CommunityOpenDay:= packetNode[4].ChildNodes[4].ChildNodes[1].NodeValue; |
| 756 |
if packetNode[4].ChildNodes[4].ChildNodes[4].HasChildNodes then |
| 757 |
FCommunityData.CommunityName := packetNode[4].ChildNodes[4].ChildNodes[4].NodeValue; |
| 758 |
if packetNode[4].ChildNodes[4].ChildNodes[5].HasChildNodes then |
| 759 |
FCommunityData.CommunityLevel := packetNode[4].ChildNodes[4].ChildNodes[5].NodeValue; |
| 760 |
if packetNode[5].ChildNodes[0].ChildNodes[7].HasChildNodes then |
| 761 |
FCommunityData.CommunityID := packetNode[5].ChildNodes[0].ChildNodes[7].NodeValue; |
| 762 |
if packetNode[4].ChildNodes[4].ChildNodes[3].HasChildNodes then |
| 763 |
FCommunityData.CommunityOwnerName := packetNode[4].ChildNodes[4].ChildNodes[3].NodeValue; |
| 764 |
if packetNode[4].ChildNodes[4].ChildNodes[6].HasChildNodes then |
| 765 |
FCommunityData.CommunityMember := packetNode[4].ChildNodes[4].ChildNodes[6].NodeValue; |
| 766 |
|
| 767 |
NCVdataArray[1] := 5; |
| 768 |
SetStatusBar(NCVdataArray); |
| 769 |
SetProgramInfoDlg(Self); |
| 770 |
|
| 771 |
if LastNum > 0 then // コメントデータ流し込み |
| 772 |
begin |
| 773 |
SetLength(FCommentData, LastNum ); // 動的配列(FCommentData)の上限数設定 |
| 774 |
for I := 0 to LastNum - 1 do |
| 775 |
begin |
| 776 |
CommentNo := StrToInt( packetNode[7].ChildNodes[i].Attributes[NodeNum] ); |
| 777 |
if CommentNo = -1 then // 3.公式放送対応 |
| 778 |
CommentNo := i + 1; |
| 779 |
|
| 780 |
UserId := packetNode[7].ChildNodes[i].Attributes[NodeUser]; |
| 781 |
Comment := packetNode[7].ChildNodes[i].ChildNodes.Nodes[0].NodeValue; |
| 782 |
CommentTime := StrToInt64Def( packetNode[7].ChildNodes[i].Attributes[NodeDate] , 0); |
| 783 |
ElapsedTime := UnixTimeToElapsedTimeStr(StartTime,CommentTime); |
| 784 |
if packetNode[7].ChildNodes[i].HasAttribute('premium') then |
| 785 |
Premium := packetNode[7].ChildNodes[i].Attributes['premium'] |
| 786 |
else |
| 787 |
Premium := ''; |
| 788 |
if CommentTime = 0 then // NCVの過去ログファイルのNGコメント処理 |
| 789 |
Premium := '100'; |
| 790 |
|
| 791 |
Comment := PrepareComments(Comment); |
| 792 |
FCommentData[CommentDateArrayIndex].CommentNum := CommentNo; |
| 793 |
FCommentData[CommentDateArrayIndex].UserName := UserId; |
| 794 |
FCommentData[CommentDateArrayIndex].Comment := Comment; |
| 795 |
FCommentData[CommentDateArrayIndex].CommentTime := UnixTimeToDatetimeStr(CommentTime); |
| 796 |
FCommentData[CommentDateArrayIndex].ElapsedTime := ElapsedTime; |
| 797 |
FCommentData[CommentDateArrayIndex].Premium := Premium; |
| 798 |
Inc(CommentDateArrayIndex); |
| 799 |
CommentCounter(CommentDateArrayIndex, LastNum); |
| 800 |
end; |
| 801 |
end |
| 802 |
else |
| 803 |
goto NoComments; |
| 804 |
end; |
| 805 |
end |
| 806 |
else |
| 807 |
NoComments: |
| 808 |
begin |
| 809 |
CommentDateArrayIndex := 0; |
| 810 |
// SetLength(FCommentData, CommentDateArrayIndex); |
| 811 |
// ListView1.Clear; |
| 812 |
MessageDlg('コメントがされなかった放送です。', mtConfirmation, [mbOK], 0); |
| 813 |
end; |
| 814 |
ListView1.Items.Count := CommentDateArrayIndex ; // ListView1 に表示する行数を決定&表示するので削除厳禁! |
| 815 |
|
| 816 |
if StatusBar.Panels.Items[4].Text <> '' then |
| 817 |
begin |
| 818 |
StatusBar.Panels.Items[4].Text := ''; |
| 819 |
end; |
| 820 |
|
| 821 |
if StatusBar.Panels.Items[0].Text = 'lv番号:不明' then // ファイル名からlv番号抽出する |
| 822 |
begin |
| 823 |
FileNameStr := ChangeFileExt( ExtractFileName(FileName) , ''); |
| 824 |
// FileNameStr := 'ふかふかふかlv20000000000)(やってみる)((lv10000)(lv196799094)'; |
| 825 |
// FileNameStr := 'ふかふかふか(やってみる)(lv196799094)'; |
| 826 |
// FileNameStr := 'ふかふかふか(やってみる)()'; |
| 827 |
if TRegEx.IsMatch(FileNameStr,'lv\d+') then |
| 828 |
begin |
| 829 |
LiveNumbers := TRegEx.Matches(FileNameStr,'lv\d+'); |
| 830 |
if LiveNumbers.Count = 1 then |
| 831 |
StatusBar.Panels.Items[0].Text := 'たぶん' + LiveNumbers.Item[0].Value |
| 832 |
else |
| 833 |
begin |
| 834 |
// 複数候補がある場合は最大値を適用する |
| 835 |
if LiveNumbers.Count > 1 then |
| 836 |
begin |
| 837 |
SortList := TStringList.Create; |
| 838 |
for I := 0 to LiveNumbers.Count - 1 do |
| 839 |
SortList.Add( LiveNumbers.Item[I].Value ); |
| 840 |
SortList.Sort; |
| 841 |
for I := 0 to SortList.Count - 1 do //ソートされて最後が最大値になっているはず |
| 842 |
FileNameStr := SortList.Strings[i]; |
| 843 |
StatusBar.Panels.Items[0].Text := 'たぶん' + FileNameStr; |
| 844 |
SortList.Free; |
| 845 |
end; |
| 846 |
end; |
| 847 |
Form1.StatusBar.Panels.Items[0].Width := 170; |
| 848 |
end; |
| 849 |
end; |
| 850 |
|
| 851 |
packetNode.Clear; |
| 852 |
FileStrings.Free; |
| 853 |
{$IFDEF DEBUG} |
| 854 |
t := timeGetTime - t; timeEndPeriod(1); |
| 855 |
StatusBar.Panels.Items[4].Text := FormatFloat('#,##0 ms',t); |
| 856 |
{$ENDIF} |
| 857 |
end; |
| 858 |
end; |
| 859 |
|
| 860 |
procedure TForm1.N1024x768Click(Sender: TObject); |
| 861 |
begin |
| 862 |
WindowResize(1024,768); |
| 863 |
end; |
| 864 |
|
| 865 |
procedure TForm1.N1200x800Click(Sender: TObject); |
| 866 |
begin |
| 867 |
WindowResize(1200,800); |
| 868 |
end; |
| 869 |
|
| 870 |
procedure TForm1.N800x600Click(Sender: TObject); |
| 871 |
begin |
| 872 |
WindowResize(800,600); |
| 873 |
end; |
| 874 |
|
| 875 |
procedure TForm1.NameID1Click(Sender: TObject); // Name と ID 列の表示/非表示 |
| 876 |
begin |
| 877 |
NameID1.Checked := not NameID1.Checked; // not は論理値の逆転に使う。 |
| 878 |
if (NameID1.Checked = False) then |
| 879 |
begin |
| 880 |
ListView1.Columns[1].MinWidth := 0; |
| 881 |
ListView1.Columns[1].Width := 0; |
| 882 |
end |
| 883 |
else |
| 884 |
begin |
| 885 |
ListView1.Columns[1].MinWidth := 50; |
| 886 |
ListView1.Columns[1].Width := 150; |
| 887 |
end; |
| 888 |
end; |
| 889 |
|
| 890 |
procedure TForm1.ListView1AdvancedCustomDrawSubItem( |
| 891 |
Sender: TCustomListView; Item: TListItem; SubItem: Integer; |
| 892 |
State: TCustomDrawState; Stage: TCustomDrawStage; |
| 893 |
var DefaultDraw: Boolean); |
| 894 |
begin |
| 895 |
// StatusStrings := TStringList.Create; |
| 896 |
// |
| 897 |
// if StatusStrings.Values['Premium'] = '1' then |
| 898 |
// begin |
| 899 |
// ListView1.Canvas.Font.Style:= [fsBold]; |
| 900 |
// end; |
| 901 |
end; |
| 902 |
|
| 903 |
procedure TForm1.ListView1Click(Sender: TObject); |
| 904 |
var |
| 905 |
hitInfo: TPoint; |
| 906 |
row, col: Integer; |
| 907 |
begin |
| 908 |
hitInfo := ListView1.ScreenToClient(Mouse.CursorPos); |
| 909 |
|
| 910 |
|
| 911 |
// if (ListView_SubItemHitTest(ListView1.Handle, @hitInfo) = -1) then |
| 912 |
// begin |
| 913 |
ShowMessage('m9'); |
| 914 |
// end |
| 915 |
// else |
| 916 |
// begin |
| 917 |
// ShowMessage('x:' + IntToStr(hitInfo.x) + '| y:' + IntToStr(hitInfo.y)); |
| 918 |
//// row := hitInfo.iItem; |
| 919 |
//// col := hitInfo.iSubItem; |
| 920 |
// if ListView1.ItemFocused.Index > 0 then |
| 921 |
// ShowMessage(IntToStr( ListView1.ItemFocused.Index)); |
| 922 |
// |
| 923 |
// end; |
| 924 |
end; |
| 925 |
|
| 926 |
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; |
| 927 |
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); |
| 928 |
//var |
| 929 |
// TL: TListView; |
| 930 |
begin |
| 931 |
// if Item.SubItems.Count<5 then Exit; // SubItems[4]、つまり非表示の Premium が無いなら処理しない |
| 932 |
// |
| 933 |
// TL:=Sender as TListView; |
| 934 |
//// ShowMessage(Item.SubItems[4]); |
| 935 |
// case StrToIntDef(Item.SubItems[4], 9999) of // 数字以外なら9999にしてcase文をスルーさせる |
| 936 |
// 1: TL.Canvas.Font.Style:=[fsBold]; |
| 937 |
// 2: begin |
| 938 |
// TL.Canvas.Font.Style:=[fsBold]; |
| 939 |
// TL.Canvas.Font.Color:=clRed; |
| 940 |
// end; |
| 941 |
// 3: TL.Canvas.Font.Color:=clBlue; |
| 942 |
// 6..7: Sender.Canvas.Brush.Color := $FFFFE0; |
| 943 |
// else |
| 944 |
// begin |
| 945 |
// TL.Canvas.Font.Color:=clBlack; |
| 946 |
// end; |
| 947 |
// end; |
| 948 |
//SetLVItemFont(Sender, Item); |
| 949 |
end; |
| 950 |
|
| 951 |
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView; |
| 952 |
Item: TListItem; SubItem: Integer; State: TCustomDrawState; |
| 953 |
var DefaultDraw: Boolean); |
| 954 |
begin |
| 955 |
//選択中は太字 = クリックしたら太字 |
| 956 |
|
| 957 |
if Item.Selected = True then |
| 958 |
begin |
| 959 |
ListView1.Canvas.Font.Style:= ListView1.Canvas.Font.Style + [fsBold]; |
| 960 |
end; |
| 961 |
|
| 962 |
if SubItem = 1 then |
| 963 |
begin |
| 964 |
SetLVItemFont(Sender, Item); |
| 965 |
end; |
| 966 |
end; |
| 967 |
|
| 968 |
procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem); // 流しこむデータを決める。 |
| 969 |
begin |
| 970 |
if Item.Index = -1 then |
| 971 |
Exit; |
| 972 |
|
| 973 |
Item.Caption := IntToStr(FCommentData[Item.Index].CommentNum); |
| 974 |
Item.SubItems.Add(FCommentData[Item.Index].UserName); |
| 975 |
Item.SubItems.Add(FCommentData[Item.Index].Comment); |
| 976 |
Item.SubItems.Add(FCommentData[Item.Index].CommentTime); |
| 977 |
Item.SubItems.Add(FCommentData[Item.Index].ElapsedTime); |
| 978 |
Item.SubItems.Add(FCommentData[Item.Index].Premium); |
| 979 |
|
| 980 |
end; |
| 981 |
|
| 982 |
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; |
| 983 |
Selected: Boolean); |
| 984 |
var |
| 985 |
popup_pt: TPoint; //ポップアップメニューを表示する座標 |
| 986 |
begin |
| 987 |
//ローカルな座標を設定します |
| 988 |
popup_pt.x := ListView1.Left + 100; |
| 989 |
popup_pt.y := ListView1.Top + ListView1.Height; |
| 990 |
//スクリーンの座標に変換します |
| 991 |
popup_pt := Form1.ClientToScreen(popup_pt); |
| 992 |
//ポップアップを表示します |
| 993 |
PopupMenu1.Popup(popup_pt.x, popup_pt.y); |
| 994 |
end; |
| 995 |
|
| 996 |
procedure TForm1.LogOpenClick(Sender: TObject); |
| 997 |
var |
| 998 |
Encoding : TEncoding; |
| 999 |
EncIndex : Integer; |
| 1000 |
Filename : String; |
| 1001 |
|
| 1002 |
// FileStrings: TStringList; |
| 1003 |
// TextFile_LineStrings: TStringList; |
| 1004 |
// i: integer; |
| 1005 |
begin |
| 1006 |
if OpenTextFileDialog1.Execute(Self.Handle) then |
| 1007 |
begin |
| 1008 |
//selecting the filename and encoding selected by the user |
| 1009 |
Filename := OpenTextFileDialog1.FileName; |
| 1010 |
// Filename := 'D:\Dropbox\Delphi-Source\NicoLiveXMLRead\test.xml'; |
| 1011 |
EncIndex := OpenTextFileDialog1.EncodingIndex; |
| 1012 |
Encoding := OpenTextFileDialog1.Encodings.Objects[EncIndex] as TEncoding; |
| 1013 |
|
| 1014 |
if WideCompareText(ExtractFileExt(Filename), '.xml') = 0 then // 大文字小文字区別なく拡張子を比較 |
| 1015 |
begin |
| 1016 |
{ DONE : 2ファイル目を開かれた場合のために ProgramInfoDlg の初期化をする。 } |
| 1017 |
ProgramInfoDlg.ReSetting(Sender); |
| 1018 |
XmlFileCheckEncoding(FileName); |
| 1019 |
exit; // exit; を消したら下のelseの処理もされてしまう = 通常終了できないエラーが発生する。 |
| 1020 |
end |
| 1021 |
else |
| 1022 |
MessageDlg('XMLファイルを開いてください。', mtConfirmation, [mbOK], 0); |
| 1023 |
end; |
| 1024 |
end; |
| 1025 |
|
| 1026 |
function TForm1.PrepareComments(rawComment: string):string; |
| 1027 |
begin |
| 1028 |
if Copy(rawComment, 1,1) = '/' then |
| 1029 |
begin |
| 1030 |
rawComment := CommentURLDecode(rawComment); |
| 1031 |
rawComment := CommentBackStagePass(rawComment); |
| 1032 |
end; |
| 1033 |
Result := rawComment; |
| 1034 |
end; |
| 1035 |
|
| 1036 |
procedure TForm1.Print2Click(Sender: TObject); |
| 1037 |
begin |
| 1038 |
// PrintDialog1.Execute(); |
| 1039 |
end; |
| 1040 |
|
| 1041 |
procedure TForm1.PrintSetup2Click(Sender: TObject); |
| 1042 |
begin |
| 1043 |
// PrinterSetupDialog1.Execute(); |
| 1044 |
end; |
| 1045 |
|
| 1046 |
procedure TForm1.ProgramInfoClick(Sender: TObject); |
| 1047 |
begin |
| 1048 |
ProgramInfoDlg.Show; |
| 1049 |
end; |
| 1050 |
|
| 1051 |
procedure TForm1.ResetProgramInfoDlgData(Sender: TObject); |
| 1052 |
var |
| 1053 |
I: Integer; // 途中 |
| 1054 |
begin |
| 1055 |
FLiveData.OpenTime := ''; // ok |
| 1056 |
FLiveData.StartTime := ''; |
| 1057 |
FLiveData.LiveID := ''; |
| 1058 |
FLiveData.LiveTitle := ''; |
| 1059 |
FLiveData.LiveOwner := ''; |
| 1060 |
FLiveData.LiveAudience := -1; // マイナスの値の場合、情報を取得できなかったという意味にする。 |
| 1061 |
FLiveData.LiveComment := -1; |
| 1062 |
FLiveData.IsLiveStatus := -1; |
| 1063 |
FLiveData.LiveMemo := ''; |
| 1064 |
|
| 1065 |
FCommunityData.CommunityAudience := ''; // ok |
| 1066 |
FCommunityData.CommunityOpenDay := ''; |
| 1067 |
FCommunityData.CommunityName := ''; |
| 1068 |
FCommunityData.CommunityLevel := ''; |
| 1069 |
FCommunityData.CommunityID := ''; |
| 1070 |
FCommunityData.CommunityOwnerName:= ''; |
| 1071 |
FCommunityData.CommunityMember := ''; |
| 1072 |
FCommunityData.CommunityMemo := ''; |
| 1073 |
FCommunityData.CommunityStatus := True; |
| 1074 |
FCommunityData.IsCommunityGetInfo:= True; |
| 1075 |
FCommunityData.IsCommunityMember := True; |
| 1076 |
|
| 1077 |
for I := 1 to TAGLIST do |
| 1078 |
begin |
| 1079 |
FLiveData.LiveTags[i] := ''; |
| 1080 |
FCommunityData.CommunityTags[i] := ''; |
| 1081 |
end; |
| 1082 |
|
| 1083 |
FUserData.IsUserGetInfo := True; //ok |
| 1084 |
FUserData.UserIsDead := True; |
| 1085 |
FUserData.UserBirthday := -1; |
| 1086 |
FUserData.UserName := ''; |
| 1087 |
FUserData.UserID := ''; |
| 1088 |
FUserData.UserMemo := ''; |
| 1089 |
FUserData.UserLocation := ''; |
| 1090 |
FUserData.UserSex := ''; |
| 1091 |
FUserData.UserStamp := -1; // マイナスの値の場合、情報を取得できなかったという意味にする。 |
| 1092 |
FUserData.UserNicorare := -1; |
| 1093 |
FUserData.UserFav := -1; |
| 1094 |
end; |
| 1095 |
|
| 1096 |
|
| 1097 |
procedure TForm1.SetStatusBar(StatusArray: TStatusArray); |
| 1098 |
begin |
| 1099 |
case StatusArray[0] of |
| 1100 |
0:StatusBar.Panels.Items[0].Text := 'lv番号:不明'; |
| 1101 |
else |
| 1102 |
begin |
| 1103 |
StatusBar.Panels.Items[0].Text := 'lv' + IntToStr( StatusArray[0] ); |
| 1104 |
end; |
| 1105 |
end; |
| 1106 |
|
| 1107 |
case StatusArray[10] of |
| 1108 |
0: ; |
| 1109 |
else |
| 1110 |
begin |
| 1111 |
StatusBar.Panels.Items[0].Text := 'co' + IntToStr( StatusArray[10] ); |
| 1112 |
end; |
| 1113 |
end; |
| 1114 |
|
| 1115 |
case StatusArray[11] of // ファイル名から推測したlv番号 |
| 1116 |
0: ; |
| 1117 |
else |
| 1118 |
begin |
| 1119 |
StatusBar.Panels.Items[0].Text := 'たぶんlv' + IntToStr( StatusArray[11] ); |
| 1120 |
end; |
| 1121 |
end; |
| 1122 |
|
| 1123 |
case StatusArray[1] of |
| 1124 |
0:StatusBar.Panels.Items[1].Text := '接続中'; |
| 1125 |
1:StatusBar.Panels.Items[1].Text := '生放送中'; |
| 1126 |
2:StatusBar.Panels.Items[1].Text := 'タイムシフト'; |
| 1127 |
3:StatusBar.Panels.Items[1].Text := 'ログファイル'; |
| 1128 |
4:StatusBar.Panels.Items[1].Text := 'ログファイル:kakoroku'; |
| 1129 |
5:StatusBar.Panels.Items[1].Text := 'ログファイル:NCV'; |
| 1130 |
else |
| 1131 |
begin |
| 1132 |
StatusBar.Panels.Items[1].Text := ''; |
| 1133 |
end; |
| 1134 |
end; |
| 1135 |
|
| 1136 |
case StatusArray[2] of |
| 1137 |
0:StatusBar.Panels.Items[2].Text := ''; |
| 1138 |
1:StatusBar.Panels.Items[2].Text := '公式放送 '; |
| 1139 |
2:StatusBar.Panels.Items[2].Text := 'チャンネル'; |
| 1140 |
3:StatusBar.Panels.Items[2].Text := 'ユーザー'; |
| 1141 |
else |
| 1142 |
begin |
| 1143 |
StatusBar.Panels.Items[2].Text := '謎の放送'; |
| 1144 |
end; |
| 1145 |
end; |
| 1146 |
|
| 1147 |
case StatusArray[3] of |
| 1148 |
0:StatusBar.Panels.Items[3].Text := 'コメント人数:0'; |
| 1149 |
else |
| 1150 |
begin |
| 1151 |
StatusBar.Panels.Items[3].Text := 'コメント人数:' + IntToStr( StatusArray[3]); |
| 1152 |
end; |
| 1153 |
end; |
| 1154 |
|
| 1155 |
case StatusArray[4] of |
| 1156 |
0:StatusBar.Panels.Items[4].Text := ''; |
| 1157 |
end; |
| 1158 |
end; |
| 1159 |
|
| 1160 |
procedure TForm1.SaveAs2Click(Sender: TObject); |
| 1161 |
var |
| 1162 |
Encoding : TEncoding; |
| 1163 |
EncIndex : Integer; |
| 1164 |
Filename : String; |
| 1165 |
|
| 1166 |
FileStrings: TStringList; |
| 1167 |
SaveLineStrings: TStringList; |
| 1168 |
i: integer; |
| 1169 |
begin { TODO : 拡張子を指定せず保存した時に自動補完する機能。 } |
| 1170 |
|
| 1171 |
if SaveTextFileDialog1.Execute(Self.Handle) then |
| 1172 |
begin |
| 1173 |
//Selecting the file name and the encoding |
| 1174 |
Filename := SaveTextFileDialog1.FileName; |
| 1175 |
|
| 1176 |
EncIndex := SaveTextFileDialog1.EncodingIndex; |
| 1177 |
Encoding := SaveTextFileDialog1.Encodings.Objects[EncIndex] as TEncoding; |
| 1178 |
|
| 1179 |
FileStrings := TStringList.Create; |
| 1180 |
SaveLineStrings := TStringList.Create; |
| 1181 |
|
| 1182 |
for i := 0 to ListView1.Items.Count - 1 do |
| 1183 |
begin |
| 1184 |
SaveLineStrings.Assign(ListView1.Items.Item[i].SubItems); |
| 1185 |
SaveLineStrings.Insert(0, ListView1.Items.Item[i].Caption); |
| 1186 |
FileStrings.Add(SaveLineStrings.CommaText); |
| 1187 |
end; |
| 1188 |
|
| 1189 |
if ExtractFileExt(Filename)='' then |
| 1190 |
begin |
| 1191 |
Filename := Filename + '.txt'; |
| 1192 |
ShowMessage('拡張子がないので「' + ExtractFileName(Filename) + '」というファイル名で保存します。'); |
| 1193 |
end; |
| 1194 |
|
| 1195 |
//Checking if the file exists |
| 1196 |
if FileExists(Filename) then |
| 1197 |
raise Exception.Create('ファイルが既に存在します。') |
| 1198 |
else |
| 1199 |
//Save to file based on the selected encoding. |
| 1200 |
FileStrings.SaveToFile(FileName, Encoding); |
| 1201 |
end; |
| 1202 |
end; |
| 1203 |
|
| 1204 |
procedure TForm1.SetLVItemFont(ACustomListView: TCustomListView; |
| 1205 |
AListItem: TListItem); |
| 1206 |
var |
| 1207 |
LV: TListView; |
| 1208 |
PL: Integer; |
| 1209 |
begin |
| 1210 |
if AListItem.SubItems.Count<5 then Exit; // Premiumが無いなら処理しない |
| 1211 |
if not TryStrToInt(AListItem.SubItems[4], PL) then Exit; // 数字以外なら処理しない |
| 1212 |
|
| 1213 |
LV:=ACustomListView as TListView; |
| 1214 |
case PL of |
| 1215 |
1: LV.Canvas.Font.Style := LV.Font.Style+[fsBold]; // プレミア会員 |
| 1216 |
2: LV.Canvas.Font.Color := clMaroon; // システムコマンド |
| 1217 |
3: LV.Canvas.Font.Color := clGreen; // 放送主コメント |
| 1218 |
6: LV.Canvas.Brush.Color := $FFFFE0; // BSP(一般) |
| 1219 |
7: begin // BSP(プレミアム) |
| 1220 |
LV.Canvas.Font.Style := [fsBold]; |
| 1221 |
LV.Canvas.Brush.Color := $FFFFE0; |
| 1222 |
LV.Canvas.Font.Color := clBlue; |
| 1223 |
end; |
| 1224 |
100:LV.Canvas.Font.Color := clRed; // NGコメント |
| 1225 |
end; |
| 1226 |
end; |
| 1227 |
|
| 1228 |
procedure TForm1.TopShowClick(Sender: TObject); |
| 1229 |
begin |
| 1230 |
TopShow.Checked := not TopShow.Checked; |
| 1231 |
if (TopShow.Checked = True) then |
| 1232 |
begin |
| 1233 |
//最前面に表示する |
| 1234 |
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE); |
| 1235 |
end |
| 1236 |
else |
| 1237 |
begin |
| 1238 |
//普通に戻す |
| 1239 |
SetWindowPos(Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE or SWP_NOMOVE); |
| 1240 |
end; |
| 1241 |
end; |
| 1242 |
|
| 1243 |
|
| 1244 |
end. |