@@ -157,6 +157,43 @@ fn update_tmp_json() {
157157 }
158158}
159159
160+ fn purge_gmod_integration_addons ( ) {
161+ let addons_dir = Path :: new ( "./garrysmod/addons" ) ;
162+ if !addons_dir. exists ( ) {
163+ print_log ( "Addons directory not found, skipping cleanup" ) ;
164+ return ;
165+ }
166+
167+ let entries = match fs:: read_dir ( addons_dir) {
168+ Ok ( entries) => entries,
169+ Err ( e) => {
170+ print_log ( & format ! ( "Failed to read addons directory: {}" , e) ) ;
171+ return ;
172+ }
173+ } ;
174+
175+ for entry in entries. flatten ( ) {
176+ let path = entry. path ( ) ;
177+ let name = entry. file_name ( ) ;
178+ let name = name. to_string_lossy ( ) . to_lowercase ( ) ;
179+
180+ if !name. contains ( "gmod" ) || !name. contains ( "integration" ) {
181+ continue ;
182+ }
183+
184+ let result = if path. is_dir ( ) {
185+ fs:: remove_dir_all ( & path)
186+ } else {
187+ fs:: remove_file ( & path)
188+ } ;
189+
190+ match result {
191+ Ok ( _) => print_log ( & format ! ( "Removed {}" , path. display( ) ) ) ,
192+ Err ( e) => print_log ( & format ! ( "Failed to remove {}: {}" , path. display( ) , e) ) ,
193+ }
194+ }
195+ }
196+
160197#[ gmod13_open]
161198fn gmod13_open ( _lua : State ) -> i32 {
162199 print_log ( "Starting auto-updater..." ) ;
@@ -236,21 +273,8 @@ fn gmod13_open(_lua: State) -> i32 {
236273 return 1 ;
237274 }
238275
239- // Check if addon folder exists and version matches
240- let addon_exists = Path :: new ( "./garrysmod/addons/_gmod_integration_latest" ) . exists ( ) ;
241-
242- if let Some ( current) = & version_cache. gmod_integration {
243- if current == & release. tag_name && addon_exists {
244- print_log ( & format ! ( "Gmod integration is up to date ({})" , release. tag_name) ) ;
245- return 0 ;
246- }
247- }
248-
249- if !addon_exists {
250- print_log ( "Addon folder missing, downloading..." ) ;
251- } else {
252- print_log ( "Version mismatch, updating..." ) ;
253- }
276+ print_log ( "Removing existing gmod integration addons..." ) ;
277+ purge_gmod_integration_addons ( ) ;
254278
255279 print_log ( "Downloading latest version..." ) ;
256280
@@ -334,7 +358,7 @@ fn gmod13_open(_lua: State) -> i32 {
334358 } ;
335359
336360 // Extract ZIP archive to addon directory
337- let target_dir = PathBuf :: from ( "./garrysmod/addons/_gmod_integration_latest " ) ;
361+ let target_dir = PathBuf :: from ( "./garrysmod/addons/gmod-integration " ) ;
338362
339363 if target_dir. exists ( ) {
340364 let _ = fs:: remove_dir_all ( & target_dir) ;
@@ -421,42 +445,6 @@ fn gmod13_open(_lua: State) -> i32 {
421445 let _ = fs:: remove_dir_all ( target_dir. join ( ".github" ) ) ;
422446 let _ = fs:: remove_file ( & zip_path) ;
423447
424- // Rename files and folders to use _gmod_integration_latest prefix
425- let old_lua_path = target_dir. join ( "lua/autorun/gmod_integration.lua" ) ;
426- let new_lua_path = target_dir. join ( "lua/autorun/_gmod_integration_latest.lua" ) ;
427-
428- if old_lua_path. exists ( ) {
429- if let Err ( e) = fs:: rename ( & old_lua_path, & new_lua_path) {
430- print_log ( & format ! ( "Failed to rename Lua file: {}" , e) ) ;
431- } else {
432- print_log ( "Renamed gmod_integration.lua to _gmod_integration_latest.lua" ) ;
433- }
434- }
435-
436- // Rename the main folder if it exists
437- let old_folder_path = target_dir. join ( "gmod_integration" ) ;
438- let new_folder_path = target_dir. join ( "_gmod_integration_latest" ) ;
439-
440- if old_folder_path. exists ( ) {
441- if let Err ( e) = fs:: rename ( & old_folder_path, & new_folder_path) {
442- print_log ( & format ! ( "Failed to rename main folder: {}" , e) ) ;
443- } else {
444- print_log ( "Renamed gmod_integration folder to _gmod_integration_latest" ) ;
445- }
446- }
447-
448- // Rename the lua/gmod_integration folder to lua/_gmod_integration_latest
449- let old_lua_folder_path = target_dir. join ( "lua/gmod_integration" ) ;
450- let new_lua_folder_path = target_dir. join ( "lua/_gmod_integration_latest" ) ;
451-
452- if old_lua_folder_path. exists ( ) {
453- if let Err ( e) = fs:: rename ( & old_lua_folder_path, & new_lua_folder_path) {
454- print_log ( & format ! ( "Failed to rename lua/gmod_integration folder: {}" , e) ) ;
455- } else {
456- print_log ( "Renamed lua/gmod_integration folder to lua/_gmod_integration_latest" ) ;
457- }
458- }
459-
460448 // Update version cache and signal completion
461449 version_cache. gmod_integration = Some ( release. tag_name ) ;
462450 save_version_cache ( & version_cache) ;
0 commit comments