11using System ;
22using UnityEngine ;
33using System . Runtime . InteropServices ;
4+ using System . Collections . Generic ;
45
56namespace SofaUnityAPI
67{
@@ -18,6 +19,44 @@ public class SofaContextAPI : IDisposable
1819
1920 private bool m_isReady = false ;
2021
22+ public static string getResourcesPath ( )
23+ {
24+ #if UNITY_ANDROID && ! UNITY_EDITOR
25+ return Application . persistentDataPath ;
26+ #else
27+ return Application . dataPath ;
28+ #endif
29+ }
30+
31+ void CopyAssetToPersistent ( )
32+ {
33+ string sofaUnityResourcesPath = getResourcesPath ( ) + "/SofaUnity" ;
34+ #if UNITY_STANDALONE_WIN && ! UNITY_EDITOR && TEST_PERSISTENT_WIN // to test the zip/unzip mechanism on Windows
35+ // Merely a test to see if it is really doing its job
36+ Debug . Log ( "unzipping to persistent data path (windows)" ) ;
37+ Utility_SharpZipCommands . ExtractTGZ ( Application . streamingAssetsPath + "/" + "Data.tgz" , Application . persistentDataPath ) ;
38+ #endif
39+ #if UNITY_ANDROID && ! UNITY_EDITOR
40+ //if stub file Resources.data doesn't exist, extract default data...
41+ if ( File . Exists ( sofaUnityResourcesPath + "/" + "Resources.data" ) == false )
42+ {
43+ Debug . Log ( "Resources.data doesn't exist, creating it for the first time." ) ;
44+ //copy tgz to directory where we can extract it
45+ WWW www = new WWW ( Application . streamingAssetsPath + "/Resources.tgz" ) ;
46+ while ( ! www . isDone ) { }
47+ System . IO . File . WriteAllBytes ( Application . persistentDataPath + "/" + "Resources.tgz" , www . bytes ) ;
48+ //extract it
49+ Utility_SharpZipCommands . ExtractTGZ ( Application . persistentDataPath + "/" + "Resources.tgz" , sofaUnityResourcesPath ) ;
50+ //delete tgz
51+ File . Delete ( Application . persistentDataPath + "/" + "Resources.tgz" ) ;
52+ }
53+ else
54+ {
55+ Debug . Log ( "Resources.data does exist, will not extract default data." ) ;
56+ }
57+ #endif
58+ }
59+
2160 /// Default constructor, will create the pointer to SofaPhysicsAPI
2261 public SofaContextAPI ( bool async )
2362 {
@@ -34,6 +73,13 @@ public SofaContextAPI(bool async)
3473 return ;
3574 }
3675
76+ // Prepare Data
77+ Debug . Log ( "data: " + Application. dataPath ) ;
78+ Debug . Log ( "persistent: " + Application. persistentDataPath ) ;
79+ Debug . Log ( "streaming: " + Application. streamingAssetsPath ) ;
80+
81+ CopyAssetToPersistent ( ) ;
82+
3783 // load the sofaIni file
3884 string pathIni = Application . dataPath + "/SofaUnity/Plugins/Native/x64/sofa.ini" ;
3985 string sharePath = sofaPhysicsAPI_loadSofaIni ( m_native , pathIni ) ;
@@ -63,7 +109,6 @@ public SofaContextAPI(bool async)
63109 Dispose ( ) ;
64110 }
65111
66-
67112 /// Dispose method to release the object
68113 public void Dispose ( )
69114 {
0 commit comments