@@ -244,36 +244,37 @@ public static string GetSteamDir()
244
244
return null ;
245
245
}
246
246
247
- public static string GetVersion ( )
247
+ public static async Task < string > GetVersion ( )
248
248
{
249
+ string result = string . Empty ;
250
+
251
+ var versions = await GetVersionsList ( ) ;
252
+
249
253
string filename = Path . Combine ( App . BeatSaberInstallDirectory , "Beat Saber_Data" , "globalgamemanagers" ) ;
250
254
using ( var stream = File . OpenRead ( filename ) )
251
- using ( var reader = new BinaryReader ( stream , Encoding . UTF8 ) )
255
+ using ( var reader = new StreamReader ( stream , Encoding . UTF8 ) )
252
256
{
253
- const string key = "public.app-category.games" ;
254
- int pos = 0 ;
257
+ var line = reader . ReadLine ( ) ;
255
258
256
- while ( stream . Position < stream . Length && pos < key . Length )
259
+ while ( line != null )
257
260
{
258
- if ( reader . ReadByte ( ) == key [ pos ] ) pos ++ ;
259
- else pos = 0 ;
260
- }
261
-
262
- if ( stream . Position == stream . Length ) // we went through the entire stream without finding the key
263
- return null ;
264
-
265
- while ( stream . Position < stream . Length )
266
- {
267
- var current = ( char ) reader . ReadByte ( ) ;
268
- if ( char . IsDigit ( current ) )
269
- break ;
261
+ foreach ( var version in versions )
262
+ {
263
+ if ( line . Contains ( version ) )
264
+ {
265
+ result = version ;
266
+ break ;
267
+ }
268
+ }
269
+ if ( ! string . IsNullOrEmpty ( result ) ) break ;
270
+ line = reader . ReadLine ( ) ;
270
271
}
271
272
272
- var rewind = - sizeof ( int ) - sizeof ( byte ) ;
273
- stream . Seek ( rewind , SeekOrigin . Current ) ; // rewind to the string length
274
-
275
- var strlen = reader . ReadInt32 ( ) ;
276
- var strbytes = reader . ReadBytes ( strlen ) ;
273
+ ////There is one version ending in "p1" on BeatMods
274
+ var filteredVersionMatch = Regex . Match ( result , @"[\d]+.[\d]+.[\d]+(p1)?" ) ;
275
+ return filteredVersionMatch . Success ? filteredVersionMatch . Value : result ;
276
+ }
277
+ }
277
278
278
279
// TODO: should cache this
279
280
public static async Task < List < string > > GetVersionsList ( )
0 commit comments