Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 04-06-2024, 08:49 AM   #1
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Feature Request - Enable Case-Sensitive Renaming

Let's say an epub has a file called Cover.xhtml.

I wish to rename it to cover.xhtml, but Sigil tells me that the name is already in use.

I get the same error message when trying to change the case of an image name.
e.g. change CH01FIG01.jpg to ch01fig01.jpg

As a workaround, I can rename the file something like Covera.xhtml and then rename again to cover.xhtml, but it would be nice to avoid this additional step.

I understand the current behaviour is by design, to allow for Windows being case-insensitive, but I'm pretty sure even on Windows it's possible to change the case of a file but keep the same name.

Last edited by KarlG; 04-06-2024 at 08:57 AM.
KarlG is offline   Reply With Quote
Old 04-06-2024, 09:33 AM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
See https://answers.microsoft.com/en-us/...e-799ca90d4e58

And macOS too by default is case insensitive (but case preserving).

You simply can not have two case-only variants of a file name in the same folder at the same time on macOS and Windows.

And reusing the same file name more than once using case variants is going to cause trouble on many e-readers as well.

Sticking to fully unique filenames no matter the case is a good design idea for epub developers who want their epub to work with the largest number of e-readers.

The other point is that epub internal file names just do not matter as they are not seen by readers.

So use Regex Rename/Rename to give each file a short, unique, direct file name that either indicates its sequence or function or both.

With RegexRename you can block add an initial char to a number of files in one step. The repeat to remove it and change case.

This works on all platforms.

Last edited by KevinH; 04-06-2024 at 09:48 AM.
KevinH is online now   Reply With Quote
Advert
Old 04-06-2024, 09:47 AM   #3
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
I think there's a slight misunderstanding here. I don't mean having two files with the same name but different case, but the ability to RENAME a file using a different case but the same name.
KarlG is offline   Reply With Quote
Old 04-06-2024, 09:51 AM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
Renaming a file can not be done if the new name already exists (in a case insensitive manner). Think unix mv -i but on a case insensitive file system.

