Skip to content

Commit 622c026

Browse files
committed
fix: Fixed subfolder extratction for transports
1 parent 8670d47 commit 622c026

File tree

1 file changed

+98
-53
lines changed

1 file changed

+98
-53
lines changed

MLAPI-Editor/MLAPIEditor.cs

Lines changed: 98 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define NOASYNC
1+
#define NOASYNC
22

33
using System;
44
using System.Collections;
@@ -49,7 +49,8 @@ public void OnGUI()
4949
for (int i = 0; i < releases.Length; i++)
5050
{
5151
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 += "...";
5354
EditorGUILayout.LabelField(releases[i].tag_name + ": " + releases[i].name + (bodySummary.Trim().Length > 0 ? (" - " + bodySummary) : ""));
5455
}
5556
GUILayout.EndScrollView();
@@ -130,12 +131,13 @@ public static MLAPIVersion GetVersionDiff(MLAPIVersion v1, MLAPIVersion v2)
130131

131132
public static MLAPIVersion Parse(string version)
132133
{
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+
};
139141

140142
string v = version;
141143
if (version[0] == 'v')
@@ -216,6 +218,7 @@ public class TransportArtifact
216218
public bool preferNet45;
217219
public bool experimental;
218220
public int mlapi_major_version;
221+
public int[] required_build_targets;
219222
}
220223

221224
[Serializable]
@@ -237,7 +240,7 @@ public class GithubAsset
237240
[InitializeOnLoad]
238241
public class MLAPIEditor : EditorWindow
239242
{
240-
private const int COMPATIBLE_ARTIFACT_PATH_VERSION = 1;
243+
private const int COMPATIBLE_ARTIFACT_PATH_VERSION = 2;
241244
private const string API_URL = "https://api.github.com/repos/MidLevel/MLAPI/releases";
242245
private const string TRANSPORT_ARTIFACT_PATH_URL = "https://api.github.com/repos/MidLevel/MLAPI.Transports/contents/artifact_paths.json";
243246
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()
428431
EditorGUILayout.Space();
429432
}
430433

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+
431456
if (transportArtifacts.artifacts[i].experimental)
432457
{
433458
EditorGUILayout.Space();
@@ -516,8 +541,10 @@ private void OnGUI()
516541
{
517542
releases = new GithubRelease[0];
518543
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");
521548
}
522549

523550
GUILayout.EndArea();
@@ -607,7 +634,8 @@ private IEnumerator InstallRelease(int index)
607634
waiting = false;
608635
}
609636

610-
while (waiting) yield return null;
637+
while (waiting)
638+
yield return null;
611639

612640
if (accepted)
613641
{
@@ -762,17 +790,17 @@ private IEnumerator InstallTransport(int index)
762790

763791
foreach (ZipStorer.ZipFileEntry entry in dir)
764792
{
765-
if (useNet35 && entry.FilenameInZip.Contains("net35"))
793+
if (useNet35 && entry.FilenameInZip.Contains("net35") && entry.FilenameInZip.Length > entry.FilenameInZip.LastIndexOf("net35", StringComparison.Ordinal) + 6)
766794
{
767795
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));
769797

770798
zip.ExtractFile(entry, Path.Combine(transportDirectory, fileSubPath));
771799
}
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)
773801
{
774802
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));
776804

777805
zip.ExtractFile(entry, Path.Combine(transportDirectory, fileSubPath));
778806
}
@@ -830,7 +858,7 @@ private IEnumerator FetchAll()
830858
isParsing = true;
831859
string json = www.downloadHandler.text;
832860

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.
834862
//The JSON serializer cant take arrays. We have to split it up outselves.
835863
List<string> releasesJson = new List<string>();
836864
int depth = 0;
@@ -986,7 +1014,8 @@ private void Stop()
9861014

9871015
void Update()
9881016
{
989-
if (!coroutine.MoveNext()) Stop();
1017+
if (!coroutine.MoveNext())
1018+
Stop();
9901019
}
9911020
}
9921021
}
@@ -1031,6 +1060,22 @@ public static Rect GetEditorMainWindowPos()
10311060
}
10321061
throw new NotSupportedException("Can't find internal main window. Maybe something has changed inside Unity");
10331062
}
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+
}
10341079
}
10351080

