mirror of
https://github.com/dazedcat19/FMD2.git
synced 2025-02-20 03:41:04 +00:00
added userdata converter
This commit is contained in:
parent
eb3e2c317d
commit
fbc93d641c
102
utils/userdataconverter/converter.lpi
Normal file
102
utils/userdataconverter/converter.lpi
Normal file
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="converter"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="win32" Default="True"/>
|
||||
<Item Name="win64">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="converter"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
<TargetCPU Value="x86_64"/>
|
||||
<TargetOS Value="win64"/>
|
||||
<Optimizations>
|
||||
<OptimizationLevel Value="2"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
</Debugging>
|
||||
<LinkSmart Value="True"/>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<DestinationDirectory Value="$(ProjPath)\published\"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="converter.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="converter"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
<TargetCPU Value="i386"/>
|
||||
<TargetOS Value="win32"/>
|
||||
<Optimizations>
|
||||
<OptimizationLevel Value="2"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
</Debugging>
|
||||
<LinkSmart Value="True"/>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
293
utils/userdataconverter/converter.lpr
Normal file
293
utils/userdataconverter/converter.lpr
Normal file
@ -0,0 +1,293 @@
|
||||
program converter;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, jsonini, SQLite3Dyn, SQLite3Conn, SQLDB;
|
||||
|
||||
var
|
||||
modules: TStringList;
|
||||
i: Integer;
|
||||
m: TStringArray;
|
||||
s, si: String;
|
||||
dbcon: TSQLite3Connection;
|
||||
dbquery: TSQLQuery;
|
||||
dbtrans: TSQLTransaction;
|
||||
|
||||
function copyfile(fromfile, tofile:string):boolean;
|
||||
begin
|
||||
result:=false;
|
||||
if not fileexists(fromfile) then exit;
|
||||
result:=true;
|
||||
if fileexists(tofile) then result:=DeleteFile(tofile);
|
||||
if result then
|
||||
with tmemorystream.create do
|
||||
try
|
||||
loadfromfile(fromfile);
|
||||
savetofile(tofile);
|
||||
result:=fileexists(tofile);
|
||||
finally
|
||||
free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ToStrZeroPad(const i, len: Word): String;
|
||||
begin
|
||||
Result:=IntToStr(i);
|
||||
if Length(Result)<len then
|
||||
Result:=StringOfChar('0',len-Length(Result))+Result;
|
||||
end;
|
||||
|
||||
function DateTimeToSQLiteDateTime(const D: TDateTime): String;
|
||||
var
|
||||
Year, Month, Day, Hour, Minute, Second, MiliSecond: word;
|
||||
begin
|
||||
DecodeDate(D, Year, Month, Day);
|
||||
DecodeTime(D, Hour, Minute, Second, MiliSecond);
|
||||
Result := ToStrZeroPad(Year,4)+'-'+ToStrZeroPad(Month,2)+'-'+ToStrZeroPad(Day,2)+' '+
|
||||
ToStrZeroPad(Hour,2)+':'+ToStrZeroPad(Minute,2)+':'+ToStrZeroPad(Second,2)+'.'+ToStrZeroPad(MiliSecond,3);
|
||||
end;
|
||||
|
||||
function QuotedStr(const S: TDateTime): String;
|
||||
begin
|
||||
Result := AnsiQuotedStr(DateTimeToSQLiteDateTime(S), '''');
|
||||
end;
|
||||
|
||||
begin
|
||||
ForceDirectories('converted\userdata');
|
||||
if FileExists('config\config.ini') then
|
||||
TJSONIniFile.ConvertIni('config\config.ini', 'converted\userdata\settings.json', True);
|
||||
|
||||
modules:=TStringList.Create;
|
||||
if FileExists('modules.txt') then
|
||||
begin
|
||||
modules.Sorted := false;
|
||||
modules.LoadFromFile('modules.txt');
|
||||
for i:=0 to modules.Count-1 do
|
||||
begin
|
||||
m:=modules[i].Split(' ');
|
||||
modules[i] := m[1]+'='+m[0];
|
||||
end;
|
||||
modules.Sorted := true;
|
||||
modules.CaseSensitive := false;
|
||||
end;
|
||||
|
||||
|
||||
if FileExists('converted\userdata\settings.json') then
|
||||
with TJSONIniFile.Create('converted\userdata\settings.json') do
|
||||
try
|
||||
s:='';
|
||||
for si in ReadString('general', 'MangaListSelect', '').Split(',') do
|
||||
begin
|
||||
i := modules.IndexOfName(si);
|
||||
if i <> -1 then
|
||||
s += modules.ValueFromIndex[i] + ',';
|
||||
end;
|
||||
WriteString('General', 'MangaListSelect', s.TrimRight(','));
|
||||
UpdateFile;
|
||||
finally
|
||||
free;
|
||||
end;
|
||||
|
||||
s:=IncludeTrailingPathDelimiter(GetCurrentDir)+Sqlite3Lib;
|
||||
if FileExists(s) then
|
||||
SQLiteDefaultLibrary := s;
|
||||
dbcon:=TSQLite3Connection.Create(nil);
|
||||
dbtrans:=TSQLTransaction.Create(nil);
|
||||
dbquery:=TSQLQuery.Create(nil);
|
||||
try
|
||||
dbcon.Transaction:=dbtrans;
|
||||
dbquery.DataBase:=dbcon;
|
||||
dbquery.Transaction:=dbtrans;
|
||||
dbquery.Options := dbquery.Options-[sqoAutoApplyUpdates];
|
||||
|
||||
if copyfile('works\downloadedchapters.db', 'converted\userdata\downloadedchapters.db') then
|
||||
begin
|
||||
dbcon.DatabaseName := 'converted\userdata\downloadedchapters.db';
|
||||
dbcon.Connected := true;
|
||||
dbcon.ExecuteDirect('ALTER TABLE "downloadedchapters" RENAME COLUMN "websitelink" TO "id"');
|
||||
dbquery.SQL.Text := 'SELECT "id" FROM "downloadedchapters"';
|
||||
dbquery.ExecSQL;
|
||||
dbquery.Active := true;
|
||||
dbquery.First;
|
||||
while dbquery.EOF=false do
|
||||
begin
|
||||
s:=dbquery.Fields[0].AsString;
|
||||
i:=Pos('/',s);
|
||||
si:=copy(s,i,Length(s));
|
||||
s:=copy(s,1,i-1);
|
||||
i:=modules.IndexOfName(s);
|
||||
if i<>-1 then
|
||||
begin
|
||||
dbquery.Edit;
|
||||
dbquery.Fields[0].AsString := modules.ValueFromIndex[i]+si;
|
||||
dbquery.Post;
|
||||
end;
|
||||
dbquery.Next;
|
||||
end;
|
||||
dbquery.ApplyUpdates;
|
||||
dbcon.ExecuteDirect('END TRANSACTION');
|
||||
dbcon.ExecuteDirect('VACUUM');
|
||||
dbcon.ExecuteDirect('BEGIN TRANSACTION');
|
||||
dbtrans.Commit;
|
||||
dbcon.Connected := false;
|
||||
end;
|
||||
|
||||
if copyfile('works\favorites.db', 'converted\userdata\favorites.db') then
|
||||
begin
|
||||
dbcon.DatabaseName := 'converted\userdata\favorites.db';
|
||||
dbcon.Connected := true;
|
||||
dbcon.ExecuteDirect('ALTER TABLE "favorites" RENAME COLUMN "websitelink" TO "id"');
|
||||
dbcon.ExecuteDirect('ALTER TABLE "favorites" RENAME COLUMN "website" TO "moduleid"');
|
||||
dbcon.ExecuteDirect('ALTER TABLE "favorites" ADD COLUMN "dateadded" DATETIME');
|
||||
dbcon.ExecuteDirect('ALTER TABLE "favorites" ADD COLUMN "datelastchecked" DATETIME');
|
||||
dbcon.ExecuteDirect('ALTER TABLE "favorites" ADD COLUMN "datelastupdated" DATETIME');
|
||||
dbcon.ExecuteDirect('UPDATE "favorites" SET "dateadded"='+QuotedStr(Now));
|
||||
dbcon.ExecuteDirect('UPDATE "favorites" SET "datelastchecked"='+QuotedStr(Now));
|
||||
dbcon.ExecuteDirect('UPDATE "favorites" SET "datelastupdated"='+QuotedStr(Now));
|
||||
dbquery.SQL.Text := 'SELECT "id", "moduleid" FROM "favorites"';
|
||||
dbquery.ExecSQL;
|
||||
dbquery.Active := true;
|
||||
dbquery.First;
|
||||
while dbquery.EOF=false do
|
||||
begin
|
||||
s:=dbquery.Fields[0].AsString;
|
||||
i:=Pos('/',s);
|
||||
si:=copy(s,i,Length(s));
|
||||
s:=copy(s,1,i-1);
|
||||
i:=modules.IndexOfName(s);
|
||||
if i<>-1 then
|
||||
begin
|
||||
dbquery.Edit;
|
||||
s:=modules.ValueFromIndex[i];
|
||||
dbquery.Fields[0].AsString := s+si;
|
||||
dbquery.Fields[1].AsString := s;
|
||||
dbquery.Post;
|
||||
end;
|
||||
dbquery.Next;
|
||||
end;
|
||||
dbquery.ApplyUpdates;
|
||||
dbcon.ExecuteDirect('END TRANSACTION');
|
||||
dbcon.ExecuteDirect('VACUUM');
|
||||
dbcon.ExecuteDirect('BEGIN TRANSACTION');
|
||||
dbtrans.Commit;
|
||||
dbcon.Connected := false;
|
||||
end;
|
||||
|
||||
if copyfile('works\downloads.db', 'converted\userdata\downloads.db') then
|
||||
begin
|
||||
dbcon.DatabaseName := 'converted\userdata\downloads.db';
|
||||
dbcon.Connected := true;
|
||||
dbcon.ExecuteDirect('ALTER TABLE "downloads" RENAME TO "olddownloads"');
|
||||
dbcon.ExecuteDirect('CREATE TABLE "downloads" ('+
|
||||
'"id" INTEGER PRIMARY KEY,' +
|
||||
'"enabled" BOOLEAN,' +
|
||||
'"order" INTEGER,' +
|
||||
'"taskstatus" INTEGER,' +
|
||||
'"chapterptr" INTEGER,' +
|
||||
'"numberofpages" INTEGER,' +
|
||||
'"currentpage" INTEGER,' +
|
||||
'"moduleid" TEXT,' +
|
||||
'"link" TEXT,' +
|
||||
'"title" TEXT,' +
|
||||
'"status" TEXT,' +
|
||||
'"progress" TEXT,' +
|
||||
'"saveto" TEXT,' +
|
||||
'"dateadded" DATETIME,' +
|
||||
'"datelastdownloaded" DATETIME,' +
|
||||
'"chapterslinks" TEXT,' +
|
||||
'"chaptersnames" TEXT,' +
|
||||
'"pagelinks" TEXT,' +
|
||||
'"pagecontainerlinks" TEXT,' +
|
||||
'"filenames" TEXT,' +
|
||||
'"customfilenames" TEXT,' +
|
||||
'"chaptersstatus" TEXT)');
|
||||
|
||||
dbcon.ExecuteDirect('INSERT INTO "downloads" (' +
|
||||
'"enabled",' +
|
||||
'"order",' +
|
||||
'"taskstatus",' +
|
||||
'"chapterptr",' +
|
||||
'"numberofpages",' +
|
||||
'"currentpage",' +
|
||||
'"moduleid",' +
|
||||
'"link",' +
|
||||
'"title",' +
|
||||
'"status",' +
|
||||
'"progress",' +
|
||||
'"saveto",' +
|
||||
'"dateadded",' +
|
||||
'"datelastdownloaded",' +
|
||||
'"chapterslinks",' +
|
||||
'"chaptersnames",' +
|
||||
'"pagelinks",' +
|
||||
'"pagecontainerlinks",' +
|
||||
'"filenames",' +
|
||||
'"customfilenames",' +
|
||||
'"chaptersstatus")' +
|
||||
' SELECT ' +
|
||||
'"enabled",' +
|
||||
'"order",' +
|
||||
'"taskstatus",' +
|
||||
'"chapterptr",' +
|
||||
'"numberofpages",' +
|
||||
'"currentpage",' +
|
||||
'"website",' +
|
||||
'"link",' +
|
||||
'"title",' +
|
||||
'"status",' +
|
||||
'"progress",' +
|
||||
'"saveto",' +
|
||||
'"datetime",' +
|
||||
'"datetime",' +
|
||||
'"chapterslinks",' +
|
||||
'"chaptersnames",' +
|
||||
'"pagelinks",' +
|
||||
'"pagecontainerlinks",' +
|
||||
'"filenames",' +
|
||||
'"customfilenames",' +
|
||||
'"chaptersstatus"' +
|
||||
' FROM "olddownloads"');
|
||||
dbcon.ExecuteDirect('DROP TABLE "olddownloads"');
|
||||
dbquery.SQL.Text := 'SELECT "id","moduleid" FROM "downloads"';
|
||||
dbquery.ExecSQL;
|
||||
dbquery.Active := true;
|
||||
dbquery.First;
|
||||
while dbquery.EOF=false do
|
||||
begin
|
||||
s:=dbquery.Fields[1].AsString;
|
||||
i:=modules.IndexOfName(s);
|
||||
if i<>-1 then
|
||||
begin
|
||||
dbquery.Edit;
|
||||
dbquery.Fields[1].AsString := modules.ValueFromIndex[i];
|
||||
dbquery.Post;
|
||||
end;
|
||||
dbquery.Next;
|
||||
end;
|
||||
dbquery.ApplyUpdates;
|
||||
dbcon.ExecuteDirect('END TRANSACTION');
|
||||
dbcon.ExecuteDirect('VACUUM');
|
||||
dbcon.ExecuteDirect('BEGIN TRANSACTION');
|
||||
dbtrans.Commit;
|
||||
dbcon.Connected := false;
|
||||
end;
|
||||
|
||||
except
|
||||
on e:Exception do
|
||||
writeln('error: '+e.Message);
|
||||
end;
|
||||
dbquery.free;
|
||||
dbtrans.free;
|
||||
dbcon.free;
|
||||
|
||||
ForceDirectories('converted\data');
|
||||
for i:=0 to modules.Count-1 do
|
||||
copyfile('data\'+modules.Names[i]+'.db', 'converted\data\'+modules.ValueFromIndex[i]+'.db');
|
||||
|
||||
modules.Free;
|
||||
end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user