unit info_update; //{$DEFINE DEBUG} interface uses Classes, // SQLiteTable3, // myDShow, libman, myTag; type T_MyInfoUpdate = class(TThread) private { Private 宣言 } // F_Player : TMyDSPlayer; F_iStart : Integer; F_iEnd : Integer; F_iCount : Integer; F_iIndex : Integer; F_sFileName : WideString; F_Tag : TMyTag; F_bTagFromFile : Boolean; //ファイルからタグ情報を取得すべきか F_bVideoSizeFromFile : Boolean; //ファイルからビデオサイズを取得すべきか(タグ情報は取得済み) F_bUpdateList : Boolean; //リストのタグ情報を更新すべきか F_bUpdateLibrary : Boolean; //ライブラリのタグ情報を更新すべきか //データベース // F_SQLiteDB : TSQLiteDatabase; // function F_GetLibTag(sFileName : WideString) : Boolean; // procedure F_UpdateLibrary(ATag : TMyTag); procedure CheckInfo; procedure UpdateInfo; procedure DoneUpdate; protected procedure Execute; override; public constructor Create(sDBFile : WideString; iStart : Integer = 0; iEnd : Integer = -1); // constructor Create(iStart : Integer = 0; iEnd : Integer = -1); destructor Destroy; override; end; implementation uses {$IFDEF DEBUG} myDebug, {$ENDIF} Forms, SysUtils, myFile, myNum, myString, myWStrings, main, list; { TMyInfoUpdate } function lfnsDBTextConvert(sText : WideString) : WideString; begin Result := WideString('''') + gfnsStrReplace(sText, '''', '''''') + WideString(''''); end; function lfnsFindConvert(sText : WideString) : WideString; begin Result := lfnsDBTextConvert(WideUpperCase(gfnsStrToHalf(gfnsStrToHiragana(sText)))); end; constructor T_MyInfoUpdate.Create(sDBFile : WideString; iStart : Integer = 0; iEnd : Integer = -1); begin // FreeOnTerminate := True; FreeOnTerminate := False; inherited Create(True); // Priority := tpLower; // Priority := tpLowest; Priority := tpIdle; F_iStart := iStart; F_iCount := G_MainForm.plyMedia.Count; if (iEnd < 0) then begin iEnd := F_iCount-1; end; F_iEnd := gfniNumLimit(iEnd, iStart, F_iCount-1); F_sFileName := ''; F_Tag := nil; Resume; end; destructor T_MyInfoUpdate.Destroy; begin {$IFDEF DEBUG} myDebug.gpcDebug('InfoUpdate Destroy'); {$ENDIF} G_PlaylistForm.EndSetTag; //中断もあり得るのでDoneSetTagではない //タグ解放 if (F_Tag <> nil) then begin FreeAndNil(F_Tag); end; inherited; end; procedure T_MyInfoUpdate.Execute; var i : Integer; begin for i := F_iStart to F_iEnd do begin if (Self.Terminated) or (Application.Terminated) then begin {$IFDEF DEBUG} myDebug.gpcDebug('Terminated Execute'); {$ENDIF} Exit; end; F_iIndex := i; Synchronize(CheckInfo); if (Self.Terminated) or (Application.Terminated) then begin {$IFDEF DEBUG} myDebug.gpcDebug('Terminated Execute CheckInfo'); {$ENDIF} Exit; end; if (F_bUpdateLibrary) then begin //ライブラリ更新 if (F_Tag = nil) or (F_bTagFromFile) then begin F_Tag := TMyTag2.Create(F_sFileName); end else if (F_bVideoSizeFromFile) then begin //長さとビデオサイズのみ取得 F_Tag.GetVideoSize; end; // F_UpdateLibrary(F_Tag); libman.PutTag(F_Tag); end else begin if (F_bTagFromFile) then begin //多分ここにはこない F_Tag := TMyTag2.Create(F_sFileName); end else if (F_bVideoSizeFromFile) then begin //多分ここにもこない //長さとビデオサイズのみ取得 F_Tag.GetVideoSize; end else begin //F_Tagはnil end; end; Synchronize(UpdateInfo); if (F_Tag <> nil) then begin FreeAndNil(F_Tag); end; end; Synchronize(DoneUpdate); end; procedure T_MyInfoUpdate.CheckInfo; //リストのF_iIndexのタグ情報をファイルから取得すべきかどうかのフラグを設定する var li_ListTime : Int64; // li_LibraryTime : Int64; li_FileTime : Int64; l_ListTag : TMyTag; // l_LibraryTag : TMyTag; begin if (Self.Terminated) or (Application.Terminated) then begin {$IFDEF DEBUG} myDebug.gpcDebug('Terminated CheckInfo'); {$ENDIF} Exit; end; F_bTagFromFile := False; F_bVideoSizeFromFile := False; F_bUpdateList := False; F_bUpdateLibrary := False; F_sFileName := G_MainForm.plyMedia.Items[F_iIndex]; // if (F_GetLibTag(F_sFileName)) then begin if (libman.GetTag(F_Tag, F_sFileName)) then begin //ライブラリにあった //F_GetLibTag内でF_TagはCreateされライブラリのタグ情報がコピーされている if not(gfnbFileExists(F_sFileName)) then begin //ファイルが存在しないのでライブラリから削除するためにライブラリ更新フラグをセット F_bUpdateLibrary := True; end else begin l_ListTag := TMyTag(G_MainForm.plyMedia.Items.Objects[F_iIndex]); if (l_ListTag <> nil) then begin li_ListTime := l_ListTag.FileWriteTimeInt; end else begin F_bUpdateList := True; //リストの更新が必要 li_ListTime := 0; end; if (G_MainForm.actList_ReadTag.Checked) then begin li_FileTime := gfniFileWriteTimeGet(F_sFileName); end else begin li_FileTime := 0; end; //ライブラリとファイルおよびリストとの比較 if (li_FileTime > F_Tag.FileWriteTimeInt) then begin //ライブラリよりファイルの方が新しい F_bTagFromFile := True; F_bUpdateList := True; //リストの更新が必要 F_bUpdateLibrary := True; //ライブラリの更新も必要 end else if (li_ListTime > F_Tag.FileWriteTimeInt) then begin //ライブラリよりリストの方が新しい。 //考えられるのはプレイリストフォームで情報表示を行ったとか。 F_bUpdateLibrary := True; //ライブラリの更新は必要。 F_Tag.Assign(l_ListTag); //F_Tagにリストのタグ情報をコピー。 if (F_Tag.MediaLength <= 0) then begin //長さが0ならビデオサイズの取得はまだ F_bVideoSizeFromFile := True; //ビデオサイズなどの取得は必要 F_bUpdateList := True; //リストの更新は必要 end; end else begin //ファイル、リスト共にライブラリより新しくない。 if (F_Tag.MediaLength <= 0) then begin //長さが0ならビデオサイズの取得はまだ F_bVideoSizeFromFile := True; //ビデオサイズなどの取得は必要 F_bUpdateList := True; //リストの更新は必要 F_bUpdateLibrary := True; //ライブラリの更新も恐らく必要なのでやっておく end; end; end; end else begin //ライブラリになかった F_bUpdateLibrary := True; //ライブラリの更新が必要。 F_bUpdateList := True; //リストも更新。 F_bTagFromFile := True; //ファイルから読み込み。 end; end; procedure T_MyInfoUpdate.UpdateInfo; begin if (Terminated) or (Application.Terminated) then begin {$IFDEF DEBUG} myDebug.gpcDebug('Terminated UpdateInfo'); {$ENDIF} Exit; end; if (F_Tag <> nil) then begin {$IFDEF DEBUG} //myDebug.gpcDebug(['UpdateInfo', F_iIndex, F_bUpdateList, F_bUpdateLibrary, F_Tag.MediaName]); {$ENDIF} G_PlaylistForm.SetTag(F_iIndex, F_Tag, F_bUpdateList, F_bUpdateLibrary); end; end; procedure T_MyInfoUpdate.DoneUpdate; begin {$IFDEF DEBUG} myDebug.gpcDebug('DoneUpdate'); {$ENDIF} G_PlaylistForm.DoneSetTag; end; end.