10361081
#region ZipStorer
@@ -1074,7 +1119,7 @@ public class ZipStorer : IDisposable
10741119
/// </summary>
10751120
public enum Compression : ushort
10761121
{
1077-
/// <summary>Uncompressed storage</summary>
1122+
/// <summary>Uncompressed storage</summary>
10781123
Store = 0,
10791124
/// <summary>Deflate compression method</summary>
10801125
Deflate = 8
@@ -1257,7 +1302,7 @@ public static ZipStorer Open(Stream _stream, FileAccess _access, bool _leaveOpen
12571302
/// <param name="_method">Compression method</param>
12581303
/// <param name="_pathname">Full path of file to add to Zip storage</param>
12591304
/// <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>
12611306
public ZipFileEntry AddFile(Compression _method, string _pathname, string _filenameInZip, string _comment = null)
12621307
{
12631308
if (Access == FileAccess.Read)
@@ -1277,7 +1322,7 @@ public ZipFileEntry AddStream(Compression _method, string _filenameInZip, Stream
12771322
{
12781323
#if NOASYNC
12791324
return this.AddStreamAsync(_method, _filenameInZip, _source, _modTime, _comment);
1280-
#else
1325+
#else
12811326
return Task.Run(() => this.AddStreamAsync(_method, _filenameInZip, _source, _modTime, _comment)).Result;
12821327
#endif
12831328
}
@@ -1292,8 +1337,8 @@ public ZipFileEntry AddStream(Compression _method, string _filenameInZip, Stream
12921337
/// <param name="_comment">Comment for stored file</param>
12931338
#if NOASYNC
12941339
private ZipFileEntry
1295-
#else
1296-
public async Task<ZipFileEntry>
1340+
#else
1341+
public async Task<ZipFileEntry>
12971342
#endif
12981343
AddStreamAsync(Compression _method, string _filenameInZip, Stream _source, DateTime _modTime, string _comment = null)
12991344
{
@@ -1410,7 +1455,7 @@ public void Close()
14101455
}
14111456

14121457
/// <summary>
1413-
/// Read all the file records in the central directory
1458+
/// Read all the file records in the central directory
14141459
/// </summary>
14151460
/// <returns>List of all entries in directory</returns>
14161461
public List<ZipFileEntry> ReadCentralDir()
@@ -1514,7 +1559,7 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
15141559
{
15151560
#if NOASYNC
15161561
return this.ExtractFileAsync(_zfe, _stream);
1517-
#else
1562+
#else
15181563
return Task.Run(() => ExtractFileAsync(_zfe, _stream)).Result;
15191564
#endif
15201565
}
@@ -1528,8 +1573,8 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
15281573
/// <remarks>Unique compression methods are Store and Deflate</remarks>
15291574
#if NOASYNC
15301575
private bool
1531-
#else
1532-
public async Task<bool>
1576+
#else
1577+
public async Task<bool>
15331578
#endif
15341579
ExtractFileAsync(ZipFileEntry _zfe, Stream _stream)
15351580
{
@@ -1703,7 +1748,7 @@ private void WriteLocalHeader(ZipFileEntry _zfe)
17031748
byte[] extraInfo = this.CreateExtraInfo(_zfe);
17041749

17051750
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
17071752
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2); // zipping method
17081753
this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
17091754
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)
17451790
byte[] extraInfo = this.CreateExtraInfo(_zfe);
17461791

17471792
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
17491794
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2); // zipping method
17501795
this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
17511796
this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.Crc32), 0, 4); // file CRC
@@ -1771,16 +1816,16 @@ private uint get32bitSize(long size)
17711816
return size >= 0xFFFFFFFF ? 0xFFFFFFFF : (uint)size;
17721817
}
17731818

