@@ -11,6 +11,7 @@ public class SaveSystem : MonoBehaviour
1111
1212 string filePath ;
1313 string playerProfilePath ;
14+ public enum StatusCodes { OK , Error } ;
1415
1516
1617 private void Awake ( )
@@ -35,32 +36,51 @@ private void Awake()
3536
3637 }
3738
38- public void saveRawJsonTextToJson ( string catalogueName , string data )
39+ public StatusCodes saveRawJsonTextToJson ( string catalogueName , string data )
3940 {
41+ try {
4042 string filename = "/" + catalogueName + ".qcat" ;
4143 string content = data ;
4244 System . IO . File . WriteAllText ( Application . persistentDataPath + filename , content ) ;
4345 Debug . Log ( "Speicherung erfolgt als... " + filename ) ;
46+ return StatusCodes . OK ;
47+ }
48+ catch {
49+ return StatusCodes . Error ;
50+ }
4451 }
4552
46- public void saveQuestionCatalogueToJson ( QuestionCatalogue _questionCatalogue )
53+ public StatusCodes saveQuestionCatalogueToJson ( QuestionCatalogue _questionCatalogue )
4754 {
55+ try {
4856 string fileName = "/" + _questionCatalogue . fileName + ".qcat" ;
4957 string content = JsonUtility . ToJson ( _questionCatalogue ) ;
5058 System . IO . File . WriteAllText ( Application . persistentDataPath + fileName , content ) ;
5159 Debug . Log ( "QuestionCatalogue has been successfully saved to the FileSystem" ) ;
60+ return StatusCodes . OK ;
61+ }
62+ catch {
63+ return StatusCodes . Error ;
64+ }
5265 }
5366
54- public void savePlayerProfileToJson ( PlayerProfile _playerProfile )
67+ public StatusCodes savePlayerProfileToJson ( PlayerProfile _playerProfile )
5568 {
69+ try {
5670 string fileName = "/" + _playerProfile . fileName + ".pp" ;
5771 string content = JsonUtility . ToJson ( _playerProfile ) ;
5872 System . IO . File . WriteAllText ( Application . persistentDataPath + fileName , content ) ;
5973 Debug . Log ( "PlayerProfile has been successfully saved to the FileSystem" ) ;
74+ return StatusCodes . OK ;
75+ }
76+ catch {
77+ return StatusCodes . Error ;
78+ }
6079 }
6180
6281 public string loadTextRawFromJson ( string catalogueName )
6382 {
83+ try {
6484 string extension = "*.qcat" ; // The "*" ist really important. It is a placeholder for the rest of the File
6585 string [ ] Files = Directory . GetFiles ( Application . persistentDataPath , extension ) ;
6686 foreach ( string file in Files )
@@ -80,6 +100,10 @@ public string loadTextRawFromJson(string catalogueName)
80100 }
81101 Debug . Log ( "----------\n OPERATION FAILED\n ----------" ) ;
82102 return null ;
103+ }
104+ catch {
105+ return StatusCodes . Error . ToString ( ) ;
106+ }
83107 }
84108
85109 public List < QuestionCatalogue > loadQuestionCataloguesFromJson ( )
@@ -91,21 +115,31 @@ public List<QuestionCatalogue> loadQuestionCataloguesFromJson()
91115 {
92116 Debug . Log ( "The following file has been found: " + Path . GetFileName ( file ) ) ;
93117 string DataFromJson = File . ReadAllText ( file ) ;
118+ try {
94119 QuestionCatalogue questionCatalogue = JsonUtility . FromJson < QuestionCatalogue > ( DataFromJson ) ;
95120 allCatalogues . Add ( questionCatalogue ) ;
96121 Debug . Log ( "A catalogue has been added to the List." ) ;
122+ }
123+ catch {
124+ Debug . Log ( "The file format was invalid." ) ;
125+ }
97126 }
98127 if ( Files . Length == 0 )
99128 {
100129 Debug . Log ( "No files with the extension " + extension + " have been found." ) ;
101130 return null ;
102131 }
132+ else if ( allCatalogues . Count == 0 ) {
133+ Debug . Log ( "A file was found but not compatible." ) ;
134+ return null ;
135+ }
103136 Debug . Log ( "The List of found QuestionCatalogues contains " + allCatalogues . Count + " QuestionCatalogues." ) ;
104137 return allCatalogues ;
105138 }
106139
107140 public PlayerProfile loadPlayerProfileFromJson ( string fileName )
108141 {
142+ try {
109143 string extension = "*.pp" ; // The "*" ist really important. It is a placeholder for the rest of the File
110144 string [ ] Files = Directory . GetFiles ( Application . persistentDataPath , extension ) ;
111145 foreach ( string file in Files )
@@ -127,6 +161,10 @@ public PlayerProfile loadPlayerProfileFromJson(string fileName)
127161 }
128162 Debug . Log ( "----------\n OPERATION FAILED\n ----------" ) ;
129163 return null ;
164+ }
165+ catch {
166+ return null ;
167+ }
130168 }
131169
132170
0 commit comments