GetSaveInfo + GetRelative in XPlatform

I implemented years ago (!) a Recents Items menu.

I deal with that by writing the Recent Paths to a text file (*).

For some reasons (bug: file not found on quit…), I want to use FolderItem’s GetRelative and GetSaveInfo.

I took the two example code from the LR and I do not understand how to code the “save to (and open from) disk in a file” part.

It looks like if GetSaveInfo generate a FolderItem (that I already have) and GetRelative takes a Path (that I already have.

Either I do not need to do that and need to check why I have a bug in my actual code (*)
Or (probably) I do not understand at all the whole “GetSaveInfo + GetRelative” process.

  • I suppose the bug appears when I move the target file from its original folder location (where it was saved…) to a different one.

Nota:
I used a text file with TextOutputStream / TextInputStream for testing purposes (but in my real project) and let the things like that until I started to get troubles (now).

Maybe create a folder, in your application support folder, and then create alias/links to the saved files and then let the OS deal with figuring out where the files are, if they get moved… If the file can’t be found, then nuke the alias/link and don’t show it in your Recent Items menu…

Hi shao, thanks for your anwer.

I already have the first part ( specific folder for this application special / preferences files, and my storage file for Recent Items is there).

AFAIK, Relative is exactly what I want (the file path will be resolved automagically), but I failed to implement it.

I’ve never played with that before, and I see that it’s lacking in the new framework… If nobody posts anything between now and when I’m done my work, I’ll take a peek and see what I can do… Any chance of you posting the code you’ve tried?

The code I used is in the LR for both instructions (read FolderItem).

Well, work was a little busier than I’m used to, but they gotta keep me on my toes :wink:
Seeing as someone more competent than me didn’t answer, you’re stuck with my help… All this code was tested on macOS and placed in the Action event of a button…

This is to save the save info:

[code]// create the recent application data folder
DIM f As FolderItem = SpecialFolder.ApplicationData.Child(“moo”)
if (f.Exists = FALSE) then f.CreateAsFolder
f = f.Child(“Recent”)
if (f.Exists = FALSE) then f.CreateAsFolder

// create a dummy document in the user’s documents folder
DIM oink As FolderItem = SpecialFolder.Documents.Child(“oink.txt”)
if (oink.Exists = FALSE) then
DIM t as TextOutputStream = TextOutputStream.Create(oink)
t.Write “oink”
t.Close
end if

// create the save info for the oink folderitem
// pass Nil to indicate that you do not care for a relative resolution of the path
// (this is, for instance, still useful on macOS where renamed and moved files can still be found with the
// FolderItem.GetRelative function nonetheless).
DIM info As String = oink.GetSaveInfo(Nil, FolderItem.SaveInfoDefaultMode)

// create the recent item in the recent application data folder
DIM recent As TextOutputStream = TextOutputStream.Create(f.Child(“recent.txt”))
recent.Write info
recent.Close[/code]

This is to load the save info:

[code]// read in the save info from the recent document in the recent application data folder
DIM f As FolderItem = SpecialFolder.ApplicationData.Child(“moo”).Child(“Recent”).Child(“recent.txt”)
DIM t As TextInputStream = TextInputStream.Open(f)
DIM info As String = t.ReadAll()
t.Close

// create the folder item based on the save info
DIM temp, recent As FolderItem
temp = NEW FolderItem
recent = temp.GetRelative(info)

Break
// look at the path for the recent variable
// on macOS if you rename, or move the file, it updates with the new path every time you run this code[/code]

Hi shao, thanks.

I cannot check that right now, I will in the afternoon.

What do my code do actually:

  1. Drop a compatible file to the main window
  2. Adds its title into the Recent Items Menu (as a new MenuItem)
  3. If you close the front window and select its entry in the Recent Items, it reloasd it.

On Application close, the Recents Menu info are saved as a couple: Name and NativePath in a text file located in this application folder, somewhere in a System folder.
(it may be saved as soon ad it is added in the Recents Items).

I have an entry called “Clear this Menu” and another, hidden, Shift-Release on a MenuItem that delete the selected MenuItem.

That is what and how I am testing this.

The feature that check if two entries are the same seem (IS) broken, but was working someties in the past. I wish this kind of things stop as soon as today :frowning:

More data will come soon.

The SaveInfo data is weird system info, I am sure you can save multiple lines to a file and then just read in each entry from that file… The code I posted will help you with what you want to do… If you have any specific questions, feel free to ask…