@@ -49,11 +49,6 @@ pub mod settings_creation {
49
49
. join ( "settings" )
50
50
. join ( "installation" ) ;
51
51
52
- let library_settings = base_dirs
53
- . config_dir ( )
54
- . join ( "com.fitlauncher.carrotrub" )
55
- . join ( "library" ) ;
56
-
57
52
if !installation_folder_path. exists ( ) {
58
53
fs:: create_dir_all ( & installation_folder_path)
59
54
. expect ( "Failed to create Installation Config directory" ) ;
@@ -92,11 +87,48 @@ pub mod settings_creation {
92
87
} ) ?;
93
88
}
94
89
95
- if !library_settings. exists ( ) {
96
- fs:: create_dir_all ( & library_settings)
90
+ let library_settings_dir = base_dirs
91
+ . config_dir ( )
92
+ . join ( "com.fitlauncher.carrotrub" )
93
+ . join ( "library" ) ;
94
+
95
+ // Ensure the library directory exists
96
+ if !library_settings_dir. exists ( ) {
97
+ fs:: create_dir_all ( & library_settings_dir)
97
98
. expect ( "Failed to create Installation Config directory" ) ;
98
99
}
99
100
101
+ // Define paths for specific files/directories within library settings
102
+ let downloaded_games_file = library_settings_dir
103
+ . join ( "downloadedGames" )
104
+ . join ( "downloaded_games.json" ) ;
105
+ let collections_dir = library_settings_dir. join ( "collections" ) ;
106
+
107
+ // Ensure the downloadedGames directory and its file exist
108
+ if !downloaded_games_file. parent ( ) . unwrap ( ) . exists ( ) {
109
+ fs:: create_dir_all ( downloaded_games_file. parent ( ) . unwrap ( ) )
110
+ . expect ( "Failed to create downloadedGames directory" ) ;
111
+ }
112
+ if !downloaded_games_file. exists ( ) {
113
+ let mut file = fs:: File :: create ( downloaded_games_file)
114
+ . expect ( "Failed to create downloaded_games.json file" ) ;
115
+ file. write_all ( b"[]" )
116
+ . expect ( "Failed to write to downloaded_games.json file" ) ;
117
+ } else {
118
+ let metadata =
119
+ fs:: metadata ( & downloaded_games_file) . expect ( "Failed to get file metadata" ) ;
120
+ if metadata. len ( ) == 0 {
121
+ // If the file is empty, write "{}"
122
+ let mut file = fs:: File :: create ( & downloaded_games_file)
123
+ . expect ( "Failed to open downloaded_games.json file for writing" ) ;
124
+ file. write_all ( b"{}" )
125
+ . expect ( "Failed to write to downloaded_games.json file" ) ;
126
+ }
127
+ }
128
+ // Ensure the collections directory exists
129
+ if !collections_dir. exists ( ) {
130
+ fs:: create_dir_all ( & collections_dir) . expect ( "Failed to create collections directory" ) ;
131
+ }
100
132
Ok ( ( ) )
101
133
}
102
134
0 commit comments