mirror of
https://github.com/dazedcat19/FMD2.git
synced 2025-03-01 08:35:38 +00:00
downloadedchaptersdb, rename db and change method call
This commit is contained in:
parent
ed72296749
commit
015b64dd8b
@ -14,14 +14,13 @@ type
|
||||
TDownloadedChaptersDB = class(TSQliteData)
|
||||
private
|
||||
locklocate: TRTLCriticalSection;
|
||||
function GetChapters(const AIdLink: String): String;
|
||||
procedure SetChapters(const AIdLink: String; AValue: String);
|
||||
function GetChapters(const AModuleID, ALink: String): String;
|
||||
procedure SetChapters(const AModuleID, ALink: String; AValue: String);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Delete(const AIdLink: String);
|
||||
property Chapters[const AIdLink: String]: String read GetChapters write SetChapters;
|
||||
function ImportFromIni(const AFilename: String): Boolean;
|
||||
procedure Delete(const AModuleID, ALink: String);
|
||||
property Chapters[const AModuleID, ALink: String]: String read GetChapters write SetChapters;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -37,30 +36,30 @@ end;
|
||||
|
||||
{ TDownloadedChaptersDB }
|
||||
|
||||
function TDownloadedChaptersDB.GetChapters(const AIdLink: String): String;
|
||||
function TDownloadedChaptersDB.GetChapters(const AModuleID, ALink: String
|
||||
): String;
|
||||
begin
|
||||
Result := '';
|
||||
if AIdLink = '' then Exit;
|
||||
if not Connected then Exit;
|
||||
EnterCriticalsection(locklocate);
|
||||
with Table do
|
||||
try
|
||||
if Locate('idlink', LowerCase(AIdLink), []) then
|
||||
if Locate('id', LowerCase(AModuleID+ALink), []) then
|
||||
Result := Fields[1].AsString;
|
||||
finally
|
||||
LeaveCriticalsection(locklocate);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDownloadedChaptersDB.SetChapters(const AIdLink: String; AValue: String);
|
||||
procedure TDownloadedChaptersDB.SetChapters(const AModuleID, ALink: String;
|
||||
AValue: String);
|
||||
begin
|
||||
if AIdLink = '' then Exit;
|
||||
if AValue = '' then Exit;
|
||||
if not Connected then Exit;
|
||||
EnterCriticalsection(locklocate);
|
||||
with Table do
|
||||
try
|
||||
if Locate('idlink', LowerCase(AIdLink), []) then
|
||||
if Locate('id', LowerCase(AModuleID+ALink), []) then
|
||||
begin
|
||||
Edit;
|
||||
Fields[1].AsString := MergeCaseInsensitive([Fields[1].AsString, AValue]);
|
||||
@ -68,7 +67,7 @@ begin
|
||||
else
|
||||
begin
|
||||
Append;
|
||||
Fields[0].AsString := LowerCase(AIdLink);
|
||||
Fields[0].AsString := LowerCase(AModuleID+ALink);
|
||||
Fields[1].AsString := AValue;
|
||||
end;
|
||||
try
|
||||
@ -88,9 +87,9 @@ begin
|
||||
AutoApplyUpdates := True;
|
||||
TableName := 'downloadedchapters';
|
||||
CreateParams :=
|
||||
'"idlink" VARCHAR(3000) NOT NULL PRIMARY KEY,' +
|
||||
'"id" VARCHAR(3000) NOT NULL PRIMARY KEY,' +
|
||||
'"chapters" TEXT';
|
||||
FieldsParams := '"idlink","chapters"';
|
||||
FieldsParams := '"id","chapters"';
|
||||
SelectParams := 'SELECT ' + FieldsParams + ' FROM ' + QuotedStrD(TableName);
|
||||
end;
|
||||
|
||||
@ -100,41 +99,18 @@ begin
|
||||
DoneCriticalsection(locklocate);
|
||||
end;
|
||||
|
||||
procedure TDownloadedChaptersDB.Delete(const AIdLink: String);
|
||||
procedure TDownloadedChaptersDB.Delete(const AModuleID, ALink: String);
|
||||
begin
|
||||
if not Connected then Exit;
|
||||
EnterCriticalsection(locklocate);
|
||||
with Table do
|
||||
try
|
||||
if Locate('idlink', LowerCase(AIdLink), []) then
|
||||
if Locate('id', LowerCase(AModuleID+ALink), []) then
|
||||
Delete;
|
||||
finally
|
||||
LeaveCriticalsection(locklocate);
|
||||
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.
|
||||
|
||||
|
@ -65,7 +65,6 @@ var
|
||||
DEFAULT_PATH,
|
||||
USERDATA_FOLDER,
|
||||
DOWNLOADSDB_FILE,
|
||||
DOWNLOADEDCHAPTERS_FILE,
|
||||
DOWNLOADEDCHAPTERSDB_FILE,
|
||||
FAVORITES_FILE,
|
||||
FAVORITESDB_FILE,
|
||||
|
@ -215,8 +215,8 @@ type
|
||||
procedure Backup;
|
||||
|
||||
// These methods relate to highlight downloaded chapters.
|
||||
procedure GetDownloadedChaptersState(const Alink: String;
|
||||
var Chapters: array of TChapterStateItem);
|
||||
procedure GetDownloadedChaptersState(const AModuleID, ALink: String;
|
||||
var AChapters: array of TChapterStateItem);
|
||||
|
||||
// Add new task to the list.
|
||||
function AddTask: Integer;
|
||||
@ -1312,9 +1312,6 @@ begin
|
||||
DownloadedChapters.Filename := DOWNLOADEDCHAPTERSDB_FILE;
|
||||
DownloadedChapters.OnError := @MainForm.ExceptionHandler;
|
||||
DownloadedChapters.Open;
|
||||
if FileExistsUTF8(DOWNLOADEDCHAPTERS_FILE) then
|
||||
if DownloadedChapters.ImportFromIni(DOWNLOADEDCHAPTERS_FILE) then
|
||||
DeleteFileUTF8(DOWNLOADEDCHAPTERS_FILE);
|
||||
|
||||
Items := TTaskContainers.Create;
|
||||
ItemsActiveTask := TTaskContainers.Create;
|
||||
@ -1464,22 +1461,23 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDownloadManager.GetDownloadedChaptersState(const Alink: String;
|
||||
var Chapters: array of TChapterStateItem);
|
||||
procedure TDownloadManager.GetDownloadedChaptersState(const AModuleID,
|
||||
ALink: String; var AChapters: array of TChapterStateItem);
|
||||
var
|
||||
s: TStringList;
|
||||
i, p: Integer;
|
||||
begin
|
||||
if Length(AChapters) = 0 then Exit;
|
||||
s := TStringList.Create;
|
||||
try
|
||||
s.Sorted := True;
|
||||
s.AddText(DownloadedChapters.Chapters[Alink]);
|
||||
s.AddText(DownloadedChapters.Chapters[AModuleID, ALink]);
|
||||
if s.Count > 0 then
|
||||
for i := Low(Chapters) to High(Chapters) do
|
||||
Chapters[i].Downloaded := s.Find(LowerCase(Chapters[i].Link), p)
|
||||
for i := Low(AChapters) to High(AChapters) do
|
||||
AChapters[i].Downloaded := s.Find(LowerCase(AChapters[i].Link), p)
|
||||
else
|
||||
for i := Low(Chapters) to High(Chapters) do
|
||||
Chapters[i].Downloaded := False;
|
||||
for i := Low(AChapters) to High(AChapters) do
|
||||
AChapters[i].Downloaded := False;
|
||||
finally
|
||||
s.Free;
|
||||
end;
|
||||
|
@ -918,7 +918,7 @@ begin
|
||||
// add to downloaded chapter list
|
||||
FavoriteInfo.downloadedChapterList := MergeCaseInsensitive([FavoriteInfo.DownloadedChapterList, chapterLinks.Text]);
|
||||
// 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;
|
||||
// free unused objects
|
||||
FreeAndNil(NewMangaInfo);
|
||||
|
@ -390,7 +390,7 @@ begin
|
||||
// save downloaded chapters
|
||||
if Info.mangaInfo.ChapterLinks.Count > 0 then
|
||||
begin
|
||||
DLManager.DownloadedChapters.Chapters[Info.mangaInfo.ModuleID + URL]:=
|
||||
DLManager.DownloadedChapters.Chapters[Info.mangaInfo.ModuleID, URL]:=
|
||||
Info.mangaInfo.ChapterLinks.Text;
|
||||
FavoriteManager.AddToDownloadedChaptersList(Info.mangaInfo.ModuleID,
|
||||
URL, Info.mangaInfo.ChapterLinks);
|
||||
|
@ -2079,7 +2079,7 @@ begin
|
||||
end;
|
||||
if Length(ChapterList) = 0 then Exit;
|
||||
if miChapterListHighlight.Checked then
|
||||
DLManager.GetDownloadedChaptersState(mangaInfo.ModuleID + mangaInfo.Link,
|
||||
DLManager.GetDownloadedChaptersState(mangaInfo.ModuleID, mangaInfo.Link,
|
||||
ChapterList)
|
||||
else
|
||||
ClearChapterListState;
|
||||
@ -2485,7 +2485,7 @@ begin
|
||||
if OptionSortDownloadsWhenAddingNewDownloadTasks then
|
||||
DLManager.Sort(DLManager.SortColumn);
|
||||
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);
|
||||
DLManager.CheckAndActiveTask;
|
||||
if OptionShowDownloadsTabOnNewTasks then
|
||||
|
Loading…
x
Reference in New Issue
Block a user