klembot / twinejs

Twine, a tool for telling interactive, nonlinear stories
https://twinery.org
GNU General Public License v3.0
2k stars 295 forks source link

Random duplicates that contains various versions #628

Closed ANLCG closed 2 years ago

ANLCG commented 4 years ago

There's a bug that create duplicates of the same story; however, the duplicates have different progress on them. Whenever I try to edit a story, some of it is saved, and it is distributed between the duplicates. There is no one copy that holds all of my changes.

Twine version: 2.3.5

Screen Shot 2019-11-27 at 1 47 06 PM

HiEv commented 4 years ago

Just curious, but did this problem start after attempting to rename a story? If so, it may be related to bug #615 "Random errors and story duplication when renaming a story".

ANLCG commented 4 years ago

I didn't rename the story, but I would save the published version under a different name. I've done it before, but nothing happened until now..It was very weird because the duplications seemingly popped out of nowhere.

greyelf commented 4 years ago

but I would save the published version under a different name.

Did you then import one of these other named publish versions?

info: Each new project created by the Twine 2.x application is assigned a unique IFID, this along with the project's name is embedded within any story HTML file you generate using that project. This IFID needs to be unique across all Twine related projects, whether they are created by you or some other person.

warnings: a. Publishing (saving) an existing project under a different file-name does not result in the generated story HTML containing a reference to a different IFID than the Twine 2.x project's, nor does it alter the embedded (project) Name. b. The Import From File option of the Twine 2.x application uses the (project) Name embedded within the story HTML file to determine the name of the Twine 2.x project being added/updated.

ANLCG commented 4 years ago

I did but the duplication happened to the original file before I imported any archived or published files.

I needed to import/upload an archived because when I tried to delete one duplicate, it ended up deleting the original file and the other duplicates.

ANLCG commented 4 years ago

I've also found that when I close Twine, all my progress from that session is gone. I have to constantly archive and publish my changes so I can import them the next time I go to work on it.

greyelf commented 4 years ago

@ANLCG note: You haven't stated this yet but I will assume that you are using the Desktop release of the application.

Which Operating System (brand, version, edition, 32/64 bit) are you using?

Have you change the system configuration of that OS to store its "Documents" somewhere other that its default location?

ANLCG commented 4 years ago

I am using the desktop version.

I have MacOS Catalina (version 10.15) and I think it's 64 bit.

I don't think I have changed the OS, but I changed where Twine stores and saves files. I see now on my computer there are two versions of some of my files -- in the folder I directed Twine to save my project's archives and published stories to, and the default Twine folder in my "documents" that has two folders in it, "backups," and "stories".

olszewski commented 4 years ago

I've also found that when I close Twine, all my progress from that session is gone. I have to constantly archive and publish my changes so I can import them the next time I go to work on it.

Same damn issue, I had done about 2 hours of work in the program and suddenly a boolan that was false and even said it was false in debug be would not work when trying to test it with {(if: $Joke is false) [False] (else: ) [True]}

It would always display true no matter what when testing... After retyping and even using premade line of code and modifying I eventually decided to restart the program and found all new data was lost.

Luckily I grabbed a html file from testing in my browser's history that I ran from the beginning of the script BUT Twine refuses to open it saying that the project already exist and any attempts to delete the half file or rename it results in saying it can't be done ("ENOENT: no such file or directory, rename")

The file is still there it can be opened but cannot be renamed, or deleted using the program and the program will not open the html file I have because of it...

HiEv commented 4 years ago

Looking into the Twine source a bit, the problem most likely stems from the "hydrate" object not staying synced with what files should and shouldn't be there when a file is deleted or renamed. Thus you can end up with duplicates in the "hydrate" object, and no way to get rid of them.

I'm guessing that a duplicate copy of a story gets added to the "hydrate" object, and then it only ever allows you to delete one, and then re-creates the deleted duplicate upon restarting, thus the duplicates can only increase, but never decrease. That's just a guess based on what parts I saw though, since I didn't trace very far into the code to verify that.

Unfortunately, I'm not sure where the "hydrate" data is stored, so I don't know a workaround to fix this. I've verified that it's not a part of the "C:\Users\YourUsername\AppData\Roaming\Twine*.*" data, or at least it's not only there, since deleting that doesn't clear the "hydrate" object.

If anyone knows where Twine/Electron stores that data, please let me know.

BeeFox-sys commented 4 years ago

Can confirm that this bug is happening. Using desktop app on windows 10 version 10.0.18362 Build 18362, 64 bit. Twine version 2.3.5 image I am just glad I keep tabs open and have been able to save the tab to keep my projects from loosing progress. Importing them again temporarily fixes the problem, but then it returns soon after, deleting any new imports. They also seem to share the same internal ID, as if you import a project that replaces it, it shows two (or more if there are more then two duplicates) projects to replace, but checking either one will check the other image Uninstalling and reinstalling twine does not fix this problem Clearing local storage did not fix this problem Removing stories and backups from the twine directory did not fix this problem. I hope it can be fixed soon as it heavily hinders development

