added custom text to be used for replace unicode character with, fixed changed replace unicode character method with unicode aware

#347
This commit is contained in:
riderkick 2016-08-15 16:49:00 +08:00
parent a55b9d04fb
commit c83ee2235f
10 changed files with 90 additions and 41 deletions

View File

@ -91,6 +91,7 @@ var
OptionLetFMDDo: TFMDDo = DO_NOTHING;
OptionChangeUnicodeCharacter: Boolean = False;
OptionChangeUnicodeCharacterStr: String = '_';
OptionGenerateMangaFolder: Boolean = False;
OptionMangaCustomRename: String;
OptionGenerateChapterFolder: Boolean = True;

View File

@ -653,7 +653,7 @@ type
end;
// Remove Unicode
function UnicodeRemove(const S: String): String;
function ReplaceUnicodeChar(const S, ReplaceStr: String): String;
// Check a directory to see if it's empty (return TRUE) or not
function IsDirectoryEmpty(const ADir: String): Boolean;
function CheckRedirect(const HTTP: THTTPSend): String;
@ -786,8 +786,9 @@ function IncStr(const I: Integer; N: Integer = 1): String; overload; inline;
function GetHeaderValue(const AHeaders: TStrings; HName: String): String;
// custom rename feature
function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist,
AChapter, ANumbering: String; const ARemoveUnicode: Boolean;
function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist, AChapter, ANumbering: String;
const AReplaceUnicode: Boolean;
const AReplaceUnicodeStr: String;
const AFilename: String = ''): String;
// Get substring from source
@ -979,19 +980,24 @@ end;
{$ENDIF}
function UnicodeRemove(const S: String): String;
function ReplaceUnicodeChar(const S, ReplaceStr: String): String;
var
i: Integer;
s1, s2, sr: UnicodeString;
begin
Result := S;
for i := 1 to Length(Result) do
if Result = '' then Exit;
s1 := UTF8Decode(S);
s2 := UTF8Decode(ReplaceStr);
sr := '';
for i := 1 to Length(s1) do
begin
if (Byte(Result[i]) < 31) or (Byte(Result[i]) > 127) then
begin
Delete(Result, i, 1);
Insert('_', Result, i);
end;
if (Ord(s1[i]) < 31) or (Ord(s1[i]) > 127) then
sr := sr + s2
else
sr := sr + s1[i];
end;
Result := UTF8Encode(sr);
end;
function IsDirectoryEmpty(const ADir: String): Boolean;
@ -2199,8 +2205,10 @@ begin
end;
end;
function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist, AChapter,
ANumbering: String; const ARemoveUnicode: Boolean; const AFilename: String): String;
function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist, AChapter, ANumbering: String;
const AReplaceUnicode: Boolean;
const AReplaceUnicodeStr: String;
const AFilename: String): String;
function FixStringLocal(const S: String): String;
begin
@ -2209,8 +2217,8 @@ function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist, ACh
// remove unaccepted character (Windows)
Result := RemoveSymbols(Result);
// strip unicode character
if ARemoveUnicode then
Result := UnicodeRemove(Result);
if AReplaceUnicode then
Result := ReplaceUnicodeChar(Result, AReplaceUnicodeStr);
end;
var

View File

@ -726,7 +726,8 @@ begin
NewMangaInfo.artists,
NewMangaInfo.chapterName[NewMangaInfoChaptersPos[j]],
Format('%.4d', [NewMangaInfoChaptersPos[j] + 1]),
OptionChangeUnicodeCharacter));
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr));
end;
if LNCResult = ncrDownload then

View File

@ -335,7 +335,8 @@ begin
Info.mangaInfo.artists,
Info.mangaInfo.chapterName.Strings[i],
Format('%.4d', [i + 1]),
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
DLManager.Items[p].chapterName.Add(s);
DLManager.Items[p].chapterLinks.Add(
Info.mangaInfo.chapterLinks.Strings[i]);
@ -372,7 +373,8 @@ begin
info.mangaInfo.artists,
'',
'',
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
end;
DLManager.Items[p].downloadInfo.SaveTo := FSavePath;
@ -465,7 +467,8 @@ begin
info.mangaInfo.artists,
'',
'',
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
s2 := '';
if (Info.mangaInfo.numChapter > 0) then
begin

View File

