@@ -43,23 +43,31 @@ public static void EndReading()
4343 CurrnetUsingFilePath = null ;
4444 }
4545
46- public static string GetVersion ( int index )
46+ public static string GetVersion ( string modName )
4747 {
48- string version ;
48+ string version = "Unknown" ;
4949 if ( xdoc == null )
5050 throw new Exception ( "invoke BeginReading before using this method" ) ;
5151 try
5252 {
53- version = xdoc . Root . Element ( "meta" ) ? . Element ( MOD_META_DATAS ) ? . Elements ( ) . ElementAt ( index ) ? . Element ( VERSION_NODENAME ) ? . Value ?? "Unknown" ;
53+ //version = xdoc.Root.Element("meta")?.Element(MOD_META_DATAS)?.Elements().ElementAt(index)?.Element(VERSION_NODENAME)?.Value ?? "Unknown";
54+ var ModMetaHeaders = xdoc . Root . Element ( "meta" ) ? . Element ( MOD_META_DATAS ) ;
55+ if ( ModMetaHeaders != null )
56+ {
57+ version = ( from node in ModMetaHeaders . Elements ( )
58+ let modNameInNode = node . Element ( "ModName" ) ? . Value
59+ where string . Equals ( modNameInNode , modName )
60+ select node . Element ( VERSION_NODENAME ) ? . Value ) . FirstOrDefault ( ) ?? "Unknown" ;
61+ }
5462 }
55- catch
63+ catch ( Exception ex )
5664 {
57- version = "Unknown" ;
65+ Log . Warning ( ex . ToString ( ) ) ;
5866 }
5967 return version ;
6068 }
6169
62- public static void SetVersions ( List < Pair < string , string > > datas )
70+ public static void SetVersions ( List < ModMetaHeader > metaHeaders )
6371 {
6472 if ( xdoc == null )
6573 throw new Exception ( "Invoke BeginReading before using this method" ) ;
@@ -69,14 +77,14 @@ public static void SetVersions(List<Pair<string, string>> datas)
6977 modVersionsNode . RemoveAll ( ) ;
7078 if ( meta . Element ( MOD_META_DATAS ) == null )
7179 throw new Exception ( "F" ) ;
72- for ( int i = 0 ; i < datas . Count ; i ++ )
80+ for ( int i = 0 ; i < metaHeaders . Count ; i ++ )
7381 {
74- var data = datas [ i ] ;
82+ var data = metaHeaders [ i ] ;
7583 var liNode = new XElement ( "li" ) ;
76- liNode . Add ( new XElement ( "ModName" ) { Value = data . First } ) ;
77- liNode . Add ( new XElement ( VERSION_NODENAME ) { Value = data . Second } ) ;
84+ liNode . Add ( new XElement ( "ModName" ) { Value = data . ModName } ) ;
85+ liNode . Add ( new XElement ( VERSION_NODENAME ) { Value = data . Version } ) ;
7886 modVersionsNode . Add ( liNode ) ;
79- Log . Message ( $ "set mod { data . First } 's version to { data . Second } ") ;
87+ Log . Message ( $ "set mod { data . ModName } 's version to { data . Version } ") ;
8088 }
8189 }
8290
@@ -114,14 +122,14 @@ public static void UpdateModVersionMetaHeader(string fileName)
114122 {
115123 string filePath = GenFilePaths . FilePathForSavedGame ( fileName ) ;
116124 MetaHeaderUtility . BeginReading ( filePath ) ;
117- List < Pair < string , string > > ModMetaDatas = new List < Pair < string , string > > ( ) ;
125+ List < ModMetaHeader > metaHeaders = new List < ModMetaHeader > ( ) ;
118126 foreach ( var modContentPack in LoadedModManager . RunningMods )
119127 {
120128 var metadata = modContentPack . GetMetaData ( ) ;
121129 var version = MetaHeaderUtility . GetVersionFromManifestFile ( modContentPack ) ;
122- ModMetaDatas . Add ( new Pair < string , string > ( metadata . Name , version ) ) ;
130+ metaHeaders . Add ( new ModMetaHeader ( ) { ModName = metadata . Name , Version = version } ) ;
123131 }
124- MetaHeaderUtility . SetVersions ( ModMetaDatas ) ;
132+ MetaHeaderUtility . SetVersions ( metaHeaders ) ;
125133 MetaHeaderUtility . EndReading ( ) ;
126134 }
127135
@@ -154,4 +162,10 @@ static void NoManifestFileInModWarning(string modName)
154162
155163 }
156164 }
165+
166+ public struct ModMetaHeader
167+ {
168+ public string ModName ;
169+ public string Version ;
170+ }
157171}
0 commit comments