@@ -311,6 +311,7 @@ private static void GetAvailableRegionsHandler(Action<List<RegionResponseModel>>
311311 updateProperty ? . Invoke ( availableRegions . Regions . ToList ( ) ) ;
312312 return ;
313313 }
314+
314315 onFailure ? . Invoke ( ) ;
315316 }
316317
@@ -452,10 +453,9 @@ void OnContinuation(bool success)
452453 GameUploadedToTheCloud ? . Invoke ( ) ;
453454 } ) ;
454455 }
455-
456456 }
457457
458- private static string [ ] compoundExtensions =
458+ internal static string [ ] compoundExtensions =
459459 {
460460 ".framework.js" ,
461461 ".wasm" ,
@@ -471,11 +471,14 @@ private static bool TryGetFullExtension(ReadOnlySpan<char> fileName, string[] kn
471471 compoundExtension = string . Empty ;
472472 foreach ( var ext in knownCompoundExtensions )
473473 {
474- if ( ! fileName . EndsWith ( ext . AsSpan ( ) , StringComparison . OrdinalIgnoreCase ) )
474+ var extIndex = fileName . IndexOf ( ext . AsSpan ( ) , StringComparison . OrdinalIgnoreCase ) ;
475+ if ( extIndex < 0 )
475476 continue ;
476- compoundExtension = ext ;
477+
478+ compoundExtension = fileName [ extIndex ..] . ToString ( ) ;
477479 return true ;
478480 }
481+
479482 return false ;
480483 }
481484
@@ -486,6 +489,21 @@ private static bool DoesFileHaveGivenCompoundExtension(string fileName, string c
486489 return false ;
487490 }
488491
492+ internal static List < ( string name , string extension ) > GetValidFiles ( string [ ] fileNames , string [ ] knownCompoundExtensions )
493+ {
494+ return fileNames . Select ( fileName =>
495+ {
496+ if ( TryGetFullExtension ( fileName . AsSpan ( ) , knownCompoundExtensions , out var compoundExtension ) )
497+ {
498+ var splitExtension = compoundExtension . Split ( '.' ) ;
499+ var split = fileName . Split ( '.' ) ;
500+ var name = string . Join ( "." , split . Take ( split . Length - splitExtension . Length + 1 ) ) ;
501+ return ( name , compoundExtension ) ;
502+ }
503+
504+ return ( string . Empty , string . Empty ) ;
505+ } ) . Where ( file => ! string . IsNullOrEmpty ( file . Item1 ) ) . ToList ( ) ;
506+ }
489507
490508 public static void UploadClientBuild ( string clientBuildPath , string gameId , string clientGameVersion , string serverGameVersion , string streamingAssetsUrl )
491509 {
@@ -517,25 +535,21 @@ void OnCheckAuthTokenAndRefreshIfNeededContinuation(bool success)
517535
518536 var filePaths = Directory . GetFiles ( clientBuildPath ) ;
519537 var fileNames = filePaths . Select ( Path . GetFileName ) . ToArray ( ) ;
520- var validFiles = fileNames . Select ( fileName =>
521- {
522- if ( TryGetFullExtension ( fileName . AsSpan ( ) , compoundExtensions , out var compoundExtension ) )
523- {
524- var name = fileName . Split ( '.' ) . First ( ) ;
525- return ( name , compoundExtension ) ;
526- }
527- return ( string . Empty , string . Empty ) ;
538+ var validFiles = GetValidFiles ( fileNames , compoundExtensions ) ;
528539
529- } ) . Where ( file => ! string . IsNullOrEmpty ( file . Item1 ) ) . ToList ( ) ;
530-
531- //TO DO: make sure all necessary files are present
540+ if ( validFiles . Count != compoundExtensions . Length )
541+ {
542+ throw new ElympicsException (
543+ $ "Not all required files will be uploaded to bucket{ Environment . NewLine } Files in directory: { string . Join ( '|' , fileNames ) } { Environment . NewLine } Validated files: { string . Join ( '|' , validFiles ) } ") ;
544+ }
532545
533546 if ( ! ElympicsConfig . IsLogin )
534547 {
535548 ElympicsLogger . LogError ( "You must be logged in Elympics to upload a client build." ) ;
536549 EditorUtility . ClearProgressBar ( ) ;
537550 return ;
538551 }
552+
539553 EditorUtility . DisplayProgressBar ( title , "Initializing upload" , 0.1f ) ;
540554
541555 var request = new ClientBuildUploadInitRequestModel ( )
@@ -544,7 +558,7 @@ void OnCheckAuthTokenAndRefreshIfNeededContinuation(bool success)
544558 clientGameVersion = clientGameVersion ,
545559 serverGameVersion = serverGameVersion ,
546560 streamingAssetsUrl = streamingAssetsUrl ,
547- files = validFiles . Select ( fileNameAndExtension => FixedPrefix + fileNameAndExtension . Item2 ) . ToArray ( ) ,
561+ files = validFiles . Select ( fileNameAndExtension => FixedPrefix + fileNameAndExtension . extension ) . ToArray ( ) ,
548562 } ;
549563
550564 var uri = GetCombinedUrl ( ElympicsWebEndpoint , "client-builds" , "init" ) ;
@@ -588,7 +602,6 @@ void OnClientBuildUploadInitResponse(ClientBuildUploadInitResponseModel response
588602 {
589603 for ( var index = 0 ; index < response . Files . Length ; index ++ )
590604 {
591-
592605 var fileUploadInfo = response . Files [ index ] ;
593606 var responseFile = Path . Combine ( clientBuildPath , fileUploadInfo . FilePath ) ;
594607 var expectedFile = validFiles [ index ] ;
@@ -602,6 +615,7 @@ void OnClientBuildUploadInitResponse(ClientBuildUploadInitResponseModel response
602615 var operation = request . SendWebRequest ( ) ;
603616 while ( ! operation . isDone )
604617 { }
618+
605619 if ( operation . webRequest . IsConnectionError ( ) || operation . webRequest . IsProtocolError ( ) )
606620 throw new ElympicsException ( $ "Failed to upload file '{ localFile } ': { operation . webRequest . error } { Environment . NewLine } { operation . webRequest . downloadHandler . text } ") ;
607621 }
0 commit comments