Seamly2D icon indicating copy to clipboard operation
Seamly2D copied to clipboard

BUG: Converting to latest file format creates poorly named backup file

Open slspencer opened this issue 4 years ago • 2 comments

When saving a pattern file from an old file format to the current file format, the original file is saved as a backup file with a user unfriendly filename. The name can be simplified, and the .bak extension isn't necessary.

When the backup file is opened and saved to the current file format, the file naming is complicated.

Steps to replicate:

Example: myPattern.val has v0.6.0 file format

Case 1: Open a file with old file format

  1. Open myPattern.val & save to new v0.6.1 file format
  2. Two files have been saved:
    • myPattern.val - new v0.6.1 file
    • myPattern(v0.6.0).val.bak - backup of original v0.6.0 file

Case 2: Open a backup file with old file format

  1. Open myPattern(v0.6.0).val.bak from Case 1 & save to v0.6.1 file format
  2. Two files have been saved:
    • myPattern(v0.6.0).val - new v0.6.1 file. The filename incorrectly indicates that it has file format v0.6.0
    • myPattern(v0(v0.6.0).6.0).val.bak - backup of original v0.6.0 file. Nested file format info is hard to read

Desired behavior:

Case 1:

  1. The two saved files will be named like this:
    • myPattern.val - new v0.6.1 file
    • myPattern_v060.val - original v0.6.0 file. Switching to the simple file format suffix _vXXX and dropping the .bak file will solve for both Case 1 & Case 2

Case 2:

  1. The two saved files will be named like this:
    • myPattern.val - new v0.6.1 file. If there is a current myPattern.val file, the local operating system will prompt the user if they want to rename this file or overwrite the current file.
    • myPattern_v060.val - original v0.6.0 file.

slspencer avatar Jan 19 '21 23:01 slspencer

Gets even worse if you associate .bak to Seamly2D and open the backup a 2nd time.

MaleShirt(v0(v0.4.0).4.0).val.bak.bak

MaleShirt(v0(v0(v0.4.0).4.0).4.0).val.bak.bak.bak

That being said the fix is pretty simple... If we (re)name the backup file filename_ver#.val, will have to search the basename string for the "_v" and truncate anything after that to strip the "_v#" out of an exiting basename so you don't end up with filename_ver#_ver#.val.

DSCaskey avatar Aug 05 '21 18:08 DSCaskey

Ok... I got the renaming of a backup file to work the first time around. Problem exists when trying to open a backup file. For example if you try to open maleshirt_v040.val, a lock is placed on the file, therefore you can't save a backup file with the same name... with the new version being maleshirt.val. Would have to version the backup file name such as maleshirt_v040.val, maleshirt_v040(1).val, maleshirt_v040(2).val, etc. AND / OR throw up a file dialog to save the backup "as".

Would also need to check the filename in the save() method if "_v###" exists to remove that when opening a backup file to save as just filename.val OR just leave the new version file named as the backup file just opened? That being said... either is a moot point currently as when you convert a file it does not change the state of the file as to having been modified, enabling the "File->Save"... so there would be no auto naming of the new converted file.

So what started as changing a few lines now turns into more code.

Could also get a bit more messy as there's a temp file in there with a conversion.

DSCaskey avatar Aug 05 '21 19:08 DSCaskey