Skip to content

Commit b2dc107

Browse files
committed
Changed: Long paths to truncate at hard limit of 255 per folder/file
1 parent e1e5e7a commit b2dc107

4 files changed

Lines changed: 76 additions & 12 deletions

File tree

baseunits/FMDOptions.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ interface
103103
OptionLetFMDDo: TFMDDo = DO_NOTHING;
104104
OptionDeleteCompletedTasksOnClose: Boolean = False;
105105
OptionSortDownloadsOnNewTasks: Boolean = False;
106+
OptionLongNamePaths: Boolean = False;
106107

107108
// saveto
108109
OptionChangeUnicodeCharacter: Boolean = False;

baseunits/uBaseUnit.pas

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ function CorrectPathSys(const Path: String): String;
14621462
if Length(s) > MAX_PATHDIR then
14631463
begin
14641464
s := MainForm.CheckLongNamePaths(s);
1465-
if not MainForm.cbOptionEnableLongNamePaths.Checked then
1465+
if not OptionLongNamePaths then
14661466
begin
14671467
SetLength(s, MAX_PATHDIR);
14681468
end;
@@ -1793,41 +1793,59 @@ function CustomRename(const AString, AWebsite, AMangaName, AAuthor, AArtist, ACh
17931793
Result := AString;
17941794

17951795
// for rename chapter only
1796-
if AChapter <> '' then begin
1796+
if AChapter <> '' then
1797+
begin
17971798
// numbering/index
17981799
if (Pos(CR_NUMBERING, Result) = 0) and (Pos(CR_CHAPTER, Result) = 0) then
1800+
begin
17991801
Result := ANumbering + Result;
1802+
end;
18001803
Result := StringReplaceBrackets(Result, CR_NUMBERING, ANumbering, [rfReplaceAll]);
18011804

18021805
// pad number
18031806
fchapter := Trim(AChapter);
18041807
if OptionConvertDigitVolume then
18051808
begin
18061809
if OptionConvertDigitChapter then
1807-
VolumeChapterPadZero(fchapter, OptionConvertDigitVolumeLength, OptionConvertDigitChapterLength)
1810+
begin
1811+
VolumeChapterPadZero(fchapter, OptionConvertDigitVolumeLength, OptionConvertDigitChapterLength);
1812+
end
18081813
else
1814+
begin
18091815
VolumeChapterPadZero(fchapter, OptionConvertDigitVolumeLength, 0);
1816+
end;
18101817
end
1811-
else
1812-
if OptionConvertDigitChapter then
1818+
else if OptionConvertDigitChapter then
1819+
begin
18131820
VolumeChapterPadZero(fchapter, 0, OptionConvertDigitChapterLength);
1821+
end;
18141822

18151823
fchapter := FixStringLocal(fchapter);
18161824

18171825
Result := StringReplaceBrackets(Result, CR_CHAPTER, fchapter, [rfReplaceAll]);
18181826

18191827
if Result = '' then
1828+
begin
18201829
Result := ANumbering;
1830+
end;
18211831
end;
18221832

18231833
Result := StringReplaceBrackets(Result, CR_WEBSITE, FixStringLocal(AWebsite), [rfReplaceAll]);
18241834
Result := StringReplaceBrackets(Result, CR_MANGA, FixStringLocal(AMangaName), [rfReplaceAll]);
18251835
Result := StringReplaceBrackets(Result, CR_AUTHOR, FixStringLocal(AAuthor), [rfReplaceAll]);
18261836
Result := StringReplaceBrackets(Result, CR_ARTIST, FixStringLocal(AArtist), [rfReplaceAll]);
18271837
Result := StringReplaceBrackets(Result, CR_FILENAME, FixStringLocal(AFileName), [rfReplaceAll]);
1828-
if Result = '' then Result := FixStringLocal(AMangaName);
1838+
if Result = '' then
1839+
begin
1840+
Result := FixStringLocal(AMangaName);
1841+
end;
18291842

1830-
if Result = '' then Exit;
1843+
if Result = '' then
1844+
begin
1845+
Exit;
1846+
end;
1847+
1848+
Result := MainForm.CheckSingularCharacterLimit(Result);
18311849

18321850
// remove pathdelim
18331851
Result := TrimChar(Result, AllowDirectorySeparators);

baseunits/uDownloadsManager.pas

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,15 @@ function TTaskThread.GetFileName(const AWorkId: Integer): String;
536536
Result := '';
537537
if (Container.FileNames.Count = Container.PageLinks.Count) and
538538
(AWorkId < Container.FileNames.Count) then
539+
begin
539540
Result := Container.FileNames[AWorkId];
541+
end;
542+
540543
if Result = '' then
544+
begin
541545
Result := Format('%.3d', [AWorkId + 1]);
546+
end;
547+
542548
Result := StringReplace(CurrentCustomFileName, CR_FILENAME, Result, [rfReplaceAll]);
543549
{$IFDEF WINDOWS}
544550
s := UTF8Decode(Result);
@@ -766,7 +772,7 @@ procedure TTaskThread.SetCurrentWorkingDir(AValue: String);
766772
{$IFDEF Windows}
767773
s := UTF8Decode(FCurrentWorkingDir);
768774

769-
if MainForm.cbOptionEnableLongNamePaths.Checked then
775+
if OptionLongNamePaths then
770776
begin
771777
FCurrentMaxFileNameLength := FMDMaxImageFilePath + Length(s);
772778
end

mangadownloader/forms/frmMain.pas

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface
2121
ExtCtrls, ComCtrls, Buttons, Spin, Menus, VirtualTrees, RichMemo, simpleipc, process,
2222
lclproc, types, LCLIntf, EditBtn, GroupedEdit, PairSplitter, MultiLog,
2323
FileChannel, FileUtil, LazStringUtils, TAGraph, TASources, TASeries, TATools,
24-
AnimatedGif, uBaseUnit, uDownloadsManager, uFavoritesManager,
24+
AnimatedGif, uBaseUnit, uDownloadsManager, uFavoritesManager, StrUtils,
2525
uSilentThread, uMisc, uGetMangaInfosThread, frmDropTarget, frmAccountManager,
2626
frmAccountSet, frmWebsiteOptionCustom, frmCustomColor, frmLogger, frmTransferFavorites,
2727
frmLuaModulesUpdater, CheckUpdate, DBDataProcess, uDarkStyleParams, uWin32WidgetSetDark,
@@ -773,6 +773,9 @@ TMainForm = class(TForm)
773773

774774
procedure AddChapterNameToList;
775775

776+
// Check and trim to max 255 character limit per folder/file
777+
function CheckSingularCharacterLimit(APath: String; ALimit: Integer = 255): String;
778+
776779
// Check and set path for long path compatibilty
777780
function CheckLongNamePaths(APath: String): String;
778781

@@ -5375,18 +5378,53 @@ procedure TMainForm.AddSilentThread(URL: string);
53755378

53765379
AddSilentThread(URL, mt);
53775380
end;
5381+
5382+
function TMainForm.CheckSingularCharacterLimit(APath: String; ALimit: Integer = 255): String;
5383+
var
5384+
TruncLength: Integer;
5385+
FileNamePos: Integer = 0;
5386+
HasFileName: Boolean = False;
5387+
CharsToTrim: Set of Char;
5388+
begin
5389+
ALimit := Min(Alimit, 255);
5390+
CharsToTrim := [' ', '.'];
5391+
HasFileName := APath.Contains(CR_FILENAME);
5392+
5393+
if HasFileName then
5394+
begin
5395+
FileNamePos := Pos(CR_FILENAME, APath);
5396+
ALimit := ALimit - 3 - 5;
5397+
end;
5398+
5399+
if Length(APath) >= ALimit then
5400+
begin
5401+
TruncLength := LastDelimiter(' ', Copy(APath, 1, ALimit));
5402+
APath := Copy(APath, 1, TruncLength);
5403+
APath := TrimRightSet(APath, CharsToTrim);
5404+
end;
5405+
5406+
if HasFileName then
5407+
begin
5408+
if FileNamePos > Alimit then
5409+
begin
5410+
APath := APath + CR_FILENAME;
5411+
end;
5412+
end;
5413+
5414+
Result := APath;
5415+
end;
53785416

53795417
function TMainForm.CheckLongNamePaths(APath: String): String;
53805418
begin
5381-
if cbOptionEnableLongNamePaths.Checked then
5419+
if OptionLongNamePaths then
53825420
begin
53835421
if Pos('\\?\', APath) = 0 then
53845422
begin
53855423
APath := '\\?\' + APath;
53865424
end;
5387-
end;
53885425

5389-
Result := APath;
5426+
Result := APath;
5427+
end;
53905428
end;
53915429

53925430
function TMainForm.TrimPath(APath: String): String;
@@ -6136,6 +6174,7 @@ procedure TMainForm.ApplyOptions;
61366174
OptionEnableLoadCover := cbOptionEnableLoadCover.Checked;
61376175
OptionDeleteCompletedTasksOnClose := cbOptionDeleteCompletedTasksOnClose.Checked;
61386176
OptionSortDownloadsOnNewTasks := cbOptionSortDownloadsOnNewTasks.Checked;
6177+
OptionLongNamePaths := cbOptionEnableLongNamePaths.Checked;
61396178
DLManager.DB.AutoVacuum:=cbOptionVacuumDatabasesOnExit.Checked;
61406179
FavoriteManager.DB.AutoVacuum:=cbOptionVacuumDatabasesOnExit.Checked;
61416180

0 commit comments

Comments
 (0)