BeeFox-sys commented 4 years ago

Found the storage location! Deleting C:\Users\USER\AppData\Local\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\LocalState\AppIconCache\150\com_electron_twine will remove all the duplicated files! I can't be sure if that directory is correct for all computers, as it looks like Microsoft.Windows.Cortana_cw5n1h2txyewy is generated per computer (That's a guess it may not be) Edit: It still seems to have the issue of not saving work or changes, however that's at least one half of the problem down Edit Edit: It seems that the duplicates still exist, but they are just no longer displaying. Overwriting a file through import will still result in the duplicated checkboxes as seen in my previous image

HiEv commented 4 years ago

Found the storage location! Deleting C:\Users\USER\AppData\Local\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\LocalState\AppIconCache\150\com_electron_twine will remove all the duplicated files! I can't be sure if that directory is correct for all computers, as it looks like Microsoft.Windows.Cortana_cw5n1h2txyewy is generated per computer (That's a guess it may not be)

FYI, Microsoft.Windows.Cortana_cw5n1h2txyewy is a standard name used for Cortana files. That's why it would't have anything to do with storing the info that's related to this. So, you shouldn't leap to deleting anything from there.

HiEv commented 4 years ago

How to fix "undeletable" duplicate stories in Twine v2.3.0 - v2.3.5

These steps are for Windows only. You will likely need to modify these steps for other OSes.

NOTE: This fix is a sledgehammer, not a scalpel, so make sure you follow all steps regarding making backups.

IMPORTANT!!!: Follow all steps carefully!!!

1.) Download this file: https://qjzhvmqlzvoo5lqnrvuhmg-on.drv.tw/TwineDupeFix.zip

2.) While that's downloading, open Twine.

3.) Create an archive of your stories (using the "Archive" button on the right), and put that HTML archive file somewhere where you can find it in case you need it later (and NOT in any of the Twine directories).

4.) Then create ANOTHER backup, and call it "Fixed_Twine_Archive.html".

5.) Close Twine.

6.) Open that "Fixed_Twine_Archive.html" file in a decent text editor (such as Notepad++).

7.) Delete any stories which shouldn't be there. They'll be in the format:

<tw-storydata name="Story name" ...
...
</tw-storydata>

8.) Once you've deleted all duplicate stories, save the "Fixed_Twine_Archive.html" file and close the text editor.

9.) Go to your "My Documents" directory and delete the "Twine" subdirectory there.

10.) Go to your "C:\Users\YourUserName\AppData\Roaming\Twine" directory and delete all of the subdirectories there. (There should only be files named "Preferences", "prefs.json", and "story-formats.json" remaining.)

11.) Go to your "Program Files\Twine\Resources" directory (or whatever you called it) and rename "app.asar" as "app.bak.asar". (If it asks for administrator privileges, let it continue with those privileges.)

12.) Open the "TwineDupeFix.zip" you downloaded, and extract the "app.asar" file somewhere.

13.) Move that "app.asar" file to your "Program Files\Twine\Resources" directory. (Again, this will probably require administrator privileges.)

14.) Open Twine. After a moment it should show you that there are zero stories.

15.) Close Twine.

16.) Go back to your "Program Files\Twine\Resources" directory and rename "app.asar" as "app.fixer.asar".

17.) Then rename "app.bak.asar" as "app.asar".

18.) Open Twine. After a moment it should show you that there are zero stories still.

19.) Choose "Import From File" and open the "Fixed_Twine_Archive.html" file. This should restore your stories.

20.) Close Twine.

21.) Open Twine. And Twine should be back to normal! B-)

NOTE: If you have any trouble playing or publishing your files after doing this...

  1. Make sure that the starting passage is set in the story. If it's not, hover your mouse over the starting passage, click the "..." and then tick the check mark next to "Start Story Here".
  2. Make sure that the story format is set. From the bottom menu choose "Change Story Format" and set the story format for that story.

Hope that helps! :-)

ANLCG commented 4 years ago

Is the "Program Files\Twine\Resources" directory (or whatever you called it)" where you put the twine archive and the Fixed_Twine_Archive.html?

Also can that directory be in an already existing twine folder that was created by me and not the application itself?

greyelf commented 4 years ago

Also can that directory be in an already existing twine folder that was created by me and not the application itself?

If you are asking if it is possible to configure the GUI application to use an end-user selected custom folder (other than that automatically created by the application) as the location for the project (and backup) HTML files the application generates, then the answer is No.

The application has been hard-wired to use specific Operating System (brand & version) dependent locations on the end-user's machine.

HiEv commented 4 years ago

Is the "Program Files\Twine\Resources" directory (or whatever you called it)" where you put the twine archive and the Fixed_Twine_Archive.html?

It pretty much doesn't matter where you put those two files, as long as you can find them later.

