mirror of
				https://github.com/Strongleong/ScrapModLoader.git
				synced 2024-08-15 00:03:19 +00:00 
			
		
		
		
	Added ability to toggle mods
This commit is contained in:
		
							parent
							
								
									cb4c8ac90d
								
							
						
					
					
						commit
						6dbf0656dc
					
				
					 2 changed files with 60 additions and 6 deletions
				
			
		|  | @ -2,8 +2,6 @@ | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.IO; | using System.IO; | ||||||
| 
 | 
 | ||||||
| using Ionic.Zip; |  | ||||||
| 
 |  | ||||||
| using Microsoft.Win32; | using Microsoft.Win32; | ||||||
| 
 | 
 | ||||||
| namespace ScrapModLoader | namespace ScrapModLoader | ||||||
|  | @ -78,10 +76,21 @@ namespace ScrapModLoader | ||||||
|             return isFound; |             return isFound; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         internal void LoadMods(String gamePath) |         public void LoadMods(String gamePath) | ||||||
|         { |         { | ||||||
|             foreach (ScrapMod mod in Mods.FindAll(mod => mod.Checked)) |             foreach (ScrapMod mod in Mods) | ||||||
|                 mod.LoadModToGame(gamePath); |             { | ||||||
|  |                 if (mod.Checked) | ||||||
|  |                 { | ||||||
|  |                     if (!mod.IsEnabled(gamePath)) | ||||||
|  |                         mod.Enable(gamePath); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     if (mod.IsEnabled(gamePath)) | ||||||
|  |                         mod.Disable(gamePath); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,7 +38,52 @@ namespace ScrapModLoader | ||||||
|             LoadFromFile(path); |             LoadFromFile(path); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public void LoadModToGame(String gamePath) | 
 | ||||||
|  |         public Boolean IsLoaded(String gamePath) => Directory.Exists(gamePath + @"Mods\" + Name); | ||||||
|  | 
 | ||||||
|  |         public Boolean IsEnabled(String gamePath) | ||||||
|  |         { | ||||||
|  |             if (IsLoaded(gamePath)) | ||||||
|  |             { | ||||||
|  |                 foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name)) | ||||||
|  |                 { | ||||||
|  |                     if (Path.GetExtension(file) == ".disabled") | ||||||
|  |                         return false; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void Enable(String gamePath) | ||||||
|  |         { | ||||||
|  |             if (!IsLoaded(gamePath)) | ||||||
|  |                 LoadModToGame(gamePath); | ||||||
|  | 
 | ||||||
|  |             if (IsEnabled(gamePath)) | ||||||
|  |                 return; | ||||||
|  | 
 | ||||||
|  |             foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name)) | ||||||
|  |             { | ||||||
|  |                 if (Path.GetExtension(file) == ".disabled") | ||||||
|  |                     File.Move(file, Path.ChangeExtension(file, null)); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public void Disable(String gamePath) | ||||||
|  |         { | ||||||
|  |             if (!IsEnabled(gamePath)) | ||||||
|  |                 return; | ||||||
|  | 
 | ||||||
|  |             foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name)) | ||||||
|  |             { | ||||||
|  |                 if (Path.GetExtension(file) == ".packed") | ||||||
|  |                     File.Move(file, file + ".disabled"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         private void LoadModToGame(String gamePath) | ||||||
|         { |         { | ||||||
|             gamePath += @"Mods\" + Name; |             gamePath += @"Mods\" + Name; | ||||||
|             Directory.CreateDirectory(gamePath); |             Directory.CreateDirectory(gamePath); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue