downloadedchaptersdb, rename db and change method call

This commit is contained in:
dazedcat19 2020-04-29 10:56:50 +08:00
parent ed72296749
commit 015b64dd8b
6 changed files with 29 additions and 56 deletions

View File

@ -14,14 +14,13 @@ type
TDownloadedChaptersDB = class(TSQliteData) TDownloadedChaptersDB = class(TSQliteData)
private private
locklocate: TRTLCriticalSection; locklocate: TRTLCriticalSection;
function GetChapters(const AIdLink: String): String; function GetChapters(const AModuleID, ALink: String): String;
procedure SetChapters(const AIdLink: String; AValue: String); procedure SetChapters(const AModuleID, ALink: String; AValue: String);
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure Delete(const AIdLink: String); procedure Delete(const AModuleID, ALink: String);
property Chapters[const AIdLink: String]: String read GetChapters write SetChapters; property Chapters[const AModuleID, ALink: String]: String read GetChapters write SetChapters;
function ImportFromIni(const AFilename: String): Boolean;
end; end;
implementation implementation
@ -37,30 +36,30 @@ end;
{ TDownloadedChaptersDB } { TDownloadedChaptersDB }
function TDownloadedChaptersDB.GetChapters(const AIdLink: String): String; function TDownloadedChaptersDB.GetChapters(const AModuleID, ALink: String
): String;
begin begin
Result := ''; Result := '';
if AIdLink = '' then Exit;
if not Connected then Exit; if not Connected then Exit;
EnterCriticalsection(locklocate); EnterCriticalsection(locklocate);
with Table do with Table do
try try
if Locate('idlink', LowerCase(AIdLink), []) then if Locate('id', LowerCase(AModuleID+ALink), []) then
Result := Fields[1].AsString; Result := Fields[1].AsString;
finally finally
LeaveCriticalsection(locklocate); LeaveCriticalsection(locklocate);
end; end;
end; end;
procedure TDownloadedChaptersDB.SetChapters(const AIdLink: String; AValue: String); procedure TDownloadedChaptersDB.SetChapters(const AModuleID, ALink: String;
AValue: String);
begin begin
if AIdLink = '' then Exit;
if AValue = '' then Exit; if AValue = '' then Exit;
if not Connected then Exit; if not Connected then Exit;
EnterCriticalsection(locklocate); EnterCriticalsection(locklocate);
with Table do with Table do
try try
if Locate('idlink', LowerCase(AIdLink), []) then if Locate('id', LowerCase(AModuleID+ALink), []) then
begin begin
Edit; Edit;
Fields[1].AsString := MergeCaseInsensitive([Fields[1].AsString, AValue]); Fields[1].AsString := MergeCaseInsensitive([Fields[1].AsString, AValue]);
@ -68,7 +67,7 @@ begin
else else
begin begin
Append; Append;
Fields[0].AsString := LowerCase(AIdLink); Fields[0].AsString := LowerCase(AModuleID+ALink);
Fields[1].AsString := AValue; Fields[1].AsString := AValue;
end; end;
try try
@ -88,9 +87,9 @@ begin
AutoApplyUpdates := True; AutoApplyUpdates := True;
TableName := 'downloadedchapters'; TableName := 'downloadedchapters';
CreateParams := CreateParams :=
'"idlink" VARCHAR(3000) NOT NULL PRIMARY KEY,' + '"id" VARCHAR(3000) NOT NULL PRIMARY KEY,' +
'"chapters" TEXT'; '"chapters" TEXT';
FieldsParams := '"idlink","chapters"'; FieldsParams := '"id","chapters"';
SelectParams := 'SELECT ' + FieldsParams + ' FROM ' + QuotedStrD(TableName); SelectParams := 'SELECT ' + FieldsParams + ' FROM ' + QuotedStrD(TableName);
end; end;
@ -100,41 +99,18 @@ begin
DoneCriticalsection(locklocate); DoneCriticalsection(locklocate);
end; end;
procedure TDownloadedChaptersDB.Delete(const AIdLink: String); procedure TDownloadedChaptersDB.Delete(const AModuleID, ALink: String);
begin begin
if not Connected then Exit; if not Connected then Exit;
EnterCriticalsection(locklocate); EnterCriticalsection(locklocate);
with Table do with Table do
try try
if Locate('idlink', LowerCase(AIdLink), []) then if Locate('id', LowerCase(AModuleID+ALink), []) then
Delete; Delete;
finally finally
LeaveCriticalsection(locklocate); LeaveCriticalsection(locklocate);
end; end;
end; end;
function TDownloadedChaptersDB.ImportFromIni(const AFilename: String): Boolean;
var
dc: TStringList;
i: Integer = 0;
begin
Result := False;
if not Connected then Exit;
if not FileExistsUTF8(AFilename) then Exit;
dc := TStringList.Create;
try
dc.LoadFromFile(AFilename);
if dc.Count > 0 then
while i <= dc.Count - 2 do
begin
Chapters[dc[i]] := RemoveHostFromURL(GetParams(dc[i + 1]));
Inc(i, 2);
end;
Result := True;
finally
dc.Free;
end;
end;
end. end.

