1
- #define NOASYNC
1
+ #define NOASYNC
2
2
3
3
using System ;
4
4
using System . Collections ;
@@ -49,7 +49,8 @@ public void OnGUI()
49
49
for ( int i = 0 ; i < releases . Length ; i ++ )
50
50
{
51
51
string bodySummary = releases [ i ] . body . Substring ( 0 , releases [ i ] . body . Length > 100 ? 100 : releases [ i ] . body . Length ) ;
52
- if ( releases [ i ] . body . Length > 100 ) bodySummary += "..." ;
52
+ if ( releases [ i ] . body . Length > 100 )
53
+ bodySummary += "..." ;
53
54
EditorGUILayout . LabelField ( releases [ i ] . tag_name + ": " + releases [ i ] . name + ( bodySummary . Trim ( ) . Length > 0 ? ( " - " + bodySummary ) : "" ) ) ;
54
55
}
55
56
GUILayout . EndScrollView ( ) ;
@@ -130,12 +131,13 @@ public static MLAPIVersion GetVersionDiff(MLAPIVersion v1, MLAPIVersion v2)
130
131
131
132
public static MLAPIVersion Parse ( string version )
132
133
{
133
- if ( version == "None" ) return new MLAPIVersion ( )
134
- {
135
- MAJOR = byte . MaxValue ,
136
- MINOR = byte . MaxValue ,
137
- PATCH = byte . MaxValue
138
- } ;
134
+ if ( version == "None" )
135
+ return new MLAPIVersion ( )
136
+ {
137
+ MAJOR = byte . MaxValue ,
138
+ MINOR = byte . MaxValue ,
139
+ PATCH = byte . MaxValue
140
+ } ;
139
141
140
142
string v = version ;
141
143
if ( version [ 0 ] == 'v' )
@@ -216,6 +218,7 @@ public class TransportArtifact
216
218
public bool preferNet45 ;
217
219
public bool experimental ;
218
220
public int mlapi_major_version ;
221
+ public int [ ] required_build_targets ;
219
222
}
220
223
221
224
[ Serializable ]
@@ -237,7 +240,7 @@ public class GithubAsset
237
240
[ InitializeOnLoad ]
238
241
public class MLAPIEditor : EditorWindow
239
242
{
240
- private const int COMPATIBLE_ARTIFACT_PATH_VERSION = 1 ;
243
+ private const int COMPATIBLE_ARTIFACT_PATH_VERSION = 2 ;
241
244
private const string API_URL = "https://api.github.com/repos/MidLevel/MLAPI/releases" ;
242
245
private const string TRANSPORT_ARTIFACT_PATH_URL = "https://api.github.com/repos/MidLevel/MLAPI.Transports/contents/artifact_paths.json" ;
243
246
private const string TRANSPORT_ARTIFACT_DOWNLOAD_URL_TEMPLATE = "https://ci.appveyor.com/api/projects/MidLevel/MLAPI-Transports/artifacts/<path>?branch=master" ;
@@ -428,6 +431,28 @@ private void OnGUI()
428
431
EditorGUILayout . Space ( ) ;
429
432
}
430
433
434
+ if ( transportArtifacts . artifacts [ i ] . required_build_targets == null )
435
+ {
436
+ transportArtifacts . artifacts [ i ] . required_build_targets = new int [ 0 ] ;
437
+ }
438
+
439
+ for ( int j = 0 ; j < transportArtifacts . artifacts [ i ] . required_build_targets . Length ; j ++ )
440
+ {
441
+ try
442
+ {
443
+ if ( ! MLAPIEditorExtensions . IsPlatformSupported ( ( BuildTarget ) transportArtifacts . artifacts [ i ] . required_build_targets [ j ] ) )
444
+ {
445
+ EditorGUILayout . HelpBox ( "This transport requires the " + ( ( BuildTarget ) transportArtifacts . artifacts [ i ] . required_build_targets [ j ] ) + " build target to be installed!" , MessageType . Warning ) ;
446
+ break ;
447
+ }
448
+ }
449
+ catch ( Exception )
450
+ {
451
+
452
+ }
453
+ }
454
+
455
+
431
456
if ( transportArtifacts . artifacts [ i ] . experimental )
432
457
{
433
458
EditorGUILayout . Space ( ) ;
@@ -516,8 +541,10 @@ private void OnGUI()
516
541
{
517
542
releases = new GithubRelease [ 0 ] ;
518
543
releaseFoldoutStatus = new bool [ 0 ] ;
519
- if ( EditorPrefs . HasKey ( Application . productName + "/MLAPI_version" ) ) EditorPrefs . DeleteKey ( Application . productName + "/MLAPI_version" ) ;
520
- if ( EditorPrefs . HasKey ( Application . productName + "/MLAPI_lastUpdated" ) ) EditorPrefs . DeleteKey ( Application . productName + "/MLAPI_lastUpdated" ) ;
544
+ if ( EditorPrefs . HasKey ( Application . productName + "/MLAPI_version" ) )
545
+ EditorPrefs . DeleteKey ( Application . productName + "/MLAPI_version" ) ;
546
+ if ( EditorPrefs . HasKey ( Application . productName + "/MLAPI_lastUpdated" ) )
547
+ EditorPrefs . DeleteKey ( Application . productName + "/MLAPI_lastUpdated" ) ;
521
548
}
522
549
523
550
GUILayout . EndArea ( ) ;
@@ -607,7 +634,8 @@ private IEnumerator InstallRelease(int index)
607
634
waiting = false ;
608
635
}
609
636
610
- while ( waiting ) yield return null ;
637
+ while ( waiting )
638
+ yield return null ;
611
639
612
640
if ( accepted )
613
641
{
@@ -762,17 +790,17 @@ private IEnumerator InstallTransport(int index)
762
790
763
791
foreach ( ZipStorer . ZipFileEntry entry in dir )
764
792
{
765
- if ( useNet35 && entry . FilenameInZip . Contains ( "net35" ) )
793
+ if ( useNet35 && entry . FilenameInZip . Contains ( "net35" ) && entry . FilenameInZip . Length > entry . FilenameInZip . LastIndexOf ( "net35" , StringComparison . Ordinal ) + 6 )
766
794
{
767
795
int lastIndexOfNet35 = entry . FilenameInZip . LastIndexOf ( "net35" , StringComparison . Ordinal ) ;
768
- string fileSubPath = entry . FilenameInZip . Substring ( lastIndexOfNet35 , entry . FilenameInZip . Length - lastIndexOfNet35 ) ;
796
+ string fileSubPath = entry . FilenameInZip . Substring ( lastIndexOfNet35 + 6 , entry . FilenameInZip . Length - ( lastIndexOfNet35 + 6 ) ) ;
769
797
770
798
zip . ExtractFile ( entry , Path . Combine ( transportDirectory , fileSubPath ) ) ;
771
799
}
772
- else if ( useNet45 && entry . FilenameInZip . Contains ( "net45" ) )
800
+ else if ( useNet45 && entry . FilenameInZip . Contains ( "net45" ) && entry . FilenameInZip . Length > entry . FilenameInZip . LastIndexOf ( "net35" , StringComparison . Ordinal ) + 6 )
773
801
{
774
802
int lastIndexOfNet45 = entry . FilenameInZip . LastIndexOf ( "net45" , StringComparison . Ordinal ) ;
775
- string fileSubPath = entry . FilenameInZip . Substring ( lastIndexOfNet45 , entry . FilenameInZip . Length - lastIndexOfNet45 ) ;
803
+ string fileSubPath = entry . FilenameInZip . Substring ( lastIndexOfNet45 + 6 , entry . FilenameInZip . Length - ( lastIndexOfNet45 + 6 ) ) ;
776
804
777
805
zip . ExtractFile ( entry , Path . Combine ( transportDirectory , fileSubPath ) ) ;
778
806
}
@@ -830,7 +858,7 @@ private IEnumerator FetchAll()
830
858
isParsing = true ;
831
859
string json = www . downloadHandler . text ;
832
860
833
- //This makes it from a json array to the individual objects in the array.
861
+ //This makes it from a json array to the individual objects in the array.
834
862
//The JSON serializer cant take arrays. We have to split it up outselves.
835
863
List < string > releasesJson = new List < string > ( ) ;
836
864
int depth = 0 ;
@@ -986,7 +1014,8 @@ private void Stop()
986
1014
987
1015
void Update ( )
988
1016
{
989
- if ( ! coroutine . MoveNext ( ) ) Stop ( ) ;
1017
+ if ( ! coroutine . MoveNext ( ) )
1018
+ Stop ( ) ;
990
1019
}
991
1020
}
992
1021
}
@@ -1031,6 +1060,22 @@ public static Rect GetEditorMainWindowPos()
1031
1060
}
1032
1061
throw new NotSupportedException ( "Can't find internal main window. Maybe something has changed inside Unity" ) ;
1033
1062
}
1063
+
1064
+ public static bool IsPlatformSupported ( BuildTarget target )
1065
+ {
1066
+ try
1067
+ {
1068
+ Type moduleManager = Type . GetType ( "UnityEditor.Modules.ModuleManager,UnityEditor.dll" ) ;
1069
+ MethodInfo isPlatformSupportLoadedMethod = moduleManager . GetMethod ( "IsPlatformSupportLoaded" , BindingFlags . Static | BindingFlags . NonPublic ) ;
1070
+ MethodInfo getTargetStringFromBuildTargetMethod = moduleManager . GetMethod ( "GetTargetStringFromBuildTarget" , BindingFlags . Static | BindingFlags . NonPublic ) ;
1071
+
1072
+ return ( bool ) isPlatformSupportLoadedMethod . Invoke ( null , new object [ ] { ( string ) getTargetStringFromBuildTargetMethod . Invoke ( null , new object [ ] { target } ) } ) ;
1073
+ }
1074
+ catch ( Exception )
1075
+ {
1076
+ return true ;
1077
+ }
1078
+ }
1034
1079
}
1035
1080
1036
1081
#region ZipStorer
@@ -1074,7 +1119,7 @@ public class ZipStorer : IDisposable
1074
1119
/// </summary>
1075
1120
public enum Compression : ushort
1076
1121
{
1077
- /// <summary>Uncompressed storage</summary>
1122
+ /// <summary>Uncompressed storage</summary>
1078
1123
Store = 0 ,
1079
1124
/// <summary>Deflate compression method</summary>
1080
1125
Deflate = 8
@@ -1257,7 +1302,7 @@ public static ZipStorer Open(Stream _stream, FileAccess _access, bool _leaveOpen
1257
1302
/// <param name="_method">Compression method</param>
1258
1303
/// <param name="_pathname">Full path of file to add to Zip storage</param>
1259
1304
/// <param name="_filenameInZip">Filename and path as desired in Zip directory</param>
1260
- /// <param name="_comment">Comment for stored file</param>
1305
+ /// <param name="_comment">Comment for stored file</param>
1261
1306
public ZipFileEntry AddFile ( Compression _method , string _pathname , string _filenameInZip , string _comment = null )
1262
1307
{
1263
1308
if ( Access == FileAccess . Read )
@@ -1277,7 +1322,7 @@ public ZipFileEntry AddStream(Compression _method, string _filenameInZip, Stream
1277
1322
{
1278
1323
#if NOASYNC
1279
1324
return this . AddStreamAsync ( _method , _filenameInZip , _source , _modTime , _comment ) ;
1280
- #else
1325
+ #else
1281
1326
return Task . Run ( ( ) => this . AddStreamAsync ( _method , _filenameInZip , _source , _modTime , _comment ) ) . Result ;
1282
1327
#endif
1283
1328
}
@@ -1292,8 +1337,8 @@ public ZipFileEntry AddStream(Compression _method, string _filenameInZip, Stream
1292
1337
/// <param name="_comment">Comment for stored file</param>
1293
1338
#if NOASYNC
1294
1339
private ZipFileEntry
1295
- #else
1296
- public async Task < ZipFileEntry >
1340
+ #else
1341
+ public async Task < ZipFileEntry >
1297
1342
#endif
1298
1343
AddStreamAsync ( Compression _method , string _filenameInZip , Stream _source , DateTime _modTime , string _comment = null )
1299
1344
{
@@ -1410,7 +1455,7 @@ public void Close()
1410
1455
}
1411
1456
1412
1457
/// <summary>
1413
- /// Read all the file records in the central directory
1458
+ /// Read all the file records in the central directory
1414
1459
/// </summary>
1415
1460
/// <returns>List of all entries in directory</returns>
1416
1461
public List < ZipFileEntry > ReadCentralDir ( )
@@ -1514,7 +1559,7 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
1514
1559
{
1515
1560
#if NOASYNC
1516
1561
return this . ExtractFileAsync ( _zfe , _stream ) ;
1517
- #else
1562
+ #else
1518
1563
return Task . Run ( ( ) => ExtractFileAsync ( _zfe , _stream ) ) . Result ;
1519
1564
#endif
1520
1565
}
@@ -1528,8 +1573,8 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
1528
1573
/// <remarks>Unique compression methods are Store and Deflate</remarks>
1529
1574
#if NOASYNC
1530
1575
private bool
1531
- #else
1532
- public async Task < bool >
1576
+ #else
1577
+ public async Task < bool >
1533
1578
#endif
1534
1579
ExtractFileAsync ( ZipFileEntry _zfe , Stream _stream )
1535
1580
{
@@ -1703,7 +1748,7 @@ private void WriteLocalHeader(ZipFileEntry _zfe)
1703
1748
byte [ ] extraInfo = this . CreateExtraInfo ( _zfe ) ;
1704
1749
1705
1750
this . ZipFileStream . Write ( new byte [ ] { 80 , 75 , 3 , 4 , 20 , 0 } , 0 , 6 ) ; // No extra header
1706
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) ( _zfe . EncodeUTF8 ? 0x0800 : 0 ) ) , 0 , 2 ) ; // filename and comment encoding
1751
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) ( _zfe . EncodeUTF8 ? 0x0800 : 0 ) ) , 0 , 2 ) ; // filename and comment encoding
1707
1752
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) _zfe . Method ) , 0 , 2 ) ; // zipping method
1708
1753
this . ZipFileStream . Write ( BitConverter . GetBytes ( DateTimeToDosTime ( _zfe . ModifyTime ) ) , 0 , 4 ) ; // zipping date and time
1709
1754
this . ZipFileStream . Write ( new byte [ ] { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , 0 , 12 ) ; // unused CRC, un/compressed size, updated later
@@ -1745,7 +1790,7 @@ private void WriteCentralDirRecord(ZipFileEntry _zfe)
1745
1790
byte [ ] extraInfo = this . CreateExtraInfo ( _zfe ) ;
1746
1791
1747
1792
this . ZipFileStream . Write ( new byte [ ] { 80 , 75 , 1 , 2 , 23 , 0xB , 20 , 0 } , 0 , 8 ) ;
1748
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) ( _zfe . EncodeUTF8 ? 0x0800 : 0 ) ) , 0 , 2 ) ; // filename and comment encoding
1793
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) ( _zfe . EncodeUTF8 ? 0x0800 : 0 ) ) , 0 , 2 ) ; // filename and comment encoding
1749
1794
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( ushort ) _zfe . Method ) , 0 , 2 ) ; // zipping method
1750
1795
this . ZipFileStream . Write ( BitConverter . GetBytes ( DateTimeToDosTime ( _zfe . ModifyTime ) ) , 0 , 4 ) ; // zipping date and time
1751
1796
this . ZipFileStream . Write ( BitConverter . GetBytes ( _zfe . Crc32 ) , 0 , 4 ) ; // file CRC
@@ -1771,16 +1816,16 @@ private uint get32bitSize(long size)
1771
1816
return size >= 0xFFFFFFFF ? 0xFFFFFFFF : ( uint ) size ;
1772
1817
}
1773
1818
1774
- /*
1819
+ /*
1775
1820
Zip64 end of central directory record
1776
- zip64 end of central dir
1821
+ zip64 end of central dir
1777
1822
signature 4 bytes (0x06064b50)
1778
1823
size of zip64 end of central
1779
1824
directory record 8 bytes
1780
1825
version made by 2 bytes
1781
1826
version needed to extract 2 bytes
1782
1827
number of this disk 4 bytes
1783
- number of the disk with the
1828
+ number of the disk with the
1784
1829
start of the central directory 4 bytes
1785
1830
total number of entries in the
1786
1831
central directory on this disk 8 bytes
@@ -1790,13 +1835,13 @@ size of the central directory 8 bytes
1790
1835
offset of start of central
1791
1836
directory with respect to
1792
1837
the starting disk number 8 bytes
1793
- zip64 extensible data sector (variable size)
1794
-
1838
+ zip64 extensible data sector (variable size)
1839
+
1795
1840
Zip64 end of central directory locator
1796
- zip64 end of central dir locator
1841
+ zip64 end of central dir locator
1797
1842
signature 4 bytes (0x07064b50)
1798
1843
number of the disk with the
1799
- start of the zip64 end of
1844
+ start of the zip64 end of
1800
1845
central directory 4 bytes
1801
1846
relative offset of the zip64
1802
1847
end of central directory record 8 bytes
@@ -1826,19 +1871,19 @@ private void WriteEndRecord(long _size, long _offset)
1826
1871
this . ZipFileStream . Write ( new byte [ ] { 80 , 75 , 6 , 6 } , 0 , 4 ) ;
1827
1872
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( Int64 ) 44 ) , 0 , 8 ) ; // size of zip64 end of central directory
1828
1873
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt16 ) 45 ) , 0 , 2 ) ; // version made by
1829
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt16 ) 45 ) , 0 , 2 ) ; // version needed to extract
1874
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt16 ) 45 ) , 0 , 2 ) ; // version needed to extract
1830
1875
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 0 ) , 0 , 4 ) ; // current disk
1831
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 0 ) , 0 , 4 ) ; // start of central directory
1876
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 0 ) , 0 , 4 ) ; // start of central directory
1832
1877
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( Int64 ) Files . Count + ExistingFiles ) , 0 , 8 ) ; // total number of entries in the central directory in disk
1833
1878
this . ZipFileStream . Write ( BitConverter . GetBytes ( ( Int64 ) Files . Count + ExistingFiles ) , 0 , 8 ) ; // total number of entries in the central directory
1834
1879
this . ZipFileStream . Write ( BitConverter . GetBytes ( _size ) , 0 , 8 ) ; // size of the central directory
1835
1880
this . ZipFileStream . Write ( BitConverter . GetBytes ( _offset ) , 0 , 8 ) ; // offset of start of central directory with respect to the starting disk number
1836
1881
1837
1882
// Zip64 end of central directory locator
1838
1883
this . ZipFileStream . Write ( new byte [ ] { 80 , 75 , 6 , 7 } , 0 , 4 ) ;
1839
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 0 ) , 0 , 4 ) ; // number of the disk
1884
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 0 ) , 0 , 4 ) ; // number of the disk
1840
1885
this . ZipFileStream . Write ( BitConverter . GetBytes ( dirOffset ) , 0 , 8 ) ; // relative offset of the zip64 end of central directory record
1841
- this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 1 ) , 0 , 4 ) ; // total number of disks
1886
+ this . ZipFileStream . Write ( BitConverter . GetBytes ( ( UInt32 ) 1 ) , 0 , 4 ) ; // total number of disks
1842
1887
1843
1888
Encoding encoder = this . EncodeUTF8 ? Encoding . UTF8 : DefaultEncoding ;
1844
1889
byte [ ] encodedComment = encoder . GetBytes ( this . Comment ) ;
@@ -1852,8 +1897,8 @@ private void WriteEndRecord(long _size, long _offset)
1852
1897
// Copies all the source file into the zip storage
1853
1898
#if NOASYNC
1854
1899
private Compression
1855
- #else
1856
- private async Task < Compression >
1900
+ #else
1901
+ private async Task < Compression >
1857
1902
#endif
1858
1903
Store ( ZipFileEntry _zfe , Stream _source )
1859
1904
{
@@ -1882,7 +1927,7 @@ private async Task<Compression>
1882
1927
bytesRead = await _source . ReadAsync ( buffer , 0 , buffer . Length ) ;
1883
1928
if ( bytesRead > 0 )
1884
1929
await outStream . WriteAsync ( buffer , 0 , bytesRead ) ;
1885
- #endif
1930
+ #endif
1886
1931
1887
1932
for ( uint i = 0 ; i < bytesRead ; i ++ )
1888
1933
{
@@ -1921,14 +1966,14 @@ private async Task<Compression>
1921
1966
}
1922
1967
1923
1968
/* DOS Date and time:
1924
- MS-DOS date. The date is a packed value with the following format. Bits Description
1925
- 0-4 Day of the month (131)
1926
- 5-8 Month (1 = January, 2 = February, and so on)
1927
- 9-15 Year offset from 1980 (add 1980 to get actual year)
1928
- MS-DOS time. The time is a packed value with the following format. Bits Description
1929
- 0-4 Second divided by 2
1930
- 5-10 Minute (059)
1931
- 11-15 Hour (023 on a 24-hour clock)
1969
+ MS-DOS date. The date is a packed value with the following format. Bits Description
1970
+ 0-4 Day of the month (131)
1971
+ 5-8 Month (1 = January, 2 = February, and so on)
1972
+ 9-15 Year offset from 1980 (add 1980 to get actual year)
1973
+ MS-DOS time. The time is a packed value with the following format. Bits Description
1974
+ 0-4 Second divided by 2
1975
+ 5-10 Minute (059)
1976
+ 11-15 Hour (023 on a 24-hour clock)
1932
1977
*/
1933
1978
private uint DateTimeToDosTime ( DateTime _dt )
1934
1979
{
@@ -2021,7 +2066,7 @@ private void ReadExtraInfo(byte[] buffer, int offset, ZipFileEntry _zfe)
2021
2066
}
2022
2067
2023
2068
/* CRC32 algorithm
2024
- The 'magic number' for the CRC is 0xdebb20e3.
2069
+ The 'magic number' for the CRC is 0xdebb20e3.
2025
2070
The proper CRC pre and post conditioning is used, meaning that the CRC register is
2026
2071
pre-conditioned with all ones (a starting value of 0xffffffff) and the value is post-conditioned by
2027
2072
taking the one's complement of the CRC residual.
@@ -2141,4 +2186,4 @@ public void Dispose()
2141
2186
#endregion
2142
2187
}
2143
2188
}
2144
- #endregion
2189
+ #endregion
0 commit comments