Also can that directory be in an already existing twine folder that was created by me and not the application itself?

If you mean the directory where you save those two files, then yes, you can save them pretty much anywhere. If you mean the directory where your "app.asar" files go, then no.

klembot commented 4 years ago

Twine in general right now doesn't cope well with mismatches between filenames and story names. I know that duplicates can also occur sometimes when renaming a story inside Twine. @HiEv could you go into more detail on what your steps are trying to fix? I don't 100% grasp the intent from the instructions.

HiEv commented 4 years ago

The problem was that, as the title of my post said, you could end up with undeletable duplicate stories in Twine.

You could delete the game from Twine, close Twine, delete the contents of the "C:\Users\YourUserName\AppData\Roaming\Twine" directory, the "My Documents\Twine" directory, and when you re-opened Twine, the story would be back again. If you just deleted it, closed and re-opened Twine, then sometimes it would even appear twice on the main screen.

The only way to fix it was the hack above, where I kept Twine from being able restore the backup from anything, including the "hydrate" object, and then repopulating the stories from scratch using the archive. My "hacked" version of "app.asar" ignores the existing "hydrate" object data, and returns an empty object instead.

The problem is that the data gets "stuck" in the "hydrate" object, and there's no way to remove it. As I stated above, I'm guessing that multiple copies of some stories end up in the "hydrate" object somehow, and after you remove one of them, there's no way to remove the rest, so one always comes back, which then gets repopulated in the "hydrate" object.

Basically, you need to make sure that all copies get removed from the "hydrate" object when one of them is deleted by the user. Better yet, turn any duplicates into separate stories, so the right one(s) can be deleted. Even better yet, figure out how duplicate copies get added, and prevent that.

This is a serious bug, since it can leave you with unusable, un-updatable, and undeletable duplicate copies of a story in Twine (a fact which may take a while for you to notice) and it's incredibly hard to fix (see the efforts I had to go through above).

I've had it happen with one test story I named "00x" and another named "0xx", so it may be related to starting with a number. It also looks like the bug may require that you trigger an error message in some way, so I'd start looking there. However, it happens very rarely, so it may also involve some sort of periodic backup or something too.

I've fixed my copy of Twine, so I can't give much more detail than that.

ANLCG commented 4 years ago

How to fix "undeletable" duplicate stories in Twine v2.3.0 - v2.3.5

These steps are for Windows only. You will likely need to modify these steps for other OSes.

Mac user here. The steps seemed simple enough but I'm already stuck on step 6. I don't seem to get any duplicate stories showing up in the text editor. Making the archives was easy enough and I just saved them to my desktop. I'm really new to all of this, so I'm not sure what I should be doing and I don't want to accidentally mess up my Twine files forever. Do you know what I need to do as a Mac user?

HiEv commented 4 years ago

Mac user here. The steps seemed simple enough but I'm already stuck on step 6. I don't seem to get any duplicate stories showing up in the text editor.

The step just says, "Delete any stories which shouldn't be there." If there aren't any duplicates and you want to keep the one copy of the story that's there, then it's fine as it is since there aren't any that shouldn't be there.

I'm really new to all of this, so I'm not sure what I should be doing and I don't want to accidentally mess up my Twine files forever.

As long as you have the archive, you'll be fine. Worst case scenario, you'll have to uninstall and then reinstall Twine, and then import that archive file.

That said, I'm assuming the "app.asar" file is the same for all OSes, but I'm not 100% certain of that. However, as long as you keep the original version, you'll be fine, since you can revert back to that if this version doesn't work.

The main step, archiving all of your stories, is the important one, and it sounds like you did that already.

Do you know what I need to do as a Mac user?

Unfortunately, no, I'm not a Mac user. That said, it should be similar enough to the steps I gave for Windows that you should probably be able to figure it out.

Please let us know what you do find out and how it works, in case any other Mac users encounter this bug and need to fix it.

Thanks!

HiEv commented 4 years ago

Here's another report of this problem and some details about what they do that causes the problem.

klembot commented 4 years ago

I appreciate the discussion here, especially the workarounds.

I'm not sure hydrate is the culprit. The purpose of it is to keep individual Twine windows in sync, as they are different Electron browser instances (this was much more needed when Twine previewed stories in-app ... this will likely get dropped in 2.4.0). hydrate shouldn't be persisted, but it is possible that it is being persisted in a way I don't understand.

HiEv commented 4 years ago

Well, clearing out hydrate is what fixes the duplicates, so it's at least related.

If it helps, the "fix" I posted to clear it out just adds:

window.twineElectron.hydrate.initialStoryData = [];

just before the:

ipcRenderer.send('setHydrate', window.twineElectron.hydrate);

line in src/electron/preload.js.

klembot commented 2 years ago

This looks like a bug with Twine 2.3 or earlier, and because of that I'm closing it. Please re-open or create a new issue if you find this is still a problem in 2.4.