@@ -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);
53775380end ;
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
53795417function TMainForm.CheckLongNamePaths (APath: String): String;
53805418begin
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 ;
53905428end ;
53915429
53925430function 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