Code: Select all
If CreateFile(0, #WorkingSavedGamesFilename$, @SavedGamesWriteCallback()) ; we create a new text file and run the callback to populate and export WriteString(0, WorkingFileData$) ;dump content into file ExportFile(0, "text/plain") CloseFile(0) ProcedureReturn "Ok" EndIf
Code: Select all
Procedure SavedGamesReadCallback(Status, Filename$, File, Size) If Status = #PB_Status_Loaded Debug "File: " + Filename$ + " - Size: " + Size + " bytes" Protected WorkingImportText$ = ReadString(0, #PB_Ascii + #PB_File_IgnoreEOL) CloseFile(0) CloseWindow(#WindowFileRequester) WriteUserTextConsole(SaveGameS(#LoadFromSavedGamesDownloadFile$, #False, WorkingImportText$)) ElseIf Status = #PB_Status_Error Debug "Error when loading the file: " + Filename$ EndIf EndProcedure Procedure OpenFileRequesterCallback() If NextSelectedFile() OpenFile(0, SelectedFileID(), @SavedGamesReadCallback(), #PB_LocalFile) EndIf EndProcedure Procedure Event_ChooseFile() OpenFileRequester("*.txt", @OpenFileRequesterCallback()) EndProcedure Procedure SelectSavedGameFileToRestore() OpenWindow(#WindowFileRequester, 0, 0, 300, 50, "Load " + #GameTitle$ + " Saved Games from File", #PB_Window_ScreenCentered) ButtonGadget(#ChooseFileButton, 10, 10, 280, 30, "Choose a file...") BindGadgetEvent(#ChooseFileButton, @Event_ChooseFile()) EndProcedure
HOWEVER, If I modify the above code to use the same fixed file name both for reading and writing along with #PB_LocalStorage and no file selector dialog for loading, it simply does not load the file from the cache.
Could someone give me a working example of reading and writing a fixed filename (will always be the same file; can just overwrite each time) using #PB_LocalStorage so that the data is stored within the browser cache? I've tried every possible iteration of this following the help files and such for SB, and while I was able to get it working with the Local Files (which actually required more code/callbacks, etc. I was never able to make it work with the #PB_LocalStorage way.) Currently, my save slots exist in RAM, and I can manually export and import those save slots as a file (like a backup/archive) but I cannot persist in the cache, which is what I REALLY need to be doing here. (The downloading and uploading is more for archive/backup of save slots. I need "real-time" browser caching to really make this practical, so if they close, they can reload from saved slots without having to have made a manual export/download file to reload.)
Any help would be highly appreciated!