1774-
/*
1819+
/*
17751820
Zip64 end of central directory record
1776-
zip64 end of central dir
1821+
zip64 end of central dir
17771822
signature 4 bytes (0x06064b50)
17781823
size of zip64 end of central
17791824
directory record 8 bytes
17801825
version made by 2 bytes
17811826
version needed to extract 2 bytes
17821827
number of this disk 4 bytes
1783-
number of the disk with the
1828+
number of the disk with the
17841829
start of the central directory 4 bytes
17851830
total number of entries in the
17861831
central directory on this disk 8 bytes
@@ -1790,13 +1835,13 @@ size of the central directory 8 bytes
17901835
offset of start of central
17911836
directory with respect to
17921837
the starting disk number 8 bytes
1793-
zip64 extensible data sector (variable size)
1794-
1838+
zip64 extensible data sector (variable size)
1839+
17951840
Zip64 end of central directory locator
1796-
zip64 end of central dir locator
1841+
zip64 end of central dir locator
17971842
signature 4 bytes (0x07064b50)
17981843
number of the disk with the
1799-
start of the zip64 end of
1844+
start of the zip64 end of
18001845
central directory 4 bytes
18011846
relative offset of the zip64
18021847
end of central directory record 8 bytes
@@ -1826,19 +1871,19 @@ private void WriteEndRecord(long _size, long _offset)
18261871
this.ZipFileStream.Write(new byte[] { 80, 75, 6, 6 }, 0, 4);
18271872
this.ZipFileStream.Write(BitConverter.GetBytes((Int64)44), 0, 8); // size of zip64 end of central directory
18281873
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
18301875
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
18321877
this.ZipFileStream.Write(BitConverter.GetBytes((Int64)Files.Count + ExistingFiles), 0, 8); // total number of entries in the central directory in disk
18331878
this.ZipFileStream.Write(BitConverter.GetBytes((Int64)Files.Count + ExistingFiles), 0, 8); // total number of entries in the central directory
18341879
this.ZipFileStream.Write(BitConverter.GetBytes(_size), 0, 8); // size of the central directory
18351880
this.ZipFileStream.Write(BitConverter.GetBytes(_offset), 0, 8); // offset of start of central directory with respect to the starting disk number
18361881

18371882
// Zip64 end of central directory locator
18381883
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
18401885
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
18421887

18431888
Encoding encoder = this.EncodeUTF8 ? Encoding.UTF8 : DefaultEncoding;
18441889
byte[] encodedComment = encoder.GetBytes(this.Comment);
@@ -1852,8 +1897,8 @@ private void WriteEndRecord(long _size, long _offset)
18521897
// Copies all the source file into the zip storage
18531898
#if NOASYNC
18541899
private Compression
1855-
#else
1856-
private async Task<Compression>
1900+
#else
1901+
private async Task<Compression>
18571902
#endif
18581903
Store(ZipFileEntry _zfe, Stream _source)
18591904
{
@@ -1882,7 +1927,7 @@ private async Task<Compression>
18821927
bytesRead = await _source.ReadAsync(buffer, 0, buffer.Length);
18831928
if (bytesRead > 0)
18841929
await outStream.WriteAsync(buffer, 0, bytesRead);
1885-
#endif
1930+
#endif
18861931

18871932
for (uint i = 0; i < bytesRead; i++)
18881933
{
@@ -1921,14 +1966,14 @@ private async Task<Compression>
19211966
}
19221967

19231968
/* 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 (1–31)
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 (0–59)
1931-
11-15 Hour (0–23 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 (1–31)
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 (0–59)
1976+
11-15 Hour (0–23 on a 24-hour clock)
19321977
*/
19331978
private uint DateTimeToDosTime(DateTime _dt)
19341979
{
@@ -2021,7 +2066,7 @@ private void ReadExtraInfo(byte[] buffer, int offset, ZipFileEntry _zfe)
20212066
}
20222067

20232068
/* CRC32 algorithm
2024-
The 'magic number' for the CRC is 0xdebb20e3.
2069+
The 'magic number' for the CRC is 0xdebb20e3.
20252070
The proper CRC pre and post conditioning is used, meaning that the CRC register is
20262071
pre-conditioned with all ones (a starting value of 0xffffffff) and the value is post-conditioned by
20272072
taking the one's complement of the CRC residual.
@@ -2141,4 +2186,4 @@ public void Dispose()
21412186
#endregion
21422187
}
21432188
}
2144-
#endregion
2189+
#endregion

0 commit comments

Comments
 (0)