@ -13,7 +13,6 @@ object MainForm: TMainForm
OnShow = FormShow
OnWindowStateChange = FormWindowStateChange
Position = poScreenCenter
LCLVersion = '1.7'
Visible = False
object sbUpdateList: TStatusBar
Left = 0
@ -2133,11 +2132,11 @@ object MainForm: TMainForm
end
object tsOption: TTabSheet
Caption = 'Options'
ClientHeight = 484
ClientHeight = 492
ClientWidth = 558
object pnOptions: TPageControl
Left = 8
Height = 407
Height = 415
Top = 8
Width = 539
ActivePage = tsGeneral
@ -2151,7 +2150,7 @@ object MainForm: TMainForm
ChildSizing.TopBottomSpacing = 8
ChildSizing.HorizontalSpacing = 4
ChildSizing.VerticalSpacing = 4
ClientHeight = 379
ClientHeight = 387
ClientWidth = 531
object cbOptionMinimizeToTray: TCheckBox
AnchorSideLeft.Control = seOptionNewMangaTime
@ -2791,22 +2790,22 @@ object MainForm: TMainForm
end
object tsSaveTo: TTabSheet
Caption = 'Save to'
ClientHeight = 379
ClientHeight = 387
ClientWidth = 531
object sbSaveTo: TScrollBox
Left = 0
Height = 379
Height = 387
Top = 0
Width = 531
HorzScrollBar.Page = 198
VertScrollBar.Page = 379
VertScrollBar.Page = 387
Align = alClient
BorderStyle = bsNone
ChildSizing.LeftRightSpacing = 4
ChildSizing.TopBottomSpacing = 8
ChildSizing.HorizontalSpacing = 4
ChildSizing.VerticalSpacing = 4
ClientHeight = 379
ClientHeight = 387
ClientWidth = 514
TabOrder = 0
object rgOptionCompress: TRadioGroup
@ -2870,10 +2869,11 @@ object MainForm: TMainForm
object cbOptionChangeUnicodeCharacter: TCheckBox
Left = 4
Height = 19
Hint = 'Enable this if you have problem with unicode character in path.'
Top = 4
Width = 494
Align = alTop
Caption = 'Change all all unicode symbols to "_" (choose this when you have problem with unicode path)'
Width = 200
Caption = 'Replace all unicode character with'
OnChange = cbOptionChangeUnicodeCharacterChange
ParentFont = False
TabOrder = 0
end
@ -3103,6 +3103,17 @@ object MainForm: TMainForm
Caption = 'Filename:'
ParentColor = False
end
object edOptionChangeUnicodeCharacterStr: TEdit
AnchorSideLeft.Control = cbOptionChangeUnicodeCharacter
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cbOptionChangeUnicodeCharacter
Left = 208
Height = 23
Top = 4
Width = 80
Enabled = False
TabOrder = 11
end
end
object lbDefaultDownloadPath: TLabel
Left = 4
@ -3817,7 +3828,7 @@ object MainForm: TMainForm
object btOptionApply: TBitBtn
Left = 8
Height = 45
Top = 426
Top = 434
Width = 125
Anchors = [akLeft, akBottom]
AutoSize = True

View File

