Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File System Access API #1594

Draft
wants to merge 68 commits into
base: master
Choose a base branch
from

Conversation

RockyTheProtogen
Copy link

@RockyTheProtogen RockyTheProtogen commented Jul 7, 2024

Notice: The extension is receiving a well needed rewrite! Why? BUGS!

Contribution of ideas, images, code, etc. is welcome, plus you will be
recognized in the JS for your contribution (even if it doesn't make it through).

License:
GNU-GPL-v3*

Untitled1_20240712021621

Description

This extension brings the File System Access API (not to be confused with File System API) to Turbowarp.

Use cases

  • For a file editor
  • User-defined game save data file
  • Memory usage reduction for large variables, lists, etc.
  • Uhhh... Linux.
  • and more!

Features

Entire File System Access API
What else would you think it was?

If there is something in the JS file that needs to be changed, please let me know.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Jul 8, 2024

Writing to a file is being fixed as I noticed it was erasing the data and not writing.
As for tonight, it will be unchanged.

@RockyTheProtogen
Copy link
Author

Also, tons of bug squashing and quality improvement will probably come in last.

ToDo list for that time:

  • removal of error throwing, which has been used to debug
  • Handling of unexpected/sudden access removal
  • Clean up js
  • Easier conditinal statements for access checking.
  • Different handling for large files (as the extension freezes entirely on large files. Wether or not I set a limit is still deterministic...)
  • Plus more...

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Jul 8, 2024

#81 Need to consider this issue. Could probably implement this as a prompt() confirm() if length is larger than 10⁸.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Jul 8, 2024

Another thing to do:
Store unchanged data in memory until no longer needed.

Edit: Not needed. Just let the people making the projects do it.

@kindpump
Copy link

kindpump commented Jul 8, 2024

It seems as though the files can be read and written to, but after they are written to, the extension breaks. Here's a modified working version of the code that is able to save data to the file more than once without breaking:
fileSystemAccessAPI.zip

@RockyTheProtogen
Copy link
Author

I'll give it a good little test. I noticed my files were being erased, haha... that is why this is a draft.
I'll do a diff check on the file and merge it with attribution.
2024-07-08_10-54

@RockyTheProtogen
Copy link
Author

Oop, forgot to format before committing, oh well.

@RockyTheProtogen
Copy link
Author

Okay, I now have reading and writing singular files done!
Next is directories/folders!

@RockyTheProtogen
Copy link
Author

And thank you, @kindpump for the fixes! That genuinely helped a ton and prevented my terrible, garbled JavaScript from breaking everything.

@CubesterYT
Copy link
Collaborator

If he's helped significantly, you can ask him if he wants to be credited for the help.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Jul 8, 2024

If he's helped significantly, you can ask him if he wants to be credited for the help.

I have put direct links to all resources and contributions in lines 7 to 16.
Which includes a link to the exact comment the file was sent from.

@RockyTheProtogen
Copy link
Author

I may go ahead and push some improved attribution

@RockyTheProtogen
Copy link
Author

Ah, named it wrong, oh well.

@RockyTheProtogen
Copy link
Author

2024-07-08_17-27
Directory stuff seems like it has gone well so far.

@RockyTheProtogen
Copy link
Author

4 main features left to implement before refining.

  • Read files in folder
  • Write to files in folder
  • Create files in folder
  • Delete files in folder

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Jul 19, 2024

Is there a reason this extension only works for 5 files at once? That feels like a rather arbitrary number.

Because I have to create variables for each FileSystemFileHandle. And five is more than enough in my opinion.
I might consider different methods in a V3.

@RockyTheProtogen
Copy link
Author

I am genuinely confused now, this didn't work before...
2024-07-19_15-54

@unknown07724
Copy link

Use a array

@RockyTheProtogen
Copy link
Author

Use a array

Another day. For now I will keep writing it under the current methods used.

@GarboMuffin
Copy link
Member

having a 5 file limit because you don't want to use an array does not inspire a lot of confidence in whoever takes the time to review the rest of the code...

@RockyTheProtogen
Copy link
Author

having a 5 file limit because you don't want to use an array does not inspire a lot of confidence in whoever takes the time to review the rest of the code...

This Is on the list of things to do, but this needs to be an extension that works reliably. This is one of the few times I have used javascript, and I hadn't realized that arrays were an option. If I say another day I mean another day, and not never.
I simply wish not to do it while I have something else to finish.

@RockyTheProtogen
Copy link
Author

Okay, I have lost most of my focus on the extension currently. I will close this PR and reopen it (if possible) when I am done.

@CubesterYT
Copy link
Collaborator

You should just mark it as a draft

@RockyTheProtogen
Copy link
Author

I think I'll rethink this extension.
Rather than making a complex utility, I should be giving the raw functions. It allows creators to have so much more control of their projects, and overall should improve the usability.

Also I am back at work on it.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Aug 29, 2024

Just going to say this API gave me a headache. Next on the list (after making this extension) is [matrix], haha.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Sep 15, 2024

image
I question things I shouldn't. Apparently Scratch.BlockType.<insert block type here> returns a string.

@RockyTheProtogen
Copy link
Author

Kate seems to not be committing changes
Odd, but I'll work with it

Rewriting to match what my original goals were: Create a functional one.
@RockyTheProtogen
Copy link
Author

apparently giving it my email just shows it without the numbers.. huh.. enjoy ig.

@RockyTheProtogen
Copy link
Author

block_9_16_2024-4_20_02 PM
It's coming along well this time!

@RockyTheProtogen
Copy link
Author

I just realized why my commits aren't under my username, and it is stupid. Should be fixed next commit.

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Sep 18, 2024

Also, note that leaving the field without an object will result in an error. I'll fix this next commit:
image

And until Firefox implements the API, which is highly unlikely, good luck with it:
image

@LSPECTRONIZTAR
Copy link

Pushing changes to files doesnt work for .exes...
also how to erase stuff from files instead of just writing new stuff at the end

@RockyTheProtogen
Copy link
Author

RockyTheProtogen commented Sep 22, 2024

Pushing changes to files doesnt work for .exes...
also how to erase stuff from files instead of just writing new stuff at the end

I am no longer working on the second rewrite. I'm on to a third and final rewrite. I will not be revisiting that version.

Edit: Why specifically executable files?

@LSPECTRONIZTAR
Copy link

Pushing changes to files doesnt work for .exes...
also how to erase stuff from files instead of just writing new stuff at the end

I am no longer working on the second rewrite. I'm on to a third and final rewrite. I will not be revisiting that version.

Edit: Why specifically executable files?

I'm making a game that i will package as an exe
but the project can't push changes to device files as an exe for some reason
will the rewrite contain being able to change the file entirely instead of just writing new content on a new line

@RockyTheProtogen
Copy link
Author

Pushing changes to files doesnt work for .exes...
also how to erase stuff from files instead of just writing new stuff at the end

I am no longer working on the second rewrite. I'm on to a third and final rewrite. I will not be revisiting that version.
Edit: Why specifically executable files?

I'm making a game that i will package as an exe but the project can't push changes to device files as an exe for some reason will the rewrite contain being able to change the file entirely instead of just writing new content on a new line

The rewrite should fix it by allowing the end user (people like you or me) to interact with the raw functions of the API (plus a few needed tools). I can't say it is definite though.

@GarboMuffin GarboMuffin added the pr: new extension Pull requests that add a new extension label Oct 14, 2024
@RockyTheProtogen
Copy link
Author

Oops, I forgot about this. Luckily I still have the repo on a hard drive, I'll get to work on it during class tomorrow I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: new extension Pull requests that add a new extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants