On Oct 15, 2019, at 5:25 PM, Paul Ringsmuth via 4D_Tech <4d_tech@lists.4d.com> 
wrote:

> I created a folder “Data” and put the various 4D data files in it. Then I put 
> the “Data” folder into the My4D.app. The first time it is launched it asks me 
> to open a data file. I navigate to and select the data file inside of 
> My4D.app. The second time it is launched it remembers where the data file 
> was. So this is a good solution to have everything in one .app package. 
> 
> But sometimes there will be updates and the old data should be used. The 
> everything in one package becomes problematic because it is too hard for the 
> user to deal with the data files. It may be better to have the Data folder 
> outside of the .app to make it easier for my users to swap in new code. It 
> might be tougher for them to locate the old data file.

You will want to use the new architecture for datafile path management system. 
I just converted an app to use this mechanism. This will allow the user to 
never have to select a datafile if you do it right. Also, app updates will not 
destroy the user’s data as it would if the data file is in the app package.

You will need to provide a default data file in the app package. In On Startup, 
you’ll check to see if you are using the default data file. If so, and you are 
running 4D Volume Desktop, then you will look for the user’s data file in the 
path where it should be, something like ~/Documents/MyApp/MyData.4dd, or 
somewhere in ~/Library/ if you don’t want the user to find the data file so 
easily. If the user’s data file does not exist, you can copy the default data 
file if you like, or create a new datafile. Once you have a user-specific data 
file to use, call OPEN DATA FILE($path). 

sample code for v17:

  // ----------------------------------------------------
$datafileObj:=Path to object(Data file)
Case of 
        : ($datafileObj.name="Default")
                  // can't run with default datafile
                Case of 
                        : (Application type=4D Remote mode)
                                ALERT("Can't run with data file "+Data file+".")
                                QUIT 4D
                                
                        : (Application type=4D Volume desktop)
                                $path:=Find_My_Datafile 
                                If ($path#"")
                                        OPEN DATA FILE($path)
                                Else 
                                        ALERT(“Cannot run with default data. 
Quitting now, try again.")
                                        QUIT 4D
                                End if 
                        : (Application type=4D Local mode)
                                  // developer should select datafile
                                $structurePathObj:=Path to object(Structure 
file)
                                $path:=Select 
document($structurePathObj.parentFolder;"4DD";"Select the data file:";0)
                                If (ok=1)
                                        OPEN DATA FILE(document)
                                Else 
                                        ALERT("Default data is being used. 
Startup code will not run.")
                                        TRACE
                                End if 
                End case 

        // more case conditions for startup
End case
  // ----------------------------------------------------

The Find_My_Datafile method looks for the user’s data file in the appropriate 
location, copies default data if necessary, etc.

See the 4D docs for more details.

https://doc.4d.com/4Dv17/4D/17.3/Data-file-management-in-final-applications.300-4639814.en.html


Jim Crate
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to