Setting User Application and My Document folders and tracking last accessed

From Planimate Knowledge Base
Jump to navigation Jump to search

Set up a Table called UserFolders with two columns:

1) Application Data

2) My Documents

Setup broadcast reciever for _Model Loaded, three routines (Clear, App, MyDoc), an Exit, and add a flow between them.

Create a Label List called User_Folder for the folder associated with the program. Add a label to the User_Folder label list (eg l.ProgramABC).

Create a Label List called l.User_Path . Set the two columns of t.UserFolders to the Label List l.User_Path

Create a label list called l.temp .

 - - - - - - - -

For the Clear routine:

- Set routine operation ClearLabelList for l.User_Path
- Delete a row in table t.Userfolders
- Add a row in table t.Userfolders

 - - - - - - - - -

For the App routine:
- add routine GetAppDataName. Create routine attribute r.AppData and set as result, and for the folder set the Label l.ProgramABC (from label list User_Folder), leave file as zero. This will get a full Application Data path/file including a subfolder and a filename. sets s.LastAccessedDataFilePath and returns non zero if the folder was created / verified writeable.
- Add check for r.AppData greater than zero using an IF statement
- Create a routine attribute r.filepath and units is Label
- use the Label List User_Path .
- After the IF, add a routine operation FormatIntoLabel; the result is the routine attribute r.filepath, and the sourceis the system attribute s.LastAccessedDataFilePath (Mode is Value, Type is System, System is String - LastAccessedDataFilePath).
- Create a rotuine r.lastchar
- Add a rotuine operation FormattedWidth with the result r.lastchar , and the source is r.filepath .
- Create a rotuine r.2ndlastchar
- Add a subtraction routine operation which the result r.2ndlastchar is equal to .lastchar minus one.
NOTE: this is to remove the zero which was added to the path in the GetAppDataName operation
. - Add a routine CropToCharacters, with the result being r.filepath from character one to last character r.2ndlastchar. This will remove the zero in the path string.

- Set the cell in the first row of the table t.UserFolders in the Application Data column equal to r.filepath.

This has now set up a pointer for saving/loading files to a folder that is associated to the user for files that are system files for the program.

- Add an else before the ENDIF, and after the ELSE add a Dialog routine operation. Create a routine attribute r.info for the result. In the dialog box enter text to inform the user that the Application Data folder is not writeable. eg

"Application Data Folder not Writeable. Please Contact InterDynamics."

 - - - - - - - - -

For the MyDoc routine:
- add routine GetMyDocumentsName. Create routine attribute r.AppData and set as result, and for the folder set the Label l.ProgramABC (from label list User_Folder), leave file as zero. This will get a full Application Data path/file including a subfolder and a filename. sets s.LastAccessedDataFilePath and returns non zero if the folder was created / verified writeable.
- Add check for r.AppData greater than zero using an IF statement - Create a routine attribute r.filepath and units is Label - use the Label List User_Path .
- After the IF, add a routine operation FormatIntoLabel; the result is the routine attribute r.filepath, and the source is the system attribute s.LastAccessedDataFilePath (Mode is Value, Type is System, System is String - LastAccessedDataFilePath).
- Create a rotuine r.lastchar
- Add a rotuine operation FormattedWidth with the result r.lastchar , and the source is r.filepath
- Create a rotuine r.2ndlastchar
- Add a subtraction routine operation which the result r.2ndlastchar is equal to .lastchar minus one. NOTE: this is to remove the zero which was added to the path in the GetAppDataName operation.
- Add a routine CropToCharacters, with the result being r.filepath from character one to last character r.2ndlastchar. This will remove the zero in the path string.

- Set the cell in the first row of the table t.UserFolders in the My Documents column equal to r.filepath.

This has now set up a pointer for saving/loading files to a folder that is associated to the user for files that are created/imported by the user.

- Add an else before the ENDIF, and after the ELSE add a Dialog routine operation. Create a routine attribute r.info for the result. In the dialog box enter text to inform the user that the My Documents folder is not writeable. eg "My Documents Folder not Writeable. Please Contact InterDynamics."

 - - - - - - - - -

In the model then when the user is reading or writing files setup two routines: one a run routine, and the other a read(or write) file.

- Create a Label list for filenames used by the application, l.FileAccessed.
- Add a label 'abcsetup.dat' to the labelist l.FileAccessed

- Add a Portal Attribute p.Target_file, using the Label l.temp

In the run routine:
- add a routine attribute r.temp using the label list l.temp
- create a routine attribute r.FileName eqaul to the label 'abcsetup.dat' for the label list l.FileAccessed.
- add a routine operation FormatIntoLabel with the result r.temp and the source t.UserFolders[1][c.Application Data] . This will get the path name.
- add a routine operation AppendToLabel with the result r.temp and the source r.FileName . This will add the filename to the path.
- Set p.Target_file equal to r.temp .

In the Read (or Write) Raw Data file routine set the option Dynamic Filename, and set the Target File Attribute to p.Target_file. Then select the appropriate table for the source.

NOTE: For User data in the run routine replace FormatIntoLabel source with the My Documents column eg t.UserFolders[1][c.My Documents]

 - - - - - - - - -

For the My Documents folder, you can keep track of the latest path accessed by the user. Adding a portal attribute p.Check , and use it for the Error Result in the Read/Write Raw Data routine.

After the Read/Write Raw Data routine add another run routine. In the run routine:
- Add an IF statement to check if p.Check is greater, or equal, to zero.
- If true add the routine operations below
- add a routine attribute r.temp using the label list l.temp
- add a routine operation FormatIntoLabel with the result r.temp and the source is system s.LastAccessedDataFile
- create a routine attribute r.Filelength
- add a routine operation FormattedWidth for the result r.Filelength and the source is r.temp
- create a routine attribute r.FilePath using theLabel List l.User_Path
- add a routine operation FormatIntoLabel with the result r.FilePath and the source is system s.LastAccessedDataFilePath - Create a routine attribute r.folderlength
- add a routine operation FormattedWidth for the result r.folderlength and the source is r.FilePath
- Create a routine attribute r.new end
- add a routine operation CropToCharacters with the result r.FilePath and the From Character is one, and the To Character is r.new end .
- Set the cell in the My Documents column in table UserFolders to r.FilePath.