| 1 |
unit Favorite; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Messages, SysUtils, Classes, Contnrs, ComCtrls, {HttpApp,} YofUtils, |
| 7 |
GikoSystem{, XMLIntf, XMLDoc}, GikoXMLDoc, BoardGroup, windows, |
| 8 |
MojuUtils; |
| 9 |
{SAX, SAXHelpers, SAXComps, SAXKW;} |
| 10 |
|
| 11 |
type |
| 12 |
TFavoriteFolder = class |
| 13 |
end; |
| 14 |
|
| 15 |
TFavoriteBoardItem = class |
| 16 |
private |
| 17 |
FItem : TBoard; |
| 18 |
FURL : string; |
| 19 |
FTitle : string; |
| 20 |
function GetItem : TBoard; |
| 21 |
public |
| 22 |
constructor Create( inURL : string; inTitle : string = ''; inItem : TBoard = nil ); |
| 23 |
constructor CreateWithItem( inItem : TBoard ); |
| 24 |
destructor Destory; |
| 25 |
property Item : TBoard read GetItem write FItem; |
| 26 |
property URL : string read FURL write FURL; // Item ?????転?長?鼎???足???? URL ???鱈???徹???????辿 |
| 27 |
property Title : string read FTitle write FTitle; |
| 28 |
end; |
| 29 |
|
| 30 |
TFavoriteThreadItem = class |
| 31 |
private |
| 32 |
FItem : TThreadItem; |
| 33 |
FURL : string; |
| 34 |
FTitle : string; |
| 35 |
function GetItem : TThreadItem; |
| 36 |
public |
| 37 |
constructor Create( inURL : string; inTitle : string = ''; inItem : TThreadItem = nil ); |
| 38 |
constructor CreateWithItem( inItem : TThreadItem ); |
| 39 |
destructor Destory; |
| 40 |
property Item : TThreadItem read GetItem write FItem; |
| 41 |
property URL : string read FURL write FURL; // Item ?????転?長?鼎???足???? URL ???鱈???徹???????辿 |
| 42 |
property Title : string read FTitle write FTitle; |
| 43 |
end; |
| 44 |
|
| 45 |
TFavoriteDM = class(TDataModule) |
| 46 |
procedure DataModuleDestroy(Sender: TObject); |
| 47 |
private |
| 48 |
{ Private ?辿?転 } |
| 49 |
FStack: TStack; |
| 50 |
FTreeView: TTreeView; |
| 51 |
|
| 52 |
procedure ReadNode(Node: IXMLNode); |
| 53 |
procedure AddSaveString(Node: TTreeNode; SaveList: TStringList); |
| 54 |
// procedure AddSaveString(Node: TTreeNode; XMLNode: IXMLNode); |
| 55 |
// procedure SAXStartDocument(Sender: TObject); |
| 56 |
// procedure SAXEndDocument(Sender: TObject); |
| 57 |
// procedure SAXStartElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString; const Atts: IAttributes); |
| 58 |
// procedure SAXEndElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString); |
| 59 |
// procedure SAXCharacters(Sender: TObject; const PCh: SAXString); |
| 60 |
public |
| 61 |
{ Public ?辿?転 } |
| 62 |
procedure Clear; |
| 63 |
function GetFavoriteFilePath() : String; |
| 64 |
function SaveFavoriteFile(FileName: String) : Boolean; |
| 65 |
procedure SetFavTreeView(TreeView: TTreeView); |
| 66 |
procedure ReadFavorite; |
| 67 |
procedure WriteFavorite; |
| 68 |
procedure URLReplace(oldURLs: TStringList; newURLs: TStringList); |
| 69 |
property TreeView: TTreeView read FTreeView; |
| 70 |
end; |
| 71 |
|
| 72 |
var |
| 73 |
FavoriteDM: TFavoriteDM; |
| 74 |
const |
| 75 |
FAVORITE_LINK_NAME = '?????N'; |
| 76 |
|
| 77 |
implementation |
| 78 |
|
| 79 |
uses ExternalBoardManager, ExternalBoardPlugInMain; |
| 80 |
|
| 81 |
const |
| 82 |
FAVORITE_ROOT_NAME = '?即?C???端??'; |
| 83 |
FAVORITE_FILE_NAME = 'Favorite.xml'; |
| 84 |
|
| 85 |
{$R *.dfm} |
| 86 |
|
| 87 |
constructor TFavoriteBoardItem.Create( |
| 88 |
inURL : string; |
| 89 |
inTitle : string = ''; |
| 90 |
inItem : TBoard = nil |
| 91 |
); |
| 92 |
begin |
| 93 |
|
| 94 |
inherited Create; |
| 95 |
|
| 96 |
URL := inURL; |
| 97 |
Title := inTitle; |
| 98 |
Item := inItem; |
| 99 |
|
| 100 |
end; |
| 101 |
|
| 102 |
constructor TFavoriteBoardItem.CreateWithItem( |
| 103 |
inItem : TBoard |
| 104 |
); |
| 105 |
begin |
| 106 |
|
| 107 |
Create( inItem.URL, inItem.Title, inItem ); |
| 108 |
|
| 109 |
end; |
| 110 |
destructor TFavoriteBoardItem.Destory; |
| 111 |
begin |
| 112 |
if FItem <> nil then |
| 113 |
FItem.Free; |
| 114 |
inherited; |
| 115 |
end; |
| 116 |
function TFavoriteBoardItem.GetItem : TBoard; |
| 117 |
var |
| 118 |
protocol, host, path, document, port, bookmark : string; |
| 119 |
BBSID, BBSKey : string; |
| 120 |
tmpURL : string; |
| 121 |
// category : TCategory; |
| 122 |
begin |
| 123 |
|
| 124 |
if FItem = nil then begin |
| 125 |
FItem := BBSsFindBoardFromURL( URL ); |
| 126 |
if FItem = nil then begin |
| 127 |
tmpURL := URL; |
| 128 |
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 129 |
if GikoSys.Is2chHost( host ) then begin |
| 130 |
BBSID := GikoSys.URLToID( tmpURL ); |
| 131 |
FItem := BBSs[ 0 ].FindBBSID( BBSID ); |
| 132 |
if FItem <> nil then |
| 133 |
URL := FItem.URL; |
| 134 |
end; |
| 135 |
{ |
| 136 |
// ???????????A???????辿?J?e?S???????????長???直?足?徹?纏 |
| 137 |
FItem := GikoSys.GetUnknownBoard( nil, URL ); |
| 138 |
FItem.Title := Title; |
| 139 |
} |
| 140 |
end; |
| 141 |
end; |
| 142 |
|
| 143 |
Result := FItem; |
| 144 |
|
| 145 |
end; |
| 146 |
|
| 147 |
constructor TFavoriteThreadItem.Create( |
| 148 |
inURL : string; |
| 149 |
inTitle : string = ''; |
| 150 |
inItem : TThreadItem = nil |
| 151 |
); |
| 152 |
begin |
| 153 |
|
| 154 |
inherited Create; |
| 155 |
|
| 156 |
URL := inURL; |
| 157 |
Title := inTitle; |
| 158 |
Item := inItem; |
| 159 |
|
| 160 |
end; |
| 161 |
|
| 162 |
constructor TFavoriteThreadItem.CreateWithItem( |
| 163 |
inItem : TThreadItem |
| 164 |
); |
| 165 |
begin |
| 166 |
|
| 167 |
Create( inItem.URL, inItem.Title, inItem ); |
| 168 |
|
| 169 |
end; |
| 170 |
destructor TFavoriteThreadItem.Destory; |
| 171 |
begin |
| 172 |
if FItem <> nil then |
| 173 |
FItem.Free; |
| 174 |
inherited; |
| 175 |
end; |
| 176 |
|
| 177 |
function TFavoriteThreadItem.GetItem : TThreadItem; |
| 178 |
var |
| 179 |
board : TBoard; |
| 180 |
boardURL : string; |
| 181 |
browsableURL : string; |
| 182 |
protocol, host, path, document, port, bookmark : string; |
| 183 |
BBSID, BBSKey : string; |
| 184 |
tmpURL : string; |
| 185 |
begin |
| 186 |
|
| 187 |
Result := nil; |
| 188 |
if FItem = nil then begin |
| 189 |
browsableURL := GikoSys.GetBrowsableThreadURL( URL ); |
| 190 |
boardURL := GikoSys.GetThreadURL2BoardURL( browsableURL ); |
| 191 |
board := BBSsFindBoardFromURL( boardURL ); |
| 192 |
|
| 193 |
if board = nil then begin |
| 194 |
tmpURL := URL; |
| 195 |
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 196 |
if GikoSys.Is2chHost( host ) then begin |
| 197 |
GikoSys.Parse2chURL( tmpURL, path, document, BBSID, BBSKey ); |
| 198 |
board := BBSs[ 0 ].FindBBSID( BBSID ); |
| 199 |
end; |
| 200 |
|
| 201 |
if board = nil then begin |
| 202 |
Exit; |
| 203 |
// ???????????A???????辿?J?e?S???????????長???直?足?徹?纏 |
| 204 |
//board := GikoSys.GetUnknownBoard( nil, boardURL ) |
| 205 |
end; |
| 206 |
end; |
| 207 |
|
| 208 |
FItem := board.FindThreadFromURL( browsableURL ); |
| 209 |
|
| 210 |
if FItem = nil then begin |
| 211 |
tmpURL := URL; |
| 212 |
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 213 |
if GikoSys.Is2chHost( host ) then begin |
| 214 |
GikoSys.Parse2chURL( tmpURL, path, document, BBSID, BBSKey ); |
| 215 |
FItem := BBSs[ 0 ].FindThreadItem( BBSID, BBSKey + '.dat' ); |
| 216 |
if FItem <> nil then |
| 217 |
URL := FItem.URL; |
| 218 |
end; |
| 219 |
end; |
| 220 |
|
| 221 |
if FItem = nil then begin |
| 222 |
FItem := TThreadItem.Create( board.BoardPlugIn, browsableURL ); |
| 223 |
|
| 224 |
FItem.Title := Title; |
| 225 |
board.Add( FItem ); |
| 226 |
end; |
| 227 |
end; |
| 228 |
|
| 229 |
Result := FItem; |
| 230 |
|
| 231 |
end; |
| 232 |
|
| 233 |
procedure TFavoriteDM.DataModuleDestroy(Sender: TObject); |
| 234 |
//var |
| 235 |
// i: Integer; |
| 236 |
begin |
| 237 |
{ TreeView.Items.BeginUpdate; |
| 238 |
for i := TreeView.Items.Count - 1 downto 0 do begin |
| 239 |
// if TObject(TreeView.Items[i].Data) <> nil then |
| 240 |
// TObject(TreeView.Items[i].Data).Free; |
| 241 |
end; |
| 242 |
TreeView.Items.Clear; |
| 243 |
TreeView.Items.EndUpdate; |
| 244 |
} //TreeView.Free; |
| 245 |
end; |
| 246 |
procedure TFavoriteDM.Clear; |
| 247 |
var |
| 248 |
i: Integer; |
| 249 |
begin |
| 250 |
TreeView.Items.BeginUpdate; |
| 251 |
for i := TreeView.Items.Count - 1 downto 0 do begin |
| 252 |
if TObject(TreeView.Items[i].Data) <> nil then |
| 253 |
TObject(TreeView.Items[i].Data).Free; |
| 254 |
end; |
| 255 |
TreeView.Items.Clear; |
| 256 |
TreeView.Items.EndUpdate; |
| 257 |
//TreeView.Free; |
| 258 |
end; |
| 259 |
|
| 260 |
procedure TFavoriteDM.SetFavTreeView(TreeView: TTreeView); |
| 261 |
begin |
| 262 |
FTreeView := TreeView; |
| 263 |
end; |
| 264 |
|
| 265 |
procedure TFavoriteDM.ReadFavorite; |
| 266 |
var |
| 267 |
FileName: string; |
| 268 |
XMLDoc: IXMLDocument; |
| 269 |
XMLNode: IXMLNode; |
| 270 |
Node: TTreeNode; |
| 271 |
i: Integer; |
| 272 |
FavFolder: TFavoriteFolder; |
| 273 |
LinkExists: Boolean; |
| 274 |
begin |
| 275 |
|
| 276 |
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 277 |
|
| 278 |
FavFolder := TFavoriteFolder.Create; |
| 279 |
Node := FTreeView.Items.AddChildObject(nil, FAVORITE_ROOT_NAME, FavFolder); |
| 280 |
Node.ImageIndex := 14; |
| 281 |
Node.SelectedIndex := 14; |
| 282 |
|
| 283 |
if FileExists(FileName) then begin |
| 284 |
try |
| 285 |
XMLDoc := IXMLDocument.Create; |
| 286 |
//XMLDoc := LoadXMLDocument(FileName); |
| 287 |
LoadXMLDocument(FileName, XMLDoc); |
| 288 |
XMLNode := XMLDoc.DocumentElement; |
| 289 |
|
| 290 |
FStack := TStack.Create; |
| 291 |
try |
| 292 |
FStack.Push(Node); |
| 293 |
LinkExists := False; |
| 294 |
if XMLNode.NodeName = 'favorite' then begin |
| 295 |
for i := 0 to XMLNode.ChildNodes.Count - 1 do begin |
| 296 |
ReadNode(XMLNode.ChildNodes[i]); |
| 297 |
if (XMLNode.ChildNodes[i].NodeName = 'folder') and |
| 298 |
(XMLNode.ChildNodes[i].Attributes['title'] = FAVORITE_LINK_NAME) then begin |
| 299 |
LinkExists := True; |
| 300 |
end; |
| 301 |
end; |
| 302 |
end; |
| 303 |
if not LinkExists then begin |
| 304 |
FavFolder := TFavoriteFolder.Create; |
| 305 |
Node := FTreeView.Items.AddChildObject(Node, FAVORITE_LINK_NAME, FavFolder); |
| 306 |
Node.ImageIndex := 14; |
| 307 |
Node.SelectedIndex := 14; |
| 308 |
end; |
| 309 |
finally |
| 310 |
FStack.Free; |
| 311 |
XMLDoc.Free; |
| 312 |
end; |
| 313 |
except |
| 314 |
end; |
| 315 |
end; |
| 316 |
|
| 317 |
{ |
| 318 |
FavFolder := TFavoriteFolder.Create; |
| 319 |
Node := FTreeView.Items.AddChildObject(nil, FAVORITE_ROOT_NAME, FavFolder); |
| 320 |
Node.ImageIndex := 12; |
| 321 |
Node.SelectedIndex := 13; |
| 322 |
|
| 323 |
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 324 |
if not FileExists(FileName) then |
| 325 |
Exit; |
| 326 |
|
| 327 |
FavSAXHandler.OnStartDocument := SAXStartDocument; |
| 328 |
FavSAXHandler.OnEndDocument := SAXEndDocument; |
| 329 |
FavSAXHandler.OnStartElement := SAXStartElement; |
| 330 |
FavSAXHandler.OnStartElement := SAXStartElement; |
| 331 |
FavSAXHandler.OnEndElement := SAXEndElement; |
| 332 |
FavSAXHandler.OnCharacters := SAXCharacters; |
| 333 |
|
| 334 |
FavSAXReader.Vendor := 'Keith Wood'; |
| 335 |
FavSAXReader.URL := FileName; |
| 336 |
FavSAXReader.Parse;} |
| 337 |
end; |
| 338 |
|
| 339 |
procedure TFavoriteDM.ReadNode(Node: IXMLNode); |
| 340 |
var |
| 341 |
i: Integer; |
| 342 |
|
| 343 |
ParentNode: TTreeNode; |
| 344 |
CurrentNode: TTreeNode; |
| 345 |
FavFolder: TFavoriteFolder; |
| 346 |
FavBoard: TFavoriteBoardItem; |
| 347 |
FavThread: TFavoriteThreadItem; |
| 348 |
board : TBoard; |
| 349 |
threadItem : TThreadItem; |
| 350 |
begin |
| 351 |
if Node.NodeName = 'folder' then begin |
| 352 |
ParentNode := FStack.Peek; |
| 353 |
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 354 |
FavFolder := TFavoriteFolder.Create; |
| 355 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavFolder); |
| 356 |
CurrentNode.ImageIndex := 14; |
| 357 |
CurrentNode.SelectedIndex := 14; |
| 358 |
CurrentNode.Expanded := Node.Attributes[ 'expanded' ] = 'true'; |
| 359 |
FStack.Push(CurrentNode); |
| 360 |
end; |
| 361 |
for i := 0 to Node.ChildNodes.Count - 1 do begin |
| 362 |
ReadNode(Node.ChildNodes[i]); |
| 363 |
end; |
| 364 |
if FStack.Count <> 0 then |
| 365 |
FStack.Pop; |
| 366 |
end else if Node.NodeName = 'favitem' then begin |
| 367 |
try |
| 368 |
ParentNode := FStack.Peek; |
| 369 |
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 370 |
if Node.Attributes['favtype'] = 'board' then begin |
| 371 |
FavBoard := nil; |
| 372 |
// ???貼???即?C???端???????????鼎?????? |
| 373 |
if Length( Node.Attributes[ 'bbs' ] ) > 0 then begin |
| 374 |
board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] ); |
| 375 |
if board <> nil then |
| 376 |
FavBoard := TFavoriteBoardItem.Create( |
| 377 |
board.URL, Node.Attributes[ 'title' ], board ); |
| 378 |
end else begin |
| 379 |
FavBoard := TFavoriteBoardItem.Create( |
| 380 |
Node.Attributes[ 'url' ], Node.Attributes[ 'title' ], nil ); |
| 381 |
end; |
| 382 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavBoard); |
| 383 |
CurrentNode.ImageIndex := 15; |
| 384 |
CurrentNode.SelectedIndex := 15; |
| 385 |
end else if Node.Attributes['favtype'] = 'thread' then begin |
| 386 |
// ???貼???即?C???端???????????鼎?????? |
| 387 |
if Length( Node.Attributes[ 'bbs' ] ) > 0 then begin |
| 388 |
board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] ); |
| 389 |
if board = nil then |
| 390 |
Exit; |
| 391 |
|
| 392 |
if not board.IsThreadDatRead then |
| 393 |
GikoSys.ReadSubjectFile( board ); |
| 394 |
threadItem := board.FindThreadFromFileName( Node.Attributes[ 'thread' ] ); |
| 395 |
if threadItem = nil then begin |
| 396 |
threadItem := TThreadItem.Create( |
| 397 |
board.BoardPlugIn, |
| 398 |
GikoSys.Get2chBoard2ThreadURL( board, ChangeFileExt( Node.Attributes[ 'thread' ], '' ) ) ); |
| 399 |
threadItem.Title := Node.Attributes[ 'title' ]; |
| 400 |
board.Add( threadItem ); |
| 401 |
end; |
| 402 |
FavThread := TFavoriteThreadItem.Create( |
| 403 |
threadItem.URL, Node.Attributes[ 'title' ], threadItem ); |
| 404 |
threadItem.Free; |
| 405 |
end else begin |
| 406 |
FavThread := TFavoriteThreadItem.Create( |
| 407 |
Node.Attributes[ 'url' ], Node.Attributes[ 'title' ], nil ); |
| 408 |
end; |
| 409 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavThread); |
| 410 |
CurrentNode.ImageIndex := 16; |
| 411 |
CurrentNode.SelectedIndex := 16; |
| 412 |
end; |
| 413 |
end; |
| 414 |
except |
| 415 |
// ?????A?C?e???長?但?????N?鼎?????添???A?C?e?????e?甜???^?????足???????長 |
| 416 |
end; |
| 417 |
end; |
| 418 |
end; |
| 419 |
|
| 420 |
procedure TFavoriteDM.WriteFavorite; |
| 421 |
{ |
| 422 |
var |
| 423 |
FileName: string; |
| 424 |
// SaveList: TStringList; |
| 425 |
// i: Integer; |
| 426 |
// Count: Integer; |
| 427 |
|
| 428 |
XMLDoc: IXMLDocument; |
| 429 |
XMLNode: IXMLNode; |
| 430 |
// FavoNode: IXMLNode; |
| 431 |
begin |
| 432 |
XMLDoc := NewXMLDocument; |
| 433 |
XMLDoc.Encoding := 'Shift_JIS'; |
| 434 |
XMLDoc.StandAlone := 'yes'; |
| 435 |
XMLNode := XMLDoc.AddChild('favorite'); |
| 436 |
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 437 |
AddSaveString(TreeView.Items.GetFirstNode, XMLNode); |
| 438 |
XMLDoc.SaveToFile(FileName); |
| 439 |
} |
| 440 |
var |
| 441 |
FileName: string; |
| 442 |
SaveList: TStringList; |
| 443 |
begin |
| 444 |
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 445 |
SaveList := TStringList.Create; |
| 446 |
try |
| 447 |
SaveList.Add('<?xml version="1.0" encoding="Shift_JIS" standalone="yes"?>'); |
| 448 |
SaveList.Add('<favorite>'); |
| 449 |
AddSaveString(TreeView.Items.GetFirstNode, SaveList); |
| 450 |
SaveList.Add('</favorite>'); |
| 451 |
SaveList.SaveToFile(FileName); |
| 452 |
finally |
| 453 |
SaveList.Free; |
| 454 |
end; |
| 455 |
end; |
| 456 |
|
| 457 |
{ |
| 458 |
procedure TFavoriteDM.AddSaveString(Node: TTreeNode; XMLNode: IXMLNode); |
| 459 |
var |
| 460 |
i: Integer; |
| 461 |
// s: string; |
| 462 |
FavBoard: TFavoriteBoardItem; |
| 463 |
FavThread: TFavoriteThreadItem; |
| 464 |
FavNode: IXMLNode; |
| 465 |
begin |
| 466 |
for i := 0 to Node.Count - 1 do begin |
| 467 |
if TObject(Node.Item[i].Data) is TFavoriteFolder then begin |
| 468 |
FavNode := XMLNode.AddChild('folder'); |
| 469 |
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 470 |
AddSaveString(Node.Item[i], FavNode); |
| 471 |
end else if TObject(Node.Item[i].Data) is TFavoriteBoardItem then begin |
| 472 |
FavBoard := TFavoriteBoardItem(Node.Item[i].Data); |
| 473 |
FavNode := XMLNode.AddChild('favitem'); |
| 474 |
FavNode.Attributes['type'] := '2ch'; |
| 475 |
FavNode.Attributes['favtype'] := 'board'; |
| 476 |
FavNode.Attributes['bbs'] := FavBoard.BBSID; |
| 477 |
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 478 |
FavNode.Attributes['boardname'] := FavBoard.BoardName; |
| 479 |
end else if TObject(Node.Item[i].Data) is TFavoriteThreadItem then begin |
| 480 |
FavThread := TFavoriteThreadItem(Node.Item[i].Data); |
| 481 |
FavNode := XMLNode.AddChild('favitem'); |
| 482 |
FavNode.Attributes['type'] := '2ch'; |
| 483 |
FavNode.Attributes['favtype'] := 'thread'; |
| 484 |
FavNode.Attributes['bbs'] := FavThread.BBSID; |
| 485 |
FavNode.Attributes['thread'] := FavThread.ThreadID; |
| 486 |
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 487 |
FavNode.Attributes['threadname'] := FavThread.ThreadName; |
| 488 |
end; |
| 489 |
end; |
| 490 |
end; |
| 491 |
} |
| 492 |
|
| 493 |
procedure TFavoriteDM.AddSaveString(Node: TTreeNode; SaveList: TStringList); |
| 494 |
var |
| 495 |
i: Integer; |
| 496 |
s: string; |
| 497 |
FavBoard: TFavoriteBoardItem; |
| 498 |
FavThread: TFavoriteThreadItem; |
| 499 |
begin |
| 500 |
for i := 0 to Node.Count - 1 do begin |
| 501 |
if TObject(Node.Item[i].Data) is TFavoriteFolder then begin |
| 502 |
if Node.Item[ i ].Expanded then |
| 503 |
s := Format('<folder title="%s" expanded="true">', [HtmlEncode(Node.Item[i].Text)]) |
| 504 |
else |
| 505 |
s := Format('<folder title="%s" expanded="false">', [HtmlEncode(Node.Item[i].Text)]); |
| 506 |
SaveList.Add(s); |
| 507 |
AddSaveString(Node.Item[i], SaveList); |
| 508 |
SaveList.Add('</folder>'); |
| 509 |
end else if TObject(Node.Item[i].Data) is TFavoriteBoardItem then begin |
| 510 |
FavBoard := TFavoriteBoardItem(Node.Item[i].Data); |
| 511 |
s := Format('<favitem type="2ch" favtype="board" url="%s" title="%s"/>', |
| 512 |
[HtmlEncode( FavBoard.URL ), HtmlEncode(Node.Item[ i ].Text)]); |
| 513 |
SaveList.Add(s); |
| 514 |
end else if TObject(Node.Item[i].Data) is TFavoriteThreadItem then begin |
| 515 |
FavThread := TFavoriteThreadItem(Node.Item[i].Data); |
| 516 |
s := Format('<favitem type="2ch" favtype="thread" url="%s" title="%s"/>', |
| 517 |
[HtmlEncode( FavThread.URL ), HtmlEncode(Node.Item[ i ].Text)]); |
| 518 |
SaveList.Add(s); |
| 519 |
end; |
| 520 |
end; |
| 521 |
end; |
| 522 |
|
| 523 |
{ |
| 524 |
procedure TFavoriteDM.SAXStartDocument(Sender: TObject); |
| 525 |
begin |
| 526 |
FStack := TStack.Create; |
| 527 |
FStack.Push(FTreeView.Items.GetFirstNode); |
| 528 |
end; |
| 529 |
|
| 530 |
procedure TFavoriteDM.SAXEndDocument(Sender: TObject); |
| 531 |
begin |
| 532 |
FStack.Free; |
| 533 |
end; |
| 534 |
|
| 535 |
procedure TFavoriteDM.SAXStartElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString; |
| 536 |
const Atts: IAttributes); |
| 537 |
var |
| 538 |
FavType: string; |
| 539 |
ParentNode: TTreeNode; |
| 540 |
CurrentNode: TTreeNode; |
| 541 |
FavFolder: TFavoriteFolder; |
| 542 |
FavBoard: TFavoriteBoardItem; |
| 543 |
FavThread: TFavoriteThreadItem; |
| 544 |
begin |
| 545 |
if QName = 'folder' then begin |
| 546 |
ParentNode := FStack.Peek; |
| 547 |
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 548 |
FavFolder := TFavoriteFolder.Create; |
| 549 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavFolder); |
| 550 |
CurrentNode.ImageIndex := 12; |
| 551 |
CurrentNode.SelectedIndex := 13; |
| 552 |
FStack.Push(CurrentNode); |
| 553 |
end; |
| 554 |
end else if QName = 'favitem' then begin |
| 555 |
ParentNode := FStack.Peek; |
| 556 |
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 557 |
FavType := Atts.getValue('favtype'); |
| 558 |
if FavType = 'board' then begin |
| 559 |
FavBoard := TFavoriteBoardItem.Create; |
| 560 |
FavBoard.BBSID := Atts.getValue('bbs'); |
| 561 |
FavBoard.BoardName := Atts.getValue('boardname'); |
| 562 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavBoard); |
| 563 |
CurrentNode.ImageIndex := 14; |
| 564 |
CurrentNode.SelectedIndex := 15; |
| 565 |
end else if FavType = 'thread' then begin |
| 566 |
FavThread := TFavoriteThreadItem.Create; |
| 567 |
FavThread.BBSID := Atts.getValue('bbs'); |
| 568 |
FavThread.ThreadID := Atts.getValue('thread'); |
| 569 |
FavThread.ThreadName := Atts.getValue('threadname'); |
| 570 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavThread); |
| 571 |
CurrentNode.ImageIndex := 16; |
| 572 |
CurrentNode.SelectedIndex := 17; |
| 573 |
end; |
| 574 |
end; |
| 575 |
end; |
| 576 |
end; |
| 577 |
|
| 578 |
procedure TFavoriteDM.SAXEndElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString); |
| 579 |
begin |
| 580 |
if QName = 'folder' then begin |
| 581 |
if FStack.Count <> 0 then |
| 582 |
FStack.Pop; |
| 583 |
end; |
| 584 |
end; |
| 585 |
|
| 586 |
procedure TFavoriteDM.SAXCharacters(Sender: TObject; const PCh: SAXString); |
| 587 |
begin |
| 588 |
// |
| 589 |
end; |
| 590 |
} |
| 591 |
function TFavoriteDM.SaveFavoriteFile(FileName: String) : Boolean; |
| 592 |
var |
| 593 |
FavoriteFilePath: string; |
| 594 |
tempStringList: TStringList; |
| 595 |
begin |
| 596 |
|
| 597 |
FavoriteFilePath := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 598 |
|
| 599 |
if FileExists( FavoriteFilePath ) then begin |
| 600 |
tempStringList := TStringList.Create; |
| 601 |
try |
| 602 |
tempStringList.LoadFromFile( FavoriteFilePath ); |
| 603 |
tempStringList.SaveToFile( FileName ); |
| 604 |
finally |
| 605 |
tempStringList.Free; |
| 606 |
end; |
| 607 |
Result := true; |
| 608 |
end else begin |
| 609 |
Result := false; |
| 610 |
end; |
| 611 |
end; |
| 612 |
|
| 613 |
procedure TFavoriteDM.URLReplace(oldURLs: TStringList; newURLs: TStringList); |
| 614 |
var |
| 615 |
FavoriteFilePath: string; |
| 616 |
tempStringList: TStringList; |
| 617 |
i: Integer; |
| 618 |
j: Integer; |
| 619 |
tmpURL: string; |
| 620 |
oldHost: string; |
| 621 |
oldBoardName: string; |
| 622 |
newHost: string; |
| 623 |
newBoardName: string; |
| 624 |
tempString: string; |
| 625 |
begin |
| 626 |
|
| 627 |
FavoriteFilePath := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 628 |
|
| 629 |
if FileExists( FavoriteFilePath ) then begin |
| 630 |
tempStringList := TStringList.Create; |
| 631 |
try |
| 632 |
tempStringList.LoadFromFile( FavoriteFilePath ); |
| 633 |
if oldURLs.Count = newURLs.Count then begin |
| 634 |
//?????長?ABoard???S?????????鱈?辿 |
| 635 |
for i := 0 to oldURLs.Count - 1 do begin |
| 636 |
CustomStringReplace(tempStringList,oldURLs[i],newURLs[i],true); |
| 637 |
end; |
| 638 |
//???|?転?纏??thread???泥???添??URL???`???b?N?直?????巽?但?????????鼎?叩???纏?????B |
| 639 |
for i := 0 to oldURLs.Count - 1 do begin |
| 640 |
tmpURL := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1); |
| 641 |
oldHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) ); |
| 642 |
oldBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/'; |
| 643 |
tmpURL := Copy(newURLs[i], 1, Length(newURLs[i]) -1); |
| 644 |
newHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) ); |
| 645 |
newBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/'; |
| 646 |
|
| 647 |
for j := 0 to tempStringList.Count - 1 do begin |
| 648 |
tempString := tempStringList[j]; |
| 649 |
if AnsiPos('favtype="thread"',tempString ) <> 0 then begin |
| 650 |
tempString := Copy(tempString, AnsiPos('url="',tempString ) + 5, AnsiPos('" title="',tempString ) -AnsiPos('url="',tempString ) - 5); |
| 651 |
if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin |
| 652 |
tempString := StringReplace(tempStringList[j], oldHost, newHost,[]); |
| 653 |
//tempString := StringReplace(tempString, oldBoardName, newBoardName,[]); |
| 654 |
tempStringList[j] := tempString; |
| 655 |
end; |
| 656 |
|
| 657 |
end; |
| 658 |
end; |
| 659 |
end; |
| 660 |
|
| 661 |
end; |
| 662 |
|
| 663 |
tempStringList.SaveToFile( FavoriteFilePath ); |
| 664 |
finally |
| 665 |
tempStringList.Free; |
| 666 |
end; |
| 667 |
end; |
| 668 |
end; |
| 669 |
|
| 670 |
function TFavoriteDM.GetFavoriteFilePath() : String; |
| 671 |
begin |
| 672 |
Result := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 673 |
end; |
| 674 |
|
| 675 |
end. |