View File

@ -65,7 +65,6 @@ var
DEFAULT_PATH, DEFAULT_PATH,
USERDATA_FOLDER, USERDATA_FOLDER,
DOWNLOADSDB_FILE, DOWNLOADSDB_FILE,
DOWNLOADEDCHAPTERS_FILE,
DOWNLOADEDCHAPTERSDB_FILE, DOWNLOADEDCHAPTERSDB_FILE,
FAVORITES_FILE, FAVORITES_FILE,
FAVORITESDB_FILE, FAVORITESDB_FILE,

View File

@ -215,8 +215,8 @@ type
procedure Backup; procedure Backup;
// These methods relate to highlight downloaded chapters. // These methods relate to highlight downloaded chapters.
procedure GetDownloadedChaptersState(const Alink: String; procedure GetDownloadedChaptersState(const AModuleID, ALink: String;
var Chapters: array of TChapterStateItem); var AChapters: array of TChapterStateItem);
// Add new task to the list. // Add new task to the list.
function AddTask: Integer; function AddTask: Integer;
@ -1312,9 +1312,6 @@ begin
DownloadedChapters.Filename := DOWNLOADEDCHAPTERSDB_FILE; DownloadedChapters.Filename := DOWNLOADEDCHAPTERSDB_FILE;
DownloadedChapters.OnError := @MainForm.ExceptionHandler; DownloadedChapters.OnError := @MainForm.ExceptionHandler;
DownloadedChapters.Open; DownloadedChapters.Open;
if FileExistsUTF8(DOWNLOADEDCHAPTERS_FILE) then
if DownloadedChapters.ImportFromIni(DOWNLOADEDCHAPTERS_FILE) then
DeleteFileUTF8(DOWNLOADEDCHAPTERS_FILE);
Items := TTaskContainers.Create; Items := TTaskContainers.Create;
ItemsActiveTask := TTaskContainers.Create; ItemsActiveTask := TTaskContainers.Create;
@ -1464,22 +1461,23 @@ begin
end; end;
end; end;
procedure TDownloadManager.GetDownloadedChaptersState(const Alink: String; procedure TDownloadManager.GetDownloadedChaptersState(const AModuleID,
var Chapters: array of TChapterStateItem); ALink: String; var AChapters: array of TChapterStateItem);
var var
s: TStringList; s: TStringList;
i, p: Integer; i, p: Integer;
begin begin
if Length(AChapters) = 0 then Exit;
s := TStringList.Create; s := TStringList.Create;
try try
s.Sorted := True; s.Sorted := True;
s.AddText(DownloadedChapters.Chapters[Alink]); s.AddText(DownloadedChapters.Chapters[AModuleID, ALink]);
if s.Count > 0 then if s.Count > 0 then
for i := Low(Chapters) to High(Chapters) do for i := Low(AChapters) to High(AChapters) do
Chapters[i].Downloaded := s.Find(LowerCase(Chapters[i].Link), p) AChapters[i].Downloaded := s.Find(LowerCase(AChapters[i].Link), p)
else else
for i := Low(Chapters) to High(Chapters) do for i := Low(AChapters) to High(AChapters) do
Chapters[i].Downloaded := False; AChapters[i].Downloaded := False;
finally finally
s.Free; s.Free;
end; end;