@ -170,7 +170,8 @@
{"hash":160200703,"name":"tmainform.tssaveto.caption","sourcebytes":[83,97,118,101,32,116,111],"value":"Save to"},
{"hash":96652067,"name":"tmainform.rgoptioncompress.caption","sourcebytes":[83,97,118,101,32,100,111,119,110,108,111,97,100,101,100,32,99,104,97,112,116,101,114,115,32,97,115],"value":"Save downloaded chapters as"},
{"hash":206060487,"name":"tmainform.gboptionrenaming.caption","sourcebytes":[82,101,110,97,109,105,110,103],"value":"Renaming"},
{"hash":25140969,"name":"tmainform.cboptionchangeunicodecharacter.caption","sourcebytes":[67,104,97,110,103,101,32,97,108,108,32,97,108,108,32,117,110,105,99,111,100,101,32,115,121,109,98,111,108,115,32,116,111,32,34,95,34,32,40,99,104,111,111,115,101,32,116,104,105,115,32,119,104,101,110,32,121,111,117,32,104,97,118,101,32,112,114,111,98,108,101,109,32,119,105,116,104,32,117,110,105,99,111,100,101,32,112,97,116,104,41],"value":"Change all all unicode symbols to \"_\" (choose this when you have problem with unicode path)"},
{"hash":117199758,"name":"tmainform.cboptionchangeunicodecharacter.hint","sourcebytes":[69,110,97,98,108,101,32,116,104,105,115,32,105,102,32,121,111,117,32,104,97,118,101,32,112,114,111,98,108,101,109,32,119,105,116,104,32,117,110,105,99,111,100,101,32,99,104,97,114,97,99,116,101,114,32,105,110,32,112,97,116,104,46],"value":"Enable this if you have problem with unicode character in path."},
{"hash":135172728,"name":"tmainform.cboptionchangeunicodecharacter.caption","sourcebytes":[82,101,112,108,97,99,101,32,97,108,108,32,117,110,105,99,111,100,101,32,99,104,97,114,97,99,116,101,114,32,119,105,116,104],"value":"Replace all unicode character with"},
{"hash":153869381,"name":"tmainform.cboptiongeneratemangafolder.caption","sourcebytes":[65,117,116,111,32,103,101,110,101,114,97,116,101,32,102,111,108,100,101,114,32,98,97,115,101,100,32,111,110,32,109,97,110,103,97,39,115,32,110,97,109,101],"value":"Auto generate folder based on manga's name"},
{"hash":8004730,"name":"tmainform.lboptionmangacustomrename.caption","sourcebytes":[77,97,110,103,97,32,102,111,108,100,101,114,32,110,97,109,101,58],"value":"Manga folder name:"},
{"hash":222491525,"name":"tmainform.edoptionmangacustomrename.texthint","sourcebytes":[67,117,115,116,111,109,32,114,101,110,97,109,101],"value":"Custom rename"},

View File

@ -70,6 +70,7 @@ type
edDownloadsSearch: TEdit;
edFilterMangaInfoChapters: TEditButton;
edFavoritesSearch: TEdit;
edOptionChangeUnicodeCharacterStr: TEdit;
edOptionFilenameCustomRename: TEdit;
edOptionDefaultPath: TDirectoryEdit;
edOptionMangaCustomRename: TEdit;
@ -400,6 +401,7 @@ type
procedure btWebsitesSearchClearClick(Sender: TObject);
procedure cbAddAsStoppedChange(Sender: TObject);
procedure cbOptionAutoCheckFavIntervalChange(Sender: TObject);
procedure cbOptionChangeUnicodeCharacterChange(Sender: TObject);
procedure cbOptionDigitChapterChange(Sender: TObject);
procedure cbOptionDigitVolumeChange(Sender: TObject);
procedure cbOptionGenerateMangaFolderChange(Sender: TObject);
@ -1971,7 +1973,8 @@ begin
mangaInfo.artists,
mangaInfo.chapterName.Strings[xNode^.Index],
Format('%.4d', [xNode^.Index + 1]),
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
DLManager.Items[pos].ChapterName.Add(s);
DLManager.Items[pos].ChapterLinks.Add(
mangaInfo.chapterLinks.Strings[xNode^.Index]);
@ -2009,7 +2012,8 @@ begin
mangaInfo.artists,
'',
'',
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
DLManager.Items[pos].DownloadInfo.SaveTo := s;
UpdateVtDownload;
@ -2040,7 +2044,8 @@ begin
mangaInfo.artists,
'',
'',
OptionChangeUnicodeCharacter);
OptionChangeUnicodeCharacter,
OptionChangeUnicodeCharacterStr);
// downloaded chapters
s2 := '';
@ -2178,6 +2183,11 @@ begin
lbOptionAutoCheckFavIntervalMinutes.Enabled := cbOptionAutoCheckFavInterval.Checked;
end;
procedure TMainForm.cbOptionChangeUnicodeCharacterChange(Sender: TObject);
begin
edOptionChangeUnicodeCharacterStr.Enabled := cbOptionChangeUnicodeCharacter.Checked;
end;
procedure TMainForm.cbOptionDigitChapterChange(Sender: TObject);
begin
seOptionDigitChapter.Enabled := cbOptionDigitChapter.Checked;
@ -4476,6 +4486,7 @@ begin
seOptionPDFQuality.Value := ReadInteger('saveto', 'PDFQuality', 100);
rgOptionCompress.ItemIndex := ReadInteger('saveto', 'Compress', 0);
cbOptionChangeUnicodeCharacter.Checked := ReadBool('saveto', 'ChangeUnicodeCharacter', False);
edOptionChangeUnicodeCharacterStr.Text := ReadString('saveto', 'ChangeUnicodeCharacterStr', OptionChangeUnicodeCharacterStr);
cbOptionRemoveMangaNameFromChapter.Checked := ReadBool('saveto', 'RemoveMangaNameFromChapter', False);
cbOptionGenerateMangaFolder.Checked := ReadBool('saveto', 'GenerateMangaFolder', True);
edOptionMangaCustomRename.Text := ReadString('saveto', 'MangaCustomRename', DEFAULT_MANGA_CUSTOMRENAME);
@ -4605,6 +4616,7 @@ begin
edOptionDefaultPath.Text := CleanAndExpandDirectory(edOptionDefaultPath.Text);
WriteString('saveto', 'SaveTo', edOptionDefaultPath.Text);
WriteBool('saveto', 'ChangeUnicodeCharacter', cbOptionChangeUnicodeCharacter.Checked);
WriteString('saveto', 'ChangeUnicodeCharacterStr', edOptionChangeUnicodeCharacterStr.Text);
WriteBool('saveto', 'GenerateMangaFolder', cbOptionGenerateMangaFolder.Checked);
if Trim(edOptionMangaCustomRename.Text) = '' then
edOptionMangaCustomRename.Text := DEFAULT_MANGA_CUSTOMRENAME;
@ -4739,6 +4751,7 @@ begin
OptionPDFQuality := seOptionPDFQuality.Value;
DLManager.compress := rgOptionCompress.ItemIndex;
OptionChangeUnicodeCharacter := cbOptionChangeUnicodeCharacter.Checked;
OptionChangeUnicodeCharacterStr := edOptionChangeUnicodeCharacterStr.Text;
OptionRemoveMangaNameFromChapter := cbOptionRemoveMangaNameFromChapter.Checked;
OptionGenerateMangaFolder := cbOptionGenerateMangaFolder.Checked;
OptionMangaCustomRename := edOptionMangaCustomRename.Text;

