30
30
using System ;
31
31
using System . IO ;
32
32
using System . Text . RegularExpressions ;
33
+ using System . Reflection ;
33
34
34
35
namespace OneSignalSDK {
35
36
/// <summary>
@@ -46,37 +47,66 @@ public override string Details
46
47
public override bool IsRequired
47
48
=> true ;
48
49
49
- protected override bool _getIsStepCompleted ( ) {
50
+ private Version _getAssetsEDM4UVersion ( ) {
50
51
var isInstalled = CompilationPipeline . GetPrecompiledAssemblyNames ( )
51
52
. Any ( assemblyName => assemblyName . StartsWith ( "Google.VersionHandler" ) ) ;
52
53
53
54
if ( ! isInstalled )
54
- return false ;
55
+ return null ;
55
56
56
57
var path = "Assets/ExternalDependencyManager/Editor" ;
57
58
var directoryInfo = new DirectoryInfo ( path ) ;
58
59
59
60
if ( ! directoryInfo . Exists )
60
- return false ;
61
+ return null ;
61
62
62
63
FileInfo [ ] files ;
63
64
64
65
try {
65
66
files = directoryInfo . GetFiles ( "external-dependency-manager_version-*_manifest.txt" ) ;
66
67
} catch ( Exception ) {
67
- return false ;
68
+ return null ;
68
69
}
69
70
70
71
if ( files . Length != 1 ) {
71
- SDKDebug . Warn ( "EDM4U version number could not be determined." ) ;
72
- return false ;
72
+ return null ;
73
73
}
74
74
75
75
var file = files [ 0 ] ;
76
76
var pattern = @"external-dependency-manager_version-(.+)_manifest\.txt" ;
77
77
var match = Regex . Match ( file . Name , pattern ) ;
78
78
var version = new Version ( match . Groups [ 1 ] . Value ) ;
79
79
80
+ return version ;
81
+ }
82
+
83
+ private Version _getPackagesEDM4UVersion ( ) {
84
+ var assembly = AppDomain . CurrentDomain . GetAssemblies ( ) . FirstOrDefault ( x => x . GetName ( ) . Name . StartsWith ( "Google.PackageManagerResolver" ) ) ;
85
+ if ( assembly == null )
86
+ return null ;
87
+
88
+ var type = assembly . GetType ( "Google.PackageManagerResolverVersionNumber" , false ) ;
89
+ if ( type == null )
90
+ return null ;
91
+
92
+ var property = type . GetProperty ( "Value" , BindingFlags . Static | BindingFlags . Public ) ;
93
+ if ( property == null )
94
+ return null ;
95
+
96
+ var version = ( Version ) property . GetValue ( null ) ;
97
+ return version ;
98
+ }
99
+
100
+ protected override bool _getIsStepCompleted ( ) {
101
+ var version = _getAssetsEDM4UVersion ( ) ;
102
+ if ( version == null )
103
+ version = _getPackagesEDM4UVersion ( ) ;
104
+
105
+ if ( version == null ) {
106
+ SDKDebug . Warn ( "EDM4U version number could not be determined." ) ;
107
+ return false ;
108
+ }
109
+
80
110
var expectedVersion = new Version ( _edm4UVersion ) ;
81
111
82
112
return version >= expectedVersion ;
0 commit comments