View File

@ -918,7 +918,7 @@ begin
// add to downloaded chapter list // add to downloaded chapter list
FavoriteInfo.downloadedChapterList := MergeCaseInsensitive([FavoriteInfo.DownloadedChapterList, chapterLinks.Text]); FavoriteInfo.downloadedChapterList := MergeCaseInsensitive([FavoriteInfo.DownloadedChapterList, chapterLinks.Text]);
// add to downloaded chapter list in downloadmanager // add to downloaded chapter list in downloadmanager
DLManager.DownloadedChapters.Chapters[FavoriteInfo.ModuleID + FavoriteInfo.Link] := chapterLinks.Text; DLManager.DownloadedChapters.Chapters[FavoriteInfo.ModuleID, FavoriteInfo.Link] := chapterLinks.Text;
end; end;
// free unused objects // free unused objects
FreeAndNil(NewMangaInfo); FreeAndNil(NewMangaInfo);

View File

@ -390,7 +390,7 @@ begin
// save downloaded chapters // save downloaded chapters
if Info.mangaInfo.ChapterLinks.Count > 0 then if Info.mangaInfo.ChapterLinks.Count > 0 then
begin begin
DLManager.DownloadedChapters.Chapters[Info.mangaInfo.ModuleID + URL]:= DLManager.DownloadedChapters.Chapters[Info.mangaInfo.ModuleID, URL]:=
Info.mangaInfo.ChapterLinks.Text; Info.mangaInfo.ChapterLinks.Text;
FavoriteManager.AddToDownloadedChaptersList(Info.mangaInfo.ModuleID, FavoriteManager.AddToDownloadedChaptersList(Info.mangaInfo.ModuleID,
URL, Info.mangaInfo.ChapterLinks); URL, Info.mangaInfo.ChapterLinks);

View File

@ -2079,7 +2079,7 @@ begin
end; end;
if Length(ChapterList) = 0 then Exit; if Length(ChapterList) = 0 then Exit;
if miChapterListHighlight.Checked then if miChapterListHighlight.Checked then
DLManager.GetDownloadedChaptersState(mangaInfo.ModuleID + mangaInfo.Link, DLManager.GetDownloadedChaptersState(mangaInfo.ModuleID, mangaInfo.Link,
ChapterList) ChapterList)
else else
ClearChapterListState; ClearChapterListState;
@ -2485,7 +2485,7 @@ begin
if OptionSortDownloadsWhenAddingNewDownloadTasks then if OptionSortDownloadsWhenAddingNewDownloadTasks then
DLManager.Sort(DLManager.SortColumn); DLManager.Sort(DLManager.SortColumn);
end; end;
DLManager.DownloadedChapters.Chapters[mangaInfo.ModuleID+mangaInfo.Link]:=links.Text; DLManager.DownloadedChapters.Chapters[mangaInfo.ModuleID, mangaInfo.Link]:=links.Text;
FavoriteManager.AddToDownloadedChaptersList(mangaInfo.ModuleID,mangaInfo.Link,links); FavoriteManager.AddToDownloadedChaptersList(mangaInfo.ModuleID,mangaInfo.Link,links);
DLManager.CheckAndActiveTask; DLManager.CheckAndActiveTask;
if OptionShowDownloadsTabOnNewTasks then if OptionShowDownloadsTabOnNewTasks then