View File

@ -586,9 +586,14 @@ msgid "Auto check for latest version "
msgstr "Auto check for latest version "
#: tmainform.cboptionchangeunicodecharacter.caption
#| msgid "Change all all character to"
msgctxt "tmainform.cboptionchangeunicodecharacter.caption"
msgid "Change all all unicode symbols to \"_\" (choose this when you have problem with unicode path)"
msgstr "Change all all unicode symbols to \"_\" (choose this when you have problem with unicode path)"
msgid "Replace all unicode character with"
msgstr "Replace all unicode character with"
#: tmainform.cboptionchangeunicodecharacter.hint
msgid "Enable this if you have problem with unicode character in path."
msgstr "Enable this if you have problem with unicode character in path."
#: tmainform.cboptiondigitchapter.caption
msgid "Chapter"
@ -2159,4 +2164,3 @@ msgstr "Synchronizing data"
#: uupdatethread.rs_updatinglist
msgid "Updating list"
msgstr "Updating list"

View File

@ -576,8 +576,12 @@ msgstr "Otomatis periksa versi terbaru"
#: tmainform.cboptionchangeunicodecharacter.caption
msgctxt "tmainform.cboptionchangeunicodecharacter.caption"
msgid "Change all all unicode symbols to \"_\" (choose this when you have problem with unicode path)"
msgstr "Ubah semua simbol unicode menjadi \"_\" (pilih ini ketika Anda memiliki masalah dengan lokasi unicode)"
msgid "Replace all unicode character with"
msgstr "Ubah semua simbol unicode menjadi"
#: tmainform.cboptionchangeunicodecharacter.hint
msgid "Enable this if you have problem with unicode character in path."
msgstr "Aktifkan pilihan ini jika anda mengalami masalah dengan karakter unicode pada path."
#: tmainform.cboptiondigitchapter.caption
msgid "Chapter"
@ -2140,4 +2144,3 @@ msgstr "Sinkronisasi data"
#: uupdatethread.rs_updatinglist
msgid "Updating list"
msgstr "Memperbarui daftar"

View File

@ -541,7 +541,11 @@ msgstr ""
#: tmainform.cboptionchangeunicodecharacter.caption
msgctxt "TMAINFORM.CBOPTIONCHANGEUNICODECHARACTER.CAPTION"
msgid "Change all all unicode symbols to \"_\" (choose this when you have problem with unicode path)"
msgid "Replace all unicode character with"
msgstr ""
#: tmainform.cboptionchangeunicodecharacter.hint
msgid "Enable this if you have problem with unicode character in path."
msgstr ""
#: tmainform.cboptiondigitchapter.caption