That is the issue. It sees the new name of the file as already existing and will not do the rename (to prevent ending up with effectively two files with the same name or overwriting a file inadvertently.

Last edited by KevinH; 04-06-2024 at 09:55 AM.
KevinH is online now   Reply With Quote
Old 04-06-2024, 09:54 AM   #5
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Ok, what about renaming to a temporary, random name and then to the new name?
KarlG is offline   Reply With Quote
Advert
Old 04-06-2024, 09:59 AM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
So just add a char and then rename it to what you want, just like macOS and Windows users have to. Sigil will not be doing that for you as detecting file system types (case sensitive vs case insensitive vs case preserving) is a pain and fraught with issues when users add different filesystems (easily done on macOS).

It can be easily done for a single file (using rename) or multiple files using RegexRename.
KevinH is online now   Reply With Quote
Old 04-06-2024, 10:02 AM   #7
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by KarlG View Post
Ok, what about renaming to a temporary, random name and then to the new name?
To save you a single step? You handle it as it makes you aware of case insensitive issues. Most people do not worry about file names unless they are horridly long. Changing just case is not needed as actual epub users never see it.

Use Renumbering rename patterns with xhtml files (or the bulk of them). Use Rename if only a handful of files or RegexRename if larger numbers of files.

Last edited by KevinH; 04-06-2024 at 10:06 AM.
KevinH is online now   Reply With Quote
Old 04-06-2024, 10:02 AM   #8
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by KevinH View Post
To save you a single step? You handle it as it makes you aware of case insensitive issues. Most people do not worry about file names unless they are horridly long. Changing just case is not needed as actual epub users never see it.

Use Rename if only a handful of files or RegexRename if larger numbers of files.
Well yes, it's something I do quite a lot and I didn't think it would be an issue to implement this in Sigil. Could you point me in the direction of the code to rename files pls. I'll have a go at implementing something myself locally.

Last edited by KarlG; 04-06-2024 at 10:06 AM.
KarlG is offline   Reply With Quote
Old 04-06-2024, 10:09 AM   #9
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
Why do you do it a lot and not just renumber xhtml files or use RegexRename or regular rename?

The renaming code is in BookBrowser.cpp, OPFModel.cpp, and in FolderKeeper.cpp, and probably needed for the Move code as well. File-renaming is done in a lot of places throughout the Sigil codebase.
KevinH is online now   Reply With Quote
Old 04-06-2024, 10:14 AM   #10
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by KevinH View Post
Why do you do it a lot and not just renumber xhtml files or use RegexRename or regular rename?

The renaming code is in BookBrowser.cpp, OPFModel.cpp, and in FolderKeeper.cpp, and probably needed for the Move code as well.
Thanks. Don't know really, I just prefer it if the files are named the way I like (eg ch01, ch02 etc etc...). TBH, I never thought about using RegexRename for a single file, I've always just pressed F2 (I know that's not the standard Sigil shortcut for rename, but it seems to be standard most other places, so I changed the shortcut in Sigil) and rename the file there, and that's when I have the issue of not being able to change the case with the same name.
KarlG is offline   Reply With Quote
Old 04-06-2024, 10:15 AM   #11
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Unless I've misunderstood, it was the regular rename that I was asking to be changed, because renaming to the same name with a different case shows the message that the filename is already in use.
KarlG is offline   Reply With Quote
Old 04-06-2024, 01:46 PM   #12
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
RegexRename is for multiple file renames at once.

Since you are on Linux that is case-sensitive, look for the routine (BookBrowser.cpp) that does case insensitive file name checking for duplicates and just change it to be case sensitive. That might work since the Linux filesystem deals with case differences.
KevinH is online now   Reply With Quote
Old 04-06-2024, 05:24 PM   #13
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
Okay, I took a look at qtbase dev branch and there is code in the latest qfile.cpp rename() code that was added after Sigil was created, sometime during Qt5 that will attempt a file rename if the destination exists but is the exact same file (ie. case change only).

Now that Sigil uses Qt6, we should be able to re-examine if we can allow case only changes.
KevinH is online now   Reply With Quote
Old 04-06-2024, 05:31 PM   #14
KarlG
Enthusiast
KarlG began at the beginning.
 
Posts: 43
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by KevinH View Post
Okay, I took a look at qtbase dev branch and there is code in the latest qfile.cpp rename() code that was added after Sigil was created, sometime during Qt5 that will attempt a file rename if the destination exists but is the exact same file (ie. case change only).

Now that Sigil uses Qt6, we should be able to re-examine if we can allow case only changes.
Great - and presumably Qt will take care of all platform-specific issues.
KarlG is offline   Reply With Quote
Old 04-06-2024, 07:48 PM   #15
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,675
Karma: 5433388
Join Date: Nov 2009
Device: many
If anyone is building their own Sigil on Windows and or Linux, I would love to have the following patch applied to the latest Sigil source, built, and tested.

Code:
diff --git a/src/MainUI/OPFModel.cpp b/src/MainUI/OPFModel.cpp
index 3e9e7715f..7bbb8a95a 100644
--- a/src/MainUI/OPFModel.cpp
+++ b/src/MainUI/OPFModel.cpp
@@ -741,6 +741,7 @@ void OPFModel::SortHTMLFilesByAlphanumeric(QList <QModelIndex> index_list)
 
 bool OPFModel::FilenameIsValid(const QString &old_bookpath, const QString &new_filename)
 {
+    QString FullPathToMainFolder = m_Book->GetFolderKeeper()->GetFullPathToMainFolder();
     foreach(QChar character, new_filename) {
         if (FORBIDDEN_FILENAME_CHARS.contains(character)) {
             Utility::DisplayStdErrorDialog(
@@ -766,9 +767,14 @@ bool OPFModel::FilenameIsValid(const QString &old_bookpath, const QString &new_f
     QString proposed_bookpath = sdir.isEmpty() ? new_filename : sdir + "/" + new_filename;
     const QStringList existing_bookpaths = m_Book->GetFolderKeeper()->GetAllBookPaths();
     if (existing_bookpaths.contains(proposed_bookpath, Qt::CaseInsensitive)) {
-        Utility::DisplayStdErrorDialog(
-            tr("The filename \"%1\" is already in use.\n").arg(new_filename));
-        return false;
+        QString orig_full_path = FullPathToMainFolder + "/" + old_bookpath;
+        QString proposed_full_path = FullPathToMainFolder + "/" + proposed_bookpath;
+        // if different files
+        if (QFileInfo(orig_full_path) != QFileInfo(proposed_full_path)) {
+            Utility::DisplayStdErrorDialog(
+                tr("The filename \"%1\" is already in use.\n").arg(new_filename));
+            return false;
+        }
     }
     return true;
 }


To test after rebuilding, just open Sigil and right click in BookBrowser on Section0001.xhtml and try renaming it to:

secTioN0001.xhtml

And let me know if it succeeds and if the OPF is properly updated.

This appears to work on macOS but really needs to be tested on Windows and Linux.

I am sure there are similar things that still have to be tracked down and changed for that to work with Move (and Restructure to Sigil Norm) but if this works, it will be a good first step.

Thanks
KevinH is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
case-sensitive search ? Jacques Q. Library Management 1 04-02-2024 05:15 PM
Case sensitive sort Karellen Editor 2 03-14-2023 07:09 PM
[Feature Request] - Enable wikipedia after the BBB filter is enabled. Lenorav Kindle Developer's Corner 2 11-12-2014 03:02 AM
Case-sensitive search john_es Calibre 1 02-18-2014 12:25 AM
K3 search case sensitive only? charonme Amazon Kindle 1 01-28-2011 05:15 PM


All times are GMT -4. The time now is 11:23 AM.


MobileRead.com is a privately owned, operated and funded community.