@@ -7,7 +7,7 @@ namespace ChuChartManager.Controllers;
77[ Route ( "api/[controller]/[action]" ) ]
88public class OptionController ( MusicScannerService scannerService ) : ControllerBase
99{
10- public record OptionDirInfo ( string DirName , int MusicCount , bool IsCustom ) ;
10+ public record OptionDirInfo ( string DirName , int MusicCount , bool IsCustom , string Version ) ;
1111 public record ConflictEntry ( int MusicId , string MusicName , string Dir , string ConflictDir ) ;
1212
1313 [ HttpGet ]
@@ -26,7 +26,8 @@ public ActionResult<List<OptionDirInfo>> GetOptionDirs()
2626 var markPath = Path . Combine ( StaticSettings . GamePath , "bin" , "option" , source , "CustomChartsMark.txt" ) ;
2727 isCustom = System . IO . File . Exists ( markPath ) ;
2828 }
29- return new OptionDirInfo ( source , musicCount , isCustom ) ;
29+ var version = ReadOptVersion ( source ) ;
30+ return new OptionDirInfo ( source , musicCount , isCustom , version ) ;
3031 } ) . ToList ( ) ;
3132
3233 return Ok ( result ) ;
@@ -208,4 +209,43 @@ private static void CopyDirectory(string source, string dest)
208209 foreach ( var dir in Directory . GetDirectories ( source ) )
209210 CopyDirectory ( dir , Path . Combine ( dest , Path . GetFileName ( dir ) ) ) ;
210211 }
212+
213+ private static string ReadOptVersion ( string dirName )
214+ {
215+ var path = ResolveOptRoot ( dirName ) ;
216+ if ( path == null ) return "" ;
217+ var confPath = Path . Combine ( path , "data.conf" ) ;
218+ if ( ! System . IO . File . Exists ( confPath ) ) return "" ;
219+
220+ try
221+ {
222+ int major = 0 , minor = 0 , release = 0 ;
223+ foreach ( var line in System . IO . File . ReadLines ( confPath ) )
224+ {
225+ if ( line . StartsWith ( "VerMajor" ) ) major = int . Parse ( line . Split ( '=' ) [ 1 ] . Trim ( ) ) ;
226+ if ( line . StartsWith ( "VerMinor" ) ) minor = int . Parse ( line . Split ( '=' ) [ 1 ] . Trim ( ) ) ;
227+ if ( line . StartsWith ( "VerRelease" ) ) release = int . Parse ( line . Split ( '=' ) [ 1 ] . Trim ( ) ) ;
228+ }
229+ var version = major > 0 ? $ "{ major } .{ minor : D2} " : "" ;
230+ if ( version . Length > 0 && release != 0 )
231+ version += "-" + ReleaseToLetters ( release ) ;
232+ return version ;
233+ }
234+ catch
235+ {
236+ return "" ;
237+ }
238+ }
239+
240+ private static string ReleaseToLetters ( int release )
241+ {
242+ var result = "" ;
243+ while ( release > 0 )
244+ {
245+ release -- ;
246+ result = ( char ) ( 'A' + release % 26 ) + result ;
247+ release /= 26 ;
248+ }
249+ return result ;
250+ }
211251}
0 commit comments