Ver Fonte

Squashed 'src/ted2go/' changes from 7c09d8d5..6c18b98b

6c18b98b Changed GetModulesNames to sort modules into dependency order.

git-subtree-dir: src/ted2go
git-subtree-split: 6c18b98b5374e085bb42a07ed306ab308691638c
Mark Sibly há 8 anos atrás
pai
commit
c75539f349
1 ficheiros alterados com 67 adições e 1 exclusões
  1. 67 1
      dialog/UpdateModulesDialog.monkey2

+ 67 - 1
dialog/UpdateModulesDialog.monkey2

@@ -1,4 +1,3 @@
-
 Namespace ted2go
 
 
@@ -163,7 +162,73 @@ Class UpdateModulesDialog Extends DialogExt
 	
 	Global _modsNames:=New StringStack
 	
+	#rem MARK WAS HERE!!!!!
+	
+	EnumModules code lifted from mx2cc.monkey2
+	
+	This sorts modules into dependancy order.
+	
+	#end
+	Function EnumModules( out:StringStack,cur:String,deps:StringMap<StringStack> )
+		If out.Contains( cur ) Return
+		
+		For Local dep:=Eachin deps[cur]
+			EnumModules( out,dep,deps )
+		Next
+		
+		out.Push( cur )
+	End
+	
+	Function EnumModules:String[]()
+	
+		Local mods:=New StringMap<StringStack>
+		
+		Local modsPath:=MainWindow.ModsPath
+	
+		For Local f:=Eachin LoadDir( modsPath )
+		
+			Local dir:=modsPath+f+"/"
+			If GetFileType( dir )<>FileType.Directory Continue
+			
+			Local str:=LoadString( dir+"module.json" )
+			If Not str Continue
+			
+			Local obj:=JsonObject.Parse( str )
+			If Not obj 
+				Print "Error parsing json:"+dir+"module.json"
+				Continue
+			Endif
+			
+			Local name:=obj["module"].ToString()
+			If name<>f Continue
+			
+			Local deps:=New StringStack
+			If name<>"monkey" deps.Push( "monkey" )
+			
+			Local jdeps:=obj["depends"]
+			If jdeps
+				For Local dep:=Eachin jdeps.ToArray()
+					deps.Push( dep.ToString() )
+				Next
+			Endif
+			
+			mods[name]=deps
+		Next
+		
+		Local out:=New StringStack
+		For Local cur:=Eachin mods.Keys
+			EnumModules( out,cur,mods )
+		Next
+		
+		Return out.ToArray()
+	End
 	
+	Function GetModulesNames( out:StringStack )
+		
+		out.AddAll( EnumModules() )
+	End
+
+#rem	
 	Function GetModulesNames( out:StringStack )
 	
 		Local modsPath:=MainWindow.ModsPath
@@ -179,6 +244,7 @@ Class UpdateModulesDialog Extends DialogExt
 			Endif
 		Next
 	End
+#end
 	
 	Function ShowMessage( title:String,msg:String,okButton:String="  OK  " )