@@ -579,30 +579,38 @@ internal static object[] NewestPackagePathFilter(string packagePath)
579579 {
580580 #region Newest Filter
581581 string [ ] versionPaths = Directory . GetDirectories ( packagePath ) ;
582- Dictionary < string , decimal > packageVersions = new Dictionary < string , decimal > ( ) ;
582+ string newestVersionPath = null ;
583+ decimal newestVersion = 0 ;
584+
583585 foreach ( var versionPath in versionPaths )
584586 {
585587 string versionName = Path . GetFileNameWithoutExtension ( versionPath ) ;
586588
589+ // 確保符合預期格式, 跳過不符合格式的資料夾
587590 if ( versionName . IndexOf ( '-' ) <= - 1 ) continue ;
588591
589- string major = versionName . Substring ( 0 , versionName . LastIndexOf ( "-" ) ) ;
590- string minor = versionName . Substring ( versionName . LastIndexOf ( "-" ) + 1 , versionName . Length - versionName . LastIndexOf ( "-" ) - 1 ) ;
592+ // 提取日期部分並處理為 "yyyyMMdd" 格式
593+ string major = versionName . Substring ( 0 , versionName . LastIndexOf ( "-" ) ) . Replace ( "-" , string . Empty ) ;
591594
592- // yyyy-mm-dd
593- major = major . Trim ( ) . Replace ( "-" , string . Empty ) ;
594- // 24 h * 60 m = 1440 m (max is 4 num of digits)
595- minor = minor . Trim ( ) . PadLeft ( 4 , '0' ) ;
596- //Debug.Log($"Major Date: {major}, Minor Minute: {minor} => {major}{minor}");
595+ // 提取分鐘部分, 並確保其為 4 位數格式
596+ string minor = versionName . Substring ( versionName . LastIndexOf ( "-" ) + 1 ) . PadLeft ( 4 , '0' ) ;
597597
598- string refineVersionName = $ "{ major } { minor } ";
599- if ( decimal . TryParse ( refineVersionName , out decimal value ) ) packageVersions . Add ( versionPath , value ) ;
600- }
598+ // 合併日期與分鐘部分, 並轉換為數字
599+ string refinedVersionName = major + minor ;
601600
602- string newestVersionPath = packageVersions . Any ( ) ? packageVersions . Aggregate ( ( x , y ) => x . Value > y . Value ? x : y ) . Key : null ;
603- decimal newestVersion = ! string . IsNullOrEmpty ( newestVersionPath ) ? packageVersions [ newestVersionPath ] : 0 ;
601+ if ( decimal . TryParse ( refinedVersionName , out decimal value ) )
602+ {
603+ // 直接比較, 更新最新版本的路徑和版本號
604+ if ( value > newestVersion )
605+ {
606+ newestVersion = value ;
607+ newestVersionPath = versionPath ;
608+ }
609+ }
610+ }
604611 #endregion
605612
613+ // 返回最新的版本路徑和版本數值
606614 return new object [ ] { newestVersionPath , newestVersion } ;
607615 }
608616
0 commit comments